GPIO
The Voltix 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 voltix_gpio_read(unsigned int pin) or the application can wait for a specified level on the pin with voltix_gpio_wait_level(...).
Important
Always check the return code of voltix_gpio_wait_level(...) to distinguish between a power failure (VOLTIX_ERR_RESET) and an actual level detection event (VOLTIX_SUCCESS).
Example usage
1#include "voltix.h"
2#include "voltix_gpio.h"
3#include "voltix_timing.h"
4
5#define PIN_BUTTON PIN_D6
6
7void lateinit(void) {
8 voltix_gpio_cfg_output(PIN_LED_CTRL);
9}
10
11int main(void) {
12 for (;;) {
13 /* Wait for low level on button */
14 voltix_gpio_wait_level(PIN_BUTTON, VOLTIX_GPIO_LEVEL_LOW, VOLTIX_GPIO_IN_PULLUP);
15 /* Disable the pullup to save energy */
16 voltix_gpio_cfg_disable(PIN_BUTTON);
17
18 /* Blink LED for ~150us */
19 voltix_gpio_set(PIN_LED_CTRL);
20 voltix_sleep_ticks(5);
21 voltix_gpio_clear(PIN_LED_CTRL);
22 /* Wait until capacitor is recharged */
23 voltix_wait_cap_charged();
24 }
25}
API Reference
-
enum voltix_gpio_in_pull_t
GPIO input pullup configuration.
Values:
-
enumerator VOLTIX_GPIO_IN_PULLUP
Pullup resistor active.
-
enumerator VOLTIX_GPIO_IN_PULLDOWN
Pulldown resisotr active.
-
enumerator VOLTIX_GPIO_IN_NOPULL
No pullup/pulldown resistor active.
-
enumerator VOLTIX_GPIO_IN_PULLUP
-
enum voltix_gpio_level_t
GPIO levels.
Values:
-
enumerator VOLTIX_GPIO_LEVEL_LOW
GPIO level high.
-
enumerator VOLTIX_GPIO_LEVEL_HIGH
GPIO level low.
-
enumerator VOLTIX_GPIO_LEVEL_LOW
-
void voltix_gpio_init(void)
Initializes GPIO. Must be called once after reset before GPIO interrupt functionality can be used.
-
voltix_rc_t voltix_gpio_wait_level(unsigned int pin, voltix_gpio_level_t level, voltix_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:
VOLTIX_SUCCESS – Specified level detected on pin.
VOLTIX_ERR_RESET – Reset occured while waiting for level.
-
static inline void voltix_gpio_cfg_output(unsigned int pin)
Configures pin as output.
- Parameters:
pin – Pin number.
-
static inline void voltix_gpio_cfg_input(unsigned int pin, voltix_gpio_in_pull_t pull)
Configures pin as output.
- Parameters:
pin – Pin number.
pull – Type of pull resistor.
-
static inline void voltix_gpio_cfg_disable(unsigned int pin)
Configures the pin for high impedance and disconnects the input buffer.
- Parameters:
pin – Pin number.
-
static inline void voltix_gpio_set(unsigned int pin)
Sets output pin to logic high.
- Parameters:
pin – Pin number.
-
static inline void voltix_gpio_clear(unsigned int pin)
Sets output pin to logic low.
- Parameters:
pin – Pin number.
-
static inline void voltix_gpio_toggle(unsigned int pin)
Toggles logic state of output pin.
- Parameters:
pin – Pin number.
-
static inline uint32_t voltix_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 voltix_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