libgpiod  1.6.2
Functions
GPIO chip operations

Functions and data structures dealing with GPIO chips. More...

Functions

struct gpiod_chip * gpiod_chip_open (const char *path) GPIOD_API
 Open a gpiochip by path. More...
 
struct gpiod_chip * gpiod_chip_open_by_name (const char *name) GPIOD_API
 Open a gpiochip by name. More...
 
struct gpiod_chip * gpiod_chip_open_by_number (unsigned int num) GPIOD_API
 Open a gpiochip by number. More...
 
struct gpiod_chip * gpiod_chip_open_by_label (const char *label) GPIOD_API
 Open a gpiochip by label. More...
 
struct gpiod_chip * gpiod_chip_open_lookup (const char *descr) GPIOD_API
 Open a gpiochip based on the best guess what the path is. More...
 
void gpiod_chip_close (struct gpiod_chip *chip) GPIOD_API
 Close a GPIO chip handle and release all allocated resources. More...
 
const char * gpiod_chip_name (struct gpiod_chip *chip) GPIOD_API
 Get the GPIO chip name as represented in the kernel. More...
 
const char * gpiod_chip_label (struct gpiod_chip *chip) GPIOD_API
 Get the GPIO chip label as represented in the kernel. More...
 
unsigned int gpiod_chip_num_lines (struct gpiod_chip *chip) GPIOD_API
 Get the number of GPIO lines exposed by this chip. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 

Detailed Description

Functions and data structures dealing with GPIO chips.

Function Documentation

◆ gpiod_chip_close()

void gpiod_chip_close ( struct gpiod_chip *  chip)

Close a GPIO chip handle and release all allocated resources.

Parameters
chipThe GPIO chip object.

◆ gpiod_chip_find_line()

struct gpiod_line* gpiod_chip_find_line ( struct gpiod_chip *  chip,
const char *  name 
)

Find a GPIO line by name among lines associated with given GPIO chip.

Parameters
chipThe GPIO chip object.
nameThe name of the GPIO line.
Returns
Pointer to the GPIO line handle or NULL if the line could not be found or an error occurred.
Note
In case a line with given name is not associated with given chip, the function sets errno to ENOENT.
Attention
GPIO line names are not unique in the linux kernel, neither globally nor within a single chip. This function finds the first line with given name.

◆ gpiod_chip_find_lines()

int gpiod_chip_find_lines ( struct gpiod_chip *  chip,
const char **  names,
struct gpiod_line_bulk bulk 
)

Find a set of GPIO lines by names among lines exposed by this chip.

Parameters
chipThe GPIO chip object.
namesArray of pointers to C-strings containing the names of the lines to lookup. Must end with a NULL-pointer.
bulkLine bulk object in which the located lines will be stored.
Returns
0 if all lines were located, -1 on error.
Note
If at least one line from the list could not be found among the lines exposed by this chip, the function sets errno to ENOENT.
Attention
GPIO line names are not unique in the linux kernel, neither globally nor within a single chip. This function finds the first line with given name.

◆ gpiod_chip_get_all_lines()

int gpiod_chip_get_all_lines ( struct gpiod_chip *  chip,
struct gpiod_line_bulk bulk 
)

Retrieve all lines exposed by a chip and store them in a bulk object.

Parameters
chipThe GPIO chip object.
bulkLine bulk object in which to store the line handles.
Returns
0 on success, -1 on error.

◆ gpiod_chip_get_line()

struct gpiod_line* gpiod_chip_get_line ( struct gpiod_chip *  chip,
unsigned int  offset 
)

Get the handle to the GPIO line at given offset.

Parameters
chipThe GPIO chip object.
offsetThe offset of the GPIO line.
Returns
Pointer to the GPIO line handle or NULL if an error occured.

◆ 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 
)

Retrieve a set of lines and store them in a line bulk object.

Parameters
chipThe GPIO chip object.
offsetsArray of offsets of lines to retrieve.
num_offsetsNumber of lines to retrieve.
bulkLine bulk object in which to store the line handles.
Returns
0 on success, -1 on error.

◆ gpiod_chip_label()

const char* gpiod_chip_label ( struct gpiod_chip *  chip)

Get the GPIO chip label as represented in the kernel.

Parameters
chipThe GPIO chip object.
Returns
Pointer to a human-readable string containing the chip label.

◆ gpiod_chip_name()

const char* gpiod_chip_name ( struct gpiod_chip *  chip)

Get the GPIO chip name as represented in the kernel.

Parameters
chipThe GPIO chip object.
Returns
Pointer to a human-readable string containing the chip name.

◆ gpiod_chip_num_lines()

unsigned int gpiod_chip_num_lines ( struct gpiod_chip *  chip)

Get the number of GPIO lines exposed by this chip.

Parameters
chipThe GPIO chip object.
Returns
Number of GPIO lines.

◆ gpiod_chip_open()

struct gpiod_chip* gpiod_chip_open ( const char *  path)

Open a gpiochip by path.

Parameters
pathPath to the gpiochip device file.
Returns
GPIO chip handle or NULL if an error occurred.

◆ gpiod_chip_open_by_label()

struct gpiod_chip* gpiod_chip_open_by_label ( const char *  label)

Open a gpiochip by label.

Parameters
labelLabel of the gpiochip to open.
Returns
GPIO chip handle or NULL if the chip with given label was not found or an error occured.
Note
If the chip cannot be found but no other error occurred, errno is set to ENOENT.

◆ gpiod_chip_open_by_name()

struct gpiod_chip* gpiod_chip_open_by_name ( const char *  name)

Open a gpiochip by name.

Parameters
nameName of the gpiochip to open.
Returns
GPIO chip handle or NULL if an error occurred.

This routine appends name to '/dev/' to create the path.

◆ gpiod_chip_open_by_number()

struct gpiod_chip* gpiod_chip_open_by_number ( unsigned int  num)

Open a gpiochip by number.

Parameters
numNumber of the gpiochip.
Returns
GPIO chip handle or NULL if an error occurred.

This routine appends num to '/dev/gpiochip' to create the path.

◆ gpiod_chip_open_lookup()

struct gpiod_chip* gpiod_chip_open_lookup ( const char *  descr)

Open a gpiochip based on the best guess what the path is.

Parameters
descrString describing the gpiochip.
Returns
GPIO chip handle or NULL if an error occurred.

This routine tries to figure out whether the user passed it the path to the GPIO chip, its name, label or number as a string. Then it tries to open it using one of the gpiod_chip_open** variants.