libgpiod  2.0.1
Functions
Line configuration objects

Functions for manipulating line configuration objects. More...

Functions

struct gpiod_line_configgpiod_line_config_new (void)
 Create a new line config object. More...
 
void gpiod_line_config_free (struct gpiod_line_config *config)
 Free the line config object and release all associated resources. More...
 
void gpiod_line_config_reset (struct gpiod_line_config *config)
 Reset the line config object. More...
 
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. More...
 
struct gpiod_line_settingsgpiod_line_config_get_line_settings (struct gpiod_line_config *config, unsigned int offset)
 Get line settings for offset. More...
 
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. More...
 
size_t gpiod_line_config_get_num_configured_offsets (struct gpiod_line_config *config)
 Get the number of configured line offsets. More...
 
size_t gpiod_line_config_get_configured_offsets (struct gpiod_line_config *config, unsigned int *offsets, size_t max_offsets)
 Get configured offsets. More...
 

Detailed Description

Functions for manipulating line configuration objects.

The line-config object contains the configuration for lines that can be used in two cases:

A new line-config object is empty. Using it in a request will lead to an error. In order to a line-config to become useful, it needs to be assigned at least one offset-to-settings mapping by calling gpiod_line_config_add_line_settings.

When calling gpiod_chip_request_lines, the library will request all offsets that were assigned settings in the order that they were assigned. If any of the offsets was duplicated, the last one will take precedence.

Function Documentation

◆ gpiod_line_config_add_line_settings()

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.

Parameters
configLine config object.
offsetsArray of offsets for which to apply the settings.
num_offsetsNumber of offsets stored in the offsets array.
settingsLine settings to apply.
Returns
0 on success, -1 on failure.

◆ gpiod_line_config_free()

void gpiod_line_config_free ( struct gpiod_line_config config)

Free the line config object and release all associated resources.

Parameters
configLine config object to free.

◆ gpiod_line_config_get_configured_offsets()

size_t gpiod_line_config_get_configured_offsets ( struct gpiod_line_config config,
unsigned int *  offsets,
size_t  max_offsets 
)

Get configured offsets.

Parameters
configLine config object.
offsetsArray to store offsets.
max_offsetsNumber of offsets that can be stored in the offsets array.
Returns
Number of offsets stored in the offsets array.

If max_offsets is lower than the number of lines actually requested (this value can be retrieved using gpiod_line_config_get_num_configured_offsets), then only up to max_lines offsets will be stored in offsets.

◆ gpiod_line_config_get_line_settings()

struct gpiod_line_settings* gpiod_line_config_get_line_settings ( struct gpiod_line_config config,
unsigned int  offset 
)

Get line settings for offset.

Parameters
configLine config object.
offsetOffset for which to get line settings.
Returns
New line settings object (must be freed by the caller) or NULL on error.

◆ gpiod_line_config_get_num_configured_offsets()

size_t gpiod_line_config_get_num_configured_offsets ( struct gpiod_line_config config)

Get the number of configured line offsets.

Parameters
configLine config object.
Returns
Number of offsets for which line settings have been added.

◆ gpiod_line_config_new()

struct gpiod_line_config* gpiod_line_config_new ( void  )

Create a new line config object.

Returns
New line config object or NULL on error. The returned object must be freed by the caller using gpiod_line_config_free.

◆ gpiod_line_config_reset()

void gpiod_line_config_reset ( struct gpiod_line_config config)

Reset the line config object.

Parameters
configLine config object to free.

Resets the entire configuration stored in the object. This is useful if the user wants to reuse the object without reallocating it.

◆ gpiod_line_config_set_output_values()

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.

Parameters
configLine config object.
valuesBuffer containing the output values.
num_valuesNumber of values in the buffer.
Returns
0 on success, -1 on error.

This is a helper that allows users to set multiple (potentially different) output values at once while using the same line settings object. Instead of modifying the output value in the settings object and calling gpiod_line_config_add_line_settings multiple times, we can specify the settings, add them for a set of offsets and then call this function to set the output values.

Values set by this function override whatever values were specified in the regular line settings.

Each value must be associated with the line identified by the corresponding entry in the offset array filled by gpiod_line_request_get_requested_offsets.