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 Structures | Typedefs | Enumerations | Functions
GPIO

GPIO (General Purpose Input/Output) API for Soletta. More...

Data Structures

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

Typedefs

typedef struct sol_gpio sol_gpio
 A handle to a GPIO. More...
 
typedef struct sol_gpio_config sol_gpio_config
 Structure to hold the configuration of a GPIO device. More...
 

Enumerations

enum  sol_gpio_direction { SOL_GPIO_DIR_OUT = 0, SOL_GPIO_DIR_IN = 1 }
 Possible values for the direction of a GPIO. More...
 
enum  sol_gpio_drive { SOL_GPIO_DRIVE_NONE = 0, SOL_GPIO_DRIVE_PULL_UP, SOL_GPIO_DRIVE_PULL_DOWN }
 Possible values for pull-up or pull-down resistor of a GPIO. More...
 
enum  sol_gpio_edge { SOL_GPIO_EDGE_NONE = 0, SOL_GPIO_EDGE_RISING, SOL_GPIO_EDGE_FALLING, SOL_GPIO_EDGE_BOTH }
 Possible values for the edge mode of a GPIO. More...
 

Functions

void sol_gpio_close (struct sol_gpio *gpio)
 Closes a given GPIO pin. More...
 
enum sol_gpio_direction sol_gpio_direction_from_str (const char *direction)
 Converts a string GPIO direction to sol_gpio_direction. More...
 
const char * sol_gpio_direction_to_str (enum sol_gpio_direction direction)
 Converts sol_gpio_direction to a string name. More...
 
enum sol_gpio_drive sol_gpio_drive_from_str (const char *drive)
 Converts a string GPIO drive to sol_gpio_drive. More...
 
const char * sol_gpio_drive_to_str (enum sol_gpio_drive drive)
 Converts sol_gpio_drive to a string name. More...
 
enum sol_gpio_edge sol_gpio_edge_from_str (const char *edge)
 Converts a string GPIO edge to sol_gpio_edge. More...
 
const char * sol_gpio_edge_to_str (enum sol_gpio_edge edge)
 Converts sol_gpio_edge to a string name. More...
 
struct sol_gpiosol_gpio_open (uint32_t pin, const struct sol_gpio_config *config)
 Opens a given pin as general purpose input or output. More...
 
struct sol_gpiosol_gpio_open_by_label (const char *label, const struct sol_gpio_config *config)
 Opens a given pin by its board label as general purpose input or output. More...
 
struct sol_gpiosol_gpio_open_raw (uint32_t pin, const struct sol_gpio_config *config)
 Opens a given pin as general purpose input or output. More...
 
int sol_gpio_read (struct sol_gpio *gpio)
 Get the current value set to pin. More...
 
bool sol_gpio_write (struct sol_gpio *gpio, bool value)
 Set an arbitrary value to pin. More...
 

Detailed Description

GPIO (General Purpose Input/Output) API for Soletta.

Typedef Documentation

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.

Enumeration Type Documentation

Possible values for the direction of a GPIO.

Enumerator
SOL_GPIO_DIR_OUT 

The GPIO is an output.

For things like LEDs.

SOL_GPIO_DIR_IN 

The GPIO is an input.

For buttons or similar devices.

Possible values for pull-up or pull-down resistor of a GPIO.

It will avoid values to float when this pin isn't connected. It'll define output value if nothing else is defined by software.

Enumerator
SOL_GPIO_DRIVE_NONE 

Do not set any state.

SOL_GPIO_DRIVE_PULL_UP 

When set as pull-up, resistor will be connected to VCC.

Logic value of output will be true while unset.

SOL_GPIO_DRIVE_PULL_DOWN 

When set as pull-down, resistor will be connected to ground.

Logic value of output will be false while unset.

Possible values for the edge mode of a GPIO.

This indicate when an interrupt event should be generated.

Enumerator
SOL_GPIO_EDGE_NONE 

Don't generate events.

When using this mode, no interrupt handler will be registered and it's up to the user to read the GPIO manually.

SOL_GPIO_EDGE_RISING 

Events will be triggered on a rising edge.

That is, when the state of the GPIO goes from low to high.

SOL_GPIO_EDGE_FALLING 

Events will be triggered onf a falling edge.

That is, when the state of the GPIO goes from high to low.

SOL_GPIO_EDGE_BOTH 

Events will be triggered for both edge levels.

Both rising and falling edges will trigger events.

Function Documentation

void sol_gpio_close ( struct sol_gpio gpio)

Closes a given GPIO pin.

See Also
sol_gpio_open(), sol_gpio_open_raw().
Parameters
gpioThe open sol_gpio representing the pin to be closed.
Examples:
/src/samples/common/linux-micro-init.c.

Referenced by shutdown().

enum sol_gpio_direction sol_gpio_direction_from_str ( const char *  direction)

Converts a string GPIO direction to sol_gpio_direction.

This function converts a string GPIO direction to enumeration sol_gpio_direction.

See Also
sol_gpio_direction_to_str().
Parameters
directionValid values are "in", "out".
Returns
enumeration sol_gpio_direction.
const char* sol_gpio_direction_to_str ( enum sol_gpio_direction  direction)

Converts sol_gpio_direction to a string name.

This function converts sol_gpio_direction enumeration to a string GPIO direction name.

See Also
sol_gpio_direction_from_str().
Parameters
directionsol_gpio_direction.
Returns
String representation of the sol_gpio_direction.
enum sol_gpio_drive sol_gpio_drive_from_str ( const char *  drive)

Converts a string GPIO drive to sol_gpio_drive.

This function converts a string GPIO drive to enumeration sol_gpio_drive.

See Also
sol_gpio_drive_to_str().
Parameters
driveValid values are "none", "up", "down".
Returns
enumeration sol_gpio_drive.
const char* sol_gpio_drive_to_str ( enum sol_gpio_drive  drive)

Converts sol_gpio_drive to a string name.

This function converts sol_gpio_drive enumeration to a string GPIO drive name.

See Also
sol_gpio_drive_from_str().
Parameters
drivesol_gpio_drive.
Returns
String representation of the sol_gpio_drive.
enum sol_gpio_edge sol_gpio_edge_from_str ( const char *  edge)

Converts a string GPIO edge to sol_gpio_edge.

This function converts a string GPIO edge to enumeration sol_gpio_edge

See Also
sol_gpio_edge_to_str().
Parameters
edgeValid values are "none", "rising", "falling", "any".
Returns
enumeration sol_gpio_edge
const char* sol_gpio_edge_to_str ( enum sol_gpio_edge  edge)

Converts sol_gpio_edge to a string name.

This function converts sol_gpio_edge enumeration to a string GPIO edge name

See Also
sol_gpio_edge_from_str().
Parameters
edgesol_gpio_edge
Returns
String representation of the sol_gpio_edge
struct sol_gpio* sol_gpio_open ( uint32_t  pin,
const struct sol_gpio_config config 
)

Opens a given pin as general purpose input or output.

A pin should be opened just once, calling this function more than once for the same pin results in undefined behaviour - per platform basis.

See Also
sol_gpio_open_raw(), sol_gpio_close().
Parameters
pinThe pin to be opened.
configContains the pin configuration.
Returns
A new sol_gpio instance on success, NULL otherwise.
Examples:
/src/samples/common/linux-micro-init.c.

Referenced by startup().

struct sol_gpio* sol_gpio_open_by_label ( const char *  label,
const struct sol_gpio_config config 
)

Opens a given pin by its board label as general purpose input or output.

This function only works when the board was successfully detected by Soletta and a corresponding pin multiplexer module was found.

A pin should be opened just once, calling this function more than once for the same pin results in undefined behavior - per platform basis.

See Also
sol_gpio_open_raw(), sol_gpio_close().
Parameters
labelThe pin to be opened.
configContains the pin configuration.
Returns
A new sol_gpio instance on success, NULL otherwise.
struct sol_gpio* sol_gpio_open_raw ( uint32_t  pin,
const struct sol_gpio_config config 
)

Opens a given pin as general purpose input or output.

A pin should be opened just once, calling this function more than once for the same pin results in undefined behaviour - per platform basis.

See Also
sol_gpio_open(), sol_gpio_close().
Parameters
pinThe pin to be opened.
configContains the pin configuration.
Returns
A new sol_gpio instance on success, NULL otherwise.
int sol_gpio_read ( struct sol_gpio gpio)

Get the current value set to pin.

Parameters
gpioThe opened sol_gpio that contains the pin that will be read.
Returns
The value of the pin on success, otherwise a negative errno value.
bool sol_gpio_write ( struct sol_gpio gpio,
bool  value 
)

Set an arbitrary value to pin.

Parameters
gpioThe opened sol_gpio that contains the pin that will be used.
valueThe value that will be set to the pin.
Returns
true on success, otherwise false.
Examples:
/src/samples/common/linux-micro-init.c.

Referenced by on_timeout().