My Project
Loading...
Searching...
No Matches
iio.h
Go to the documentation of this file.
1/* SPDX-License-Identifier: MIT */
2/*
3 * libiio - Library for interfacing industrial I/O (IIO) devices
4 *
5 * Copyright (C) 2014 Analog Devices, Inc.
6 * Author: Paul Cercueil <paul.cercueil@analog.com>
7 *
8 * Note: This header file is released under the MIT License as specified by
9 * the SPDX identifier above. However, libiio as a whole includes components
10 * under multiple open-source licenses. The license of the final binary
11 * depends on the build configuration and may differ from that of this file.
12 * Please review the full licensing information and configuration options
13 * to ensure compliance with applicable license terms.
14 */
15
36
39
40#ifndef __IIO_H__
41#define __IIO_H__
42
43#ifndef DOXYGEN
44
45#ifdef __cplusplus
46extern "C" {
47#endif
48
49#include <limits.h>
50#include <stddef.h>
51#include <stdint.h>
52#include <stdio.h>
53#include <stdlib.h>
54
55#if (defined(_WIN32) || defined(__MBED__))
56#ifndef _SSIZE_T_DEFINED
57typedef ptrdiff_t ssize_t;
58#define _SSIZE_T_DEFINED
59#endif
60#else
61#include <sys/types.h>
62#endif
63
64#if defined(_MSC_VER) && (_MSC_VER < 1800) && !defined(__BOOL_DEFINED)
65#undef bool
66#undef false
67#undef true
68#define bool char
69#define false 0
70#define true 1
71#else
72#include <stdbool.h>
73#endif
74
75#if defined(__GNUC__) && !defined(MATLAB_MEX_FILE) && !defined(MATLAB_LOADLIBRARY)
76#ifndef __cnst
77#define __cnst __attribute__((const))
78#endif
79#ifndef __pure
80#define __pure __attribute__((pure))
81#endif
82#define __notused __attribute__((unused))
83#ifdef IIO_CHECK_RET
84#define __check_ret __attribute__((warn_unused_result))
85#else
86#define __check_ret
87#endif
88#else
89#define __cnst
90#define __pure
91#define __notused
92#define __check_ret
93#endif
94
95#if !defined(_WIN32) && __GNUC__ >= 4 && !defined(MATLAB_MEX_FILE) && !defined(MATLAB_LOADLIBRARY)
96#define __iio_api_export __attribute__((visibility("default")))
97#define __iio_api_import
98#elif defined(_WIN32) && !defined(LIBIIO_STATIC)
99#define __iio_api_export __declspec(dllexport)
100#define __iio_api_import __declspec(dllimport)
101#else
102#define __iio_api_export
103#define __iio_api_import
104#endif
105
106#ifdef LIBIIO_EXPORTS
107#define __iio_api __iio_api_export
108#else
109#define __iio_api __iio_api_import
110#endif
111
112#define __api __iio_api
113
114#endif /* DOXYGEN */
115
116struct iio_attr;
117struct iio_block;
118struct iio_context;
119struct iio_device;
120struct iio_channel;
121struct iio_channels_mask;
122struct iio_event_stream;
123struct iio_buffer;
124struct iio_scan;
125struct iio_stream;
126
132 /* @brief No log output from the library */
133 LEVEL_NOLOG = 1,
134
135 /* @brief Only print error messages */
136 LEVEL_ERROR = 2,
137
138 /* @brief Also print warnings */
139 LEVEL_WARNING = 3,
140
141 /* @brief Also print noteworthy information */
142 LEVEL_INFO = 4,
143
144 /* @brief Also print debug messages */
145 LEVEL_DEBUG = 5,
146};
147
149#define IIO_TIMEOUT_BACKEND 0
151#define IIO_TIMEOUT_INFINITE (-1)
153#define IIO_TIMEOUT_NONBLOCK INT_MIN
154
165
175 FILE *out;
176
178 FILE *err;
179
183
189
196
204
207 unsigned int flags;
208
210 char __rsrv[32];
211};
212
213/*
214 * <linux/iio/types.h> header guard to protect these enums from being defined
215 * twice
216 */
217#ifndef _IIO_TYPES_H_
218#define _IIO_TYPES_H_
219
228 IIO_VOLTAGE,
229 IIO_CURRENT,
230 IIO_POWER,
231 IIO_ACCEL,
232 IIO_ANGL_VEL,
233 IIO_MAGN,
234 IIO_LIGHT,
235 IIO_INTENSITY,
236 IIO_PROXIMITY,
237 IIO_TEMP,
238 IIO_INCLI,
239 IIO_ROT,
240 IIO_ANGL,
241 IIO_TIMESTAMP,
242 IIO_CAPACITANCE,
243 IIO_ALTVOLTAGE,
244 IIO_CCT,
245 IIO_PRESSURE,
246 IIO_HUMIDITYRELATIVE,
247 IIO_ACTIVITY,
248 IIO_STEPS,
249 IIO_ENERGY,
250 IIO_DISTANCE,
251 IIO_VELOCITY,
252 IIO_CONCENTRATION,
253 IIO_RESISTANCE,
254 IIO_PH,
255 IIO_UVINDEX,
256 IIO_ELECTRICALCONDUCTIVITY,
257 IIO_COUNT,
258 IIO_INDEX,
259 IIO_GRAVITY,
260 IIO_POSITIONRELATIVE,
261 IIO_PHASE,
262 IIO_MASSCONCENTRATION,
263 IIO_DELTA_ANGL,
264 IIO_DELTA_VELOCITY,
265 IIO_COLORTEMP,
266 IIO_CHROMATICITY,
267 IIO_ATTENTION,
268 IIO_ALTCURRENT,
269 IIO_COVERAGE,
270 IIO_VOLUMEFLOW,
271 IIO_CHAN_TYPE_UNKNOWN = INT_MAX,
272};
273
282 IIO_NO_MOD,
283 IIO_MOD_X,
284 IIO_MOD_Y,
285 IIO_MOD_Z,
286 IIO_MOD_X_AND_Y,
287 IIO_MOD_X_AND_Z,
288 IIO_MOD_Y_AND_Z,
289 IIO_MOD_X_AND_Y_AND_Z,
290 IIO_MOD_X_OR_Y,
291 IIO_MOD_X_OR_Z,
292 IIO_MOD_Y_OR_Z,
293 IIO_MOD_X_OR_Y_OR_Z,
294 IIO_MOD_LIGHT_BOTH,
295 IIO_MOD_LIGHT_IR,
296 IIO_MOD_ROOT_SUM_SQUARED_X_Y,
297 IIO_MOD_SUM_SQUARED_X_Y_Z,
298 IIO_MOD_LIGHT_CLEAR,
299 IIO_MOD_LIGHT_RED,
300 IIO_MOD_LIGHT_GREEN,
301 IIO_MOD_LIGHT_BLUE,
302 IIO_MOD_QUATERNION,
303 IIO_MOD_TEMP_AMBIENT,
304 IIO_MOD_TEMP_OBJECT,
305 IIO_MOD_NORTH_MAGN,
306 IIO_MOD_NORTH_TRUE,
307 IIO_MOD_NORTH_MAGN_TILT_COMP,
308 IIO_MOD_NORTH_TRUE_TILT_COMP,
309 IIO_MOD_RUNNING,
310 IIO_MOD_JOGGING,
311 IIO_MOD_WALKING,
312 IIO_MOD_STILL,
313 IIO_MOD_ROOT_SUM_SQUARED_X_Y_Z,
314 IIO_MOD_I,
315 IIO_MOD_Q,
316 IIO_MOD_CO2,
317 IIO_MOD_VOC,
318 IIO_MOD_LIGHT_UV,
319 IIO_MOD_LIGHT_DUV,
320 IIO_MOD_PM1,
321 IIO_MOD_PM2P5,
322 IIO_MOD_PM4,
323 IIO_MOD_PM10,
324 IIO_MOD_ETHANOL,
325 IIO_MOD_H2,
326 IIO_MOD_O2,
327 IIO_MOD_LINEAR_X,
328 IIO_MOD_LINEAR_Y,
329 IIO_MOD_LINEAR_Z,
330 IIO_MOD_PITCH,
331 IIO_MOD_YAW,
332 IIO_MOD_ROLL,
333 IIO_MOD_LIGHT_UVA,
334 IIO_MOD_LIGHT_UVB,
335 IIO_MOD_RMS,
336 IIO_MOD_ACTIVE,
337 IIO_MOD_REACTIVE,
338 IIO_MOD_APPARENT,
339 IIO_MOD_QUATERNION_AXIS,
340};
341
350 IIO_EV_TYPE_THRESH,
351 IIO_EV_TYPE_MAG,
352 IIO_EV_TYPE_ROC,
353 IIO_EV_TYPE_THRESH_ADAPTIVE,
354 IIO_EV_TYPE_MAG_ADAPTIVE,
355 IIO_EV_TYPE_CHANGE,
356 IIO_EV_TYPE_MAG_REFERENCED,
357 IIO_EV_TYPE_GESTURE,
358 IIO_EV_TYPE_FAULT,
359};
360
368 IIO_EV_DIR_EITHER,
369 IIO_EV_DIR_RISING,
370 IIO_EV_DIR_FALLING,
371 IIO_EV_DIR_NONE,
372 IIO_EV_DIR_SINGLETAP,
373 IIO_EV_DIR_DOUBLETAP,
374 IIO_EV_DIR_FAULT_OPENWIRE,
375};
376
377#endif /* _IIO_TYPES_H_ */
378
379/* ---------------------------------------------------------------------------*/
380/* ---------------------------- Error handling -------------------------------*/
387static inline __check_ret void *iio_ptr(int err)
388{
389 return (void *)(intptr_t)err;
390}
391
395static inline __check_ret int iio_err(const void *ptr)
396{
397 return (uintptr_t)ptr >= (uintptr_t)-4095 ? (int)(intptr_t)ptr : 0;
398}
399
403static inline __check_ret void *iio_err_cast(const void *ptr)
404{
405 return (void *)ptr;
406}
407 /* ------------------------------------------------------------------*/
409/* ------------------------- Attributes functions ----------------------------*/
415
422__api __check_ret ssize_t iio_attr_read_raw(const struct iio_attr *attr, char *dst, size_t len);
423
429#ifndef __cplusplus
430#define iio_attr_read(attr, ptr) \
431 _Generic((ptr), \
432 bool *: iio_attr_read_bool, \
433 long long *: iio_attr_read_longlong, \
434 double *: iio_attr_read_double)(attr, ptr)
435#endif /* __cplusplus */
436
443__api __check_ret ssize_t iio_attr_write_raw(
444 const struct iio_attr *attr, const void *src, size_t len);
445
451#ifndef __cplusplus
452#define iio_attr_write(attr, val) \
453 _Generic((val), \
454 const char *: iio_attr_write_string, \
455 char *: iio_attr_write_string, \
456 bool: iio_attr_write_bool, \
457 long long: iio_attr_write_longlong, \
458 double: iio_attr_write_double)(attr, val)
459#endif /* __cplusplus */
460
464__api __pure const char *iio_attr_get_name(const struct iio_attr *attr);
465
469__api __check_ret __pure const char *iio_attr_get_filename(const struct iio_attr *attr);
470
475__api __pure const char *iio_attr_get_static_value(const struct iio_attr *attr);
476
486__api int iio_attr_get_range(const struct iio_attr *attr, double *min, double *step, double *max);
487
499__api int iio_attr_get_available(const struct iio_attr *attr, char ***list, size_t *count);
500
524 const struct iio_attr *attr, char *buf, size_t buflen, char **list, size_t *count);
525
530__api void iio_available_list_free(char **list, size_t count);
531 /* ------------------------------------------------------------------*/
533/* ------------------------- Scan functions ----------------------------------*/
539
555__api __check_ret struct iio_scan *iio_scan(
556 const struct iio_context_params *params, const char *backends);
557
562__api void iio_scan_destroy(struct iio_scan *ctx);
563
568__api __check_ret __pure size_t iio_scan_get_results_count(const struct iio_scan *ctx);
569
575__api __check_ret __pure const char *iio_scan_get_description(
576 const struct iio_scan *ctx, size_t idx);
577
583__api __check_ret __pure const char *iio_scan_get_uri(const struct iio_scan *ctx, size_t idx);
584 /* ------------------------------------------------------------------*/
586/* ------------------------- Top-level functions -----------------------------*/
589
595__api void iio_strerror(int err, char *dst, size_t len);
596
602__api __check_ret bool iio_has_backend(
603 const struct iio_context_params *params, const char *backend);
604
607__api __check_ret __cnst unsigned int iio_get_builtin_backends_count(void);
608
613__api __check_ret __cnst const char *iio_get_builtin_backend(unsigned int index);
614 /* ------------------------------------------------------------------*/
616/* ------------------------- Context functions -------------------------------*/
621
670__api __check_ret struct iio_context *iio_create_context(
671 const struct iio_context_params *params, const char *uri);
672
677__api void iio_context_destroy(struct iio_context *ctx);
678
685__api __pure unsigned int iio_context_get_version_major(const struct iio_context *ctx);
686
693__api __pure unsigned int iio_context_get_version_minor(const struct iio_context *ctx);
694
702__api __pure unsigned int iio_context_get_version_patch(const struct iio_context *ctx);
703
710__api __pure const char *iio_context_get_version_tag(const struct iio_context *ctx);
711
716__api __check_ret char *iio_context_get_xml(const struct iio_context *ctx);
717
725__api __check_ret __pure const char *iio_context_get_name(const struct iio_context *ctx);
726
733__api __check_ret __pure const char *iio_context_get_description(const struct iio_context *ctx);
734
740__api __check_ret __pure unsigned int iio_context_get_attrs_count(const struct iio_context *ctx);
741
747__api __check_ret __pure const struct iio_attr *iio_context_get_attr(
748 const struct iio_context *ctx, unsigned int index);
749
757__api __check_ret __pure const struct iio_attr *iio_context_find_attr(
758 const struct iio_context *ctx, const char *name);
759
763__api __check_ret __pure unsigned int iio_context_get_devices_count(const struct iio_context *ctx);
764
770__api __check_ret __pure struct iio_device *iio_context_get_device(
771 const struct iio_context *ctx, unsigned int index);
772
780__api __check_ret __pure struct iio_device *iio_context_find_device(
781 const struct iio_context *ctx, const char *name);
782
793__api __check_ret int iio_context_set_timeout(struct iio_context *ctx, int timeout_ms);
794
798__api __cnst const struct iio_context_params *iio_context_get_params(const struct iio_context *ctx);
799
803__api void iio_context_set_data(struct iio_context *ctx, void *data);
804
808__api void *iio_context_get_data(const struct iio_context *ctx);
809
819__api __check_ret int iio_context_ping(struct iio_context *ctx);
820 /* ------------------------------------------------------------------*/
822/* ------------------------- Device functions --------------------------------*/
827
831__api __check_ret __pure const struct iio_context *iio_device_get_context(
832 const struct iio_device *dev);
833
837__api __check_ret __pure const char *iio_device_get_id(const struct iio_device *dev);
838
844__api __check_ret __pure const char *iio_device_get_name(const struct iio_device *dev);
845
851__api __check_ret __pure const char *iio_device_get_label(const struct iio_device *dev);
852
856__api __check_ret __pure unsigned int iio_device_get_channels_count(const struct iio_device *dev);
857
861__api __check_ret __pure unsigned int iio_device_get_attrs_count(const struct iio_device *dev);
862
866__api __check_ret __pure unsigned int iio_device_get_buffers_count(const struct iio_device *dev);
867
873__api __check_ret __pure struct iio_channel *iio_device_get_channel(
874 const struct iio_device *dev, unsigned int index);
875
881__api __check_ret __pure const struct iio_attr *iio_device_get_attr(
882 const struct iio_device *dev, unsigned int index);
883
889__api __check_ret __pure struct iio_buffer *iio_device_get_buffer(
890 const struct iio_device *dev, unsigned int index);
891
900__api __check_ret __pure struct iio_channel *iio_device_find_channel(
901 const struct iio_device *dev, const char *name, bool output);
902
914__api __check_ret __pure const struct iio_attr *iio_device_find_attr(
915 const struct iio_device *dev, const char *name);
916
920__api void iio_device_set_data(struct iio_device *dev, void *data);
921
925__api void *iio_device_get_data(const struct iio_device *dev);
926
934__api __check_ret const struct iio_device *iio_device_get_trigger(const struct iio_device *dev);
935
942__api __check_ret int iio_device_set_trigger(
943 const struct iio_device *dev, const struct iio_device *trigger);
944
948__api __check_ret __pure bool iio_device_is_trigger(const struct iio_device *dev);
949 /* ------------------------------------------------------------------*/
951/* ------------------------- Channel functions -------------------------------*/
956
960__api __check_ret __pure const struct iio_device *iio_channel_get_device(
961 const struct iio_channel *chn);
962
966__api __check_ret __pure const char *iio_channel_get_id(const struct iio_channel *chn);
967
973__api __check_ret __pure const char *iio_channel_get_name(const struct iio_channel *chn);
974
980__api __check_ret __pure const char *iio_channel_get_label(const struct iio_channel *chn);
981
985__api __check_ret __pure bool iio_channel_is_output(const struct iio_channel *chn);
986
994__api __check_ret __pure bool iio_channel_is_scan_element(const struct iio_channel *chn);
995
999__api __check_ret __pure unsigned int iio_channel_get_attrs_count(const struct iio_channel *chn);
1000
1006__api __check_ret __pure const struct iio_attr *iio_channel_get_attr(
1007 const struct iio_channel *chn, unsigned int index);
1008
1016__api __check_ret __pure const struct iio_attr *iio_channel_find_attr(
1017 const struct iio_channel *chn, const char *name);
1018
1022__api __check_ret __pure unsigned int iio_channel_get_event_attrs_count(
1023 const struct iio_channel *chn);
1024
1030__api __check_ret __pure const struct iio_attr *iio_channel_get_event_attr(
1031 const struct iio_channel *chn, unsigned int index);
1032
1040__api __check_ret __pure const struct iio_attr *iio_channel_find_event_attr(
1041 const struct iio_channel *chn, const char *name);
1042
1046__api void iio_channel_enable(const struct iio_channel *chn, struct iio_channels_mask *mask);
1047
1051__api void iio_channel_disable(const struct iio_channel *chn, struct iio_channels_mask *mask);
1052
1057__api __check_ret bool iio_channel_is_enabled(
1058 const struct iio_channel *chn, const struct iio_channels_mask *mask);
1059
1069__api __check_ret size_t iio_channel_read(const struct iio_channel *chn,
1070 const struct iio_block *block, void *dst, size_t len, bool raw);
1071
1081__api __check_ret size_t iio_channel_write(const struct iio_channel *chn, struct iio_block *block,
1082 const void *src, size_t len, bool raw);
1083
1087__api void iio_channel_set_data(struct iio_channel *chn, void *data);
1088
1092__api void *iio_channel_get_data(const struct iio_channel *chn);
1093
1099__api __check_ret __pure enum iio_chan_type iio_channel_get_type(const struct iio_channel *chn);
1100
1104__api __check_ret __pure enum iio_modifier iio_channel_get_modifier(const struct iio_channel *chn);
1105 /* ------------------------------------------------------------------*/
1107/* ------------------------- Buffer functions --------------------------------*/
1112
1116__api __check_ret __pure const struct iio_device *iio_buffer_get_device(
1117 const struct iio_buffer *buf);
1118
1122__api __check_ret __pure unsigned int iio_buffer_get_attrs_count(const struct iio_buffer *buf);
1123
1129__api __check_ret __pure const struct iio_attr *iio_buffer_get_attr(
1130 const struct iio_buffer *buf, unsigned int index);
1131
1135__api __check_ret __pure unsigned int iio_buffer_get_scan_elements_count(
1136 const struct iio_buffer *buf);
1137
1143__api __check_ret __pure const struct iio_channel *iio_buffer_get_scan_element(
1144 const struct iio_buffer *buf, unsigned int index);
1145
1153__api __check_ret __pure const struct iio_attr *iio_buffer_find_attr(
1154 const struct iio_buffer *buf, const char *name);
1155
1159__api __check_ret __pure bool iio_buffer_is_output(const struct iio_buffer *buf);
1160
1164__api void iio_buffer_set_data(struct iio_buffer *buf, void *data);
1165
1169__api void *iio_buffer_get_data(const struct iio_buffer *buf);
1170 /* ------------------------------------------------------------------*/
1172/* ------------------------- Buffer Stream functions -------------------------*/
1177
1184__api __check_ret struct iio_buffer_stream *iio_buffer_open(
1185 struct iio_buffer *buf, const struct iio_channels_mask *mask);
1186
1189__api void iio_buffer_close(struct iio_buffer_stream *buf_stream);
1190
1193__api void iio_buffer_stream_cancel(struct iio_buffer_stream *buf_stream);
1194
1199__api __check_ret int iio_buffer_stream_start(struct iio_buffer_stream *buf_stream);
1200
1205__api int iio_buffer_stream_stop(struct iio_buffer_stream *buf_stream);
1206
1210__api const struct iio_channels_mask *iio_buffer_stream_get_channels_mask(
1211 const struct iio_buffer_stream *buf_stream);
1212 /* ------------------------------------------------------------------*/
1214/* -------------------------- Block functions --------------------------------*/
1219
1226 struct iio_buffer_stream *buf_stream, size_t size);
1227
1233__api void iio_block_destroy(struct iio_block *block);
1234
1243__api __check_ret int iio_block_get_dmabuf_fd(const struct iio_block *block);
1244
1257__api int iio_block_disable_cpu_access(struct iio_block *block, bool disable);
1258
1267__api void *iio_block_start(const struct iio_block *block);
1268
1291__api void *iio_block_first(const struct iio_block *block, const struct iio_channel *chn);
1292
1298__api void *iio_block_end(const struct iio_block *block);
1299
1314__api __check_ret ssize_t iio_block_foreach_sample(const struct iio_block *block,
1315 const struct iio_channels_mask *mask,
1316 ssize_t (*callback)(
1317 const struct iio_channel *chn, void *src, size_t bytes, void *d),
1318 void *data);
1319
1331__api int iio_block_enqueue(struct iio_block *block, size_t bytes_used, bool cyclic);
1332
1339__api int iio_block_dequeue(struct iio_block *block, bool nonblock);
1340
1345 /* ------------------------------------------------------------------*/
1347/* ------------------------- Stream functions --------------------------------*/
1352
1361__api __check_ret struct iio_stream *iio_buffer_create_stream(struct iio_buffer *buffer,
1362 size_t nb_blocks, size_t samples_count, struct iio_channels_mask *mask);
1363
1366__api void iio_stream_cancel(struct iio_stream *stream);
1367
1370__api void iio_stream_destroy(struct iio_stream *stream);
1371
1376__api __check_ret const struct iio_block *iio_stream_get_next_block(struct iio_stream *stream);
1377 /* ------------------------------------------------------------------*/
1379/* ---------------------------- HWMON support --------------------------------*/
1393 HWMON_VOLTAGE,
1394 HWMON_FAN,
1395 HWMON_PWM,
1396 HWMON_TEMP,
1397 HWMON_CURRENT,
1398 HWMON_POWER,
1399 HWMON_ENERGY,
1400 HWMON_HUMIDITY,
1401 HWMON_INTRUSION,
1402 HWMON_CHAN_TYPE_UNKNOWN = IIO_CHAN_TYPE_UNKNOWN,
1403};
1404
1411static inline enum hwmon_chan_type hwmon_channel_get_type(const struct iio_channel *chn)
1412{
1413 return (enum hwmon_chan_type)iio_channel_get_type(chn);
1414}
1415
1421static inline bool iio_device_is_hwmon(const struct iio_device *dev)
1422{
1423 const char *id = iio_device_get_id(dev);
1424
1425 return id[0] == 'h';
1426}
1427 /* ------------------------------------------------------------------*/
1429/* ---------------------------- IIO events support ---------------------------*/
1438 uint64_t id;
1439 int64_t timestamp;
1440};
1441
1449static inline enum iio_event_type iio_event_get_type(const struct iio_event *event)
1450{
1451 return (enum iio_event_type)((event->id >> 56) & 0xff);
1452}
1453
1461static inline enum iio_event_direction iio_event_get_direction(const struct iio_event *event)
1462{
1463 return (enum iio_event_direction)((event->id >> 48) & 0x7f);
1464}
1465
1473__api __check_ret const struct iio_channel *iio_event_get_channel(
1474 const struct iio_event *event, const struct iio_device *dev, bool diff);
1475
1481__api __check_ret struct iio_event_stream *iio_device_create_event_stream(
1482 const struct iio_device *dev);
1483
1487__api void iio_event_stream_destroy(struct iio_event_stream *stream);
1488
1503 struct iio_event_stream *stream, struct iio_event *out_event, bool nonblock);
1504 /* ------------------------------------------------------------------*/
1506/* ------------------------- Low-level functions -----------------------------*/
1518 unsigned int length;
1519
1521 unsigned int bits;
1522
1524 unsigned int shift;
1525
1528
1531
1533 bool is_be;
1534
1537
1539 double scale;
1540
1542 unsigned int repeat;
1543
1546 double offset;
1547
1550};
1551
1556__api struct iio_channels_mask *iio_create_channels_mask(unsigned int nb_channels);
1557
1560__api void iio_channels_mask_destroy(struct iio_channels_mask *mask);
1561
1570__api __check_ret ssize_t iio_device_get_sample_size(
1571 const struct iio_device *dev, const struct iio_channels_mask *mask);
1572
1577__api __check_ret __pure long iio_channel_get_index(const struct iio_channel *chn);
1578
1582__api __check_ret __cnst const struct iio_data_format *iio_channel_get_data_format(
1583 const struct iio_channel *chn);
1584
1590__api void iio_channel_convert(const struct iio_channel *chn, void *dst, const void *src);
1591
1597__api void iio_channel_convert_inverse(const struct iio_channel *chn, void *dst, const void *src);
1598
1626__api __check_ret int iio_channel_refresh_format(struct iio_channel *chn);
1627
1631__api __check_ret __pure unsigned int iio_device_get_event_attrs_count(
1632 const struct iio_device *dev);
1633
1639__api __check_ret __pure const struct iio_attr *iio_device_get_event_attr(
1640 const struct iio_device *dev, unsigned int index);
1641
1649__api __check_ret __pure const struct iio_attr *iio_device_find_event_attr(
1650 const struct iio_device *dev, const char *name);
1651
1655__api __check_ret __pure unsigned int iio_device_get_debug_attrs_count(
1656 const struct iio_device *dev);
1657
1663__api __check_ret __pure const struct iio_attr *iio_device_get_debug_attr(
1664 const struct iio_device *dev, unsigned int index);
1665
1673__api __check_ret __pure const struct iio_attr *iio_device_find_debug_attr(
1674 const struct iio_device *dev, const char *name);
1675
1682__api __check_ret int iio_device_reg_write(
1683 struct iio_device *dev, uint32_t address, uint32_t value);
1684
1691__api __check_ret int iio_device_reg_read(
1692 struct iio_device *dev, uint32_t address, uint32_t *value);
1693
1695
1696#ifndef DOXYGEN
1697/* These functions can be used directly, but should be used through the generic
1698 * macros iio_attr_{read,write}() */
1699
1700__api __check_ret int iio_attr_read_bool(const struct iio_attr *attr, bool *val);
1701
1702__api __check_ret int iio_attr_read_longlong(const struct iio_attr *attr, long long *val);
1703
1704__api __check_ret int iio_attr_read_double(const struct iio_attr *attr, double *val);
1705
1706__api __check_ret ssize_t iio_attr_write_string(const struct iio_attr *attr, const char *src);
1707
1708__api __check_ret int iio_attr_write_bool(const struct iio_attr *attr, bool val);
1709
1710__api __check_ret int iio_attr_write_longlong(const struct iio_attr *attr, long long val);
1711
1712__api __check_ret int iio_attr_write_double(const struct iio_attr *attr, double val);
1713
1714#endif /* DOXYGEN */
1715
1716#ifdef __cplusplus
1717}
1718#endif
1719
1720#undef __api
1721
1722#endif /* __IIO_H__ */
ssize_t iio_attr_write_raw(const struct iio_attr *attr, const void *src, size_t len)
Set the value of the given attribute.
void iio_available_list_free(char **list, size_t count)
Free the resources allocated only by iio_attr_get_available().
const char * iio_attr_get_static_value(const struct iio_attr *attr)
Retrieve the static value of an attribute.
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'.
const char * iio_attr_get_filename(const struct iio_attr *attr)
Retrieve the filename of an attribute.
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....
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'.
ssize_t iio_attr_read_raw(const struct iio_attr *attr, char *dst, size_t len)
Read the content of the given attribute.
const char * iio_attr_get_name(const struct iio_attr *attr)
Retrieve the name of an attribute.
void * iio_block_end(const struct iio_block *block)
Get the address after the last sample in a block.
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.
int iio_block_enqueue(struct iio_block *block, size_t bytes_used, bool cyclic)
Enqueue the given iio_block to the buffer's queue.
void iio_block_destroy(struct iio_block *block)
Destroy the given block.
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.
int iio_block_get_dmabuf_fd(const struct iio_block *block)
Get the file descriptor of the underlying DMABUF object.
void * iio_block_start(const struct iio_block *block)
Get the start address of the block.
void * iio_block_first(const struct iio_block *block, const struct iio_channel *chn)
Find the first sample of a channel in a block.
struct iio_buffer_stream * iio_block_get_buffer_stream(const struct iio_block *block)
Retrieve a pointer to the iio_buffer_stream structure.
int iio_block_dequeue(struct iio_block *block, bool nonblock)
Dequeue the given iio_block from the buffer's queue.
int iio_block_disable_cpu_access(struct iio_block *block, bool disable)
Disable CPU access of a given block.
struct iio_buffer_stream * iio_buffer_open(struct iio_buffer *buf, const struct iio_channels_mask *mask)
Open a buffer for data streaming.
int iio_buffer_stream_start(struct iio_buffer_stream *buf_stream)
Start the buffer stream.
void iio_buffer_stream_cancel(struct iio_buffer_stream *buf_stream)
Cancel all buffer stream operations.
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.
int iio_buffer_stream_stop(struct iio_buffer_stream *buf_stream)
Stop the buffer stream.
void iio_buffer_close(struct iio_buffer_stream *buf_stream)
Close a buffer stream.
void iio_buffer_set_data(struct iio_buffer *buf, void *data)
Associate a pointer to an iio_buffer structure.
unsigned int iio_buffer_get_attrs_count(const struct iio_buffer *buf)
Enumerate the attributes of the given buffer.
const struct iio_attr * iio_buffer_get_attr(const struct iio_buffer *buf, unsigned int index)
Get the buffer-specific attribute present at the given index.
const struct iio_attr * iio_buffer_find_attr(const struct iio_buffer *buf, const char *name)
Try to find a buffer-specific attribute by its name.
const struct iio_device * iio_buffer_get_device(const struct iio_buffer *buf)
Retrieve a pointer to the iio_device structure.
bool iio_buffer_is_output(const struct iio_buffer *buf)
Returns true if the buffer is an output buffer.
void * iio_buffer_get_data(const struct iio_buffer *buf)
Retrieve a previously associated pointer of an iio_buffer structure.
unsigned int iio_buffer_get_scan_elements_count(const struct iio_buffer *buf)
Enumerate the scan elements of the given buffer.
const struct iio_channel * iio_buffer_get_scan_element(const struct iio_buffer *buf, unsigned int index)
Get the scan element present at the given index.
const struct iio_attr * iio_channel_find_attr(const struct iio_channel *chn, const char *name)
Try to find a channel-specific attribute by its name.
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.
void iio_channel_enable(const struct iio_channel *chn, struct iio_channels_mask *mask)
Enable the given channel.
const char * iio_channel_get_name(const struct iio_channel *chn)
Retrieve the channel name (e.g. vccint).
void * iio_channel_get_data(const struct iio_channel *chn)
Retrieve a previously associated pointer of an iio_channel structure.
void iio_channel_disable(const struct iio_channel *chn, struct iio_channels_mask *mask)
Disable the given channel.
unsigned int iio_channel_get_attrs_count(const struct iio_channel *chn)
Enumerate the channel-specific attributes of the given channel.
bool iio_channel_is_enabled(const struct iio_channel *chn, const struct iio_channels_mask *mask)
Returns True if the channel is enabled.
const struct iio_device * iio_channel_get_device(const struct iio_channel *chn)
Retrieve a pointer to the iio_device structure.
const struct iio_attr * iio_channel_find_event_attr(const struct iio_channel *chn, const char *name)
Try to find a channel event attribute by its name.
const char * iio_channel_get_label(const struct iio_channel *chn)
Retrieve the channel label (e.g. anglY).
void iio_channel_set_data(struct iio_channel *chn, void *data)
Associate a pointer to an iio_channel structure.
bool iio_channel_is_scan_element(const struct iio_channel *chn)
Return True if the given channel is a scan element.
const char * iio_channel_get_id(const struct iio_channel *chn)
Retrieve the channel ID (e.g. voltage0).
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.
unsigned int iio_channel_get_event_attrs_count(const struct iio_channel *chn)
Enumerate the event attributes of the given channel.
const struct iio_attr * iio_channel_get_attr(const struct iio_channel *chn, unsigned int index)
Get the channel-specific attribute present at the given index.
const struct iio_attr * iio_channel_get_event_attr(const struct iio_channel *chn, unsigned int index)
Get the event attribute present at the given index.
enum iio_modifier iio_channel_get_modifier(const struct iio_channel *chn)
Get the modifier type of the given channel.
bool iio_channel_is_output(const struct iio_channel *chn)
Return True if the given channel is an output channel.
enum iio_chan_type iio_channel_get_type(const struct iio_channel *chn)
Get the type of the given channel.
void iio_context_destroy(struct iio_context *ctx)
Destroy the given context.
struct iio_device * iio_context_find_device(const struct iio_context *ctx, const char *name)
Try to find a device structure by its ID, label or name.
void * iio_context_get_data(const struct iio_context *ctx)
Retrieve a previously associated pointer of an iio_context structure.
unsigned int iio_context_get_version_minor(const struct iio_context *ctx)
Get the minor number of the library version.
unsigned int iio_context_get_attrs_count(const struct iio_context *ctx)
Get the number of context-specific attributes.
const struct iio_attr * iio_context_find_attr(const struct iio_context *ctx, const char *name)
Try to find a context-specific attribute by its name.
char * iio_context_get_xml(const struct iio_context *ctx)
Obtain a XML representation of the given context.
const struct iio_attr * iio_context_get_attr(const struct iio_context *ctx, unsigned int index)
Retrieve the context-specific attribute at the given index.
unsigned int iio_context_get_devices_count(const struct iio_context *ctx)
Enumerate the devices found in the given context.
const struct iio_context_params * iio_context_get_params(const struct iio_context *ctx)
Get a pointer to the params structure.
const char * iio_context_get_description(const struct iio_context *ctx)
Get a description of the given context.
unsigned int iio_context_get_version_patch(const struct iio_context *ctx)
Get the patch number of the library version.
const char * iio_context_get_version_tag(const struct iio_context *ctx)
Get the git hash string of the library version.
unsigned int iio_context_get_version_major(const struct iio_context *ctx)
Get the major number of the library version.
int iio_context_ping(struct iio_context *ctx)
Ping the IIO context to check if it is still responsive.
void iio_context_set_data(struct iio_context *ctx, void *data)
Associate a pointer to an iio_context structure.
const char * iio_context_get_name(const struct iio_context *ctx)
Get the name of the given context.
struct iio_device * iio_context_get_device(const struct iio_context *ctx, unsigned int index)
Get the device present at the given index.
struct iio_context * iio_create_context(const struct iio_context_params *params, const char *uri)
Create a context from a URI description.
int iio_context_set_timeout(struct iio_context *ctx, int timeout_ms)
Set a timeout for I/O operations.
void iio_channel_convert_inverse(const struct iio_channel *chn, void *dst, const void *src)
Convert the sample from host format to hardware format.
unsigned int iio_device_get_debug_attrs_count(const struct iio_device *dev)
Enumerate the debug attributes of the given device.
long iio_channel_get_index(const struct iio_channel *chn)
Get the index of the given channel.
int iio_device_reg_read(struct iio_device *dev, uint32_t address, uint32_t *value)
Get the value of a hardware register.
unsigned int iio_device_get_event_attrs_count(const struct iio_device *dev)
Enumerate the event attributes of the given device.
ssize_t iio_device_get_sample_size(const struct iio_device *dev, const struct iio_channels_mask *mask)
Get the current sample size.
void iio_channels_mask_destroy(struct iio_channels_mask *mask)
Destroy a channels mask.
const struct iio_data_format * iio_channel_get_data_format(const struct iio_channel *chn)
Get a pointer to a channel's data format structure.
int iio_channel_refresh_format(struct iio_channel *chn)
Refresh the data format of a scan element channel from hardware.
const struct iio_attr * iio_device_get_debug_attr(const struct iio_device *dev, unsigned int index)
Get the debug attribute present at the given index.
const struct iio_attr * iio_device_get_event_attr(const struct iio_device *dev, unsigned int index)
Get the event attribute present at the given index.
struct iio_channels_mask * iio_create_channels_mask(unsigned int nb_channels)
Create a new empty channels mask.
const struct iio_attr * iio_device_find_debug_attr(const struct iio_device *dev, const char *name)
Try to find a debug attribute by its name.
int iio_device_reg_write(struct iio_device *dev, uint32_t address, uint32_t value)
Set the value of a hardware register.
const struct iio_attr * iio_device_find_event_attr(const struct iio_device *dev, const char *name)
Try to find an event attribute by its name.
void iio_channel_convert(const struct iio_channel *chn, void *dst, const void *src)
Convert the sample from hardware format to host format.
const char * iio_device_get_name(const struct iio_device *dev)
Retrieve the device name (e.g. xadc).
unsigned int iio_device_get_buffers_count(const struct iio_device *dev)
Enumerate the buffers of the given device.
const struct iio_attr * iio_device_find_attr(const struct iio_device *dev, const char *name)
Try to find a device-specific attribute by its name.
unsigned int iio_device_get_attrs_count(const struct iio_device *dev)
Enumerate the device-specific attributes of the given device.
bool iio_device_is_trigger(const struct iio_device *dev)
Return True if the given device is a trigger.
void * iio_device_get_data(const struct iio_device *dev)
Retrieve a previously associated pointer of an iio_device structure.
const struct iio_context * iio_device_get_context(const struct iio_device *dev)
Retrieve a pointer to the iio_context structure.
unsigned int iio_device_get_channels_count(const struct iio_device *dev)
Enumerate the channels of the given device.
struct iio_channel * iio_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.
const char * iio_device_get_label(const struct iio_device *dev)
Retrieve the device label (e.g. lo_pll0_rx_adf4351).
struct iio_channel * iio_device_get_channel(const struct iio_device *dev, unsigned int index)
Get the channel present at the given index.
const struct iio_attr * iio_device_get_attr(const struct iio_device *dev, unsigned int index)
Get the device-specific attribute present at the given index.
struct iio_buffer * iio_device_get_buffer(const struct iio_device *dev, unsigned int index)
Get the buffer present at the given index.
const struct iio_device * iio_device_get_trigger(const struct iio_device *dev)
Retrieve the trigger of a given device.
void iio_device_set_data(struct iio_device *dev, void *data)
Associate a pointer to an iio_device structure.
const char * iio_device_get_id(const struct iio_device *dev)
Retrieve the device ID (e.g. iio:device0).
int iio_device_set_trigger(const struct iio_device *dev, const struct iio_device *trigger)
Associate a trigger to a given device.
void iio_event_stream_destroy(struct iio_event_stream *stream)
Destroy the given event stream.
int iio_event_stream_read(struct iio_event_stream *stream, struct iio_event *out_event, bool nonblock)
Read an event from the event stream.
const struct iio_channel * iio_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.
struct iio_event_stream * iio_device_create_event_stream(const struct iio_device *dev)
Create an events stream for the given IIO device.
hwmon_chan_type
Hwmon channel type.
Definition iio.h:1392
const char * iio_scan_get_description(const struct iio_scan *ctx, size_t idx)
Get description of scanned context.
const char * iio_scan_get_uri(const struct iio_scan *ctx, size_t idx)
Get URI of scanned context.
void iio_scan_destroy(struct iio_scan *ctx)
Destroy the given scan context.
size_t iio_scan_get_results_count(const struct iio_scan *ctx)
Get number of results of a scan operation.
void iio_stream_cancel(struct iio_stream *stream)
Cancel all stream operations.
void iio_stream_destroy(struct iio_stream *stream)
Destroy the given stream object.
const struct iio_block * iio_stream_get_next_block(struct iio_stream *stream)
Get a pointer to the next data block.
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.
const char * iio_get_builtin_backend(unsigned int index)
Retrieve the name of a given built-in backend.
bool iio_has_backend(const struct iio_context_params *params, const char *backend)
Check if the specified backend is available.
void iio_strerror(int err, char *dst, size_t len)
Get a string description of an error code.
unsigned int iio_get_builtin_backends_count(void)
Get the number of available built-in backends.
iio_event_type
IIO event type.
Definition iio.h:349
iio_chan_type
IIO channel type.
Definition iio.h:227
iio_event_direction
IIO event direction.
Definition iio.h:367
iio_modifier
IIO channel modifier.
Definition iio.h:281
iio_context_flags
Flags controlling context behavior;.
Definition iio.h:159
@ IIO_CTX_XML_INCLUDE_VALUES
Include values in XML output When set, iio_context_get_xml() will read and serialize attribute values...
Definition iio.h:163
iio_log_level
Level of verbosity of libiio's log output.
Definition iio.h:131
Structure holding meta-data for an attribute.
Definition iio-backend.h:88
A block of memory containing data samples.
An opened buffer ready for data streaming.
An input or output buffer, used to read or write samples.
Represents an input or output channel of a device.
IIO context creation information.
Definition iio.h:173
unsigned int flags
Flags that control context behavior. Bitmask of values from enum iio_context_flags.
Definition iio.h:207
FILE * err
Handle to the error output. If NULL, defaults to stderr.
Definition iio.h:178
char __rsrv[32]
Reserved for future fields.
Definition iio.h:210
enum iio_log_level log_level
Log level to use. Defaults to the log level that was specified at compilation.
Definition iio.h:182
enum iio_log_level timestamp_level
Under this log level (excluded), messages are sent without timestamp; above this log level (included)...
Definition iio.h:195
enum iio_log_level stderr_level
Under this log level (included), messages are sent to the error output ; above this log level (exclud...
Definition iio.h:188
FILE * out
Handle to the standard output. If NULL, defaults to stdout.
Definition iio.h:175
int timeout_ms
Timeout for I/O operations in milliseconds.
Definition iio.h:203
Contains the representation of an IIO context.
Contains the format of a data sample.
Definition iio.h:1516
bool is_signed
Contains True if the sample is signed.
Definition iio.h:1527
bool is_be
Contains True if the sample is in big-endian format.
Definition iio.h:1533
bool with_scale
Contains True if the sample should be scaled when converted.
Definition iio.h:1536
bool is_float
Contains True if the channel's samples are floating-point numbers.
Definition iio.h:1549
double scale
Contains the scale to apply if with_scale is set.
Definition iio.h:1539
unsigned int repeat
Number of times length repeats (added in v0.8).
Definition iio.h:1542
unsigned int length
Total length of the sample, in bits.
Definition iio.h:1518
bool is_fully_defined
Contains True if the sample is fully defined, sign extended, etc.
Definition iio.h:1530
unsigned int shift
Right-shift to apply when converting sample.
Definition iio.h:1524
double offset
Contains a value to be added to the raw sample before applying the scale.
Definition iio.h:1546
unsigned int bits
Length of valuable data in the sample, in bits.
Definition iio.h:1521
Represents a device in the IIO context.
Represents a IIO event.
Definition iio.h:1437
Structure holding scanning information.
A helper object to simplify reading/writing to a iio_buffer.