GPIO Interface
GPIO Platform interface
GPIO Overview:
GPIO (General-Purpose Input/Output) is a flexible pin on a microcontroller or integrated circuit that can be configured as an input or output to interact with external hardware. GPIOs serve as the fundamental interface between digital systems and their surrounding environment, enabling communication, control, and data acquisition.
GPIO Supported Modes
The middleware part will be responsible for debouncing the GPIO’s inputs, triggering call backs, sleep mode settings, etc. Technically this is the value addition, RAPIDSEA is going to provide. The GPIO input mode macro (RS_GPIO_INPUT_MODE macro) can be configured in 3 modes.
Mode |
Description |
---|---|
RS_GPIO_INPUT_MODE_PASS_THROUGH |
No action by middleware |
RS_GPIO_INPUT_MODE_STATIC_DEBOUNCE |
Static number of debounce counts across all inputs. Defined per rs_gpio_process call |
RS_GPIO_INPUT_MODE_DYNAMIC_DEBOUNCE |
Dynamic settings configurable for each input. Defined in milliseconds |
Application Interface
The below table captures the functions that are to be called from the application layer.
Function |
Description |
---|---|
rs_gpio_callback_enable |
To enable the gpio callback. |
rs_gpio_configure_pin |
To configure the gpio pins. |
rs_gpio_configures_pin |
To configure the arrary of GPIO port pins. |
rs_gpio_set_pin_level |
To set the gpio value to the pin levels. |
rs_gpio_get_pin_level |
To get the gpio value from the pin levels. |
rs_gpio_set_port_levels |
To sets the output levels of the GPIO port group |
rs_gpio_register_interrupt_callback |
To register the gpio interrupt callback. |
Error Code
Every API’s for the GPIO returns some success or failure values. Please refer below section,
Implementation Guide
Users can directly call the API’s though most of them will be called by device drivers.
Configure the GPIO port and pins.
Register the interrupt callback.
Set the gpio pins and get the gpio pins if needed.
The user will have to repeatedly call rs_gpio_process routine when de-bouncing is configured for.
Documentation from the relevant header as follows:
Defines
-
RS_GPIO_PORT_00_INDEX
Port Index.
-
RS_GPIO_PORT_01_INDEX
-
RS_GPIO_PORT_02_INDEX
-
RS_GPIO_PORT_03_INDEX
-
RS_GPIO_PORT_04_INDEX
-
RS_GPIO_PORT_05_INDEX
-
RS_GPIO_PORT_06_INDEX
-
RS_GPIO_PORT_07_INDEX
-
RS_GPIO_PORT_08_INDEX
-
RS_GPIO_PORT_09_INDEX
-
RS_GPIO_PORT_10_INDEX
-
RS_GPIO_PORT_11_INDEX
-
RS_GPIO_PORT_12_INDEX
-
RS_GPIO_PORT_13_INDEX
-
RS_GPIO_PORT_14_INDEX
-
RS_GPIO_PORT_15_INDEX
-
RS_GPIO_PORT_16_INDEX
-
RS_GPIO_PORT_17_INDEX
-
RS_GPIO_PORT_42_INDEX
-
RS_GPIO_PORT_43_INDEX
-
RS_GPIO_PORT_44_INDEX
-
RS_GPIO_PORT_45_INDEX
-
RS_GPIO_LEVEL_LOW
Set pin level.
-
RS_GPIO_LEVEL_HIGH
-
RS_GPIO_DIR_INPUT
Set Pin direction.
Set direction as input
-
RS_GPIO_DIR_OUTPUT
Set direction as output.
-
RS_GPIO_PULL_NON
Set Pullup.
No resistor connected
-
RS_GPIO_PULL_UP
Connect pullup resistor.
-
RS_GPIO_PULL_DOWN
Connect pulldown resistor.
-
RS_GPIO_ALT_FUNCTION_NONE
Alternate functions.
Function as GPIO
-
RS_GPIO_ALT_FUNCTION_1
Alternative function 1.
-
RS_GPIO_ALT_FUNCTION_2
Alternative function 2.
-
RS_GPIO_ALT_FUNCTION_3
Alternative function 3.
-
RS_GPIO_ALT_FUNCTION_4
Alternative function 4.
-
RS_GPIO_ALT_FUNCTION_5
Alternative function 5.
-
RS_GPIO_ALT_FUNCTION_6
Alternative function 6.
-
RS_GPIO_DRIVE_NONE
Drive/Input modes.
Default Drive
-
RS_GPIO_DRIVE_INPUT_CMOS
Input as CMOS.
-
RS_GPIO_DRIVE_INPUT_TTL
Input as TTL.
-
RS_GPIO_INTERRUPT_NONE
Interrupt mode.
Do not configure for interrupts
-
RS_GPIO_INTERRUPT_RISING_EDGE
Interruptible for Rising edge.
-
RS_GPIO_INTERRUPT_FALLING_EDGE
Interruptible for falling edge.
-
RS_GPIO_INTERRUPT_BOTH_EDGES
Interruptible for both edges.
-
RS_GPIO_WAKEUP_DISABLED
Wakeup.
Do not wakeup
-
RS_GPIO_WAKEUP_ENABLED
Configure for wakeup.
-
RS_GPIO_SLEEP_MODE_NO_CHANGE
Sleep mode.
Do not anything when entering sleep
-
RS_GPIO_SLEEP_MODE_OUTPUT_HIGH
Configure as output-high when entering sleep.
-
RS_GPIO_SLEEP_MODE_OUTPUT_LOW
Configure as output-low when entering sleep.
-
RS_GPIO_SLEEP_MODE_INPUT
Configure as input when entering sleep.
Typedefs
-
typedef void (*rs_gpio_callback_pin_interrupt)(uint8_t u8_port_index, uint8_t u8_pin, uint8_t u8_interrupt_type)
Callback function for pin interrupt.
Callback function format.
This callback function is called on change in interrupt
- Param u8_port_index:
[in] - Index to the port
- Param u8_pin:
[in] - Pin number inside the port
- Param u8_interrupt_type:
[in] - Typoe of interrupt
- Return:
None
-
typedef struct tag_rs_gpio_pin_config rs_gpio_pin_config_t
Structure for setting up each GPIO pin configuration.
Functions
-
rs_ret_val_t rs_gpio_callback_enable()
Enables the GPIO callback.
This function enables the GPIO callback.
- Parameters:
None – [in]
- Returns:
0 on success or error code on failure
-
rs_ret_val_t rs_gpio_configure_pin(rs_gpio_pin_config_t *ptr_config)
Configures the GPIO port pin.
This function configures/reconfigures the port pin as per the given configuration
- Parameters:
ptr_config – [in] - Pointer to the configuration structure
- Returns:
0 on success or error code on failure
-
rs_ret_val_t rs_gpio_configure_pins(rs_gpio_pin_config_t *ptr_config, uint32_t u32_count)
Configures the arrary of GPIO port pins.
This function configures/reconfigured the port pins as per the given configuration in array format
- Parameters:
ptr_config – [in] - Pointer to the configuration structures
u32_count – [in] - Number of pins to configure
- Returns:
0 on success or error code on failure
-
rs_ret_val_t rs_gpio_set_pin_level(uint8_t u8_port_index, uint8_t u8_pin, uint8_t u8_level)
Sets the output level of the GPIO pin.
This function sets the output level of the GPIO port to the given level
- Parameters:
u8_port_index – [in] - Index to the port
u8_pin – [in] - Pin number inside the port
u8_level – [in] - Output level to set to
- Returns:
0 on success or error code on failure
-
uint8_t rs_gpio_get_pin_level(uint8_t u8_port_index, uint8_t u8_pin)
Gets the input level of the GPIO pin.
This function gets the input level of the given GPIO port
- Parameters:
u8_port_index – [in] - Index to the port
u8_pin – [in] - Pin number inside the port
- Returns:
Input level of the pin
-
rs_ret_val_t rs_gpio_set_port_levels(uint8_t u8_port_index, uint32_t u32_levels)
Sets the output levels of the GPIO port group.
This function sets the output level of the GPIO port to the given levels
- Parameters:
u8_port_index – [in] - Index to the port
u32_levels – [in] - Output levels to set to mapped to each bit
- Returns:
0 on success or error code on failure
-
uint32_t rs_gpio_get_port_levels(uint8_t u8_port_index)
Gets the input levels of the GPIO port.
This function gets the input levels of the given GPIO port
- Parameters:
u8_port_index – [in] - Index to the port
- Returns:
Input level of the pins mapped to each bit
-
rs_ret_val_t rs_gpio_register_interrupt_callback(rs_gpio_pin_config_t *ptr_config, rs_gpio_callback_pin_interrupt ptr_func)
-
struct tag_rs_gpio_pin_config
- #include <rs_gpio.h>
Structure for setting up each GPIO pin configuration.
Public Members
-
uint8_t port_index
Index to GPIO port group as defined by underlying HAL layer.
-
uint8_t pin
Pin number inside the group.
-
uint8_t direction
Pin Direction.
-
uint8_t pull
Pull direction.
-
uint8_t alt_func
Alternate function as defined by underlying HAL.
-
uint8_t drive_type
Drive strength/type function as defined by underlying HAL.
-
uint8_t interrupt
Trigger interrupt from pin change.
-
uint8_t level
Pin level to set to.
-
uint16_t debounce
Debounce Time for inputs.
-
uint8_t wakeup
Pin set for wakeup.
-
uint8_t sleep_mode
Setting for sleep mode.
-
rs_gpio_callback_pin_interrupt ptr_cb_completion
Callback for pin interrupt.
-
uint8_t port_index