Wirepas SDK
gpio.h File Reference

Board-independent GPIO functions. More...

Detailed Description

Board-independent GPIO functions.

Definition in file gpio.h.

Go to the source code of this file.

Typedefs

typedef uint8_t gpio_id_t
 GPIO identification number. More...
 
typedef uint8_t gpio_port_t
 GPIO port number. More...
 
typedef uint8_t gpio_pin_t
 GPIO pin number. More...
 
typedef void(* gpio_in_event_cb_f) (gpio_id_t id, gpio_in_event_e event)
 Callback structure for a GPIO event. More...
 

Functions

gpio_res_e Gpio_init (void)
 Initialize GPIO module. More...
 
gpio_res_e Gpio_inputSetCfg (gpio_id_t id, const gpio_in_cfg_t *in_cfg)
 Configure a GPIO as an input GPIO. More...
 
gpio_res_e Gpio_inputRead (gpio_id_t id, gpio_level_e *level)
 Read the GPIO input level. More...
 
gpio_res_e Gpio_outputSetCfg (gpio_id_t id, const gpio_out_cfg_t *out_cfg)
 Configure a GPIO as an output GPIO. More...
 
gpio_res_e Gpio_outputWrite (gpio_id_t id, gpio_level_e level)
 Write GPIO output level. More...
 
gpio_res_e Gpio_outputToggle (gpio_id_t id)
 Toggle GPIO output level. More...
 
gpio_res_e Gpio_outputRead (gpio_id_t id, gpio_level_e *level)
 Read the GPIO output level. More...
 
gpio_res_e Gpio_getPin (gpio_id_t id, gpio_port_t *port, gpio_pin_t *pin)
 Get the GPIO port and pin numbers of the given GPIO id. More...
 
uint8_t Gpio_getNumber (void)
 Get the number of GPIOs. More...
 

Data Structures

struct  gpio_in_cfg_t
 GPIO input configuration. More...
 
struct  gpio_out_cfg_t
 GPIO output configuration. More...
 

Enumerations

enum  gpio_res_e {
  GPIO_RES_OK = 0, GPIO_RES_UNINITIALIZED = 1, GPIO_RES_NOT_IMPLEMENTED = 2, GPIO_RES_INVALID_PARAM = 3,
  GPIO_RES_INVALID_PIN = 4, GPIO_RES_INVALID_DIRECTION = 5, GPIO_RES_NO_FREE_IT = 6
}
 List of return code. More...
 
enum  gpio_level_e { GPIO_LEVEL_LOW, GPIO_LEVEL_HIGH }
 GPIO logical level. More...
 
enum  gpio_in_mode_cfg_e { GPIO_IN_DISABLED, GPIO_IN_PULL_NONE, GPIO_IN_PULL_DOWN, GPIO_IN_PULL_UP }
 GPIO pull configuration. More...
 
enum  gpio_out_mode_cfg_e { GPIO_OUT_MODE_PUSH_PULL, GPIO_OUT_MODE_OPEN_DRAIN, GPIO_OUT_MODE_OPEN_DRAIN_WITH_PULL_UP }
 GPIO operating mode configuration. More...
 
enum  gpio_in_event_e { GPIO_IN_EVENT_NONE = 0, GPIO_IN_EVENT_RISING_EDGE = 1U << 0U, GPIO_IN_EVENT_FALLING_EDGE = 1U << 1U }
 GPIO event. More...
 

Macros

#define IS_RISING_EDGE(event)   ((event & GPIO_IN_EVENT_RISING_EDGE) == GPIO_IN_EVENT_RISING_EDGE)
 Check if event has its rising edge bit set. More...
 
#define IS_FALLING_EDGE(event)   ((event & GPIO_IN_EVENT_FALLING_EDGE) == GPIO_IN_EVENT_FALLING_EDGE)
 Check if event has its falling edge bit set. More...
 

Typedef Documentation

◆ gpio_id_t

typedef uint8_t gpio_id_t

GPIO identification number.

Definition at line 18 of file gpio.h.

◆ gpio_in_event_cb_f

typedef void(* gpio_in_event_cb_f) (gpio_id_t id, gpio_in_event_e event)

Callback structure for a GPIO event.

Parameters
idId of the GPIO which raised the event
eventEvent raised

Definition at line 110 of file gpio.h.

◆ gpio_pin_t

typedef uint8_t gpio_pin_t

GPIO pin number.

Definition at line 24 of file gpio.h.

◆ gpio_port_t

typedef uint8_t gpio_port_t

GPIO port number.

Definition at line 21 of file gpio.h.

Function Documentation

◆ Gpio_getNumber()

uint8_t Gpio_getNumber ( void  )

Get the number of GPIOs.

Returns
Number of GPIOs

◆ Gpio_getPin()

gpio_res_e Gpio_getPin ( gpio_id_t  id,
gpio_port_t port,
gpio_pin_t pin 
)

Get the GPIO port and pin numbers of the given GPIO id.

Parameters
idId of the GPIO
[out]portReturned GPIO port number
[out]pinReturned GPIO pin number
Returns
Return code of operation

◆ Gpio_init()

gpio_res_e Gpio_init ( void  )

Initialize GPIO module.

Example on use:

void App_init(const app_global_functions_t * functions)
{
...
// Set up GPIOs first
...
Gpio_inputSetCfg(GPIO_INPUT_ID, &in_cfg);
...
Gpio_outputSetCfg(GPIO_OUTPUT_ID, &out_cfg);
...
}

◆ Gpio_inputRead()

gpio_res_e Gpio_inputRead ( gpio_id_t  id,
gpio_level_e level 
)

Read the GPIO input level.

Note
The GPIO should be configured as an input GPIO
Parameters
idId of the GPIO
[out]levelReturned GPIO level (low or high)
Returns
Return code of operation

◆ Gpio_inputSetCfg()

gpio_res_e Gpio_inputSetCfg ( gpio_id_t  id,
const gpio_in_cfg_t in_cfg 
)

Configure a GPIO as an input GPIO.

Parameters
idId of the GPIO
[in]in_cfgGPIO input configuration
Returns
Return code of operation

◆ Gpio_outputRead()

gpio_res_e Gpio_outputRead ( gpio_id_t  id,
gpio_level_e level 
)

Read the GPIO output level.

Note
The GPIO should be configured as an output GPIO
Parameters
idId of the GPIO
[out]levelReturned GPIO level (low or high)
Returns
Return code of operation

◆ Gpio_outputSetCfg()

gpio_res_e Gpio_outputSetCfg ( gpio_id_t  id,
const gpio_out_cfg_t out_cfg 
)

Configure a GPIO as an output GPIO.

Parameters
idId of the GPIO
[in]out_cfgGPIO output configuration
Returns
Return code of operation

◆ Gpio_outputToggle()

gpio_res_e Gpio_outputToggle ( gpio_id_t  id)

Toggle GPIO output level.

Note
The GPIO should be configured as an output GPIO
Parameters
idId of the GPIO
Returns
Return code of operation

◆ Gpio_outputWrite()

gpio_res_e Gpio_outputWrite ( gpio_id_t  id,
gpio_level_e  level 
)

Write GPIO output level.

Note
The GPIO should be configured as an output GPIO
Parameters
idId of the GPIO
levelGPIO level (low or high) to write
Returns
Return code of operation

Data Structure Documentation

◆ gpio_in_cfg_t

struct gpio_in_cfg_t

GPIO input configuration.

Definition at line 113 of file gpio.h.

Data Fields
gpio_in_event_cb_f event_cb

Callback called on GPIO events

gpio_in_event_e event_cfg: 2

Event configuration. Use | (OR) operator to detect both rising and falling edges. e.g.: .event_cfg = (GPIO_IN_EVENT_RISING_EDGE | GPIO_IN_EVENT_FALLING_EDGE)

gpio_in_mode_cfg_e in_mode_cfg: 2

Pull configuration (e.g.: Pull-down)

◆ gpio_out_cfg_t

struct gpio_out_cfg_t

GPIO output configuration.

Definition at line 128 of file gpio.h.

Data Fields
gpio_level_e level_default: 1

GPIO default logical level (e.g.: Low)

gpio_out_mode_cfg_e out_mode_cfg: 2

Operating mode configuration (e.g.: Push-pull)

Enumeration Type Documentation

◆ gpio_in_event_e

GPIO event.

Note
Used for input GPIOs
Enumerator
GPIO_IN_EVENT_NONE 

No event

GPIO_IN_EVENT_RISING_EDGE 

Rising edge event

GPIO_IN_EVENT_FALLING_EDGE 

Falling edge event

Definition at line 88 of file gpio.h.

89 {
93  GPIO_IN_EVENT_RISING_EDGE = 1U << 0U,
95  GPIO_IN_EVENT_FALLING_EDGE = 1U << 1U,

◆ gpio_in_mode_cfg_e

GPIO pull configuration.

Note
Used for input GPIOs
Enumerator
GPIO_IN_DISABLED 

input disabled

GPIO_IN_PULL_NONE 

No pull (floating if no external pull-up or pull-down)

GPIO_IN_PULL_DOWN 

Pull-down

GPIO_IN_PULL_UP 

Pull-up

Definition at line 58 of file gpio.h.

◆ gpio_level_e

GPIO logical level.

Enumerator
GPIO_LEVEL_LOW 

The GPIO is low

GPIO_LEVEL_HIGH 

The GPIO is high

Definition at line 46 of file gpio.h.

47 {
52 } gpio_level_e;

◆ gpio_out_mode_cfg_e

GPIO operating mode configuration.

Note
Used for output GPIOs
Enumerator
GPIO_OUT_MODE_PUSH_PULL 

Push-pull

GPIO_OUT_MODE_OPEN_DRAIN 

Open-drain

GPIO_OUT_MODE_OPEN_DRAIN_WITH_PULL_UP 

Open-drain with pull-up

Definition at line 74 of file gpio.h.

◆ gpio_res_e

enum gpio_res_e

List of return code.

Enumerator
GPIO_RES_OK 

Operation is successful

GPIO_RES_UNINITIALIZED 

GPIO iniatialization has not been performed

GPIO_RES_NOT_IMPLEMENTED 

GPIO HAL is not implemented. Weak definitions are used instead

GPIO_RES_INVALID_PARAM 

Invalid parameter(s)

GPIO_RES_INVALID_PIN 

Invalid pin number

GPIO_RES_INVALID_DIRECTION 

Invalid GPIO direction

GPIO_RES_NO_FREE_IT 

No free external interrupt: all of them are already in use. Note: Only used on SiLabs/EFR32 boards

Definition at line 27 of file gpio.h.

Macro Definition Documentation

◆ IS_FALLING_EDGE

#define IS_FALLING_EDGE (   event)    ((event & GPIO_IN_EVENT_FALLING_EDGE) == GPIO_IN_EVENT_FALLING_EDGE)

Check if event has its falling edge bit set.

Definition at line 101 of file gpio.h.

◆ IS_RISING_EDGE

#define IS_RISING_EDGE (   event)    ((event & GPIO_IN_EVENT_RISING_EDGE) == GPIO_IN_EVENT_RISING_EDGE)

Check if event has its rising edge bit set.

Definition at line 99 of file gpio.h.

gpio_in_mode_cfg_e
gpio_in_mode_cfg_e
GPIO pull configuration.
Definition: gpio.h:58
GPIO_IN_EVENT_FALLING_EDGE
@ GPIO_IN_EVENT_FALLING_EDGE
Definition: gpio.h:95
Gpio_inputSetCfg
gpio_res_e Gpio_inputSetCfg(gpio_id_t id, const gpio_in_cfg_t *in_cfg)
Configure a GPIO as an input GPIO.
GPIO_RES_INVALID_PARAM
@ GPIO_RES_INVALID_PARAM
Definition: gpio.h:36
GPIO_RES_INVALID_DIRECTION
@ GPIO_RES_INVALID_DIRECTION
Definition: gpio.h:40
Gpio_init
gpio_res_e Gpio_init(void)
Initialize GPIO module.
GPIO_IN_PULL_NONE
@ GPIO_IN_PULL_NONE
Definition: gpio.h:63
GPIO_RES_NOT_IMPLEMENTED
@ GPIO_RES_NOT_IMPLEMENTED
Definition: gpio.h:34
GPIO_RES_INVALID_PIN
@ GPIO_RES_INVALID_PIN
Definition: gpio.h:38
GPIO_IN_PULL_DOWN
@ GPIO_IN_PULL_DOWN
Definition: gpio.h:65
GPIO_RES_NO_FREE_IT
@ GPIO_RES_NO_FREE_IT
Definition: gpio.h:42
GPIO_LEVEL_HIGH
@ GPIO_LEVEL_HIGH
Definition: gpio.h:51
GPIO_RES_OK
@ GPIO_RES_OK
Definition: gpio.h:30
gpio_in_event_e
gpio_in_event_e
GPIO event.
Definition: gpio.h:88
app_global_functions_t
List of global functions, passed to App_entrypoint()
Definition: wms_app.h:157
GPIO_OUT_MODE_PUSH_PULL
@ GPIO_OUT_MODE_PUSH_PULL
Definition: gpio.h:77
GPIO_IN_EVENT_RISING_EDGE
@ GPIO_IN_EVENT_RISING_EDGE
Definition: gpio.h:93
gpio_out_mode_cfg_e
gpio_out_mode_cfg_e
GPIO operating mode configuration.
Definition: gpio.h:74
GPIO_IN_DISABLED
@ GPIO_IN_DISABLED
Definition: gpio.h:61
Gpio_outputSetCfg
gpio_res_e Gpio_outputSetCfg(gpio_id_t id, const gpio_out_cfg_t *out_cfg)
Configure a GPIO as an output GPIO.
GPIO_OUT_MODE_OPEN_DRAIN_WITH_PULL_UP
@ GPIO_OUT_MODE_OPEN_DRAIN_WITH_PULL_UP
Definition: gpio.h:81
GPIO_LEVEL_LOW
@ GPIO_LEVEL_LOW
Definition: gpio.h:49
gpio_level_e
gpio_level_e
GPIO logical level.
Definition: gpio.h:46
GPIO_IN_PULL_UP
@ GPIO_IN_PULL_UP
Definition: gpio.h:67
GPIO_RES_UNINITIALIZED
@ GPIO_RES_UNINITIALIZED
Definition: gpio.h:32
gpio_res_e
gpio_res_e
List of return code.
Definition: gpio.h:27
GPIO_IN_EVENT_NONE
@ GPIO_IN_EVENT_NONE
Definition: gpio.h:91
GPIO_OUT_MODE_OPEN_DRAIN
@ GPIO_OUT_MODE_OPEN_DRAIN
Definition: gpio.h:79