TI-RTOS Drivers  tidrivers_full_2_20_00_08
Typedefs | Functions
GPIO.h File Reference

Detailed Description

GPIO driver.

============================================================================

The GPIO header file should be included in an application as follows:

Operation

The GPIO module allows you to manage General Purpose I/O pins via simple and portable APIs. GPIO pin behaviour can be configured completely statically, or dynamically defined at runtime.

The application is required to supply a device specific GPIOXXX_Config structure to the module. This structure communicates to the GPIO module how to configure the pins that will be used by the application (See the description of GPIO_PinConfig).

The application is required to call GPIO_init(). This function will initialize all the GPIO pins defined in the GPIO_PinConfig table to the configurations specified. Once that is completed the other APIs can be used to access the pins.

Asserts are used to verify that the driver has been initialized and to validate pin indexes within the various APIs.

See the device specific GPIO header file for configuration details.


#include <stdint.h>
Include dependency graph for GPIO.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

GPIO_PinConfig pin direction configuration macros
#define GPIO_CFG_OUTPUT   (((uint32_t) 0) << GPIO_CFG_IO_LSB) /*! Pin is an output. */
 
#define GPIO_CFG_OUT_STD   (((uint32_t) 0) << GPIO_CFG_IO_LSB) /*! Output pin is not Open Drain */
 
#define GPIO_CFG_OUT_OD_NOPULL   (((uint32_t) 2) << GPIO_CFG_IO_LSB) /*! Output pin is Open Drain */
 
#define GPIO_CFG_OUT_OD_PU   (((uint32_t) 4) << GPIO_CFG_IO_LSB) /*! Output pin is Open Drain w/ pull up */
 
#define GPIO_CFG_OUT_OD_PD   (((uint32_t) 6) << GPIO_CFG_IO_LSB) /*! Output pin is Open Drain w/ pull dn */
 
#define GPIO_CFG_OUT_HIGH   (((uint32_t) 1) << GPIO_CFG_OUT_BIT) /*! Set pin's output to 1. */
 
#define GPIO_CFG_OUT_LOW   (((uint32_t) 0) << GPIO_CFG_OUT_BIT) /*! Set pin's output to 0. */
 
#define GPIO_CFG_OUT_STR_LOW   (((uint32_t) 0) << GPIO_CFG_OUT_STRENGTH_LSB)
 
#define GPIO_CFG_OUT_STR_MED   (((uint32_t) 1) << GPIO_CFG_OUT_STRENGTH_LSB)
 
#define GPIO_CFG_OUT_STR_HIGH   (((uint32_t) 2) << GPIO_CFG_OUT_STRENGTH_LSB)
 
#define GPIO_CFG_INPUT   (((uint32_t) 1) << GPIO_CFG_IO_LSB) /*! Pin is an input. */
 
#define GPIO_CFG_IN_NOPULL   (((uint32_t) 1) << GPIO_CFG_IO_LSB) /*! Input pin with no internal PU/PD */
 
#define GPIO_CFG_IN_PU   (((uint32_t) 3) << GPIO_CFG_IO_LSB) /*! Input pin with internal PU */
 
#define GPIO_CFG_IN_PD   (((uint32_t) 5) << GPIO_CFG_IO_LSB) /*! Input pin with internal PD */
 
GPIO_PinConfig pin interrupt configuration macros
#define GPIO_CFG_IN_INT_NONE   (((uint32_t) 0) << GPIO_CFG_INT_LSB) /*! No Interrupt */
 
#define GPIO_CFG_IN_INT_FALLING   (((uint32_t) 1) << GPIO_CFG_INT_LSB) /*! Interrupt on falling edge */
 
#define GPIO_CFG_IN_INT_RISING   (((uint32_t) 2) << GPIO_CFG_INT_LSB) /*! Interrupt on rising edge */
 
#define GPIO_CFG_IN_INT_BOTH_EDGES   (((uint32_t) 3) << GPIO_CFG_INT_LSB) /*! Interrupt on both edges */
 
#define GPIO_CFG_IN_INT_LOW   (((uint32_t) 4) << GPIO_CFG_INT_LSB) /*! Interrupt on low level */
 
#define GPIO_CFG_IN_INT_HIGH   (((uint32_t) 5) << GPIO_CFG_INT_LSB) /*! Interrupt on high level */
 
Special GPIO_PinConfig configuration macros
#define GPIO_CFG_IN_INT_ONLY   (((uint32_t) 1) << 27) /*! configure interrupt 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   0x40000000 /*! Do not configure this Pin */
 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) (unsigned int index)
 GPIO callback function type. More...
 

Functions

void GPIO_clearInt (unsigned int index)
 Clear a GPIO pin interrupt flag. More...
 
void GPIO_disableInt (unsigned int index)
 Disable a GPIO pin interrupt. More...
 
void GPIO_enableInt (unsigned int index)
 Enable a GPIO pin interrupt. More...
 
void GPIO_init ()
 Initializes the GPIO module. More...
 
unsigned int GPIO_read (unsigned int index)
 Reads the value of a GPIO pin. More...
 
void GPIO_setCallback (unsigned int index, GPIO_CallbackFxn callback)
 Bind a callback function to a GPIO pin interrupt. More...
 
void GPIO_setConfig (unsigned int index, GPIO_PinConfig pinConfig)
 Configure the gpio pin. More...
 
void GPIO_toggle (unsigned int index)
 Toggles the current state of a GPIO. More...
 
void GPIO_write (unsigned int index, unsigned int value)
 Writes the value to a GPIO pin. More...
 

Macro Definition Documentation

#define GPIO_CFG_OUTPUT   (((uint32_t) 0) << GPIO_CFG_IO_LSB) /*! Pin is an output. */
#define GPIO_CFG_OUT_STD   (((uint32_t) 0) << GPIO_CFG_IO_LSB) /*! Output pin is not Open Drain */
#define GPIO_CFG_OUT_OD_NOPULL   (((uint32_t) 2) << GPIO_CFG_IO_LSB) /*! Output pin is Open Drain */
#define GPIO_CFG_OUT_OD_PU   (((uint32_t) 4) << GPIO_CFG_IO_LSB) /*! Output pin is Open Drain w/ pull up */
#define GPIO_CFG_OUT_OD_PD   (((uint32_t) 6) << GPIO_CFG_IO_LSB) /*! Output pin is Open Drain w/ pull dn */
#define GPIO_CFG_OUT_HIGH   (((uint32_t) 1) << GPIO_CFG_OUT_BIT) /*! Set pin's output to 1. */
#define GPIO_CFG_OUT_LOW   (((uint32_t) 0) << GPIO_CFG_OUT_BIT) /*! Set pin's output to 0. */
#define GPIO_CFG_OUT_STR_LOW   (((uint32_t) 0) << GPIO_CFG_OUT_STRENGTH_LSB)
#define GPIO_CFG_OUT_STR_MED   (((uint32_t) 1) << GPIO_CFG_OUT_STRENGTH_LSB)
#define GPIO_CFG_OUT_STR_HIGH   (((uint32_t) 2) << GPIO_CFG_OUT_STRENGTH_LSB)
#define GPIO_CFG_INPUT   (((uint32_t) 1) << GPIO_CFG_IO_LSB) /*! Pin is an input. */
#define GPIO_CFG_IN_NOPULL   (((uint32_t) 1) << GPIO_CFG_IO_LSB) /*! Input pin with no internal PU/PD */
#define GPIO_CFG_IN_PU   (((uint32_t) 3) << GPIO_CFG_IO_LSB) /*! Input pin with internal PU */
#define GPIO_CFG_IN_PD   (((uint32_t) 5) << GPIO_CFG_IO_LSB) /*! Input pin with internal PD */
#define GPIO_CFG_IN_INT_NONE   (((uint32_t) 0) << GPIO_CFG_INT_LSB) /*! No Interrupt */
#define GPIO_CFG_IN_INT_FALLING   (((uint32_t) 1) << GPIO_CFG_INT_LSB) /*! Interrupt on falling edge */
#define GPIO_CFG_IN_INT_RISING   (((uint32_t) 2) << GPIO_CFG_INT_LSB) /*! Interrupt on rising edge */
#define GPIO_CFG_IN_INT_BOTH_EDGES   (((uint32_t) 3) << GPIO_CFG_INT_LSB) /*! Interrupt on both edges */
#define GPIO_CFG_IN_INT_LOW   (((uint32_t) 4) << GPIO_CFG_INT_LSB) /*! Interrupt on low level */
#define GPIO_CFG_IN_INT_HIGH   (((uint32_t) 5) << GPIO_CFG_INT_LSB) /*! Interrupt on high level */
#define GPIO_CFG_IN_INT_ONLY   (((uint32_t) 1) << 27) /*! configure interrupt only */

'Or' in this GPIO_PinConfig definition to inform GPIO_setConfig() to only configure the interrupt attributes of a GPIO input pin.

#define GPIO_DO_NOT_CONFIG   0x40000000 /*! Do not configure this Pin */

Use this GPIO_PinConfig definition to inform GPIO_init() NOT to configure the corresponding pin.

Typedef Documentation

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) (unsigned int index)

GPIO callback function type.

Parameters
indexGPIO 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.

Function Documentation

void GPIO_clearInt ( unsigned int  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.

Parameters
indexGPIO index
void GPIO_disableInt ( unsigned int  index)

Disable a GPIO pin interrupt.

Disables interrupts for the specified GPIO index.

Parameters
indexGPIO index
void GPIO_enableInt ( unsigned int  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.

Parameters
indexGPIO index
void GPIO_init ( )

Initializes the GPIO module.

The pins defined in the application-provided GPIOXXX_config structure are initialized accordingly.

Precondition
The GPIO_config structure must exist and be persistent before this function can be called. This function must also be called before any other GPIO driver APIs.
unsigned int GPIO_read ( unsigned int  index)

Reads the value of a GPIO pin.

The value returned will either be zero or one depending on the state of the pin.

Parameters
indexGPIO index
Returns
0 or 1, depending on the state of the pin.
void GPIO_setCallback ( unsigned int  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.

Parameters
indexGPIO index
callbackaddress of the callback function
void GPIO_setConfig ( unsigned int  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.

Parameters
indexGPIO index
pinConfigdevice specific pin configuration settings
void GPIO_toggle ( unsigned int  index)

Toggles the current state of a GPIO.

Parameters
indexGPIO index
void GPIO_write ( unsigned int  index,
unsigned int  value 
)

Writes the value to a GPIO pin.

Parameters
indexGPIO index
valuemust be either 0 or 1
Copyright 2016, Texas Instruments Incorporated