nrfcxx
0.1.0
C++-17 Framework for Nordic nRF5 Devices
|
Go to the documentation of this file. 7 #ifndef NRFCXX_GPIO_HPP 8 #define NRFCXX_GPIO_HPP 22 constexpr uint32_t
PIN_CNF_RDONLY = ((GPIO_PIN_CNF_SENSE_Disabled << GPIO_PIN_CNF_SENSE_Pos)
23 | (GPIO_PIN_CNF_DRIVE_S0S1 << GPIO_PIN_CNF_DRIVE_Pos)
24 | (GPIO_PIN_CNF_INPUT_Connect << GPIO_PIN_CNF_INPUT_Pos)
25 | (GPIO_PIN_CNF_DIR_Input << GPIO_PIN_CNF_DIR_Pos));
31 constexpr uint32_t
PIN_CNF_WRONLY = ((GPIO_PIN_CNF_SENSE_Disabled << GPIO_PIN_CNF_SENSE_Pos)
32 | (GPIO_PIN_CNF_DRIVE_S0S1 << GPIO_PIN_CNF_DRIVE_Pos)
33 | (GPIO_PIN_CNF_INPUT_Disconnect << GPIO_PIN_CNF_INPUT_Pos)
34 | (GPIO_PIN_CNF_DIR_Output << GPIO_PIN_CNF_DIR_Pos));
40 constexpr uint32_t
PIN_CNF_RDWR = ((GPIO_PIN_CNF_SENSE_Disabled << GPIO_PIN_CNF_SENSE_Pos)
41 | (GPIO_PIN_CNF_DRIVE_S0S1 << GPIO_PIN_CNF_DRIVE_Pos)
42 | (GPIO_PIN_CNF_INPUT_Connect << GPIO_PIN_CNF_INPUT_Pos)
43 | (GPIO_PIN_CNF_DIR_Output << GPIO_PIN_CNF_DIR_Pos));
54 constexpr uint32_t
PIN_CNF_PWRUP = ((GPIO_PIN_CNF_SENSE_Disabled << GPIO_PIN_CNF_SENSE_Pos)
55 | (GPIO_PIN_CNF_DRIVE_S0S1 << GPIO_PIN_CNF_DRIVE_Pos)
56 | (GPIO_PIN_CNF_INPUT_Disconnect << GPIO_PIN_CNF_INPUT_Pos)
57 | (GPIO_PIN_CNF_DIR_Input << GPIO_PIN_CNF_DIR_Pos));
60 constexpr uint32_t
PIN_CNF_PULLUP = (GPIO_PIN_CNF_PULL_Pullup << GPIO_PIN_CNF_PULL_Pos);
63 constexpr uint32_t
PIN_CNF_PULLDOWN = (GPIO_PIN_CNF_PULL_Pulldown << GPIO_PIN_CNF_PULL_Pos);
70 | (GPIO_PIN_CNF_SENSE_Low << GPIO_PIN_CNF_SENSE_Pos));
83 | (GPIO_PIN_CNF_SENSE_High << GPIO_PIN_CNF_SENSE_Pos));
148 constexpr
static uint8_t
psel = (PSEL - GPIO_Instance::begin_psel);
151 constexpr
static uint8_t
gpio_instance = GPIO_Instance::peripheral.INSTANCE;
172 instr_psel (
const instr_psel&) =
delete;
173 instr_psel& operator= (
const instr_psel&) =
delete;
174 instr_psel (instr_psel&&) =
delete;
175 instr_psel& operator= (instr_psel&&) =
delete;
225 void set (
bool asserted)
const 257 template <
typename INSTR_P
SEL>
261 using instr_psel_type = INSTR_PSEL;
267 instance.enable(start_set);
296 void set (
bool asserted)
const 298 instance.set(asserted);
307 const instr_psel_type& instance;
329 template <
typename INSTR_P
SEL>
330 instr_psel_scoped<INSTR_PSEL>
332 bool start_set =
true)
334 return {instance, start_set};
577 template <
bool ACTIVE_HIGH = false>
581 static constexpr
bool active_high = ACTIVE_HIGH;
636 return active_high == pin.
is_set();
642 return active_high ? pin.
set() : pin.
clear();
648 return active_high ? pin.
clear() : pin.
set();
713 unsigned int input = GPIO_PIN_CNF_INPUT_Disconnect,
714 unsigned int pull = GPIO_PIN_CNF_PULL_Disabled,
715 unsigned int drive = GPIO_PIN_CNF_DRIVE_S0S1,
716 unsigned int sense = GPIO_PIN_CNF_SENSE_Disabled)
718 return (GPIO_PIN_CNF_DIR_Msk & (dir << GPIO_PIN_CNF_DIR_Pos))
719 | (GPIO_PIN_CNF_INPUT_Msk & (input << GPIO_PIN_CNF_INPUT_Pos))
720 | (GPIO_PIN_CNF_PULL_Msk & (input << GPIO_PIN_CNF_PULL_Pos))
721 | (GPIO_PIN_CNF_DRIVE_Msk & (input << GPIO_PIN_CNF_DRIVE_Pos))
722 | (GPIO_PIN_CNF_SENSE_Msk & (input << GPIO_PIN_CNF_SENSE_Pos));
733 template <
typename mutex_type = null_mutex>
739 const uint32_t pin_cnf = nrf5::GPIO->PIN_CNF[psel];
740 nrf5::GPIO->PIN_CNF[psel] = pin_cnf & ~GPIO_PIN_CNF_SENSE_Msk;
781 bool assume_change =
false);
constexpr uint32_t PIN_CNF_RDWR
GPIO pin configuration for input and output.
Definition: gpio.hpp:40
virtual void clear()
Set the pin to drive the output low.
Definition: gpio.hpp:460
constexpr uint32_t PIN_CNF_PULLUP
Addition to no-pull GPIO pin configuration to pull up.
Definition: gpio.hpp:60
unsigned int update_sense_bi(unsigned int psel, bool assume_change=false)
Function to set the SENSE field of a GPIO pin configuration to detect a change in the input signal.
Instrumentation through toggling GPIOs.
Definition: gpio.hpp:130
scoped_assert make_scoped() const
Construct an RAII object that asserts the signal while it exists.
Definition: gpio.hpp:609
bool is_set() const override
Return true iff the pin is valid and is configured to drive the output high.
Definition: gpio.hpp:559
unsigned int configuration() const override
Return implementation-specific information about the pin configuration.
Definition: gpio.hpp:544
uint32_t configuration() const
Return the PIN_CNF entry for the pin, or zero if the reference is invalid.
Definition: gpio.hpp:397
constexpr static uint32_t bit
The bit mask corresponding to PSEL.
Definition: gpio.hpp:161
constexpr static uint8_t gpio_instance
The GPIO instance ordinal.
Definition: gpio.hpp:151
void assert() const
Forward to instr_psel::assert().
Definition: gpio.hpp:284
Class supporting a generic GPIO pin interface.
Definition: gpio.hpp:439
void enable(bool set=false) const
Enable the instrumentation functionality.
Definition: gpio.hpp:183
void set(bool asserted) const
Set the corresponding GPIO to a specific state.
Definition: gpio.hpp:225
void toggle() const
Forward to instr_psel::toggle().
Definition: gpio.hpp:302
bool asserted() const
Indicate whether the signal is currently asserted.
Definition: gpio.hpp:634
RAII class for scoped instrumentation.
Definition: gpio.hpp:258
Extension of generic_pin using an owned pin_reference.
Definition: gpio.hpp:507
uint8_t const global_psel
The pin selector index across all GPIO instances.
Definition: gpio.hpp:348
virtual bool valid() const
Indicate whether the pin is functional.
Definition: gpio.hpp:450
RAII instance used to assert the signal within a scope.
Definition: gpio.hpp:589
bool is_set() const
Return true iff the pin is valid and is configured to drive the output high.
Definition: gpio.hpp:417
bool valid() const override
Indicate whether the pin is functional.
Definition: gpio.hpp:524
void clear_sense(unsigned int psel)
Function to clear the SENSE field of a GPIO pin configuration.
Definition: gpio.hpp:735
void deassert() const
Set the corresponding GPIO to logic 0.
Definition: gpio.hpp:215
Capture information about an nRF5 peripheral instance.
Definition: core.hpp:165
Wrapper supporting GPIO control of output signals by explicit or scoped assertion.
Definition: gpio.hpp:578
constexpr uint32_t PIN_CNF_WRONLY
GPIO pin configuration for output only.
Definition: gpio.hpp:31
void deassert() const
Forward to instr_psel::deassert().
Definition: gpio.hpp:290
const uint8_t AUX
Auxiliary information relevant to the specific peripheral and type.
Definition: core.hpp:245
bool read() const override
Return the input signal observed at the pin, or zero if the reference is invalid.
Definition: gpio.hpp:554
virtual bool is_set() const
Return true iff the pin is valid and is configured to drive the output high.
Definition: gpio.hpp:500
void assert() const
Clear the associated GPIO to assert the active-low signal.
Definition: gpio.hpp:640
constexpr uint32_t PIN_CNF_PULLDOWN
Addition to no-pull GPIO pin configuration to pull down.
Definition: gpio.hpp:63
constexpr uint32_t PIN_CNF_ACTIVE_LOW_NOPULL
GPIO pin configuration to detect active-low signals without pulling to inactive.
Definition: gpio.hpp:69
constexpr uint32_t PIN_CNF_RDONLY
GPIO pin configuration for input only.
Definition: gpio.hpp:22
bool valid() const
Indicate whether the signal is configured with a valid pin reference.
Definition: gpio.hpp:628
uint8_t const local_psel
The pin selector index within peripheral.
Definition: gpio.hpp:351
static constexpr int instance_for_psel(int psel)
Determine the GPIO instance associated with a given pin selector.
Definition: gpio.hpp:95
gpio_pin(int psel)
Construct the instance.
Definition: gpio.hpp:514
const pin_reference & implementation() const
Access the underlying pin_reference instance.
Definition: gpio.hpp:519
constexpr static nrf5::GPIO_Type gpio
The GPIO instance that provides access to #PSEL.
Definition: gpio.hpp:154
A traits type identifying GPIO peripheral instances.
Definition: core.hpp:260
virtual bool read() const
Return the input signal observed at the pin, or zero if the reference is invalid.
Definition: gpio.hpp:493
void deassert() const
Set the associated GPIO to deassert the active-low signal.
Definition: gpio.hpp:646
constexpr uint32_t PIN_CNF_ACTIVE_HIGH
GPIO pin configuration to detect active-low signals with pull to inactive.
Definition: gpio.hpp:89
void enable(unsigned int aux=0) const
Configure the associated GPIO to control the signal output.
Definition: gpio.hpp:656
void configure(unsigned int pin_cnf) override
Set the PIN_CNF entry for the pin if the reference is valid.
Definition: gpio.hpp:549
void set() override
Set the pin to drive the output high.
Definition: gpio.hpp:529
void disable() const
Configure the associated GPIO to its power-up (non-controlling) state.
Definition: gpio.hpp:662
constexpr uint32_t PIN_CNF_ACTIVE_LOW
GPIO pin configuration to detect active-low signals with pull to inactive.
Definition: gpio.hpp:76
constexpr static uint8_t psel
Index for the PSEL within its GPIO instance.
Definition: gpio.hpp:148
void assert() const
Set the corresponding GPIO to logic 1.
Definition: gpio.hpp:207
constexpr static int global_psel
Index for the PSEL within all GPIO peripherals on the device.
Definition: gpio.hpp:145
void toggle() const
Toggle the pin drive state.
Definition: gpio.hpp:386
active_signal(generic_pin &pin)
Construct the helper for an active-low signal.
Definition: gpio.hpp:621
Primary header for nrfcxx implementation dependencies.
virtual void set()
Set the pin to drive the output high.
Definition: gpio.hpp:456
void disable() const
Disable the instrumentation functionality.
Definition: gpio.hpp:199
void set() const
Set the pin to drive the output high.
Definition: gpio.hpp:374
uint32_t const local_bit
A mask isolating the local_psel bit within the value space of peripheral.
Definition: gpio.hpp:355
constexpr uint32_t PIN_CNF_ACTIVE_HIGH_NOPULL
GPIO pin configuration to detect active-high signals without pulling to inactive.
Definition: gpio.hpp:82
virtual void toggle()
Toggle the pin drive state.
Definition: gpio.hpp:464
constexpr uint32_t PIN_CNF_PWRUP
GPIO pin configuration at power-up.
Definition: gpio.hpp:54
bool read() const
Return the input signal observed at the pin, or zero if the reference is invalid.
Definition: gpio.hpp:410
constexpr static bool psel_valid
Valid GPIOs are non-negative values that are among the pins supported by the instance.
Definition: gpio.hpp:158
void toggle() const
Invert the state of the corresponding GPIO.
Definition: gpio.hpp:237
void clear() const
Set the pin to drive the output low.
Definition: gpio.hpp:380
void clear() override
Set the pin to drive the output low.
Definition: gpio.hpp:534
void set(bool asserted) const
Forward to instr_psel::set().
Definition: gpio.hpp:296
void toggle() override
Toggle the pin drive state.
Definition: gpio.hpp:539
instr_psel_scoped< INSTR_PSEL > make_scoped_instr(const INSTR_PSEL &instance, bool start_set=true)
Create an RAII-style object that instruments a code block.
Definition: gpio.hpp:331
Generalized reference to a GPIO pin using a global psel ordinal.
Definition: gpio.hpp:344
constexpr uint32_t pin_config(unsigned int dir=GPIO_PIN_CNF_DIR_Input, unsigned int input=GPIO_PIN_CNF_INPUT_Disconnect, unsigned int pull=GPIO_PIN_CNF_PULL_Disabled, unsigned int drive=GPIO_PIN_CNF_DRIVE_S0S1, unsigned int sense=GPIO_PIN_CNF_SENSE_Disabled)
Helper to build up a GPIO PIN_CNF.
Definition: gpio.hpp:712
static pin_reference create(int psel)
Construct the instance for the given global ordinal GPIO pin.
const nrf5::GPIO_Type & peripheral
Reference to a valid GPIO peripheral wrapper.
Definition: gpio.hpp:360
Primary namespace for nrfcxx functionality.
Definition: clock.hpp:17
void configure(uint32_t pin_cnf) const
Set the PIN_CNF entry for the pin.
Definition: gpio.hpp:403
virtual unsigned int configuration() const
Return implementation-specific information about the pin configuration.
Definition: gpio.hpp:486
virtual void configure(unsigned int pin_cnf)
Set the PIN_CNF entry for the pin if the reference is valid.
Definition: gpio.hpp:480