8 #ifndef __LIBGPIOD_GPIOD_H__
9 #define __LIBGPIOD_GPIOD_H__
48 struct gpiod_chip_iter;
49 struct gpiod_line_iter;
62 #define GPIOD_API __attribute__((visibility("default")))
67 #define GPIOD_UNUSED __attribute__((unused))
74 #define GPIOD_BIT(nr) (1UL << (nr))
79 #define GPIOD_DEPRECATED __attribute__((deprecated))
116 bool active_low,
const char *consumer)
GPIOD_API;
128 bool active_low,
const char *consumer,
142 const unsigned int *offsets,
int *values,
158 const unsigned int *offsets,
160 bool active_low,
const char *consumer,
182 bool active_low,
const char *consumer,
201 int value,
bool active_low,
202 const char *consumer,
220 const unsigned int *offsets,
221 const int *values,
unsigned int num_lines,
222 bool active_low,
const char *consumer,
241 const unsigned int *offsets,
245 const char *consumer,
258 GPIOD_CTXLESS_EVENT_BOTH_EDGES,
297 const struct timespec *,
void *);
338 const struct timespec *,
void *);
359 bool active_low,
const char *consumer,
360 const struct timespec *timeout,
397 const unsigned int *offsets,
398 unsigned int num_lines,
bool active_low,
399 const char *consumer,
400 const struct timespec *timeout,
422 unsigned int offset,
bool active_low,
423 const char *consumer,
424 const struct timespec *timeout,
447 unsigned int offset,
bool active_low,
448 const char *consumer,
449 const struct timespec *timeout,
485 const char *device,
int event_type,
486 const unsigned int *offsets,
487 unsigned int num_lines,
bool active_low,
488 const char *consumer,
const struct timespec *timeout,
525 const char *device,
int event_type,
526 const unsigned int *offsets,
527 unsigned int num_lines,
bool active_low,
528 const char *consumer,
const struct timespec *timeout,
549 size_t chipname_size,
652 unsigned int *offsets,
unsigned int num_offsets,
713 #define GPIOD_LINE_BULK_MAX_LINES 64
734 #define GPIOD_LINE_BULK_INITIALIZER { { NULL }, 0 }
753 struct gpiod_line *line)
764 static inline struct gpiod_line *
767 return bulk->
lines[offset];
775 static inline unsigned int
788 #define gpiod_line_bulk_foreach_line(bulk, line, lineptr) \
789 for ((lineptr) = (bulk)->lines, (line) = *(lineptr); \
790 (lineptr) <= (bulk)->lines + ((bulk)->num_lines - 1); \
791 (lineptr)++, (line) = *(lineptr))
806 #define gpiod_line_bulk_foreach_line_off(bulk, line, offset) \
807 for ((offset) = 0, (line) = (bulk)->lines[0]; \
808 (offset) < (bulk)->num_lines; \
809 (offset)++, (line) = (bulk)->lines[(offset)])
1050 const char *consumer,
int default_val)
GPIOD_API;
1087 const char *consumer,
int flags)
GPIOD_API;
1098 const char *consumer,
int flags,
1109 const char *consumer,
1120 const char *consumer,
1131 const char *consumer,
1168 const char *consumer,
1206 const char *consumer,
1218 const char *consumer,
int flags,
1230 const char *consumer,
1242 const char *consumer,
1254 const char *consumer,
1387 int direction,
int flags,
1498 const struct timespec *timeout)
GPIOD_API;
1510 const struct timespec *timeout,
1697 #define gpiod_foreach_chip(iter, chip) \
1698 for ((chip) = gpiod_chip_iter_next(iter); \
1700 (chip) = gpiod_chip_iter_next(iter))
1712 #define gpiod_foreach_chip_noclose(iter, chip) \
1713 for ((chip) = gpiod_chip_iter_next_noclose(iter); \
1715 (chip) = gpiod_chip_iter_next_noclose(iter))
1723 struct gpiod_line_iter *
1747 #define gpiod_foreach_line(iter, line) \
1748 for ((line) = gpiod_line_iter_next(iter); \
1750 (line) = gpiod_line_iter_next(iter))
Direction is output - we're driving the GPIO line.
The line has pull-up resistor enabled.
int gpiod_line_update(struct gpiod_line *line) GPIOD_API
Re-read the line info.
The internal pull-down bias is enabled.
struct gpiod_chip * gpiod_chip_open_by_name(const char *name) GPIOD_API
Open a gpiochip by name.
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.
int gpiod_line_set_direction_output(struct gpiod_line *line, int value) GPIOD_API
Set the direction of a single GPIO line to output.
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.
Helper structure for the ctxless event loop poll callback.
void gpiod_line_release_bulk(struct gpiod_line_bulk *bulk) GPIOD_API
Release a set of previously reserved lines.
bool gpiod_line_needs_update(struct gpiod_line *line) GPIOD_API GPIOD_DEPRECATED
Check if the line info needs to be updated.
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 gp...
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.
static void gpiod_line_bulk_add(struct gpiod_line_bulk *bulk, struct gpiod_line *line)
Add a single line to a GPIO bulk object.
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.
struct gpiod_chip * gpiod_chip_open_by_number(unsigned int num) GPIOD_API
Open a gpiochip by number.
int gpiod_line_event_wait(struct gpiod_line *line, const struct timespec *timeout) GPIOD_API
Wait for an event on a single line.
int gpiod_line_set_flags(struct gpiod_line *line, int flags) GPIOD_API
Update the configuration flags of a single GPIO line.
struct gpiod_chip * gpiod_chip_open(const char *path) GPIOD_API
Open a gpiochip by path.
The line is an open-drain port.
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.
int gpiod_line_set_direction_input(struct gpiod_line *line) GPIOD_API
Set the direction of a single GPIO line to input.
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.
unsigned int num_lines
Number of lines currently held in this structure.
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.
The event loop should stop processing events.
struct gpiod_chip * gpiod_line_get_chip(struct gpiod_line *line) GPIOD_API
Get the handle to the GPIO chip controlling this line.
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.
const char * gpiod_chip_label(struct gpiod_chip *chip) GPIOD_API
Get the GPIO chip label as represented in the kernel.
int gpiod_line_event_get_fd(struct gpiod_line *line) GPIOD_API
Get the event file descriptor.
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.
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.
Direction is input - we're reading the state of a GPIO line.
Request the line(s), but don't change current direction.
The active state of the line is low (high is the default).
int gpiod_line_direction(struct gpiod_line *line) GPIOD_API
Read the GPIO line direction setting.
The active state of a GPIO is active-high.
#define GPIOD_LINE_BULK_MAX_LINES
Maximum number of GPIO lines that can be requested at once.
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.
bool gpiod_line_is_requested(struct gpiod_line *line) GPIOD_API
Check if the calling user has ownership of this line.
unsigned int gpiod_line_offset(struct gpiod_line *line) GPIOD_API
Read the GPIO line offset.
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.
bool gpiod_line_is_open_source(struct gpiod_line *line) GPIOD_API
Check if the line is an open-source GPIO.
The line has neither either pull-up nor pull-down resistor.
Stop processing events and indicate an error.
The internal bias state is unknown.
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.
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.
Structure holding event info.
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.
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.
const char * gpiod_line_consumer(struct gpiod_line *line) GPIOD_API
Read the GPIO line consumer name.
bool event
Indicates whether an event occurred on this file descriptor.
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.
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.
int fd
File descriptor number.
int gpiod_line_active_state(struct gpiod_line *line) GPIOD_API
Read the GPIO line active state setting.
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.
int gpiod_line_get_value_bulk(struct gpiod_line_bulk *bulk, int *values) GPIOD_API
Read current values of a set of GPIO lines.
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.
Request the line(s) for setting the GPIO line state.
The internal pull-up bias is enabled.
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.
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.
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.
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 notif...
The line is an open-source port.
void gpiod_line_release(struct gpiod_line *line) GPIOD_API
Release a previously reserved line.
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.
struct timespec ts
Best estimate of time of event occurrence.
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.
struct gpiod_line * lines[GPIOD_LINE_BULK_MAX_LINES]
Buffer for line pointers.
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.
#define GPIOD_BIT(nr)
Shift 1 by given offset.
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.
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.
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.
struct gpiod_line * gpiod_line_iter_next(struct gpiod_line_iter *iter) GPIOD_API
Get the next GPIO line handle.
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.
const char * gpiod_version_string(void) GPIOD_API
Get the API version of the library as a human-readable string.
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.
Helper structure for storing a set of GPIO line objects.
int(* gpiod_ctxless_event_poll_cb)(unsigned int, struct gpiod_ctxless_event_poll_fd *, const struct timespec *, void *)
Simple event poll callback signature.
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.
Only watch rising edge events.
int(* gpiod_ctxless_event_handle_cb)(int, unsigned int, const struct timespec *, void *)
Simple event callback signature.
int event_type
Type of the event that occurred.
int request_type
Request type.
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.
The active state of a GPIO is active-low.
const char * consumer
Name of the consumer.
int gpiod_line_event_read(struct gpiod_line *line, struct gpiod_line_event *event) GPIOD_API
Read next pending event from the GPIO line.
int flags
Other configuration flags.
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.
Wait for rising edge events only.
struct gpiod_line_iter * gpiod_line_iter_new(struct gpiod_chip *chip) GPIOD_API
Create a new line iterator.
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.
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.
struct gpiod_line * gpiod_line_find(const char *name) GPIOD_API
Find a GPIO line by its name.
int gpiod_line_set_value(struct gpiod_line *line, int value) GPIOD_API
Set the value of a single GPIO line.
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.
struct gpiod_chip * gpiod_chip_open_lookup(const char *descr) GPIOD_API
Open a gpiochip based on the best guess what the path is.
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.
Monitor both types of events.
bool gpiod_line_is_used(struct gpiod_line *line) GPIOD_API
Check if the line is currently in use.
int gpiod_line_bias(struct gpiod_line *line) GPIOD_API
Read the GPIO line bias setting.
unsigned int gpiod_chip_num_lines(struct gpiod_chip *chip) GPIOD_API
Get the number of GPIO lines exposed by this chip.
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.
struct gpiod_chip_iter * gpiod_chip_iter_new(void) GPIOD_API
Create a new gpiochip iterator.
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...
The line has neither either pull-up nor pull-down resistor.
static void gpiod_line_bulk_init(struct gpiod_line_bulk *bulk)
Initialize a GPIO bulk object.
#define GPIOD_DEPRECATED
Marks a public function as deprecated.
The line is an open-drain port.
The line is an open-source port.
void(* gpiod_ctxless_set_value_cb)(void *)
Simple set value callback signature.
Wait for both types of events.
Only watch falling edge events.
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.
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.
Waiting for events timed out.
struct gpiod_chip * gpiod_chip_iter_next(struct gpiod_chip_iter *iter) GPIOD_API
Get the next gpiochip handle.
Falling edge event occured.
Polling error occurred (the polling function should set errno).
The line has pull-down resistor enabled.
const char * gpiod_line_name(struct gpiod_line *line) GPIOD_API
Read the GPIO line name.
The line has pull-down resistor enabled.
const char * gpiod_chip_name(struct gpiod_chip *chip) GPIOD_API
Get the GPIO chip name as represented in the kernel.
The line has pull-up resistor enabled.
int gpiod_line_get_value(struct gpiod_line *line) GPIOD_API
Read current value of a single GPIO line.
Structure holding configuration of a line request.
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.
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.
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.
bool gpiod_line_is_open_drain(struct gpiod_line *line) GPIOD_API
Check if the line is an open-drain GPIO.
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.
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.
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.
The internal bias is disabled.
Request the line(s) for reading the GPIO line state.
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.
void gpiod_chip_close(struct gpiod_chip *chip) GPIOD_API
Close a GPIO chip handle and release all allocated resources.
Continue processing events.
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.
int gpiod_line_request_input(struct gpiod_line *line, const char *consumer) GPIOD_API
Reserve a single line, set the direction to input.
void gpiod_line_close_chip(struct gpiod_line *line) GPIOD_API
Close a GPIO chip owning this line and release all resources.
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.
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.
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.
struct gpiod_chip * gpiod_chip_open_by_label(const char *label) GPIOD_API
Open a gpiochip by label.
#define GPIOD_API
Makes symbol visible.
Rising edge event occured.
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.
int gpiod_line_request(struct gpiod_line *line, const struct gpiod_line_request_config *config, int default_val) GPIOD_API
Reserve a single line.
void gpiod_line_iter_free(struct gpiod_line_iter *iter) GPIOD_API
Free all resources associated with a GPIO line iterator.
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.