libgpiod  1.5.2
gpiod.h
1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
2 /*
3  * This file is part of libgpiod.
4  *
5  * Copyright (C) 2017-2018 Bartosz Golaszewski <bartekgola@gmail.com>
6  */
7 
8 #ifndef __LIBGPIOD_GPIOD_H__
9 #define __LIBGPIOD_GPIOD_H__
10 
11 #include <stdbool.h>
12 #include <stdlib.h>
13 #include <time.h>
14 
15 #ifdef __cplusplus
16 extern "C" {
17 #endif
18 
42 struct gpiod_chip;
43 struct gpiod_line;
44 struct gpiod_chip_iter;
45 struct gpiod_line_iter;
46 struct gpiod_line_bulk;
47 
58 #define GPIOD_API __attribute__((visibility("default")))
59 
63 #define GPIOD_UNUSED __attribute__((unused))
64 
70 #define GPIOD_BIT(nr) (1UL << (nr))
71 
75 #define GPIOD_DEPRECATED __attribute__((deprecated))
76 
90 enum {
101 };
102 
111 int gpiod_ctxless_get_value(const char *device, unsigned int offset,
112  bool active_low, const char *consumer) GPIOD_API;
113 
123 int gpiod_ctxless_get_value_ext(const char *device, unsigned int offset,
124  bool active_low, const char *consumer,
125  int flags) GPIOD_API;
126 
137 int gpiod_ctxless_get_value_multiple(const char *device,
138  const unsigned int *offsets, int *values,
139  unsigned int num_lines, bool active_low,
140  const char *consumer) GPIOD_API;
141 
154  const unsigned int *offsets,
155  int *values, unsigned int num_lines,
156  bool active_low, const char *consumer,
157  int flags) GPIOD_API;
158 
162 typedef void (*gpiod_ctxless_set_value_cb)(void *);
163 
177 int gpiod_ctxless_set_value(const char *device, unsigned int offset, int value,
178  bool active_low, const char *consumer,
180  void *data) GPIOD_API;
181 
196 int gpiod_ctxless_set_value_ext(const char *device, unsigned int offset,
197  int value, bool active_low,
198  const char *consumer,
200  void *data, int flags) GPIOD_API;
201 
215 int gpiod_ctxless_set_value_multiple(const char *device,
216  const unsigned int *offsets,
217  const int *values, unsigned int num_lines,
218  bool active_low, const char *consumer,
220  void *data) GPIOD_API;
221 
237  const unsigned int *offsets,
238  const int *values,
239  unsigned int num_lines,
240  bool active_low,
241  const char *consumer,
243  void *data, int flags) GPIOD_API;
244 
248 enum {
254  GPIOD_CTXLESS_EVENT_BOTH_EDGES,
255 };
256 
260 enum {
267 };
268 
272 enum {
279 };
280 
292 typedef int (*gpiod_ctxless_event_handle_cb)(int, unsigned int,
293  const struct timespec *, void *);
294 
301 enum {
308 };
309 
314  int fd;
316  bool event;
318 };
319 
332 typedef int (*gpiod_ctxless_event_poll_cb)(unsigned int,
334  const struct timespec *, void *);
335 
351 int gpiod_ctxless_event_loop(const char *device, unsigned int offset,
352  bool active_low, const char *consumer,
353  const struct timespec *timeout,
356  void *data) GPIOD_API GPIOD_DEPRECATED;
357 
386 int gpiod_ctxless_event_loop_multiple(const char *device,
387  const unsigned int *offsets,
388  unsigned int num_lines, bool active_low,
389  const char *consumer,
390  const struct timespec *timeout,
393  void *data) GPIOD_API GPIOD_DEPRECATED;
394 
411 int gpiod_ctxless_event_monitor(const char *device, int event_type,
412  unsigned int offset, bool active_low,
413  const char *consumer,
414  const struct timespec *timeout,
417  void *data) GPIOD_API;
418 
436 int gpiod_ctxless_event_monitor_ext(const char *device, int event_type,
437  unsigned int offset, bool active_low,
438  const char *consumer,
439  const struct timespec *timeout,
442  void *data, int flags) GPIOD_API;
443 
475  const char *device, int event_type,
476  const unsigned int *offsets,
477  unsigned int num_lines, bool active_low,
478  const char *consumer, const struct timespec *timeout,
481  void *data) GPIOD_API;
482 
515  const char *device, int event_type,
516  const unsigned int *offsets,
517  unsigned int num_lines, bool active_low,
518  const char *consumer, const struct timespec *timeout,
521  void *data, int flags) GPIOD_API;
522 
523 
535 int gpiod_ctxless_find_line(const char *name, char *chipname,
536  size_t chipname_size,
537  unsigned int *offset) GPIOD_API;
538 
553 struct gpiod_chip *gpiod_chip_open(const char *path) GPIOD_API;
554 
562 struct gpiod_chip *gpiod_chip_open_by_name(const char *name) GPIOD_API;
563 
571 struct gpiod_chip *gpiod_chip_open_by_number(unsigned int num) GPIOD_API;
572 
581 struct gpiod_chip *gpiod_chip_open_by_label(const char *label) GPIOD_API;
582 
592 struct gpiod_chip *gpiod_chip_open_lookup(const char *descr) GPIOD_API;
593 
598 void gpiod_chip_close(struct gpiod_chip *chip) GPIOD_API;
599 
605 const char *gpiod_chip_name(struct gpiod_chip *chip) GPIOD_API;
606 
612 const char *gpiod_chip_label(struct gpiod_chip *chip) GPIOD_API;
613 
619 unsigned int gpiod_chip_num_lines(struct gpiod_chip *chip) GPIOD_API;
620 
627 struct gpiod_line *
628 gpiod_chip_get_line(struct gpiod_chip *chip, unsigned int offset) GPIOD_API;
629 
638 int gpiod_chip_get_lines(struct gpiod_chip *chip,
639  unsigned int *offsets, unsigned int num_offsets,
640  struct gpiod_line_bulk *bulk) GPIOD_API;
641 
648 int gpiod_chip_get_all_lines(struct gpiod_chip *chip,
649  struct gpiod_line_bulk *bulk) GPIOD_API;
650 
660 struct gpiod_line *
661 gpiod_chip_find_line(struct gpiod_chip *chip, const char *name) GPIOD_API;
662 
673 int gpiod_chip_find_lines(struct gpiod_chip *chip, const char **names,
674  struct gpiod_line_bulk *bulk) GPIOD_API;
675 
691 #define GPIOD_LINE_BULK_MAX_LINES 64
692 
701  struct gpiod_line *lines[GPIOD_LINE_BULK_MAX_LINES];
703  unsigned int num_lines;
705 };
706 
712 #define GPIOD_LINE_BULK_INITIALIZER { { NULL }, 0 }
713 
720 static inline void gpiod_line_bulk_init(struct gpiod_line_bulk *bulk)
721 {
722  bulk->num_lines = 0;
723 }
724 
730 static inline void gpiod_line_bulk_add(struct gpiod_line_bulk *bulk,
731  struct gpiod_line *line)
732 {
733  bulk->lines[bulk->num_lines++] = line;
734 }
735 
742 static inline struct gpiod_line *
743 gpiod_line_bulk_get_line(struct gpiod_line_bulk *bulk, unsigned int offset)
744 {
745  return bulk->lines[offset];
746 }
747 
753 static inline unsigned int
755 {
756  return bulk->num_lines;
757 }
758 
766 #define gpiod_line_bulk_foreach_line(bulk, line, lineptr) \
767  for ((lineptr) = (bulk)->lines, (line) = *(lineptr); \
768  (lineptr) <= (bulk)->lines + ((bulk)->num_lines - 1); \
769  (lineptr)++, (line) = *(lineptr))
770 
784 #define gpiod_line_bulk_foreach_line_off(bulk, line, offset) \
785  for ((offset) = 0, (line) = (bulk)->lines[0]; \
786  (offset) < (bulk)->num_lines; \
787  (offset)++, (line) = (bulk)->lines[(offset)])
788 
799 enum {
804 };
805 
809 enum {
814 };
815 
819 enum {
828 };
829 
835 unsigned int gpiod_line_offset(struct gpiod_line *line) GPIOD_API;
836 
844 const char *gpiod_line_name(struct gpiod_line *line) GPIOD_API;
845 
853 const char *gpiod_line_consumer(struct gpiod_line *line) GPIOD_API;
854 
860 int gpiod_line_direction(struct gpiod_line *line) GPIOD_API;
861 
867 int gpiod_line_active_state(struct gpiod_line *line) GPIOD_API;
868 
875 int gpiod_line_bias(struct gpiod_line *line) GPIOD_API;
876 
886 bool gpiod_line_is_used(struct gpiod_line *line) GPIOD_API;
887 
893 bool gpiod_line_is_open_drain(struct gpiod_line *line) GPIOD_API;
894 
900 bool gpiod_line_is_open_source(struct gpiod_line *line) GPIOD_API;
901 
922 int gpiod_line_update(struct gpiod_line *line) GPIOD_API;
923 
929 bool
931 
942 enum {
955 };
956 
960 enum {
973 };
974 
979  const char *consumer;
983  int flags;
985 };
986 
999 int gpiod_line_request(struct gpiod_line *line,
1000  const struct gpiod_line_request_config *config,
1001  int default_val) GPIOD_API;
1002 
1009 int gpiod_line_request_input(struct gpiod_line *line,
1010  const char *consumer) GPIOD_API;
1011 
1019 int gpiod_line_request_output(struct gpiod_line *line,
1020  const char *consumer, int default_val) GPIOD_API;
1021 
1028 int gpiod_line_request_rising_edge_events(struct gpiod_line *line,
1029  const char *consumer) GPIOD_API;
1030 
1037 int gpiod_line_request_falling_edge_events(struct gpiod_line *line,
1038  const char *consumer) GPIOD_API;
1039 
1046 int gpiod_line_request_both_edges_events(struct gpiod_line *line,
1047  const char *consumer) GPIOD_API;
1048 
1056 int gpiod_line_request_input_flags(struct gpiod_line *line,
1057  const char *consumer, int flags) GPIOD_API;
1058 
1067 int gpiod_line_request_output_flags(struct gpiod_line *line,
1068  const char *consumer, int flags,
1069  int default_val) GPIOD_API;
1070 
1079  const char *consumer,
1080  int flags) GPIOD_API;
1081 
1090  const char *consumer,
1091  int flags) GPIOD_API;
1092 
1101  const char *consumer,
1102  int flags) GPIOD_API;
1103 
1118  const struct gpiod_line_request_config *config,
1119  const int *default_vals) GPIOD_API;
1120 
1128  const char *consumer) GPIOD_API;
1129 
1138  const char *consumer,
1139  const int *default_vals) GPIOD_API;
1140 
1148  const char *consumer) GPIOD_API;
1149 
1157  const char *consumer) GPIOD_API;
1158 
1166  const char *consumer) GPIOD_API;
1167 
1176  const char *consumer,
1177  int flags) GPIOD_API;
1178 
1188  const char *consumer, int flags,
1189  const int *default_vals) GPIOD_API;
1190 
1199  struct gpiod_line_bulk *bulk,
1200  const char *consumer,
1201  int flags) GPIOD_API;
1202 
1211  struct gpiod_line_bulk *bulk,
1212  const char *consumer,
1213  int flags) GPIOD_API;
1214 
1223  struct gpiod_line_bulk *bulk,
1224  const char *consumer,
1225  int flags) GPIOD_API;
1226 
1231 void gpiod_line_release(struct gpiod_line *line) GPIOD_API;
1232 
1241 
1247 bool gpiod_line_is_requested(struct gpiod_line *line) GPIOD_API;
1248 
1255 bool gpiod_line_is_free(struct gpiod_line *line) GPIOD_API;
1256 
1270 int gpiod_line_get_value(struct gpiod_line *line) GPIOD_API;
1271 
1284  int *values) GPIOD_API;
1285 
1293 int gpiod_line_set_value(struct gpiod_line *line, int value) GPIOD_API;
1294 
1307  const int *values) GPIOD_API;
1308 
1329 int gpiod_line_set_config(struct gpiod_line *line, int direction,
1330  int flags, int value) GPIOD_API;
1331 
1351  int direction, int flags,
1352  const int *values) GPIOD_API;
1353 
1354 
1362 int gpiod_line_set_flags(struct gpiod_line *line, int flags) GPIOD_API;
1363 
1375  int flags) GPIOD_API;
1376 
1383 int gpiod_line_set_direction_input(struct gpiod_line *line) GPIOD_API;
1384 
1394 int
1396 
1404 int gpiod_line_set_direction_output(struct gpiod_line *line,
1405  int value) GPIOD_API;
1406 
1420  const int *values) GPIOD_API;
1421 
1432 enum {
1437 };
1438 
1443  struct timespec ts;
1447 };
1448 
1456 int gpiod_line_event_wait(struct gpiod_line *line,
1457  const struct timespec *timeout) GPIOD_API;
1458 
1469  const struct timespec *timeout,
1470  struct gpiod_line_bulk *event_bulk) GPIOD_API;
1471 
1479 int gpiod_line_event_read(struct gpiod_line *line,
1480  struct gpiod_line_event *event) GPIOD_API;
1481 
1491 int gpiod_line_event_read_multiple(struct gpiod_line *line,
1492  struct gpiod_line_event *events,
1493  unsigned int num_events) GPIOD_API;
1494 
1505 int gpiod_line_event_get_fd(struct gpiod_line *line) GPIOD_API;
1506 
1518 
1529  unsigned int num_events) GPIOD_API;
1530 
1550 struct gpiod_line *
1551 gpiod_line_get(const char *device, unsigned int offset) GPIOD_API;
1552 
1563 struct gpiod_line *gpiod_line_find(const char *name) GPIOD_API;
1564 
1571 void gpiod_line_close_chip(struct gpiod_line *line) GPIOD_API;
1572 
1578 struct gpiod_chip *gpiod_line_get_chip(struct gpiod_line *line) GPIOD_API;
1579 
1600 struct gpiod_chip_iter *gpiod_chip_iter_new(void) GPIOD_API;
1601 
1607 void gpiod_chip_iter_free(struct gpiod_chip_iter *iter) GPIOD_API;
1608 
1618 void gpiod_chip_iter_free_noclose(struct gpiod_chip_iter *iter) GPIOD_API;
1619 
1627 struct gpiod_chip *
1628 gpiod_chip_iter_next(struct gpiod_chip_iter *iter) GPIOD_API;
1629 
1638 struct gpiod_chip *
1639 gpiod_chip_iter_next_noclose(struct gpiod_chip_iter *iter) GPIOD_API;
1640 
1651 #define gpiod_foreach_chip(iter, chip) \
1652  for ((chip) = gpiod_chip_iter_next(iter); \
1653  (chip); \
1654  (chip) = gpiod_chip_iter_next(iter))
1655 
1666 #define gpiod_foreach_chip_noclose(iter, chip) \
1667  for ((chip) = gpiod_chip_iter_next_noclose(iter); \
1668  (chip); \
1669  (chip) = gpiod_chip_iter_next_noclose(iter))
1670 
1677 struct gpiod_line_iter *
1678 gpiod_line_iter_new(struct gpiod_chip *chip) GPIOD_API;
1679 
1684 void gpiod_line_iter_free(struct gpiod_line_iter *iter) GPIOD_API;
1685 
1692 struct gpiod_line *
1693 gpiod_line_iter_next(struct gpiod_line_iter *iter) GPIOD_API;
1694 
1701 #define gpiod_foreach_line(iter, line) \
1702  for ((line) = gpiod_line_iter_next(iter); \
1703  (line); \
1704  (line) = gpiod_line_iter_next(iter))
1705 
1720 
1725 #ifdef __cplusplus
1726 } /* extern "C" */
1727 #endif
1728 
1729 #endif /* __LIBGPIOD_GPIOD_H__ */
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) GPIOD_API
Wait for events on multiple GPIO lines.
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) GPIOD_API GPIOD_DEPRECATED
Wait for events on multiple GPIO lines.
gpiod_chip_name
const char * gpiod_chip_name(struct gpiod_chip *chip) GPIOD_API
Get the GPIO chip name as represented in the kernel.
GPIOD_LINE_BIAS_PULL_UP
@ GPIOD_LINE_BIAS_PULL_UP
The internal pull-up bias is enabled.
Definition: gpiod.h:824
gpiod_chip_num_lines
unsigned int gpiod_chip_num_lines(struct gpiod_chip *chip) GPIOD_API
Get the number of GPIO lines exposed by this chip.
GPIOD_LINE_EVENT_RISING_EDGE
@ GPIOD_LINE_EVENT_RISING_EDGE
Rising edge event.
Definition: gpiod.h:1433
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) GPIOD_API
Reserve a set of GPIO lines, set the direction to output.
gpiod_chip_find_line
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.
gpiod_chip_iter_free
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...
GPIOD_CTXLESS_EVENT_FALLING_EDGE
@ GPIOD_CTXLESS_EVENT_FALLING_EDGE
Wait for both types of events.
Definition: gpiod.h:252
gpiod_line_needs_update
bool gpiod_line_needs_update(struct gpiod_line *line) GPIOD_API GPIOD_DEPRECATED
Check if the line info needs to be updated.
gpiod_line_is_requested
bool gpiod_line_is_requested(struct gpiod_line *line) GPIOD_API
Check if the calling user has ownership of this line.
gpiod_line_bulk_init
static void gpiod_line_bulk_init(struct gpiod_line_bulk *bulk)
Initialize a GPIO bulk object.
Definition: gpiod.h:720
gpiod_line_bias
int gpiod_line_bias(struct gpiod_line *line) GPIOD_API
Read the GPIO line bias setting.
gpiod_line_event_read_fd
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.
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) GPIOD_API
Read current values from a set of GPIO lines.
GPIOD_LINE_REQUEST_FLAG_OPEN_DRAIN
@ GPIOD_LINE_REQUEST_FLAG_OPEN_DRAIN
The line is an open-drain port.
Definition: gpiod.h:961
gpiod_line_bulk
Helper structure for storing a set of GPIO line objects.
Definition: gpiod.h:700
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) GPIOD_API
Read current value from a single GPIO line.
gpiod_line_direction
int gpiod_line_direction(struct gpiod_line *line) GPIOD_API
Read the GPIO line direction setting.
gpiod_ctxless_get_value
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.
gpiod_line_set_direction_input
int gpiod_line_set_direction_input(struct gpiod_line *line) GPIOD_API
Set the direction of a single GPIO line to input.
gpiod_line_bulk::lines
struct gpiod_line * lines[GPIOD_LINE_BULK_MAX_LINES]
Buffer for line pointers.
Definition: gpiod.h:701
GPIOD_LINE_BIAS_DISABLE
@ GPIOD_LINE_BIAS_DISABLE
The internal bias is disabled.
Definition: gpiod.h:822
gpiod_line_event::ts
struct timespec ts
Best estimate of time of event occurrence.
Definition: gpiod.h:1443
GPIOD_CTXLESS_EVENT_CB_FALLING_EDGE
@ GPIOD_CTXLESS_EVENT_CB_FALLING_EDGE
Falling edge event occured.
Definition: gpiod.h:265
GPIOD_CTXLESS_FLAG_BIAS_PULL_DOWN
@ GPIOD_CTXLESS_FLAG_BIAS_PULL_DOWN
The line has pull-down resistor enabled.
Definition: gpiod.h:97
gpiod_ctxless_event_poll_fd
Helper structure for the ctxless event loop poll callback.
Definition: gpiod.h:313
gpiod_line_set_config
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.
gpiod_ctxless_set_value_cb
void(* gpiod_ctxless_set_value_cb)(void *)
Simple set value callback signature.
Definition: gpiod.h:162
gpiod_ctxless_event_poll_fd::event
bool event
Indicates whether an event occurred on this file descriptor.
Definition: gpiod.h:316
gpiod_line_request_input
int gpiod_line_request_input(struct gpiod_line *line, const char *consumer) GPIOD_API
Reserve a single line, set the direction to input.
gpiod_line_request_rising_edge_events_flags
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.
GPIOD_CTXLESS_EVENT_RISING_EDGE
@ GPIOD_CTXLESS_EVENT_RISING_EDGE
Wait for rising edge events only.
Definition: gpiod.h:250
gpiod_chip_open_by_label
struct gpiod_chip * gpiod_chip_open_by_label(const char *label) GPIOD_API
Open a gpiochip by label.
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) GPIOD_API
Set value of a single GPIO line.
GPIOD_CTXLESS_EVENT_CB_RET_ERR
@ GPIOD_CTXLESS_EVENT_CB_RET_ERR
Stop processing events and indicate an error.
Definition: gpiod.h:273
GPIOD_CTXLESS_EVENT_POLL_RET_ERR
@ GPIOD_CTXLESS_EVENT_POLL_RET_ERR
Polling error occurred (the polling function should set errno).
Definition: gpiod.h:304
gpiod_line_request_config
Structure holding configuration of a line request.
Definition: gpiod.h:978
gpiod_line_get
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.
gpiod_chip_open_lookup
struct gpiod_chip * gpiod_chip_open_lookup(const char *descr) GPIOD_API
Open a gpiochip based on the best guess what the path is.
gpiod_line_close_chip
void gpiod_line_close_chip(struct gpiod_line *line) GPIOD_API
Close a GPIO chip owning this line and release all resources.
gpiod_line_set_value_bulk
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.
gpiod_line_find
struct gpiod_line * gpiod_line_find(const char *name) GPIOD_API
Find a GPIO line by its name.
GPIOD_LINE_REQUEST_EVENT_FALLING_EDGE
@ GPIOD_LINE_REQUEST_EVENT_FALLING_EDGE
Monitor both types of events.
Definition: gpiod.h:949
gpiod_line_request_input_flags
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.
gpiod_line_is_free
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...
GPIOD_CTXLESS_FLAG_OPEN_SOURCE
@ GPIOD_CTXLESS_FLAG_OPEN_SOURCE
The line is an open-source port.
Definition: gpiod.h:93
GPIOD_LINE_REQUEST_DIRECTION_OUTPUT
@ GPIOD_LINE_REQUEST_DIRECTION_OUTPUT
Request the line(s) for setting the GPIO line state.
Definition: gpiod.h:947
gpiod_chip_open_by_name
struct gpiod_chip * gpiod_chip_open_by_name(const char *name) GPIOD_API
Open a gpiochip by name.
gpiod_line_get_chip
struct gpiod_chip * gpiod_line_get_chip(struct gpiod_line *line) GPIOD_API
Get the handle to the GPIO chip controlling this line.
GPIOD_LINE_DIRECTION_INPUT
@ GPIOD_LINE_DIRECTION_INPUT
Direction is input - we're reading the state of a GPIO line.
Definition: gpiod.h:800
gpiod_line_bulk_num_lines
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.
Definition: gpiod.h:754
GPIOD_API
#define GPIOD_API
Makes symbol visible.
Definition: gpiod.h:58
gpiod_line_iter_new
struct gpiod_line_iter * gpiod_line_iter_new(struct gpiod_chip *chip) GPIOD_API
Create a new line iterator.
gpiod_ctxless_event_poll_cb
int(* gpiod_ctxless_event_poll_cb)(unsigned int, struct gpiod_ctxless_event_poll_fd *, const struct timespec *, void *)
Simple event poll callback signature.
Definition: gpiod.h:332
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) GPIOD_API
Wait for events on a single GPIO line.
GPIOD_LINE_REQUEST_EVENT_RISING_EDGE
@ GPIOD_LINE_REQUEST_EVENT_RISING_EDGE
Only watch rising edge events.
Definition: gpiod.h:951
gpiod_line_request_output_flags
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.
gpiod_line_release_bulk
void gpiod_line_release_bulk(struct gpiod_line_bulk *bulk) GPIOD_API
Release a set of previously reserved lines.
gpiod_chip_get_all_lines
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.
gpiod_line_request_both_edges_events_flags
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.
gpiod_line_consumer
const char * gpiod_line_consumer(struct gpiod_line *line) GPIOD_API
Read the GPIO line consumer name.
gpiod_line_request_output
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.
gpiod_line_name
const char * gpiod_line_name(struct gpiod_line *line) GPIOD_API
Read the GPIO line name.
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) GPIOD_API
Retrieve a set of lines and store them in a line bulk object.
GPIOD_CTXLESS_FLAG_BIAS_DISABLE
@ GPIOD_CTXLESS_FLAG_BIAS_DISABLE
The line has neither either pull-up nor pull-down resistor.
Definition: gpiod.h:95
gpiod_line_request_bulk_falling_edge_events
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.
gpiod_line_iter_free
void gpiod_line_iter_free(struct gpiod_line_iter *iter) GPIOD_API
Free all resources associated with a GPIO line iterator.
GPIOD_LINE_REQUEST_FLAG_OPEN_SOURCE
@ GPIOD_LINE_REQUEST_FLAG_OPEN_SOURCE
The line is an open-source port.
Definition: gpiod.h:963
gpiod_line_set_config_bulk
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.
GPIOD_LINE_REQUEST_DIRECTION_AS_IS
@ GPIOD_LINE_REQUEST_DIRECTION_AS_IS
Request the line(s), but don't change current direction.
Definition: gpiod.h:943
GPIOD_LINE_REQUEST_FLAG_ACTIVE_LOW
@ GPIOD_LINE_REQUEST_FLAG_ACTIVE_LOW
The active state of the line is low (high is the default).
Definition: gpiod.h:965
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) GPIOD_API GPIOD_DEPRECATED
Wait for events on a single GPIO line.
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) GPIOD_API
Reserve a set of GPIO lines.
gpiod_line_request_bulk_input_flags
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.
gpiod_chip_label
const char * gpiod_chip_label(struct gpiod_chip *chip) GPIOD_API
Get the GPIO chip label as represented in the kernel.
gpiod_line_set_direction_output_bulk
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.
GPIOD_CTXLESS_FLAG_OPEN_DRAIN
@ GPIOD_CTXLESS_FLAG_OPEN_DRAIN
The line is an open-drain port.
Definition: gpiod.h:91
GPIOD_LINE_BIAS_AS_IS
@ GPIOD_LINE_BIAS_AS_IS
The internal bias state is unknown.
Definition: gpiod.h:820
gpiod_chip_open
struct gpiod_chip * gpiod_chip_open(const char *path) GPIOD_API
Open a gpiochip by path.
gpiod_line_request_bulk_both_edges_events
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.
GPIOD_CTXLESS_FLAG_BIAS_PULL_UP
@ GPIOD_CTXLESS_FLAG_BIAS_PULL_UP
The line has pull-up resistor enabled.
Definition: gpiod.h:99
gpiod_line_request_falling_edge_events_flags
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.
gpiod_line_event::event_type
int event_type
Type of the event that occurred.
Definition: gpiod.h:1445
GPIOD_LINE_REQUEST_EVENT_BOTH_EDGES
@ GPIOD_LINE_REQUEST_EVENT_BOTH_EDGES
Only watch falling edge events.
Definition: gpiod.h:953
gpiod_line_request_config::request_type
int request_type
Request type.
Definition: gpiod.h:981
GPIOD_LINE_REQUEST_FLAG_BIAS_PULL_UP
@ GPIOD_LINE_REQUEST_FLAG_BIAS_PULL_UP
The line has pull-up resistor enabled.
Definition: gpiod.h:971
gpiod_line_update
int gpiod_line_update(struct gpiod_line *line) GPIOD_API
Re-read the line info.
gpiod_line_request
int gpiod_line_request(struct gpiod_line *line, const struct gpiod_line_request_config *config, int default_val) GPIOD_API
Reserve a single line.
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_ctxless_event_poll_fd::fd
int fd
File descriptor number.
Definition: gpiod.h:314
GPIOD_BIT
#define GPIOD_BIT(nr)
Shift 1 by given offset.
Definition: gpiod.h:70
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) GPIOD_API
Wait for events on a single GPIO line.
GPIOD_CTXLESS_EVENT_CB_RISING_EDGE
@ GPIOD_CTXLESS_EVENT_CB_RISING_EDGE
Rising edge event occured.
Definition: gpiod.h:263
gpiod_chip_iter_new
struct gpiod_chip_iter * gpiod_chip_iter_new(void) GPIOD_API
Create a new gpiochip iterator.
gpiod_line_request_config::flags
int flags
Other configuration flags.
Definition: gpiod.h:983
gpiod_line_event_read_fd_multiple
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.
gpiod_line_request_falling_edge_events
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.
gpiod_chip_iter_next
struct gpiod_chip * gpiod_chip_iter_next(struct gpiod_chip_iter *iter) GPIOD_API
Get the next gpiochip handle.
GPIOD_DEPRECATED
#define GPIOD_DEPRECATED
Marks a public function as deprecated.
Definition: gpiod.h:75
gpiod_line_request_both_edges_events
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.
gpiod_line_request_bulk_rising_edge_events
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.
gpiod_line_bulk::num_lines
unsigned int num_lines
Number of lines currently held in this structure.
Definition: gpiod.h:703
gpiod_line_is_used
bool gpiod_line_is_used(struct gpiod_line *line) GPIOD_API
Check if the line is currently in use.
gpiod_version_string
const char * gpiod_version_string(void) GPIOD_API
Get the API version of the library as a human-readable string.
gpiod_line_is_open_source
bool gpiod_line_is_open_source(struct gpiod_line *line) GPIOD_API
Check if the line is an open-source GPIO.
gpiod_line_request_bulk_output
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.
gpiod_ctxless_event_handle_cb
int(* gpiod_ctxless_event_handle_cb)(int, unsigned int, const struct timespec *, void *)
Simple event callback signature.
Definition: gpiod.h:292
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) GPIOD_API
Request falling edge event notifications on a set of lines.
gpiod_line_request_config::consumer
const char * consumer
Name of the consumer.
Definition: gpiod.h:979
gpiod_line_event_get_fd
int gpiod_line_event_get_fd(struct gpiod_line *line) GPIOD_API
Get the event file descriptor.
GPIOD_LINE_BULK_MAX_LINES
#define GPIOD_LINE_BULK_MAX_LINES
Maximum number of GPIO lines that can be requested at once.
Definition: gpiod.h:691
gpiod_line_offset
unsigned int gpiod_line_offset(struct gpiod_line *line) GPIOD_API
Read the GPIO line offset.
GPIOD_LINE_REQUEST_FLAG_BIAS_DISABLE
@ GPIOD_LINE_REQUEST_FLAG_BIAS_DISABLE
The line has neither either pull-up nor pull-down resistor.
Definition: gpiod.h:967
GPIOD_CTXLESS_EVENT_CB_TIMEOUT
@ GPIOD_CTXLESS_EVENT_CB_TIMEOUT
Waiting for events timed out.
Definition: gpiod.h:261
gpiod_line_bulk_add
static void gpiod_line_bulk_add(struct gpiod_line_bulk *bulk, struct gpiod_line *line)
Add a single line to a GPIO bulk object.
Definition: gpiod.h:730
GPIOD_CTXLESS_EVENT_POLL_RET_TIMEOUT
@ GPIOD_CTXLESS_EVENT_POLL_RET_TIMEOUT
Poll timed out.
Definition: gpiod.h:306
gpiod_line_event
Structure holding event info.
Definition: gpiod.h:1442
gpiod_line_is_open_drain
bool gpiod_line_is_open_drain(struct gpiod_line *line) GPIOD_API
Check if the line is an open-drain GPIO.
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) GPIOD_API
Read current values from a set of GPIO lines.
gpiod_line_release
void gpiod_line_release(struct gpiod_line *line) GPIOD_API
Release a previously reserved line.
gpiod_line_set_flags
int gpiod_line_set_flags(struct gpiod_line *line, int flags) GPIOD_API
Update the configuration flags of a single GPIO line.
gpiod_line_set_flags_bulk
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.
gpiod_line_active_state
int gpiod_line_active_state(struct gpiod_line *line) GPIOD_API
Read the GPIO line active state setting.
gpiod_line_request_bulk_input
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.
gpiod_chip_find_lines
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.
GPIOD_LINE_BIAS_PULL_DOWN
@ GPIOD_LINE_BIAS_PULL_DOWN
The internal pull-down bias is enabled.
Definition: gpiod.h:826
gpiod_chip_iter_free_noclose
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...
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) GPIOD_API
Request all event type notifications on a set of lines.
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) GPIOD_API
Set value of a single GPIO line.
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) GPIOD_API
Set values of multiple GPIO lines.
gpiod_line_get_value
int gpiod_line_get_value(struct gpiod_line *line) GPIOD_API
Read current value of a single GPIO line.
gpiod_line_event_read_multiple
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.
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) GPIOD_API
Wait for events on multiple GPIO lines.
gpiod_line_event_wait
int gpiod_line_event_wait(struct gpiod_line *line, const struct timespec *timeout) GPIOD_API
Wait for an event on a single line.
GPIOD_LINE_ACTIVE_STATE_LOW
@ GPIOD_LINE_ACTIVE_STATE_LOW
The active state of a GPIO is active-low.
Definition: gpiod.h:812
gpiod_line_event_read
int gpiod_line_event_read(struct gpiod_line *line, struct gpiod_line_event *event) GPIOD_API
Read the last event from the GPIO line.
GPIOD_LINE_REQUEST_DIRECTION_INPUT
@ GPIOD_LINE_REQUEST_DIRECTION_INPUT
Request the line(s) for reading the GPIO line state.
Definition: gpiod.h:945
GPIOD_CTXLESS_EVENT_CB_RET_OK
@ GPIOD_CTXLESS_EVENT_CB_RET_OK
Continue processing events.
Definition: gpiod.h:275
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.
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) GPIOD_API
Request rising edge event notifications on a set of lines.
gpiod_line_get_value_bulk
int gpiod_line_get_value_bulk(struct gpiod_line_bulk *bulk, int *values) GPIOD_API
Read current values of a set of GPIO lines.
GPIOD_LINE_EVENT_FALLING_EDGE
@ GPIOD_LINE_EVENT_FALLING_EDGE
Falling edge event.
Definition: gpiod.h:1435
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) GPIOD_API
Wait for events on a set of lines.
gpiod_line_request_rising_edge_events
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.
GPIOD_CTXLESS_EVENT_CB_RET_STOP
@ GPIOD_CTXLESS_EVENT_CB_RET_STOP
Stop processing events.
Definition: gpiod.h:277
gpiod_chip_close
void gpiod_chip_close(struct gpiod_chip *chip) GPIOD_API
Close a GPIO chip handle and release all allocated resources.
gpiod_chip_open_by_number
struct gpiod_chip * gpiod_chip_open_by_number(unsigned int num) GPIOD_API
Open a gpiochip by number.
gpiod_line_bulk_get_line
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.
Definition: gpiod.h:743
GPIOD_LINE_ACTIVE_STATE_HIGH
@ GPIOD_LINE_ACTIVE_STATE_HIGH
The active state of a GPIO is active-high.
Definition: gpiod.h:810
gpiod_line_set_value
int gpiod_line_set_value(struct gpiod_line *line, int value) GPIOD_API
Set the value of a single GPIO line.
gpiod_ctxless_find_line
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.
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) GPIOD_API
Set values of multiple GPIO lines.
gpiod_line_set_direction_output
int gpiod_line_set_direction_output(struct gpiod_line *line, int value) GPIOD_API
Set the direction of a single GPIO line to output.
GPIOD_LINE_DIRECTION_OUTPUT
@ GPIOD_LINE_DIRECTION_OUTPUT
Direction is output - we're driving the GPIO line.
Definition: gpiod.h:802
GPIOD_LINE_REQUEST_FLAG_BIAS_PULL_DOWN
@ GPIOD_LINE_REQUEST_FLAG_BIAS_PULL_DOWN
The line has pull-down resistor enabled.
Definition: gpiod.h:969
GPIOD_CTXLESS_EVENT_POLL_RET_STOP
@ GPIOD_CTXLESS_EVENT_POLL_RET_STOP
The event loop should stop processing events.
Definition: gpiod.h:302
gpiod_line_set_direction_input_bulk
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.
gpiod_chip_get_line
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.