libgpiod 2.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
16extern "C" {
17#endif
18
63struct gpiod_chip;
64
73struct gpiod_chip_info;
74
83struct gpiod_line_info;
84
95
104struct gpiod_line_config;
105
116
126struct gpiod_line_request;
127
136struct gpiod_info_event;
137
146struct gpiod_edge_event;
147
158
177struct gpiod_chip *gpiod_chip_open(const char *path);
178
183void gpiod_chip_close(struct gpiod_chip *chip);
184
192
200const char *gpiod_chip_get_path(struct gpiod_chip *chip);
201
210 unsigned int offset);
211
223 unsigned int offset);
224
231int gpiod_chip_unwatch_line_info(struct gpiod_chip *chip, unsigned int offset);
232
243
255int gpiod_chip_wait_info_event(struct gpiod_chip *chip, int64_t timeout_ns);
256
265
275 const char *name);
276
285struct gpiod_line_request *
287 struct gpiod_request_config *req_cfg,
288 struct gpiod_line_config *line_cfg);
289
315
324
333
340
361
374
388
404
416
428
456
464
474
484
496
507
516
525
534
543
551
559
566unsigned long
568
578
605
611
621
628
642struct gpiod_line_info *
644
668
674
680
687struct gpiod_line_settings *
689
697 enum gpiod_line_direction direction);
698
706
714 enum gpiod_line_edge edge);
715
723
731 enum gpiod_line_bias bias);
732
740
748 enum gpiod_line_drive drive);
749
757
764 bool active_low);
765
772
778void
780 unsigned long period);
781
787unsigned long
789 struct gpiod_line_settings *settings);
790
798 enum gpiod_line_clock event_clock);
799
807
815 enum gpiod_line_value value);
816
824
854
860
869
879 const unsigned int *offsets,
880 size_t num_offsets,
881 struct gpiod_line_settings *settings);
882
890struct gpiod_line_settings *
892 unsigned int offset);
893
916 const enum gpiod_line_value *values,
917 size_t num_values);
918
924size_t
926
938size_t
940 unsigned int *offsets,
941 size_t max_offsets);
942
963
969
978 const char *consumer);
979
985const char *
987
997void
999 size_t event_buffer_size);
1000
1006size_t
1008
1023
1030const char *
1032
1038size_t
1040
1052size_t
1054 unsigned int *offsets,
1055 size_t max_offsets);
1056
1065 unsigned int offset);
1066
1079 size_t num_values,
1080 const unsigned int *offsets,
1081 enum gpiod_line_value *values);
1082
1095 enum gpiod_line_value *values);
1096
1105 unsigned int offset,
1106 enum gpiod_line_value value);
1107
1121 size_t num_values,
1122 const unsigned int *offsets,
1123 const enum gpiod_line_value *values);
1124
1137 const enum gpiod_line_value *values);
1138
1151 struct gpiod_line_config *config);
1152
1162
1177 int64_t timeout_ns);
1178
1191 struct gpiod_edge_event_buffer *buffer,
1192 size_t max_events);
1193
1221
1227
1235
1244
1253
1260
1268
1276
1291
1298size_t
1300
1306
1321struct gpiod_edge_event *
1323 unsigned long index);
1324
1330size_t
1332
1348bool gpiod_is_gpiochip_device(const char *path);
1349
1356const char *gpiod_api_version(void);
1357
1362#ifdef __cplusplus
1363} /* extern "C" */
1364#endif
1365
1366#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.
const char * gpiod_chip_info_get_name(struct gpiod_chip_info *info)
Get the name of the chip as represented in the kernel.
size_t gpiod_chip_info_get_num_lines(struct gpiod_chip_info *info)
Get the number of lines exposed by 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.
struct gpiod_chip_info * gpiod_chip_get_info(struct gpiod_chip *chip)
Get information about the chip.
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.
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.
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_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_unwatch_line_info(struct gpiod_chip *chip, unsigned int offset)
Stop watching a line for status changes.
struct gpiod_chip * gpiod_chip_open(const char *path)
Open a chip by path.
const char * gpiod_chip_get_path(struct gpiod_chip *chip)
Get the path used to open the chip.
struct gpiod_edge_event_buffer * gpiod_edge_event_buffer_new(size_t capacity)
Create a new edge event buffer.
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 * gpiod_edge_event_copy(struct gpiod_edge_event *event)
Copy the edge event object.
uint64_t gpiod_edge_event_get_timestamp_ns(struct gpiod_edge_event *event)
Get the timestamp of the event.
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.
gpiod_edge_event_type
Event types.
Definition gpiod.h:1215
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:1218
@ GPIOD_EDGE_EVENT_RISING_EDGE
Rising edge event.
Definition gpiod.h:1216
size_t gpiod_line_config_get_num_configured_offsets(struct gpiod_line_config *config)
Get the number of configured line offsets.
struct gpiod_line_settings * gpiod_line_config_get_line_settings(struct gpiod_line_config *config, unsigned int offset)
Get line settings for offset.
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_config * gpiod_line_config_new(void)
Create a new line config object.
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:420
gpiod_line_bias
Internal bias settings.
Definition gpiod.h:392
gpiod_line_edge
Edge detection settings.
Definition gpiod.h:378
gpiod_line_direction
Direction settings.
Definition gpiod.h:365
gpiod_line_value
Logical line state.
Definition gpiod.h:353
gpiod_line_drive
Drive settings.
Definition gpiod.h:408
@ GPIOD_LINE_CLOCK_REALTIME
Line uses the realtime clock for edge event timestamps.
Definition gpiod.h:423
@ GPIOD_LINE_CLOCK_HTE
Line uses the hardware timestamp engine for event timestamps.
Definition gpiod.h:425
@ GPIOD_LINE_CLOCK_MONOTONIC
Line uses the monotonic clock for edge event timestamps.
Definition gpiod.h:421
@ GPIOD_LINE_BIAS_AS_IS
Don't change the bias setting when applying line config.
Definition gpiod.h:393
@ GPIOD_LINE_BIAS_UNKNOWN
The internal bias state is unknown.
Definition gpiod.h:395
@ GPIOD_LINE_BIAS_PULL_UP
The internal pull-up bias is enabled.
Definition gpiod.h:399
@ GPIOD_LINE_BIAS_PULL_DOWN
The internal pull-down bias is enabled.
Definition gpiod.h:401
@ GPIOD_LINE_BIAS_DISABLED
The internal bias is disabled.
Definition gpiod.h:397
@ GPIOD_LINE_EDGE_NONE
Line edge detection is disabled.
Definition gpiod.h:379
@ GPIOD_LINE_EDGE_FALLING
Line detects falling edge events.
Definition gpiod.h:383
@ GPIOD_LINE_EDGE_RISING
Line detects rising edge events.
Definition gpiod.h:381
@ GPIOD_LINE_EDGE_BOTH
Line detects both rising and falling edge events.
Definition gpiod.h:385
@ GPIOD_LINE_DIRECTION_AS_IS
Request the line(s), but don't change direction.
Definition gpiod.h:366
@ GPIOD_LINE_DIRECTION_INPUT
Direction is input - for reading the value of an externally driven GPIO line.
Definition gpiod.h:368
@ GPIOD_LINE_DIRECTION_OUTPUT
Direction is output - for driving the GPIO line.
Definition gpiod.h:371
@ GPIOD_LINE_VALUE_INACTIVE
Line is logically inactive.
Definition gpiod.h:356
@ GPIOD_LINE_VALUE_ACTIVE
Line is logically active.
Definition gpiod.h:358
@ GPIOD_LINE_VALUE_ERROR
Returned to indicate an error when reading the value.
Definition gpiod.h:354
@ GPIOD_LINE_DRIVE_OPEN_SOURCE
Line output is open-source.
Definition gpiod.h:413
@ GPIOD_LINE_DRIVE_PUSH_PULL
Drive setting is push-pull.
Definition gpiod.h:409
@ GPIOD_LINE_DRIVE_OPEN_DRAIN
Line output is open-drain.
Definition gpiod.h:411
struct gpiod_line_info * gpiod_line_info_copy(struct gpiod_line_info *info)
Copy a line info object.
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_name(struct gpiod_line_info *info)
Get the name of the line.
const char * gpiod_line_info_get_consumer(struct gpiod_line_info *info)
Get the name of the consumer of the line.
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.
const char * gpiod_line_request_get_chip_name(struct gpiod_line_request *request)
Get the name of the chip this request was made on.
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.
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.
struct gpiod_line_settings * gpiod_line_settings_copy(struct gpiod_line_settings *settings)
Copy the line settings object.
enum gpiod_line_edge gpiod_line_settings_get_edge_detection(struct gpiod_line_settings *settings)
Get edge detection.
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.
struct gpiod_line_settings * gpiod_line_settings_new(void)
Create a new line settings object.
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:597
@ GPIOD_INFO_EVENT_LINE_RELEASED
Previously requested line has been released.
Definition gpiod.h:600
@ GPIOD_INFO_EVENT_LINE_CONFIG_CHANGED
Line configuration has changed.
Definition gpiod.h:602
@ GPIOD_INFO_EVENT_LINE_REQUESTED
Line has been requested.
Definition gpiod.h:598
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.
struct gpiod_request_config * gpiod_request_config_new(void)
Create a new request config object.
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.
const char * gpiod_request_config_get_consumer(struct gpiod_request_config *config)
Get the consumer name configured in the request config.
Refer to Chip info for functions that operate on gpiod_chip_info.
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.
Refer to Line edge events handling for functions that operate on gpiod_edge_event.
Refer to Line status watch events for functions that operate on gpiod_info_event.
Refer to Line configuration objects for functions that operate on gpiod_line_config.
Refer to Line info for functions that operate on gpiod_line_info.
Refer to Line request operations for functions that operate on gpiod_line_request.
Refer to Line settings objects for functions that operate on gpiod_line_settings.
Refer to Request configuration objects for functions that operate on gpiod_request_config.