libgpiod  2.0.1
Functions
GPIO chips

Functions and data structures for GPIO chip operations. More...

Functions

struct gpiod_chipgpiod_chip_open (const char *path)
 Open a chip by path. More...
 
void gpiod_chip_close (struct gpiod_chip *chip)
 Close the chip and release all associated resources. More...
 
struct gpiod_chip_infogpiod_chip_get_info (struct gpiod_chip *chip)
 Get information about the chip. More...
 
const char * gpiod_chip_get_path (struct gpiod_chip *chip)
 Get the path used to open the chip. More...
 
struct gpiod_line_infogpiod_chip_get_line_info (struct gpiod_chip *chip, unsigned int offset)
 Get a snapshot of information about a line. More...
 
struct gpiod_line_infogpiod_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. More...
 
int gpiod_chip_unwatch_line_info (struct gpiod_chip *chip, unsigned int offset)
 Stop watching a line for status changes. More...
 
int gpiod_chip_get_fd (struct gpiod_chip *chip)
 Get the file descriptor associated with the chip. More...
 
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. More...
 
struct gpiod_info_eventgpiod_chip_read_info_event (struct gpiod_chip *chip)
 Read a single line status change event from the chip. More...
 
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. More...
 
struct gpiod_line_requestgpiod_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. More...
 

Detailed Description

Functions and data structures for GPIO chip operations.

A GPIO chip object is associated with an open file descriptor to the GPIO character device. It exposes basic information about the chip and allows callers to retrieve information about each line, watch lines for state changes and make line requests.

Function Documentation

◆ gpiod_chip_close()

void gpiod_chip_close ( struct gpiod_chip chip)

Close the chip and release all associated resources.

Parameters
chipChip to close.

◆ gpiod_chip_get_fd()

int gpiod_chip_get_fd ( struct gpiod_chip chip)

Get the file descriptor associated with the chip.

Parameters
chipGPIO chip object.
Returns
File descriptor number for the chip.

This function never fails. The returned file descriptor must not be closed by the caller. Call gpiod_chip_close to close the file descriptor by closing the chip owning it.

◆ gpiod_chip_get_info()

struct gpiod_chip_info* gpiod_chip_get_info ( struct gpiod_chip chip)

Get information about the chip.

Parameters
chipGPIO chip object.
Returns
New GPIO chip info object or NULL if an error occurred. The returned object must be freed by the caller using gpiod_chip_info_free.

◆ gpiod_chip_get_line_info()

struct gpiod_line_info* gpiod_chip_get_line_info ( struct gpiod_chip chip,
unsigned int  offset 
)

Get a snapshot of information about a line.

Parameters
chipGPIO chip object.
offsetThe offset of the GPIO line.
Returns
New GPIO line info object or NULL if an error occurred. The returned object must be freed by the caller using gpiod_line_info_free.

◆ gpiod_chip_get_line_offset_from_name()

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.

Parameters
chipGPIO chip object.
nameName of the GPIO line to map.
Returns
Offset of the line within the chip or -1 on error.
Note
If a line with given name is not exposed by the chip, the function sets errno to ENOENT.

◆ gpiod_chip_get_path()

const char* gpiod_chip_get_path ( struct gpiod_chip chip)

Get the path used to open the chip.

Parameters
chipGPIO chip object.
Returns
Path to the file passed as argument to gpiod_chip_open. The returned pointer is valid for the lifetime of the chip object and must not be freed by the caller.

◆ gpiod_chip_open()

struct gpiod_chip* gpiod_chip_open ( const char *  path)

Open a chip by path.

Parameters
pathPath to the gpiochip device file.
Returns
GPIO chip object or NULL if an error occurred. The returned object must be closed by the caller using gpiod_chip_close.

◆ gpiod_chip_read_info_event()

struct gpiod_info_event* gpiod_chip_read_info_event ( struct gpiod_chip chip)

Read a single line status change event from the chip.

Parameters
chipGPIO chip object.
Returns
Newly read watch event object or NULL on error. The event must be freed by the caller using gpiod_info_event_free.
Note
If no events are pending, this function will block.

◆ gpiod_chip_request_lines()

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.

Parameters
chipGPIO chip object.
req_cfgRequest config object. Can be NULL for default settings.
line_cfgLine config object.
Returns
New line request object or NULL if an error occurred. The request must be released by the caller using gpiod_line_request_release.

◆ gpiod_chip_unwatch_line_info()

int gpiod_chip_unwatch_line_info ( struct gpiod_chip chip,
unsigned int  offset 
)

Stop watching a line for status changes.

Parameters
chipGPIO chip object.
offsetThe offset of the line to stop watching.
Returns
0 on success, -1 on failure.

◆ gpiod_chip_wait_info_event()

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.

Parameters
chipGPIO chip object.
timeout_nsWait time limit in nanoseconds. If set to 0, the function returns immediatelly. If set to a negative number, the function blocks indefinitely until an event becomes available.
Returns
0 if wait timed out, -1 if an error occurred, 1 if an event is pending.

◆ gpiod_chip_watch_line_info()

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.

Parameters
chipGPIO chip object.
offsetThe offset of the GPIO line.
Returns
New GPIO line info object or NULL if an error occurred. The returned object must be freed by the caller using gpiod_line_info_free.
Note
Line status does not include the line value. To monitor the line value the line must be requested as an input with edge detection set.