General Purpose I/O driver interface.
The GPIO header file should be included in an application as follows:
The GPIO module allows you to manage General Purpose I/O pins via simple and portable APIs. GPIO pin behavior is usually configured statically, but can also be configured or reconfigured at runtime.
Because of its simplicity, the GPIO driver does not follow the model of other TI-RTOS drivers in which a driver application interface has separate device-specific implementations. This difference is most apparent in the GPIOxxx_Config structure, which does not require you to specify a particular function table or object.
This section provides a basic usage summary and a set of examples in the form of commented code fragments. Detailed descriptions of the GPIO APIs and their effect are provided in subsequent sections.
Creating an input callback: The following example demonstrates how to configure a GPIO pin to generate an interrupt and how to toggle an an LED on and off within the registered interrupt callback function.
Runtime pin configuration: The following example demonstrates how to (re)configure GPIO pins.
In order to use the GPIO APIs, the application is required to provide 3 structures in the ti_drivers_config.c file:
GPIO_init() must be called before any other GPIO APIs. This function configures each GPIO pin in the user-provided GPIO_PinConfig array according to the defined settings. The user can also reconfigure a pin dynamically after GPIO_init() is called by using the GPIO_setConfig(), and GPIO_setCallback() APIs.
Unlike most other TI-RTOS drivers, the GPIO driver has no generic function table with pointers to device-specific API implementations. All the generic GPIO APIs are implemented by the device-specific GPIO driver module. Additionally, there is no notion of an instance 'handle' with the GPIO driver.
GPIO pins are referenced by their numeric index in the GPIO_PinConfig array. This design approach was used to enhance runtime and memory efficiency.
#include <stdint.h>
Go to the source code of this file.
Macros | |
GPIO_STATUS_* macros are general status codes returned by GPIO driver APIs. | |
#define | GPIO_STATUS_RESERVED (-32) |
Common GPIO status code reservation offset. More... | |
#define | GPIO_STATUS_SUCCESS (0) |
Successful status code returned by GPI_setConfig(). More... | |
#define | GPIO_STATUS_ERROR (-1) |
Generic error status code returned by GPI_setConfig(). More... | |
GPIO_PinConfig output pin configuration macros | |
#define | GPIO_CFG_OUTPUT |
#define | GPIO_CFG_OUT_STD |
#define | GPIO_CFG_OUT_OD_NOPULL |
#define | GPIO_CFG_OUT_OD_PU |
#define | GPIO_CFG_OUT_OD_PD |
#define | GPIO_CFG_OUT_STR_LOW |
#define | GPIO_CFG_OUT_STR_MED |
#define | GPIO_CFG_OUT_STR_HIGH |
#define | GPIO_CFG_OUT_HIGH |
#define | GPIO_CFG_OUT_LOW |
GPIO_PinConfig input pin configuration macros | |
#define | GPIO_CFG_INPUT |
#define | GPIO_CFG_IN_NOPULL |
#define | GPIO_CFG_IN_PU |
#define | GPIO_CFG_IN_PD |
GPIO_PinConfig interrupt configuration macros | |
#define | GPIO_CFG_IN_INT_NONE |
#define | GPIO_CFG_IN_INT_FALLING |
#define | GPIO_CFG_IN_INT_RISING |
#define | GPIO_CFG_IN_INT_BOTH_EDGES |
#define | GPIO_CFG_IN_INT_LOW |
#define | GPIO_CFG_IN_INT_HIGH |
Special GPIO_PinConfig configuration macros | |
#define | GPIO_CFG_IN_INT_ONLY |
'Or' in this GPIO_PinConfig definition to inform GPIO_setConfig() to only configure the interrupt attributes of a GPIO input pin. More... | |
#define | GPIO_DO_NOT_CONFIG |
Use this GPIO_PinConfig definition to inform GPIO_init() NOT to configure the corresponding pin. More... | |
Typedefs | |
typedef uint32_t | GPIO_PinConfig |
GPIO pin configuration settings. More... | |
typedef void(* | GPIO_CallbackFxn) (uint_least8_t index) |
GPIO callback function type. More... | |
Functions | |
void | GPIO_clearInt (uint_least8_t index) |
Clear a GPIO pin interrupt flag. More... | |
void | GPIO_disableInt (uint_least8_t index) |
Disable a GPIO pin interrupt. More... | |
void | GPIO_enableInt (uint_least8_t index) |
Enable a GPIO pin interrupt. More... | |
void | GPIO_getConfig (uint_least8_t index, GPIO_PinConfig *pinConfig) |
Get the current configuration for a gpio pin. More... | |
void | GPIO_init () |
Initializes the GPIO module. More... | |
uint_fast8_t | GPIO_read (uint_least8_t index) |
Reads the value of a GPIO pin. More... | |
void | GPIO_setCallback (uint_least8_t index, GPIO_CallbackFxn callback) |
Bind a callback function to a GPIO pin interrupt. More... | |
int_fast16_t | GPIO_setConfig (uint_least8_t index, GPIO_PinConfig pinConfig) |
Configure the gpio pin. More... | |
void | GPIO_toggle (uint_least8_t index) |
Toggles the current state of a GPIO. More... | |
void | GPIO_write (uint_least8_t index, unsigned int value) |
Writes the value to a GPIO pin. More... | |
#define GPIO_STATUS_RESERVED (-32) |
Common GPIO status code reservation offset.
GPIO driver implementations should offset status codes with GPIO_STATUS_RESERVED growing negatively.
Example implementation specific status codes:
#define GPIO_STATUS_SUCCESS (0) |
Successful status code returned by GPI_setConfig().
GPI_setConfig() returns GPIO_STATUS_SUCCESS if the API was executed successfully.
#define GPIO_STATUS_ERROR (-1) |
Generic error status code returned by GPI_setConfig().
GPI_setConfig() returns GPIO_STATUS_ERROR if the API was not executed successfully.
typedef uint32_t GPIO_PinConfig |
GPIO pin configuration settings.
The upper 16 bits of the 32 bit PinConfig is reserved for pin configuration settings.
The lower 16 bits are reserved for device-specific port/pin identifications
typedef void(* GPIO_CallbackFxn) (uint_least8_t index) |
GPIO callback function type.
index | GPIO index. This is the same index that was passed to GPIO_setCallback(). This allows you to use the same callback function for multiple GPIO interrupts, by using the index to identify the GPIO that caused the interrupt. |
void GPIO_clearInt | ( | uint_least8_t | index | ) |
Clear a GPIO pin interrupt flag.
Clears the GPIO interrupt for the specified index.
Note: It is not necessary to call this API within a callback assigned to a pin.
index | GPIO index |
void GPIO_disableInt | ( | uint_least8_t | index | ) |
Disable a GPIO pin interrupt.
Disables interrupts for the specified GPIO index.
index | GPIO index |
void GPIO_enableInt | ( | uint_least8_t | index | ) |
Enable a GPIO pin interrupt.
Enables GPIO interrupts for the selected index to occur.
Note: Prior to enabling a GPIO pin interrupt, make sure that a corresponding callback function has been provided. Use the GPIO_setCallback() API for this purpose at runtime. Alternatively, the callback function can be statically configured in the GPIO_CallbackFxn array provided.
index | GPIO index |
void GPIO_getConfig | ( | uint_least8_t | index, |
GPIO_PinConfig * | pinConfig | ||
) |
Get the current configuration for a gpio pin.
The pin configuration is provided in the static GPIO_PinConfig array, but can be changed with GPIO_setConfig(). GPIO_getConfig() gets the current pin configuration.
index | GPIO index |
pinConfig | Location to store device specific pin configuration settings |
void GPIO_init | ( | ) |
Initializes the GPIO module.
The pins defined in the application-provided GPIOXXX_config structure are initialized accordingly.
uint_fast8_t GPIO_read | ( | uint_least8_t | index | ) |
Reads the value of a GPIO pin.
The value returned will either be zero or one depending on the state of the pin.
index | GPIO index |
void GPIO_setCallback | ( | uint_least8_t | index, |
GPIO_CallbackFxn | callback | ||
) |
Bind a callback function to a GPIO pin interrupt.
Associate a callback function with a particular GPIO pin interrupt.
Callbacks can be changed at any time, making it easy to switch between efficient, state-specific interrupt handlers.
Note: The callback function is called within the context of an interrupt handler.
Note: This API does not enable the GPIO pin interrupt. Use GPIO_enableInt() and GPIO_disableInt() to enable and disable the pin interrupt as necessary.
Note: it is not necessary to call GPIO_clearInt() within a callback. That operation is performed internally before the callback is invoked.
index | GPIO index |
callback | address of the callback function |
int_fast16_t GPIO_setConfig | ( | uint_least8_t | index, |
GPIO_PinConfig | pinConfig | ||
) |
Configure the gpio pin.
Dynamically configure a gpio pin to a device specific setting. For many applications, the pin configurations provided in the static GPIO_PinConfig array is sufficient.
For input pins with interrupt configurations, a corresponding interrupt object will be created as needed.
index | GPIO index |
pinConfig | device specific pin configuration settings |
void GPIO_toggle | ( | uint_least8_t | index | ) |
Toggles the current state of a GPIO.
index | GPIO index |
void GPIO_write | ( | uint_least8_t | index, |
unsigned int | value | ||
) |
Writes the value to a GPIO pin.
index | GPIO index |
value | must be either 0 or 1 |