FreeRTOS: Common I/O
AWS IoT Common I/O library
Return to main page ↑
GPIO HAL APIs

Macros

#define IOT_GPIO_SUCCESS   ( 0 )
 Error codes. More...
 
#define IOT_GPIO_INVALID_VALUE   ( 1 )
 
#define IOT_GPIO_READ_FAILED   ( 2 )
 
#define IOT_GPIO_WRITE_FAILED   ( 3 )
 
#define IOT_GPIO_FUNCTION_NOT_SUPPORTED   ( 4 )
 

Typedefs

typedef struct IotGpioDescriptor * IotGpioHandle_t
 IotGpioHandle_t type is the GPIO handle returned by calling iot_gpio_open() this is initialized in open and returned to caller. Caller must pass this pointer to the rest of the APIs.
 
typedef void(* IotGpioCallback_t) (uint8_t ucPinState, void *pvUserContext)
 GPIO interrupt callback type. This callback is passed to the driver by using iot_gpio_set_callback API. More...
 

Enumerations

enum  IotGpioDirection_t { eGpioDirectionInput, eGpioDirectionOutput }
 enum for configuring GPIO input/output direction. More...
 
enum  IotGpioOutputMode_t { eGpioOpenDrain, eGpioPushPull }
 enum for configuring GPIO output type. More...
 
enum  IotGpioPull_t { eGpioPullNone, eGpioPullUp, eGpioPullDown }
 GPIO pin internal pull state. Sets the default state for output pins. More...
 
enum  IotGpioInterrupt_t {
  eGpioInterruptNone, eGpioInterruptRising, eGpioInterruptFalling, eGpioInterruptEdge,
  eGpioInterruptLow, eGpioInterruptHigh
}
 GPIO pin interrupt config types. More...
 
enum  IotGpioIoctlRequest_t {
  eSetGpioFunction, eSetGpioDirection, eSetGpioPull, eSetGpioOutputMode,
  eSetGpioInterrupt, eSetGpioSpeed, eSetGpioDriveStrength, eGetGpioFunction,
  eGetGpioDirection, eGetGpioPull, eGetGpioOutputType, eGetGpioInterrupt,
  eGetGpioSpeed, eGetGpioDriveStrength
}
 Ioctl request types. More...
 

Functions

IotGpioHandle_t iot_gpio_open (int32_t lGpioNumber)
 iot_gpio_open is used to open the GPIO handle. The application must call this function to open desired GPIO and use other functions. More...
 
void iot_gpio_set_callback (IotGpioHandle_t const pxGpio, IotGpioCallback_t xGpioCallback, void *pvUserContext)
 iot_gpio_set_callback is used to set the callback to be called when an interrupt is tirggered. More...
 
int32_t iot_gpio_read_sync (IotGpioHandle_t const pxGpio, uint8_t *pucPinState)
 iot_gpio_read_sync is used to read data from GPIO pin in blocking mode. More...
 
int32_t iot_gpio_write_sync (IotGpioHandle_t const pxGpio, uint8_t ucPinState)
 iot_gpio_write_sync is used to write data into the GPIO pin in blocking mode. More...
 
int32_t iot_gpio_close (IotGpioHandle_t const pxGpio)
 iot_gpio_close is used to deinitializes the GPIO pin to default value and close the handle. The application should call this function to reset and deinitialize the GPIO pin. More...
 
int32_t iot_gpio_ioctl (IotGpioHandle_t const pxGpio, IotGpioIoctlRequest_t xRequest, void *const pvBuffer)
 iot_gpio_ioctl is used to configure GPIO pin options. The application should call this function to configure various GPIO pin options: pin function, I/O direction, pin internal pull mode, drive strength, slew rate etc More...
 

Detailed Description

Macro Definition Documentation

◆ IOT_GPIO_SUCCESS

#define IOT_GPIO_SUCCESS   ( 0 )

Error codes.

GPIO operation completed succesfully.

◆ IOT_GPIO_INVALID_VALUE

#define IOT_GPIO_INVALID_VALUE   ( 1 )

At least one parameter is invalid.

◆ IOT_GPIO_READ_FAILED

#define IOT_GPIO_READ_FAILED   ( 2 )

GPIO read operation failed.

◆ IOT_GPIO_WRITE_FAILED

#define IOT_GPIO_WRITE_FAILED   ( 3 )

GPIO write operation failed.

◆ IOT_GPIO_FUNCTION_NOT_SUPPORTED

#define IOT_GPIO_FUNCTION_NOT_SUPPORTED   ( 4 )

GPIO operation not supported.

Typedef Documentation

◆ IotGpioCallback_t

typedef void( * IotGpioCallback_t) (uint8_t ucPinState, void *pvUserContext)

GPIO interrupt callback type. This callback is passed to the driver by using iot_gpio_set_callback API.

Parameters
[out]ucPinStateThe variable which has state of the GPIO pin.
[in]pvUserContextUser Context passed when setting the callback. This is not used by the driver, but just passed back to the user in the callback.

Enumeration Type Documentation

◆ IotGpioDirection_t

enum for configuring GPIO input/output direction.

Enumerator
eGpioDirectionInput 

Configure GPIO pin direction for input.

eGpioDirectionOutput 

Configure GPIO pin direction for output.

◆ IotGpioOutputMode_t

enum for configuring GPIO output type.

Enumerator
eGpioOpenDrain 

Configure GPIO pin mode as open drain.

eGpioPushPull 

Configure GPIO pin mode as push pull.

◆ IotGpioPull_t

GPIO pin internal pull state. Sets the default state for output pins.

Enumerator
eGpioPullNone 

Configure GPIO pin with no pull direction.

eGpioPullUp 

Configure GPIO pin as pull up.

eGpioPullDown 

Configure GPIO pin as pull down.

◆ IotGpioInterrupt_t

GPIO pin interrupt config types.

Enumerator
eGpioInterruptNone 

Configure GPIO pin to not generate an interrupt.

eGpioInterruptRising 

Configure GPIO pin to generate an interrupt when signal rises.

eGpioInterruptFalling 

Configure GPIO pin to generate an interrupt when signal falls.

eGpioInterruptEdge 

Configure GPIO pin to generate an interrupt when either rising or falling.

eGpioInterruptLow 

Configure GPIO pin to generate an interrupt when signal is low.

eGpioInterruptHigh 

Configure GPIO pin to generate an interrupt when signal is high.

◆ IotGpioIoctlRequest_t

Ioctl request types.

Enumerator
eSetGpioFunction 

Set GPIO function. Takes int32_t as input to set the alternate function. The value of the alternate function depends on the HW

eSetGpioDirection 

Set GPIO Direction. Takes input type IotGpioDirection_t

eSetGpioPull 

Set GPIO Pull mode. Takes input type IotGpioPull_t

eSetGpioOutputMode 

Set GPIO output type. Takes input type IotGpioOutputType_t

eSetGpioInterrupt 

Set GPIO Interrupt type. This configures the GPIO to generate an interrupt based on the configuration. Takes input type IotGpioInterrupt_t

eSetGpioSpeed 

Set GPIO Speed. Takes a int32_t value based on the underlying HW support

eSetGpioDriveStrength 

Set GPIO Drive Strength. Takes an int32_t value based on the underlying HW support

eGetGpioFunction 

Get GPIO function setting. Returns an int32_t

eGetGpioDirection 

Get GPIO Direction setting. Returns IotGpioDirection_t

eGetGpioPull 

Get GPIO Pull mode setting. Returns IotGpioPull_t

eGetGpioOutputType 

Get GPIO output type. Returns IotGpioOutputType_t

eGetGpioInterrupt 

Get GPIO Interrupt config. Returns IotGpioInterrupt_t type

eGetGpioSpeed 

Get GPIO Speed setting. Returns an int32_t type

eGetGpioDriveStrength 

Get GPIO Drive Strength. Returns int32_t type

Function Documentation

◆ iot_gpio_open()

IotGpioHandle_t iot_gpio_open ( int32_t  lGpioNumber)

iot_gpio_open is used to open the GPIO handle. The application must call this function to open desired GPIO and use other functions.

Parameters
[in]lGpioNumberThe logical GPIO number to open. It depends on the implementation to map logical GPIO number to physical GPIO port and pin.
Returns
  • handle to the GPIO peripheral if everything succeeds
  • NULL, if
    • invalid instance number
    • open same instance more than once before closing it.

◆ iot_gpio_set_callback()

void iot_gpio_set_callback ( IotGpioHandle_t const  pxGpio,
IotGpioCallback_t  xGpioCallback,
void *  pvUserContext 
)

iot_gpio_set_callback is used to set the callback to be called when an interrupt is tirggered.

Note
Single callback is used for both read_async and write_async. Newly set callback overrides the one previously set
This callback will not be invoked when synchronous operation completes.
This callback is per handle. Each instance has its own callback.
Warning
If input handle or if callback function is NULL, this function silently takes no action.
Parameters
[in]pxGpioThe GPIO handle returned in the open() call.
[in]xGpioCallbackThe callback function to be called on interrupt.
[in]pvUserContextThe user context to be passed back when callback is called.

◆ iot_gpio_read_sync()

int32_t iot_gpio_read_sync ( IotGpioHandle_t const  pxGpio,
uint8_t *  pucPinState 
)

iot_gpio_read_sync is used to read data from GPIO pin in blocking mode.

Parameters
[in]pxGpioThe GPIO handle returned in the open() call.
[out]pucPinStateThe variable which reads state of the GPIO pin.
Returns
  • IOT_GPIO_SUCCESS on success
  • IOT_GPIO_INVALID_VALUE if pxGpio or pucPinState are NULL
  • IOT_GPIO_READ_FAILED on failure.

◆ iot_gpio_write_sync()

int32_t iot_gpio_write_sync ( IotGpioHandle_t const  pxGpio,
uint8_t  ucPinState 
)

iot_gpio_write_sync is used to write data into the GPIO pin in blocking mode.

Parameters
[in]pxGpioThe GPIO handle returned in the open() call.
[in]ucStateThe value to write into the GPIO pin.
Returns
  • IOT_GPIO_SUCCESS on success
  • IOT_GPIO_INVALID_VALUE if pxGpio or pucPinState are NULL
  • IOT_GPIO_WRITE_FAILED on failure.

◆ iot_gpio_close()

int32_t iot_gpio_close ( IotGpioHandle_t const  pxGpio)

iot_gpio_close is used to deinitializes the GPIO pin to default value and close the handle. The application should call this function to reset and deinitialize the GPIO pin.

Parameters
[in]pxGpioThe GPIO handle returned in the open() call.
Returns
  • IOT_GPIO_SUCCESS on success
  • IOT_GPIO_INVALID_VALUE if
    • pxGpio handle is NULL
    • if is not in open state (already closed).

◆ iot_gpio_ioctl()

int32_t iot_gpio_ioctl ( IotGpioHandle_t const  pxGpio,
IotGpioIoctlRequest_t  xRequest,
void *const  pvBuffer 
)

iot_gpio_ioctl is used to configure GPIO pin options. The application should call this function to configure various GPIO pin options: pin function, I/O direction, pin internal pull mode, drive strength, slew rate etc

Parameters
[in]pxGpioThe GPIO handle returned in the open() call.
[in]xRequestOne of IotGpioIoctlRequest_t enum
[in/out]pvBuffer Buffer holding GPIO set or get values.
Returns
  • IOT_GPIO_SUCCESS on success
  • IOT_GPIO_INVALID_VALUE on NULL handle, invalid request, or NULL buffer when required.
  • IOT_GPIO_FUNCTION_NOT_SUPPORTED is only valid for
    • eSetGpioFunction / eGetGpioFunction
    • eSetGpioSpeed / eGetGpioSpeed
    • eSetGpioDriveStrength / eGetGpioDriveStrength
    • eSetGpioInterrupt / eGetGpioInterrupt