![]() |
nRF5 SDK
v16.0.0
|
| Choose documentation: | nRF5 SDK | S112 SoftDevice API | S113 SoftDevice API | S132 SoftDevice API | S140 SoftDevice API | S212 SoftDevice API | S312 SoftDevice API | S332 SoftDevice API | S340 SoftDevice API |
Module for configuring and using PCAL6408A GPIO expander. More...
Macros | |
| #define | PCAL6408A_BASE_ADDRESS_FIRST 0x20u |
| First possible expander address. | |
| #define | PCAL6408A_BASE_ADDRESS_SECOND 0x21u |
| Second possible expander address. | |
| #define | PCAL6408A_INSTANCES_DEF_START(pcal6408a_inst_name, instance_count) static pcal6408a_instance_t pcal6408a_inst_name[instance_count] |
| Macro that defines expander module. More... | |
| #define | PIN_NUM_CONVERT(pin_num, instance_num) (pin_num + instance_num * PCAL6408A_INNER_PIN_COUNT) |
| Macro that converts absolute pin number to pin number dependent on number of expander. More... | |
Enumerations | |
| enum | pcal6408a_registers_t { PCAL6408A_REG_INPUT_PORT = 0x00, PCAL6408A_REG_OUTPUT_PORT = 0x01, PCAL6408A_REG_POLARITY_INVERSION = 0x02, PCAL6408A_REG_CONFIGURATION = 0x03, PCAL6408A_REG_OUTPUT_DRIVE_STRENGTH_0 = 0x40, PCAL6408A_REG_OUTPUT_DRIVE_STRENGTH_1 = 0x41, PCAL6408A_REG_INPUT_LATCH = 0x42, PCAL6408A_REG_PULL_UP_DOWN_ENABLE = 0x43, PCAL6408A_REG_PULL_UP_DOWN_SELECT = 0x44, PCAL6408A_REG_INTERRUPT_MASK = 0x45, PCAL6408A_REG_INTERRUPT_STATUS = 0x46, PCAL6408A_REG_OUTPUT_PORT_CONFIGURATION = 0x4F } |
| Device registers. | |
| enum | pcal6408a_pin_dir_t { PCAL6408A_PIN_DIR_OUTPUT, PCAL6408A_PIN_DIR_INPUT } |
| Enumerator used for setting the direction of a pin. More... | |
| enum | pcal6408a_port_dir_t { PCAL6408A_PORT_DIR_OUTPUT = 0x00, PCAL6408A_PORT_DIR_INPUT = 0xFF } |
| Enumerator used for setting the direction of a port. More... | |
| enum | pcal6408a_pin_set_t { PCAL6408A_PIN_CLR, PCAL6408A_PIN_SET } |
| Enumerator used for setting the state of a pin configured as an output. More... | |
| enum | pcal6408a_pin_pull_t { PCAL6408A_PIN_NOPULL, PCAL6408A_PIN_PULLDOWN, PCAL6408A_PIN_PULLUP } |
| Enumerator used for selecting the pin to be pulled down or up. More... | |
| enum | pcal6408a_port_op_t { PCAL6408A_PORT_WRITE, PCAL6408A_PORT_CLEAR, PCAL6408A_PORT_SET } |
| Enumerator used for selecting the operation for a port. More... | |
| enum | pcal6408a_pin_drive_strength_t { PCAL6408A_PIN_25_DRIVE_STRENGTH, PCAL6408A_PIN_50_DRIVE_STRENGTH, PCAL6408A_PIN_75_DRIVE_STRENGTH, PCAL6408A_PIN_100_DRIVE_STRENGTH } |
| Enumerator used for setting the drive strength of a pin. More... | |
| enum | pcal6408a_port_io_stage_t { PCAL6408A_PORT_PUSH_PULL, PCAL6408A_PORT_OPEN_DRAIN } |
| Enumerator used for setting push-pull or open-drain I/O stage for a port. More... | |
Functions | |
| void | pcal6408a_init (pcal6408a_instance_t *p_instances, uint8_t count) |
| Function initialising expander module. More... | |
| ret_code_t | pcal6408a_add_instance (nrf_twi_sensor_t *p_twi_sensor, uint8_t sensor_address) |
| Function adding expander instance. More... | |
| ret_code_t | pcal6408a_cfg_write (uint8_t instance_num) |
| Function for writing current configuration to expander. More... | |
| ret_code_t | pcal6408a_cfg_read (uint8_t instance_num) |
| Function for reading current configuration of expander. More... | |
| ret_code_t | pcal6408a_pin_cfg_reg_set (pcal6408a_registers_t reg_addr, uint32_t pin, uint8_t value) |
| Function for setting register configuration of a single pin. More... | |
| uint8_t | pcal6408a_pin_cfg_reg_get (pcal6408a_registers_t reg_addr, uint32_t pin) |
| Function for getting register configuration of a single pin. More... | |
| ret_code_t | pcal6408a_port_cfg_reg_set (pcal6408a_registers_t reg_addr, uint32_t port, uint8_t mask, pcal6408a_port_op_t flag) |
| Function for setting register configuration of a port. More... | |
| uint8_t | pcal6408a_port_cfg_reg_get (pcal6408a_registers_t reg_addr, uint32_t port) |
| Function for getting register configuration of a port. More... | |
| ret_code_t | pcal6408a_pin_data_update (nrf_twi_sensor_reg_cb_t user_cb) |
| Function for updating pin data. More... | |
| ret_code_t | pcal6408a_int_status_update (nrf_twi_sensor_reg_cb_t user_cb) |
| Function for updating interrupt status data. More... | |
| __STATIC_INLINE ret_code_t | pcal6408a_pin_cfg_polarity_inversion (uint32_t pin_number, bool state) |
| Function for setting polarity inversion of a given pin. More... | |
| __STATIC_INLINE ret_code_t | pcal6408a_pin_cfg_interrupt (uint32_t pin_number, bool state) |
| Function for setting interrupt of a given pin. More... | |
| __STATIC_INLINE ret_code_t | pcal6408a_pin_cfg_latch (uint32_t pin_number, bool state) |
| Function for setting input latch of a given pin. More... | |
| ret_code_t | pcal6408a_pin_cfg_drive_strength (uint32_t pin_number, pcal6408a_pin_drive_strength_t drive_strength_config) |
| Function for setting drive strength for a given pin. More... | |
| __STATIC_INLINE ret_code_t | pcal6408a_port_cfg_polarity_inversion (uint32_t port_number, uint8_t polarity_mask, pcal6408a_port_op_t flag) |
| Function for setting polarity inversion of a given port. More... | |
| __STATIC_INLINE ret_code_t | pcal6408a_port_cfg_interrupt (uint32_t port_number, uint8_t interrupt_mask, pcal6408a_port_op_t flag) |
| Function for setting interrupt of a given port. More... | |
| __STATIC_INLINE ret_code_t | pcal6408a_port_cfg_latch (uint32_t port_number, uint8_t latch_mask, pcal6408a_port_op_t flag) |
| Function for setting input latch of a given port. More... | |
| ret_code_t | pcal6408a_port_cfg_drive_strength (uint32_t port_number, uint16_t drive_strength_mask, pcal6408a_port_op_t flag) |
| Function for setting drive strength for a given port. More... | |
| __STATIC_INLINE ret_code_t | pcal6408a_port_cfg_io_stage (uint32_t port_number, pcal6408a_port_io_stage_t io_stage_config) |
| Function for selecting push-pull or open-drain I/O stage for the given port. More... | |
| __STATIC_INLINE ret_code_t | pcal6408a_pin_cfg_output (uint32_t pin_number) |
| Function for configuring the given pin number as output. More... | |
| ret_code_t | pcal6408a_pin_cfg_input (uint32_t pin_number, pcal6408a_pin_pull_t pull_config) |
| Function for configuring the given pin number as input. More... | |
| __STATIC_INLINE ret_code_t | pcal6408a_pin_set (uint32_t pin_number) |
| Function for setting a pin. More... | |
| __STATIC_INLINE ret_code_t | pcal6408a_pin_clear (uint32_t pin_number) |
| Function for clearing a pin. More... | |
| ret_code_t | pcal6408a_range_cfg_output (uint32_t pin_range_start, uint32_t pin_range_end) |
| Function for configuring the pin range as outputs. More... | |
| ret_code_t | pcal6408a_range_cfg_input (uint32_t pin_range_start, uint32_t pin_range_end, pcal6408a_pin_pull_t pull_config) |
| Function for configuring the pin range as inputs. More... | |
| __STATIC_INLINE ret_code_t | pcal6408a_pin_dir_set (uint32_t pin_number, pcal6408a_pin_dir_t direction) |
| Function for setting the direction for a given pin. More... | |
| __STATIC_INLINE ret_code_t | pcal6408a_pin_toggle (uint32_t pin_number) |
| Function for toggling a given pin. More... | |
| __STATIC_INLINE ret_code_t | pcal6408a_pin_write (uint32_t pin_number, uint8_t value) |
| Function for writing a value to a given pin. More... | |
| __STATIC_INLINE uint32_t | pcal6408a_pin_read (uint32_t pin_number) |
| Function for reading the input level of a given pin. More... | |
| __STATIC_INLINE ret_code_t | pcal6408a_port_dir_set (uint32_t port_number, pcal6408a_port_dir_t direction) |
| Function for setting the direction of a port. More... | |
| __STATIC_INLINE uint32_t | pcal6408a_port_read (uint32_t port_number) |
| Function for reading a given port. More... | |
| __STATIC_INLINE ret_code_t | pcal6408a_port_write (uint32_t port_number, uint8_t value) |
| Function for writing to a given port. More... | |
| __STATIC_INLINE ret_code_t | pcal6408a_port_set (uint32_t port_number, uint8_t set_mask) |
| Function for setting individual pins on given port. More... | |
| __STATIC_INLINE ret_code_t | pcal6408a_port_clear (uint32_t port_number, uint8_t clr_mask) |
| Function for clearing individual pins on given port. More... | |
Module for configuring and using PCAL6408A GPIO expander.
| #define PCAL6408A_INSTANCES_DEF_START | ( | pcal6408a_inst_name, | |
| instance_count | |||
| ) | static pcal6408a_instance_t pcal6408a_inst_name[instance_count] |
Macro that defines expander module.
| [in] | pcal6408a_inst_name | Name of the instance to be created. |
| [in] | instance_count | Number of connected expanders. |
| #define PIN_NUM_CONVERT | ( | pin_num, | |
| instance_num | |||
| ) | (pin_num + instance_num * PCAL6408A_INNER_PIN_COUNT) |
Macro that converts absolute pin number to pin number dependent on number of expander.
| [in] | pin_num | Absolute pin number ranging from 0 to 7. |
| [in] | instance_num | Number of expander, order is the same as pcal6408a_add_instance calls. |
| enum pcal6408a_pin_dir_t |
Enumerator used for setting the drive strength of a pin.
| enum pcal6408a_pin_pull_t |
| enum pcal6408a_pin_set_t |
| enum pcal6408a_port_dir_t |
| enum pcal6408a_port_op_t |
| ret_code_t pcal6408a_add_instance | ( | nrf_twi_sensor_t * | p_twi_sensor, |
| uint8_t | sensor_address | ||
| ) |
Function adding expander instance.
| [in] | p_twi_sensor | Pointer to common sensor instance. NRF_TWI_SENSOR_DEF |
| [in] | sensor_address | Address of expander on I2C bus. |
| NRF_ERROR_MODULE_NOT_INITIALIZED | If expander module wasn't initialised |
| NRF_ERROR_STORAGE_FULL | If trying to add more instances than defined. |
| other | Error code from nrf_twi_sensor nrf_twi_sensor_write |
| ret_code_t pcal6408a_cfg_read | ( | uint8_t | instance_num | ) |
Function for reading current configuration of expander.
| [in] | instance_num | Number of expander, order is the same as pcal6408a_add_instance calls. |
| NRF_ERROR_INVALID_PARAM | If there is no expander with given number. |
| other | Error code from nrf_twi_sensor nrf_twi_sensor_write |
| ret_code_t pcal6408a_cfg_write | ( | uint8_t | instance_num | ) |
Function for writing current configuration to expander.
| [in] | instance_num | Number of expander, order is the same as pcal6408a_add_instance calls. |
| NRF_ERROR_INVALID_PARAM | If there is no expander with given number. |
| other | Error code from nrf_twi_sensor nrf_twi_sensor_write |
| void pcal6408a_init | ( | pcal6408a_instance_t * | p_instances, |
| uint8_t | count | ||
| ) |
Function initialising expander module.
| [in] | p_instances | Pointer to expander module. |
| [in] | count | Number of connected expanders. |
| ret_code_t pcal6408a_int_status_update | ( | nrf_twi_sensor_reg_cb_t | user_cb | ) |
Function for updating interrupt status data.
| user_cb | Function to be called after interrupt status update is done. |
| ret_code_t pcal6408a_pin_cfg_drive_strength | ( | uint32_t | pin_number, |
| pcal6408a_pin_drive_strength_t | drive_strength_config | ||
| ) |
Function for setting drive strength for a given pin.
| [in] | pin_number | Specifies the pin number. |
| [in] | drive_strength_config | Drive strength of current drive capability (25%, 50%, 75% or 100%) pcal6408a_pin_drive_strength_t |
| ret_code_t pcal6408a_pin_cfg_input | ( | uint32_t | pin_number, |
| pcal6408a_pin_pull_t | pull_config | ||
| ) |
Function for configuring the given pin number as input.
| [in] | pin_number | Specifies the pin number. |
| [in] | pull_config | State of the pin pull resistor (no pull, pulled down, or pulled high) pcal6408a_pin_pull_t |
| __STATIC_INLINE ret_code_t pcal6408a_pin_cfg_interrupt | ( | uint32_t | pin_number, |
| bool | state | ||
| ) |
Function for setting interrupt of a given pin.
| [in] | pin_number | Specifies the pin number. |
| [in] | state |
|
| __STATIC_INLINE ret_code_t pcal6408a_pin_cfg_latch | ( | uint32_t | pin_number, |
| bool | state | ||
| ) |
Function for setting input latch of a given pin.
| [in] | pin_number | Specifies the pin number. |
| [in] | state |
|
| __STATIC_INLINE ret_code_t pcal6408a_pin_cfg_output | ( | uint32_t | pin_number | ) |
Function for configuring the given pin number as output.
| [in] | pin_number | Specifies the pin number. |
| __STATIC_INLINE ret_code_t pcal6408a_pin_cfg_polarity_inversion | ( | uint32_t | pin_number, |
| bool | state | ||
| ) |
Function for setting polarity inversion of a given pin.
| [in] | pin_number | Specifies the pin number. |
| [in] | state |
|
| uint8_t pcal6408a_pin_cfg_reg_get | ( | pcal6408a_registers_t | reg_addr, |
| uint32_t | pin | ||
| ) |
Function for getting register configuration of a single pin.
| [in] | reg_addr | Register address. |
| [in] | pin | Pin number. |
| ret_code_t pcal6408a_pin_cfg_reg_set | ( | pcal6408a_registers_t | reg_addr, |
| uint32_t | pin, | ||
| uint8_t | value | ||
| ) |
Function for setting register configuration of a single pin.
| [in] | reg_addr | Register address. |
| [in] | pin | Pin number. |
| [in] | value | Value to set. |
| __STATIC_INLINE ret_code_t pcal6408a_pin_clear | ( | uint32_t | pin_number | ) |
Function for clearing a pin.
| [in] | pin_number | Specifies the pin number to clear. |
| ret_code_t pcal6408a_pin_data_update | ( | nrf_twi_sensor_reg_cb_t | user_cb | ) |
Function for updating pin data.
| user_cb | Function to be called after pin data update is done. |
| __STATIC_INLINE ret_code_t pcal6408a_pin_dir_set | ( | uint32_t | pin_number, |
| pcal6408a_pin_dir_t | direction | ||
| ) |
Function for setting the direction for a given pin.
| [in] | pin_number | Specifies the pin number. |
| [in] | direction | Specifies the direction. |
| __STATIC_INLINE uint32_t pcal6408a_pin_read | ( | uint32_t | pin_number | ) |
Function for reading the input level of a given pin.
| [in] | pin_number | Specifies the pin number. |
| __STATIC_INLINE ret_code_t pcal6408a_pin_set | ( | uint32_t | pin_number | ) |
Function for setting a pin.
| [in] | pin_number | Specifies the pin number to set. |
| __STATIC_INLINE ret_code_t pcal6408a_pin_toggle | ( | uint32_t | pin_number | ) |
Function for toggling a given pin.
| [in] | pin_number | Specifies the pin number. |
| __STATIC_INLINE ret_code_t pcal6408a_pin_write | ( | uint32_t | pin_number, |
| uint8_t | value | ||
| ) |
Function for writing a value to a given pin.
| [in] | pin_number | Specifies the pin number. |
| [in] | value | Specifies the value to be written to the pin.
|
| ret_code_t pcal6408a_port_cfg_drive_strength | ( | uint32_t | port_number, |
| uint16_t | drive_strength_mask, | ||
| pcal6408a_port_op_t | flag | ||
| ) |
Function for setting drive strength for a given port.
| [in] | port_number | Specifies the port number. |
| [in] | drive_strength_mask | Specifies the mask. Note that for each pin there are dedicated two adjacent bits. |
| [in] | flag | Operation, whether mask should be written into register, values should be cleared or set pcal6408a_port_op_t |
| __STATIC_INLINE ret_code_t pcal6408a_port_cfg_interrupt | ( | uint32_t | port_number, |
| uint8_t | interrupt_mask, | ||
| pcal6408a_port_op_t | flag | ||
| ) |
Function for setting interrupt of a given port.
| [in] | port_number | Specifies the port number. |
| [in] | interrupt_mask | Specifies the mask. |
| [in] | flag | Operation, whether mask should be written into register, values should be cleared or set pcal6408a_port_op_t |
| __STATIC_INLINE ret_code_t pcal6408a_port_cfg_io_stage | ( | uint32_t | port_number, |
| pcal6408a_port_io_stage_t | io_stage_config | ||
| ) |
Function for selecting push-pull or open-drain I/O stage for the given port.
| [in] | port_number | Specifies the port number. |
| [in] | io_stage_config | I/O stage of the port (push-pull or open-drain) pcal6408a_port_io_stage_t |
| __STATIC_INLINE ret_code_t pcal6408a_port_cfg_latch | ( | uint32_t | port_number, |
| uint8_t | latch_mask, | ||
| pcal6408a_port_op_t | flag | ||
| ) |
Function for setting input latch of a given port.
| [in] | port_number | Specifies the port number. |
| [in] | latch_mask | Specifies the mask. |
| [in] | flag | Operation, whether mask should be written into register, values should be cleared or set pcal6408a_port_op_t |
| __STATIC_INLINE ret_code_t pcal6408a_port_cfg_polarity_inversion | ( | uint32_t | port_number, |
| uint8_t | polarity_mask, | ||
| pcal6408a_port_op_t | flag | ||
| ) |
Function for setting polarity inversion of a given port.
| [in] | port_number | Specifies the port number. |
| [in] | polarity_mask | Specifies the mask. |
| [in] | flag | Operation, whether mask should be written into register, values should be cleared or set pcal6408a_port_op_t |
| uint8_t pcal6408a_port_cfg_reg_get | ( | pcal6408a_registers_t | reg_addr, |
| uint32_t | port | ||
| ) |
Function for getting register configuration of a port.
| [in] | reg_addr | Register address. |
| [in] | port | Port number. |
| ret_code_t pcal6408a_port_cfg_reg_set | ( | pcal6408a_registers_t | reg_addr, |
| uint32_t | port, | ||
| uint8_t | mask, | ||
| pcal6408a_port_op_t | flag | ||
| ) |
Function for setting register configuration of a port.
| [in] | reg_addr | Register address. |
| [in] | port | Port number. |
| [in] | mask | Mask for the operation. |
| [in] | flag | Operation, whether mask should be written into register, values should be cleared or set pcal6408a_port_op_t |
| NRF_ERROR_INVALID_PARAM | If there is no port with such number or invalid flag operation. |
| other | Error code from nrf_twi_sensor nrf_twi_sensor_write |
| __STATIC_INLINE ret_code_t pcal6408a_port_clear | ( | uint32_t | port_number, |
| uint8_t | clr_mask | ||
| ) |
Function for clearing individual pins on given port.
| [in] | port_number | Specifies the port number. |
| [in] | clr_mask | Mask specifying which pins to clear. A bit set to 1 indicates that the corresponding port pin shall be cleared. |
| __STATIC_INLINE ret_code_t pcal6408a_port_dir_set | ( | uint32_t | port_number, |
| pcal6408a_port_dir_t | direction | ||
| ) |
Function for setting the direction of a port.
| [in] | port_number | Specifies the port number. |
| [in] | direction | Specifies the direction. |
| __STATIC_INLINE uint32_t pcal6408a_port_read | ( | uint32_t | port_number | ) |
Function for reading a given port.
| [in] | port_number | Specifies the port number. |
| __STATIC_INLINE ret_code_t pcal6408a_port_set | ( | uint32_t | port_number, |
| uint8_t | set_mask | ||
| ) |
Function for setting individual pins on given port.
| [in] | port_number | Specifies the port number. |
| [in] | set_mask | Mask specifying which pins to set. A bit set to 1 indicates that the corresponding port pin shall be set. |
| __STATIC_INLINE ret_code_t pcal6408a_port_write | ( | uint32_t | port_number, |
| uint8_t | value | ||
| ) |
Function for writing to a given port.
| [in] | port_number | Specifies the port number. |
| [in] | value | Specifies the value to be written to the port. |
| ret_code_t pcal6408a_range_cfg_input | ( | uint32_t | pin_range_start, |
| uint32_t | pin_range_end, | ||
| pcal6408a_pin_pull_t | pull_config | ||
| ) |
Function for configuring the pin range as inputs.
| [in] | pin_range_start | Specifies the start number (inclusive) in the range of pin numbers to be configured. |
| [in] | pin_range_end | Specifies the end number (inclusive) in the range of pin numbers to be configured. |
| [in] | pull_config | State of the pin pull resistor (no pull, pulled down, or pulled high) pcal6408a_pin_pull_t |
| NRF_ERROR_INVALID_LENGTH | If start number is greater than end number. |
| other | Error code from port_cfg_reg_set pcal6408a_port_cfg_reg_set |
| ret_code_t pcal6408a_range_cfg_output | ( | uint32_t | pin_range_start, |
| uint32_t | pin_range_end | ||
| ) |
Function for configuring the pin range as outputs.
| [in] | pin_range_start | Specifies the start number (inclusive) in the range of pin numbers to be configured. |
| [in] | pin_range_end | Specifies the end number (inclusive) in the range of pin numbers to be configured. |
| NRF_ERROR_INVALID_LENGTH | If start number is greater than end number. |
| other | Error code from port_cfg_reg_set pcal6408a_port_cfg_reg_set |