libgpiod
gpiod.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
2 /* SPDX-FileCopyrightText: 2017-2022 Bartosz Golaszewski <brgl@bgdev.pl> */
3 
8 #ifndef __LIBGPIOD_GPIOD_H__
9 #define __LIBGPIOD_GPIOD_H__
10 
11 #include <stdbool.h>
12 #include <stddef.h>
13 #include <stdint.h>
14 
15 #ifdef __cplusplus
16 extern "C" {
17 #endif
18 
27 struct gpiod_chip;
28 
38 
48 
59 
69 
80 
91 
101 
111 
122 
141 struct gpiod_chip *gpiod_chip_open(const char *path);
142 
147 void gpiod_chip_close(struct gpiod_chip *chip);
148 
155 struct gpiod_chip_info *gpiod_chip_get_info(struct gpiod_chip *chip);
156 
164 const char *gpiod_chip_get_path(struct gpiod_chip *chip);
165 
174  unsigned int offset);
175 
187  unsigned int offset);
188 
195 int gpiod_chip_unwatch_line_info(struct gpiod_chip *chip, unsigned int offset);
196 
206 int gpiod_chip_get_fd(struct gpiod_chip *chip);
207 
219 int gpiod_chip_wait_info_event(struct gpiod_chip *chip, int64_t timeout_ns);
220 
229 
239  const char *name);
240 
249 struct gpiod_line_request *
251  struct gpiod_request_config *req_cfg,
252  struct gpiod_line_config *line_cfg);
253 
278 void gpiod_chip_info_free(struct gpiod_chip_info *info);
279 
287 const char *gpiod_chip_info_get_name(struct gpiod_chip_info *info);
288 
296 const char *gpiod_chip_info_get_label(struct gpiod_chip_info *info);
297 
304 
324 };
325 
337 };
338 
351 };
352 
367 };
368 
379 };
380 
391 };
392 
419 void gpiod_line_info_free(struct gpiod_line_info *info);
420 
428 
437 unsigned int gpiod_line_info_get_offset(struct gpiod_line_info *info);
438 
447 const char *gpiod_line_info_get_name(struct gpiod_line_info *info);
448 
459 bool gpiod_line_info_is_used(struct gpiod_line_info *info);
460 
470 const char *gpiod_line_info_get_consumer(struct gpiod_line_info *info);
471 
480 
487 enum gpiod_line_edge
489 
496 enum gpiod_line_bias
498 
505 enum gpiod_line_drive
507 
515 
523 
530 unsigned long
532 
540 enum gpiod_line_clock
542 
568 };
569 
574 void gpiod_info_event_free(struct gpiod_info_event *event);
575 
585 
592 
606 struct gpiod_line_info *
608 
632 
637 void gpiod_line_settings_free(struct gpiod_line_settings *settings);
638 
643 void gpiod_line_settings_reset(struct gpiod_line_settings *settings);
644 
651 struct gpiod_line_settings *
653 
662 
670 
678  enum gpiod_line_edge edge);
679 
685 enum gpiod_line_edge
687 
695  enum gpiod_line_bias bias);
696 
702 enum gpiod_line_bias
704 
712  enum gpiod_line_drive drive);
713 
719 enum gpiod_line_drive
721 
728  bool active_low);
729 
736 
742 void
744  unsigned long period);
745 
751 unsigned long
753  struct gpiod_line_settings *settings);
754 
762  enum gpiod_line_clock event_clock);
763 
769 enum gpiod_line_clock
771 
779  enum gpiod_line_value value);
780 
786 enum gpiod_line_value
788 
818 
823 void gpiod_line_config_free(struct gpiod_line_config *config);
824 
832 void gpiod_line_config_reset(struct gpiod_line_config *config);
833 
843  const unsigned int *offsets,
844  size_t num_offsets,
845  struct gpiod_line_settings *settings);
846 
854 struct gpiod_line_settings *
856  unsigned int offset);
857 
880  const enum gpiod_line_value *values,
881  size_t num_values);
882 
888 size_t
890 
902 size_t
904  unsigned int *offsets,
905  size_t max_offsets);
906 
927 
933 
942  const char *consumer);
943 
949 const char *
951 
961 void
963  size_t event_buffer_size);
964 
970 size_t
972 
986 void gpiod_line_request_release(struct gpiod_line_request *request);
987 
994 const char *
996 
1002 size_t
1004 
1016 size_t
1018  unsigned int *offsets,
1019  size_t max_offsets);
1020 
1027 enum gpiod_line_value
1029  unsigned int offset);
1030 
1043  size_t num_values,
1044  const unsigned int *offsets,
1045  enum gpiod_line_value *values);
1046 
1059  enum gpiod_line_value *values);
1060 
1069  unsigned int offset,
1070  enum gpiod_line_value value);
1071 
1085  size_t num_values,
1086  const unsigned int *offsets,
1087  const enum gpiod_line_value *values);
1088 
1101  const enum gpiod_line_value *values);
1102 
1115  struct gpiod_line_config *config);
1116 
1125 int gpiod_line_request_get_fd(struct gpiod_line_request *request);
1126 
1141  int64_t timeout_ns);
1142 
1155  struct gpiod_edge_event_buffer *buffer,
1156  size_t max_events);
1157 
1184 };
1185 
1190 void gpiod_edge_event_free(struct gpiod_edge_event *event);
1191 
1199 
1208 
1216 uint64_t gpiod_edge_event_get_timestamp_ns(struct gpiod_edge_event *event);
1217 
1223 unsigned int gpiod_edge_event_get_line_offset(struct gpiod_edge_event *event);
1224 
1231 unsigned long gpiod_edge_event_get_global_seqno(struct gpiod_edge_event *event);
1232 
1239 unsigned long gpiod_edge_event_get_line_seqno(struct gpiod_edge_event *event);
1240 
1253 struct gpiod_edge_event_buffer *
1254 gpiod_edge_event_buffer_new(size_t capacity);
1255 
1262 size_t
1264 
1270 
1285 struct gpiod_edge_event *
1287  unsigned long index);
1288 
1294 size_t
1296 
1312 bool gpiod_is_gpiochip_device(const char *path);
1313 
1320 const char *gpiod_api_version(void);
1321 
1326 #ifdef __cplusplus
1327 } /* extern "C" */
1328 #endif
1329 
1330 #endif /* __LIBGPIOD_GPIOD_H__ */
Definition: gpiod.h:322
void gpiod_line_settings_set_active_low(struct gpiod_line_settings *settings, bool active_low)
Set active-low setting.
int gpiod_line_settings_set_drive(struct gpiod_line_settings *settings, enum gpiod_line_drive drive)
Set drive.
struct gpiod_line_settings * gpiod_line_settings_copy(struct gpiod_line_settings *settings)
Copy the line settings object.
Definition: gpiod.h:320
Definition: gpiod.h:361
Definition: gpiod.h:564
Definition: gpiod.h:385
int gpiod_line_config_set_output_values(struct gpiod_line_config *config, const enum gpiod_line_value *values, size_t num_values)
Set output values for a number of lines.
enum gpiod_line_edge gpiod_line_info_get_edge_detection(struct gpiod_line_info *info)
Get the edge detection setting of the line.
size_t gpiod_line_config_get_configured_offsets(struct gpiod_line_config *config, unsigned int *offsets, size_t max_offsets)
Get configured offsets.
void gpiod_line_request_release(struct gpiod_line_request *request)
Release the requested lines and free all associated resources.
struct gpiod_line_settings * gpiod_line_config_get_line_settings(struct gpiod_line_config *config, unsigned int offset)
Get line settings for offset.
int gpiod_line_request_wait_edge_events(struct gpiod_line_request *request, int64_t timeout_ns)
Wait for edge events on any of the requested lines.
edge
Edge detection settings.
Definition: line.hpp:105
Definition: gpiod.h:387
unsigned long gpiod_edge_event_get_line_seqno(struct gpiod_edge_event *event)
Get the event sequence number specific to the line.
Definition: gpiod.h:79
int gpiod_line_request_get_values(struct gpiod_line_request *request, enum gpiod_line_value *values)
Get the values of all requested lines.
struct gpiod_info_event * gpiod_chip_read_info_event(struct gpiod_chip *chip)
Read a single line status change event from the chip.
const char * gpiod_line_request_get_chip_name(struct gpiod_line_request *request)
Get the name of the chip this request was made on.
const char * gpiod_line_info_get_consumer(struct gpiod_line_info *info)
Get the name of the consumer of the line.
void gpiod_chip_close(struct gpiod_chip *chip)
Close the chip and release all associated resources.
void gpiod_edge_event_buffer_free(struct gpiod_edge_event_buffer *buffer)
Free the edge event buffer and release all associated resources.
enum gpiod_line_bias gpiod_line_settings_get_bias(struct gpiod_line_settings *settings)
Get bias.
int gpiod_line_settings_set_edge_detection(struct gpiod_line_settings *settings, enum gpiod_line_edge edge)
Set edge detection.
size_t gpiod_edge_event_buffer_get_capacity(struct gpiod_edge_event_buffer *buffer)
Get the capacity (the max number of events that can be stored) of the event buffer.
Definition: gpiod.h:562
Definition: gpiod.h:318
Definition: gpiod.h:347
enum gpiod_line_value gpiod_line_request_get_value(struct gpiod_line_request *request, unsigned int offset)
Get the value of a single requested line.
struct gpiod_request_config * gpiod_request_config_new(void)
Create a new request config object.
size_t gpiod_line_config_get_num_configured_offsets(struct gpiod_line_config *config)
Get the number of configured line offsets.
struct gpiod_line_config * gpiod_line_config_new(void)
Create a new line config object.
enum gpiod_line_clock gpiod_line_settings_get_event_clock(struct gpiod_line_settings *settings)
Get event clock setting.
void gpiod_request_config_set_consumer(struct gpiod_request_config *config, const char *consumer)
Set the consumer name for the request.
enum gpiod_line_bias gpiod_line_info_get_bias(struct gpiod_line_info *info)
Get the bias setting of the line.
::std::vector< value > values
Vector of line values.
Definition: line.hpp:168
bool gpiod_line_info_is_debounced(struct gpiod_line_info *info)
Check if the line is debounced (either by hardware or by the kernel software debouncer).
const char * gpiod_chip_info_get_label(struct gpiod_chip_info *info)
Get the label of the chip as represented in the kernel.
enum gpiod_line_drive gpiod_line_info_get_drive(struct gpiod_line_info *info)
Get the drive setting of the line.
Definition: gpiod.h:27
int gpiod_line_settings_set_event_clock(struct gpiod_line_settings *settings, enum gpiod_line_clock event_clock)
Set event clock.
enum gpiod_line_direction gpiod_line_settings_get_direction(struct gpiod_line_settings *settings)
Get direction.
Definition: gpiod.h:37
Definition: gpiod.h:363
void gpiod_line_settings_set_debounce_period_us(struct gpiod_line_settings *settings, unsigned long period)
Set debounce period.
int gpiod_chip_get_fd(struct gpiod_chip *chip)
Get the file descriptor associated with the chip.
Definition: gpiod.h:90
gpiod_line_edge
Edge detection settings.
Definition: gpiod.h:342
size_t gpiod_request_config_get_event_buffer_size(struct gpiod_request_config *config)
Get the edge event buffer size for the request config.
const char * gpiod_api_version(void)
Get the API version of the library as a human-readable string.
struct gpiod_line_request * gpiod_chip_request_lines(struct gpiod_chip *chip, struct gpiod_request_config *req_cfg, struct gpiod_line_config *line_cfg)
Request a set of lines for exclusive usage.
Definition: gpiod.h:335
Definition: gpiod.h:349
gpiod_line_drive
Drive settings.
Definition: gpiod.h:372
struct gpiod_chip_info * gpiod_chip_get_info(struct gpiod_chip *chip)
Get information about the chip.
Definition: gpiod.h:332
int gpiod_line_settings_set_direction(struct gpiod_line_settings *settings, enum gpiod_line_direction direction)
Set direction.
Definition: gpiod.h:58
void gpiod_request_config_set_event_buffer_size(struct gpiod_request_config *config, size_t event_buffer_size)
Set the size of the kernel event buffer for the request.
void gpiod_edge_event_free(struct gpiod_edge_event *event)
Free the edge event object.
const char * gpiod_request_config_get_consumer(struct gpiod_request_config *config)
Get the consumer name configured in the request config.
enum gpiod_line_direction gpiod_line_info_get_direction(struct gpiod_line_info *info)
Get the direction setting of the line.
enum gpiod_line_clock gpiod_line_info_get_event_clock(struct gpiod_line_info *info)
Get the event clock setting used for edge event timestamps for the line.
gpiod_info_event_type
Line status change event types.
Definition: gpiod.h:561
value
Logical line states.
Definition: line.hpp:81
struct gpiod_edge_event * gpiod_edge_event_buffer_get_event(struct gpiod_edge_event_buffer *buffer, unsigned long index)
Get an event stored in the buffer.
struct gpiod_chip * gpiod_chip_open(const char *path)
Open a chip by path.
const char * gpiod_chip_info_get_name(struct gpiod_chip_info *info)
Get the name of the chip as represented in the kernel.
int gpiod_line_settings_set_output_value(struct gpiod_line_settings *settings, enum gpiod_line_value value)
Set the output value.
int gpiod_line_request_set_values_subset(struct gpiod_line_request *request, size_t num_values, const unsigned int *offsets, const enum gpiod_line_value *values)
Set the values of a subset of requested lines.
int gpiod_chip_unwatch_line_info(struct gpiod_chip *chip, unsigned int offset)
Stop watching a line for status changes.
uint64_t gpiod_info_event_get_timestamp_ns(struct gpiod_info_event *event)
Get the timestamp of the event.
Definition: gpiod.h:345
void gpiod_line_settings_reset(struct gpiod_line_settings *settings)
Reset the line settings object to its default values.
unsigned long gpiod_line_info_get_debounce_period_us(struct gpiod_line_info *info)
Get the debounce period of the line, in microseconds.
Definition: gpiod.h:1182
struct gpiod_line_info * gpiod_line_info_copy(struct gpiod_line_info *info)
Copy a line info object.
gpiod_line_value
Logical line state.
Definition: gpiod.h:317
int gpiod_line_settings_set_bias(struct gpiod_line_settings *settings, enum gpiod_line_bias bias)
Set bias.
gpiod_line_bias
Internal bias settings.
Definition: gpiod.h:356
int gpiod_line_config_add_line_settings(struct gpiod_line_config *config, const unsigned int *offsets, size_t num_offsets, struct gpiod_line_settings *settings)
Add line settings for a set of offsets.
void gpiod_line_info_free(struct gpiod_line_info *info)
Free a line info object and release all associated resources.
unsigned long gpiod_line_settings_get_debounce_period_us(struct gpiod_line_settings *settings)
Get debounce period.
size_t gpiod_line_request_get_num_requested_lines(struct gpiod_line_request *request)
Get the number of lines in the request.
gpiod_edge_event_type
Event types.
Definition: gpiod.h:1179
Definition: gpiod.h:357
direction
Direction settings.
Definition: line.hpp:92
Definition: gpiod.h:375
int gpiod_line_request_read_edge_events(struct gpiod_line_request *request, struct gpiod_edge_event_buffer *buffer, size_t max_events)
Read a number of edge events from a line request.
const char * gpiod_line_info_get_name(struct gpiod_line_info *info)
Get the name of the line.
void gpiod_line_config_reset(struct gpiod_line_config *config)
Reset the line config object.
bias
Internal bias settings.
Definition: line.hpp:120
int gpiod_line_request_get_values_subset(struct gpiod_line_request *request, size_t num_values, const unsigned int *offsets, enum gpiod_line_value *values)
Get the values of a subset of requested lines.
Definition: gpiod.h:359
uint64_t gpiod_edge_event_get_timestamp_ns(struct gpiod_edge_event *event)
Get the timestamp of the event.
enum gpiod_edge_event_type gpiod_edge_event_get_event_type(struct gpiod_edge_event *event)
Get the event type.
Definition: gpiod.h:389
struct gpiod_line_info * gpiod_info_event_get_line_info(struct gpiod_info_event *event)
Get the snapshot of line-info associated with the event.
struct gpiod_line_info * gpiod_chip_get_line_info(struct gpiod_chip *chip, unsigned int offset)
Get a snapshot of information about a line.
unsigned long gpiod_edge_event_get_global_seqno(struct gpiod_edge_event *event)
Get the global sequence number of the event.
void gpiod_info_event_free(struct gpiod_info_event *event)
Free the info event object and release all associated resources.
bool gpiod_line_info_is_used(struct gpiod_line_info *info)
Check if the line is in use.
bool gpiod_line_info_is_active_low(struct gpiod_line_info *info)
Check if the logical value of the line is inverted compared to the physical.
int gpiod_line_request_get_fd(struct gpiod_line_request *request)
Get the file descriptor associated with a line request.
int gpiod_line_request_set_values(struct gpiod_line_request *request, const enum gpiod_line_value *values)
Set the values of all lines associated with a request.
void gpiod_request_config_free(struct gpiod_request_config *config)
Free the request config object and release all associated resources.
unsigned int gpiod_edge_event_get_line_offset(struct gpiod_edge_event *event)
Get the offset of the line which triggered the event.
enum gpiod_info_event_type gpiod_info_event_get_event_type(struct gpiod_info_event *event)
Get the event type of the status change event.
Definition: gpiod.h:68
size_t gpiod_edge_event_buffer_get_num_events(struct gpiod_edge_event_buffer *buffer)
Get the number of events a buffer has stored.
struct gpiod_line_info * gpiod_chip_watch_line_info(struct gpiod_chip *chip, unsigned int offset)
Get a snapshot of the status of a line and start watching it for future changes.
gpiod_line_direction
Direction settings.
Definition: gpiod.h:329
Definition: gpiod.h:343
void gpiod_chip_info_free(struct gpiod_chip_info *info)
Free a chip info object and release all associated resources.
::std::vector< offset > offsets
Vector of line offsets.
Definition: line.hpp:163
struct gpiod_edge_event * gpiod_edge_event_copy(struct gpiod_edge_event *event)
Copy the edge event object.
struct gpiod_line_settings * gpiod_line_settings_new(void)
Create a new line settings object.
gpiod_line_clock
Clock settings.
Definition: gpiod.h:384
int gpiod_line_request_reconfigure_lines(struct gpiod_line_request *request, struct gpiod_line_config *config)
Update the configuration of lines associated with a line request.
const char * gpiod_chip_get_path(struct gpiod_chip *chip)
Get the path used to open the chip.
int gpiod_chip_get_line_offset_from_name(struct gpiod_chip *chip, const char *name)
Map a line's name to its offset within the chip.
Definition: gpiod.h:373
enum gpiod_line_value gpiod_line_settings_get_output_value(struct gpiod_line_settings *settings)
Get the output value.
void gpiod_line_config_free(struct gpiod_line_config *config)
Free the line config object and release all associated resources.
bool gpiod_is_gpiochip_device(const char *path)
Check if the file pointed to by path is a GPIO chip character device.
drive
Drive settings.
Definition: line.hpp:137
Definition: gpiod.h:100
int gpiod_chip_wait_info_event(struct gpiod_chip *chip, int64_t timeout_ns)
Wait for line status change events on any of the watched lines on the chip.
bool gpiod_line_settings_get_active_low(struct gpiod_line_settings *settings)
Get active-low setting.
unsigned int gpiod_line_info_get_offset(struct gpiod_line_info *info)
Get the offset of the line.
size_t gpiod_chip_info_get_num_lines(struct gpiod_chip_info *info)
Get the number of lines exposed by the chip.
struct gpiod_edge_event_buffer * gpiod_edge_event_buffer_new(size_t capacity)
Create a new edge event buffer.
Definition: gpiod.h:47
void gpiod_line_settings_free(struct gpiod_line_settings *settings)
Free the line settings object and release all associated resources.
Definition: gpiod.h:1180
Definition: gpiod.h:330
enum gpiod_line_drive gpiod_line_settings_get_drive(struct gpiod_line_settings *settings)
Get drive.
Definition: gpiod.h:377
size_t gpiod_line_request_get_requested_offsets(struct gpiod_line_request *request, unsigned int *offsets, size_t max_offsets)
Get the offsets of the lines in the request.
Definition: gpiod.h:110
int gpiod_line_request_set_value(struct gpiod_line_request *request, unsigned int offset, enum gpiod_line_value value)
Set the value of a single requested line.
Definition: gpiod.h:365
enum gpiod_line_edge gpiod_line_settings_get_edge_detection(struct gpiod_line_settings *settings)
Get edge detection.