nrfcxx  0.1.0
C++-17 Framework for Nordic nRF5 Devices
Data Structures | Typedefs | Functions | Variables
nrfcxx::gpio Namespace Reference

Abstractions and constants around GPIO capability. More...

Data Structures

class  active_signal
 Wrapper supporting GPIO control of output signals by explicit or scoped assertion. More...
 
class  generic_pin
 Class supporting a generic GPIO pin interface. More...
 
class  gpio_pin
 Extension of generic_pin using an owned pin_reference. More...
 
class  instr_psel
 Instrumentation through toggling GPIOs. More...
 
class  instr_psel_scoped
 RAII class for scoped instrumentation. More...
 
class  pin_reference
 Generalized reference to a GPIO pin using a global psel ordinal. More...
 

Typedefs

using active_low = active_signal< false >
 Alias type used for CSn, RESETn, and other active low output signals.
 

Functions

static constexpr int instance_for_psel (int psel)
 Determine the GPIO instance associated with a given pin selector. More...
 
template<typename INSTR_PSEL >
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. More...
 
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. More...
 
template<typename mutex_type = null_mutex>
void clear_sense (unsigned int psel)
 Function to clear the SENSE field of a GPIO pin configuration. More...
 
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. More...
 

Variables

constexpr uint32_t PIN_CNF_RDONLY
 GPIO pin configuration for input only. More...
 
constexpr uint32_t PIN_CNF_WRONLY
 GPIO pin configuration for output only. More...
 
constexpr uint32_t PIN_CNF_RDWR
 GPIO pin configuration for input and output. More...
 
constexpr uint32_t PIN_CNF_PWRUP
 GPIO pin configuration at power-up. More...
 
constexpr uint32_t PIN_CNF_PULLUP = (GPIO_PIN_CNF_PULL_Pullup << GPIO_PIN_CNF_PULL_Pos)
 Addition to no-pull GPIO pin configuration to pull up.
 
constexpr uint32_t PIN_CNF_PULLDOWN = (GPIO_PIN_CNF_PULL_Pulldown << GPIO_PIN_CNF_PULL_Pos)
 Addition to no-pull GPIO pin configuration to pull down.
 
constexpr uint32_t PIN_CNF_ACTIVE_LOW_NOPULL
 GPIO pin configuration to detect active-low signals without pulling to inactive. More...
 
constexpr uint32_t PIN_CNF_ACTIVE_LOW = (PIN_CNF_ACTIVE_LOW_NOPULL | PIN_CNF_PULLUP)
 GPIO pin configuration to detect active-low signals with pull to inactive. More...
 
constexpr uint32_t PIN_CNF_ACTIVE_HIGH_NOPULL
 GPIO pin configuration to detect active-high signals without pulling to inactive. More...
 
constexpr uint32_t PIN_CNF_ACTIVE_HIGH = (PIN_CNF_ACTIVE_HIGH_NOPULL | PIN_CNF_PULLDOWN)
 GPIO pin configuration to detect active-low signals with pull to inactive. More...
 

Detailed Description

Abstractions and constants around GPIO capability.

Function Documentation

◆ clear_sense()

template<typename mutex_type = null_mutex>
void nrfcxx::gpio::clear_sense ( unsigned int  psel)

Function to clear the SENSE field of a GPIO pin configuration.

Template Parameters
mutex_typethe mutex type required to ensure the pin configuration is not changed while the clear operation is in progress.
See also
pin_config()

◆ instance_for_psel()

static constexpr int nrfcxx::gpio::instance_for_psel ( int  psel)
staticconstexpr

Determine the GPIO instance associated with a given pin selector.

Returns
the instance number starting from zero, or negative if the selector is not supported on the device.

◆ make_scoped_instr()

template<typename INSTR_PSEL >
instr_psel_scoped<INSTR_PSEL> nrfcxx::gpio::make_scoped_instr ( const INSTR_PSEL &  instance,
bool  start_set = true 
)

Create an RAII-style object that instruments a code block.

Use this in cases where there's no need for cross-block instrumentation, especially in cases where there's no convenient code site where instrumentation instances can be enabled.

{
    auto scope = nrfcxx::gpio::make_scoped_instr(scope1);
    // region marked by scope1 high
}
Template Parameters
INSTR_PSELthe type of the instrumentation instance. Generally this will be inferred.
Parameters
start_setwhether the instrumentation signal should be set on construction (default true) or left unset (false). Note that the default here is not the same as in instr_psel::enable().

◆ pin_config()

constexpr uint32_t nrfcxx::gpio::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 
)
inlineconstexpr

Helper to build up a GPIO PIN_CNF.

Parameters
dirone of:
  • GPIO_PIN_CNF_DIR_Input (default)
  • GPIO_PIN_CNF_DIR_Output
inputone of:
  • GPIO_PIN_CNF_INPUT_Connect
  • GPIO_PIN_CNF_INPUT_Disconnect (default)
pullone of:
  • GPIO_PIN_CNF_PULL_Disabled (default)
  • GPIO_PIN_CNF_PULL_Pulldown
  • GPIO_PIN_CNF_PULL_Pullup
driveone of:
  • GPIO_PIN_CNF_DRIVE_S0S1 (default)
  • GPIO_PIN_CNF_DRIVE_H0S1
  • GPIO_PIN_CNF_DRIVE_S0H1
  • GPIO_PIN_CNF_DRIVE_H0S1
  • GPIO_PIN_CNF_DRIVE_D0S1
  • GPIO_PIN_CNF_DRIVE_S0D1
  • GPIO_PIN_CNF_DRIVE_H0D1
senseone of:
  • GPIO_PIN_CNF_SENSE_Disabled (default)
  • GPIO_PIN_CNF_SENSE_High
  • GPIO_PIN_CNF_SENSE_Low
See also
PIN_CNF_ACTIVE_HIGH
PIN_CNF_ACTIVE_HIGH_NOPULL
PIN_CNF_ACTIVE_LOW
PIN_CNF_ACTIVE_LOW_NOPULL
PIN_CNF_PWRUP
PIN_CNF_RDONLY
PIN_CNF_RDWR
PIN_CNF_WRONLY

◆ update_sense_bi()

unsigned int nrfcxx::gpio::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.

This function reads the IN signal of a GPIO and configures its SENSE field to detect a change from that state. The function ensures that the IN signal state after pin configuration is complete matches the original state.

The as-configured state of the pin is specified in the low bit of the return value, while bits 1 and higher count the number of times the state changed during the configuration. For example, the value 3 indicates that the final observed state of the pin was set; on completion the GPIO was configured to emit a SENSE event on a falling edge (transition to clear), and that at least one state change occurred while setting the pin configuration.

The caller is responsible for determining what, if anything, should be recorded about state changes observed during configuration.

Note
This function must be invoked in an approriate mutex type context to ensure the pin configuration is not changed and DETECT events are not processed while the configuration operation is in progress. If not invoked within a mutex region periph::GPIOTE::mutex_type might be appropriate.
Parameters
pselthe pin index for which sense is to be updated
assume_changeif false and the sense matches the input signal the return value will indicate that no changes occurred. If true and the sense matches the input signal the return value will indicate that two changes occurred. If the sense does not match the input signal at least one change will occur.
Returns
an unsigned integer value as described above.

Variable Documentation

◆ PIN_CNF_ACTIVE_HIGH

constexpr uint32_t nrfcxx::gpio::PIN_CNF_ACTIVE_HIGH = (PIN_CNF_ACTIVE_HIGH_NOPULL | PIN_CNF_PULLDOWN)
constexpr

GPIO pin configuration to detect active-low signals with pull to inactive.

Use this with instances.

◆ PIN_CNF_ACTIVE_HIGH_NOPULL

constexpr uint32_t nrfcxx::gpio::PIN_CNF_ACTIVE_HIGH_NOPULL
constexpr
Initial value:
| (GPIO_PIN_CNF_SENSE_High << GPIO_PIN_CNF_SENSE_Pos))

GPIO pin configuration to detect active-high signals without pulling to inactive.

Use this with instances.

◆ PIN_CNF_ACTIVE_LOW

constexpr uint32_t nrfcxx::gpio::PIN_CNF_ACTIVE_LOW = (PIN_CNF_ACTIVE_LOW_NOPULL | PIN_CNF_PULLUP)
constexpr

GPIO pin configuration to detect active-low signals with pull to inactive.

Use this with instances.

◆ PIN_CNF_ACTIVE_LOW_NOPULL

constexpr uint32_t nrfcxx::gpio::PIN_CNF_ACTIVE_LOW_NOPULL
constexpr
Initial value:
| (GPIO_PIN_CNF_SENSE_Low << GPIO_PIN_CNF_SENSE_Pos))

GPIO pin configuration to detect active-low signals without pulling to inactive.

Use this with instances.

◆ PIN_CNF_PWRUP

constexpr uint32_t nrfcxx::gpio::PIN_CNF_PWRUP
constexpr
Initial value:
= ((GPIO_PIN_CNF_SENSE_Disabled << GPIO_PIN_CNF_SENSE_Pos)
| (GPIO_PIN_CNF_DRIVE_S0S1 << GPIO_PIN_CNF_DRIVE_Pos)
| (GPIO_PIN_CNF_INPUT_Disconnect << GPIO_PIN_CNF_INPUT_Pos)
| (GPIO_PIN_CNF_DIR_Input << GPIO_PIN_CNF_DIR_Pos))

GPIO pin configuration at power-up.

Use this to set the pin to what might be its lowest-power state. Note that the proper configuration for true low-power operation may depend on what's connected to the pin (e.g. current sink or voltage source).

Warning
The integer value of this configuration is not zero.

◆ PIN_CNF_RDONLY

constexpr uint32_t nrfcxx::gpio::PIN_CNF_RDONLY
constexpr
Initial value:
= ((GPIO_PIN_CNF_SENSE_Disabled << GPIO_PIN_CNF_SENSE_Pos)
| (GPIO_PIN_CNF_DRIVE_S0S1 << GPIO_PIN_CNF_DRIVE_Pos)
| (GPIO_PIN_CNF_INPUT_Connect << GPIO_PIN_CNF_INPUT_Pos)
| (GPIO_PIN_CNF_DIR_Input << GPIO_PIN_CNF_DIR_Pos))

GPIO pin configuration for input only.

The value allows any non-default configuration for SENSE, DRIVER, or PULL to be added without masking off bits.

◆ PIN_CNF_RDWR

constexpr uint32_t nrfcxx::gpio::PIN_CNF_RDWR
constexpr
Initial value:
= ((GPIO_PIN_CNF_SENSE_Disabled << GPIO_PIN_CNF_SENSE_Pos)
| (GPIO_PIN_CNF_DRIVE_S0S1 << GPIO_PIN_CNF_DRIVE_Pos)
| (GPIO_PIN_CNF_INPUT_Connect << GPIO_PIN_CNF_INPUT_Pos)
| (GPIO_PIN_CNF_DIR_Output << GPIO_PIN_CNF_DIR_Pos))

GPIO pin configuration for input and output.

The value allows any non-default configuration for SENSE, DRIVER, or PULL to be added without masking off bits.

◆ PIN_CNF_WRONLY

constexpr uint32_t nrfcxx::gpio::PIN_CNF_WRONLY
constexpr
Initial value:
= ((GPIO_PIN_CNF_SENSE_Disabled << GPIO_PIN_CNF_SENSE_Pos)
| (GPIO_PIN_CNF_DRIVE_S0S1 << GPIO_PIN_CNF_DRIVE_Pos)
| (GPIO_PIN_CNF_INPUT_Disconnect << GPIO_PIN_CNF_INPUT_Pos)
| (GPIO_PIN_CNF_DIR_Output << GPIO_PIN_CNF_DIR_Pos))

GPIO pin configuration for output only.

The value allows any non-default configuration for SENSE, DRIVER, or PULL to be added without masking off bits.

nrfcxx::gpio::PIN_CNF_RDONLY
constexpr uint32_t PIN_CNF_RDONLY
GPIO pin configuration for input only.
Definition: gpio.hpp:22