libiio 1.0
Library for interfacing with IIO devices
Loading...
Searching...
No Matches
iio.h File Reference

Public interface. More...

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  iio_context_params
 IIO context creation information. More...
 
struct  iio_event
 Represents a IIO event. More...
 
struct  iio_data_format
 Contains the format of a data sample. More...
 

Macros

#define _IIO_TYPES_H_
 
#define iio_attr_read(attr, ptr)
 Read the content of the given attribute.
 
#define iio_attr_write(attr, val)
 Set the value of the given attribute.
 

Enumerations

enum  iio_log_level {
  LEVEL_NOLOG = 1 , LEVEL_ERROR = 2 , LEVEL_WARNING = 3 , LEVEL_INFO = 4 ,
  LEVEL_DEBUG = 5
}
 Level of verbosity of libiio's log output.
 
enum  iio_context_flags { IIO_CTX_XML_INCLUDE_VALUES = 1 << 0 }
 Flags controlling context behavior;. More...
 
enum  iio_chan_type {
  IIO_VOLTAGE , IIO_CURRENT , IIO_POWER , IIO_ACCEL ,
  IIO_ANGL_VEL , IIO_MAGN , IIO_LIGHT , IIO_INTENSITY ,
  IIO_PROXIMITY , IIO_TEMP , IIO_INCLI , IIO_ROT ,
  IIO_ANGL , IIO_TIMESTAMP , IIO_CAPACITANCE , IIO_ALTVOLTAGE ,
  IIO_CCT , IIO_PRESSURE , IIO_HUMIDITYRELATIVE , IIO_ACTIVITY ,
  IIO_STEPS , IIO_ENERGY , IIO_DISTANCE , IIO_VELOCITY ,
  IIO_CONCENTRATION , IIO_RESISTANCE , IIO_PH , IIO_UVINDEX ,
  IIO_ELECTRICALCONDUCTIVITY , IIO_COUNT , IIO_INDEX , IIO_GRAVITY ,
  IIO_POSITIONRELATIVE , IIO_PHASE , IIO_MASSCONCENTRATION , IIO_DELTA_ANGL ,
  IIO_DELTA_VELOCITY , IIO_COLORTEMP , IIO_CHROMATICITY , IIO_ATTENTION ,
  IIO_ALTCURRENT , IIO_CHAN_TYPE_UNKNOWN = INT_MAX
}
 IIO channel type. More...
 
enum  iio_modifier {
  IIO_NO_MOD , IIO_MOD_X , IIO_MOD_Y , IIO_MOD_Z ,
  IIO_MOD_X_AND_Y , IIO_MOD_X_AND_Z , IIO_MOD_Y_AND_Z , IIO_MOD_X_AND_Y_AND_Z ,
  IIO_MOD_X_OR_Y , IIO_MOD_X_OR_Z , IIO_MOD_Y_OR_Z , IIO_MOD_X_OR_Y_OR_Z ,
  IIO_MOD_LIGHT_BOTH , IIO_MOD_LIGHT_IR , IIO_MOD_ROOT_SUM_SQUARED_X_Y , IIO_MOD_SUM_SQUARED_X_Y_Z ,
  IIO_MOD_LIGHT_CLEAR , IIO_MOD_LIGHT_RED , IIO_MOD_LIGHT_GREEN , IIO_MOD_LIGHT_BLUE ,
  IIO_MOD_QUATERNION , IIO_MOD_TEMP_AMBIENT , IIO_MOD_TEMP_OBJECT , IIO_MOD_NORTH_MAGN ,
  IIO_MOD_NORTH_TRUE , IIO_MOD_NORTH_MAGN_TILT_COMP , IIO_MOD_NORTH_TRUE_TILT_COMP , IIO_MOD_RUNNING ,
  IIO_MOD_JOGGING , IIO_MOD_WALKING , IIO_MOD_STILL , IIO_MOD_ROOT_SUM_SQUARED_X_Y_Z ,
  IIO_MOD_I , IIO_MOD_Q , IIO_MOD_CO2 , IIO_MOD_VOC ,
  IIO_MOD_LIGHT_UV , IIO_MOD_LIGHT_DUV , IIO_MOD_PM1 , IIO_MOD_PM2P5 ,
  IIO_MOD_PM4 , IIO_MOD_PM10 , IIO_MOD_ETHANOL , IIO_MOD_H2 ,
  IIO_MOD_O2 , IIO_MOD_LINEAR_X , IIO_MOD_LINEAR_Y , IIO_MOD_LINEAR_Z ,
  IIO_MOD_PITCH , IIO_MOD_YAW , IIO_MOD_ROLL , IIO_MOD_LIGHT_UVA ,
  IIO_MOD_LIGHT_UVB , IIO_MOD_RMS , IIO_MOD_ACTIVE , IIO_MOD_REACTIVE ,
  IIO_MOD_APPARENT
}
 IIO channel modifier. More...
 
enum  iio_event_type {
  IIO_EV_TYPE_THRESH , IIO_EV_TYPE_MAG , IIO_EV_TYPE_ROC , IIO_EV_TYPE_THRESH_ADAPTIVE ,
  IIO_EV_TYPE_MAG_ADAPTIVE , IIO_EV_TYPE_CHANGE , IIO_EV_TYPE_MAG_REFERENCED , IIO_EV_TYPE_GESTURE ,
  IIO_EV_TYPE_FAULT
}
 IIO event type. More...
 
enum  iio_event_direction {
  IIO_EV_DIR_EITHER , IIO_EV_DIR_RISING , IIO_EV_DIR_FALLING , IIO_EV_DIR_NONE ,
  IIO_EV_DIR_SINGLETAP , IIO_EV_DIR_DOUBLETAP , IIO_EV_DIR_FAULT_OPENWIRE
}
 IIO event direction. More...
 
enum  hwmon_chan_type {
  HWMON_VOLTAGE , HWMON_FAN , HWMON_PWM , HWMON_TEMP ,
  HWMON_CURRENT , HWMON_POWER , HWMON_ENERGY , HWMON_HUMIDITY ,
  HWMON_INTRUSION , HWMON_CHAN_TYPE_UNKNOWN = IIO_CHAN_TYPE_UNKNOWN
}
 Hwmon channel type. More...
 

Functions

__api __check_ret ssize_t iio_attr_read_raw (const struct iio_attr *attr, char *dst, size_t len)
 Read the content of the given attribute.
 
__api __check_ret ssize_t iio_attr_write_raw (const struct iio_attr *attr, const void *src, size_t len)
 Set the value of the given attribute.
 
__api __pure const char * iio_attr_get_name (const struct iio_attr *attr)
 Retrieve the name of an attribute.
 
__api __check_ret __pure const char * iio_attr_get_filename (const struct iio_attr *attr)
 Retrieve the filename of an attribute.
 
__api __pure const char * iio_attr_get_static_value (const struct iio_attr *attr)
 Retrieve the static value of an attribute.
 
__api int iio_attr_get_range (const struct iio_attr *attr, double *min, double *step, double *max)
 Extract the range from an attribute with suffix '_available'.
 
__api int iio_attr_get_available (const struct iio_attr *attr, char ***list, size_t *count)
 Extract the list of elements from an attribute with suffix '_available'.
 
__api int iio_attr_get_available_buf (const struct iio_attr *attr, char *buf, size_t buflen, char **list, size_t *count)
 A variant of iio_attr_get_available() that uses a caller-supplied, preallocated buffer. If the optional 'list' and 'count' parameters are provided, the buffer will be tokenized in place by replacing each delimiter with a null terminator ('\0'). As a result, each element in 'list' will point to the start of a substring in the buffer, representing one of the available values. For instance, 'list[0]' points to the first value, 'list[1]' to the second, and so forth.
 
__api void iio_available_list_free (char **list, size_t count)
 Free the resources allocated only by iio_attr_get_available()
 
__api __check_ret struct iio_scan * iio_scan (const struct iio_context_params *params, const char *backends)
 Scan backends for IIO contexts.
 
__api void iio_scan_destroy (struct iio_scan *ctx)
 Destroy the given scan context.
 
__api __check_ret __pure size_t iio_scan_get_results_count (const struct iio_scan *ctx)
 Get number of results of a scan operation.
 
__api __check_ret __pure const char * iio_scan_get_description (const struct iio_scan *ctx, size_t idx)
 Get description of scanned context.
 
__api __check_ret __pure const char * iio_scan_get_uri (const struct iio_scan *ctx, size_t idx)
 Get URI of scanned context.
 
__api void iio_strerror (int err, char *dst, size_t len)
 Get a string description of an error code.
 
__api __check_ret bool iio_has_backend (const struct iio_context_params *params, const char *backend)
 Check if the specified backend is available.
 
__api __check_ret __cnst unsigned int iio_get_builtin_backends_count (void)
 Get the number of available built-in backends.
 
__api __check_ret __cnst const char * iio_get_builtin_backend (unsigned int index)
 Retrieve the name of a given built-in backend.
 
__api __check_ret struct iio_contextiio_create_context (const struct iio_context_params *params, const char *uri)
 Create a context from a URI description.
 
__api void iio_context_destroy (struct iio_context *ctx)
 Destroy the given context.
 
__api __pure unsigned int iio_context_get_version_major (const struct iio_context *ctx)
 Get the major number of the library version.
 
__api __pure unsigned int iio_context_get_version_minor (const struct iio_context *ctx)
 Get the minor number of the library version.
 
__api __pure const char * iio_context_get_version_tag (const struct iio_context *ctx)
 Get the git hash string of the library version.
 
__api __check_ret char * iio_context_get_xml (const struct iio_context *ctx)
 Obtain a XML representation of the given context.
 
__api __check_ret __pure const char * iio_context_get_name (const struct iio_context *ctx)
 Get the name of the given context.
 
__api __check_ret __pure const char * iio_context_get_description (const struct iio_context *ctx)
 Get a description of the given context.
 
__api __check_ret __pure unsigned int iio_context_get_attrs_count (const struct iio_context *ctx)
 Get the number of context-specific attributes.
 
__api __check_ret __pure const struct iio_attriio_context_get_attr (const struct iio_context *ctx, unsigned int index)
 Retrieve the context-specific attribute at the given index.
 
__api __check_ret __pure const struct iio_attriio_context_find_attr (const struct iio_context *ctx, const char *name)
 Try to find a context-specific attribute by its name.
 
__api __check_ret __pure unsigned int iio_context_get_devices_count (const struct iio_context *ctx)
 Enumerate the devices found in the given context.
 
__api __check_ret __pure struct iio_deviceiio_context_get_device (const struct iio_context *ctx, unsigned int index)
 Get the device present at the given index.
 
__api __check_ret __pure struct iio_deviceiio_context_find_device (const struct iio_context *ctx, const char *name)
 Try to find a device structure by its ID, label or name.
 
__api __check_ret int iio_context_set_timeout (struct iio_context *ctx, unsigned int timeout_ms)
 Set a timeout for I/O operations.
 
__api __cnst const struct iio_context_paramsiio_context_get_params (const struct iio_context *ctx)
 Get a pointer to the params structure.
 
__api void iio_context_set_data (struct iio_context *ctx, void *data)
 Associate a pointer to an iio_context structure.
 
__api void * iio_context_get_data (const struct iio_context *ctx)
 Retrieve a previously associated pointer of an iio_context structure.
 
__api __check_ret __pure const struct iio_contextiio_device_get_context (const struct iio_device *dev)
 Retrieve a pointer to the iio_context structure.
 
__api __check_ret __pure const char * iio_device_get_id (const struct iio_device *dev)
 Retrieve the device ID (e.g. iio:device0)
 
__api __check_ret __pure const char * iio_device_get_name (const struct iio_device *dev)
 Retrieve the device name (e.g. xadc)
 
__api __check_ret __pure const char * iio_device_get_label (const struct iio_device *dev)
 Retrieve the device label (e.g. lo_pll0_rx_adf4351)
 
__api __check_ret __pure unsigned int iio_device_get_channels_count (const struct iio_device *dev)
 Enumerate the channels of the given device.
 
__api __check_ret __pure unsigned int iio_device_get_attrs_count (const struct iio_device *dev)
 Enumerate the device-specific attributes of the given device.
 
__api __check_ret __pure unsigned int iio_device_get_buffers_count (const struct iio_device *dev)
 Enumerate the buffers of the given device.
 
__api __check_ret __pure struct iio_channeliio_device_get_channel (const struct iio_device *dev, unsigned int index)
 Get the channel present at the given index.
 
__api __check_ret __pure const struct iio_attriio_device_get_attr (const struct iio_device *dev, unsigned int index)
 Get the device-specific attribute present at the given index.
 
__api __check_ret __pure struct iio_bufferiio_device_get_buffer (const struct iio_device *dev, unsigned int index)
 Get the buffer present at the given index.
 
__api __check_ret __pure struct iio_channeliio_device_find_channel (const struct iio_device *dev, const char *name, bool output)
 Try to find a channel structure by its ID, label or name.
 
__api __check_ret __pure const struct iio_attriio_device_find_attr (const struct iio_device *dev, const char *name)
 Try to find a device-specific attribute by its name.
 
__api void iio_device_set_data (struct iio_device *dev, void *data)
 Associate a pointer to an iio_device structure.
 
__api void * iio_device_get_data (const struct iio_device *dev)
 Retrieve a previously associated pointer of an iio_device structure.
 
__api __check_ret const struct iio_deviceiio_device_get_trigger (const struct iio_device *dev)
 Retrieve the trigger of a given device.
 
__api __check_ret int iio_device_set_trigger (const struct iio_device *dev, const struct iio_device *trigger)
 Associate a trigger to a given device.
 
__api __check_ret __pure bool iio_device_is_trigger (const struct iio_device *dev)
 Return True if the given device is a trigger.
 
__api __check_ret __pure const struct iio_deviceiio_channel_get_device (const struct iio_channel *chn)
 Retrieve a pointer to the iio_device structure.
 
__api __check_ret __pure const char * iio_channel_get_id (const struct iio_channel *chn)
 Retrieve the channel ID (e.g. voltage0)
 
__api __check_ret __pure const char * iio_channel_get_name (const struct iio_channel *chn)
 Retrieve the channel name (e.g. vccint)
 
__api __check_ret __pure const char * iio_channel_get_label (const struct iio_channel *chn)
 Retrieve the channel label (e.g. anglY)
 
__api __check_ret __pure bool iio_channel_is_output (const struct iio_channel *chn)
 Return True if the given channel is an output channel.
 
__api __check_ret __pure bool iio_channel_is_scan_element (const struct iio_channel *chn)
 Return True if the given channel is a scan element.
 
__api __check_ret __pure unsigned int iio_channel_get_attrs_count (const struct iio_channel *chn)
 Enumerate the channel-specific attributes of the given channel.
 
__api __check_ret __pure const struct iio_attriio_channel_get_attr (const struct iio_channel *chn, unsigned int index)
 Get the channel-specific attribute present at the given index.
 
__api __check_ret __pure const struct iio_attriio_channel_find_attr (const struct iio_channel *chn, const char *name)
 Try to find a channel-specific attribute by its name.
 
__api void iio_channel_enable (const struct iio_channel *chn, struct iio_channels_mask *mask)
 Enable the given channel.
 
__api void iio_channel_disable (const struct iio_channel *chn, struct iio_channels_mask *mask)
 Disable the given channel.
 
__api __check_ret bool iio_channel_is_enabled (const struct iio_channel *chn, const struct iio_channels_mask *mask)
 Returns True if the channel is enabled.
 
__api __check_ret size_t iio_channel_read (const struct iio_channel *chn, const struct iio_block *block, void *dst, size_t len, bool raw)
 Demultiplex and convert the samples of a given channel.
 
__api __check_ret size_t iio_channel_write (const struct iio_channel *chn, struct iio_block *block, const void *src, size_t len, bool raw)
 Convert and multiplex the samples of a given channel.
 
__api void iio_channel_set_data (struct iio_channel *chn, void *data)
 Associate a pointer to an iio_channel structure.
 
__api void * iio_channel_get_data (const struct iio_channel *chn)
 Retrieve a previously associated pointer of an iio_channel structure.
 
__api __check_ret __pure enum iio_chan_type iio_channel_get_type (const struct iio_channel *chn)
 Get the type of the given channel.
 
__api __check_ret __pure enum iio_modifier iio_channel_get_modifier (const struct iio_channel *chn)
 Get the modifier type of the given channel.
 
__api __check_ret __pure const struct iio_deviceiio_buffer_get_device (const struct iio_buffer *buf)
 Retrieve a pointer to the iio_device structure.
 
__api __check_ret __pure unsigned int iio_buffer_get_attrs_count (const struct iio_buffer *buf)
 Enumerate the attributes of the given buffer.
 
__api __check_ret __pure const struct iio_attriio_buffer_get_attr (const struct iio_buffer *buf, unsigned int index)
 Get the buffer-specific attribute present at the given index.
 
__api __check_ret __pure const struct iio_attriio_buffer_find_attr (const struct iio_buffer *buf, const char *name)
 Try to find a buffer-specific attribute by its name.
 
__api __check_ret __pure bool iio_buffer_is_output (const struct iio_buffer *buf)
 Returns true if the buffer is an output buffer.
 
__api void iio_buffer_set_data (struct iio_buffer *buf, void *data)
 Associate a pointer to an iio_buffer structure.
 
__api void * iio_buffer_get_data (const struct iio_buffer *buf)
 Retrieve a previously associated pointer of an iio_buffer structure.
 
__api __check_ret struct iio_buffer_streamiio_buffer_open (struct iio_buffer *buf, const struct iio_channels_mask *mask)
 Open a buffer for data streaming.
 
__api void iio_buffer_close (struct iio_buffer_stream *buf_stream)
 Close a buffer stream.
 
__api void iio_buffer_stream_cancel (struct iio_buffer_stream *buf_stream)
 Cancel all buffer stream operations.
 
__api __check_ret int iio_buffer_stream_start (struct iio_buffer_stream *buf_stream)
 Start the buffer stream.
 
__api int iio_buffer_stream_stop (struct iio_buffer_stream *buf_stream)
 Stop the buffer stream.
 
__api const struct iio_channels_mask * iio_buffer_stream_get_channels_mask (const struct iio_buffer_stream *buf_stream)
 Retrieve the channels mask of a buffer stream.
 
__api __check_ret struct iio_block * iio_buffer_stream_create_block (struct iio_buffer_stream *buf_stream, size_t size)
 Create a data block for the given buffer stream.
 
__api void iio_block_destroy (struct iio_block *block)
 Destroy the given block.
 
__api __check_ret int iio_block_get_dmabuf_fd (const struct iio_block *block)
 Get the file descriptor of the underlying DMABUF object.
 
__api int iio_block_disable_cpu_access (struct iio_block *block, bool disable)
 Disable CPU access of a given block.
 
__api void * iio_block_start (const struct iio_block *block)
 Get the start address of the block.
 
__api void * iio_block_first (const struct iio_block *block, const struct iio_channel *chn)
 Find the first sample of a channel in a block.
 
__api void * iio_block_end (const struct iio_block *block)
 Get the address after the last sample in a block.
 
__api __check_ret ssize_t iio_block_foreach_sample (const struct iio_block *block, const struct iio_channels_mask *mask, ssize_t(*callback)(const struct iio_channel *chn, void *src, size_t bytes, void *d), void *data)
 Call the supplied callback for each sample found in a block.
 
__api int iio_block_enqueue (struct iio_block *block, size_t bytes_used, bool cyclic)
 Enqueue the given iio_block to the buffer's queue.
 
__api int iio_block_dequeue (struct iio_block *block, bool nonblock)
 Dequeue the given iio_block from the buffer's queue.
 
__api struct iio_buffer_streamiio_block_get_buffer_stream (const struct iio_block *block)
 Retrieve a pointer to the iio_buffer_stream structure.
 
__api __check_ret struct iio_stream * iio_buffer_create_stream (struct iio_buffer *buffer, size_t nb_blocks, size_t samples_count, struct iio_channels_mask *mask)
 Create a iio_stream object for the given iio_buffer.
 
__api void iio_stream_cancel (struct iio_stream *stream)
 Cancel all stream operations.
 
__api void iio_stream_destroy (struct iio_stream *stream)
 Destroy the given stream object.
 
__api __check_ret const struct iio_block * iio_stream_get_next_block (struct iio_stream *stream)
 Get a pointer to the next data block.
 
__api __check_ret const struct iio_channeliio_event_get_channel (const struct iio_event *event, const struct iio_device *dev, bool diff)
 Get a pointer to the IIO channel that corresponds to this event.
 
__api __check_ret struct iio_event_stream * iio_device_create_event_stream (const struct iio_device *dev)
 Create an events stream for the given IIO device.
 
__api void iio_event_stream_destroy (struct iio_event_stream *stream)
 Destroy the given event stream.
 
__api int iio_event_stream_read (struct iio_event_stream *stream, struct iio_event *out_event, bool nonblock)
 Read an event from the event stream.
 
__api struct iio_channels_mask * iio_create_channels_mask (unsigned int nb_channels)
 Create a new empty channels mask.
 
__api void iio_channels_mask_destroy (struct iio_channels_mask *mask)
 Destroy a channels mask.
 
__api __check_ret ssize_t iio_device_get_sample_size (const struct iio_device *dev, const struct iio_channels_mask *mask)
 Get the current sample size.
 
__api __check_ret __pure long iio_channel_get_index (const struct iio_channel *chn)
 Get the index of the given channel.
 
__api __check_ret __cnst const struct iio_data_formatiio_channel_get_data_format (const struct iio_channel *chn)
 Get a pointer to a channel's data format structure.
 
__api void iio_channel_convert (const struct iio_channel *chn, void *dst, const void *src)
 Convert the sample from hardware format to host format.
 
__api void iio_channel_convert_inverse (const struct iio_channel *chn, void *dst, const void *src)
 Convert the sample from host format to hardware format.
 
__api __check_ret __pure unsigned int iio_device_get_debug_attrs_count (const struct iio_device *dev)
 Enumerate the debug attributes of the given device.
 
__api __check_ret __pure const struct iio_attriio_device_get_debug_attr (const struct iio_device *dev, unsigned int index)
 Get the debug attribute present at the given index.
 
__api __check_ret __pure const struct iio_attriio_device_find_debug_attr (const struct iio_device *dev, const char *name)
 Try to find a debug attribute by its name.
 
__api __check_ret int iio_device_reg_write (struct iio_device *dev, uint32_t address, uint32_t value)
 Set the value of a hardware register.
 
__api __check_ret int iio_device_reg_read (struct iio_device *dev, uint32_t address, uint32_t *value)
 Get the value of a hardware register.
 

Detailed Description

Public interface.

Warning
libiio includes source components released under different open-source licenses, including MIT, GPL, and LGPL. As a result, the license of the final binary is determined by how libiio is configured at build time. The specific build options selected can affect which licensing terms apply to the resulting binary. In most cases, particularly when building for Linux or other POSIX-compliant systems, the default configuration produces a shared library binary licensed under the GNU Lesser General Public License version 2.1 or later (LGPL-2.1-or-later).

Additionally, depending on the selected configuration options, some optional backends may link against external system libraries. These libraries have their own licensing terms and may influence the overall license of the resulting binary, based on how they are used and linked.

To ensure that the final license aligns with your project's compliance and distribution requirements, we strongly recommend reviewing your build configuration. You can enable a license compatibility check during configuration by adding the CMake option: -DLICENSE_CHECK=ON

Enumeration Type Documentation

◆ iio_chan_type

IIO channel type.

A IIO channel has a type specifying the type of data associated with the channel.

◆ iio_context_flags

Flags controlling context behavior;.

Enumerator
IIO_CTX_XML_INCLUDE_VALUES 

Include values in XML output When set, iio_context_get_xml() will read and serialize attribute values into the XML output.

◆ iio_event_direction

IIO event direction.

When applicable, this enum specifies the direction of the iio_event_type.

◆ iio_event_type

IIO event type.

Some IIO devices can deliver events. The type of the event can be specified by one of the iio_event_type values.

◆ iio_modifier

IIO channel modifier.

In a addition to a type a IIO channel can optionally have a channel modifier further specifying the data type of of the channel.