libiio  0.8
Library for interfacing with IIO devices
Data Structures | Functions
Channel

Data Structures

struct  iio_channel
 Represents an input or output channel of a device. More...
 

Functions

__api __pure const struct iio_deviceiio_channel_get_device (const struct iio_channel *chn)
 Retrieve a pointer to the iio_device structure. More...
 
__api __pure const char * iio_channel_get_id (const struct iio_channel *chn)
 Retrieve the channel ID (e.g. voltage0) More...
 
__api __pure const char * iio_channel_get_name (const struct iio_channel *chn)
 Retrieve the channel name (e.g. vccint) More...
 
__api __pure bool iio_channel_is_output (const struct iio_channel *chn)
 Return True if the given channel is an output channel. More...
 
__api __pure bool iio_channel_is_scan_element (const struct iio_channel *chn)
 Return True if the given channel is a scan element. More...
 
__api __pure unsigned int iio_channel_get_attrs_count (const struct iio_channel *chn)
 Enumerate the channel-specific attributes of the given channel. More...
 
__api __pure const char * iio_channel_get_attr (const struct iio_channel *chn, unsigned int index)
 Get the channel-specific attribute present at the given index. More...
 
__api __pure const char * iio_channel_find_attr (const struct iio_channel *chn, const char *name)
 Try to find a channel-specific attribute by its name. More...
 
__api __pure const char * iio_channel_attr_get_filename (const struct iio_channel *chn, const char *attr)
 Retrieve the filename of an attribute. More...
 
__api ssize_t iio_channel_attr_read (const struct iio_channel *chn, const char *attr, char *dst, size_t len)
 Read the content of the given channel-specific attribute. More...
 
__api int iio_channel_attr_read_all (struct iio_channel *chn, int(*cb)(struct iio_channel *chn, const char *attr, const char *val, size_t len, void *d), void *data)
 Read the content of all channel-specific attributes. More...
 
__api int iio_channel_attr_read_bool (const struct iio_channel *chn, const char *attr, bool *val)
 Read the content of the given channel-specific attribute. More...
 
__api int iio_channel_attr_read_longlong (const struct iio_channel *chn, const char *attr, long long *val)
 Read the content of the given channel-specific attribute. More...
 
__api int iio_channel_attr_read_double (const struct iio_channel *chn, const char *attr, double *val)
 Read the content of the given channel-specific attribute. More...
 
__api ssize_t iio_channel_attr_write (const struct iio_channel *chn, const char *attr, const char *src)
 Set the value of the given channel-specific attribute. More...
 
__api ssize_t iio_channel_attr_write_raw (const struct iio_channel *chn, const char *attr, const void *src, size_t len)
 Set the value of the given channel-specific attribute. More...
 
__api int iio_channel_attr_write_all (struct iio_channel *chn, ssize_t(*cb)(struct iio_channel *chn, const char *attr, void *buf, size_t len, void *d), void *data)
 Set the values of all channel-specific attributes. More...
 
__api int iio_channel_attr_write_bool (const struct iio_channel *chn, const char *attr, bool val)
 Set the value of the given channel-specific attribute. More...
 
__api int iio_channel_attr_write_longlong (const struct iio_channel *chn, const char *attr, long long val)
 Set the value of the given channel-specific attribute. More...
 
__api int iio_channel_attr_write_double (const struct iio_channel *chn, const char *attr, double val)
 Set the value of the given channel-specific attribute. More...
 
__api void iio_channel_enable (struct iio_channel *chn)
 Enable the given channel. More...
 
__api void iio_channel_disable (struct iio_channel *chn)
 Disable the given channel. More...
 
__api bool iio_channel_is_enabled (const struct iio_channel *chn)
 Returns True if the channel is enabled. More...
 
__api size_t iio_channel_read_raw (const struct iio_channel *chn, struct iio_buffer *buffer, void *dst, size_t len)
 
__api size_t iio_channel_read (const struct iio_channel *chn, struct iio_buffer *buffer, void *dst, size_t len)
 
__api size_t iio_channel_write_raw (const struct iio_channel *chn, struct iio_buffer *buffer, const void *src, size_t len)
 
__api size_t iio_channel_write (const struct iio_channel *chn, struct iio_buffer *buffer, const void *src, size_t len)
 
__api void iio_channel_set_data (struct iio_channel *chn, void *data)
 Associate a pointer to an iio_channel structure. More...
 
__api void * iio_channel_get_data (const struct iio_channel *chn)
 Retrieve a previously associated pointer of an iio_channel structure. More...
 
__api __pure enum iio_chan_type iio_channel_get_type (const struct iio_channel *chn)
 Get the type of the given channel. More...
 
__api __pure enum iio_modifier iio_channel_get_modifier (const struct iio_channel *chn)
 Get the modifier type of the given channel. More...
 

Detailed Description

Function Documentation

◆ iio_channel_attr_get_filename()

__api __pure const char* iio_channel_attr_get_filename ( const struct iio_channel chn,
const char *  attr 
)

Retrieve the filename of an attribute.

Parameters
chnA pointer to an iio_channel structure
attra NULL-terminated string corresponding to the name of the attribute
Returns
On success, a pointer to a static NULL-terminated string
If the attribute name is unknown, NULL is returned

◆ iio_channel_attr_read()

__api ssize_t iio_channel_attr_read ( const struct iio_channel chn,
const char *  attr,
char *  dst,
size_t  len 
)

Read the content of the given channel-specific attribute.

Parameters
chnA pointer to an iio_channel structure
attrA NULL-terminated string corresponding to the name of the attribute
dstA pointer to the memory area where the NULL-terminated string corresponding to the value read will be stored
lenThe available length of the memory area, in bytes
Returns
On success, the number of bytes written to the buffer
On error, a negative errno code is returned

NOTE:By passing NULL as the "attr" argument to iio_channel_attr_read, it is now possible to read all of the attributes of a channel.

The buffer is filled with one block of data per attribute of the channel, by the order they appear in the iio_channel structure.

The first four bytes of one block correspond to a 32-bit signed value in network order. If negative, it corresponds to the errno code that were returned when reading the attribute; if positive, it corresponds to the length of the data read. In that case, the rest of the block contains the data.

◆ iio_channel_attr_read_all()

__api int iio_channel_attr_read_all ( struct iio_channel chn,
int(*)(struct iio_channel *chn, const char *attr, const char *val, size_t len, void *d)  cb,
void *  data 
)

Read the content of all channel-specific attributes.

Parameters
chnA pointer to an iio_channel structure
cbA pointer to a callback function
dataA pointer that will be passed to the callback function
Returns
On success, 0 is returned
On error, a negative errno code is returned

NOTE: This function is especially useful when used with the network backend, as all the channel-specific attributes are read in one single command.

◆ iio_channel_attr_read_bool()

__api int iio_channel_attr_read_bool ( const struct iio_channel chn,
const char *  attr,
bool *  val 
)

Read the content of the given channel-specific attribute.

Parameters
chnA pointer to an iio_channel structure
attrA NULL-terminated string corresponding to the name of the attribute
valA pointer to a bool variable where the value should be stored
Returns
On success, 0 is returned
On error, a negative errno code is returned

◆ iio_channel_attr_read_double()

__api int iio_channel_attr_read_double ( const struct iio_channel chn,
const char *  attr,
double *  val 
)

Read the content of the given channel-specific attribute.

Parameters
chnA pointer to an iio_channel structure
attrA NULL-terminated string corresponding to the name of the attribute
valA pointer to a double variable where the value should be stored
Returns
On success, 0 is returned
On error, a negative errno code is returned

◆ iio_channel_attr_read_longlong()

__api int iio_channel_attr_read_longlong ( const struct iio_channel chn,
const char *  attr,
long long *  val 
)

Read the content of the given channel-specific attribute.

Parameters
chnA pointer to an iio_channel structure
attrA NULL-terminated string corresponding to the name of the attribute
valA pointer to a long long variable where the value should be stored
Returns
On success, 0 is returned
On error, a negative errno code is returned

◆ iio_channel_attr_write()

__api ssize_t iio_channel_attr_write ( const struct iio_channel chn,
const char *  attr,
const char *  src 
)

Set the value of the given channel-specific attribute.

Parameters
chnA pointer to an iio_channel structure
attrA NULL-terminated string corresponding to the name of the attribute
srcA NULL-terminated string to set the attribute to
Returns
On success, the number of bytes written
On error, a negative errno code is returned

NOTE:By passing NULL as the "attr" argument to iio_channel_attr_write, it is now possible to write all of the attributes of a channel.

The buffer must contain one block of data per attribute of the channel, by the order they appear in the iio_channel structure.

The first four bytes of one block correspond to a 32-bit signed value in network order. If negative, the attribute is not written; if positive, it corresponds to the length of the data to write. In that case, the rest of the block must contain the data.

◆ iio_channel_attr_write_all()

__api int iio_channel_attr_write_all ( struct iio_channel chn,
ssize_t(*)(struct iio_channel *chn, const char *attr, void *buf, size_t len, void *d)  cb,
void *  data 
)

Set the values of all channel-specific attributes.

Parameters
chnA pointer to an iio_channel structure
cbA pointer to a callback function
dataA pointer that will be passed to the callback function
Returns
On success, 0 is returned
On error, a negative errno code is returned

NOTE: This function is especially useful when used with the network backend, as all the channel-specific attributes are written in one single command.

◆ iio_channel_attr_write_bool()

__api int iio_channel_attr_write_bool ( const struct iio_channel chn,
const char *  attr,
bool  val 
)

Set the value of the given channel-specific attribute.

Parameters
chnA pointer to an iio_channel structure
attrA NULL-terminated string corresponding to the name of the attribute
valA bool value to set the attribute to
Returns
On success, 0 is returned
On error, a negative errno code is returned

◆ iio_channel_attr_write_double()

__api int iio_channel_attr_write_double ( const struct iio_channel chn,
const char *  attr,
double  val 
)

Set the value of the given channel-specific attribute.

Parameters
chnA pointer to an iio_channel structure
attrA NULL-terminated string corresponding to the name of the attribute
valA double value to set the attribute to
Returns
On success, 0 is returned
On error, a negative errno code is returned

◆ iio_channel_attr_write_longlong()

__api int iio_channel_attr_write_longlong ( const struct iio_channel chn,
const char *  attr,
long long  val 
)

Set the value of the given channel-specific attribute.

Parameters
chnA pointer to an iio_channel structure
attrA NULL-terminated string corresponding to the name of the attribute
valA long long value to set the attribute to
Returns
On success, 0 is returned
On error, a negative errno code is returned

◆ iio_channel_attr_write_raw()

__api ssize_t iio_channel_attr_write_raw ( const struct iio_channel chn,
const char *  attr,
const void *  src,
size_t  len 
)

Set the value of the given channel-specific attribute.

Parameters
chnA pointer to an iio_channel structure
attrA NULL-terminated string corresponding to the name of the attribute
srcA pointer to the data to be written
lenThe number of bytes that should be written
Returns
On success, the number of bytes written
On error, a negative errno code is returned

◆ iio_channel_disable()

__api void iio_channel_disable ( struct iio_channel chn)

Disable the given channel.

Parameters
chnA pointer to an iio_channel structure

◆ iio_channel_enable()

__api void iio_channel_enable ( struct iio_channel chn)

Enable the given channel.

Parameters
chnA pointer to an iio_channel structure

NOTE:Before creating an iio_buffer structure with iio_device_create_buffer, it is required to enable at least one channel of the device to read from.

◆ iio_channel_find_attr()

__api __pure const char* iio_channel_find_attr ( const struct iio_channel chn,
const char *  name 
)

Try to find a channel-specific attribute by its name.

Parameters
chnA pointer to an iio_channel structure
nameA NULL-terminated string corresponding to the name of the attribute
Returns
On success, a pointer to a static NULL-terminated string
If the name does not correspond to any known attribute of the given channel, NULL is returned

NOTE: This function is useful to detect the presence of an attribute. It can also be used to retrieve the name of an attribute as a pointer to a static string from a dynamically allocated string.

◆ iio_channel_get_attr()

__api __pure const char* iio_channel_get_attr ( const struct iio_channel chn,
unsigned int  index 
)

Get the channel-specific attribute present at the given index.

Parameters
chnA pointer to an iio_channel structure
indexThe index corresponding to the attribute
Returns
On success, a pointer to a static NULL-terminated string
If the index is invalid, NULL is returned

◆ iio_channel_get_attrs_count()

__api __pure unsigned int iio_channel_get_attrs_count ( const struct iio_channel chn)

Enumerate the channel-specific attributes of the given channel.

Parameters
chnA pointer to an iio_channel structure
Returns
The number of channel-specific attributes found

◆ iio_channel_get_data()

__api void* iio_channel_get_data ( const struct iio_channel chn)

Retrieve a previously associated pointer of an iio_channel structure.

Parameters
chnA pointer to an iio_channel structure
Returns
The pointer previously associated if present, or NULL

◆ iio_channel_get_device()

__api __pure const struct iio_device* iio_channel_get_device ( const struct iio_channel chn)

Retrieve a pointer to the iio_device structure.

Parameters
chnA pointer to an iio_channel structure
Returns
A pointer to an iio_device structure

◆ iio_channel_get_id()

__api __pure const char* iio_channel_get_id ( const struct iio_channel chn)

Retrieve the channel ID (e.g. voltage0)

Parameters
chnA pointer to an iio_channel structure
Returns
A pointer to a static NULL-terminated string

◆ iio_channel_get_modifier()

__api __pure enum iio_modifier iio_channel_get_modifier ( const struct iio_channel chn)

Get the modifier type of the given channel.

Parameters
chnA pointer to an iio_channel structure
Returns
The modifier type of the channel

◆ iio_channel_get_name()

__api __pure const char* iio_channel_get_name ( const struct iio_channel chn)

Retrieve the channel name (e.g. vccint)

Parameters
chnA pointer to an iio_channel structure
Returns
A pointer to a static NULL-terminated string

NOTE: if the channel has no name, NULL is returned.

◆ iio_channel_get_type()

__api __pure enum iio_chan_type iio_channel_get_type ( const struct iio_channel chn)

Get the type of the given channel.

Parameters
chnA pointer to an iio_channel structure
Returns
The type of the channel

◆ iio_channel_is_enabled()

__api bool iio_channel_is_enabled ( const struct iio_channel chn)

Returns True if the channel is enabled.

Parameters
chnA pointer to an iio_channel structure
Returns
True if the channel is enabled, False otherwise

◆ iio_channel_is_output()

__api __pure bool iio_channel_is_output ( const struct iio_channel chn)

Return True if the given channel is an output channel.

Parameters
chnA pointer to an iio_channel structure
Returns
True if the channel is an output channel, False otherwise

◆ iio_channel_is_scan_element()

__api __pure bool iio_channel_is_scan_element ( const struct iio_channel chn)

Return True if the given channel is a scan element.

Parameters
chnA pointer to an iio_channel structure
Returns
True if the channel is a scan element, False otherwise

NOTE: a channel that is a scan element is a channel that can generate samples (for an input channel) or receive samples (for an output channel) after being enabled.

◆ iio_channel_read()

__api size_t iio_channel_read ( const struct iio_channel chn,
struct iio_buffer buffer,
void *  dst,
size_t  len 
)

Demultiplex and convert the samples of a given channel

Parameters
chnA pointer to an iio_channel structure
bufferA pointer to an iio_buffer structure
dstA pointer to the memory area where the converted data will be stored
lenThe available length of the memory area, in bytes
Returns
The size of the converted data, in bytes

◆ iio_channel_read_raw()

__api size_t iio_channel_read_raw ( const struct iio_channel chn,
struct iio_buffer buffer,
void *  dst,
size_t  len 
)

Demultiplex the samples of a given channel

Parameters
chnA pointer to an iio_channel structure
bufferA pointer to an iio_buffer structure
dstA pointer to the memory area where the demultiplexed data will be stored
lenThe available length of the memory area, in bytes
Returns
The size of the demultiplexed data, in bytes

◆ iio_channel_set_data()

__api void iio_channel_set_data ( struct iio_channel chn,
void *  data 
)

Associate a pointer to an iio_channel structure.

Parameters
chnA pointer to an iio_channel structure
dataThe pointer to be associated

◆ iio_channel_write()

__api size_t iio_channel_write ( const struct iio_channel chn,
struct iio_buffer buffer,
const void *  src,
size_t  len 
)

Convert and multiplex the samples of a given channel

Parameters
chnA pointer to an iio_channel structure
bufferA pointer to an iio_buffer structure
srcA pointer to the memory area where the sequential data will be read from
lenThe length of the memory area, in bytes
Returns
The number of bytes actually converted and multiplexed

◆ iio_channel_write_raw()

__api size_t iio_channel_write_raw ( const struct iio_channel chn,
struct iio_buffer buffer,
const void *  src,
size_t  len 
)

Multiplex the samples of a given channel

Parameters
chnA pointer to an iio_channel structure
bufferA pointer to an iio_buffer structure
srcA pointer to the memory area where the sequential data will be read from
lenThe length of the memory area, in bytes
Returns
The number of bytes actually multiplexed