R1 code for micro:bit based train controller code, requires second micro:bit running rx code to operate - see https://meanderingpi.wordpress.com/ for more information
Fork of nrf51-sdk by
GPIO abstraction
GPIO pin abstraction and port abstraction for reading and writing byte-wise to GPIO ports. More...
Enumerations | |
enum | nrf_gpio_port_select_t { NRF_GPIO_PORT_SELECT_PORT0 = 0, NRF_GPIO_PORT_SELECT_PORT1, NRF_GPIO_PORT_SELECT_PORT2, NRF_GPIO_PORT_SELECT_PORT3 } |
Enumerator used for selecting between port 0 - 3. More... | |
enum | nrf_gpio_port_dir_t { NRF_GPIO_PORT_DIR_OUTPUT, NRF_GPIO_PORT_DIR_INPUT } |
Enumerator used for setting the direction of a GPIO port. More... | |
enum | nrf_gpio_pin_dir_t { NRF_GPIO_PIN_DIR_INPUT = GPIO_PIN_CNF_DIR_Input, NRF_GPIO_PIN_DIR_OUTPUT = GPIO_PIN_CNF_DIR_Output } |
Pin direction definitions. More... | |
enum | nrf_gpio_pin_input_t { NRF_GPIO_PIN_INPUT_CONNECT = GPIO_PIN_CNF_INPUT_Connect, NRF_GPIO_PIN_INPUT_DISCONNECT = GPIO_PIN_CNF_INPUT_Disconnect } |
Connection of input buffer. More... | |
enum | nrf_gpio_pin_pull_t { NRF_GPIO_PIN_NOPULL = GPIO_PIN_CNF_PULL_Disabled, NRF_GPIO_PIN_PULLDOWN = GPIO_PIN_CNF_PULL_Pulldown, NRF_GPIO_PIN_PULLUP = GPIO_PIN_CNF_PULL_Pullup } |
Enumerator used for selecting the pin to be pulled down or up at the time of pin configuration. More... | |
enum | nrf_gpio_pin_drive_t { NRF_GPIO_PIN_S0S1 = GPIO_PIN_CNF_DRIVE_S0S1, NRF_GPIO_PIN_H0S1 = GPIO_PIN_CNF_DRIVE_H0S1, NRF_GPIO_PIN_S0H1 = GPIO_PIN_CNF_DRIVE_S0H1, NRF_GPIO_PIN_H0H1 = GPIO_PIN_CNF_DRIVE_H0H1, NRF_GPIO_PIN_D0S1 = GPIO_PIN_CNF_DRIVE_D0S1, NRF_GPIO_PIN_D0H1 = GPIO_PIN_CNF_DRIVE_D0H1, NRF_GPIO_PIN_S0D1 = GPIO_PIN_CNF_DRIVE_S0D1, NRF_GPIO_PIN_H0D1 = GPIO_PIN_CNF_DRIVE_H0D1 } |
Enumerator used for selecting output drive mode. More... | |
enum | nrf_gpio_pin_sense_t { NRF_GPIO_PIN_NOSENSE = GPIO_PIN_CNF_SENSE_Disabled, NRF_GPIO_PIN_SENSE_LOW = GPIO_PIN_CNF_SENSE_Low, NRF_GPIO_PIN_SENSE_HIGH = GPIO_PIN_CNF_SENSE_High } |
Enumerator used for selecting the pin to sense high or low level on the pin input. More... | |
Functions | |
__STATIC_INLINE void | nrf_gpio_range_cfg_output (uint32_t pin_range_start, uint32_t pin_range_end) |
Function for configuring the GPIO pin range as outputs with normal drive strength. | |
__STATIC_INLINE void | nrf_gpio_range_cfg_input (uint32_t pin_range_start, uint32_t pin_range_end, nrf_gpio_pin_pull_t pull_config) |
Function for configuring the GPIO pin range as inputs with given initial value set, hiding inner details. | |
__STATIC_INLINE void | nrf_gpio_cfg (uint32_t pin_number, nrf_gpio_pin_dir_t dir, nrf_gpio_pin_input_t input, nrf_gpio_pin_pull_t pull, nrf_gpio_pin_drive_t drive, nrf_gpio_pin_sense_t sense) |
Pin configuration function. | |
__STATIC_INLINE void | nrf_gpio_cfg_output (uint32_t pin_number) |
Function for configuring the given GPIO pin number as output with given initial value set, hiding inner details. | |
__STATIC_INLINE void | nrf_gpio_cfg_input (uint32_t pin_number, nrf_gpio_pin_pull_t pull_config) |
Function for configuring the given GPIO pin number as input with given initial value set, hiding inner details. | |
__STATIC_INLINE void | nrf_gpio_cfg_default (uint32_t pin_number) |
Function for reseting pin configuration to its default state. | |
__STATIC_INLINE void | nrf_gpio_cfg_watcher (uint32_t pin_number) |
Function for configuring the given GPIO pin number as a watcher. | |
__STATIC_INLINE void | nrf_gpio_input_disconnect (uint32_t pin_number) |
Function for disconnecting input for the given GPIO. | |
__STATIC_INLINE void | nrf_gpio_cfg_sense_input (uint32_t pin_number, nrf_gpio_pin_pull_t pull_config, nrf_gpio_pin_sense_t sense_config) |
Function for configuring the given GPIO pin number as input with given initial value set, hiding inner details. | |
__STATIC_INLINE void | nrf_gpio_cfg_sense_set (uint32_t pin_number, nrf_gpio_pin_sense_t sense_config) |
Function for configuring sense level for the given GPIO. | |
__STATIC_INLINE void | nrf_gpio_pin_dir_set (uint32_t pin_number, nrf_gpio_pin_dir_t direction) |
Function for setting the direction for a GPIO pin. | |
__STATIC_INLINE void | nrf_gpio_pin_set (uint32_t pin_number) |
Function for setting a GPIO pin. | |
__STATIC_INLINE void | nrf_gpio_pins_set (uint32_t pin_mask) |
Function for setting GPIO pins. | |
__STATIC_INLINE void | nrf_gpio_pin_clear (uint32_t pin_number) |
Function for clearing a GPIO pin. | |
__STATIC_INLINE void | nrf_gpio_pins_clear (uint32_t pin_mask) |
Function for clearing GPIO pins. | |
__STATIC_INLINE void | nrf_gpio_pin_toggle (uint32_t pin_number) |
Function for toggling a GPIO pin. | |
__STATIC_INLINE void | nrf_gpio_pin_write (uint32_t pin_number, uint32_t value) |
Function for writing a value to a GPIO pin. | |
__STATIC_INLINE uint32_t | nrf_gpio_pin_read (uint32_t pin_number) |
Function for reading the input level of a GPIO pin. | |
__STATIC_INLINE uint32_t | nrf_gpio_pins_read (void) |
Function for reading the input level of all GPIO pins. | |
__STATIC_INLINE nrf_gpio_pin_sense_t | nrf_gpio_pin_sense_get (uint32_t pin_number) |
Function for reading the sense configuration of a GPIO pin. | |
__STATIC_INLINE void | nrf_gpio_word_byte_write (volatile uint32_t *word_address, uint8_t byte_no, uint8_t value) |
Generic function for writing a single byte of a 32 bit word at a given address. | |
__STATIC_INLINE uint8_t | nrf_gpio_word_byte_read (const volatile uint32_t *word_address, uint8_t byte_no) |
Generic function for reading a single byte of a 32 bit word at a given address. | |
__STATIC_INLINE void | nrf_gpio_port_dir_set (nrf_gpio_port_select_t port, nrf_gpio_port_dir_t dir) |
Function for setting the direction of a port. | |
__STATIC_INLINE uint8_t | nrf_gpio_port_read (nrf_gpio_port_select_t port) |
Function for reading a GPIO port. | |
__STATIC_INLINE void | nrf_gpio_port_write (nrf_gpio_port_select_t port, uint8_t value) |
Function for writing to a GPIO port. | |
__STATIC_INLINE void | nrf_gpio_port_set (nrf_gpio_port_select_t port, uint8_t set_mask) |
Function for setting individual pins on GPIO port. | |
__STATIC_INLINE void | nrf_gpio_port_clear (nrf_gpio_port_select_t port, uint8_t clr_mask) |
Function for clearing individual pins on GPIO port. |
Detailed Description
GPIO pin abstraction and port abstraction for reading and writing byte-wise to GPIO ports.
Here, the GPIO ports are defined as follows:
- Port 0 -> pin 0-7
- Port 1 -> pin 8-15
- Port 2 -> pin 16-23
- Port 3 -> pin 24-31
Enumeration Type Documentation
enum nrf_gpio_pin_dir_t |
Pin direction definitions.
Definition at line 76 of file nrf_gpio.h.
enum nrf_gpio_pin_drive_t |
Enumerator used for selecting output drive mode.
- Enumerator:
Definition at line 104 of file nrf_gpio.h.
enum nrf_gpio_pin_input_t |
Connection of input buffer.
- Enumerator:
NRF_GPIO_PIN_INPUT_CONNECT Connect input buffer.
NRF_GPIO_PIN_INPUT_DISCONNECT Disconnect input buffer.
Definition at line 85 of file nrf_gpio.h.
enum nrf_gpio_pin_pull_t |
Enumerator used for selecting the pin to be pulled down or up at the time of pin configuration.
- Enumerator:
NRF_GPIO_PIN_NOPULL Pin pullup resistor disabled.
NRF_GPIO_PIN_PULLDOWN Pin pulldown resistor enabled.
NRF_GPIO_PIN_PULLUP Pin pullup resistor enabled.
Definition at line 94 of file nrf_gpio.h.
enum nrf_gpio_pin_sense_t |
Enumerator used for selecting the pin to sense high or low level on the pin input.
- Enumerator:
NRF_GPIO_PIN_NOSENSE Pin sense level disabled.
NRF_GPIO_PIN_SENSE_LOW Pin sense low level.
NRF_GPIO_PIN_SENSE_HIGH Pin sense high level.
Definition at line 119 of file nrf_gpio.h.
enum nrf_gpio_port_dir_t |
Enumerator used for setting the direction of a GPIO port.
Definition at line 67 of file nrf_gpio.h.
Enumerator used for selecting between port 0 - 3.
- Enumerator:
Definition at line 56 of file nrf_gpio.h.
Function Documentation
__STATIC_INLINE void nrf_gpio_cfg | ( | uint32_t | pin_number, |
nrf_gpio_pin_dir_t | dir, | ||
nrf_gpio_pin_input_t | input, | ||
nrf_gpio_pin_pull_t | pull, | ||
nrf_gpio_pin_drive_t | drive, | ||
nrf_gpio_pin_sense_t | sense | ||
) |
Pin configuration function.
The main pin configuration function. This function allows to set any aspect in PIN_CNF register.
- Parameters:
-
pin_number Specifies the pin number (allowed values 0-31). dir Pin direction input Connect or disconnect input buffer pull Pull configuration drive Drive configuration sense Pin sensing mechanism
Definition at line 460 of file nrf_gpio.h.
__STATIC_INLINE void nrf_gpio_cfg_default | ( | uint32_t | pin_number ) |
Function for reseting pin configuration to its default state.
- Parameters:
-
pin_number Specifies the pin number (allowed values 0-31).
Definition at line 497 of file nrf_gpio.h.
__STATIC_INLINE void nrf_gpio_cfg_input | ( | uint32_t | pin_number, |
nrf_gpio_pin_pull_t | pull_config | ||
) |
Function for configuring the given GPIO pin number as input with given initial value set, hiding inner details.
This function can be used to configure pin range as simple input with gate driving GPIO_PIN_CNF_DRIVE_S0S1 (normal cases).
- Parameters:
-
pin_number Specifies the pin number (allowed values 0-30). pull_config State of the pin range pull resistor (no pull, pulled down or pulled high).
- Note:
- Sense capability on the pin is disabled, and input is connected to buffer so that the GPIO->IN register is readable
Definition at line 486 of file nrf_gpio.h.
__STATIC_INLINE void nrf_gpio_cfg_output | ( | uint32_t | pin_number ) |
Function for configuring the given GPIO pin number as output with given initial value set, hiding inner details.
This function can be used to configure pin range as simple input with gate driving GPIO_PIN_CNF_DRIVE_S0S1 (normal cases).
- Parameters:
-
pin_number specifies the pin number (allowed values 0-31)
- Note:
- Sense capability on the pin is disabled, and input is disconnected from the buffer as the pins are configured as output.
Definition at line 475 of file nrf_gpio.h.
__STATIC_INLINE void nrf_gpio_cfg_sense_input | ( | uint32_t | pin_number, |
nrf_gpio_pin_pull_t | pull_config, | ||
nrf_gpio_pin_sense_t | sense_config | ||
) |
Function for configuring the given GPIO pin number as input with given initial value set, hiding inner details.
This function can be used to configure pin range as simple input with gate driving GPIO_PIN_CNF_DRIVE_S0S1 (normal cases). Sense capability on the pin is configurable, and input is connected to buffer so that the GPIO->IN register is readable.
- Parameters:
-
pin_number Specifies the pin number (allowed values 0-30). pull_config State of the pin pull resistor (no pull, pulled down or pulled high). sense_config Sense level of the pin (no sense, sense low or sense high).
Definition at line 522 of file nrf_gpio.h.
__STATIC_INLINE void nrf_gpio_cfg_sense_set | ( | uint32_t | pin_number, |
nrf_gpio_pin_sense_t | sense_config | ||
) |
Function for configuring sense level for the given GPIO.
- Parameters:
-
pin_number Specifies the pin number of gpio pin numbers to be configured (allowed values 0-30). sense_config Sense configuration.
Definition at line 533 of file nrf_gpio.h.
__STATIC_INLINE void nrf_gpio_cfg_watcher | ( | uint32_t | pin_number ) |
Function for configuring the given GPIO pin number as a watcher.
Only input is connected.
- Parameters:
-
pin_number Specifies the pin number (allowed values 0-31).
Definition at line 508 of file nrf_gpio.h.
__STATIC_INLINE void nrf_gpio_input_disconnect | ( | uint32_t | pin_number ) |
Function for disconnecting input for the given GPIO.
- Parameters:
-
pin_number Specifies the pin number (allowed values 0-31).
Definition at line 515 of file nrf_gpio.h.
__STATIC_INLINE void nrf_gpio_pin_clear | ( | uint32_t | pin_number ) |
Function for clearing a GPIO pin.
Note that the pin must be configured as an output for this function to have any effect.
- Parameters:
-
pin_number specifies the pin number [0:31] to clear.
Definition at line 569 of file nrf_gpio.h.
__STATIC_INLINE void nrf_gpio_pin_dir_set | ( | uint32_t | pin_number, |
nrf_gpio_pin_dir_t | direction | ||
) |
Function for setting the direction for a GPIO pin.
- Parameters:
-
pin_number specifies the pin number [0:31] for which to set the direction. direction specifies the direction
Definition at line 541 of file nrf_gpio.h.
__STATIC_INLINE uint32_t nrf_gpio_pin_read | ( | uint32_t | pin_number ) |
Function for reading the input level of a GPIO pin.
Note that the pin must have input connected for the value returned from this function to be valid.
- Parameters:
-
pin_number specifies the pin number [0:31] to read.
- Returns:
- Return values:
-
0 if the pin input level is low. 1 if the pin input level is high. > 1 should never occur.
Definition at line 608 of file nrf_gpio.h.
__STATIC_INLINE nrf_gpio_pin_sense_t nrf_gpio_pin_sense_get | ( | uint32_t | pin_number ) |
Function for reading the sense configuration of a GPIO pin.
- Parameters:
-
pin_number specifies the pin number [0:31] to read.
- Return values:
-
Sense configuration
Definition at line 618 of file nrf_gpio.h.
__STATIC_INLINE void nrf_gpio_pin_set | ( | uint32_t | pin_number ) |
Function for setting a GPIO pin.
Note that the pin must be configured as an output for this function to have any effect.
- Parameters:
-
pin_number specifies the pin number [0:31] to set.
Definition at line 559 of file nrf_gpio.h.
__STATIC_INLINE void nrf_gpio_pin_toggle | ( | uint32_t | pin_number ) |
Function for toggling a GPIO pin.
Note that the pin must be configured as an output for this function to have any effect.
- Parameters:
-
pin_number specifies the pin number [0:31] to toggle.
Definition at line 579 of file nrf_gpio.h.
__STATIC_INLINE void nrf_gpio_pin_write | ( | uint32_t | pin_number, |
uint32_t | value | ||
) |
Function for writing a value to a GPIO pin.
Note that the pin must be configured as an output for this function to have any effect.
- Parameters:
-
pin_number specifies the pin number [0:31] to write. value specifies the value to be written to the pin. - 0 clears the pin
- >=1 sets the pin.
Definition at line 596 of file nrf_gpio.h.
__STATIC_INLINE void nrf_gpio_pins_clear | ( | uint32_t | pin_mask ) |
Function for clearing GPIO pins.
Note that pins must be configured as an output for this function to have any effect.
- Parameters:
-
pin_mask Specifies the pins to clear. set.
Definition at line 574 of file nrf_gpio.h.
__STATIC_INLINE uint32_t nrf_gpio_pins_read | ( | void | ) |
Function for reading the input level of all GPIO pins.
Note that the pin must have input connected for the value returned from this function to be valid.
- Return values:
-
Status of input of all pins
Definition at line 613 of file nrf_gpio.h.
__STATIC_INLINE void nrf_gpio_pins_set | ( | uint32_t | pin_mask ) |
Function for setting GPIO pins.
Note that pins must be configured as an output for this function to have any effect.
- Parameters:
-
pin_mask Specifies the pins to set. set.
Definition at line 564 of file nrf_gpio.h.
__STATIC_INLINE void nrf_gpio_port_clear | ( | nrf_gpio_port_select_t | port, |
uint8_t | clr_mask | ||
) |
Function for clearing individual pins on GPIO port.
- Parameters:
-
port is the port for which to clear the pins. clr_mask is a mask specifying which pins to clear. A bit set to 1 indicates that the corresponding port pin shall be cleared.
- See also:
- nrf_gpio_port_dir_set()
Definition at line 660 of file nrf_gpio.h.
__STATIC_INLINE void nrf_gpio_port_dir_set | ( | nrf_gpio_port_select_t | port, |
nrf_gpio_port_dir_t | dir | ||
) |
Function for setting the direction of a port.
- Parameters:
-
port is the port for which to set the direction. dir direction to be set for this port.
Definition at line 633 of file nrf_gpio.h.
__STATIC_INLINE uint8_t nrf_gpio_port_read | ( | nrf_gpio_port_select_t | port ) |
Function for reading a GPIO port.
- Parameters:
-
port is the port to read.
- Returns:
- the input value on this port.
Definition at line 645 of file nrf_gpio.h.
__STATIC_INLINE void nrf_gpio_port_set | ( | nrf_gpio_port_select_t | port, |
uint8_t | set_mask | ||
) |
Function for setting individual pins on GPIO port.
- Parameters:
-
port is the port for which to set the pins. set_mask is a mask specifying which pins to set. A bit set to 1 indicates that the corresponding port pin shall be set.
- See also:
- nrf_gpio_port_dir_set()
Definition at line 655 of file nrf_gpio.h.
__STATIC_INLINE void nrf_gpio_port_write | ( | nrf_gpio_port_select_t | port, |
uint8_t | value | ||
) |
Function for writing to a GPIO port.
- Parameters:
-
port is the port to write. value is the value to write to this port.
- See also:
- nrf_gpio_port_dir_set()
Definition at line 650 of file nrf_gpio.h.
__STATIC_INLINE void nrf_gpio_range_cfg_input | ( | uint32_t | pin_range_start, |
uint32_t | pin_range_end, | ||
nrf_gpio_pin_pull_t | pull_config | ||
) |
Function for configuring the GPIO pin range as inputs with given initial value set, hiding inner details.
This function can be used to configure pin range as simple input.
- Parameters:
-
pin_range_start specifies the start number (inclusive) in the range of pin numbers to be configured (allowed values 0-30) pin_range_end specifies the end number (inclusive) in the range of pin numbers to be configured (allowed values 0-30) pull_config State of the pin range pull resistor (no pull, pulled down or pulled high)
- Note:
- For configuring only one pin as input use nrf_gpio_cfg_input Sense capability on the pin is disabled, and input is connected to buffer so that the GPIO->IN register is readable
Definition at line 451 of file nrf_gpio.h.
__STATIC_INLINE void nrf_gpio_range_cfg_output | ( | uint32_t | pin_range_start, |
uint32_t | pin_range_end | ||
) |
Function for configuring the GPIO pin range as outputs with normal drive strength.
This function can be used to configure pin range as simple output with gate driving GPIO_PIN_CNF_DRIVE_S0S1 (normal cases).
- Parameters:
-
pin_range_start specifies the start number (inclusive) in the range of pin numbers to be configured (allowed values 0-30) pin_range_end specifies the end number (inclusive) in the range of pin numbers to be configured (allowed values 0-30)
- Note:
- For configuring only one pin as output use nrf_gpio_cfg_output Sense capability on the pin is disabled, and input is disconnected from the buffer as the pins are configured as output.
Definition at line 442 of file nrf_gpio.h.
__STATIC_INLINE uint8_t nrf_gpio_word_byte_read | ( | const volatile uint32_t * | word_address, |
uint8_t | byte_no | ||
) |
Generic function for reading a single byte of a 32 bit word at a given address.
This function should not be called from outside the nrf_gpio abstraction layer.
- Parameters:
-
word_address is the address of the word to be read. byte_no is the byte number (0-3) of the word to be read.
- Returns:
- byte "byte_no" of word at address "word_address".
Definition at line 628 of file nrf_gpio.h.
__STATIC_INLINE void nrf_gpio_word_byte_write | ( | volatile uint32_t * | word_address, |
uint8_t | byte_no, | ||
uint8_t | value | ||
) |
Generic function for writing a single byte of a 32 bit word at a given address.
This function should not be called from outside the nrf_gpio abstraction layer.
- Parameters:
-
word_address is the address of the word to be written. byte_no is the word byte number (0-3) to be written. value is the value to be written to byte "byte_no" of word at address "word_address"
Definition at line 623 of file nrf_gpio.h.
Generated on Tue Jul 12 2022 19:00:13 by 1.7.2