Soletta™ Framework
Framework for making IoT devices

Full online documentation | C API Index
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Data Structures | Macros | Typedefs | Functions
IIO

IIO (Linux Industrial I/O) API for Soletta. More...

Data Structures

struct  sol_iio_channel_config
 A configuration struct for an IIO channel. More...
 
struct  sol_iio_config
 A configuration struct for an IIO device. More...
 

Macros

#define SOL_IIO_CHANNEL_CONFIG_INIT
 Macro that may be used for initialized a sol_iio_channel_config. More...
 

Typedefs

typedef struct sol_iio_channel sol_iio_channel
 An IIO channel handle. More...
 
typedef struct
sol_iio_channel_config 
sol_iio_channel_config
 A configuration struct for an IIO channel. More...
 
typedef struct sol_iio_config sol_iio_config
 A configuration struct for an IIO device. More...
 
typedef struct sol_iio_device sol_iio_device
 An IIO device handle. More...
 

Functions

struct sol_iio_channelsol_iio_add_channel (struct sol_iio_device *device, const char *name, const struct sol_iio_channel_config *config)
 Add reading channel. More...
 
int sol_iio_address_device (const char *commands)
 Address an IIO device from a list of commands to find them. More...
 
const char * sol_iio_channel_get_name (const struct sol_iio_channel *channel)
 Gets the configuration attribute name of a channel. More...
 
void sol_iio_close (struct sol_iio_device *device)
 Close an IIO device. More...
 
int sol_iio_device_get_offset (const struct sol_iio_device *device, const char *prefix_name, double *offset)
 Gets the configuration offset attribute from one device. More...
 
int sol_iio_device_get_sampling_frequency (const struct sol_iio_device *device, const char *prefix_name, int *sampling_frequency)
 Gets the configuration sampling_frequency attribute from one device. More...
 
int sol_iio_device_get_scale (const struct sol_iio_device *device, const char *prefix_name, double *scale)
 Gets the configuration scale attribute from one device. More...
 
int sol_iio_device_start_buffer (struct sol_iio_device *device)
 Start reading device buffer. More...
 
int sol_iio_device_trigger (struct sol_iio_device *device)
 Manually 'pull' device current trigger. More...
 
int sol_iio_mount_calibration (struct sol_iio_device *device, sol_direction_vector *value)
 Perform the mount calibration. More...
 
struct sol_iio_devicesol_iio_open (int id, const struct sol_iio_config *config)
 Open an IIO device. More...
 
struct sol_str_slice sol_iio_read_channel_raw_buffer (struct sol_iio_channel *channel)
 Returns raw buffer with channel sample. More...
 
int sol_iio_read_channel_value (struct sol_iio_channel *channel, double *value)
 Read channel value. More...
 

Detailed Description

IIO (Linux Industrial I/O) API for Soletta.

Macro Definition Documentation

#define SOL_IIO_CHANNEL_CONFIG_INIT
Value:
{ \
.scale = -1.0, .offset = 0, .use_custom_offset = false }
#define SOL_IIO_CHANNEL_CONFIG_API_VERSION
Definition: sol-iio.h:92
#define SOL_SET_API_VERSION(expression)
This macro will cope with SOL_NO_API_VERSION and allows easy declaration of api_version fields...
Definition: sol-mainloop.h:660

Macro that may be used for initialized a sol_iio_channel_config.

This macro will init a with default values a sol_iio_channel_config. It'll start with scale -1.0 and without custom offset.

Examples:
/src/samples/iio+network/iio-gyroscope-console-and-mqtt-publish.c.

Referenced by main().

Typedef Documentation

A configuration struct for an IIO channel.

See Also
sol_iio_add_channel()

A configuration struct for an IIO device.

See Also
sol_iio_open()

Function Documentation

struct sol_iio_channel* sol_iio_add_channel ( struct sol_iio_device device,
const char *  name,
const struct sol_iio_channel_config config 
)

Add reading channel.

Parameters
deviceIIO handle of device to which channel is being add
nameName of channel. Eg 'in_anglvel_x'.
configChannel config.
Returns
A new IIO channel handle
Examples:
/src/samples/iio+network/iio-gyroscope-console-and-mqtt-publish.c.

Referenced by main().

int sol_iio_address_device ( const char *  commands)

Address an IIO device from a list of commands to find them.

IIO devices may exist on sysfs after being plugged, or need to be explicitly created if, for instance, they use I2C or SPI interfaces. This function provides a way of addressing an IIO device to get its IIO id from a series of space separated commands. Commands are processed from left to right and processing stops on first command that worked. IIO device id will be returned, or a negative number if no command resolved to an IIO device.

There are essentially five commands. It can be an absolute path (starting with '/') pointing to sysfs dir of device. Alternatively, it can be i2c/X-YYYY, for i2c device, where X is the bus number and YYYY is the device number, eg, 7-0069 for device 0x69 on bus 7. If its a raw number, will be interpreted as IIO device id and this function will only check the id. It can also be device name, as it appears on 'name' file on sysfs. Finally, it can describe a command to create an IIO device. In this case, command is a combination on the form create,<bus_type>,<rel_path>,<devnumber>,<devname>

  • bus_type is the bus type, supported values are: i2c
  • rel_path is the relative path for device on '/sys/devices', like 'platform/80860F41:05'
  • devnumber is device number on bus, like 0xA4
  • devname is device name, the one recognized by its driver

If device already exists, will just return its IIO id.

Parameters
commandsspace separated commands on format specified above. e.g. l3g4200d create,i2c,platform/80860F41:05,0x69,l3g4200d
Returns
IIO device id on success. A negative number means failure.
Examples:
/src/samples/iio+network/iio-gyroscope-console-and-mqtt-publish.c.

Referenced by main().

const char* sol_iio_channel_get_name ( const struct sol_iio_channel channel)

Gets the configuration attribute name of a channel.

Parameters
channelsol_iio_channel structure which the name is desired.
Returns
The configuration attribute name of the channel on success, NULL on error.
void sol_iio_close ( struct sol_iio_device device)

Close an IIO device.

Parameters
deviceIIO device handle to close
Examples:
/src/samples/iio+network/iio-gyroscope-console-and-mqtt-publish.c.

Referenced by main().

int sol_iio_device_get_offset ( const struct sol_iio_device device,
const char *  prefix_name,
double *  offset 
)

Gets the configuration offset attribute from one device.

Parameters
deviceThe sol_iio_device structure which the offset is desired
prefix_namepointer to the attribute name Eg: "in_anglvel_x"
offsetdata to be get from attribute name
Returns
0 on success, -errno on failure.
int sol_iio_device_get_sampling_frequency ( const struct sol_iio_device device,
const char *  prefix_name,
int *  sampling_frequency 
)

Gets the configuration sampling_frequency attribute from one device.

Parameters
deviceThe sol_iio_device structure which the sampling_frequency is desired
prefix_namepointer to the attribute name Eg: "in_anglvel"
sampling_frequencydata to be get from attribute name
Returns
0 on success, -errno on failure.
int sol_iio_device_get_scale ( const struct sol_iio_device device,
const char *  prefix_name,
double *  scale 
)

Gets the configuration scale attribute from one device.

Parameters
deviceThe sol_iio_device structure which the scale is desired
prefix_namepointer to the attribute name Eg: "in_anglvel_x"
scaledata to be get from attribute name
Returns
0 on success, -errno on failure.
int sol_iio_device_start_buffer ( struct sol_iio_device device)

Start reading device buffer.

Reading on buffer should start after all channels were enabled (which is done when a channel is added using sol_iio_add_channel()). So, call this function after having added all channels. Reading here means that the buffer will be opened; when real readings happens the callback set on config will be called.

Parameters
deviceIIO handler of device on which reading will be performed
Returns
0 if reading started successfully, if fail return error code always negative.
Examples:
/src/samples/iio+network/iio-gyroscope-console-and-mqtt-publish.c.

Referenced by main().

int sol_iio_device_trigger ( struct sol_iio_device device)

Manually 'pull' device current trigger.

If device current trigger has a 'trigger_now' file that start a reading on device, writes to it to produce a new reading

Parameters
deviceIIO handler of device to have its trigger manually 'pulled'.
Returns
0 if writing to file is successful, if fail return error code always negative.
int sol_iio_mount_calibration ( struct sol_iio_device device,
sol_direction_vector value 
)

Perform the mount calibration.

This function is meaningful only when mount_matrix is supported.

Parameters
devicedevice to get mount matrix
valuedata to be calibrated
Returns
0 if mount_matrix is exits and perform the calibration, -1 means does not support mount_matrix.
Examples:
/src/samples/iio+network/iio-gyroscope-console-and-mqtt-publish.c.

Referenced by iio_gyroscope_reader_cb().

struct sol_iio_device* sol_iio_open ( int  id,
const struct sol_iio_config config 
)

Open an IIO device.

Using different channel_id and the same configuration, one device can be opened multiple times

Parameters
idId of iio device. It's the number which identifies device on file system. Can be found at '/sys/bus/iio/devices/iio:deviceX'.
configIIO config.
Returns
A new IIO handle
Examples:
/src/samples/iio+network/iio-gyroscope-console-and-mqtt-publish.c.

Referenced by main().

struct sol_str_slice sol_iio_read_channel_raw_buffer ( struct sol_iio_channel channel)

Returns raw buffer with channel sample.

This function is meaningful only when buffer is enabled. Useful for reading samples bigger than 64 bits. For channels with 64 or less bits, prefer sol_iio_read_channel_value, with return a more meaningful value, adjusted by channel offset and scale.

Parameters
channelchannel to get raw buffer
Returns
a sol_str_slice containing channel raw readings. Slice will be empty if buffer is not enabled or if there are no readings yet.
Note
Buffer size is the same as storage bits (aligned to byte boundary).
int sol_iio_read_channel_value ( struct sol_iio_channel channel,
double *  value 
)

Read channel value.

If buffer is enabled, it will read from last buffer data. Callback 'sol_iio_reader_cb' is called when there are new data on buffer. If buffer is disabled, will read from channel file on sysfs.

Parameters
channelIIO channel handle to be read
valueWhere read value will be stored
Returns
0 if reading was performed correctly, if fail return error code always negative.
Examples:
/src/samples/iio+network/iio-gyroscope-console-and-mqtt-publish.c.

Referenced by iio_gyroscope_reader_cb().