libgpiod  2.0.1
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 
55 struct gpiod_chip;
56 
65 struct gpiod_chip_info;
66 
75 struct gpiod_line_info;
76 
86 struct gpiod_line_settings;
87 
96 struct gpiod_line_config;
97 
107 struct gpiod_request_config;
108 
118 struct gpiod_line_request;
119 
128 struct gpiod_info_event;
129 
138 struct gpiod_edge_event;
139 
150 
169 struct gpiod_chip *gpiod_chip_open(const char *path);
170 
175 void gpiod_chip_close(struct gpiod_chip *chip);
176 
184 
192 const char *gpiod_chip_get_path(struct gpiod_chip *chip);
193 
202  unsigned int offset);
203 
215  unsigned int offset);
216 
223 int gpiod_chip_unwatch_line_info(struct gpiod_chip *chip, unsigned int offset);
224 
234 int gpiod_chip_get_fd(struct gpiod_chip *chip);
235 
247 int gpiod_chip_wait_info_event(struct gpiod_chip *chip, int64_t timeout_ns);
248 
257 
267  const char *name);
268 
277 struct gpiod_line_request *
279  struct gpiod_request_config *req_cfg,
280  struct gpiod_line_config *line_cfg);
281 
307 
315 const char *gpiod_chip_info_get_name(struct gpiod_chip_info *info);
316 
324 const char *gpiod_chip_info_get_label(struct gpiod_chip_info *info);
325 
332 
352 };
353 
365 };
366 
379 };
380 
395 };
396 
407 };
408 
419 };
420 
448 
456 
465 unsigned int gpiod_line_info_get_offset(struct gpiod_line_info *info);
466 
475 const char *gpiod_line_info_get_name(struct gpiod_line_info *info);
476 
488 
499 
508 
515 enum gpiod_line_edge
517 
524 enum gpiod_line_bias
526 
533 enum gpiod_line_drive
535 
543 
551 
558 unsigned long
560 
568 enum gpiod_line_clock
570 
596 };
597 
603 
613 
620 
628 struct gpiod_line_info *
630 
654 
660 
666 
673 struct gpiod_line_settings *
675 
684 
692 
700  enum gpiod_line_edge edge);
701 
707 enum gpiod_line_edge
709 
717  enum gpiod_line_bias bias);
718 
724 enum gpiod_line_bias
726 
734  enum gpiod_line_drive drive);
735 
741 enum gpiod_line_drive
743 
750  bool active_low);
751 
758 
764 void
766  unsigned long period);
767 
773 unsigned long
775  struct gpiod_line_settings *settings);
776 
784  enum gpiod_line_clock event_clock);
785 
791 enum gpiod_line_clock
793 
801  enum gpiod_line_value value);
802 
808 enum gpiod_line_value
810 
840 
846 
855 
865  const unsigned int *offsets,
866  size_t num_offsets,
867  struct gpiod_line_settings *settings);
868 
876 struct gpiod_line_settings *
878  unsigned int offset);
879 
902  const enum gpiod_line_value *values,
903  size_t num_values);
904 
910 size_t
912 
924 size_t
926  unsigned int *offsets,
927  size_t max_offsets);
928 
949 
955 
964  const char *consumer);
965 
971 const char *
973 
983 void
985  size_t event_buffer_size);
986 
992 size_t
994 
1009 
1015 size_t
1017 
1029 size_t
1031  unsigned int *offsets,
1032  size_t max_offsets);
1033 
1040 enum gpiod_line_value
1042  unsigned int offset);
1043 
1056  size_t num_values,
1057  const unsigned int *offsets,
1058  enum gpiod_line_value *values);
1059 
1072  enum gpiod_line_value *values);
1073 
1081  unsigned int offset,
1082  enum gpiod_line_value value);
1083 
1097  size_t num_values,
1098  const unsigned int *offsets,
1099  const enum gpiod_line_value *values);
1100 
1112  const enum gpiod_line_value *values);
1113 
1126  struct gpiod_line_config *config);
1127 
1137 
1152  int64_t timeout_ns);
1153 
1166  struct gpiod_edge_event_buffer *buffer,
1167  size_t max_events);
1168 
1195 };
1196 
1202 
1210 
1219 
1228 
1235 
1243 
1251 
1264 struct gpiod_edge_event_buffer *
1266 
1273 size_t
1275 
1281 
1290 struct gpiod_edge_event *
1292  unsigned long index);
1293 
1299 size_t
1301 
1317 bool gpiod_is_gpiochip_device(const char *path);
1318 
1325 const char *gpiod_api_version(void);
1326 
1331 #ifdef __cplusplus
1332 } /* extern "C" */
1333 #endif
1334 
1335 #endif /* __LIBGPIOD_GPIOD_H__ */
const char * gpiod_chip_info_get_label(struct gpiod_chip_info *info)
Get the label of the chip as represented in the kernel.
void gpiod_chip_info_free(struct gpiod_chip_info *info)
Free a chip info object and release all associated resources.
size_t gpiod_chip_info_get_num_lines(struct gpiod_chip_info *info)
Get the number of lines exposed by the chip.
const char * gpiod_chip_info_get_name(struct gpiod_chip_info *info)
Get the name of the chip as represented in the kernel.
struct gpiod_chip * gpiod_chip_open(const char *path)
Open a chip by path.
struct gpiod_line_info * gpiod_chip_get_line_info(struct gpiod_chip *chip, unsigned int offset)
Get a snapshot of information about a line.
struct gpiod_info_event * gpiod_chip_read_info_event(struct gpiod_chip *chip)
Read a single line status change event from the chip.
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.
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.
int gpiod_chip_get_fd(struct gpiod_chip *chip)
Get the file descriptor associated with 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.
void gpiod_chip_close(struct gpiod_chip *chip)
Close the chip and release all associated resources.
const char * gpiod_chip_get_path(struct gpiod_chip *chip)
Get the path used to open the chip.
struct gpiod_chip_info * gpiod_chip_get_info(struct gpiod_chip *chip)
Get information about the chip.
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.
int gpiod_chip_unwatch_line_info(struct gpiod_chip *chip, unsigned int offset)
Stop watching a line for status changes.
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_edge_event * gpiod_edge_event_copy(struct gpiod_edge_event *event)
Copy the edge event object.
unsigned int gpiod_edge_event_get_line_offset(struct gpiod_edge_event *event)
Get the offset of the line which triggered the event.
struct gpiod_edge_event_buffer * gpiod_edge_event_buffer_new(size_t capacity)
Create a new edge event buffer.
uint64_t gpiod_edge_event_get_timestamp_ns(struct gpiod_edge_event *event)
Get the timestamp of the event.
gpiod_edge_event_type
Event types.
Definition: gpiod.h:1190
unsigned long gpiod_edge_event_get_line_seqno(struct gpiod_edge_event *event)
Get the event sequence number specific to the line.
void gpiod_edge_event_buffer_free(struct gpiod_edge_event_buffer *buffer)
Free the edge event buffer and release all associated resources.
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.
unsigned long gpiod_edge_event_get_global_seqno(struct gpiod_edge_event *event)
Get the global sequence number of the event.
size_t gpiod_edge_event_buffer_get_num_events(struct gpiod_edge_event_buffer *buffer)
Get the number of events a buffer has stored.
enum gpiod_edge_event_type gpiod_edge_event_get_event_type(struct gpiod_edge_event *event)
Get the event type.
void gpiod_edge_event_free(struct gpiod_edge_event *event)
Free the edge event object.
@ GPIOD_EDGE_EVENT_FALLING_EDGE
Falling edge event.
Definition: gpiod.h:1193
@ GPIOD_EDGE_EVENT_RISING_EDGE
Rising edge event.
Definition: gpiod.h:1191
struct gpiod_line_config * gpiod_line_config_new(void)
Create a new line config object.
size_t gpiod_line_config_get_num_configured_offsets(struct gpiod_line_config *config)
Get the number of configured line offsets.
size_t gpiod_line_config_get_configured_offsets(struct gpiod_line_config *config, unsigned int *offsets, size_t max_offsets)
Get configured offsets.
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.
struct gpiod_line_settings * gpiod_line_config_get_line_settings(struct gpiod_line_config *config, unsigned int offset)
Get line settings for offset.
void gpiod_line_config_free(struct gpiod_line_config *config)
Free the line config object and release all associated resources.
void gpiod_line_config_reset(struct gpiod_line_config *config)
Reset the line config object.
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.
gpiod_line_clock
Clock settings.
Definition: gpiod.h:412
gpiod_line_bias
Internal bias settings.
Definition: gpiod.h:384
gpiod_line_edge
Edge detection settings.
Definition: gpiod.h:370
gpiod_line_direction
Direction settings.
Definition: gpiod.h:357
gpiod_line_value
Logical line state.
Definition: gpiod.h:345
gpiod_line_drive
Drive settings.
Definition: gpiod.h:400
@ GPIOD_LINE_CLOCK_REALTIME
Line uses the realtime clock for edge event timestamps.
Definition: gpiod.h:415
@ GPIOD_LINE_CLOCK_HTE
Line uses the hardware timestamp engine for event timestamps.
Definition: gpiod.h:417
@ GPIOD_LINE_CLOCK_MONOTONIC
Line uses the monotonic clock for edge event timestamps.
Definition: gpiod.h:413
@ GPIOD_LINE_BIAS_AS_IS
Don't change the bias setting when applying line config.
Definition: gpiod.h:385
@ GPIOD_LINE_BIAS_UNKNOWN
The internal bias state is unknown.
Definition: gpiod.h:387
@ GPIOD_LINE_BIAS_PULL_UP
The internal pull-up bias is enabled.
Definition: gpiod.h:391
@ GPIOD_LINE_BIAS_PULL_DOWN
The internal pull-down bias is enabled.
Definition: gpiod.h:393
@ GPIOD_LINE_BIAS_DISABLED
The internal bias is disabled.
Definition: gpiod.h:389
@ GPIOD_LINE_EDGE_NONE
Line edge detection is disabled.
Definition: gpiod.h:371
@ GPIOD_LINE_EDGE_FALLING
Line detects falling edge events.
Definition: gpiod.h:375
@ GPIOD_LINE_EDGE_RISING
Line detects rising edge events.
Definition: gpiod.h:373
@ GPIOD_LINE_EDGE_BOTH
Line detects both rising and falling edge events.
Definition: gpiod.h:377
@ GPIOD_LINE_DIRECTION_AS_IS
Request the line(s), but don't change direction.
Definition: gpiod.h:358
@ GPIOD_LINE_DIRECTION_INPUT
Direction is input - for reading the value of an externally driven GPIO line.
Definition: gpiod.h:360
@ GPIOD_LINE_DIRECTION_OUTPUT
Direction is output - for driving the GPIO line.
Definition: gpiod.h:363
@ GPIOD_LINE_VALUE_INACTIVE
Line is logically inactive.
Definition: gpiod.h:348
@ GPIOD_LINE_VALUE_ACTIVE
Line is logically active.
Definition: gpiod.h:350
@ GPIOD_LINE_VALUE_ERROR
Returned to indicate an error when reading the value.
Definition: gpiod.h:346
@ GPIOD_LINE_DRIVE_OPEN_SOURCE
Line output is open-source.
Definition: gpiod.h:405
@ GPIOD_LINE_DRIVE_PUSH_PULL
Drive setting is push-pull.
Definition: gpiod.h:401
@ GPIOD_LINE_DRIVE_OPEN_DRAIN
Line output is open-drain.
Definition: gpiod.h:403
void gpiod_line_info_free(struct gpiod_line_info *info)
Free a line info object and release all associated resources.
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.
unsigned int gpiod_line_info_get_offset(struct gpiod_line_info *info)
Get the offset of the line.
enum gpiod_line_direction gpiod_line_info_get_direction(struct gpiod_line_info *info)
Get the direction setting of the line.
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_line_info_get_consumer(struct gpiod_line_info *info)
Get the name of the consumer of the line.
const char * gpiod_line_info_get_name(struct gpiod_line_info *info)
Get the name of the line.
struct gpiod_line_info * gpiod_line_info_copy(struct gpiod_line_info *info)
Copy a line info object.
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.
bool gpiod_line_info_is_used(struct gpiod_line_info *info)
Check if the line is in use.
enum gpiod_line_edge gpiod_line_info_get_edge_detection(struct gpiod_line_info *info)
Get the edge detection setting of the line.
unsigned long gpiod_line_info_get_debounce_period_us(struct gpiod_line_info *info)
Get the debounce period of the line, in microseconds.
enum gpiod_line_bias gpiod_line_info_get_bias(struct gpiod_line_info *info)
Get the bias setting of the line.
enum gpiod_line_drive gpiod_line_info_get_drive(struct gpiod_line_info *info)
Get the drive setting of the line.
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.
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.
int gpiod_line_request_get_values(struct gpiod_line_request *request, enum gpiod_line_value *values)
Get the values of all requested lines.
size_t gpiod_line_request_get_num_requested_lines(struct gpiod_line_request *request)
Get the number of lines in the request.
void gpiod_line_request_release(struct gpiod_line_request *request)
Release the requested lines and free all associated resources.
int gpiod_line_request_get_fd(struct gpiod_line_request *request)
Get the file descriptor associated with a line request.
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.
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_line_request_wait_edge_events(struct gpiod_line_request *request, int64_t timeout_ns)
Wait for edge events on any of the requested lines.
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.
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.
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.
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.
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.
int gpiod_line_settings_set_bias(struct gpiod_line_settings *settings, enum gpiod_line_bias bias)
Set bias.
void gpiod_line_settings_reset(struct gpiod_line_settings *settings)
Reset the line settings object to its default values.
enum gpiod_line_drive gpiod_line_settings_get_drive(struct gpiod_line_settings *settings)
Get drive.
unsigned long gpiod_line_settings_get_debounce_period_us(struct gpiod_line_settings *settings)
Get debounce period.
enum gpiod_line_clock gpiod_line_settings_get_event_clock(struct gpiod_line_settings *settings)
Get event clock setting.
void gpiod_line_settings_free(struct gpiod_line_settings *settings)
Free the line settings object and release all associated resources.
int gpiod_line_settings_set_edge_detection(struct gpiod_line_settings *settings, enum gpiod_line_edge edge)
Set edge detection.
void gpiod_line_settings_set_debounce_period_us(struct gpiod_line_settings *settings, unsigned long period)
Set debounce period.
enum gpiod_line_value gpiod_line_settings_get_output_value(struct gpiod_line_settings *settings)
Get the output value.
int gpiod_line_settings_set_output_value(struct gpiod_line_settings *settings, enum gpiod_line_value value)
Set the output value.
struct gpiod_line_settings * gpiod_line_settings_copy(struct gpiod_line_settings *settings)
Copy the line settings object.
bool gpiod_line_settings_get_active_low(struct gpiod_line_settings *settings)
Get active-low setting.
void gpiod_line_settings_set_active_low(struct gpiod_line_settings *settings, bool active_low)
Set active-low setting.
enum gpiod_line_edge gpiod_line_settings_get_edge_detection(struct gpiod_line_settings *settings)
Get edge detection.
struct gpiod_line_settings * gpiod_line_settings_new(void)
Create a new line settings object.
int gpiod_line_settings_set_drive(struct gpiod_line_settings *settings, enum gpiod_line_drive drive)
Set drive.
enum gpiod_line_bias gpiod_line_settings_get_bias(struct gpiod_line_settings *settings)
Get bias.
int gpiod_line_settings_set_direction(struct gpiod_line_settings *settings, enum gpiod_line_direction direction)
Set direction.
void gpiod_info_event_free(struct gpiod_info_event *event)
Free the info event object and release all associated resources.
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.
uint64_t gpiod_info_event_get_timestamp_ns(struct gpiod_info_event *event)
Get the timestamp of the event.
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.
gpiod_info_event_type
Line status change event types.
Definition: gpiod.h:589
@ GPIOD_INFO_EVENT_LINE_RELEASED
Previously requested line has been released.
Definition: gpiod.h:592
@ GPIOD_INFO_EVENT_LINE_CONFIG_CHANGED
Line configuration has changed.
Definition: gpiod.h:594
@ GPIOD_INFO_EVENT_LINE_REQUESTED
Line has been requested.
Definition: gpiod.h:590
const char * gpiod_api_version(void)
Get the API version of the library as a human-readable string.
bool gpiod_is_gpiochip_device(const char *path)
Check if the file pointed to by path is a GPIO chip character device.
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_request_config_get_consumer(struct gpiod_request_config *config)
Get the consumer name configured in the request config.
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_request_config_free(struct gpiod_request_config *config)
Free the request config object and release all associated resources.
void gpiod_request_config_set_consumer(struct gpiod_request_config *config, const char *consumer)
Set the consumer name for the request.
struct gpiod_request_config * gpiod_request_config_new(void)
Create a new request config object.
edge
Edge detection settings.
Definition: line.hpp:111
direction
Direction settings.
Definition: line.hpp:98
::std::vector< value > values
Vector of line values.
Definition: line.hpp:173
::std::vector< offset > offsets
Vector of line offsets.
Definition: line.hpp:168
drive
Drive settings.
Definition: line.hpp:143
bias
Internal bias settings.
Definition: line.hpp:126
value
Logical line states.
Definition: line.hpp:87
Refer to Chip info for functions that operate on gpiod_chip_info.
Definition: gpiod.h:55
Refer to GPIO chips for functions that operate on gpiod_chip.
Refer to Line edge events handling for functions that operate on gpiod_edge_event_buffer.
Definition: gpiod.h:138
Refer to Line edge events handling for functions that operate on gpiod_edge_event.
Definition: gpiod.h:128
Refer to Line status watch events for functions that operate on gpiod_info_event.
Definition: gpiod.h:118
Refer to Line configuration objects for functions that operate on gpiod_line_config.
Definition: gpiod.h:86
Refer to Line info for functions that operate on gpiod_line_info.
Definition: gpiod.h:65
Refer to Line request operations for functions that operate on gpiod_line_request.
Definition: gpiod.h:107
Refer to Line settings objects for functions that operate on gpiod_line_settings.
Definition: gpiod.h:75
Refer to Request configuration objects for functions that operate on gpiod_request_config.
Definition: gpiod.h:96