| Nordic Thingy:52 v2.0.0

Modules | Data Structures | Macros | Enumerations | Functions
GPIO extender
Drivers

GPIO extender API. More...

## Modules

| GPIO extender LED driver
| GPIO extender LED driver API.
| SX1509 GPIO extender driver
| SX1509 GPIO extender API.

## Data Structures

struct | drv_ext_gpio_init_t
| GPIO extender driver configuration. More...

## Macros

#define | DRV_EXT_GPIO_NUM_PINS_TOTAL (DRV_EXT_GPIO_PIN_HIGHEST_ID + 1)
| Number of pins total.
#define | DRV_EXT_GPIO_PIN_HIGHEST_ID DRV_SX1509_DATA_PIN15_Pos
| Highest pin ID.

## Enumerations

enum | { DRV_EXT_GPIO_STATUS_CODE_SUCCESS = NRF_SUCCESS, DRV_EXT_GPIO_STATUS_CODE_INVALID_PARAM, DRV_EXT_GPIO_STATUS_CODE_INVALID_PIN }
| GPIO extender status codes. More...
enum | drv_ext_gpio_pin_dir_t { DRV_EXT_GPIO_PIN_DIR_OUTPUT, DRV_EXT_GPIO_PIN_DIR_INPUT }
| Pin direction definitions. More...
enum | drv_ext_gpio_pin_drive_type_t { DRV_EXT_GPIO_PIN_DRIVE_PUSHPULL, DRV_EXT_GPIO_PIN_DRIVE_OPENDRAIN }
| Push-pull or open drain operation. More...
enum | drv_ext_gpio_pin_input_buf_t { DRV_EXT_GPIO_PIN_INPUT_BUF_ENABLED, DRV_EXT_GPIO_PIN_INPUT_BUF_DISABLED }
| Connection of input buffer. More...
enum | drv_ext_gpio_pin_pull_t { DRV_EXT_GPIO_PIN_NOPULL, DRV_EXT_GPIO_PIN_PULLDOWN, DRV_EXT_GPIO_PIN_PULLUP }
| Pin to be pulled down, up, or no-pull. More...
enum | drv_ext_gpio_pin_slew_rate_t { DRV_EXT_GPIO_PIN_INCREASED_SLEWRATE_DISABLED, DRV_EXT_GPIO_PIN_INCREASED_SLEWRATE_ENABLED }
| Regular or increased slew rate. More...

## Functions

uint32_t | drv_ext_gpio_cfg (uint32_t pin_number, drv_ext_gpio_pin_dir_t dir, drv_ext_gpio_pin_input_buf_t input_buf, drv_ext_gpio_pin_pull_t pull_config, drv_ext_gpio_pin_drive_type_t drive_type, drv_ext_gpio_pin_slew_rate_t slew_rate)
| Pin configuration function. More...
uint32_t | drv_ext_gpio_cfg_input (uint32_t pin_number, drv_ext_gpio_pin_pull_t pull_config)
| Function for configuring the given GPIO pin number as input with given initial value set, hiding inner details. More...
uint32_t | drv_ext_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. More...
uint32_t | drv_ext_gpio_init (drv_ext_gpio_init_t const *const p_init, bool on_init_reset)
| Function for initializing the GPIO extender. More...
uint32_t | drv_ext_gpio_pin_clear (uint32_t pin_number)
| Function for clearing a GPIO pin. More...
uint32_t | drv_ext_gpio_pin_dir_modify (uint32_t pin_number, drv_ext_gpio_pin_dir_t direction)
| Function for setting the direction of a GPIO pin. More...
uint32_t | drv_ext_gpio_pin_drive_type_modify (uint32_t pin_number, drv_ext_gpio_pin_drive_type_t drive_type)
| Function for setting the drive type a given GPIO pin. More...
uint32_t | drv_ext_gpio_pin_input_buffer_modify (uint32_t pin_number, drv_ext_gpio_pin_input_buf_t input_buf)
| Function for enabling and disabling the input buffer. More...
uint32_t | drv_ext_gpio_pin_read (uint32_t pin_number, uint32_t *const p_pin)
| Function for reading the input level of a GPIO pin. More...
uint32_t | drv_ext_gpio_pin_set (uint32_t pin_number)
| Function for setting a GPIO pin. More...
uint32_t | drv_ext_gpio_pin_slew_rate_modify (uint32_t pin_number, drv_ext_gpio_pin_slew_rate_t slew_rate)
| Function for enabling or disabling increased slew rate for a given GPIO pin. More...
uint32_t | drv_ext_gpio_pin_toggle (uint32_t pin_number)
| Function for toggling a GPIO pin. More...
uint32_t | drv_ext_gpio_pin_write (uint32_t pin_number, uint32_t value)
| Function for writing a value to a GPIO pin. More...
uint32_t | drv_ext_gpio_pins_clear (uint32_t pin_mask)
| Function for clearing GPIO pins. More...
uint32_t | drv_ext_gpio_pins_read (uint32_t *const p_pins)
| Function for reading the input level of all GPIO pins. More...
uint32_t | drv_ext_gpio_pins_set (uint32_t pin_mask)
| Function for setting GPIO pins. More...
uint32_t | drv_ext_gpio_pins_toggle (uint32_t pin_mask)
| Function for toggling GPIO pins. More...
uint32_t | drv_ext_gpio_reg_data_init (uint32_t data)
| Function for setting all the RegData registers at the same time. More...
uint32_t | drv_ext_gpio_reset (void)
| Function for resetting all the registers of the GPIO extender to their default values. More...

## Detailed Description

GPIO extender API.

## Enumeration Type Documentation

## ◆ anonymous enum

anonymous enum

GPIO extender status codes.

Enumerator
DRV_EXT_GPIO_STATUS_CODE_SUCCESS | Successfull.
DRV_EXT_GPIO_STATUS_CODE_INVALID_PARAM | Invalid parameters.
DRV_EXT_GPIO_STATUS_CODE_INVALID_PIN | Invalid GPIO pin or pin mask selected.

## ◆ drv_ext_gpio_pin_dir_t

enum drv_ext_gpio_pin_dir_t

Pin direction definitions.

Enumerator
DRV_EXT_GPIO_PIN_DIR_OUTPUT | Output.
DRV_EXT_GPIO_PIN_DIR_INPUT | Input.

## ◆ drv_ext_gpio_pin_drive_type_t

enum drv_ext_gpio_pin_drive_type_t

Push-pull or open drain operation.

Enumerator
DRV_EXT_GPIO_PIN_DRIVE_PUSHPULL | Standard push-pull operation.
DRV_EXT_GPIO_PIN_DRIVE_OPENDRAIN | Open drain.

## ◆ drv_ext_gpio_pin_input_buf_t

enum drv_ext_gpio_pin_input_buf_t

Connection of input buffer.

Enumerator
DRV_EXT_GPIO_PIN_INPUT_BUF_ENABLED | Connect input buffer.
DRV_EXT_GPIO_PIN_INPUT_BUF_DISABLED | Disconnect input buffer.

## ◆ drv_ext_gpio_pin_pull_t

enum drv_ext_gpio_pin_pull_t

Pin to be pulled down, up, or no-pull.

Enumerator
DRV_EXT_GPIO_PIN_NOPULL | No pin pullup or pulldown.
DRV_EXT_GPIO_PIN_PULLDOWN | Pin pulldown resistor enabled.
DRV_EXT_GPIO_PIN_PULLUP | Pin pullup resistor enabled.

## ◆ drv_ext_gpio_pin_slew_rate_t

enum drv_ext_gpio_pin_slew_rate_t

Regular or increased slew rate.

Enumerator
DRV_EXT_GPIO_PIN_INCREASED_SLEWRATE_DISABLED | No slew rate alteration.
DRV_EXT_GPIO_PIN_INCREASED_SLEWRATE_ENABLED | Increased slew rate.

## Function Documentation

## ◆ drv_ext_gpio_cfg()

uint32_t drv_ext_gpio_cfg | ( | uint32_t | pin_number,
|  | drv_ext_gpio_pin_dir_t | dir,
|  | drv_ext_gpio_pin_input_buf_t | input_buf,
|  | drv_ext_gpio_pin_pull_t | pull_config,
|  | drv_ext_gpio_pin_drive_type_t | drive_type,
|  | drv_ext_gpio_pin_slew_rate_t | slew_rate
| ) |  |

Pin configuration function.

Note
  The main pin configuration function. This function allows to set any aspect in PIN_CNF register.

Parameters

  [in] | pin_number | Specifies the pin number (Allowed values: 0 to DRV_EXT_GPIO_PIN_HIGHEST_ID).
  [in] | dir | Pin direction.
  [in] | input_buf | Connect or disconnect input buffer.
  [in] | pull_config | Pull configuration.
  [in] | drive_type | Push-pull or open drain.
  [in] | slew_rate | Normal or increased slew rate.

Returns
  DRV_EXT_GPIO_STATUS_CODE_SUCCESS If the call was successful.
  DRV_EXT_GPIO_STATUS_CODE_INVALID_PARAM Invalid parameters supplied.
  DRV_EXT_GPIO_STATUS_CODE_INVALID_PIN Pin number not available.
  Other codes from the underlying driver.

## ◆ drv_ext_gpio_cfg_input()

uint32_t drv_ext_gpio_cfg_input | ( | uint32_t | pin_number,
|  | drv_ext_gpio_pin_pull_t | pull_config
| ) |  |

Function for configuring the given GPIO pin number as input with given initial value set, hiding inner details.

Parameters

  [in] | pin_number | The pin number (allowed values 0-DRV_EXT_GPIO_PIN_HIGHEST_ID).
  [in] | pull_config | State of the pin range pull resistor (no pull, pulled down, or pulled high).

Returns
  DRV_EXT_GPIO_STATUS_CODE_SUCCESS If the call was successful.
  DRV_EXT_GPIO_STATUS_CODE_INVALID_PARAM Invalid parameters supplied.
  DRV_EXT_GPIO_STATUS_CODE_INVALID_PIN Pin number not available.
  Other codes from the underlying driver.

## ◆ drv_ext_gpio_cfg_output()

uint32_t drv_ext_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.

Parameters

  [in] | pin_number | The pin number (allowed values 0-DRV_EXT_GPIO_PIN_HIGHEST_ID).

Returns
  DRV_EXT_GPIO_STATUS_CODE_SUCCESS If the call was successful.
  DRV_EXT_GPIO_STATUS_CODE_INVALID_PIN Pin number not available.
  Other codes from the underlying driver.

## ◆ drv_ext_gpio_init()

uint32_t drv_ext_gpio_init | ( | drv_ext_gpio_init_t const *const | p_init,
|  | bool | on_init_reset
| ) |  |

Function for initializing the GPIO extender.

Parameters

  [in] | p_init | Configuration struct.
  [in] | on_init_reset | If true, the IO extender will be reset on init. This will put the IO extender in a known state, but will delete any previous configurations, even from other drivers.

Returns
  DRV_EXT_GPIO_STATUS_CODE_SUCCESS If the call was successful.
  Other codes from the underlying driver.

## ◆ drv_ext_gpio_pin_clear()

uint32_t drv_ext_gpio_pin_clear | ( | uint32_t | pin_number | ) |

Function for clearing a GPIO pin.

Note
  The pin must be configured as an output for this function to have any effect.

Parameters

  [in] | pin_number | The pin number (0-DRV_EXT_GPIO_PIN_HIGHEST_ID) to clear.

Returns
  DRV_EXT_GPIO_STATUS_CODE_SUCCESS If the call was successful.
  DRV_EXT_GPIO_STATUS_CODE_INVALID_PIN Pin number not available.
  Other codes from the underlying driver.

## ◆ drv_ext_gpio_pin_dir_modify()

uint32_t drv_ext_gpio_pin_dir_modify | ( | uint32_t | pin_number,
|  | drv_ext_gpio_pin_dir_t | direction
| ) |  |

Function for setting the direction of a GPIO pin.

Parameters

  [in] | pin_number | The pin number (allowed values 0-DRV_EXT_GPIO_PIN_HIGHEST_ID).
  [in] | direction | The direction.

Returns
  DRV_EXT_GPIO_STATUS_CODE_SUCCESS If the call was successful.
  DRV_EXT_GPIO_STATUS_CODE_INVALID_PARAM Invalid parameters supplied.
  DRV_EXT_GPIO_STATUS_CODE_INVALID_PIN Pin number not available.
  Other codes from the underlying driver.

## ◆ drv_ext_gpio_pin_drive_type_modify()

uint32_t drv_ext_gpio_pin_drive_type_modify | ( | uint32_t | pin_number,
|  | drv_ext_gpio_pin_drive_type_t | drive_type
| ) |  |

Function for setting the drive type a given GPIO pin.

Parameters

  [in] | pin_number | The pin number (allowed values 0-DRV_EXT_GPIO_PIN_HIGHEST_ID).
  [in] | drive_type | Pin drive: push-pull or open drain.

Returns
  DRV_EXT_GPIO_STATUS_CODE_SUCCESS If the call was successful.
  DRV_EXT_GPIO_STATUS_CODE_INVALID_PARAM Invalid parameters supplied.
  DRV_EXT_GPIO_STATUS_CODE_INVALID_PIN Pin number not available.
  Other codes from the underlying driver.

## ◆ drv_ext_gpio_pin_input_buffer_modify()

uint32_t drv_ext_gpio_pin_input_buffer_modify | ( | uint32_t | pin_number,
|  | drv_ext_gpio_pin_input_buf_t | input_buf
| ) |  |

Function for enabling and disabling the input buffer.

Parameters

  [in] | pin_number | The pin number (allowed values 0-DRV_EXT_GPIO_PIN_HIGHEST_ID).
  [in] | input_buf | Disabled or enabled.

Returns
  DRV_EXT_GPIO_STATUS_CODE_SUCCESS If the call was successful.
  DRV_EXT_GPIO_STATUS_CODE_INVALID_PARAM Invalid parameters supplied.
  DRV_EXT_GPIO_STATUS_CODE_INVALID_PIN Pin number not available.
  Other codes from the underlying driver.

## ◆ drv_ext_gpio_pin_read()

uint32_t drv_ext_gpio_pin_read | ( | uint32_t | pin_number,
|  | uint32_t *const | p_pin
| ) |  |

Function for reading the input level of a GPIO pin.

Note
  The pin must have input connected for the value returned from this function to be valid.

Parameters

  [in] | pin_number | The pin number (0-DRV_EXT_GPIO_PIN_HIGHEST_ID) to read.
  [out] | p_pin | Pin value.

Return values

  0 | if the pin input level is low.
  1 | if the pin input level is high.
  > | 1 should never occur.

Returns
  DRV_EXT_GPIO_STATUS_CODE_SUCCESS If the call was successful.
  DRV_EXT_GPIO_STATUS_CODE_INVALID_PIN Pin number not available.
  Other codes from the underlying driver.

## ◆ drv_ext_gpio_pin_set()

uint32_t drv_ext_gpio_pin_set | ( | uint32_t | pin_number | ) |

Function for setting a GPIO pin.

Note
  The pin must be configured as an output for this function to have any effect.

Parameters

  [in] | pin_number | The pin number (0-DRV_EXT_GPIO_PIN_HIGHEST_ID) to set.

Returns
  DRV_EXT_GPIO_STATUS_CODE_SUCCESS If the call was successful.
  DRV_EXT_GPIO_STATUS_CODE_INVALID_PIN Pin number not available.
  Other codes from the underlying driver.

## ◆ drv_ext_gpio_pin_slew_rate_modify()

uint32_t drv_ext_gpio_pin_slew_rate_modify | ( | uint32_t | pin_number,
|  | drv_ext_gpio_pin_slew_rate_t | slew_rate
| ) |  |

Function for enabling or disabling increased slew rate for a given GPIO pin.

Parameters

  [in] | pin_number | The pin number (allowed values 0-DRV_EXT_GPIO_PIN_HIGHEST_ID).
  [in] | slew_rate | Enabled or disabled.

Returns
  DRV_EXT_GPIO_STATUS_CODE_SUCCESS If the call was successful.
  DRV_EXT_GPIO_STATUS_CODE_INVALID_PARAM Invalid parameters supplied.
  DRV_EXT_GPIO_STATUS_CODE_INVALID_PIN Pin number not available.
  Other codes from the underlying driver.

## ◆ drv_ext_gpio_pin_toggle()

uint32_t drv_ext_gpio_pin_toggle | ( | uint32_t | pin_number | ) |

Function for toggling a GPIO pin.

Note
  The pin must be configured as an output for this function to have any effect.

Parameters

  [in] | pin_number | Pin number (0-DRV_EXT_GPIO_PIN_HIGHEST_ID) to toggle.

Returns
  DRV_EXT_GPIO_STATUS_CODE_SUCCESS If the call was successful.
  DRV_EXT_GPIO_STATUS_CODE_INVALID_PIN Pin number not available.
  Other codes from the underlying driver.

## ◆ drv_ext_gpio_pin_write()

uint32_t drv_ext_gpio_pin_write | ( | uint32_t | pin_number,
|  | uint32_t | value
| ) |  |

Function for writing a value to a GPIO pin.

Note
  The pin must be configured as an output for this function to have any effect.

Parameters

  [in] | pin_number | The pin number (0-DRV_EXT_GPIO_PIN_HIGHEST_ID) to write.
  [in] | value | Specifies the value to be written to the pin.
  - 0 clears the pin.
  - >=1 sets the pin.

Returns
  DRV_EXT_GPIO_STATUS_CODE_SUCCESS If the call was successful.
  DRV_EXT_GPIO_STATUS_CODE_INVALID_PIN Pin number not available.
  Other codes from the underlying driver.

## ◆ drv_ext_gpio_pins_clear()

uint32_t drv_ext_gpio_pins_clear | ( | uint32_t | pin_mask | ) |

Function for clearing GPIO pins.

Note
  Pins must be configured as outputs for this function to have any effect.

Parameters

  [in] | pin_mask | Pins to clear.

Returns
  DRV_EXT_GPIO_STATUS_CODE_SUCCESS If the call was successful.
  DRV_EXT_GPIO_STATUS_CODE_INVALID_PIN Pin number not available.
  Other codes from the underlying driver.

## ◆ drv_ext_gpio_pins_read()

uint32_t drv_ext_gpio_pins_read | ( | uint32_t *const | p_pins | ) |

Function for reading the input level of all GPIO pins.

Note
  The pins must have input connected for the value returned from this function to be valid.
  The most significant 16 bits will always be zero, due to 16 pins on the IO extender.

Parameters

  [out] | p_pins | State of all pins.

Returns
  DRV_EXT_GPIO_STATUS_CODE_SUCCESS If the call was successful.
  DRV_EXT_GPIO_STATUS_CODE_INVALID_PIN Pin number not available.
  Other codes from the underlying driver.

## ◆ drv_ext_gpio_pins_set()

uint32_t drv_ext_gpio_pins_set | ( | uint32_t | pin_mask | ) |

Function for setting GPIO pins.

Note
  Pins must be configured as outputs for this function to have any effect.

Parameters

  [in] | pin_mask | Specifies the pins to set.

Returns
  DRV_EXT_GPIO_STATUS_CODE_SUCCESS If the call was successful.
  DRV_EXT_GPIO_STATUS_CODE_INVALID_PIN Pin number not available.
  Other codes from the underlying driver.

## ◆ drv_ext_gpio_pins_toggle()

uint32_t drv_ext_gpio_pins_toggle | ( | uint32_t | pin_mask | ) |

Function for toggling GPIO pins.

Note
  Pins must be configured as outputs for this function to have any effect.

Parameters

  [in] | pin_mask | Pins to toggle.

Returns
  DRV_EXT_GPIO_STATUS_CODE_SUCCESS If the call was successful.
  DRV_EXT_GPIO_STATUS_CODE_INVALID_PIN Pin number not available.
  Other codes from the underlying driver.

## ◆ drv_ext_gpio_reg_data_init()

uint32_t drv_ext_gpio_reg_data_init | ( | uint32_t | data | ) |

Function for setting all the RegData registers at the same time.

Note
  When reading RegData from the IO extender, it reads the data seen at the IOs (if the input buffer is enabled) independent of IO configured direction. Writing changes the value of RegData. As some functions in drv_sx1509 reads a register and does not write back if there is no apparant change this may cause unintended effects for RegData. This function writes to RegData regardless of previous contents and sets all bits in this function. The feature is valuable on IO extender initialization.

Parameters

  [in] | data | The value to be written to the RegData regsiters. (Max 2^DRV_EXT_GPIO_NUM_PINS_TOTAL) - 1

Returns
  DRV_EXT_GPIO_STATUS_CODE_SUCCESS If the call was successful.
  DRV_EXT_GPIO_STATUS_CODE_INVALID_PIN Pin value is too large.
  Other codes from the underlying driver.

## ◆ drv_ext_gpio_reset()

uint32_t drv_ext_gpio_reset | ( | void |  | ) |

Function for resetting all the registers of the GPIO extender to their default values.

Note
  This reset applies to all registers, regardless if they were set by another driver outside of drv_ext_gpio.

Returns
  DRV_EXT_GPIO_STATUS_CODE_SUCCESS If the call was successful.
  Other codes from the underlying driver.