libgpiod  1.6.2
Macros | Functions
Iterators for GPIO chips and lines

These functions and data structures allow easy iterating over GPIO chips and lines. More...

Macros

#define gpiod_foreach_chip(iter, chip)
 Iterate over all GPIO chips present in the system. More...
 
#define gpiod_foreach_chip_noclose(iter, chip)
 Iterate over all chips present in the system without closing them. More...
 
#define gpiod_foreach_line(iter, line)
 Iterate over all GPIO lines of a single chip. More...
 

Functions

struct gpiod_chip_iter * gpiod_chip_iter_new (void) GPIOD_API
 Create a new gpiochip iterator. More...
 
void gpiod_chip_iter_free (struct gpiod_chip_iter *iter) GPIOD_API
 Release all resources allocated for the gpiochip iterator and close the most recently opened gpiochip (if any). More...
 
void gpiod_chip_iter_free_noclose (struct gpiod_chip_iter *iter) GPIOD_API
 Release all resources allocated for the gpiochip iterator but don't close the most recently opened gpiochip (if any). More...
 
struct gpiod_chip * gpiod_chip_iter_next (struct gpiod_chip_iter *iter) GPIOD_API
 Get the next gpiochip handle. More...
 
struct gpiod_chip * gpiod_chip_iter_next_noclose (struct gpiod_chip_iter *iter) GPIOD_API
 Get the next gpiochip handle without closing the previous one. More...
 
struct gpiod_line_iter * gpiod_line_iter_new (struct gpiod_chip *chip) GPIOD_API
 Create a new line iterator. More...
 
void gpiod_line_iter_free (struct gpiod_line_iter *iter) GPIOD_API
 Free all resources associated with a GPIO line iterator. More...
 
struct gpiod_line * gpiod_line_iter_next (struct gpiod_line_iter *iter) GPIOD_API
 Get the next GPIO line handle. More...
 

Detailed Description

These functions and data structures allow easy iterating over GPIO chips and lines.

Macro Definition Documentation

◆ gpiod_foreach_chip

#define gpiod_foreach_chip (   iter,
  chip 
)
Value:
for ((chip) = gpiod_chip_iter_next(iter); \
(chip); \
(chip) = gpiod_chip_iter_next(iter))

Iterate over all GPIO chips present in the system.

Parameters
iterAn initialized GPIO chip iterator.
chipPointer to a GPIO chip handle. On each iteration the newly opened chip handle is assigned to this argument.

The user must not close the GPIO chip manually - instead the previous chip handle is closed automatically on the next iteration. The last chip to be opened is closed internally by gpiod_chip_iter_free.

Definition at line 1697 of file gpiod.h.

◆ gpiod_foreach_chip_noclose

#define gpiod_foreach_chip_noclose (   iter,
  chip 
)
Value:
for ((chip) = gpiod_chip_iter_next_noclose(iter); \
(chip); \

Iterate over all chips present in the system without closing them.

Parameters
iterAn initialized GPIO chip iterator.
chipPointer to a GPIO chip handle. On each iteration the newly opened chip handle is assigned to this argument.

The user must close all the GPIO chips manually after use, until then, the chips remain open. Free the iterator by calling gpiod_chip_iter_free_noclose to avoid closing the last chip automatically.

Definition at line 1712 of file gpiod.h.

◆ gpiod_foreach_line

#define gpiod_foreach_line (   iter,
  line 
)
Value:
for ((line) = gpiod_line_iter_next(iter); \
(line); \
(line) = gpiod_line_iter_next(iter))

Iterate over all GPIO lines of a single chip.

Parameters
iterAn initialized GPIO line iterator.
linePointer to a GPIO line handle - on each iteration, the next GPIO line will be assigned to this argument.

Definition at line 1747 of file gpiod.h.

Function Documentation

◆ gpiod_chip_iter_free()

void gpiod_chip_iter_free ( struct gpiod_chip_iter *  iter)

Release all resources allocated for the gpiochip iterator and close the most recently opened gpiochip (if any).

Parameters
iterThe gpiochip iterator object.

◆ gpiod_chip_iter_free_noclose()

void gpiod_chip_iter_free_noclose ( struct gpiod_chip_iter *  iter)

Release all resources allocated for the gpiochip iterator but don't close the most recently opened gpiochip (if any).

Parameters
iterThe gpiochip iterator object.

Users may want to break the loop when iterating over gpiochips and keep the most recently opened chip active while freeing the iterator data. This routine enables that.

◆ gpiod_chip_iter_new()

struct gpiod_chip_iter* gpiod_chip_iter_new ( void  )

Create a new gpiochip iterator.

Returns
Pointer to a new chip iterator object or NULL if an error occurred.

Internally this routine scans the /dev/ directory for GPIO chip device files, opens them and stores their the handles until gpiod_chip_iter_free or gpiod_chip_iter_free_noclose is called.

◆ gpiod_chip_iter_next()

struct gpiod_chip* gpiod_chip_iter_next ( struct gpiod_chip_iter *  iter)

Get the next gpiochip handle.

Parameters
iterThe gpiochip iterator object.
Returns
Pointer to the next open gpiochip handle or NULL if no more chips are present in the system.
Note
The previous chip handle will be closed using gpiod_chip_iter_free.

◆ gpiod_chip_iter_next_noclose()

struct gpiod_chip* gpiod_chip_iter_next_noclose ( struct gpiod_chip_iter *  iter)

Get the next gpiochip handle without closing the previous one.

Parameters
iterThe gpiochip iterator object.
Returns
Pointer to the next open gpiochip handle or NULL if no more chips are present in the system.
Note
This function works just like gpiod_chip_iter_next but doesn't close the most recently opened chip handle.

◆ gpiod_line_iter_free()

void gpiod_line_iter_free ( struct gpiod_line_iter *  iter)

Free all resources associated with a GPIO line iterator.

Parameters
iterLine iterator object.

◆ gpiod_line_iter_new()

struct gpiod_line_iter* gpiod_line_iter_new ( struct gpiod_chip *  chip)

Create a new line iterator.

Parameters
chipActive gpiochip handle over the lines of which we want to iterate.
Returns
New line iterator or NULL if an error occurred.

◆ gpiod_line_iter_next()

struct gpiod_line* gpiod_line_iter_next ( struct gpiod_line_iter *  iter)

Get the next GPIO line handle.

Parameters
iterThe GPIO line iterator object.
Returns
Pointer to the next GPIO line handle or NULL if there are no more lines left.
gpiod_chip_iter_next_noclose
struct gpiod_chip * gpiod_chip_iter_next_noclose(struct gpiod_chip_iter *iter) GPIOD_API
Get the next gpiochip handle without closing the previous one.
gpiod_line_iter_next
struct gpiod_line * gpiod_line_iter_next(struct gpiod_line_iter *iter) GPIOD_API
Get the next GPIO line handle.
gpiod_chip_iter_next
struct gpiod_chip * gpiod_chip_iter_next(struct gpiod_chip_iter *iter) GPIOD_API
Get the next gpiochip handle.