libgpiod  1.6.2
gpiod.h
Go to the documentation of this file.
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 
46 struct gpiod_chip;
47 struct gpiod_line;
48 struct gpiod_chip_iter;
49 struct gpiod_line_iter;
50 struct gpiod_line_bulk;
51 
62 #define GPIOD_API __attribute__((visibility("default")))
63 
67 #define GPIOD_UNUSED __attribute__((unused))
68 
74 #define GPIOD_BIT(nr) (1UL << (nr))
75 
79 #define GPIOD_DEPRECATED __attribute__((deprecated))
80 
94 enum {
105 };
106 
115 int gpiod_ctxless_get_value(const char *device, unsigned int offset,
116  bool active_low, const char *consumer) GPIOD_API;
117 
127 int gpiod_ctxless_get_value_ext(const char *device, unsigned int offset,
128  bool active_low, const char *consumer,
129  int flags) GPIOD_API;
130 
141 int gpiod_ctxless_get_value_multiple(const char *device,
142  const unsigned int *offsets, int *values,
143  unsigned int num_lines, bool active_low,
144  const char *consumer) GPIOD_API;
145 
158  const unsigned int *offsets,
159  int *values, unsigned int num_lines,
160  bool active_low, const char *consumer,
161  int flags) GPIOD_API;
162 
166 typedef void (*gpiod_ctxless_set_value_cb)(void *);
167 
181 int gpiod_ctxless_set_value(const char *device, unsigned int offset, int value,
182  bool active_low, const char *consumer,
184  void *data) GPIOD_API;
185 
200 int gpiod_ctxless_set_value_ext(const char *device, unsigned int offset,
201  int value, bool active_low,
202  const char *consumer,
204  void *data, int flags) GPIOD_API;
205 
219 int gpiod_ctxless_set_value_multiple(const char *device,
220  const unsigned int *offsets,
221  const int *values, unsigned int num_lines,
222  bool active_low, const char *consumer,
224  void *data) GPIOD_API;
225 
241  const unsigned int *offsets,
242  const int *values,
243  unsigned int num_lines,
244  bool active_low,
245  const char *consumer,
247  void *data, int flags) GPIOD_API;
248 
252 enum {
258  GPIOD_CTXLESS_EVENT_BOTH_EDGES,
259 };
260 
264 enum {
271 };
272 
276 enum {
283 };
284 
296 typedef int (*gpiod_ctxless_event_handle_cb)(int, unsigned int,
297  const struct timespec *, void *);
298 
305 enum {
312 };
313 
318  int fd;
320  bool event;
322 };
323 
336 typedef int (*gpiod_ctxless_event_poll_cb)(unsigned int,
338  const struct timespec *, void *);
339 
358 int gpiod_ctxless_event_loop(const char *device, unsigned int offset,
359  bool active_low, const char *consumer,
360  const struct timespec *timeout,
363  void *data) GPIOD_API GPIOD_DEPRECATED;
364 
396 int gpiod_ctxless_event_loop_multiple(const char *device,
397  const unsigned int *offsets,
398  unsigned int num_lines, bool active_low,
399  const char *consumer,
400  const struct timespec *timeout,
403  void *data) GPIOD_API GPIOD_DEPRECATED;
404 
421 int gpiod_ctxless_event_monitor(const char *device, int event_type,
422  unsigned int offset, bool active_low,
423  const char *consumer,
424  const struct timespec *timeout,
427  void *data) GPIOD_API;
428 
446 int gpiod_ctxless_event_monitor_ext(const char *device, int event_type,
447  unsigned int offset, bool active_low,
448  const char *consumer,
449  const struct timespec *timeout,
452  void *data, int flags) GPIOD_API;
453 
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,
491  void *data) GPIOD_API;
492 
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,
531  void *data, int flags) GPIOD_API;
532 
533 
548 int gpiod_ctxless_find_line(const char *name, char *chipname,
549  size_t chipname_size,
550  unsigned int *offset) GPIOD_API;
551 
566 struct gpiod_chip *gpiod_chip_open(const char *path) GPIOD_API;
567 
575 struct gpiod_chip *gpiod_chip_open_by_name(const char *name) GPIOD_API;
576 
584 struct gpiod_chip *gpiod_chip_open_by_number(unsigned int num) GPIOD_API;
585 
594 struct gpiod_chip *gpiod_chip_open_by_label(const char *label) GPIOD_API;
595 
605 struct gpiod_chip *gpiod_chip_open_lookup(const char *descr) GPIOD_API;
606 
611 void gpiod_chip_close(struct gpiod_chip *chip) GPIOD_API;
612 
618 const char *gpiod_chip_name(struct gpiod_chip *chip) GPIOD_API;
619 
625 const char *gpiod_chip_label(struct gpiod_chip *chip) GPIOD_API;
626 
632 unsigned int gpiod_chip_num_lines(struct gpiod_chip *chip) GPIOD_API;
633 
640 struct gpiod_line *
641 gpiod_chip_get_line(struct gpiod_chip *chip, unsigned int offset) GPIOD_API;
642 
651 int gpiod_chip_get_lines(struct gpiod_chip *chip,
652  unsigned int *offsets, unsigned int num_offsets,
653  struct gpiod_line_bulk *bulk) GPIOD_API;
654 
661 int gpiod_chip_get_all_lines(struct gpiod_chip *chip,
662  struct gpiod_line_bulk *bulk) GPIOD_API;
663 
676 struct gpiod_line *
677 gpiod_chip_find_line(struct gpiod_chip *chip, const char *name) GPIOD_API;
678 
692 int gpiod_chip_find_lines(struct gpiod_chip *chip, const char **names,
693  struct gpiod_line_bulk *bulk) GPIOD_API;
694 
713 #define GPIOD_LINE_BULK_MAX_LINES 64
714 
723  struct gpiod_line *lines[GPIOD_LINE_BULK_MAX_LINES];
725  unsigned int num_lines;
727 };
728 
734 #define GPIOD_LINE_BULK_INITIALIZER { { NULL }, 0 }
735 
742 static inline void gpiod_line_bulk_init(struct gpiod_line_bulk *bulk)
743 {
744  bulk->num_lines = 0;
745 }
746 
752 static inline void gpiod_line_bulk_add(struct gpiod_line_bulk *bulk,
753  struct gpiod_line *line)
754 {
755  bulk->lines[bulk->num_lines++] = line;
756 }
757 
764 static inline struct gpiod_line *
765 gpiod_line_bulk_get_line(struct gpiod_line_bulk *bulk, unsigned int offset)
766 {
767  return bulk->lines[offset];
768 }
769 
775 static inline unsigned int
777 {
778  return bulk->num_lines;
779 }
780 
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))
792 
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)])
810 
824 enum {
829 };
830 
834 enum {
839 };
840 
844 enum {
853 };
854 
860 unsigned int gpiod_line_offset(struct gpiod_line *line) GPIOD_API;
861 
869 const char *gpiod_line_name(struct gpiod_line *line) GPIOD_API;
870 
878 const char *gpiod_line_consumer(struct gpiod_line *line) GPIOD_API;
879 
885 int gpiod_line_direction(struct gpiod_line *line) GPIOD_API;
886 
892 int gpiod_line_active_state(struct gpiod_line *line) GPIOD_API;
893 
900 int gpiod_line_bias(struct gpiod_line *line) GPIOD_API;
901 
911 bool gpiod_line_is_used(struct gpiod_line *line) GPIOD_API;
912 
918 bool gpiod_line_is_open_drain(struct gpiod_line *line) GPIOD_API;
919 
925 bool gpiod_line_is_open_source(struct gpiod_line *line) GPIOD_API;
926 
947 int gpiod_line_update(struct gpiod_line *line) GPIOD_API;
948 
956 bool
958 
972 enum {
985 };
986 
990 enum {
1003 };
1004 
1009  const char *consumer;
1013  int flags;
1015 };
1016 
1029 int gpiod_line_request(struct gpiod_line *line,
1030  const struct gpiod_line_request_config *config,
1031  int default_val) GPIOD_API;
1032 
1039 int gpiod_line_request_input(struct gpiod_line *line,
1040  const char *consumer) GPIOD_API;
1041 
1049 int gpiod_line_request_output(struct gpiod_line *line,
1050  const char *consumer, int default_val) GPIOD_API;
1051 
1058 int gpiod_line_request_rising_edge_events(struct gpiod_line *line,
1059  const char *consumer) GPIOD_API;
1060 
1067 int gpiod_line_request_falling_edge_events(struct gpiod_line *line,
1068  const char *consumer) GPIOD_API;
1069 
1076 int gpiod_line_request_both_edges_events(struct gpiod_line *line,
1077  const char *consumer) GPIOD_API;
1078 
1086 int gpiod_line_request_input_flags(struct gpiod_line *line,
1087  const char *consumer, int flags) GPIOD_API;
1088 
1097 int gpiod_line_request_output_flags(struct gpiod_line *line,
1098  const char *consumer, int flags,
1099  int default_val) GPIOD_API;
1100 
1109  const char *consumer,
1110  int flags) GPIOD_API;
1111 
1120  const char *consumer,
1121  int flags) GPIOD_API;
1122 
1131  const char *consumer,
1132  int flags) GPIOD_API;
1133 
1148  const struct gpiod_line_request_config *config,
1149  const int *default_vals) GPIOD_API;
1150 
1158  const char *consumer) GPIOD_API;
1159 
1168  const char *consumer,
1169  const int *default_vals) GPIOD_API;
1170 
1178  const char *consumer) GPIOD_API;
1179 
1187  const char *consumer) GPIOD_API;
1188 
1196  const char *consumer) GPIOD_API;
1197 
1206  const char *consumer,
1207  int flags) GPIOD_API;
1208 
1218  const char *consumer, int flags,
1219  const int *default_vals) GPIOD_API;
1220 
1229  struct gpiod_line_bulk *bulk,
1230  const char *consumer,
1231  int flags) GPIOD_API;
1232 
1241  struct gpiod_line_bulk *bulk,
1242  const char *consumer,
1243  int flags) GPIOD_API;
1244 
1253  struct gpiod_line_bulk *bulk,
1254  const char *consumer,
1255  int flags) GPIOD_API;
1256 
1261 void gpiod_line_release(struct gpiod_line *line) GPIOD_API;
1262 
1271 
1277 bool gpiod_line_is_requested(struct gpiod_line *line) GPIOD_API;
1278 
1285 bool gpiod_line_is_free(struct gpiod_line *line) GPIOD_API;
1286 
1303 int gpiod_line_get_value(struct gpiod_line *line) GPIOD_API;
1304 
1317  int *values) GPIOD_API;
1318 
1326 int gpiod_line_set_value(struct gpiod_line *line, int value) GPIOD_API;
1327 
1340  const int *values) GPIOD_API;
1341 
1365 int gpiod_line_set_config(struct gpiod_line *line, int direction,
1366  int flags, int value) GPIOD_API;
1367 
1387  int direction, int flags,
1388  const int *values) GPIOD_API;
1389 
1390 
1398 int gpiod_line_set_flags(struct gpiod_line *line, int flags) GPIOD_API;
1399 
1411  int flags) GPIOD_API;
1412 
1419 int gpiod_line_set_direction_input(struct gpiod_line *line) GPIOD_API;
1420 
1430 int
1432 
1440 int gpiod_line_set_direction_output(struct gpiod_line *line,
1441  int value) GPIOD_API;
1442 
1456  const int *values) GPIOD_API;
1457 
1473 enum {
1478 };
1479 
1484  struct timespec ts;
1488 };
1489 
1497 int gpiod_line_event_wait(struct gpiod_line *line,
1498  const struct timespec *timeout) GPIOD_API;
1499 
1510  const struct timespec *timeout,
1511  struct gpiod_line_bulk *event_bulk) GPIOD_API;
1512 
1520 int gpiod_line_event_read(struct gpiod_line *line,
1521  struct gpiod_line_event *event) GPIOD_API;
1522 
1532 int gpiod_line_event_read_multiple(struct gpiod_line *line,
1533  struct gpiod_line_event *events,
1534  unsigned int num_events) GPIOD_API;
1535 
1546 int gpiod_line_event_get_fd(struct gpiod_line *line) GPIOD_API;
1547 
1559 
1570  unsigned int num_events) GPIOD_API;
1571 
1593 struct gpiod_line *
1594 gpiod_line_get(const char *device, unsigned int offset) GPIOD_API;
1595 
1609 struct gpiod_line *gpiod_line_find(const char *name) GPIOD_API;
1610 
1617 void gpiod_line_close_chip(struct gpiod_line *line) GPIOD_API;
1618 
1624 struct gpiod_chip *gpiod_line_get_chip(struct gpiod_line *line) GPIOD_API;
1625 
1646 struct gpiod_chip_iter *gpiod_chip_iter_new(void) GPIOD_API;
1647 
1653 void gpiod_chip_iter_free(struct gpiod_chip_iter *iter) GPIOD_API;
1654 
1664 void gpiod_chip_iter_free_noclose(struct gpiod_chip_iter *iter) GPIOD_API;
1665 
1673 struct gpiod_chip *
1674 gpiod_chip_iter_next(struct gpiod_chip_iter *iter) GPIOD_API;
1675 
1684 struct gpiod_chip *
1685 gpiod_chip_iter_next_noclose(struct gpiod_chip_iter *iter) GPIOD_API;
1686 
1697 #define gpiod_foreach_chip(iter, chip) \
1698  for ((chip) = gpiod_chip_iter_next(iter); \
1699  (chip); \
1700  (chip) = gpiod_chip_iter_next(iter))
1701 
1712 #define gpiod_foreach_chip_noclose(iter, chip) \
1713  for ((chip) = gpiod_chip_iter_next_noclose(iter); \
1714  (chip); \
1715  (chip) = gpiod_chip_iter_next_noclose(iter))
1716 
1723 struct gpiod_line_iter *
1724 gpiod_line_iter_new(struct gpiod_chip *chip) GPIOD_API;
1725 
1730 void gpiod_line_iter_free(struct gpiod_line_iter *iter) GPIOD_API;
1731 
1738 struct gpiod_line *
1739 gpiod_line_iter_next(struct gpiod_line_iter *iter) GPIOD_API;
1740 
1747 #define gpiod_foreach_line(iter, line) \
1748  for ((line) = gpiod_line_iter_next(iter); \
1749  (line); \
1750  (line) = gpiod_line_iter_next(iter))
1751 
1766 
1771 #ifdef __cplusplus
1772 } /* extern "C" */
1773 #endif
1774 
1775 #endif /* __LIBGPIOD_GPIOD_H__ */
gpiod_chip_open_by_name
struct gpiod_chip * gpiod_chip_open_by_name(const char *name) GPIOD_API
Open a gpiochip by name.
gpiod_chip_open
struct gpiod_chip * gpiod_chip_open(const char *path) GPIOD_API
Open a gpiochip by path.
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_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_line_active_state
int gpiod_line_active_state(struct gpiod_line *line) GPIOD_API
Read the GPIO line active state setting.
GPIOD_LINE_REQUEST_EVENT_RISING_EDGE
@ GPIOD_LINE_REQUEST_EVENT_RISING_EDGE
Only watch rising edge events.
Definition: gpiod.h:981
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_BIT
#define GPIOD_BIT(nr)
Shift 1 by given offset.
Definition: gpiod.h:74
GPIOD_LINE_REQUEST_DIRECTION_OUTPUT
@ GPIOD_LINE_REQUEST_DIRECTION_OUTPUT
Request the line(s) for setting the GPIO line state.
Definition: gpiod.h:977
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_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_bulk
Helper structure for storing a set of GPIO line objects.
Definition: gpiod.h:722
GPIOD_LINE_BIAS_DISABLE
@ GPIOD_LINE_BIAS_DISABLE
The internal bias is disabled.
Definition: gpiod.h:847
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_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_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_bulk::lines
struct gpiod_line * lines[GPIOD_LINE_BULK_MAX_LINES]
Buffer for line pointers.
Definition: gpiod.h:723
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_line_event::ts
struct timespec ts
Best estimate of time of event occurrence.
Definition: gpiod.h:1484
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_EVENT_RISING_EDGE
@ GPIOD_CTXLESS_EVENT_RISING_EDGE
Wait for rising edge events only.
Definition: gpiod.h:254
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_EVENT_CB_RISING_EDGE
@ GPIOD_CTXLESS_EVENT_CB_RISING_EDGE
Rising edge event occured.
Definition: gpiod.h:267
GPIOD_LINE_DIRECTION_INPUT
@ GPIOD_LINE_DIRECTION_INPUT
Direction is input - we're reading the state of a GPIO line.
Definition: gpiod.h:825
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_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_CTXLESS_EVENT_POLL_RET_ERR
@ GPIOD_CTXLESS_EVENT_POLL_RET_ERR
Polling error occurred (the polling function should set errno).
Definition: gpiod.h:308
gpiod_line_event_read
int gpiod_line_event_read(struct gpiod_line *line, struct gpiod_line_event *event) GPIOD_API
Read next pending event from the GPIO line.
gpiod_ctxless_event_poll_fd
Helper structure for the ctxless event loop poll callback.
Definition: gpiod.h:317
gpiod_ctxless_event_poll_fd::event
bool event
Indicates whether an event occurred on this file descriptor.
Definition: gpiod.h:320
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_BIAS_PULL_DOWN
@ GPIOD_LINE_BIAS_PULL_DOWN
The internal pull-down bias is enabled.
Definition: gpiod.h:851
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_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_LINE_BULK_MAX_LINES
#define GPIOD_LINE_BULK_MAX_LINES
Maximum number of GPIO lines that can be requested at once.
Definition: gpiod.h:713
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_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_chip_open_by_number
struct gpiod_chip * gpiod_chip_open_by_number(unsigned int num) GPIOD_API
Open a gpiochip by number.
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_update
int gpiod_line_update(struct gpiod_line *line) GPIOD_API
Re-read the line info.
gpiod_line_request_config
Structure holding configuration of a line request.
Definition: gpiod.h:1008
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_API
#define GPIOD_API
Makes symbol visible.
Definition: gpiod.h:62
GPIOD_CTXLESS_EVENT_CB_RET_OK
@ GPIOD_CTXLESS_EVENT_CB_RET_OK
Continue processing events.
Definition: gpiod.h:279
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_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_FLAG_OPEN_SOURCE
@ GPIOD_LINE_REQUEST_FLAG_OPEN_SOURCE
The line is an open-source port.
Definition: gpiod.h:993
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_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_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:765
gpiod_line_bulk_init
static void gpiod_line_bulk_init(struct gpiod_line_bulk *bulk)
Initialize a GPIO bulk object.
Definition: gpiod.h:742
gpiod_line_is_used
bool gpiod_line_is_used(struct gpiod_line *line) GPIOD_API
Check if the line is currently in use.
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_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_CTXLESS_FLAG_OPEN_DRAIN
@ GPIOD_CTXLESS_FLAG_OPEN_DRAIN
The line is an open-drain port.
Definition: gpiod.h:95
GPIOD_LINE_BIAS_AS_IS
@ GPIOD_LINE_BIAS_AS_IS
The internal bias state is unknown.
Definition: gpiod.h:845
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
int gpiod_line_bias(struct gpiod_line *line) GPIOD_API
Read the GPIO line bias setting.
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_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_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_REQUEST_EVENT_FALLING_EDGE
@ GPIOD_LINE_REQUEST_EVENT_FALLING_EDGE
Only watch falling edge events.
Definition: gpiod.h:979
GPIOD_LINE_BIAS_PULL_UP
@ GPIOD_LINE_BIAS_PULL_UP
The internal pull-up bias is enabled.
Definition: gpiod.h:849
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_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_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_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_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_CTXLESS_FLAG_BIAS_DISABLE
@ GPIOD_CTXLESS_FLAG_BIAS_DISABLE
The line has neither either pull-up nor pull-down resistor.
Definition: gpiod.h:99
GPIOD_CTXLESS_EVENT_CB_TIMEOUT
@ GPIOD_CTXLESS_EVENT_CB_TIMEOUT
Waiting for events timed out.
Definition: gpiod.h:265
GPIOD_CTXLESS_EVENT_POLL_RET_TIMEOUT
@ GPIOD_CTXLESS_EVENT_POLL_RET_TIMEOUT
Poll timed out.
Definition: gpiod.h:310
GPIOD_LINE_ACTIVE_STATE_HIGH
@ GPIOD_LINE_ACTIVE_STATE_HIGH
The active state of a GPIO is active-high.
Definition: gpiod.h:835
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_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_handle_cb
int(* gpiod_ctxless_event_handle_cb)(int, unsigned int, const struct timespec *, void *)
Simple event callback signature.
Definition: gpiod.h:296
GPIOD_CTXLESS_FLAG_OPEN_SOURCE
@ GPIOD_CTXLESS_FLAG_OPEN_SOURCE
The line is an open-source port.
Definition: gpiod.h:97
GPIOD_LINE_REQUEST_DIRECTION_INPUT
@ GPIOD_LINE_REQUEST_DIRECTION_INPUT
Request the line(s) for reading the GPIO line state.
Definition: gpiod.h:975
gpiod_ctxless_set_value_cb
void(* gpiod_ctxless_set_value_cb)(void *)
Simple set value callback signature.
Definition: gpiod.h:166
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_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_DEPRECATED
#define GPIOD_DEPRECATED
Marks a public function as deprecated.
Definition: gpiod.h:79
GPIOD_CTXLESS_EVENT_CB_RET_STOP
@ GPIOD_CTXLESS_EVENT_CB_RET_STOP
Stop processing events.
Definition: gpiod.h:281
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_line_direction
int gpiod_line_direction(struct gpiod_line *line) GPIOD_API
Read the GPIO line direction setting.
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_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_CTXLESS_EVENT_POLL_RET_STOP
@ GPIOD_CTXLESS_EVENT_POLL_RET_STOP
The event loop should stop processing events.
Definition: gpiod.h:306
gpiod_line_consumer
const char * gpiod_line_consumer(struct gpiod_line *line) GPIOD_API
Read the GPIO line consumer name.
GPIOD_LINE_EVENT_FALLING_EDGE
@ GPIOD_LINE_EVENT_FALLING_EDGE
Falling edge event.
Definition: gpiod.h:1476
GPIOD_LINE_ACTIVE_STATE_LOW
@ GPIOD_LINE_ACTIVE_STATE_LOW
The active state of a GPIO is active-low.
Definition: gpiod.h:837
GPIOD_LINE_REQUEST_FLAG_OPEN_DRAIN
@ GPIOD_LINE_REQUEST_FLAG_OPEN_DRAIN
The line is an open-drain port.
Definition: gpiod.h:991
gpiod_line_event::event_type
int event_type
Type of the event that occurred.
Definition: gpiod.h:1486
gpiod_line_name
const char * gpiod_line_name(struct gpiod_line *line) GPIOD_API
Read the GPIO line name.
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_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:995
gpiod_line_request_config::request_type
int request_type
Request type.
Definition: gpiod.h:1011
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_CTXLESS_EVENT_FALLING_EDGE
@ GPIOD_CTXLESS_EVENT_FALLING_EDGE
Wait for both types of events.
Definition: gpiod.h:256
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:997
gpiod_ctxless_event_poll_fd::fd
int fd
File descriptor number.
Definition: gpiod.h:318
gpiod_line_request_config::flags
int flags
Other configuration flags.
Definition: gpiod.h:1013
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_line_find
struct gpiod_line * gpiod_line_find(const char *name) GPIOD_API
Find a GPIO line by its name.
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_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_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_release_bulk
void gpiod_line_release_bulk(struct gpiod_line_bulk *bulk) GPIOD_API
Release a set of previously reserved 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_REQUEST_DIRECTION_AS_IS
@ GPIOD_LINE_REQUEST_DIRECTION_AS_IS
Request the line(s), but don't change current direction.
Definition: gpiod.h:973
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:336
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.
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_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_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_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_line_bulk::num_lines
unsigned int num_lines
Number of lines currently held in this structure.
Definition: gpiod.h:725
gpiod_line_offset
unsigned int gpiod_line_offset(struct gpiod_line *line) GPIOD_API
Read the GPIO line offset.
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_event_get_fd
int gpiod_line_event_get_fd(struct gpiod_line *line) GPIOD_API
Get the event file descriptor.
gpiod_line_request_config::consumer
const char * consumer
Name of the consumer.
Definition: gpiod.h:1009
GPIOD_CTXLESS_FLAG_BIAS_PULL_UP
@ GPIOD_CTXLESS_FLAG_BIAS_PULL_UP
The line has pull-up resistor enabled.
Definition: gpiod.h:103
GPIOD_LINE_EVENT_RISING_EDGE
@ GPIOD_LINE_EVENT_RISING_EDGE
Rising edge event.
Definition: gpiod.h:1474
GPIOD_LINE_REQUEST_FLAG_BIAS_PULL_DOWN
@ GPIOD_LINE_REQUEST_FLAG_BIAS_PULL_DOWN
The line has pull-down resistor enabled.
Definition: gpiod.h:999
gpiod_chip_iter_next
struct gpiod_chip * gpiod_chip_iter_next(struct gpiod_chip_iter *iter) GPIOD_API
Get the next gpiochip handle.
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_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_line_event
Structure holding event info.
Definition: gpiod.h:1483
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_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_BIAS_PULL_DOWN
@ GPIOD_CTXLESS_FLAG_BIAS_PULL_DOWN
The line has pull-down resistor enabled.
Definition: gpiod.h:101
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_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_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_CB_FALLING_EDGE
@ GPIOD_CTXLESS_EVENT_CB_FALLING_EDGE
Falling edge event occured.
Definition: gpiod.h:269
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_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_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_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_EVENT_BOTH_EDGES
@ GPIOD_LINE_REQUEST_EVENT_BOTH_EDGES
Monitor both types of events.
Definition: gpiod.h:983
gpiod_line_release
void gpiod_line_release(struct gpiod_line *line) GPIOD_API
Release a previously reserved line.
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_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_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_REQUEST_FLAG_BIAS_PULL_UP
@ GPIOD_LINE_REQUEST_FLAG_BIAS_PULL_UP
The line has pull-up resistor enabled.
Definition: gpiod.h:1001
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_chip_iter_new
struct gpiod_chip_iter * gpiod_chip_iter_new(void) GPIOD_API
Create a new gpiochip iterator.
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_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_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_chip_close
void gpiod_chip_close(struct gpiod_chip *chip) GPIOD_API
Close a GPIO chip handle and release all allocated resources.
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_DIRECTION_OUTPUT
@ GPIOD_LINE_DIRECTION_OUTPUT
Direction is output - we're driving the GPIO line.
Definition: gpiod.h:827
gpiod_chip_open_by_label
struct gpiod_chip * gpiod_chip_open_by_label(const char *label) GPIOD_API
Open a gpiochip by label.
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:776
GPIOD_CTXLESS_EVENT_CB_RET_ERR
@ GPIOD_CTXLESS_EVENT_CB_RET_ERR
Stop processing events and indicate an error.
Definition: gpiod.h:277
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_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_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_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:752
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.