libgpiod  1.5.2
Data Structures | Macros | Typedefs | Enumerations | Functions
>common</strong> Common helper macros

Commonly used utility macros. More...

Data Structures

struct  gpiod_ctxless_event_poll_fd
 Helper structure for the ctxless event loop poll callback. More...
 
struct  gpiod_line_bulk
 Helper structure for storing a set of GPIO line objects. More...
 
struct  gpiod_line_request_config
 Structure holding configuration of a line request. More...
 
struct  gpiod_line_event
 Structure holding event info. More...
 
class  gpiod::chip
 Represents a GPIO chip. More...
 
struct  gpiod::line_request
 Stores the configuration for line requests. More...
 
class  gpiod::line
 Represents a single GPIO line. More...
 
struct  gpiod::line_event
 Describes a single GPIO line event. More...
 
class  gpiod::line_bulk
 Represents a set of GPIO lines. More...
 
class  gpiod::chip_iter
 Allows to iterate over all GPIO chips present on the system. More...
 
class  gpiod::line_iter
 Allows to iterate over all lines owned by a GPIO chip. More...
 

Macros

#define GPIOD_API   __attribute__((visibility("default")))
 Makes symbol visible.
 
#define GPIOD_UNUSED   __attribute__((unused))
 Marks a function argument or variable as potentially unused.
 
#define GPIOD_BIT(nr)   (1UL << (nr))
 Shift 1 by given offset. More...
 
#define GPIOD_DEPRECATED   __attribute__((deprecated))
 Marks a public function as deprecated.
 
#define GPIOD_LINE_BULK_MAX_LINES   64
 Maximum number of GPIO lines that can be requested at once.
 
#define GPIOD_LINE_BULK_INITIALIZER   { { NULL }, 0 }
 Static initializer for GPIO bulk objects. More...
 
#define gpiod_line_bulk_foreach_line(bulk, line, lineptr)
 Iterate over all line handles held by a line bulk object. More...
 
#define gpiod_line_bulk_foreach_line_off(bulk, line, offset)
 Iterate over all line handles held by a line bulk object (integer counter variant). More...
 
#define gpiod_foreach_chip(iter, chip)
 Iterate over all GPIO chips present in the system. More...
 
#define gpiod_foreach_chip_noclose(iter, chip)
 Iterate over all chips present in the system without closing them. More...
 
#define gpiod_foreach_line(iter, line)
 Iterate over all GPIO lines of a single chip. More...
 

Typedefs

typedef void(* gpiod_ctxless_set_value_cb) (void *)
 Simple set value callback signature.
 
typedef int(* gpiod_ctxless_event_handle_cb) (int, unsigned int, const struct timespec *, void *)
 Simple event callback signature. More...
 
typedef int(* gpiod_ctxless_event_poll_cb) (unsigned int, struct gpiod_ctxless_event_poll_fd *, const struct timespec *, void *)
 Simple event poll callback signature. More...
 

Enumerations

enum  {
  GPIOD_CTXLESS_FLAG_OPEN_DRAIN = GPIOD_BIT(0), GPIOD_CTXLESS_FLAG_OPEN_SOURCE = GPIOD_BIT(1), GPIOD_CTXLESS_FLAG_BIAS_DISABLE = GPIOD_BIT(2), GPIOD_CTXLESS_FLAG_BIAS_PULL_DOWN = GPIOD_BIT(3),
  GPIOD_CTXLESS_FLAG_BIAS_PULL_UP = GPIOD_BIT(4)
}
 Miscellaneous GPIO flags. More...
 
enum  { GPIOD_CTXLESS_EVENT_RISING_EDGE = 1, GPIOD_CTXLESS_EVENT_FALLING_EDGE, GPIOD_CTXLESS_EVENT_BOTH_EDGES }
 Event types that the ctxless event monitor can wait for. More...
 
enum  { GPIOD_CTXLESS_EVENT_CB_TIMEOUT = 1, GPIOD_CTXLESS_EVENT_CB_RISING_EDGE, GPIOD_CTXLESS_EVENT_CB_FALLING_EDGE }
 Event types that can be passed to the ctxless event callback. More...
 
enum  { GPIOD_CTXLESS_EVENT_CB_RET_ERR = -1, GPIOD_CTXLESS_EVENT_CB_RET_OK = 0, GPIOD_CTXLESS_EVENT_CB_RET_STOP = 1 }
 Return status values that the ctxless event callback can return. More...
 
enum  { GPIOD_CTXLESS_EVENT_POLL_RET_STOP = -2, GPIOD_CTXLESS_EVENT_POLL_RET_ERR = -1, GPIOD_CTXLESS_EVENT_POLL_RET_TIMEOUT = 0 }
 Return status values that the ctxless event poll callback can return. More...
 
enum  { GPIOD_LINE_DIRECTION_INPUT = 1, GPIOD_LINE_DIRECTION_OUTPUT }
 Possible direction settings. More...
 
enum  { GPIOD_LINE_ACTIVE_STATE_HIGH = 1, GPIOD_LINE_ACTIVE_STATE_LOW }
 Possible active state settings. More...
 
enum  { GPIOD_LINE_BIAS_AS_IS = 1, GPIOD_LINE_BIAS_DISABLE, GPIOD_LINE_BIAS_PULL_UP, GPIOD_LINE_BIAS_PULL_DOWN }
 Possible internal bias settings. More...
 
enum  {
  GPIOD_LINE_REQUEST_DIRECTION_AS_IS = 1, GPIOD_LINE_REQUEST_DIRECTION_INPUT, GPIOD_LINE_REQUEST_DIRECTION_OUTPUT, GPIOD_LINE_REQUEST_EVENT_FALLING_EDGE,
  GPIOD_LINE_REQUEST_EVENT_RISING_EDGE, GPIOD_LINE_REQUEST_EVENT_BOTH_EDGES
}
 Available types of requests. More...
 
enum  {
  GPIOD_LINE_REQUEST_FLAG_OPEN_DRAIN = GPIOD_BIT(0), GPIOD_LINE_REQUEST_FLAG_OPEN_SOURCE = GPIOD_BIT(1), GPIOD_LINE_REQUEST_FLAG_ACTIVE_LOW = GPIOD_BIT(2), GPIOD_LINE_REQUEST_FLAG_BIAS_DISABLE = GPIOD_BIT(3),
  GPIOD_LINE_REQUEST_FLAG_BIAS_PULL_DOWN = GPIOD_BIT(4), GPIOD_LINE_REQUEST_FLAG_BIAS_PULL_UP = GPIOD_BIT(5)
}
 Miscellaneous GPIO request flags. More...
 
enum  { GPIOD_LINE_EVENT_RISING_EDGE = 1, GPIOD_LINE_EVENT_FALLING_EDGE }
 Event types. More...
 

Functions

int gpiod_ctxless_get_value (const char *device, unsigned int offset, bool active_low, const char *consumer) GPIOD_API
 Read current value from a single GPIO line. More...
 
int gpiod_ctxless_get_value_ext (const char *device, unsigned int offset, bool active_low, const char *consumer, int flags) GPIOD_API
 Read current value from a single GPIO line. More...
 
int gpiod_ctxless_get_value_multiple (const char *device, const unsigned int *offsets, int *values, unsigned int num_lines, bool active_low, const char *consumer) GPIOD_API
 Read current values from a set of GPIO lines. More...
 
int gpiod_ctxless_get_value_multiple_ext (const char *device, const unsigned int *offsets, int *values, unsigned int num_lines, bool active_low, const char *consumer, int flags) GPIOD_API
 Read current values from a set of GPIO lines. More...
 
int gpiod_ctxless_set_value (const char *device, unsigned int offset, int value, bool active_low, const char *consumer, gpiod_ctxless_set_value_cb cb, void *data) GPIOD_API
 Set value of a single GPIO line. More...
 
int gpiod_ctxless_set_value_ext (const char *device, unsigned int offset, int value, bool active_low, const char *consumer, gpiod_ctxless_set_value_cb cb, void *data, int flags) GPIOD_API
 Set value of a single GPIO line. More...
 
int gpiod_ctxless_set_value_multiple (const char *device, const unsigned int *offsets, const int *values, unsigned int num_lines, bool active_low, const char *consumer, gpiod_ctxless_set_value_cb cb, void *data) GPIOD_API
 Set values of multiple GPIO lines. More...
 
int gpiod_ctxless_set_value_multiple_ext (const char *device, const unsigned int *offsets, const int *values, unsigned int num_lines, bool active_low, const char *consumer, gpiod_ctxless_set_value_cb cb, void *data, int flags) GPIOD_API
 Set values of multiple GPIO lines. More...
 
int gpiod_ctxless_event_loop (const char *device, unsigned int offset, bool active_low, const char *consumer, const struct timespec *timeout, gpiod_ctxless_event_poll_cb poll_cb, gpiod_ctxless_event_handle_cb event_cb, void *data) GPIOD_API GPIOD_DEPRECATED
 Wait for events on a single GPIO line. More...
 
int gpiod_ctxless_event_loop_multiple (const char *device, const unsigned int *offsets, unsigned int num_lines, bool active_low, const char *consumer, const struct timespec *timeout, gpiod_ctxless_event_poll_cb poll_cb, gpiod_ctxless_event_handle_cb event_cb, void *data) GPIOD_API GPIOD_DEPRECATED
 Wait for events on multiple GPIO lines. More...
 
int gpiod_ctxless_event_monitor (const char *device, int event_type, unsigned int offset, bool active_low, const char *consumer, const struct timespec *timeout, gpiod_ctxless_event_poll_cb poll_cb, gpiod_ctxless_event_handle_cb event_cb, void *data) GPIOD_API
 Wait for events on a single GPIO line. More...
 
int gpiod_ctxless_event_monitor_ext (const char *device, int event_type, unsigned int offset, bool active_low, const char *consumer, const struct timespec *timeout, gpiod_ctxless_event_poll_cb poll_cb, gpiod_ctxless_event_handle_cb event_cb, void *data, int flags) GPIOD_API
 Wait for events on a single GPIO line. More...
 
int gpiod_ctxless_event_monitor_multiple (const char *device, int event_type, const unsigned int *offsets, unsigned int num_lines, bool active_low, const char *consumer, const struct timespec *timeout, gpiod_ctxless_event_poll_cb poll_cb, gpiod_ctxless_event_handle_cb event_cb, void *data) GPIOD_API
 Wait for events on multiple GPIO lines. More...
 
int gpiod_ctxless_event_monitor_multiple_ext (const char *device, int event_type, const unsigned int *offsets, unsigned int num_lines, bool active_low, const char *consumer, const struct timespec *timeout, gpiod_ctxless_event_poll_cb poll_cb, gpiod_ctxless_event_handle_cb event_cb, void *data, int flags) GPIOD_API
 Wait for events on multiple GPIO lines. More...
 
int gpiod_ctxless_find_line (const char *name, char *chipname, size_t chipname_size, unsigned int *offset) GPIOD_API
 Determine the chip name and line offset of a line with given name. More...
 
struct gpiod_chip * gpiod_chip_open (const char *path) GPIOD_API
 Open a gpiochip by path. More...
 
struct gpiod_chip * gpiod_chip_open_by_name (const char *name) GPIOD_API
 Open a gpiochip by name. More...
 
struct gpiod_chip * gpiod_chip_open_by_number (unsigned int num) GPIOD_API
 Open a gpiochip by number. More...
 
struct gpiod_chip * gpiod_chip_open_by_label (const char *label) GPIOD_API
 Open a gpiochip by label. More...
 
struct gpiod_chip * gpiod_chip_open_lookup (const char *descr) GPIOD_API
 Open a gpiochip based on the best guess what the path is. More...
 
void gpiod_chip_close (struct gpiod_chip *chip) GPIOD_API
 Close a GPIO chip handle and release all allocated resources. More...
 
const char * gpiod_chip_name (struct gpiod_chip *chip) GPIOD_API
 Get the GPIO chip name as represented in the kernel. More...
 
const char * gpiod_chip_label (struct gpiod_chip *chip) GPIOD_API
 Get the GPIO chip label as represented in the kernel. More...
 
unsigned int gpiod_chip_num_lines (struct gpiod_chip *chip) GPIOD_API
 Get the number of GPIO lines exposed by this chip. More...
 
struct gpiod_line * gpiod_chip_get_line (struct gpiod_chip *chip, unsigned int offset) GPIOD_API
 Get the handle to the GPIO line at given offset. More...
 
int gpiod_chip_get_lines (struct gpiod_chip *chip, unsigned int *offsets, unsigned int num_offsets, struct gpiod_line_bulk *bulk) GPIOD_API
 Retrieve a set of lines and store them in a line bulk object. More...
 
int gpiod_chip_get_all_lines (struct gpiod_chip *chip, struct gpiod_line_bulk *bulk) GPIOD_API
 Retrieve all lines exposed by a chip and store them in a bulk object. More...
 
struct gpiod_line * gpiod_chip_find_line (struct gpiod_chip *chip, const char *name) GPIOD_API
 Find a GPIO line by name among lines associated with given GPIO chip. More...
 
int gpiod_chip_find_lines (struct gpiod_chip *chip, const char **names, struct gpiod_line_bulk *bulk) GPIOD_API
 Find a set of GPIO lines by names among lines exposed by this chip. More...
 
static void gpiod_line_bulk_init (struct gpiod_line_bulk *bulk)
 Initialize a GPIO bulk object. More...
 
static void gpiod_line_bulk_add (struct gpiod_line_bulk *bulk, struct gpiod_line *line)
 Add a single line to a GPIO bulk object. More...
 
static struct gpiod_line * gpiod_line_bulk_get_line (struct gpiod_line_bulk *bulk, unsigned int offset)
 Retrieve the line handle from a line bulk object at given offset. More...
 
static unsigned int gpiod_line_bulk_num_lines (struct gpiod_line_bulk *bulk)
 Retrieve the number of GPIO lines held by this line bulk object. More...
 
unsigned int gpiod_line_offset (struct gpiod_line *line) GPIOD_API
 Read the GPIO line offset. More...
 
const char * gpiod_line_name (struct gpiod_line *line) GPIOD_API
 Read the GPIO line name. More...
 
const char * gpiod_line_consumer (struct gpiod_line *line) GPIOD_API
 Read the GPIO line consumer name. More...
 
int gpiod_line_direction (struct gpiod_line *line) GPIOD_API
 Read the GPIO line direction setting. More...
 
int gpiod_line_active_state (struct gpiod_line *line) GPIOD_API
 Read the GPIO line active state setting. More...
 
int gpiod_line_bias (struct gpiod_line *line) GPIOD_API
 Read the GPIO line bias setting. More...
 
bool gpiod_line_is_used (struct gpiod_line *line) GPIOD_API
 Check if the line is currently in use. More...
 
bool gpiod_line_is_open_drain (struct gpiod_line *line) GPIOD_API
 Check if the line is an open-drain GPIO. More...
 
bool gpiod_line_is_open_source (struct gpiod_line *line) GPIOD_API
 Check if the line is an open-source GPIO. More...
 
int gpiod_line_update (struct gpiod_line *line) GPIOD_API
 Re-read the line info. More...
 
bool gpiod_line_needs_update (struct gpiod_line *line) GPIOD_API GPIOD_DEPRECATED
 Check if the line info needs to be updated. More...
 
int gpiod_line_request (struct gpiod_line *line, const struct gpiod_line_request_config *config, int default_val) GPIOD_API
 Reserve a single line. More...
 
int gpiod_line_request_input (struct gpiod_line *line, const char *consumer) GPIOD_API
 Reserve a single line, set the direction to input. More...
 
int gpiod_line_request_output (struct gpiod_line *line, const char *consumer, int default_val) GPIOD_API
 Reserve a single line, set the direction to output. More...
 
int gpiod_line_request_rising_edge_events (struct gpiod_line *line, const char *consumer) GPIOD_API
 Request rising edge event notifications on a single line. More...
 
int gpiod_line_request_falling_edge_events (struct gpiod_line *line, const char *consumer) GPIOD_API
 Request falling edge event notifications on a single line. More...
 
int gpiod_line_request_both_edges_events (struct gpiod_line *line, const char *consumer) GPIOD_API
 Request all event type notifications on a single line. More...
 
int gpiod_line_request_input_flags (struct gpiod_line *line, const char *consumer, int flags) GPIOD_API
 Reserve a single line, set the direction to input. More...
 
int gpiod_line_request_output_flags (struct gpiod_line *line, const char *consumer, int flags, int default_val) GPIOD_API
 Reserve a single line, set the direction to output. More...
 
int gpiod_line_request_rising_edge_events_flags (struct gpiod_line *line, const char *consumer, int flags) GPIOD_API
 Request rising edge event notifications on a single line. More...
 
int gpiod_line_request_falling_edge_events_flags (struct gpiod_line *line, const char *consumer, int flags) GPIOD_API
 Request falling edge event notifications on a single line. More...
 
int gpiod_line_request_both_edges_events_flags (struct gpiod_line *line, const char *consumer, int flags) GPIOD_API
 Request all event type notifications on a single line. More...
 
int gpiod_line_request_bulk (struct gpiod_line_bulk *bulk, const struct gpiod_line_request_config *config, const int *default_vals) GPIOD_API
 Reserve a set of GPIO lines. More...
 
int gpiod_line_request_bulk_input (struct gpiod_line_bulk *bulk, const char *consumer) GPIOD_API
 Reserve a set of GPIO lines, set the direction to input. More...
 
int gpiod_line_request_bulk_output (struct gpiod_line_bulk *bulk, const char *consumer, const int *default_vals) GPIOD_API
 Reserve a set of GPIO lines, set the direction to output. More...
 
int gpiod_line_request_bulk_rising_edge_events (struct gpiod_line_bulk *bulk, const char *consumer) GPIOD_API
 Request rising edge event notifications on a set of lines. More...
 
int gpiod_line_request_bulk_falling_edge_events (struct gpiod_line_bulk *bulk, const char *consumer) GPIOD_API
 Request falling edge event notifications on a set of lines. More...
 
int gpiod_line_request_bulk_both_edges_events (struct gpiod_line_bulk *bulk, const char *consumer) GPIOD_API
 Request all event type notifications on a set of lines. More...
 
int gpiod_line_request_bulk_input_flags (struct gpiod_line_bulk *bulk, const char *consumer, int flags) GPIOD_API
 Reserve a set of GPIO lines, set the direction to input. More...
 
int gpiod_line_request_bulk_output_flags (struct gpiod_line_bulk *bulk, const char *consumer, int flags, const int *default_vals) GPIOD_API
 Reserve a set of GPIO lines, set the direction to output. More...
 
int gpiod_line_request_bulk_rising_edge_events_flags (struct gpiod_line_bulk *bulk, const char *consumer, int flags) GPIOD_API
 Request rising edge event notifications on a set of lines. More...
 
int gpiod_line_request_bulk_falling_edge_events_flags (struct gpiod_line_bulk *bulk, const char *consumer, int flags) GPIOD_API
 Request falling edge event notifications on a set of lines. More...
 
int gpiod_line_request_bulk_both_edges_events_flags (struct gpiod_line_bulk *bulk, const char *consumer, int flags) GPIOD_API
 Request all event type notifications on a set of lines. More...
 
void gpiod_line_release (struct gpiod_line *line) GPIOD_API
 Release a previously reserved line. More...
 
void gpiod_line_release_bulk (struct gpiod_line_bulk *bulk) GPIOD_API
 Release a set of previously reserved lines. More...
 
bool gpiod_line_is_requested (struct gpiod_line *line) GPIOD_API
 Check if the calling user has ownership of this line. More...
 
bool gpiod_line_is_free (struct gpiod_line *line) GPIOD_API
 Check if the calling user has neither requested ownership of this line nor configured any event notifications. More...
 
int gpiod_line_get_value (struct gpiod_line *line) GPIOD_API
 Read current value of a single GPIO line. More...
 
int gpiod_line_get_value_bulk (struct gpiod_line_bulk *bulk, int *values) GPIOD_API
 Read current values of a set of GPIO lines. More...
 
int gpiod_line_set_value (struct gpiod_line *line, int value) GPIOD_API
 Set the value of a single GPIO line. More...
 
int gpiod_line_set_value_bulk (struct gpiod_line_bulk *bulk, const int *values) GPIOD_API
 Set the values of a set of GPIO lines. More...
 
int gpiod_line_set_config (struct gpiod_line *line, int direction, int flags, int value) GPIOD_API
 Update the configuration of a single GPIO line. More...
 
int gpiod_line_set_config_bulk (struct gpiod_line_bulk *bulk, int direction, int flags, const int *values) GPIOD_API
 Update the configuration of a set of GPIO lines. More...
 
int gpiod_line_set_flags (struct gpiod_line *line, int flags) GPIOD_API
 Update the configuration flags of a single GPIO line. More...
 
int gpiod_line_set_flags_bulk (struct gpiod_line_bulk *bulk, int flags) GPIOD_API
 Update the configuration flags of a set of GPIO lines. More...
 
int gpiod_line_set_direction_input (struct gpiod_line *line) GPIOD_API
 Set the direction of a single GPIO line to input. More...
 
int gpiod_line_set_direction_input_bulk (struct gpiod_line_bulk *bulk) GPIOD_API
 Set the direction of a set of GPIO lines to input. More...
 
int gpiod_line_set_direction_output (struct gpiod_line *line, int value) GPIOD_API
 Set the direction of a single GPIO line to output. More...
 
int gpiod_line_set_direction_output_bulk (struct gpiod_line_bulk *bulk, const int *values) GPIOD_API
 Set the direction of a set of GPIO lines to output. More...
 
int gpiod_line_event_wait (struct gpiod_line *line, const struct timespec *timeout) GPIOD_API
 Wait for an event on a single line. More...
 
int gpiod_line_event_wait_bulk (struct gpiod_line_bulk *bulk, const struct timespec *timeout, struct gpiod_line_bulk *event_bulk) GPIOD_API
 Wait for events on a set of lines. More...
 
int gpiod_line_event_read (struct gpiod_line *line, struct gpiod_line_event *event) GPIOD_API
 Read the last event from the GPIO line. More...
 
int gpiod_line_event_read_multiple (struct gpiod_line *line, struct gpiod_line_event *events, unsigned int num_events) GPIOD_API
 Read up to a certain number of events from the GPIO line. More...
 
int gpiod_line_event_get_fd (struct gpiod_line *line) GPIOD_API
 Get the event file descriptor. More...
 
int gpiod_line_event_read_fd (int fd, struct gpiod_line_event *event) GPIOD_API
 Read the last GPIO event directly from a file descriptor. More...
 
int gpiod_line_event_read_fd_multiple (int fd, struct gpiod_line_event *events, unsigned int num_events) GPIOD_API
 Read up to a certain number of events directly from a file descriptor. More...
 
struct gpiod_line * gpiod_line_get (const char *device, unsigned int offset) GPIOD_API
 Get a GPIO line handle by GPIO chip description and offset. More...
 
struct gpiod_line * gpiod_line_find (const char *name) GPIOD_API
 Find a GPIO line by its name. More...
 
void gpiod_line_close_chip (struct gpiod_line *line) GPIOD_API
 Close a GPIO chip owning this line and release all resources. More...
 
struct gpiod_chip * gpiod_line_get_chip (struct gpiod_line *line) GPIOD_API
 Get the handle to the GPIO chip controlling this line. More...
 
struct gpiod_chip_iter * gpiod_chip_iter_new (void) GPIOD_API
 Create a new gpiochip iterator. More...
 
void gpiod_chip_iter_free (struct gpiod_chip_iter *iter) GPIOD_API
 Release all resources allocated for the gpiochip iterator and close the most recently opened gpiochip (if any). More...
 
void gpiod_chip_iter_free_noclose (struct gpiod_chip_iter *iter) GPIOD_API
 Release all resources allocated for the gpiochip iterator but don't close the most recently opened gpiochip (if any). More...
 
struct gpiod_chip * gpiod_chip_iter_next (struct gpiod_chip_iter *iter) GPIOD_API
 Get the next gpiochip handle. More...
 
struct gpiod_chip * gpiod_chip_iter_next_noclose (struct gpiod_chip_iter *iter) GPIOD_API
 Get the next gpiochip handle without closing the previous one. More...
 
struct gpiod_line_iter * gpiod_line_iter_new (struct gpiod_chip *chip) GPIOD_API
 Create a new line iterator. More...
 
void gpiod_line_iter_free (struct gpiod_line_iter *iter) GPIOD_API
 Free all resources associated with a GPIO line iterator. More...
 
struct gpiod_line * gpiod_line_iter_next (struct gpiod_line_iter *iter) GPIOD_API
 Get the next GPIO line handle. More...
 
const char * gpiod_version_string (void) GPIOD_API
 Get the API version of the library as a human-readable string. More...
 
GPIOD_API line gpiod::find_line (const ::std::string &name)
 Find a GPIO line by name. More...
 
GPIOD_API chip_iter gpiod::make_chip_iter (void)
 Create a new chip_iter. More...
 
GPIOD_API chip_iter gpiod::begin (chip_iter iter) noexcept
 Support for range-based loops for chip iterators. More...
 
GPIOD_API chip_iter gpiod::end (const chip_iter &iter) noexcept
 Support for range-based loops for chip iterators. More...
 
GPIOD_API line_iter gpiod::begin (line_iter iter) noexcept
 Support for range-based loops for line iterators. More...
 
GPIOD_API line_iter gpiod::end (const line_iter &iter) noexcept
 Support for range-based loops for line iterators. More...
 

Detailed Description

Commonly used utility macros.

Various libgpiod-related functions.

These functions and data structures allow easy iterating over GPIO chips and lines.

Functions and data structures dealing with GPIO lines.

Functions and data structures dealing with GPIO chips.

Simple high-level routines for straightforward GPIO manipulation without the need to use the gpiod_* structures or to keep track of resources.

Macro Definition Documentation

◆ GPIOD_BIT

#define GPIOD_BIT (   nr)    (1UL << (nr))

Shift 1 by given offset.

Parameters
nrBit position.
Returns
1 shifted by nr.

Definition at line 70 of file gpiod.h.

◆ gpiod_foreach_chip

#define gpiod_foreach_chip (   iter,
  chip 
)
Value:
for ((chip) = gpiod_chip_iter_next(iter); \
(chip); \
(chip) = gpiod_chip_iter_next(iter))

Iterate over all GPIO chips present in the system.

Parameters
iterAn initialized GPIO chip iterator.
chipPointer to a GPIO chip handle. On each iteration the newly opened chip handle is assigned to this argument.

The user must not close the GPIO chip manually - instead the previous chip handle is closed automatically on the next iteration. The last chip to be opened is closed internally by gpiod_chip_iter_free.

Definition at line 1651 of file gpiod.h.

◆ gpiod_foreach_chip_noclose

#define gpiod_foreach_chip_noclose (   iter,
  chip 
)
Value:
for ((chip) = gpiod_chip_iter_next_noclose(iter); \
(chip); \

Iterate over all chips present in the system without closing them.

Parameters
iterAn initialized GPIO chip iterator.
chipPointer to a GPIO chip handle. On each iteration the newly opened chip handle is assigned to this argument.

The user must close all the GPIO chips manually after use, until then, the chips remain open. Free the iterator by calling gpiod_chip_iter_free_noclose to avoid closing the last chip automatically.

Definition at line 1666 of file gpiod.h.

◆ gpiod_foreach_line

#define gpiod_foreach_line (   iter,
  line 
)
Value:
for ((line) = gpiod_line_iter_next(iter); \
(line); \
(line) = gpiod_line_iter_next(iter))

Iterate over all GPIO lines of a single chip.

Parameters
iterAn initialized GPIO line iterator.
linePointer to a GPIO line handle - on each iteration, the next GPIO line will be assigned to this argument.

Definition at line 1701 of file gpiod.h.

◆ gpiod_line_bulk_foreach_line

#define gpiod_line_bulk_foreach_line (   bulk,
  line,
  lineptr 
)
Value:
for ((lineptr) = (bulk)->lines, (line) = *(lineptr); \
(lineptr) <= (bulk)->lines + ((bulk)->num_lines - 1); \
(lineptr)++, (line) = *(lineptr))

Iterate over all line handles held by a line bulk object.

Parameters
bulkLine bulk object.
lineGPIO line handle. On each iteration, the subsequent line handle is assigned to this pointer.
lineptrPointer to a GPIO line handle used to store the loop state.

Definition at line 766 of file gpiod.h.

◆ gpiod_line_bulk_foreach_line_off

#define gpiod_line_bulk_foreach_line_off (   bulk,
  line,
  offset 
)
Value:
for ((offset) = 0, (line) = (bulk)->lines[0]; \
(offset) < (bulk)->num_lines; \
(offset)++, (line) = (bulk)->lines[(offset)])

Iterate over all line handles held by a line bulk object (integer counter variant).

Parameters
bulkLine bulk object.
lineGPIO line handle. On each iteration, the subsequent line handle is assigned to this pointer.
offsetAn integer variable used to store the loop state.

This is a variant of gpiod_line_bulk_foreach_line which uses an integer variable (either signed or unsigned) to store the loop state. This offset variable is guaranteed to correspond to the offset of the current line in the bulk->lines array.

Definition at line 784 of file gpiod.h.

◆ GPIOD_LINE_BULK_INITIALIZER

#define GPIOD_LINE_BULK_INITIALIZER   { { NULL }, 0 }

Static initializer for GPIO bulk objects.

This macro simply sets the internally held number of lines to 0.

Definition at line 712 of file gpiod.h.

Typedef Documentation

◆ gpiod_ctxless_event_handle_cb

typedef int(* gpiod_ctxless_event_handle_cb) (int, unsigned int, const struct timespec *, void *)

Simple event callback signature.

The callback function takes the following arguments: event type (int), GPIO line offset (unsigned int), event timestamp (const struct timespec *) and a pointer to user data (void *).

This callback is called by the ctxless event loop functions for each GPIO event. If the callback returns GPIOD_CTXLESS_EVENT_CB_RET_ERR, it should also set errno.

Definition at line 292 of file gpiod.h.

◆ gpiod_ctxless_event_poll_cb

typedef int(* gpiod_ctxless_event_poll_cb) (unsigned int, struct gpiod_ctxless_event_poll_fd *, const struct timespec *, void *)

Simple event poll callback signature.

The poll callback function takes the following arguments: number of lines (unsigned int), an array of file descriptors on which input events should be monitored (struct gpiod_ctxless_event_poll_fd *), poll timeout (const struct timespec *) and a pointer to user data (void *).

The callback should poll for input events on the set of descriptors and return an appropriate value that can be interpreted by the event loop routine.

Definition at line 332 of file gpiod.h.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum

Miscellaneous GPIO flags.

Enumerator
GPIOD_CTXLESS_FLAG_OPEN_DRAIN 

The line is an open-drain port.

GPIOD_CTXLESS_FLAG_OPEN_SOURCE 

The line is an open-source port.

GPIOD_CTXLESS_FLAG_BIAS_DISABLE 

The line has neither either pull-up nor pull-down resistor.

GPIOD_CTXLESS_FLAG_BIAS_PULL_DOWN 

The line has pull-down resistor enabled.

GPIOD_CTXLESS_FLAG_BIAS_PULL_UP 

The line has pull-up resistor enabled.

Definition at line 90 of file gpiod.h.

◆ anonymous enum

anonymous enum

Event types that the ctxless event monitor can wait for.

Enumerator
GPIOD_CTXLESS_EVENT_RISING_EDGE 

Wait for rising edge events only.

Wait for falling edge events only.

GPIOD_CTXLESS_EVENT_FALLING_EDGE 

Wait for both types of events.

Definition at line 248 of file gpiod.h.

◆ anonymous enum

anonymous enum

Event types.

Enumerator
GPIOD_LINE_EVENT_RISING_EDGE 

Rising edge event.

GPIOD_LINE_EVENT_FALLING_EDGE 

Falling edge event.

Definition at line 1432 of file gpiod.h.

◆ anonymous enum

anonymous enum

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

Enumerator
GPIOD_CTXLESS_EVENT_CB_TIMEOUT 

Waiting for events timed out.

GPIOD_CTXLESS_EVENT_CB_RISING_EDGE 

Rising edge event occured.

GPIOD_CTXLESS_EVENT_CB_FALLING_EDGE 

Falling edge event occured.

Definition at line 260 of file gpiod.h.

◆ anonymous enum

anonymous enum

Return status values that the ctxless event callback can return.

Enumerator
GPIOD_CTXLESS_EVENT_CB_RET_ERR 

Stop processing events and indicate an error.

GPIOD_CTXLESS_EVENT_CB_RET_OK 

Continue processing events.

GPIOD_CTXLESS_EVENT_CB_RET_STOP 

Stop processing events.

Definition at line 272 of file gpiod.h.

◆ anonymous enum

anonymous enum

Return status values that the ctxless event poll callback can return.

Positive value returned from the polling callback indicates the number of events that occurred on the set of monitored lines.

Enumerator
GPIOD_CTXLESS_EVENT_POLL_RET_STOP 

The event loop should stop processing events.

GPIOD_CTXLESS_EVENT_POLL_RET_ERR 

Polling error occurred (the polling function should set errno).

GPIOD_CTXLESS_EVENT_POLL_RET_TIMEOUT 

Poll timed out.

Definition at line 301 of file gpiod.h.

◆ anonymous enum

anonymous enum

Possible direction settings.

Enumerator
GPIOD_LINE_DIRECTION_INPUT 

Direction is input - we're reading the state of a GPIO line.

GPIOD_LINE_DIRECTION_OUTPUT 

Direction is output - we're driving the GPIO line.

Definition at line 799 of file gpiod.h.

◆ anonymous enum

anonymous enum

Possible active state settings.

Enumerator
GPIOD_LINE_ACTIVE_STATE_HIGH 

The active state of a GPIO is active-high.

GPIOD_LINE_ACTIVE_STATE_LOW 

The active state of a GPIO is active-low.

Definition at line 809 of file gpiod.h.

◆ anonymous enum

anonymous enum

Possible internal bias settings.

Enumerator
GPIOD_LINE_BIAS_AS_IS 

The internal bias state is unknown.

GPIOD_LINE_BIAS_DISABLE 

The internal bias is disabled.

GPIOD_LINE_BIAS_PULL_UP 

The internal pull-up bias is enabled.

GPIOD_LINE_BIAS_PULL_DOWN 

The internal pull-down bias is enabled.

Definition at line 819 of file gpiod.h.

◆ anonymous enum

anonymous enum

Available types of requests.

Enumerator
GPIOD_LINE_REQUEST_DIRECTION_AS_IS 

Request the line(s), but don't change current direction.

GPIOD_LINE_REQUEST_DIRECTION_INPUT 

Request the line(s) for reading the GPIO line state.

GPIOD_LINE_REQUEST_DIRECTION_OUTPUT 

Request the line(s) for setting the GPIO line state.

GPIOD_LINE_REQUEST_EVENT_FALLING_EDGE 

Monitor both types of events.

GPIOD_LINE_REQUEST_EVENT_RISING_EDGE 

Only watch rising edge events.

GPIOD_LINE_REQUEST_EVENT_BOTH_EDGES 

Only watch falling edge events.

Definition at line 942 of file gpiod.h.

◆ anonymous enum

anonymous enum

Miscellaneous GPIO request flags.

Enumerator
GPIOD_LINE_REQUEST_FLAG_OPEN_DRAIN 

The line is an open-drain port.

GPIOD_LINE_REQUEST_FLAG_OPEN_SOURCE 

The line is an open-source port.

GPIOD_LINE_REQUEST_FLAG_ACTIVE_LOW 

The active state of the line is low (high is the default).

GPIOD_LINE_REQUEST_FLAG_BIAS_DISABLE 

The line has neither either pull-up nor pull-down resistor.

GPIOD_LINE_REQUEST_FLAG_BIAS_PULL_DOWN 

The line has pull-down resistor enabled.

GPIOD_LINE_REQUEST_FLAG_BIAS_PULL_UP 

The line has pull-up resistor enabled.

Definition at line 960 of file gpiod.h.

Function Documentation

◆ begin() [1/2]

GPIOD_API chip_iter gpiod::begin ( chip_iter  iter)
noexcept

Support for range-based loops for chip iterators.

Parameters
iterA chip iterator.
Returns
Iterator unchanged.

◆ begin() [2/2]

GPIOD_API line_iter gpiod::begin ( line_iter  iter)
noexcept

Support for range-based loops for line iterators.

Parameters
iterA line iterator.
Returns
Iterator unchanged.

◆ end() [1/2]

GPIOD_API chip_iter gpiod::end ( const chip_iter iter)
noexcept

Support for range-based loops for chip iterators.

Parameters
iterA chip iterator.
Returns
New end iterator.

◆ end() [2/2]

GPIOD_API line_iter gpiod::end ( const line_iter iter)
noexcept

Support for range-based loops for line iterators.

Parameters
iterA line iterator.
Returns
New end iterator.

◆ find_line()

GPIOD_API line gpiod::find_line ( const ::std::string &  name)

Find a GPIO line by name.

Search all GPIO chips present on the system.

Parameters
nameName of the line.
Returns
Returns a line object - empty if the line was not found.

◆ gpiod_chip_close()

void gpiod_chip_close ( struct gpiod_chip *  chip)

Close a GPIO chip handle and release all allocated resources.

Parameters
chipThe GPIO chip object.

◆ gpiod_chip_find_line()

struct gpiod_line* gpiod_chip_find_line ( struct gpiod_chip *  chip,
const char *  name 
)

Find a GPIO line by name among lines associated with given GPIO chip.

Parameters
chipThe GPIO chip object.
nameThe name of the GPIO line.
Returns
Pointer to the GPIO line handle or NULL if the line could not be found or an error occurred.
Note
In case a line with given name is not associated with given chip, the function sets errno to ENOENT.

◆ gpiod_chip_find_lines()

int gpiod_chip_find_lines ( struct gpiod_chip *  chip,
const char **  names,
struct gpiod_line_bulk bulk 
)

Find a set of GPIO lines by names among lines exposed by this chip.

Parameters
chipThe GPIO chip object.
namesArray of pointers to C-strings containing the names of the lines to lookup. Must end with a NULL-pointer.
bulkLine bulk object in which the located lines will be stored.
Returns
0 if all lines were located, -1 on error.
Note
If at least one line from the list could not be found among the lines exposed by this chip, the function sets errno to ENOENT.

◆ gpiod_chip_get_all_lines()

int gpiod_chip_get_all_lines ( struct gpiod_chip *  chip,
struct gpiod_line_bulk bulk 
)

Retrieve all lines exposed by a chip and store them in a bulk object.

Parameters
chipThe GPIO chip object.
bulkLine bulk object in which to store the line handles.
Returns
0 on success, -1 on error.

◆ gpiod_chip_get_line()

struct gpiod_line* gpiod_chip_get_line ( struct gpiod_chip *  chip,
unsigned int  offset 
)

Get the handle to the GPIO line at given offset.

Parameters
chipThe GPIO chip object.
offsetThe offset of the GPIO line.
Returns
Pointer to the GPIO line handle or NULL if an error occured.

◆ gpiod_chip_get_lines()

int gpiod_chip_get_lines ( struct gpiod_chip *  chip,
unsigned int *  offsets,
unsigned int  num_offsets,
struct gpiod_line_bulk bulk 
)

Retrieve a set of lines and store them in a line bulk object.

Parameters
chipThe GPIO chip object.
offsetsArray of offsets of lines to retrieve.
num_offsetsNumber of lines to retrieve.
bulkLine bulk object in which to store the line handles.
Returns
0 on success, -1 on error.

◆ gpiod_chip_iter_free()

void gpiod_chip_iter_free ( struct gpiod_chip_iter *  iter)

Release all resources allocated for the gpiochip iterator and close the most recently opened gpiochip (if any).

Parameters
iterThe gpiochip iterator object.

◆ gpiod_chip_iter_free_noclose()

void gpiod_chip_iter_free_noclose ( struct gpiod_chip_iter *  iter)

Release all resources allocated for the gpiochip iterator but don't close the most recently opened gpiochip (if any).

Parameters
iterThe gpiochip iterator object.

Users may want to break the loop when iterating over gpiochips and keep the most recently opened chip active while freeing the iterator data. This routine enables that.

◆ gpiod_chip_iter_new()

struct gpiod_chip_iter* gpiod_chip_iter_new ( void  )

Create a new gpiochip iterator.

Returns
Pointer to a new chip iterator object or NULL if an error occurred.

Internally this routine scans the /dev/ directory for GPIO chip device files, opens them and stores their the handles until gpiod_chip_iter_free or gpiod_chip_iter_free_noclose is called.

◆ gpiod_chip_iter_next()

struct gpiod_chip* gpiod_chip_iter_next ( struct gpiod_chip_iter *  iter)

Get the next gpiochip handle.

Parameters
iterThe gpiochip iterator object.
Returns
Pointer to the next open gpiochip handle or NULL if no more chips are present in the system.
Note
The previous chip handle will be closed using gpiod_chip_iter_free.

◆ gpiod_chip_iter_next_noclose()

struct gpiod_chip* gpiod_chip_iter_next_noclose ( struct gpiod_chip_iter *  iter)

Get the next gpiochip handle without closing the previous one.

Parameters
iterThe gpiochip iterator object.
Returns
Pointer to the next open gpiochip handle or NULL if no more chips are present in the system.
Note
This function works just like gpiod_chip_iter_next but doesn't close the most recently opened chip handle.

◆ gpiod_chip_label()

const char* gpiod_chip_label ( struct gpiod_chip *  chip)

Get the GPIO chip label as represented in the kernel.

Parameters
chipThe GPIO chip object.
Returns
Pointer to a human-readable string containing the chip label.

◆ gpiod_chip_name()

const char* gpiod_chip_name ( struct gpiod_chip *  chip)

Get the GPIO chip name as represented in the kernel.

Parameters
chipThe GPIO chip object.
Returns
Pointer to a human-readable string containing the chip name.

◆ gpiod_chip_num_lines()

unsigned int gpiod_chip_num_lines ( struct gpiod_chip *  chip)

Get the number of GPIO lines exposed by this chip.

Parameters
chipThe GPIO chip object.
Returns
Number of GPIO lines.

◆ gpiod_chip_open()

struct gpiod_chip* gpiod_chip_open ( const char *  path)

Open a gpiochip by path.

Parameters
pathPath to the gpiochip device file.
Returns
GPIO chip handle or NULL if an error occurred.

◆ gpiod_chip_open_by_label()

struct gpiod_chip* gpiod_chip_open_by_label ( const char *  label)

Open a gpiochip by label.

Parameters
labelLabel of the gpiochip to open.
Returns
GPIO chip handle or NULL if the chip with given label was not found or an error occured.
Note
If the chip cannot be found but no other error occurred, errno is set to ENOENT.

◆ gpiod_chip_open_by_name()

struct gpiod_chip* gpiod_chip_open_by_name ( const char *  name)

Open a gpiochip by name.

Parameters
nameName of the gpiochip to open.
Returns
GPIO chip handle or NULL if an error occurred.

This routine appends name to '/dev/' to create the path.

◆ gpiod_chip_open_by_number()

struct gpiod_chip* gpiod_chip_open_by_number ( unsigned int  num)

Open a gpiochip by number.

Parameters
numNumber of the gpiochip.
Returns
GPIO chip handle or NULL if an error occurred.

This routine appends num to '/dev/gpiochip' to create the path.

◆ gpiod_chip_open_lookup()

struct gpiod_chip* gpiod_chip_open_lookup ( const char *  descr)

Open a gpiochip based on the best guess what the path is.

Parameters
descrString describing the gpiochip.
Returns
GPIO chip handle or NULL if an error occurred.

This routine tries to figure out whether the user passed it the path to the GPIO chip, its name, label or number as a string. Then it tries to open it using one of the gpiod_chip_open** variants.

◆ gpiod_ctxless_event_loop()

int gpiod_ctxless_event_loop ( const char *  device,
unsigned int  offset,
bool  active_low,
const char *  consumer,
const struct timespec *  timeout,
gpiod_ctxless_event_poll_cb  poll_cb,
gpiod_ctxless_event_handle_cb  event_cb,
void *  data 
)

Wait for events on a single GPIO line.

Parameters
deviceName, path, number or label of the gpiochip.
offsetGPIO line offset to monitor.
active_lowThe active state of this line - true if low.
consumerName of the consumer.
timeoutMaximum wait time for each iteration.
poll_cbCallback function to call when waiting for events.
event_cbCallback function to call for each line event.
dataUser data passed to the callback.
Returns
0 if no errors were encountered, -1 if an error occurred.
Note
The way the ctxless event loop works is described in detail in gpiod_ctxless_event_loop_multiple - this is just a wrapper aound this routine which calls it for a single GPIO line.

◆ gpiod_ctxless_event_loop_multiple()

int gpiod_ctxless_event_loop_multiple ( const char *  device,
const unsigned int *  offsets,
unsigned int  num_lines,
bool  active_low,
const char *  consumer,
const struct timespec *  timeout,
gpiod_ctxless_event_poll_cb  poll_cb,
gpiod_ctxless_event_handle_cb  event_cb,
void *  data 
)

Wait for events on multiple GPIO lines.

Parameters
deviceName, path, number or label of the gpiochip.
offsetsArray of GPIO line offsets to monitor.
num_linesNumber of lines to monitor.
active_lowThe active state of this line - true if low.
consumerName of the consumer.
timeoutMaximum wait time for each iteration.
poll_cbCallback function to call when waiting for events. Can be NULL.
event_cbCallback function to call on event occurrence.
dataUser data passed to the callback.
Returns
0 no errors were encountered, -1 if an error occurred.
Note
The poll callback can be NULL in which case the routine will fall back to a basic, ppoll() based callback.

Internally this routine opens the GPIO chip, requests the set of lines for both-edges events and calls the polling callback in a loop. The role of the polling callback is to detect input events on a set of file descriptors and notify the caller about the fds ready for reading.

The ctxless event loop then reads each queued event from marked descriptors and calls the event callback. Both callbacks can stop the loop at any point.

The poll_cb argument can be NULL in which case the function falls back to a default, ppoll() based callback.

◆ gpiod_ctxless_event_monitor()

int gpiod_ctxless_event_monitor ( const char *  device,
int  event_type,
unsigned int  offset,
bool  active_low,
const char *  consumer,
const struct timespec *  timeout,
gpiod_ctxless_event_poll_cb  poll_cb,
gpiod_ctxless_event_handle_cb  event_cb,
void *  data 
)

Wait for events on a single GPIO line.

Parameters
deviceName, path, number or label of the gpiochip.
event_typeType of events to listen for.
offsetGPIO line offset to monitor.
active_lowThe active state of this line - true if low.
consumerName of the consumer.
timeoutMaximum wait time for each iteration.
poll_cbCallback function to call when waiting for events.
event_cbCallback function to call for each line event.
dataUser data passed to the callback.
Returns
0 if no errors were encountered, -1 if an error occurred.
Note
The way the ctxless event loop works is described in detail in gpiod_ctxless_event_monitor_multiple - this is just a wrapper aound this routine which calls it for a single GPIO line.

◆ gpiod_ctxless_event_monitor_ext()

int gpiod_ctxless_event_monitor_ext ( const char *  device,
int  event_type,
unsigned int  offset,
bool  active_low,
const char *  consumer,
const struct timespec *  timeout,
gpiod_ctxless_event_poll_cb  poll_cb,
gpiod_ctxless_event_handle_cb  event_cb,
void *  data,
int  flags 
)

Wait for events on a single GPIO line.

Parameters
deviceName, path, number or label of the gpiochip.
event_typeType of events to listen for.
offsetGPIO line offset to monitor.
active_lowThe active state of this line - true if low.
consumerName of the consumer.
timeoutMaximum wait time for each iteration.
poll_cbCallback function to call when waiting for events.
event_cbCallback function to call for each line event.
dataUser data passed to the callback.
flagsThe flags for the line.
Returns
0 if no errors were encountered, -1 if an error occurred.
Note
The way the ctxless event loop works is described in detail in gpiod_ctxless_event_monitor_multiple - this is just a wrapper aound this routine which calls it for a single GPIO line.

◆ gpiod_ctxless_event_monitor_multiple()

int gpiod_ctxless_event_monitor_multiple ( const char *  device,
int  event_type,
const unsigned int *  offsets,
unsigned int  num_lines,
bool  active_low,
const char *  consumer,
const struct timespec *  timeout,
gpiod_ctxless_event_poll_cb  poll_cb,
gpiod_ctxless_event_handle_cb  event_cb,
void *  data 
)

Wait for events on multiple GPIO lines.

Parameters
deviceName, path, number or label of the gpiochip.
event_typeType of events to listen for.
offsetsArray of GPIO line offsets to monitor.
num_linesNumber of lines to monitor.
active_lowThe active state of this line - true if low.
consumerName of the consumer.
timeoutMaximum wait time for each iteration.
poll_cbCallback function to call when waiting for events. Can be NULL.
event_cbCallback function to call on event occurrence.
dataUser data passed to the callback.
Returns
0 no errors were encountered, -1 if an error occurred.
Note
The poll callback can be NULL in which case the routine will fall back to a basic, ppoll() based callback.

Internally this routine opens the GPIO chip, requests the set of lines for the type of events specified in the event_type parameter and calls the polling callback in a loop. The role of the polling callback is to detect input events on a set of file descriptors and notify the caller about the fds ready for reading.

The ctxless event loop then reads each queued event from marked descriptors and calls the event callback. Both callbacks can stop the loop at any point.

The poll_cb argument can be NULL in which case the function falls back to a default, ppoll() based callback.

◆ gpiod_ctxless_event_monitor_multiple_ext()

int gpiod_ctxless_event_monitor_multiple_ext ( const char *  device,
int  event_type,
const unsigned int *  offsets,
unsigned int  num_lines,
bool  active_low,
const char *  consumer,
const struct timespec *  timeout,
gpiod_ctxless_event_poll_cb  poll_cb,
gpiod_ctxless_event_handle_cb  event_cb,
void *  data,
int  flags 
)

Wait for events on multiple GPIO lines.

Parameters
deviceName, path, number or label of the gpiochip.
event_typeType of events to listen for.
offsetsArray of GPIO line offsets to monitor.
num_linesNumber of lines to monitor.
active_lowThe active state of this line - true if low.
consumerName of the consumer.
timeoutMaximum wait time for each iteration.
poll_cbCallback function to call when waiting for events. Can be NULL.
event_cbCallback function to call on event occurrence.
dataUser data passed to the callback.
flagsThe flags for the lines.
Returns
0 no errors were encountered, -1 if an error occurred.
Note
The poll callback can be NULL in which case the routine will fall back to a basic, ppoll() based callback.

Internally this routine opens the GPIO chip, requests the set of lines for the type of events specified in the event_type parameter and calls the polling callback in a loop. The role of the polling callback is to detect input events on a set of file descriptors and notify the caller about the fds ready for reading.

The ctxless event loop then reads each queued event from marked descriptors and calls the event callback. Both callbacks can stop the loop at any point.

The poll_cb argument can be NULL in which case the function falls back to a default, ppoll() based callback.

◆ gpiod_ctxless_find_line()

int gpiod_ctxless_find_line ( const char *  name,
char *  chipname,
size_t  chipname_size,
unsigned int *  offset 
)

Determine the chip name and line offset of a line with given name.

Parameters
nameThe name of the GPIO line to lookup.
chipnameBuffer in which the name of the GPIO chip will be stored.
chipname_sizeSize of the chip name buffer.
offsetPointer to an integer in which the line offset will be stored.
Returns
-1 on error, 0 if the line with given name doesn't exist and 1 if the line was found. In the first two cases the contents of chipname and offset remain unchanged.
Note
The chip name is truncated if the buffer can't hold its entire size.

◆ gpiod_ctxless_get_value()

int gpiod_ctxless_get_value ( const char *  device,
unsigned int  offset,
bool  active_low,
const char *  consumer 
)

Read current value from a single GPIO line.

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

◆ gpiod_ctxless_get_value_ext()

int gpiod_ctxless_get_value_ext ( const char *  device,
unsigned int  offset,
bool  active_low,
const char *  consumer,
int  flags 
)

Read current value from a single GPIO line.

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

◆ gpiod_ctxless_get_value_multiple()

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

Read current values from a set of GPIO lines.

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

◆ gpiod_ctxless_get_value_multiple_ext()

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

Read current values from a set of GPIO lines.

Parameters
deviceName, path, number or label of the gpiochip.
offsetsArray of offsets of lines whose values should be read.
valuesBuffer in which the values will be stored.
num_linesNumber of lines, must be > 0.
active_lowThe active state of this line - true if low.
consumerName of the consumer.
flagsThe flags for the lines.
Returns
0 if the operation succeeds, -1 on error.

◆ gpiod_ctxless_set_value()

int gpiod_ctxless_set_value ( const char *  device,
unsigned int  offset,
int  value,
bool  active_low,
const char *  consumer,
gpiod_ctxless_set_value_cb  cb,
void *  data 
)

Set value of a single GPIO line.

Parameters
deviceName, path, number or label of the gpiochip.
offsetThe offset of the GPIO line.
valueNew value (0 or 1).
active_lowThe active state of this line - true if low.
consumerName of the consumer.
cbOptional callback function that will be called right after setting the value. Users can use this, for example, to pause the execution after toggling a GPIO.
dataOptional user data that will be passed to the callback function.
Returns
0 if the operation succeeds, -1 on error.

◆ gpiod_ctxless_set_value_ext()

int gpiod_ctxless_set_value_ext ( const char *  device,
unsigned int  offset,
int  value,
bool  active_low,
const char *  consumer,
gpiod_ctxless_set_value_cb  cb,
void *  data,
int  flags 
)

Set value of a single GPIO line.

Parameters
deviceName, path, number or label of the gpiochip.
offsetThe offset of the GPIO line.
valueNew value (0 or 1).
active_lowThe active state of this line - true if low.
consumerName of the consumer.
cbOptional callback function that will be called right after setting the value. Users can use this, for example, to pause the execution after toggling a GPIO.
dataOptional user data that will be passed to the callback function.
flagsThe flags for the line.
Returns
0 if the operation succeeds, -1 on error.

◆ gpiod_ctxless_set_value_multiple()

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

Set values of multiple GPIO lines.

Parameters
deviceName, path, number or label of the gpiochip.
offsetsArray of offsets of lines the values of which should be set.
valuesArray of integers containing new values.
num_linesNumber of lines, must be > 0.
active_lowThe active state of the lines - true if low.
consumerName of the consumer.
cbOptional callback function that will be called right after setting all values. Works the same as in gpiod_ctxless_set_value.
dataOptional user data that will be passed to the callback function.
Returns
0 if the operation succeeds, -1 on error.

◆ gpiod_ctxless_set_value_multiple_ext()

int gpiod_ctxless_set_value_multiple_ext ( const char *  device,
const unsigned int *  offsets,
const int *  values,
unsigned int  num_lines,
bool  active_low,
const char *  consumer,
gpiod_ctxless_set_value_cb  cb,
void *  data,
int  flags 
)

Set values of multiple GPIO lines.

Parameters
deviceName, path, number or label of the gpiochip.
offsetsArray of offsets of lines the values of which should be set.
valuesArray of integers containing new values.
num_linesNumber of lines, must be > 0.
active_lowThe active state of this line - true if low.
consumerName of the consumer.
cbOptional callback function that will be called right after setting all values. Works the same as in gpiod_ctxless_set_value.
dataOptional user data that will be passed to the callback function.
flagsThe flags for the lines.
Returns
0 if the operation succeeds, -1 on error.

References GPIOD_CTXLESS_EVENT_FALLING_EDGE, and GPIOD_CTXLESS_EVENT_RISING_EDGE.

◆ gpiod_line_active_state()

int gpiod_line_active_state ( struct gpiod_line *  line)

Read the GPIO line active state setting.

Parameters
lineGPIO line object.
Returns
Returns GPIOD_LINE_ACTIVE_STATE_HIGH or GPIOD_LINE_ACTIVE_STATE_LOW.

◆ gpiod_line_bias()

int gpiod_line_bias ( struct gpiod_line *  line)

Read the GPIO line bias setting.

Parameters
lineGPIO line object.
Returns
Returns GPIOD_LINE_BIAS_PULL_UP, GPIOD_LINE_BIAS_PULL_DOWN, GPIOD_LINE_BIAS_DISABLE or GPIOD_LINE_BIAS_AS_IS.

◆ gpiod_line_bulk_add()

static void gpiod_line_bulk_add ( struct gpiod_line_bulk bulk,
struct gpiod_line *  line 
)
inlinestatic

Add a single line to a GPIO bulk object.

Parameters
bulkLine bulk object.
lineLine to add.

Definition at line 730 of file gpiod.h.

References gpiod_line_bulk::lines, and gpiod_line_bulk::num_lines.

◆ gpiod_line_bulk_get_line()

static struct gpiod_line* gpiod_line_bulk_get_line ( struct gpiod_line_bulk bulk,
unsigned int  offset 
)
inlinestatic

Retrieve the line handle from a line bulk object at given offset.

Parameters
bulkLine bulk object.
offsetLine offset.
Returns
Line handle at given offset.

Definition at line 743 of file gpiod.h.

References gpiod_line_bulk::lines.

◆ gpiod_line_bulk_init()

static void gpiod_line_bulk_init ( struct gpiod_line_bulk bulk)
inlinestatic

Initialize a GPIO bulk object.

Parameters
bulkLine bulk object.

This routine simply sets the internally held number of lines to 0.

Definition at line 720 of file gpiod.h.

References gpiod_line_bulk::num_lines.

◆ gpiod_line_bulk_num_lines()

static unsigned int gpiod_line_bulk_num_lines ( struct gpiod_line_bulk bulk)
inlinestatic

Retrieve the number of GPIO lines held by this line bulk object.

Parameters
bulkLine bulk object.
Returns
Number of lines held by this line bulk.

Definition at line 754 of file gpiod.h.

References gpiod_line_bulk::num_lines.

◆ gpiod_line_close_chip()

void gpiod_line_close_chip ( struct gpiod_line *  line)

Close a GPIO chip owning this line and release all resources.

Parameters
lineGPIO line object

After this function returns, the line must no longer be used.

◆ gpiod_line_consumer()

const char* gpiod_line_consumer ( struct gpiod_line *  line)

Read the GPIO line consumer name.

Parameters
lineGPIO line object.
Returns
Name of the GPIO consumer name as it is represented in the kernel. This routine returns a pointer to a null-terminated string or NULL if the line is not used.

◆ gpiod_line_direction()

int gpiod_line_direction ( struct gpiod_line *  line)

Read the GPIO line direction setting.

Parameters
lineGPIO line object.
Returns
Returns GPIOD_LINE_DIRECTION_INPUT or GPIOD_LINE_DIRECTION_OUTPUT.

◆ gpiod_line_event_get_fd()

int gpiod_line_event_get_fd ( struct gpiod_line *  line)

Get the event file descriptor.

Parameters
lineGPIO line object.
Returns
Number of the event file descriptor or -1 if the user tries to retrieve the descriptor from a line that wasn't configured for event monitoring.

Users may want to poll the event file descriptor on their own. This routine allows to access it.

◆ gpiod_line_event_read()

int gpiod_line_event_read ( struct gpiod_line *  line,
struct gpiod_line_event event 
)

Read the last event from the GPIO line.

Parameters
lineGPIO line object.
eventBuffer to which the event data will be copied.
Returns
0 if the event was read correctly, -1 on error.
Note
This function will block if no event was queued for this line.

◆ gpiod_line_event_read_fd()

int gpiod_line_event_read_fd ( int  fd,
struct gpiod_line_event event 
)

Read the last GPIO event directly from a file descriptor.

Parameters
fdFile descriptor.
eventBuffer in which the event data will be stored.
Returns
0 if the event was read correctly, -1 on error.

Users who directly poll the file descriptor for incoming events can also directly read the event data from it using this routine. This function translates the kernel representation of the event to the libgpiod format.

◆ gpiod_line_event_read_fd_multiple()

int gpiod_line_event_read_fd_multiple ( int  fd,
struct gpiod_line_event events,
unsigned int  num_events 
)

Read up to a certain number of events directly from a file descriptor.

Parameters
fdFile descriptor.
eventsBuffer to which the event data will be copied. Must hold at least the amount of events specified in num_events.
num_eventsSpecifies how many events can be stored in the buffer.
Returns
On success returns the number of events stored in the buffer, on failure -1 is returned.

◆ gpiod_line_event_read_multiple()

int gpiod_line_event_read_multiple ( struct gpiod_line *  line,
struct gpiod_line_event events,
unsigned int  num_events 
)

Read up to a certain number of events from the GPIO line.

Parameters
lineGPIO line object.
eventsBuffer to which the event data will be copied. Must hold at least the amount of events specified in num_events.
num_eventsSpecifies how many events can be stored in the buffer.
Returns
On success returns the number of events stored in the buffer, on failure -1 is returned.

◆ gpiod_line_event_wait()

int gpiod_line_event_wait ( struct gpiod_line *  line,
const struct timespec *  timeout 
)

Wait for an event on a single line.

Parameters
lineGPIO line object.
timeoutWait time limit.
Returns
0 if wait timed out, -1 if an error occurred, 1 if an event occurred.

◆ gpiod_line_event_wait_bulk()

int gpiod_line_event_wait_bulk ( struct gpiod_line_bulk bulk,
const struct timespec *  timeout,
struct gpiod_line_bulk event_bulk 
)

Wait for events on a set of lines.

Parameters
bulkSet of GPIO lines to monitor.
timeoutWait time limit.
event_bulkBulk object in which to store the line handles on which events occurred. Can be NULL.
Returns
0 if wait timed out, -1 if an error occurred, 1 if at least one event occurred.

◆ gpiod_line_find()

struct gpiod_line* gpiod_line_find ( const char *  name)

Find a GPIO line by its name.

Parameters
nameName of the GPIO line.
Returns
Returns the GPIO line handle if the line exists in the system or NULL if it couldn't be located or an error occurred.

If this routine succeeds, the user must manually close the GPIO chip owning this line to avoid memory leaks. If the line could not be found, this functions sets errno to ENOENT.

◆ gpiod_line_get()

struct gpiod_line* gpiod_line_get ( const char *  device,
unsigned int  offset 
)

Get a GPIO line handle by GPIO chip description and offset.

Parameters
deviceString describing the gpiochip.
offsetThe offset of the GPIO line.
Returns
GPIO line handle or NULL if an error occurred.

This routine provides a shorter alternative to calling gpiod_chip_open_lookup and gpiod_chip_get_line.

If this function succeeds, the caller is responsible for closing the associated GPIO chip.

◆ gpiod_line_get_chip()

struct gpiod_chip* gpiod_line_get_chip ( struct gpiod_line *  line)

Get the handle to the GPIO chip controlling this line.

Parameters
lineThe GPIO line object.
Returns
Pointer to the GPIO chip handle controlling this line.

◆ gpiod_line_get_value()

int gpiod_line_get_value ( struct gpiod_line *  line)

Read current value of a single GPIO line.

Parameters
lineGPIO line object.
Returns
0 or 1 if the operation succeeds. On error this routine returns -1 and sets the last error number.

◆ gpiod_line_get_value_bulk()

int gpiod_line_get_value_bulk ( struct gpiod_line_bulk bulk,
int *  values 
)

Read current values of a set of GPIO lines.

Parameters
bulkSet of GPIO lines to reserve.
valuesAn array big enough to hold line_bulk->num_lines values.
Returns
0 is the operation succeeds. In case of an error this routine returns -1 and sets the last error number.

If succeeds, this routine fills the values array with a set of values in the same order, the lines are added to line_bulk. If the lines were not previously requested together, the behavior is undefined.

◆ gpiod_line_is_free()

bool gpiod_line_is_free ( struct gpiod_line *  line)

Check if the calling user has neither requested ownership of this line nor configured any event notifications.

Parameters
lineGPIO line object.
Returns
True if given line is free, false otherwise.

◆ gpiod_line_is_open_drain()

bool gpiod_line_is_open_drain ( struct gpiod_line *  line)

Check if the line is an open-drain GPIO.

Parameters
lineGPIO line object.
Returns
True if the line is an open-drain GPIO, false otherwise.

◆ gpiod_line_is_open_source()

bool gpiod_line_is_open_source ( struct gpiod_line *  line)

Check if the line is an open-source GPIO.

Parameters
lineGPIO line object.
Returns
True if the line is an open-source GPIO, false otherwise.

◆ gpiod_line_is_requested()

bool gpiod_line_is_requested ( struct gpiod_line *  line)

Check if the calling user has ownership of this line.

Parameters
lineGPIO line object.
Returns
True if given line was requested, false otherwise.

◆ gpiod_line_is_used()

bool gpiod_line_is_used ( struct gpiod_line *  line)

Check if the line is currently in use.

Parameters
lineGPIO line object.
Returns
True if the line is in use, false otherwise.

The user space can't know exactly why a line is busy. It may have been requested by another process or hogged by the kernel. It only matters that the line is used and we can't request it.

◆ gpiod_line_iter_free()

void gpiod_line_iter_free ( struct gpiod_line_iter *  iter)

Free all resources associated with a GPIO line iterator.

Parameters
iterLine iterator object.

◆ gpiod_line_iter_new()

struct gpiod_line_iter* gpiod_line_iter_new ( struct gpiod_chip *  chip)

Create a new line iterator.

Parameters
chipActive gpiochip handle over the lines of which we want to iterate.
Returns
New line iterator or NULL if an error occurred.

◆ gpiod_line_iter_next()

struct gpiod_line* gpiod_line_iter_next ( struct gpiod_line_iter *  iter)

Get the next GPIO line handle.

Parameters
iterThe GPIO line iterator object.
Returns
Pointer to the next GPIO line handle or NULL if there are no more lines left.

◆ gpiod_line_name()

const char* gpiod_line_name ( struct gpiod_line *  line)

Read the GPIO line name.

Parameters
lineGPIO line object.
Returns
Name of the GPIO line as it is represented in the kernel. This routine returns a pointer to a null-terminated string or NULL if the line is unnamed.

◆ gpiod_line_needs_update()

bool gpiod_line_needs_update ( struct gpiod_line *  line)

Check if the line info needs to be updated.

Parameters
lineGPIO line object.
Returns
Deprecated and no longer functional - always returns false.

References GPIOD_LINE_REQUEST_DIRECTION_AS_IS, GPIOD_LINE_REQUEST_DIRECTION_INPUT, GPIOD_LINE_REQUEST_DIRECTION_OUTPUT, GPIOD_LINE_REQUEST_EVENT_BOTH_EDGES, GPIOD_LINE_REQUEST_EVENT_FALLING_EDGE, and GPIOD_LINE_REQUEST_EVENT_RISING_EDGE.

◆ gpiod_line_offset()

unsigned int gpiod_line_offset ( struct gpiod_line *  line)

Read the GPIO line offset.

Parameters
lineGPIO line object.
Returns
Line offset.

◆ gpiod_line_release()

void gpiod_line_release ( struct gpiod_line *  line)

Release a previously reserved line.

Parameters
lineGPIO line object.

◆ gpiod_line_release_bulk()

void gpiod_line_release_bulk ( struct gpiod_line_bulk bulk)

Release a set of previously reserved lines.

Parameters
bulkSet of GPIO lines to release.

If the lines were not previously requested together, the behavior is undefined.

◆ gpiod_line_request()

int gpiod_line_request ( struct gpiod_line *  line,
const struct gpiod_line_request_config config,
int  default_val 
)

Reserve a single line.

Parameters
lineGPIO line object.
configRequest options.
default_valInitial line value - only relevant if we're setting the direction to output.
Returns
0 if the line was properly reserved. In case of an error this routine returns -1 and sets the last error number.

If this routine succeeds, the caller takes ownership of the GPIO line until it's released.

◆ gpiod_line_request_both_edges_events()

int gpiod_line_request_both_edges_events ( struct gpiod_line *  line,
const char *  consumer 
)

Request all event type notifications on a single line.

Parameters
lineGPIO line object.
consumerName of the consumer.
Returns
0 if the operation succeeds, -1 on failure.

◆ gpiod_line_request_both_edges_events_flags()

int gpiod_line_request_both_edges_events_flags ( struct gpiod_line *  line,
const char *  consumer,
int  flags 
)

Request all event type notifications on a single line.

Parameters
lineGPIO line object.
consumerName of the consumer.
flagsAdditional request flags.
Returns
0 if the operation succeeds, -1 on failure.

◆ gpiod_line_request_bulk()

int gpiod_line_request_bulk ( struct gpiod_line_bulk bulk,
const struct gpiod_line_request_config config,
const int *  default_vals 
)

Reserve a set of GPIO lines.

Parameters
bulkSet of GPIO lines to reserve.
configRequest options.
default_valsInitial line values - only relevant if we're setting the direction to output.
Returns
0 if the all lines were properly requested. In case of an error this routine returns -1 and sets the last error number.

If this routine succeeds, the caller takes ownership of the GPIO lines until they're released. All the requested lines must be prodivided by the same gpiochip.

◆ gpiod_line_request_bulk_both_edges_events()

int gpiod_line_request_bulk_both_edges_events ( struct gpiod_line_bulk bulk,
const char *  consumer 
)

Request all event type notifications on a set of lines.

Parameters
bulkSet of GPIO lines to request.
consumerName of the consumer.
Returns
0 if the operation succeeds, -1 on failure.

◆ gpiod_line_request_bulk_both_edges_events_flags()

int gpiod_line_request_bulk_both_edges_events_flags ( struct gpiod_line_bulk bulk,
const char *  consumer,
int  flags 
)

Request all event type notifications on a set of lines.

Parameters
bulkSet of GPIO lines to request.
consumerName of the consumer.
flagsAdditional request flags.
Returns
0 if the operation succeeds, -1 on failure.

◆ gpiod_line_request_bulk_falling_edge_events()

int gpiod_line_request_bulk_falling_edge_events ( struct gpiod_line_bulk bulk,
const char *  consumer 
)

Request falling edge event notifications on a set of lines.

Parameters
bulkSet of GPIO lines to request.
consumerName of the consumer.
Returns
0 if the operation succeeds, -1 on failure.

◆ gpiod_line_request_bulk_falling_edge_events_flags()

int gpiod_line_request_bulk_falling_edge_events_flags ( struct gpiod_line_bulk bulk,
const char *  consumer,
int  flags 
)

Request falling edge event notifications on a set of lines.

Parameters
bulkSet of GPIO lines to request.
consumerName of the consumer.
flagsAdditional request flags.
Returns
0 if the operation succeeds, -1 on failure.

◆ gpiod_line_request_bulk_input()

int gpiod_line_request_bulk_input ( struct gpiod_line_bulk bulk,
const char *  consumer 
)

Reserve a set of GPIO lines, set the direction to input.

Parameters
bulkSet of GPIO lines to reserve.
consumerName of the consumer.
Returns
0 if the lines were properly reserved, -1 on failure.

◆ gpiod_line_request_bulk_input_flags()

int gpiod_line_request_bulk_input_flags ( struct gpiod_line_bulk bulk,
const char *  consumer,
int  flags 
)

Reserve a set of GPIO lines, set the direction to input.

Parameters
bulkSet of GPIO lines to reserve.
consumerName of the consumer.
flagsAdditional request flags.
Returns
0 if the lines were properly reserved, -1 on failure.

◆ gpiod_line_request_bulk_output()

int gpiod_line_request_bulk_output ( struct gpiod_line_bulk bulk,
const char *  consumer,
const int *  default_vals 
)

Reserve a set of GPIO lines, set the direction to output.

Parameters
bulkSet of GPIO lines to reserve.
consumerName of the consumer.
default_valsInitial line values.
Returns
0 if the lines were properly reserved, -1 on failure.

◆ gpiod_line_request_bulk_output_flags()

int gpiod_line_request_bulk_output_flags ( struct gpiod_line_bulk bulk,
const char *  consumer,
int  flags,
const int *  default_vals 
)

Reserve a set of GPIO lines, set the direction to output.

Parameters
bulkSet of GPIO lines to reserve.
consumerName of the consumer.
flagsAdditional request flags.
default_valsInitial line values.
Returns
0 if the lines were properly reserved, -1 on failure.

◆ gpiod_line_request_bulk_rising_edge_events()

int gpiod_line_request_bulk_rising_edge_events ( struct gpiod_line_bulk bulk,
const char *  consumer 
)

Request rising edge event notifications on a set of lines.

Parameters
bulkSet of GPIO lines to request.
consumerName of the consumer.
Returns
0 if the operation succeeds, -1 on failure.

◆ gpiod_line_request_bulk_rising_edge_events_flags()

int gpiod_line_request_bulk_rising_edge_events_flags ( struct gpiod_line_bulk bulk,
const char *  consumer,
int  flags 
)

Request rising edge event notifications on a set of lines.

Parameters
bulkSet of GPIO lines to request.
consumerName of the consumer.
flagsAdditional request flags.
Returns
0 if the operation succeeds, -1 on failure.

◆ gpiod_line_request_falling_edge_events()

int gpiod_line_request_falling_edge_events ( struct gpiod_line *  line,
const char *  consumer 
)

Request falling edge event notifications on a single line.

Parameters
lineGPIO line object.
consumerName of the consumer.
Returns
0 if the operation succeeds, -1 on failure.

◆ gpiod_line_request_falling_edge_events_flags()

int gpiod_line_request_falling_edge_events_flags ( struct gpiod_line *  line,
const char *  consumer,
int  flags 
)

Request falling edge event notifications on a single line.

Parameters
lineGPIO line object.
consumerName of the consumer.
flagsAdditional request flags.
Returns
0 if the operation succeeds, -1 on failure.

◆ gpiod_line_request_input()

int gpiod_line_request_input ( struct gpiod_line *  line,
const char *  consumer 
)

Reserve a single line, set the direction to input.

Parameters
lineGPIO line object.
consumerName of the consumer.
Returns
0 if the line was properly reserved, -1 on failure.

◆ gpiod_line_request_input_flags()

int gpiod_line_request_input_flags ( struct gpiod_line *  line,
const char *  consumer,
int  flags 
)

Reserve a single line, set the direction to input.

Parameters
lineGPIO line object.
consumerName of the consumer.
flagsAdditional request flags.
Returns
0 if the line was properly reserved, -1 on failure.

◆ gpiod_line_request_output()

int gpiod_line_request_output ( struct gpiod_line *  line,
const char *  consumer,
int  default_val 
)

Reserve a single line, set the direction to output.

Parameters
lineGPIO line object.
consumerName of the consumer.
default_valInitial line value.
Returns
0 if the line was properly reserved, -1 on failure.

◆ gpiod_line_request_output_flags()

int gpiod_line_request_output_flags ( struct gpiod_line *  line,
const char *  consumer,
int  flags,
int  default_val 
)

Reserve a single line, set the direction to output.

Parameters
lineGPIO line object.
consumerName of the consumer.
flagsAdditional request flags.
default_valInitial line value.
Returns
0 if the line was properly reserved, -1 on failure.

◆ gpiod_line_request_rising_edge_events()

int gpiod_line_request_rising_edge_events ( struct gpiod_line *  line,
const char *  consumer 
)

Request rising edge event notifications on a single line.

Parameters
lineGPIO line object.
consumerName of the consumer.
Returns
0 if the operation succeeds, -1 on failure.

◆ gpiod_line_request_rising_edge_events_flags()

int gpiod_line_request_rising_edge_events_flags ( struct gpiod_line *  line,
const char *  consumer,
int  flags 
)

Request rising edge event notifications on a single line.

Parameters
lineGPIO line object.
consumerName of the consumer.
flagsAdditional request flags.
Returns
0 if the operation succeeds, -1 on failure.

◆ gpiod_line_set_config()

int gpiod_line_set_config ( struct gpiod_line *  line,
int  direction,
int  flags,
int  value 
)

Update the configuration of a single GPIO line.

Parameters
lineGPIO line object.
directionUpdated direction which may be one of GPIOD_LINE_REQUEST_DIRECTION_AS_IS, GPIOD_LINE_REQUEST_DIRECTION_INPUT, or GPIOD_LINE_REQUEST_DIRECTION_OUTPUT.
flagsReplacement flags.
valueThe new output value for the line when direction is GPIOD_LINE_REQUEST_DIRECTION_OUTPUT.
Returns
0 is the operation succeeds. In case of an error this routine returns -1 and sets the last error number.

◆ gpiod_line_set_config_bulk()

int gpiod_line_set_config_bulk ( struct gpiod_line_bulk bulk,
int  direction,
int  flags,
const int *  values 
)

Update the configuration of a set of GPIO lines.

Parameters
bulkSet of GPIO lines.
directionUpdated direction which may be one of GPIOD_LINE_REQUEST_DIRECTION_AS_IS, GPIOD_LINE_REQUEST_DIRECTION_INPUT, or GPIOD_LINE_REQUEST_DIRECTION_OUTPUT.
flagsReplacement flags.
valuesAn array holding line_bulk->num_lines new logical values for lines when direction is GPIOD_LINE_REQUEST_DIRECTION_OUTPUT. A NULL pointer is interpreted as a logical low for all lines.
Returns
0 is the operation succeeds. In case of an error this routine returns -1 and sets the last error number.

If the lines were not previously requested together, the behavior is undefined.

◆ gpiod_line_set_direction_input()

int gpiod_line_set_direction_input ( struct gpiod_line *  line)

Set the direction of a single GPIO line to input.

Parameters
lineGPIO line object.
Returns
0 is the operation succeeds. In case of an error this routine returns -1 and sets the last error number.

◆ gpiod_line_set_direction_input_bulk()

int gpiod_line_set_direction_input_bulk ( struct gpiod_line_bulk bulk)

Set the direction of a set of GPIO lines to input.

Parameters
bulkSet of GPIO lines.
Returns
0 is the operation succeeds. In case of an error this routine returns -1 and sets the last error number.

If the lines were not previously requested together, the behavior is undefined.

◆ gpiod_line_set_direction_output()

int gpiod_line_set_direction_output ( struct gpiod_line *  line,
int  value 
)

Set the direction of a single GPIO line to output.

Parameters
lineGPIO line object.
valueThe logical value output on the line.
Returns
0 is the operation succeeds. In case of an error this routine returns -1 and sets the last error number.

◆ gpiod_line_set_direction_output_bulk()

int gpiod_line_set_direction_output_bulk ( struct gpiod_line_bulk bulk,
const int *  values 
)

Set the direction of a set of GPIO lines to output.

Parameters
bulkSet of GPIO lines.
valuesAn array holding line_bulk->num_lines new logical values for lines. A NULL pointer is interpreted as a logical low for all lines.
Returns
0 is the operation succeeds. In case of an error this routine returns -1 and sets the last error number.

If the lines were not previously requested together, the behavior is undefined.

References GPIOD_LINE_EVENT_FALLING_EDGE, and GPIOD_LINE_EVENT_RISING_EDGE.

◆ gpiod_line_set_flags()

int gpiod_line_set_flags ( struct gpiod_line *  line,
int  flags 
)

Update the configuration flags of a single GPIO line.

Parameters
lineGPIO line object.
flagsReplacement flags.
Returns
0 is the operation succeeds. In case of an error this routine returns -1 and sets the last error number.

◆ gpiod_line_set_flags_bulk()

int gpiod_line_set_flags_bulk ( struct gpiod_line_bulk bulk,
int  flags 
)

Update the configuration flags of a set of GPIO lines.

Parameters
bulkSet of GPIO lines.
flagsReplacement flags.
Returns
0 is the operation succeeds. In case of an error this routine returns -1 and sets the last error number.

If the lines were not previously requested together, the behavior is undefined.

◆ gpiod_line_set_value()

int gpiod_line_set_value ( struct gpiod_line *  line,
int  value 
)

Set the value of a single GPIO line.

Parameters
lineGPIO line object.
valueNew value.
Returns
0 is the operation succeeds. In case of an error this routine returns -1 and sets the last error number.

◆ gpiod_line_set_value_bulk()

int gpiod_line_set_value_bulk ( struct gpiod_line_bulk bulk,
const int *  values 
)

Set the values of a set of GPIO lines.

Parameters
bulkSet of GPIO lines to reserve.
valuesAn array holding line_bulk->num_lines new values for lines. A NULL pointer is interpreted as a logical low for all lines.
Returns
0 is the operation succeeds. In case of an error this routine returns -1 and sets the last error number.

If the lines were not previously requested together, the behavior is undefined.

◆ gpiod_line_update()

int gpiod_line_update ( struct gpiod_line *  line)

Re-read the line info.

Parameters
lineGPIO line object.
Returns
0 if the operation succeeds. In case of an error this routine returns -1 and sets the last error number.

The line info is initially retrieved from the kernel by gpiod_chip_get_line() and is later re-read after every successful request. Users can use this function to manually re-read the line info when needed.

We currently have no mechanism provided by the kernel for keeping the line info synchronized and for the sake of speed and simplicity of this low-level library we don't want to re-read the line info automatically everytime a property is retrieved. Any daemon using this library must track the state of lines on its own and call this routine if needed.

The state of requested lines is kept synchronized (or rather cannot be changed by external agents while the ownership of the line is taken) so there's no need to call this function in that case.

◆ gpiod_version_string()

const char* gpiod_version_string ( void  )

Get the API version of the library as a human-readable string.

Returns
Human-readable string containing the library version.

◆ make_chip_iter()

GPIOD_API chip_iter gpiod::make_chip_iter ( void  )

Create a new chip_iter.

Returns
New chip iterator object pointing to the first GPIO chip on the system.
Note
This function is needed as we already use the default constructor of gpiod::chip_iter as the return value of gpiod::end.
gpiod_line_iter_next
struct gpiod_line * gpiod_line_iter_next(struct gpiod_line_iter *iter) GPIOD_API
Get the next GPIO line handle.
gpiod_chip_iter_next
struct gpiod_chip * gpiod_chip_iter_next(struct gpiod_chip_iter *iter) GPIOD_API
Get the next gpiochip handle.
gpiod_chip_iter_next_noclose
struct gpiod_chip * gpiod_chip_iter_next_noclose(struct gpiod_chip_iter *iter) GPIOD_API
Get the next gpiochip handle without closing the previous one.