21 #ifndef __LIBGPIOD_GPIOD_H__ 22 #define __LIBGPIOD_GPIOD_H__ 34 struct gpiod_chip_iter;
46 #define GPIOD_API __attribute__((visibility("default"))) 53 #define GPIOD_BIT(nr) (1UL << (nr)) 74 #define _GPIOD_ERRNO_OFFSET 10000 135 const unsigned int *offsets,
int *values,
136 unsigned int num_lines,
149 unsigned int offset,
bool active_low)
154 &value, 1, active_low);
180 const unsigned int *offsets,
181 const int *values,
unsigned int num_lines,
200 unsigned int offset,
int value,
205 &value, 1, active_low,
249 unsigned int offset,
bool active_low,
250 const struct timespec *timeout,
300 #define GPIOD_REQUEST_MAX_LINES 64 321 #define GPIOD_LINE_BULK_INITIALIZER { { NULL }, 0 } 340 struct gpiod_line *line)
470 const char *consumer,
482 bool active_low,
int default_val)
GPIOD_API;
509 const char *consumer,
521 const char *consumer,
bool active_low,
677 const char *consumer,
688 const char *consumer,
699 const char *consumer,
723 const struct timespec *timeout)
GPIOD_API;
735 const struct timespec *timeout,
933 #define gpiod_foreach_chip(iter, chip) \ 934 for ((chip) = gpiod_chip_iter_next(iter); \ 935 !gpiod_chip_iter_done(iter); \ 936 (chip) = gpiod_chip_iter_next(iter)) 948 #define gpiod_foreach_chip_noclose(iter, chip) \ 949 for ((chip) = gpiod_chip_iter_next_noclose(iter); \ 950 !gpiod_chip_iter_done(iter); \ 951 (chip) = gpiod_chip_iter_next_noclose(iter)) 1013 #define GPIOD_LINE_ITER_INITIALIZER(chip) { 0, (chip), GPIOD_LINE_ITER_INIT } 1021 struct gpiod_chip *chip)
1065 static inline unsigned int 1077 #define gpiod_foreach_line(iter, line) \ 1078 for ((line) = gpiod_line_iter_next(iter); \ 1079 !gpiod_line_iter_done(iter); \ 1080 (line) = gpiod_line_iter_next(iter)) Private: number of libgpiod-specific error numbers.
int gpiod_line_event_get_fd(struct gpiod_line *line) GPIOD_API
Get the event file descriptor.
void gpiod_line_event_release(struct gpiod_line *line) GPIOD_API
Stop listening for events and release the line.
bool gpiod_line_is_open_drain(struct gpiod_line *line) GPIOD_API
Check if the line is an open-drain GPIO.
Rising or falling edge event: only relevant for event requests.
Direction is output - we're driving the GPIO line.
const char * gpiod_chip_name(struct gpiod_chip *chip) GPIOD_API
Get the GPIO chip name as represented in the kernel.
int gpiod_line_event_wait_bulk(struct gpiod_line_bulk *bulk, const struct timespec *timeout, struct gpiod_line **line) GPIOD_API
Wait for the first event on a set of lines.
struct gpiod_chip * gpiod_line_get_chip(struct gpiod_line *line) GPIOD_API
Get the handle to the GPIO chip controlling this line.
bool gpiod_chip_iter_done(struct gpiod_chip_iter *iter) GPIOD_API
Check if we're done iterating over gpiochips on this iterator.
struct gpiod_line * gpiod_line_find_by_name(const char *name) GPIOD_API
Find a GPIO line by its name.
int active_state
Requested active state configuration.
bool gpiod_chip_iter_err(struct gpiod_chip_iter *iter) GPIOD_API
Check if we've encountered an error condition while opening a gpiochip.
Direction is input - we're reading the state of a GPIO line.
Waiting for events timed out.
struct gpiod_chip * gpiod_chip_open_lookup(const char *descr) GPIOD_API
Open a gpiochip based on the best guess what the path is.
Continue processing events.
int gpiod_line_get_value(struct gpiod_line *line) GPIOD_API
Read current value of a single GPIO line.
Number of lines in the request exceeds limit.
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_event_cb)(int, const struct timespec *, void *)
Simple event callack signature.
static void gpiod_line_iter_init(struct gpiod_line_iter *iter, struct gpiod_chip *chip)
Initialize a GPIO line iterator.
unsigned int num_lines
Number of lines currently held in this structure.
void gpiod_chip_close(struct gpiod_chip *chip) GPIOD_API
Close a GPIO chip handle and release all allocated resources.
int event_type
Type of the event we want to be notified about.
int gpiod_line_set_value(struct gpiod_line *line, int value) GPIOD_API
Set the value of a single GPIO line.
int line_flags
Misc line flags - same as for line requests.
Falling edge event occured.
static bool gpiod_line_iter_done(const struct gpiod_line_iter *iter)
Check if we're done iterating over lines on this iterator.
#define GPIOD_API
Makes symbol visible.
int gpiod_line_get_value_bulk(struct gpiod_line_bulk *bulk, int *values) GPIOD_API
Read current values of a set of GPIO lines.
struct gpiod_chip * gpiod_chip_open_by_number(unsigned int num) GPIOD_API
Open a gpiochip by number.
Not all lines in bulk belong to the same GPIO chip.
The active state of a GPIO is active-low.
const char * consumer
Name of the consumer.
There was an error retrieving info for a line.
int gpiod_simple_get_value_multiple(const char *consumer, const char *device, const unsigned int *offsets, int *values, unsigned int num_lines, bool active_low) GPIOD_API
Read current values from a set of GPIO lines.
const char * gpiod_last_strerror(void) GPIOD_API
Convert the last libgpiod error number to a human-readable string.
static bool gpiod_line_iter_err(const struct gpiod_line_iter *iter)
Check if we've encountered an error condition while retrieving info for a line.
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_event_read(struct gpiod_line *line, struct gpiod_line_event *event) GPIOD_API
Read the last event from the GPIO line.
int gpiod_line_event_request_rising(struct gpiod_line *line, const char *consumer, bool active_low) GPIOD_API
Request rising edge event notifications on a single line.
Line iterator is initiated or iterating over lines.
void gpiod_line_release(struct gpiod_line *line) GPIOD_API
Release a previously reserved line.
struct gpiod_chip * gpiod_chip_open(const char *path) GPIOD_API
Open a gpiochip by path.
Structure holding event info.
unsigned int offset
Current line offset.
int gpiod_simple_set_value_multiple(const char *consumer, const char *device, const unsigned int *offsets, const int *values, unsigned int num_lines, bool active_low, gpiod_set_value_cb cb, void *data) GPIOD_API
Set values of a set of a set of GPIO lines.
int gpiod_line_request_bulk_output(struct gpiod_line_bulk *bulk, const char *consumer, bool active_low, const int *default_vals) GPIOD_API
Reserve a set of GPIO lines, set the direction to output.
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...
Line iterator is done with all lines on this chip.
#define GPIOD_BIT(nr)
Shift 1 by given offset.
struct gpiod_chip * gpiod_chip_open_by_name(const char *name) GPIOD_API
Open a gpiochip by name.
bool gpiod_line_is_open_source(struct gpiod_line *line) GPIOD_API
Check if the line is an open-source GPIO.
int direction
Requested direction.
int gpiod_line_request_bulk_input(struct gpiod_line_bulk *bulk, const char *consumer, bool active_low) GPIOD_API
Reserve a set of GPIO lines, set the direction to input.
int gpiod_line_active_state(struct gpiod_line *line) GPIOD_API
Read the GPIO line active state setting.
bool gpiod_line_is_used_by_kernel(struct gpiod_line *line) GPIOD_API
Check if the line is used by the kernel.
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...
int gpiod_line_direction(struct gpiod_line *line) GPIOD_API
Read the GPIO line direction setting.
int gpiod_line_event_request_all(struct gpiod_line *line, const char *consumer, bool active_low) GPIOD_API
Request all event type notifications on a single line.
The caller has no ownership of this line.
static unsigned int gpiod_line_iter_last_offset(const struct gpiod_line_iter *iter)
Get the offset of the last line we tried to open.
const char * gpiod_line_name(struct gpiod_line *line) GPIOD_API
Read the GPIO line name.
void(* gpiod_set_value_cb)(void *)
Simple set value callback signature.
The caller has not configured any events on this line.
int gpiod_line_event_request(struct gpiod_line *line, struct gpiod_line_evreq_config *config) GPIOD_API
Request event notifications for a single line.
Rising edge event occured.
Only relevant for line requests - don't set the direction.
Helper structure for storing a set of GPIO line objects.
const char * gpiod_strerror(int errnum) GPIOD_API
Convert error number to a human-readable string.
#define GPIOD_REQUEST_MAX_LINES
Maximum number of GPIO lines that can be requested at once.
int gpiod_line_update(struct gpiod_line *line) GPIOD_API
Re-read the line info.
#define _GPIOD_ERRNO_OFFSET
Private: offset for all libgpiod error numbers.
unsigned int gpiod_line_offset(struct gpiod_line *line) GPIOD_API
Read the GPIO line offset.
int state
Current state of the iterator.
static int gpiod_simple_get_value(const char *consumer, const char *device, unsigned int offset, bool active_low)
Read current value from a single GPIO line.
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 event_type
Type of the event that occurred.
bool gpiod_line_needs_update(struct gpiod_line *line) GPIOD_API
Check if the line info needs to be updated.
struct gpiod_chip * chip
GPIO chip whose line we're iterating over.
const char * consumer
Name of the consumer.
int flags
Other configuration flags.
struct gpiod_chip * gpiod_chip_open_by_label(const char *label) GPIOD_API
Open a gpiochip by label.
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.
static void gpiod_line_bulk_init(struct gpiod_line_bulk *bulk)
Initialize a GPIO bulk object.
bool gpiod_line_event_configured(struct gpiod_line *line) GPIOD_API
Check if event notifications are configured on this line.
The line is an open-source port.
This line is currently in use.
void gpiod_line_release_bulk(struct gpiod_line_bulk *bulk) GPIOD_API
Release a set of previously reserved 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_request_falling(struct gpiod_line *line, const char *consumer, bool active_low) GPIOD_API
Request falling edge event notifications on a single line.
const char * gpiod_chip_iter_failed_chip(struct gpiod_chip_iter *iter) GPIOD_API
Get the name of the gpiochip that we failed to access.
int gpiod_line_set_value_bulk(struct gpiod_line_bulk *bulk, int *values) GPIOD_API
Set the values of a set of GPIO lines.
struct gpiod_line * lines[GPIOD_REQUEST_MAX_LINES]
Buffer for line pointers.
bool gpiod_line_is_reserved(struct gpiod_line *line) GPIOD_API
Check if the calling user has ownership of this line.
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.
const char * gpiod_line_consumer(struct gpiod_line *line) GPIOD_API
Read the GPIO line consumer name.
The active state of a GPIO is active-high.
GPIO line iterator structure.
Structure holding configuration of a line request.
int gpiod_line_request_output(struct gpiod_line *line, const char *consumer, bool active_low, int default_val) GPIOD_API
Reserve a single line, set the direction to output.
const char * gpiod_version_string(void) GPIOD_API
Get the version of the library as a human-readable string.
int gpiod_line_request_input(struct gpiod_line *line, const char *consumer, bool active_low) GPIOD_API
Reserve a single line, set the direction to input.
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.
struct gpiod_line * gpiod_line_iter_next(struct gpiod_line_iter *iter) GPIOD_API
Get the next GPIO line handle.
int gpiod_simple_event_loop(const char *consumer, const char *device, unsigned int offset, bool active_low, const struct timespec *timeout, gpiod_event_cb callback, void *cbdata) GPIOD_API
Wait for events on a single GPIO line.
Structure holding configuration of a line event request.
int active_state
GPIO line active state.
int gpiod_line_request(struct gpiod_line *line, const struct gpiod_line_request_config *config, int default_val) GPIOD_API
Reserve a single line.
static int gpiod_simple_set_value(const char *consumer, const char *device, unsigned int offset, int value, bool active_low, gpiod_set_value_cb cb, void *data)
Set value of a single GPIO line.
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_errno(void) GPIOD_API
Return last error.
The line is an open-drain port.
struct gpiod_chip * gpiod_chip_iter_next(struct gpiod_chip_iter *iter) GPIOD_API
Get the next gpiochip handle.
unsigned int gpiod_chip_num_lines(struct gpiod_chip *chip) GPIOD_API
Get the number of GPIO lines exposed by this chip.