Soletta™ Framework
Framework for making IoT devices

Full online documentation | C API Index
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Data Fields
sol_gpio_config Struct Reference

Structure to hold the configuration of a GPIO device. More...

#include <sol-gpio.h>

Data Fields

union {
   struct {
      void(*   cb )(void *data, struct sol_gpio
         *gpio, bool value)
 The function to call when an event happens. More...
 
      uint32_t   poll_timeout
 Time to poll for events, in milliseconds. More...
 
      enum sol_gpio_edge   trigger_mode
 When to trigger events for this GPIO. More...
 
      const void *   user_data
 User data poinetr to pass to the cb function. More...
 
   }   in
 Configuration parameters for input GPIOs. More...
 
   struct {
      bool   value
 The initial value to write when the GPIO is opened. More...
 
   }   out
 Configuration parameters for output GPIOs. More...
 
}; 
 
bool active_low
 Whether the GPIO is considered active when it's in a low state. More...
 
uint16_t api_version
 The API version. More...
 
enum sol_gpio_direction dir
 The direction in which to open the GPIO. More...
 
enum sol_gpio_drive drive_mode
 Pull-up or pull-down resistor state for this GPIO. More...
 

Detailed Description

Structure to hold the configuration of a GPIO device.

When opening a GPIO with sol_gpio_open_by_label(), sol_gpio_open() or sol_gpio_open_raw(), the parameters with which the GPIO is configured are those defined in this structure.

If there's a need to change any of these parameters, the GPIO must be closed and opened again with a new configuration.

Examples:
/src/samples/common/linux-micro-init.c.

Field Documentation

union { ... }
bool sol_gpio_config::active_low

Whether the GPIO is considered active when it's in a low state.

If set, then the logical state of the GPIO will be reversed in relation to the physical state. That is, for input GPIOs, when the current on the wire goes to a low state, the value returned by sol_gpio_read() will be true. Conversely, it will be false when the physical state is high.

The same logic applies for output GPIOs when a value is written through sol_gpio_write().

This is useful to keep the application logic simpler in the face of different hardware configurations.

uint16_t sol_gpio_config::api_version

The API version.

Examples:
/src/samples/common/linux-micro-init.c.

Referenced by startup().

void(* sol_gpio_config::cb)(void *data, struct sol_gpio *gpio, bool value)

The function to call when an event happens.

Different systems handle interruptions differently, and so to maintain consistency across them, there is no queue of values triggered by interruptions. Instead, when an interruption happens, the main loop will handle it and call the user function provided here, with the value of the GPIO at that time. This means that the if the application takes too long to return to the main loop while interruptions are happening, some of those values will be lost.

Parameters
dataThe user data pointer provided in user_data.
gpioThe GPIO instance that triggered the event.
valueThe value of the GPIO at the moment the function is called.
enum sol_gpio_direction sol_gpio_config::dir

The direction in which to open the GPIO.

enum sol_gpio_drive sol_gpio_config::drive_mode

Pull-up or pull-down resistor state for this GPIO.

One of sol_gpio_drive. Some platforms will configure GPIO taking this in consideration, as Continki and RIOT.

struct { ... } sol_gpio_config::in

Configuration parameters for input GPIOs.

struct { ... } sol_gpio_config::out

Configuration parameters for output GPIOs.

uint32_t sol_gpio_config::poll_timeout

Time to poll for events, in milliseconds.

In the case that interruptions are not supported by the selected GPIO, the implementation will fall back to polling the pin for changes in its value.

The cb function provided will be called only when a change in the value is detected, so if the timeout is too long, it may lose events.

enum sol_gpio_edge sol_gpio_config::trigger_mode

When to trigger events for this GPIO.

One of sol_gpio_edge. If the value set is anything other than SOL_GPIO_EDGE_NONE, then the cb member must be set.

const void* sol_gpio_config::user_data

User data poinetr to pass to the cb function.

bool sol_gpio_config::value

The initial value to write when the GPIO is opened.


The documentation for this struct was generated from the following file: