GPIO

The Riotee Module/Board has 11 digital GPIO pins. The API allows configuring pins as input or output. Outputs can be controlled similar to any other battery-powered device. Inputs can always be read with riotee_gpio_read(unsigned int pin) or the application can wait for a specified level on the pin with riotee_gpio_wait_level(...).

Important

Always check the return code of riotee_gpio_wait_level(...) to distinguish between a power failure (RIOTEE_ERR_RESET) and an actual level detection event (RIOTEE_SUCCESS).

Example usage

 1#include "riotee.h"
 2#include "riotee_gpio.h"
 3#include "riotee_timing.h"
 4
 5#define PIN_BUTTON PIN_D6
 6
 7void lateinit(void) {
 8  riotee_gpio_cfg_output(PIN_LED_CTRL);
 9}
10
11int main(void) {
12  for (;;) {
13    /* Wait for low level on button */
14    riotee_gpio_wait_level(PIN_BUTTON, RIOTEE_GPIO_LEVEL_LOW, RIOTEE_GPIO_IN_PULLUP);
15    /* Disable the pullup to save energy */
16    riotee_gpio_cfg_disable(PIN_BUTTON);
17
18    /* Blink LED for ~150us */
19    riotee_gpio_set(PIN_LED_CTRL);
20    riotee_sleep_ticks(5);
21    riotee_gpio_clear(PIN_LED_CTRL);
22    /* Wait until capacitor is recharged */
23    riotee_wait_cap_charged();
24  }
25}

API Reference

enum riotee_gpio_in_pull_t

GPIO input pullup configuration.

Values:

enumerator RIOTEE_GPIO_IN_PULLUP

Pullup resistor active.

enumerator RIOTEE_GPIO_IN_PULLDOWN

Pulldown resisotr active.

enumerator RIOTEE_GPIO_IN_NOPULL

No pullup/pulldown resistor active.

enum riotee_gpio_level_t

GPIO levels.

Values:

enumerator RIOTEE_GPIO_LEVEL_LOW

GPIO level high.

enumerator RIOTEE_GPIO_LEVEL_HIGH

GPIO level low.

void riotee_gpio_init(void)

Initializes GPIO. Must be called once after reset before GPIO interrupt functionality can be used.

riotee_rc_t riotee_gpio_wait_level(unsigned int pin, riotee_gpio_level_t level, riotee_gpio_in_pull_t pull)

Waits in low power mode until level is detected on pin.

CAUTION: The pin remains in the specified pull configuration after the function returns.

Parameters:
  • pin – Pin number.

  • level – Level to wait for.

  • pull – Pullup configuration.

Return values:
  • RIOTEE_SUCCESS – Specified level detected on pin.

  • RIOTEE_ERR_RESET – Reset occured while waiting for level.

static inline void riotee_gpio_cfg_output(unsigned int pin)

Configures pin as output.

Parameters:

pin – Pin number.

static inline void riotee_gpio_cfg_input(unsigned int pin, riotee_gpio_in_pull_t pull)

Configures pin as output.

Parameters:
  • pin – Pin number.

  • pull – Type of pull resistor.

static inline void riotee_gpio_cfg_disable(unsigned int pin)

Configures the pin for high impedance and disconnects the input buffer.

Parameters:

pin – Pin number.

static inline void riotee_gpio_set(unsigned int pin)

Sets output pin to logic high.

Parameters:

pin – Pin number.

static inline void riotee_gpio_clear(unsigned int pin)

Sets output pin to logic low.

Parameters:

pin – Pin number.

static inline void riotee_gpio_toggle(unsigned int pin)

Toggles logic state of output pin.

Parameters:

pin – Pin number.

static inline uint32_t riotee_gpio_read(unsigned int pin)

Reads logic state of input pin.

Parameters:

pin – Pin number.

Returns:

uint32_t 1 if logic high, 0 if logic low

static inline uint32_t riotee_gpio_is_set(unsigned int pin)

Reads logic state of output pin.

Parameters:

pin – Pin number.

Returns:

uint32_t 1 if logic high, 0 if logic low