libgpiod  1.6.2
Data Structures | Macros | Typedefs | Enumerations | Functions
gpiod.h File Reference
#include <stdbool.h>
#include <stdlib.h>
#include <time.h>
Include dependency graph for gpiod.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

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...
 

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 next pending 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...