libgpiod  0.3.2
Typedefs | Enumerations | Functions
High-level API

Simple high-level routines for straightforward GPIO manipulation. More...

Typedefs

typedef void(* gpiod_set_value_cb) (void *)
 Simple set value callback signature.
 
typedef int(* gpiod_event_cb) (int, const struct timespec *, void *)
 Simple event callack signature.
 

Enumerations

enum  { GPIOD_EVENT_CB_TIMEOUT, GPIOD_EVENT_CB_RISING_EDGE, GPIOD_EVENT_CB_FALLING_EDGE }
 Event types that can be passed to the simple event callback. More...
 
enum  { GPIOD_EVENT_CB_OK = 0, GPIOD_EVENT_CB_STOP }
 Return status values that the simple event callback can return. More...
 

Functions

int gpiod_simple_get_value_multiple (const char *consumer, const char *device, const unsigned int *offsets, int *values, unsigned int num_lines, bool active_low) GPIOD_API
 Read current values from a set of GPIO lines. More...
 
static int gpiod_simple_get_value (const char *consumer, const char *device, unsigned int offset, bool active_low)
 Read current value from a single GPIO line. More...
 
int gpiod_simple_set_value_multiple (const char *consumer, const char *device, const unsigned int *offsets, const int *values, unsigned int num_lines, bool active_low, gpiod_set_value_cb cb, void *data) GPIOD_API
 Set values of a set of a set of GPIO lines. More...
 
static int gpiod_simple_set_value (const char *consumer, const char *device, unsigned int offset, int value, bool active_low, gpiod_set_value_cb cb, void *data)
 Set value of a single GPIO line. More...
 
int gpiod_simple_event_loop (const char *consumer, const char *device, unsigned int offset, bool active_low, const struct timespec *timeout, gpiod_event_cb callback, void *cbdata) GPIOD_API
 Wait for events on a single GPIO line. More...
 

Detailed Description

Simple high-level routines for straightforward GPIO manipulation.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum

Event types that can be passed to the simple event callback.

Enumerator
GPIOD_EVENT_CB_TIMEOUT 

Waiting for events timed out.

GPIOD_EVENT_CB_RISING_EDGE 

Rising edge event occured.

GPIOD_EVENT_CB_FALLING_EDGE 

Falling edge event occured.

Definition at line 212 of file gpiod.h.

◆ anonymous enum

anonymous enum

Return status values that the simple event callback can return.

Enumerator
GPIOD_EVENT_CB_OK 

Continue processing events.

GPIOD_EVENT_CB_STOP 

Stop processing events.

Definition at line 224 of file gpiod.h.

Function Documentation

◆ gpiod_simple_event_loop()

int gpiod_simple_event_loop ( const char *  consumer,
const char *  device,
unsigned int  offset,
bool  active_low,
const struct timespec *  timeout,
gpiod_event_cb  callback,
void *  cbdata 
)

Wait for events on a single GPIO line.

Parameters
consumerName of the consumer.
deviceName, path or number of the gpiochip.
offsetGPIO line offset on the chip.
active_lowThe active state of this line - true if low.
timeoutMaximum wait time for each iteration.
callbackCallback function to call on event occurence.
cbdataUser data passed to the callback.
Returns
0 no errors were encountered, -1 if an error occured.

◆ gpiod_simple_get_value()

static int gpiod_simple_get_value ( const char *  consumer,
const char *  device,
unsigned int  offset,
bool  active_low 
)
inlinestatic

Read current value from a single GPIO line.

Parameters
consumerName of the consumer.
deviceName, path or number of the gpiochip.
offsetGPIO line offset on the chip.
active_lowThe active state of this line - true if low.
Returns
0 or 1 (GPIO value) if the operation succeeds, -1 on error.

Definition at line 147 of file gpiod.h.

References gpiod_simple_get_value_multiple().

◆ gpiod_simple_get_value_multiple()

int gpiod_simple_get_value_multiple ( const char *  consumer,
const char *  device,
const unsigned int *  offsets,
int *  values,
unsigned int  num_lines,
bool  active_low 
)

Read current values from a set of GPIO lines.

Parameters
consumerName of the consumer.
deviceName, path or number of the gpiochip.
offsetsAn array of offsets of lines whose values should be read.
valuesA buffer in which the values will be stored.
num_linesNumber of lines, must be > 0.
active_lowThe active state of the lines - true if low.
Returns
0 if the operation succeeds, -1 on error.

Referenced by gpiod_simple_get_value().

◆ gpiod_simple_set_value()

static int gpiod_simple_set_value ( const char *  consumer,
const char *  device,
unsigned int  offset,
int  value,
bool  active_low,
gpiod_set_value_cb  cb,
void *  data 
)
inlinestatic

Set value of a single GPIO line.

Parameters
consumerName of the consumer.
deviceName, path or number of the gpiochip.
offsetGPIO line offset on the chip.
valueNew value.
active_lowThe active state of this line - true if low.
cbCallback function that will be called right after the value is set. Users can use this, for example, to pause the execution after toggling a GPIO.
dataUser data that will be passed to the callback function.
Returns
0 if the operation succeeds, -1 on error.

Definition at line 198 of file gpiod.h.

References gpiod_simple_set_value_multiple().

◆ gpiod_simple_set_value_multiple()

int gpiod_simple_set_value_multiple ( const char *  consumer,
const char *  device,
const unsigned int *  offsets,
const int *  values,
unsigned int  num_lines,
bool  active_low,
gpiod_set_value_cb  cb,
void *  data 
)

Set values of a set of a set of GPIO lines.

Parameters
consumerName of the consumer.
deviceName, path or number of the gpiochip.
offsetsAn array of offsets of lines whose values should be set.
valuesAn array of integers containing new values.
num_linesNumber of lines, must be > 0.
active_lowThe active state of the lines - true if low.
cbCallback function that will be called right after the values are set.
dataUser data that will be passed to the callback function.
Returns
0 if the operation succeeds, -1 on error.

Referenced by gpiod_simple_set_value().