GPIO HAL

The GPIO HAL definitions are in dev_gpio.h, it provides interfaces for gpio driver to implement. Here is a diagram for the gpio interface.

GPIO HAL

Definitions

group DEVICE_HAL_GPIO_DEVSTRUCT

contains definitions of gpio device structure.

This structure will be used in user implemented code, which was called Device Driver Implement Layer for gpio to use in implementation code. Application developer should use the GPIO API provided here to access to GPIO devices. BSP developer should follow the API definition to implement GPIO device drivers.

Defines

DEV_GPIO_INFO_SET_EXTRA_OBJECT(gpio_info_ptr, extra_info)

Set extra information pointer of gpio info.

DEV_GPIO_INFO_GET_EXTRA_OBJECT(gpio_info_ptr)

Get extra information pointer of gpio info.

DEV_GPIO_BITS_MTHD_POLL

Method of all gpio bits set to poll.

DEV_GPIO_BITS_MTHD_INTERRUPT

Method of all gpio bits set to interrupt.

DEV_GPIO_BITS_MTHD_DEFAULT

Default method of all gpio bits should be poll for first open.

Typedefs

typedef struct dev_gpio_info DEV_GPIO_INFO

gpio information struct definition

Informations about gpio open count, working status gpio registers and control block, gpio io direction and interrupt/poll for each bit of gpio

Note

Only available for gpio with max 32bits

typedef struct dev_gpio_info *DEV_GPIO_INFO_PTR
typedef struct dev_gpio DEV_GPIO

gpio device interface definition

Define gpio device interface, like gpio information structure, fuctions to open/close/control gpio, write or read data via gpio

Note

All this details are implemented by user in user porting code

typedef struct dev_gpio *DEV_GPIO_PTR

Variables

int32_t (*gpio_open)(uint32_t dir)

open gpio device with pre-defined gpio direction

Open a gpio device with pre-defined io direction.

Parameters
  • [in] dir: gpio direction for each bit

Return Value
  • E_OK: Open successfully without any issues

  • E_OPNED: If device was opened before with different parameters, then just increase the opn_cnt and return E_OPNED

  • E_OBJ: Device object is not valid

  • E_PAR: Parameter is not valid

  • E_NOSPT: Open settings are not supported

int32_t (*gpio_close)(void)

close gpio device

Close a gpio device, just decrease the opn_cnt, if opn_cnt equals 0, then close the device

Return Value
  • E_OK: Close successfully without any issues(including scenario that device is already closed)

  • E_OPNED: Device is still opened, the device opn_cnt decreased by 1

  • E_OBJ: Device object is not valid

int32_t (*gpio_control)(uint32_t ctrl_cmd, void *param)

control gpio device

Control an gpio device by ctrl_cmd, with passed param. you can control gpio device using predefined gpio control commands defined using DEV_SET_SYSCMD (which must be implemented by bsp developer), such as change masked gpio direction to input, and more. And you can also control gpio device using your own specified commands defined using DEV_SET_USRCMD, but these specified commands should be defined in your own gpio device driver implementation.

Parameters
  • [in] ctrl_cmd: control command, to change or get some thing related to gpio

  • [inout] param: parameters that maybe argument of the command, or return values of the command

Return Value
  • E_OK: Control device successfully

  • E_CLSED: Device is not opened

  • E_OBJ: Device object is not valid or not exists

  • E_PAR: Parameter is not valid for current control command

  • E_SYS: Control device failed, due to hardware issues

  • E_CTX: Control device failed, due to different reasons like in transfer state

  • E_NOSPT: Control command is not supported or not valid, such as interrupt is not supported

int32_t (*gpio_write)(uint32_t val, uint32_t mask)

write gpio device with val, only write the masked bits

Write gpio with val, and only change the masked bits of gpio.

Parameters
  • [in] val: the data that need to write to gpio

  • [in] mask: gpio bit mask

Return Value
  • E_OK: Write gpio with specified value successfully

  • E_OBJ: Device object is not valid or not exists

  • E_PAR: Parameter is not valid

int32_t (*gpio_read)(uint32_t *val, uint32_t mask)

read gpio device val, only read the masked bits

Read the masked gpio value

Parameters
  • [out] val: pointer to data need to read from gpio

  • [in] mask: gpio bit mask

Return Value
  • E_OK: Read gpio data successfully

  • E_OBJ: Device object is not valid or not exists

  • E_PAR: Parameter is not valid

struct dev_gpio_info
#include <dev_gpio.h>

gpio information struct definition

Informations about gpio open count, working status gpio registers and control block, gpio io direction and interrupt/poll for each bit of gpio

Note

Only available for gpio with max 32bits

struct dev_gpio
#include <dev_gpio.h>

gpio device interface definition

Define gpio device interface, like gpio information structure, fuctions to open/close/control gpio, write or read data via gpio

Note

All this details are implemented by user in user porting code