1 /*
2  * libiio - Library for interfacing industrial I/O (IIO) devices
3  *
4  * Copyright (C) 2014 Analog Devices, Inc.
5  * Author: Paul Cercueil <paul.cercueil@analog.com>
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Lesser General Public License for more details.
16  *
17  * */
18 
19 /** @file iio.h
20  * @brief Public interface */
21 
22 #ifndef __IIO_H__
23 #define __IIO_H__
24 
25 #ifdef __cplusplus
26 extern "C" {
27 #endif
28 
29 #include <limits.h>
30 #include <stdint.h>
31 #include <stdlib.h>
32 #include <stddef.h>
33 
34 #if (defined(_WIN32) || defined(__MBED__))
35 #ifndef _SSIZE_T_DEFINED
36 typedef ptrdiff_t ssize_t;
37 #define _SSIZE_T_DEFINED
38 #endif
39 #else
40 #include <sys/types.h>
41 #endif
42 
43 #if defined(_MSC_VER) && (_MSC_VER < 1800) && !defined(__BOOL_DEFINED)
44 #undef bool
45 #undef false
46 #undef true
47 #define bool char
48 #define false 0
49 #define true 1
50 #else
51 #include <stdbool.h>
52 #endif
53 
54 #if defined(__GNUC__) && !defined(MATLAB_MEX_FILE) && !defined(MATLAB_LOADLIBRARY)
55 #ifndef __cnst
56 #define __cnst __attribute__((const))
57 #endif
58 #ifndef __pure
59 #define __pure __attribute__((pure))
60 #endif
61 #define __notused __attribute__((unused))
62 #ifdef IIO_CHECK_RET
63 #define __check_ret __attribute__((warn_unused_result))
64 #else
65 #define __check_ret
66 #endif
67 #else
68 #define __cnst
69 #define __pure
70 #define __notused
71 #define __check_ret
72 #endif
73 
74 #ifdef _WIN32
75 #   ifdef LIBIIO_EXPORTS
76 #	define __api __declspec(dllexport)
77 #   else
78 #	define __api __declspec(dllimport)
79 #   endif
80 #elif __GNUC__ >= 4 && !defined(MATLAB_MEX_FILE) && !defined(MATLAB_LOADLIBRARY)
81 #   define __api __attribute__((visibility ("default")))
82 #else
83 #   define __api
84 #endif
85 
86 struct iio_context;
87 struct iio_device;
88 struct iio_channel;
89 struct iio_buffer;
90 
91 struct iio_context_info;
92 struct iio_scan_context;
93 struct iio_scan_block;
94 
95 /**
96  * @enum iio_chan_type
97  * @brief IIO channel type
98  *
99  * A IIO channel has a type specifying the type of data associated with the
100  * channel.
101  */
102 enum iio_chan_type {
103 	IIO_VOLTAGE,
104 	IIO_CURRENT,
105 	IIO_POWER,
106 	IIO_ACCEL,
107 	IIO_ANGL_VEL,
108 	IIO_MAGN,
109 	IIO_LIGHT,
110 	IIO_INTENSITY,
111 	IIO_PROXIMITY,
112 	IIO_TEMP,
113 	IIO_INCLI,
114 	IIO_ROT,
115 	IIO_ANGL,
116 	IIO_TIMESTAMP,
117 	IIO_CAPACITANCE,
118 	IIO_ALTVOLTAGE,
119 	IIO_CCT,
120 	IIO_PRESSURE,
121 	IIO_HUMIDITYRELATIVE,
122 	IIO_ACTIVITY,
123 	IIO_STEPS,
124 	IIO_ENERGY,
125 	IIO_DISTANCE,
126 	IIO_VELOCITY,
127 	IIO_CONCENTRATION,
128 	IIO_RESISTANCE,
129 	IIO_PH,
130 	IIO_UVINDEX,
131 	IIO_ELECTRICALCONDUCTIVITY,
132 	IIO_COUNT,
133 	IIO_INDEX,
134 	IIO_GRAVITY,
135 	IIO_POSITIONRELATIVE,
136 	IIO_PHASE,
137 	IIO_MASSCONCENTRATION,
138 	IIO_CHAN_TYPE_UNKNOWN = INT_MAX
139 };
140 
141 /**
142  * @enum iio_modifier
143  * @brief IIO channel modifier
144  *
145  * In a addition to a type a IIO channel can optionally have a channel modifier
146  * further specifying the data type of of the channel.
147  */
148 enum iio_modifier {
149 	IIO_NO_MOD,
150 	IIO_MOD_X,
151 	IIO_MOD_Y,
152 	IIO_MOD_Z,
153 	IIO_MOD_X_AND_Y,
154 	IIO_MOD_X_AND_Z,
155 	IIO_MOD_Y_AND_Z,
156 	IIO_MOD_X_AND_Y_AND_Z,
157 	IIO_MOD_X_OR_Y,
158 	IIO_MOD_X_OR_Z,
159 	IIO_MOD_Y_OR_Z,
160 	IIO_MOD_X_OR_Y_OR_Z,
161 	IIO_MOD_LIGHT_BOTH,
162 	IIO_MOD_LIGHT_IR,
163 	IIO_MOD_ROOT_SUM_SQUARED_X_Y,
164 	IIO_MOD_SUM_SQUARED_X_Y_Z,
165 	IIO_MOD_LIGHT_CLEAR,
166 	IIO_MOD_LIGHT_RED,
167 	IIO_MOD_LIGHT_GREEN,
168 	IIO_MOD_LIGHT_BLUE,
169 	IIO_MOD_QUATERNION,
170 	IIO_MOD_TEMP_AMBIENT,
171 	IIO_MOD_TEMP_OBJECT,
172 	IIO_MOD_NORTH_MAGN,
173 	IIO_MOD_NORTH_TRUE,
174 	IIO_MOD_NORTH_MAGN_TILT_COMP,
175 	IIO_MOD_NORTH_TRUE_TILT_COMP,
176 	IIO_MOD_RUNNING,
177 	IIO_MOD_JOGGING,
178 	IIO_MOD_WALKING,
179 	IIO_MOD_STILL,
180 	IIO_MOD_ROOT_SUM_SQUARED_X_Y_Z,
181 	IIO_MOD_I,
182 	IIO_MOD_Q,
183 	IIO_MOD_CO2,
184 	IIO_MOD_VOC,
185 	IIO_MOD_LIGHT_UV,
186 	IIO_MOD_LIGHT_DUV,
187 	IIO_MOD_PM1,
188 	IIO_MOD_PM2P5,
189 	IIO_MOD_PM4,
190 	IIO_MOD_PM10,
191 	IIO_MOD_ETHANOL,
192 	IIO_MOD_H2,
193 };
194 
195 /* ---------------------------------------------------------------------------*/
196 /* ------------------------- Scan functions ----------------------------------*/
197 /** @defgroup Scan Functions for scanning available contexts
198  * @{
199  * @struct iio_scan_context
200  * @brief The scanning context
201  *
202  * @struct iio_context_info
203  * @brief The information related to a discovered context
204  */
205 
206 
207 /** @brief Create a scan context
208  * @param backend A NULL-terminated string containing the backend(s) to use for
209  * scanning (example: pre version 0.20 :  "local", "ip", or "usb"; post version
210  * 0.20 can handle multiple, including "local:usb:", "ip:usb:", "local:usb:ip:").
211  * If NULL, all the available backends are used.
212  * @param flags Unused for now. Set to 0.
213  * @return on success, a pointer to a iio_scan_context structure
214  * @return On failure, NULL is returned and errno is set appropriately */
215 __api __check_ret struct iio_scan_context * iio_create_scan_context(
216 		const char *backend, unsigned int flags);
217 
218 
219 /** @brief Destroy the given scan context
220  * @param ctx A pointer to an iio_scan_context structure
221  *
222  * <b>NOTE:</b> After that function, the iio_scan_context pointer shall be invalid. */
223 __api void iio_scan_context_destroy(struct iio_scan_context *ctx);
224 
225 
226 /** @brief Enumerate available contexts
227  * @param ctx A pointer to an iio_scan_context structure
228  * @param info A pointer to a 'const struct iio_context_info **' typed variable.
229  * The pointed variable will be initialized on success.
230  * @returns On success, the number of contexts found.
231  * @returns On failure, a negative error number.
232  */
233 __api __check_ret ssize_t iio_scan_context_get_info_list(struct iio_scan_context *ctx,
234 		struct iio_context_info ***info);
235 
236 
237 /** @brief Free a context info list
238  * @param info A pointer to a 'const struct iio_context_info *' typed variable
239  */
240 __api void iio_context_info_list_free(struct iio_context_info **info);
241 
242 
243 /** @brief Get a description of a discovered context
244  * @param info A pointer to an iio_context_info structure
245  * @return A pointer to a static NULL-terminated string
246  */
247 __api __check_ret __pure const char * iio_context_info_get_description(
248 		const struct iio_context_info *info);
249 
250 
251 /** @brief Get the URI of a discovered context
252  * @param info A pointer to an iio_context_info structure
253  * @return A pointer to a static NULL-terminated string
254  */
255 __api __check_ret __pure const char * iio_context_info_get_uri(
256 		const struct iio_context_info *info);
257 
258 
259 /** @brief Create a scan block
260  * @param backend A NULL-terminated string containing the backend to use for
261  * scanning. If NULL, all the available backends are used.
262  * @param flags Unused for now. Set to 0.
263  * @return on success, a pointer to a iio_scan_block structure
264  * @return On failure, NULL is returned and errno is set appropriately
265  *
266  * Introduced in version 0.20. */
267 __api struct iio_scan_block * iio_create_scan_block(
268 		const char *backend, unsigned int flags);
269 
270 
271 /** @brief Destroy the given scan block
272  * @param blk A pointer to an iio_scan_block structure
273  *
274  * <b>NOTE:</b> After that function, the iio_scan_block pointer shall be invalid.
275  *
276  * Introduced in version 0.20. */
277 __api void iio_scan_block_destroy(struct iio_scan_block *blk);
278 
279 
280 /** @brief Enumerate available contexts via scan block
281  * @param blk A pointer to a iio_scan_block structure.
282  * @returns On success, the number of contexts found.
283  * @returns On failure, a negative error number.
284  *
285  * Introduced in version 0.20. */
286 __api ssize_t iio_scan_block_scan(struct iio_scan_block *blk);
287 
288 
289 /** @brief Get the iio_context_info for a particular context
290  * @param blk A pointer to an iio_scan_block structure
291  * @param index The index corresponding to the context.
292  * @return A pointer to the iio_context_info for the context
293  * @returns On success, a pointer to the specified iio_context_info
294  * @returns On failure, NULL is returned and errno is set appropriately
295  *
296  * Introduced in version 0.20. */
297 __api struct iio_context_info *iio_scan_block_get_info(
298 		struct iio_scan_block *blk, unsigned int index);
299 
300 
301 /** @} *//* ------------------------------------------------------------------*/
302 /* ------------------------- Top-level functions -----------------------------*/
303 /** @defgroup TopLevel Top-level functions
304  * @{ */
305 
306 
307 /** @brief Get the version of the libiio library
308  * @param major A pointer to an unsigned integer (NULL accepted)
309  * @param minor A pointer to an unsigned integer (NULL accepted)
310  * @param git_tag A pointer to a 8-characters buffer (NULL accepted) */
311 __api void iio_library_get_version(unsigned int *major,
312 		unsigned int *minor, char git_tag[8]);
313 
314 
315 /** @brief Get a string description of an error code
316  * @param err The error code
317  * @param dst A pointer to the memory area where the NULL-terminated string
318  * corresponding to the error message will be stored
319  * @param len The available length of the memory area, in bytes */
320 __api void iio_strerror(int err, char *dst, size_t len);
321 
322 
323 /** @brief Check if the specified backend is available
324  * @param backend The name of the backend to query
325  * @return True if the backend is available, false otherwise
326  *
327  * Introduced in version 0.9. */
328 __api __check_ret __cnst bool iio_has_backend(const char *backend);
329 
330 
331 /** @brief Get the number of available backends
332  * @return The number of available backends
333  *
334  * Introduced in version 0.9. */
335 __api __check_ret __cnst unsigned int iio_get_backends_count(void);
336 
337 
338 /** @brief Retrieve the name of a given backend
339  * @param index The index corresponding to the attribute
340  * @return On success, a pointer to a static NULL-terminated string
341  * @return If the index is invalid, NULL is returned
342  *
343  * Introduced in version 0.9. */
344 __api __check_ret __cnst const char * iio_get_backend(unsigned int index);
345 
346 
347 /** @} *//* ------------------------------------------------------------------*/
348 /* ------------------------- Context functions -------------------------------*/
349 /** @defgroup Context Context
350  * @{
351  * @struct iio_context
352  * @brief Contains the representation of an IIO context */
353 
354 
355 /** @brief Create a context from local or remote IIO devices
356  * @return On success, A pointer to an iio_context structure
357  * @return On failure, NULL is returned and errno is set appropriately
358  *
359  * <b>NOTE:</b> This function will create a network context if the IIOD_REMOTE
360  * environment variable is set to the hostname where the IIOD server runs. If
361  * set to an empty string, the server will be discovered using ZeroConf.
362  * If the environment variable is not set, a local context will be created
363  * instead. */
364 __api __check_ret struct iio_context * iio_create_default_context(void);
365 
366 
367 /** @brief Create a context from local IIO devices (Linux only)
368  * @return On success, A pointer to an iio_context structure
369  * @return On failure, NULL is returned and errno is set appropriately */
370 __api __check_ret struct iio_context * iio_create_local_context(void);
371 
372 
373 /** @brief Create a context from a XML file
374  * @param xml_file Path to the XML file to open
375  * @return On success, A pointer to an iio_context structure
376  * @return On failure, NULL is returned and errno is set appropriately
377  *
378  * <b>NOTE:</b> The format of the XML must comply to the one returned by
379  * iio_context_get_xml. */
380 __api __check_ret struct iio_context * iio_create_xml_context(const char *xml_file);
381 
382 
383 /** @brief Create a context from XML data in memory
384  * @param xml Pointer to the XML data in memory
385  * @param len Length of the XML string in memory (excluding the final \0)
386  * @return On success, A pointer to an iio_context structure
387  * @return On failure, NULL is returned and errno is set appropriately
388  *
389  * <b>NOTE:</b> The format of the XML must comply to the one returned by
390  * iio_context_get_xml */
391 __api __check_ret struct iio_context * iio_create_xml_context_mem(
392 		const char *xml, size_t len);
393 
394 
395 /** @brief Create a context from the network
396  * @param host Hostname, IPv4 or IPv6 address where the IIO Daemon is running
397  * @return On success, a pointer to an iio_context structure
398  * @return On failure, NULL is returned and errno is set appropriately */
399 __api __check_ret struct iio_context * iio_create_network_context(const char *host);
400 
401 
402 /** @brief Create a context from a URI description
403  * @param uri A URI describing the context location
404  * @return On success, a pointer to a iio_context structure
405  * @return On failure, NULL is returned and errno is set appropriately
406  *
407  * <b>NOTE:</b> The following URIs are supported based on compile time backend
408  * support:
409  * - Local backend, "local:"\n
410  *   Does not have an address part. For example <i>"local:"</i>
411  * - XML backend, "xml:"\n Requires a path to the XML file for the address part.
412  *   For example <i>"xml:/home/user/file.xml"</i>
413  * - Network backend, "ip:"\n Requires a hostname, IPv4, or IPv6 to connect to
414  *   a specific running IIO Daemon or no address part for automatic discovery
415  *   when library is compiled with ZeroConf support. For example
416  *   <i>"ip:192.168.2.1"</i>, <b>or</b> <i>"ip:localhost"</i>, <b>or</b> <i>"ip:"</i>
417  *   <b>or</b> <i>"ip:plutosdr.local"</i>
418  * - USB backend, "usb:"\n When more than one usb device is attached, requires
419  *   bus, address, and interface parts separated with a dot. For example
420  *   <i>"usb:3.32.5"</i>. Where there is only one USB device attached, the shorthand
421  *   <i>"usb:"</i> can be used.
422  * - Serial backend, "serial:"\n Requires:
423  *     - a port (/dev/ttyUSB0),
424  *     - baud_rate (default <b>115200</b>)
425  *     - serial port configuration
426  *        - data bits (5 6 7 <b>8</b> 9)
427  *        - parity ('<b>n</b>' none, 'o' odd, 'e' even, 'm' mark, 's' space)
428  *        - stop bits (<b>1</b> 2)
429  *        - flow control ('<b>\0</b>' none, 'x' Xon Xoff, 'r' RTSCTS, 'd' DTRDSR)
430  *
431  *  For example <i>"serial:/dev/ttyUSB0,115200"</i> <b>or</b> <i>"serial:/dev/ttyUSB0,115200,8n1"</i>*/
432 __api __check_ret struct iio_context * iio_create_context_from_uri(const char *uri);
433 
434 
435 /** @brief Duplicate a pre-existing IIO context
436  * @param ctx A pointer to an iio_context structure
437  * @return On success, A pointer to an iio_context structure
438  * @return On failure, NULL is returned and errno is set appropriately
439  *
440  * <b>NOTE:</b> This function is not supported on 'usb:' contexts, since libusb
441  * can only claim the interface once. "Function not implemented" is the expected errno.
442  * Any context which is cloned, must be destroyed via calling iio_context_destroy() */
443 __api __check_ret struct iio_context * iio_context_clone(const struct iio_context *ctx);
444 
445 
446 /** @brief Destroy the given context
447  * @param ctx A pointer to an iio_context structure
448  *
449  * <b>NOTE:</b> After that function, the iio_context pointer shall be invalid. */
450 __api void iio_context_destroy(struct iio_context *ctx);
451 
452 
453 /** @brief Get the version of the backend in use
454  * @param ctx A pointer to an iio_context structure
455  * @param major A pointer to an unsigned integer (NULL accepted)
456  * @param minor A pointer to an unsigned integer (NULL accepted)
457  * @param git_tag A pointer to a 8-characters buffer (NULL accepted)
458  * @return On success, 0 is returned
459  * @return On error, a negative errno code is returned */
460 __api __check_ret int iio_context_get_version(const struct iio_context *ctx,
461 		unsigned int *major, unsigned int *minor, char git_tag[8]);
462 
463 
464 /** @brief Obtain a XML representation of the given context
465  * @param ctx A pointer to an iio_context structure
466  * @return A pointer to a static NULL-terminated string */
467 __api __check_ret __pure const char * iio_context_get_xml(const struct iio_context *ctx);
468 
469 
470 /** @brief Get the name of the given context
471  * @param ctx A pointer to an iio_context structure
472  * @return A pointer to a static NULL-terminated string
473  *
474  * <b>NOTE:</b>The returned string will be <b><i>local</i></b>,
475  * <b><i>xml</i></b> or <b><i>network</i></b> when the context has been
476  * created with the local, xml and network backends respectively.*/
477 __api __check_ret __pure const char * iio_context_get_name(const struct iio_context *ctx);
478 
479 
480 /** @brief Get a description of the given context
481  * @param ctx A pointer to an iio_context structure
482  * @return A pointer to a static NULL-terminated string
483  *
484  * <b>NOTE:</b>The returned string will contain human-readable information about
485  * the current context. */
486 __api __check_ret __pure const char * iio_context_get_description(
487 		const struct iio_context *ctx);
488 
489 
490 /** @brief Get the number of context-specific attributes
491  * @param ctx A pointer to an iio_context structure
492  * @return The number of context-specific attributes
493  *
494  * Introduced in version 0.9. */
495 __api __check_ret __pure unsigned int iio_context_get_attrs_count(
496 		const struct iio_context *ctx);
497 
498 
499 /** @brief Retrieve the name and value of a context-specific attribute
500  * @param ctx A pointer to an iio_context structure
501  * @param index The index corresponding to the attribute
502  * @param name A pointer to a const char * pointer (NULL accepted)
503  * @param value A pointer to a const char * pointer (NULL accepted)
504  * @return On success, 0 is returned
505  * @return On error, a negative errno code is returned
506  *
507  * Introduced in version 0.9. */
508 __api __check_ret int iio_context_get_attr(
509 		const struct iio_context *ctx, unsigned int index,
510 		const char **name, const char **value);
511 
512 
513 /** @brief Retrieve the value of a context-specific attribute
514  * @param ctx A pointer to an iio_context structure
515  * @param name The name of the context attribute to read
516  * @return On success, a pointer to a static NULL-terminated string
517  * @return If the name does not correspond to any attribute, NULL is
518  * returned
519  *
520  * Introduced in version 0.9. */
521 __api __check_ret const char * iio_context_get_attr_value(
522 		const struct iio_context *ctx, const char *name);
523 
524 
525 /** @brief Enumerate the devices found in the given context
526  * @param ctx A pointer to an iio_context structure
527  * @return The number of devices found */
528 __api __check_ret __pure unsigned int iio_context_get_devices_count(
529 		const struct iio_context *ctx);
530 
531 
532 /** @brief Get the device present at the given index
533  * @param ctx A pointer to an iio_context structure
534  * @param index The index corresponding to the device
535  * @return On success, a pointer to an iio_device structure
536  * @return If the index is invalid, NULL is returned */
537 __api __check_ret __pure struct iio_device * iio_context_get_device(
538 		const struct iio_context *ctx, unsigned int index);
539 
540 
541 /** @brief Try to find a device structure by its name of ID
542  * @param ctx A pointer to an iio_context structure
543  * @param name A NULL-terminated string corresponding to the name or the ID of
544  * the device to search for
545  * @return On success, a pointer to an iio_device structure
546  * @return If the name or ID does not correspond to any known device, NULL is
547  * returned */
548 __api __check_ret __pure struct iio_device * iio_context_find_device(
549 		const struct iio_context *ctx, const char *name);
550 
551 
552 /** @brief Set a timeout for I/O operations
553  * @param ctx A pointer to an iio_context structure
554  * @param timeout_ms A positive integer representing the time in milliseconds
555  * after which a timeout occurs. A value of 0 is used to specify that no
556  * timeout should occur.
557  * @return On success, 0 is returned
558  * @return On error, a negative errno code is returned */
559 __api __check_ret int iio_context_set_timeout(
560 		struct iio_context *ctx, unsigned int timeout_ms);
561 
562 
563 /** @} *//* ------------------------------------------------------------------*/
564 /* ------------------------- Device functions --------------------------------*/
565 /** @defgroup Device Device
566  * @{
567  * @struct iio_device
568  * @brief Represents a device in the IIO context */
569 
570 
571 /** @brief Retrieve a pointer to the iio_context structure
572  * @param dev A pointer to an iio_device structure
573  * @return A pointer to an iio_context structure */
574 __api __check_ret __pure const struct iio_context * iio_device_get_context(
575 		const struct iio_device *dev);
576 
577 
578 /** @brief Retrieve the device ID (e.g. <b><i>iio:device0</i></b>)
579  * @param dev A pointer to an iio_device structure
580  * @return A pointer to a static NULL-terminated string */
581 __api __check_ret __pure const char * iio_device_get_id(const struct iio_device *dev);
582 
583 
584 /** @brief Retrieve the device name (e.g. <b><i>xadc</i></b>)
585  * @param dev A pointer to an iio_device structure
586  * @return A pointer to a static NULL-terminated string
587  *
588  * <b>NOTE:</b> if the device has no name, NULL is returned. */
589 __api __check_ret __pure const char * iio_device_get_name(const struct iio_device *dev);
590 
591 
592 /** @brief Enumerate the channels of the given device
593  * @param dev A pointer to an iio_device structure
594  * @return The number of channels found */
595 __api __check_ret __pure unsigned int iio_device_get_channels_count(
596 		const struct iio_device *dev);
597 
598 
599 /** @brief Enumerate the device-specific attributes of the given device
600  * @param dev A pointer to an iio_device structure
601  * @return The number of device-specific attributes found */
602 __api __check_ret __pure unsigned int iio_device_get_attrs_count(
603 		const struct iio_device *dev);
604 
605 /** @brief Enumerate the buffer-specific attributes of the given device
606  * @param dev A pointer to an iio_device structure
607  * @return The number of buffer-specific attributes found */
608 __api __check_ret __pure unsigned int iio_device_get_buffer_attrs_count(
609 		const struct iio_device *dev);
610 
611 /** @brief Get the channel present at the given index
612  * @param dev A pointer to an iio_device structure
613  * @param index The index corresponding to the channel
614  * @return On success, a pointer to an iio_channel structure
615  * @return If the index is invalid, NULL is returned */
616 __api __check_ret __pure struct iio_channel * iio_device_get_channel(
617 		const struct iio_device *dev, unsigned int index);
618 
619 
620 /** @brief Get the device-specific attribute present at the given index
621  * @param dev A pointer to an iio_device structure
622  * @param index The index corresponding to the attribute
623  * @return On success, a pointer to a static NULL-terminated string
624  * @return If the index is invalid, NULL is returned */
625 __api __check_ret __pure const char * iio_device_get_attr(
626 		const struct iio_device *dev, unsigned int index);
627 
628 /** @brief Get the buffer-specific attribute present at the given index
629  * @param dev A pointer to an iio_device structure
630  * @param index The index corresponding to the attribute
631  * @return On success, a pointer to a static NULL-terminated string
632  * @return If the index is invalid, NULL is returned */
633 __api __check_ret __pure const char * iio_device_get_buffer_attr(
634 		const struct iio_device *dev, unsigned int index);
635 
636 /** @brief Try to find a channel structure by its name of ID
637  * @param dev A pointer to an iio_device structure
638  * @param name A NULL-terminated string corresponding to the name or the ID of
639  * the channel to search for
640  * @param output True if the searched channel is output, False otherwise
641  * @return On success, a pointer to an iio_channel structure
642  * @return If the name or ID does not correspond to any known channel of the
643  * given device, NULL is returned */
644 __api __check_ret __pure struct iio_channel * iio_device_find_channel(
645 		const struct iio_device *dev, const char *name, bool output);
646 
647 
648 /** @brief Try to find a device-specific attribute by its name
649  * @param dev A pointer to an iio_device structure
650  * @param name A NULL-terminated string corresponding to the name of the
651  * attribute
652  * @return On success, a pointer to a static NULL-terminated string
653  * @return If the name does not correspond to any known attribute of the given
654  * device, NULL is returned
655  *
656  * <b>NOTE:</b> This function is useful to detect the presence of an attribute.
657  * It can also be used to retrieve the name of an attribute as a pointer to a
658  * static string from a dynamically allocated string. */
659 __api __check_ret __pure const char * iio_device_find_attr(
660 		const struct iio_device *dev, const char *name);
661 
662 /** @brief Try to find a buffer-specific attribute by its name
663  * @param dev A pointer to an iio_device structure
664  * @param name A NULL-terminated string corresponding to the name of the
665  * attribute
666  * @return On success, a pointer to a static NULL-terminated string
667  * @return If the name does not correspond to any known attribute of the given
668  * device, NULL is returned
669  *
670  * <b>NOTE:</b> This function is useful to detect the presence of an attribute.
671  * It can also be used to retrieve the name of an attribute as a pointer to a
672  * static string from a dynamically allocated string. */
673 __api __check_ret __pure const char * iio_device_find_buffer_attr(
674 		const struct iio_device *dev, const char *name);
675 
676 /** @brief Read the content of the given device-specific attribute
677  * @param dev A pointer to an iio_device structure
678  * @param attr A NULL-terminated string corresponding to the name of the
679  * attribute
680  * @param dst A pointer to the memory area where the NULL-terminated string
681  * corresponding to the value read will be stored
682  * @param len The available length of the memory area, in bytes
683  * @return On success, the number of bytes written to the buffer
684  * @return On error, a negative errno code is returned
685  *
686  * <b>NOTE:</b>By passing NULL as the "attr" argument to iio_device_attr_read,
687  * it is now possible to read all of the attributes of a device.
688  *
689  * The buffer is filled with one block of data per attribute of the device,
690  * by the order they appear in the iio_device structure.
691  *
692  * The first four bytes of one block correspond to a 32-bit signed value in
693  * network order. If negative, it corresponds to the errno code that were
694  * returned when reading the attribute; if positive, it corresponds to the
695  * length of the data read. In that case, the rest of the block contains
696  * the data. */
697 __api __check_ret ssize_t iio_device_attr_read(const struct iio_device *dev,
698 		const char *attr, char *dst, size_t len);
699 
700 
701 /** @brief Read the content of all device-specific attributes
702  * @param dev A pointer to an iio_device structure
703  * @param cb A pointer to a callback function
704  * @param data A pointer that will be passed to the callback function
705  * @return On success, 0 is returned
706  * @return On error, a negative errno code is returned
707  *
708  * <b>NOTE:</b> This function is especially useful when used with the network
709  * backend, as all the device-specific attributes are read in one single
710  * command. */
711 __api __check_ret int iio_device_attr_read_all(struct iio_device *dev,
712 		int (*cb)(struct iio_device *dev, const char *attr,
713 			const char *value, size_t len, void *d),
714 		void *data);
715 
716 
717 /** @brief Read the content of the given device-specific attribute
718  * @param dev A pointer to an iio_device structure
719  * @param attr A NULL-terminated string corresponding to the name of the
720  * attribute
721  * @param val A pointer to a bool variable where the value should be stored
722  * @return On success, 0 is returned
723  * @return On error, a negative errno code is returned */
724 __api __check_ret int iio_device_attr_read_bool(const struct iio_device *dev,
725 		const char *attr, bool *val);
726 
727 
728 /** @brief Read the content of the given device-specific attribute
729  * @param dev A pointer to an iio_device structure
730  * @param attr A NULL-terminated string corresponding to the name of the
731  * attribute
732  * @param val A pointer to a long long variable where the value should be stored
733  * @return On success, 0 is returned
734  * @return On error, a negative errno code is returned */
735 __api __check_ret int iio_device_attr_read_longlong(const struct iio_device *dev,
736 		const char *attr, long long *val);
737 
738 
739 /** @brief Read the content of the given device-specific attribute
740  * @param dev A pointer to an iio_device structure
741  * @param attr A NULL-terminated string corresponding to the name of the
742  * attribute
743  * @param val A pointer to a double variable where the value should be stored
744  * @return On success, 0 is returned
745  * @return On error, a negative errno code is returned */
746 __api __check_ret int iio_device_attr_read_double(const struct iio_device *dev,
747 		const char *attr, double *val);
748 
749 
750 /** @brief Set the value of the given device-specific attribute
751  * @param dev A pointer to an iio_device structure
752  * @param attr A NULL-terminated string corresponding to the name of the
753  * attribute
754  * @param src A NULL-terminated string to set the attribute to
755  * @return On success, the number of bytes written
756  * @return On error, a negative errno code is returned
757  *
758  * <b>NOTE:</b>By passing NULL as the "attr" argument to iio_device_attr_write,
759  * it is now possible to write all of the attributes of a device.
760  *
761  * The buffer must contain one block of data per attribute of the device,
762  * by the order they appear in the iio_device structure.
763  *
764  * The first four bytes of one block correspond to a 32-bit signed value in
765  * network order. If negative, the attribute is not written; if positive,
766  * it corresponds to the length of the data to write. In that case, the rest
767  * of the block must contain the data. */
768 __api __check_ret ssize_t iio_device_attr_write(const struct iio_device *dev,
769 		const char *attr, const char *src);
770 
771 
772 /** @brief Set the value of the given device-specific attribute
773  * @param dev A pointer to an iio_device structure
774  * @param attr A NULL-terminated string corresponding to the name of the
775  * attribute
776  * @param src A pointer to the data to be written
777  * @param len The number of bytes that should be written
778  * @return On success, the number of bytes written
779  * @return On error, a negative errno code is returned */
780 __api __check_ret ssize_t iio_device_attr_write_raw(const struct iio_device *dev,
781 		const char *attr, const void *src, size_t len);
782 
783 
784 /** @brief Set the values of all device-specific attributes
785  * @param dev A pointer to an iio_device structure
786  * @param cb A pointer to a callback function
787  * @param data A pointer that will be passed to the callback function
788  * @return On success, 0 is returned
789  * @return On error, a negative errno code is returned
790  *
791  * <b>NOTE:</b> This function is especially useful when used with the network
792  * backend, as all the device-specific attributes are written in one single
793  * command. */
794 __api __check_ret int iio_device_attr_write_all(struct iio_device *dev,
795 		ssize_t (*cb)(struct iio_device *dev,
796 			const char *attr, void *buf, size_t len, void *d),
797 		void *data);
798 
799 
800 /** @brief Set the value of the given device-specific attribute
801  * @param dev A pointer to an iio_device structure
802  * @param attr A NULL-terminated string corresponding to the name of the
803  * attribute
804  * @param val A bool value to set the attribute to
805  * @return On success, 0 is returned
806  * @return On error, a negative errno code is returned */
807 __api __check_ret int iio_device_attr_write_bool(const struct iio_device *dev,
808 		const char *attr, bool val);
809 
810 
811 /** @brief Set the value of the given device-specific attribute
812  * @param dev A pointer to an iio_device structure
813  * @param attr A NULL-terminated string corresponding to the name of the
814  * attribute
815  * @param val A long long value to set the attribute to
816  * @return On success, 0 is returned
817  * @return On error, a negative errno code is returned */
818 __api __check_ret int iio_device_attr_write_longlong(const struct iio_device *dev,
819 		const char *attr, long long val);
820 
821 
822 /** @brief Set the value of the given device-specific attribute
823  * @param dev A pointer to an iio_device structure
824  * @param attr A NULL-terminated string corresponding to the name of the
825  * attribute
826  * @param val A double value to set the attribute to
827  * @return On success, 0 is returned
828  * @return On error, a negative errno code is returned */
829 __api __check_ret int iio_device_attr_write_double(const struct iio_device *dev,
830 		const char *attr, double val);
831 
832 /** @brief Read the content of the given buffer-specific attribute
833  * @param dev A pointer to an iio_device structure
834  * @param attr A NULL-terminated string corresponding to the name of the
835  * attribute
836  * @param dst A pointer to the memory area where the NULL-terminated string
837  * corresponding to the value read will be stored
838  * @param len The available length of the memory area, in bytes
839  * @return On success, the number of bytes written to the buffer
840  * @return On error, a negative errno code is returned
841  *
842  * <b>NOTE:</b>By passing NULL as the "attr" argument to
843  * iio_device_buffer_attr_read, it is now possible to read all of the attributes
844  * of a device.
845  *
846  * The buffer is filled with one block of data per attribute of the buffer,
847  * by the order they appear in the iio_device structure.
848  *
849  * The first four bytes of one block correspond to a 32-bit signed value in
850  * network order. If negative, it corresponds to the errno code that were
851  * returned when reading the attribute; if positive, it corresponds to the
852  * length of the data read. In that case, the rest of the block contains
853  * the data. */
854 __api __check_ret ssize_t iio_device_buffer_attr_read(const struct iio_device *dev,
855 		const char *attr, char *dst, size_t len);
856 
857 /** @brief Read the content of all buffer-specific attributes
858  * @param dev A pointer to an iio_device structure
859  * @param cb A pointer to a callback function
860  * @param data A pointer that will be passed to the callback function
861  * @return On success, 0 is returned
862  * @return On error, a negative errno code is returned
863  *
864  * <b>NOTE:</b> This function is especially useful when used with the network
865  * backend, as all the buffer-specific attributes are read in one single
866  * command. */
867 __api __check_ret int iio_device_buffer_attr_read_all(struct iio_device *dev,
868 		int (*cb)(struct iio_device *dev, const char *attr,
869 			const char *value, size_t len, void *d),
870 		void *data);
871 
872 
873 /** @brief Read the content of the given buffer-specific attribute
874  * @param dev A pointer to an iio_device structure
875  * @param attr A NULL-terminated string corresponding to the name of the
876  * attribute
877  * @param val A pointer to a bool variable where the value should be stored
878  * @return On success, 0 is returned
879  * @return On error, a negative errno code is returned */
880 __api __check_ret int iio_device_buffer_attr_read_bool(const struct iio_device *dev,
881 		const char *attr, bool *val);
882 
883 
884 /** @brief Read the content of the given buffer-specific attribute
885  * @param dev A pointer to an iio_device structure
886  * @param attr A NULL-terminated string corresponding to the name of the
887  * attribute
888  * @param val A pointer to a long long variable where the value should be stored
889  * @return On success, 0 is returned
890  * @return On error, a negative errno code is returned */
891 __api __check_ret int iio_device_buffer_attr_read_longlong(const struct iio_device *dev,
892 		const char *attr, long long *val);
893 
894 
895 /** @brief Read the content of the given buffer-specific attribute
896  * @param dev A pointer to an iio_device structure
897  * @param attr A NULL-terminated string corresponding to the name of the
898  * attribute
899  * @param val A pointer to a double variable where the value should be stored
900  * @return On success, 0 is returned
901  * @return On error, a negative errno code is returned */
902 __api __check_ret int iio_device_buffer_attr_read_double(const struct iio_device *dev,
903 		const char *attr, double *val);
904 
905 
906 /** @brief Set the value of the given buffer-specific attribute
907  * @param dev A pointer to an iio_device structure
908  * @param attr A NULL-terminated string corresponding to the name of the
909  * attribute
910  * @param src A NULL-terminated string to set the attribute to
911  * @return On success, the number of bytes written
912  * @return On error, a negative errno code is returned
913  *
914  * <b>NOTE:</b>By passing NULL as the "attr" argument to
915  * iio_device_buffer_attr_write, it is now possible to write all of the
916  * attributes of a device.
917  *
918  * The buffer must contain one block of data per attribute of the buffer,
919  * by the order they appear in the iio_device structure.
920  *
921  * The first four bytes of one block correspond to a 32-bit signed value in
922  * network order. If negative, the attribute is not written; if positive,
923  * it corresponds to the length of the data to write. In that case, the rest
924  * of the block must contain the data. */
925 __api __check_ret ssize_t iio_device_buffer_attr_write(const struct iio_device *dev,
926 		const char *attr, const char *src);
927 
928 
929 /** @brief Set the value of the given buffer-specific attribute
930  * @param dev A pointer to an iio_device structure
931  * @param attr A NULL-terminated string corresponding to the name of the
932  * attribute
933  * @param src A pointer to the data to be written
934  * @param len The number of bytes that should be written
935  * @return On success, the number of bytes written
936  * @return On error, a negative errno code is returned */
937 __api __check_ret ssize_t iio_device_buffer_attr_write_raw(const struct iio_device *dev,
938 		const char *attr, const void *src, size_t len);
939 
940 
941 /** @brief Set the values of all buffer-specific attributes
942  * @param dev A pointer to an iio_device structure
943  * @param cb A pointer to a callback function
944  * @param data A pointer that will be passed to the callback function
945  * @return On success, 0 is returned
946  * @return On error, a negative errno code is returned
947  *
948  * <b>NOTE:</b> This function is especially useful when used with the network
949  * backend, as all the buffer-specific attributes are written in one single
950  * command. */
951 __api __check_ret int iio_device_buffer_attr_write_all(struct iio_device *dev,
952 		ssize_t (*cb)(struct iio_device *dev,
953 			const char *attr, void *buf, size_t len, void *d),
954 		void *data);
955 
956 
957 /** @brief Set the value of the given buffer-specific attribute
958  * @param dev A pointer to an iio_device structure
959  * @param attr A NULL-terminated string corresponding to the name of the
960  * attribute
961  * @param val A bool value to set the attribute to
962  * @return On success, 0 is returned
963  * @return On error, a negative errno code is returned */
964 __api __check_ret int iio_device_buffer_attr_write_bool(const struct iio_device *dev,
965 		const char *attr, bool val);
966 
967 
968 /** @brief Set the value of the given buffer-specific attribute
969  * @param dev A pointer to an iio_device structure
970  * @param attr A NULL-terminated string corresponding to the name of the
971  * attribute
972  * @param val A long long value to set the attribute to
973  * @return On success, 0 is returned
974  * @return On error, a negative errno code is returned */
975 __api __check_ret int iio_device_buffer_attr_write_longlong(const struct iio_device *dev,
976 		const char *attr, long long val);
977 
978 
979 /** @brief Set the value of the given buffer-specific attribute
980  * @param dev A pointer to an iio_device structure
981  * @param attr A NULL-terminated string corresponding to the name of the
982  * attribute
983  * @param val A double value to set the attribute to
984  * @return On success, 0 is returned
985  * @return On error, a negative errno code is returned */
986 __api __check_ret int iio_device_buffer_attr_write_double(const struct iio_device *dev,
987 		const char *attr, double val);
988 
989 
990 /** @brief Associate a pointer to an iio_device structure
991  * @param dev A pointer to an iio_device structure
992  * @param data The pointer to be associated */
993 __api void iio_device_set_data(struct iio_device *dev, void *data);
994 
995 
996 /** @brief Retrieve a previously associated pointer of an iio_device structure
997  * @param dev A pointer to an iio_device structure
998  * @return The pointer previously associated if present, or NULL */
999 __api void * iio_device_get_data(const struct iio_device *dev);
1000 
1001 
1002 /** @brief Retrieve the trigger of a given device
1003  * @param dev A pointer to an iio_device structure
1004  * @param trigger a pointer to a pointer of an iio_device structure. The pointed
1005  * pointer will be set to the address of the iio_device structure corresponding
1006  * to the associated trigger device.
1007  * @return On success, 0 is returned
1008  * @return On error, a negative errno code is returned */
1009 __api __check_ret int iio_device_get_trigger(const struct iio_device *dev,
1010 		const struct iio_device **trigger);
1011 
1012 
1013 /** @brief Associate a trigger to a given device
1014  * @param dev A pointer to an iio_device structure
1015  * @param trigger a pointer to the iio_device structure corresponding to the
1016  * trigger that should be associated.
1017  * @return On success, 0 is returned
1018  * @return On error, a negative errno code is returned */
1019 __api __check_ret int iio_device_set_trigger(const struct iio_device *dev,
1020 		const struct iio_device *trigger);
1021 
1022 
1023 /** @brief Return True if the given device is a trigger
1024  * @param dev A pointer to an iio_device structure
1025  * @return True if the device is a trigger, False otherwise */
1026 __api __check_ret __pure bool iio_device_is_trigger(const struct iio_device *dev);
1027 
1028 /** @brief Configure the number of kernel buffers for a device
1029  *
1030  * This function allows to change the number of buffers on kernel side.
1031  * @param dev A pointer to an iio_device structure
1032  * @param nb_buffers The number of buffers
1033  * @return On success, 0 is returned
1034  * @return On error, a negative errno code is returned */
1035 __api __check_ret int iio_device_set_kernel_buffers_count(const struct iio_device *dev,
1036 		unsigned int nb_buffers);
1037 
1038 /** @} *//* ------------------------------------------------------------------*/
1039 /* ------------------------- Channel functions -------------------------------*/
1040 /** @defgroup Channel Channel
1041  * @{
1042  * @struct iio_channel
1043  * @brief Represents an input or output channel of a device */
1044 
1045 
1046 /** @brief Retrieve a pointer to the iio_device structure
1047  * @param chn A pointer to an iio_channel structure
1048  * @return A pointer to an iio_device structure */
1049 __api __check_ret __pure const struct iio_device * iio_channel_get_device(
1050 		const struct iio_channel *chn);
1051 
1052 
1053 /** @brief Retrieve the channel ID (e.g. <b><i>voltage0</i></b>)
1054  * @param chn A pointer to an iio_channel structure
1055  * @return A pointer to a static NULL-terminated string */
1056 __api __check_ret __pure const char * iio_channel_get_id(const struct iio_channel *chn);
1057 
1058 
1059 /** @brief Retrieve the channel name (e.g. <b><i>vccint</i></b>)
1060  * @param chn A pointer to an iio_channel structure
1061  * @return A pointer to a static NULL-terminated string
1062  *
1063  * <b>NOTE:</b> if the channel has no name, NULL is returned. */
1064 __api __check_ret __pure const char * iio_channel_get_name(const struct iio_channel *chn);
1065 
1066 
1067 /** @brief Return True if the given channel is an output channel
1068  * @param chn A pointer to an iio_channel structure
1069  * @return True if the channel is an output channel, False otherwise */
1070 __api __check_ret __pure bool iio_channel_is_output(const struct iio_channel *chn);
1071 
1072 
1073 /** @brief Return True if the given channel is a scan element
1074  * @param chn A pointer to an iio_channel structure
1075  * @return True if the channel is a scan element, False otherwise
1076  *
1077  * <b>NOTE:</b> a channel that is a scan element is a channel that can
1078  * generate samples (for an input channel) or receive samples (for an output
1079  * channel) after being enabled. */
1080 __api __check_ret __pure bool iio_channel_is_scan_element(const struct iio_channel *chn);
1081 
1082 
1083 /** @brief Enumerate the channel-specific attributes of the given channel
1084  * @param chn A pointer to an iio_channel structure
1085  * @return The number of channel-specific attributes found */
1086 __api __check_ret __pure unsigned int iio_channel_get_attrs_count(
1087 		const struct iio_channel *chn);
1088 
1089 
1090 /** @brief Get the channel-specific attribute present at the given index
1091  * @param chn A pointer to an iio_channel structure
1092  * @param index The index corresponding to the attribute
1093  * @return On success, a pointer to a static NULL-terminated string
1094  * @return If the index is invalid, NULL is returned */
1095 __api __check_ret __pure const char * iio_channel_get_attr(
1096 		const struct iio_channel *chn, unsigned int index);
1097 
1098 
1099 /** @brief Try to find a channel-specific attribute by its name
1100  * @param chn A pointer to an iio_channel structure
1101  * @param name A NULL-terminated string corresponding to the name of the
1102  * attribute
1103  * @return On success, a pointer to a static NULL-terminated string
1104  * @return If the name does not correspond to any known attribute of the given
1105  * channel, NULL is returned
1106  *
1107  * <b>NOTE:</b> This function is useful to detect the presence of an attribute.
1108  * It can also be used to retrieve the name of an attribute as a pointer to a
1109  * static string from a dynamically allocated string. */
1110 __api __check_ret __pure const char * iio_channel_find_attr(
1111 		const struct iio_channel *chn, const char *name);
1112 
1113 
1114 /** @brief Retrieve the filename of an attribute
1115  * @param chn A pointer to an iio_channel structure
1116  * @param attr a NULL-terminated string corresponding to the name of the
1117  * attribute
1118  * @return On success, a pointer to a static NULL-terminated string
1119  * @return If the attribute name is unknown, NULL is returned */
1120 __api __check_ret __pure const char * iio_channel_attr_get_filename(
1121 		const struct iio_channel *chn, const char *attr);
1122 
1123 
1124 /** @brief Read the content of the given channel-specific attribute
1125  * @param chn A pointer to an iio_channel structure
1126  * @param attr A NULL-terminated string corresponding to the name of the
1127  * attribute
1128  * @param dst A pointer to the memory area where the NULL-terminated string
1129  * corresponding to the value read will be stored
1130  * @param len The available length of the memory area, in bytes
1131  * @return On success, the number of bytes written to the buffer
1132  * @return On error, a negative errno code is returned
1133  *
1134  * <b>NOTE:</b>By passing NULL as the "attr" argument to iio_channel_attr_read,
1135  * it is now possible to read all of the attributes of a channel.
1136  *
1137  * The buffer is filled with one block of data per attribute of the channel,
1138  * by the order they appear in the iio_channel structure.
1139  *
1140  * The first four bytes of one block correspond to a 32-bit signed value in
1141  * network order. If negative, it corresponds to the errno code that were
1142  * returned when reading the attribute; if positive, it corresponds to the
1143  * length of the data read. In that case, the rest of the block contains
1144  * the data. */
1145 __api __check_ret ssize_t iio_channel_attr_read(const struct iio_channel *chn,
1146 		const char *attr, char *dst, size_t len);
1147 
1148 
1149 /** @brief Read the content of all channel-specific attributes
1150  * @param chn A pointer to an iio_channel structure
1151  * @param cb A pointer to a callback function
1152  * @param data A pointer that will be passed to the callback function
1153  * @return On success, 0 is returned
1154  * @return On error, a negative errno code is returned
1155  *
1156  * <b>NOTE:</b> This function is especially useful when used with the network
1157  * backend, as all the channel-specific attributes are read in one single
1158  * command. */
1159 __api __check_ret int iio_channel_attr_read_all(struct iio_channel *chn,
1160 		int (*cb)(struct iio_channel *chn,
1161 			const char *attr, const char *val, size_t len, void *d),
1162 		void *data);
1163 
1164 
1165 /** @brief Read the content of the given channel-specific attribute
1166  * @param chn A pointer to an iio_channel structure
1167  * @param attr A NULL-terminated string corresponding to the name of the
1168  * attribute
1169  * @param val A pointer to a bool variable where the value should be stored
1170  * @return On success, 0 is returned
1171  * @return On error, a negative errno code is returned */
1172 __api __check_ret int iio_channel_attr_read_bool(const struct iio_channel *chn,
1173 		const char *attr, bool *val);
1174 
1175 
1176 /** @brief Read the content of the given channel-specific attribute
1177  * @param chn A pointer to an iio_channel structure
1178  * @param attr A NULL-terminated string corresponding to the name of the
1179  * attribute
1180  * @param val A pointer to a long long variable where the value should be stored
1181  * @return On success, 0 is returned
1182  * @return On error, a negative errno code is returned */
1183 __api __check_ret int iio_channel_attr_read_longlong(const struct iio_channel *chn,
1184 		const char *attr, long long *val);
1185 
1186 
1187 /** @brief Read the content of the given channel-specific attribute
1188  * @param chn A pointer to an iio_channel structure
1189  * @param attr A NULL-terminated string corresponding to the name of the
1190  * attribute
1191  * @param val A pointer to a double variable where the value should be stored
1192  * @return On success, 0 is returned
1193  * @return On error, a negative errno code is returned */
1194 __api __check_ret int iio_channel_attr_read_double(const struct iio_channel *chn,
1195 		const char *attr, double *val);
1196 
1197 
1198 /** @brief Set the value of the given channel-specific attribute
1199  * @param chn A pointer to an iio_channel structure
1200  * @param attr A NULL-terminated string corresponding to the name of the
1201  * attribute
1202  * @param src A NULL-terminated string to set the attribute to
1203  * @return On success, the number of bytes written
1204  * @return On error, a negative errno code is returned
1205  *
1206  * <b>NOTE:</b>By passing NULL as the "attr" argument to iio_channel_attr_write,
1207  * it is now possible to write all of the attributes of a channel.
1208  *
1209  * The buffer must contain one block of data per attribute of the channel,
1210  * by the order they appear in the iio_channel structure.
1211  *
1212  * The first four bytes of one block correspond to a 32-bit signed value in
1213  * network order. If negative, the attribute is not written; if positive,
1214  * it corresponds to the length of the data to write. In that case, the rest
1215  * of the block must contain the data. */
1216 __api __check_ret ssize_t iio_channel_attr_write(const struct iio_channel *chn,
1217 		const char *attr, const char *src);
1218 
1219 
1220 /** @brief Set the value of the given channel-specific attribute
1221  * @param chn A pointer to an iio_channel structure
1222  * @param attr A NULL-terminated string corresponding to the name of the
1223  * attribute
1224  * @param src A pointer to the data to be written
1225  * @param len The number of bytes that should be written
1226  * @return On success, the number of bytes written
1227  * @return On error, a negative errno code is returned */
1228 __api __check_ret ssize_t iio_channel_attr_write_raw(const struct iio_channel *chn,
1229 		const char *attr, const void *src, size_t len);
1230 
1231 
1232 /** @brief Set the values of all channel-specific attributes
1233  * @param chn A pointer to an iio_channel structure
1234  * @param cb A pointer to a callback function
1235  * @param data A pointer that will be passed to the callback function
1236  * @return On success, 0 is returned
1237  * @return On error, a negative errno code is returned
1238  *
1239  * <b>NOTE:</b> This function is especially useful when used with the network
1240  * backend, as all the channel-specific attributes are written in one single
1241  * command. */
1242 __api __check_ret int iio_channel_attr_write_all(struct iio_channel *chn,
1243 		ssize_t (*cb)(struct iio_channel *chn,
1244 			const char *attr, void *buf, size_t len, void *d),
1245 		void *data);
1246 
1247 
1248 /** @brief Set the value of the given channel-specific attribute
1249  * @param chn A pointer to an iio_channel structure
1250  * @param attr A NULL-terminated string corresponding to the name of the
1251  * attribute
1252  * @param val A bool value to set the attribute to
1253  * @return On success, 0 is returned
1254  * @return On error, a negative errno code is returned */
1255 __api __check_ret int iio_channel_attr_write_bool(const struct iio_channel *chn,
1256 		const char *attr, bool val);
1257 
1258 
1259 /** @brief Set the value of the given channel-specific attribute
1260  * @param chn A pointer to an iio_channel structure
1261  * @param attr A NULL-terminated string corresponding to the name of the
1262  * attribute
1263  * @param val A long long value to set the attribute to
1264  * @return On success, 0 is returned
1265  * @return On error, a negative errno code is returned */
1266 __api __check_ret int iio_channel_attr_write_longlong(const struct iio_channel *chn,
1267 		const char *attr, long long val);
1268 
1269 
1270 /** @brief Set the value of the given channel-specific attribute
1271  * @param chn A pointer to an iio_channel structure
1272  * @param attr A NULL-terminated string corresponding to the name of the
1273  * attribute
1274  * @param val A double value to set the attribute to
1275  * @return On success, 0 is returned
1276  * @return On error, a negative errno code is returned */
1277 __api __check_ret int iio_channel_attr_write_double(const struct iio_channel *chn,
1278 		const char *attr, double val);
1279 
1280 
1281 /** @brief Enable the given channel
1282  * @param chn A pointer to an iio_channel structure
1283  *
1284  * <b>NOTE:</b>Before creating an iio_buffer structure with
1285  * iio_device_create_buffer, it is required to enable at least one channel of
1286  * the device to read from. */
1287 __api void iio_channel_enable(struct iio_channel *chn);
1288 
1289 
1290 /** @brief Disable the given channel
1291  * @param chn A pointer to an iio_channel structure */
1292 __api void iio_channel_disable(struct iio_channel *chn);
1293 
1294 
1295 /** @brief Returns True if the channel is enabled
1296  * @param chn A pointer to an iio_channel structure
1297  * @return True if the channel is enabled, False otherwise */
1298 __api __check_ret bool iio_channel_is_enabled(const struct iio_channel *chn);
1299 
1300 
1301 /** @brief Demultiplex the samples of a given channel
1302  * @param chn A pointer to an iio_channel structure
1303  * @param buffer A pointer to an iio_buffer structure
1304  * @param dst A pointer to the memory area where the demultiplexed data will be
1305  * stored
1306  * @param len The available length of the memory area, in bytes
1307  * @return The size of the demultiplexed data, in bytes */
1308 __api __check_ret size_t iio_channel_read_raw(const struct iio_channel *chn,
1309 		struct iio_buffer *buffer, void *dst, size_t len);
1310 
1311 
1312 /** @brief Demultiplex and convert the samples of a given channel
1313  * @param chn A pointer to an iio_channel structure
1314  * @param buffer A pointer to an iio_buffer structure
1315  * @param dst A pointer to the memory area where the converted data will be
1316  * stored
1317  * @param len The available length of the memory area, in bytes
1318  * @return The size of the converted data, in bytes */
1319 __api __check_ret size_t iio_channel_read(const struct iio_channel *chn,
1320 		struct iio_buffer *buffer, void *dst, size_t len);
1321 
1322 
1323 /** @brief Multiplex the samples of a given channel
1324  * @param chn A pointer to an iio_channel structure
1325  * @param buffer A pointer to an iio_buffer structure
1326  * @param src A pointer to the memory area where the sequential data will
1327  * be read from
1328  * @param len The length of the memory area, in bytes
1329  * @return The number of bytes actually multiplexed */
1330 __api __check_ret size_t iio_channel_write_raw(const struct iio_channel *chn,
1331 		struct iio_buffer *buffer, const void *src, size_t len);
1332 
1333 
1334 /** @brief Convert and multiplex the samples of a given channel
1335  * @param chn A pointer to an iio_channel structure
1336  * @param buffer A pointer to an iio_buffer structure
1337  * @param src A pointer to the memory area where the sequential data will
1338  * be read from
1339  * @param len The length of the memory area, in bytes
1340  * @return The number of bytes actually converted and multiplexed */
1341 __api __check_ret size_t iio_channel_write(const struct iio_channel *chn,
1342 		struct iio_buffer *buffer, const void *src, size_t len);
1343 
1344 
1345 /** @brief Associate a pointer to an iio_channel structure
1346  * @param chn A pointer to an iio_channel structure
1347  * @param data The pointer to be associated */
1348 __api void iio_channel_set_data(struct iio_channel *chn, void *data);
1349 
1350 
1351 /** @brief Retrieve a previously associated pointer of an iio_channel structure
1352  * @param chn A pointer to an iio_channel structure
1353  * @return The pointer previously associated if present, or NULL */
1354 __api void * iio_channel_get_data(const struct iio_channel *chn);
1355 
1356 
1357 /** @brief Get the type of the given channel
1358  * @param chn A pointer to an iio_channel structure
1359  * @return The type of the channel */
1360 __api __check_ret __pure enum iio_chan_type iio_channel_get_type(
1361 		const struct iio_channel *chn);
1362 
1363 
1364 /** @brief Get the modifier type of the given channel
1365  * @param chn A pointer to an iio_channel structure
1366  * @return The modifier type of the channel */
1367 __api __check_ret __pure enum iio_modifier iio_channel_get_modifier(
1368 		const struct iio_channel *chn);
1369 
1370 
1371 /** @} *//* ------------------------------------------------------------------*/
1372 /* ------------------------- Buffer functions --------------------------------*/
1373 /** @defgroup Buffer Buffer
1374  * @{
1375  * @struct iio_buffer
1376  * @brief An input or output buffer, used to read or write samples */
1377 
1378 
1379 /** @brief Retrieve a pointer to the iio_device structure
1380  * @param buf A pointer to an iio_buffer structure
1381  * @return A pointer to an iio_device structure */
1382 __api __check_ret __pure const struct iio_device * iio_buffer_get_device(
1383 		const struct iio_buffer *buf);
1384 
1385 
1386 /** @brief Create an input or output buffer associated to the given device
1387  * @param dev A pointer to an iio_device structure
1388  * @param samples_count The number of samples that the buffer should contain
1389  * @param cyclic If True, enable cyclic mode
1390  * @return On success, a pointer to an iio_buffer structure
1391  * @return On error, NULL is returned, and errno is set to the error code
1392  *
1393  * <b>NOTE:</b> Channels that have to be written to / read from must be enabled
1394  * before creating the buffer. */
1395 __api __check_ret struct iio_buffer * iio_device_create_buffer(const struct iio_device *dev,
1396 		size_t samples_count, bool cyclic);
1397 
1398 
1399 /** @brief Destroy the given buffer
1400  * @param buf A pointer to an iio_buffer structure
1401  *
1402  * <b>NOTE:</b> After that function, the iio_buffer pointer shall be invalid. */
1403 __api void iio_buffer_destroy(struct iio_buffer *buf);
1404 
1405 /** @brief Get a pollable file descriptor
1406  *
1407  * Can be used to know when iio_buffer_refill() or iio_buffer_push() can be
1408  * called
1409  * @param buf A pointer to an iio_buffer structure
1410  * @return On success, valid file descriptor
1411  * @return On error, a negative errno code is returned
1412  */
1413 __api __check_ret int iio_buffer_get_poll_fd(struct iio_buffer *buf);
1414 
1415 /** @brief Make iio_buffer_refill() and iio_buffer_push() blocking or not
1416  *
1417  * After this function has been called with blocking == false,
1418  * iio_buffer_refill() and iio_buffer_push() will return -EAGAIN if no data is
1419  * ready.
1420  * A device is blocking by default.
1421  * @param buf A pointer to an iio_buffer structure
1422  * @param blocking true if the buffer API should be blocking, else false
1423  * @return On success, 0
1424  * @return On error, a negative errno code is returned
1425  */
1426 __api __check_ret int iio_buffer_set_blocking_mode(struct iio_buffer *buf, bool blocking);
1427 
1428 
1429 /** @brief Fetch more samples from the hardware
1430  * @param buf A pointer to an iio_buffer structure
1431  * @return On success, the number of bytes read is returned
1432  * @return On error, a negative errno code is returned
1433  *
1434  * <b>NOTE:</b> Only valid for input buffers */
1435 __api __check_ret ssize_t iio_buffer_refill(struct iio_buffer *buf);
1436 
1437 
1438 /** @brief Send the samples to the hardware
1439  * @param buf A pointer to an iio_buffer structure
1440  * @return On success, the number of bytes written is returned
1441  * @return On error, a negative errno code is returned
1442  *
1443  * <b>NOTE:</b> Only valid for output buffers */
1444 __api __check_ret ssize_t iio_buffer_push(struct iio_buffer *buf);
1445 
1446 
1447 /** @brief Send a given number of samples to the hardware
1448  * @param buf A pointer to an iio_buffer structure
1449  * @param samples_count The number of samples to submit
1450  * @return On success, the number of bytes written is returned
1451  * @return On error, a negative errno code is returned
1452  *
1453  * <b>NOTE:</b> Only valid for output buffers */
1454 __api __check_ret ssize_t iio_buffer_push_partial(struct iio_buffer *buf,
1455 		size_t samples_count);
1456 
1457 /** @brief Cancel all buffer operations
1458  * @param buf The buffer for which operations should be canceled
1459  *
1460  * This function cancels all outstanding buffer operations previously scheduled.
1461  * This means any pending iio_buffer_push() or iio_buffer_refill() operation
1462  * will abort and return immediately, any further invocations of these functions
1463  * on the same buffer will return immediately with an error.
1464  *
1465  * Usually iio_buffer_push() and iio_buffer_refill() will block until either all
1466  * data has been transferred or a timeout occurs. This can depending on the
1467  * configuration take a significant amount of time. iio_buffer_cancel() is
1468  * useful to bypass these conditions if the buffer operation is supposed to be
1469  * stopped in response to an external event (e.g. user input).
1470  *
1471  * To be able to capture additional data after calling this function the buffer
1472  * should be destroyed and then re-created.
1473  *
1474  * This function can be called multiple times for the same buffer, but all but
1475  * the first invocation will be without additional effect.
1476  *
1477  * This function is thread-safe, but not signal-safe, i.e. it must not be called
1478  * from a signal handler.
1479  */
1480 __api void iio_buffer_cancel(struct iio_buffer *buf);
1481 
1482 
1483 /** @brief Get the start address of the buffer
1484  * @param buf A pointer to an iio_buffer structure
1485  * @return A pointer corresponding to the start address of the buffer */
1486 __api void * iio_buffer_start(const struct iio_buffer *buf);
1487 
1488 
1489 /** @brief Find the first sample of a channel in a buffer
1490  * @param buf A pointer to an iio_buffer structure
1491  * @param chn A pointer to an iio_channel structure
1492  * @return A pointer to the first sample found, or to the end of the buffer if
1493  * no sample for the given channel is present in the buffer
1494  *
1495  * <b>NOTE:</b> This function, coupled with iio_buffer_step and iio_buffer_end,
1496  * can be used to iterate on all the samples of a given channel present in the
1497  * buffer, doing the following:
1498  *
1499  * @verbatim
1500  for (void *ptr = iio_buffer_first(buffer, chn); ptr < iio_buffer_end(buffer); ptr += iio_buffer_step(buffer)) {
1501     ....
1502  }
1503  @endverbatim */
1504 __api void * iio_buffer_first(const struct iio_buffer *buf,
1505 		const struct iio_channel *chn);
1506 
1507 
1508 /** @brief Get the step size between two samples of one channel
1509  * @param buf A pointer to an iio_buffer structure
1510  * @return the difference between the addresses of two consecutive samples of
1511  * one same channel */
1512 __api __check_ret ptrdiff_t iio_buffer_step(const struct iio_buffer *buf);
1513 
1514 
1515 /** @brief Get the address that follows the last sample in a buffer
1516  * @param buf A pointer to an iio_buffer structure
1517  * @return A pointer corresponding to the address that follows the last sample
1518  * present in the buffer */
1519 __api void * iio_buffer_end(const struct iio_buffer *buf);
1520 
1521 
1522 /** @brief Call the supplied callback for each sample found in a buffer
1523  * @param buf A pointer to an iio_buffer structure
1524  * @param callback A pointer to a function to call for each sample found
1525  * @param data A user-specified pointer that will be passed to the callback
1526  * @return number of bytes processed.
1527  *
1528  * <b>NOTE:</b> The callback receives four arguments:
1529  * * A pointer to the iio_channel structure corresponding to the sample,
1530  * * A pointer to the sample itself,
1531  * * The length of the sample in bytes,
1532  * * The user-specified pointer passed to iio_buffer_foreach_sample. */
1533 __api __check_ret ssize_t iio_buffer_foreach_sample(struct iio_buffer *buf,
1534 		ssize_t (*callback)(const struct iio_channel *chn,
1535 			void *src, size_t bytes, void *d), void *data);
1536 
1537 
1538 /** @brief Associate a pointer to an iio_buffer structure
1539  * @param buf A pointer to an iio_buffer structure
1540  * @param data The pointer to be associated */
1541 __api void iio_buffer_set_data(struct iio_buffer *buf, void *data);
1542 
1543 
1544 /** @brief Retrieve a previously associated pointer of an iio_buffer structure
1545  * @param buf A pointer to an iio_buffer structure
1546  * @return The pointer previously associated if present, or NULL */
1547 __api void * iio_buffer_get_data(const struct iio_buffer *buf);
1548 
1549 
1550 /** @} *//* ------------------------------------------------------------------*/
1551 /* ------------------------- Low-level functions -----------------------------*/
1552 /** @defgroup Debug Debug and low-level functions
1553  * @{
1554  * @struct iio_data_format
1555  * @brief Contains the format of a data sample.
1556  *
1557  * The different fields inform about the correct way to convert one sample from
1558  * its raw format (as read from / generated by the hardware) to its real-world
1559  * value.
1560  */
1561 struct iio_data_format {
1562 	/** @brief Total length of the sample, in bits */
1563 	unsigned int length;
1564 
1565 	/** @brief Length of valuable data in the sample, in bits */
1566 	unsigned int bits;
1567 
1568 	/** @brief Right-shift to apply when converting sample */
1569 	unsigned int shift;
1570 
1571 	/** @brief Contains True if the sample is signed */
1572 	bool is_signed;
1573 
1574 	/** @brief Contains True if the sample is fully defined, sign extended, etc. */
1575 	bool is_fully_defined;
1576 
1577 	/** @brief Contains True if the sample is in big-endian format */
1578 	bool is_be;
1579 
1580 	/** @brief Contains True if the sample should be scaled when converted */
1581 	bool with_scale;
1582 
1583 	/** @brief Contains the scale to apply if with_scale is set */
1584 	double scale;
1585 
1586 	/** @brief Number of times length repeats (added in v0.8) */
1587 	unsigned int repeat;
1588 };
1589 
1590 
1591 /** @brief Get the current sample size
1592  * @param dev A pointer to an iio_device structure
1593  * @return On success, the sample size in bytes
1594  * @return On error, a negative errno code is returned
1595  *
1596  * <b>NOTE:</b> The sample size is not constant and will change when channels
1597  * get enabled or disabled. */
1598 __api __check_ret ssize_t iio_device_get_sample_size(const struct iio_device *dev);
1599 
1600 
1601 /** @brief Get the index of the given channel
1602  * @param chn A pointer to an iio_channel structure
1603  * @return On success, the index of the specified channel
1604  * @return On error, a negative errno code is returned */
1605 __api __check_ret __pure long iio_channel_get_index(const struct iio_channel *chn);
1606 
1607 
1608 /** @brief Get a pointer to a channel's data format structure
1609  * @param chn A pointer to an iio_channel structure
1610  * @return A pointer to the channel's iio_data_format structure */
1611 __api __check_ret __cnst const struct iio_data_format * iio_channel_get_data_format(
1612 		const struct iio_channel *chn);
1613 
1614 
1615 /** @brief Convert the sample from hardware format to host format
1616  * @param chn A pointer to an iio_channel structure
1617  * @param dst A pointer to the destination buffer where the converted sample
1618  * should be written
1619  * @param src A pointer to the source buffer containing the sample */
1620 __api void iio_channel_convert(const struct iio_channel *chn,
1621 		void *dst, const void *src);
1622 
1623 
1624 /** @brief Convert the sample from host format to hardware format
1625  * @param chn A pointer to an iio_channel structure
1626  * @param dst A pointer to the destination buffer where the converted sample
1627  * should be written
1628  * @param src A pointer to the source buffer containing the sample */
1629 __api void iio_channel_convert_inverse(const struct iio_channel *chn,
1630 		void *dst, const void *src);
1631 
1632 
1633 /** @brief Enumerate the debug attributes of the given device
1634  * @param dev A pointer to an iio_device structure
1635  * @return The number of debug attributes found */
1636 __api __check_ret __pure unsigned int iio_device_get_debug_attrs_count(
1637 		const struct iio_device *dev);
1638 
1639 
1640 /** @brief Get the debug attribute present at the given index
1641  * @param dev A pointer to an iio_device structure
1642  * @param index The index corresponding to the debug attribute
1643  * @return On success, a pointer to a static NULL-terminated string
1644  * @return If the index is invalid, NULL is returned */
1645 __api __check_ret __pure const char * iio_device_get_debug_attr(
1646 		const struct iio_device *dev, unsigned int index);
1647 
1648 
1649 /** @brief Try to find a debug attribute by its name
1650  * @param dev A pointer to an iio_device structure
1651  * @param name A NULL-terminated string corresponding to the name of the
1652  * debug attribute
1653  * @return On success, a pointer to a static NULL-terminated string
1654  * @return If the name does not correspond to any known debug attribute of the
1655  * given device, NULL is returned
1656  *
1657  * <b>NOTE:</b> This function is useful to detect the presence of a debug
1658  * attribute.
1659  * It can also be used to retrieve the name of a debug attribute as a pointer
1660  * to a static string from a dynamically allocated string. */
1661 __api __check_ret __pure const char * iio_device_find_debug_attr(
1662 		const struct iio_device *dev, const char *name);
1663 
1664 
1665 /** @brief Read the content of the given debug attribute
1666  * @param dev A pointer to an iio_device structure
1667  * @param attr A NULL-terminated string corresponding to the name of the
1668  * debug attribute
1669  * @param dst A pointer to the memory area where the NULL-terminated string
1670  * corresponding to the value read will be stored
1671  * @param len The available length of the memory area, in bytes
1672  * @return On success, the number of bytes written to the buffer
1673  * @return On error, a negative errno code is returned
1674  *
1675  * <b>NOTE:</b>By passing NULL as the "attr" argument to
1676  * iio_device_debug_attr_read, it is now possible to read all of the debug
1677  * attributes of a device.
1678  *
1679  * The buffer is filled with one block of data per debug attribute of the
1680  * device, by the order they appear in the iio_device structure.
1681  *
1682  * The first four bytes of one block correspond to a 32-bit signed value in
1683  * network order. If negative, it corresponds to the errno code that were
1684  * returned when reading the debug attribute; if positive, it corresponds
1685  * to the length of the data read. In that case, the rest of the block contains
1686  * the data. */
1687 __api __check_ret ssize_t iio_device_debug_attr_read(const struct iio_device *dev,
1688 		const char *attr, char *dst, size_t len);
1689 
1690 
1691 /** @brief Read the content of all debug attributes
1692  * @param dev A pointer to an iio_device structure
1693  * @param cb A pointer to a callback function
1694  * @param data A pointer that will be passed to the callback function
1695  * @return On success, 0 is returned
1696  * @return On error, a negative errno code is returned
1697  *
1698  * <b>NOTE:</b> This function is especially useful when used with the network
1699  * backend, as all the debug attributes are read in one single command. */
1700 __api __check_ret int iio_device_debug_attr_read_all(struct iio_device *dev,
1701 		int (*cb)(struct iio_device *dev, const char *attr,
1702 			const char *value, size_t len, void *d),
1703 		void *data);
1704 
1705 
1706 /** @brief Set the value of the given debug attribute
1707  * @param dev A pointer to an iio_device structure
1708  * @param attr A NULL-terminated string corresponding to the name of the
1709  * debug attribute
1710  * @param src A NULL-terminated string to set the debug attribute to
1711  * @return On success, the number of bytes written
1712  * @return On error, a negative errno code is returned
1713  *
1714  * <b>NOTE:</b>By passing NULL as the "attr" argument to
1715  * iio_device_debug_attr_write, it is now possible to write all of the
1716  * debug attributes of a device.
1717  *
1718  * The buffer must contain one block of data per debug attribute of the device,
1719  * by the order they appear in the iio_device structure.
1720  *
1721  * The first four bytes of one block correspond to a 32-bit signed value in
1722  * network order. If negative, the debug attribute is not written; if positive,
1723  * it corresponds to the length of the data to write. In that case, the rest
1724  * of the block must contain the data. */
1725 __api __check_ret ssize_t iio_device_debug_attr_write(const struct iio_device *dev,
1726 		const char *attr, const char *src);
1727 
1728 
1729 /** @brief Set the value of the given debug attribute
1730  * @param dev A pointer to an iio_device structure
1731  * @param attr A NULL-terminated string corresponding to the name of the
1732  * debug attribute
1733  * @param src A pointer to the data to be written
1734  * @param len The number of bytes that should be written
1735  * @return On success, the number of bytes written
1736  * @return On error, a negative errno code is returned */
1737 __api __check_ret ssize_t iio_device_debug_attr_write_raw(const struct iio_device *dev,
1738 		const char *attr, const void *src, size_t len);
1739 
1740 
1741 /** @brief Set the values of all debug attributes
1742  * @param dev A pointer to an iio_device structure
1743  * @param cb A pointer to a callback function
1744  * @param data A pointer that will be passed to the callback function
1745  * @return On success, 0 is returned
1746  * @return On error, a negative errno code is returned
1747  *
1748  * <b>NOTE:</b> This function is especially useful when used with the network
1749  * backend, as all the debug attributes are written in one single command. */
1750 __api __check_ret int iio_device_debug_attr_write_all(struct iio_device *dev,
1751 		ssize_t (*cb)(struct iio_device *dev,
1752 			const char *attr, void *buf, size_t len, void *d),
1753 		void *data);
1754 
1755 
1756 /** @brief Read the content of the given debug attribute
1757  * @param dev A pointer to an iio_device structure
1758  * @param attr A NULL-terminated string corresponding to the name of the
1759  * debug attribute
1760  * @param val A pointer to a bool variable where the value should be stored
1761  * @return On success, 0 is returned
1762  * @return On error, a negative errno code is returned */
1763 __api __check_ret int iio_device_debug_attr_read_bool(const struct iio_device *dev,
1764 		const char *attr, bool *val);
1765 
1766 
1767 /** @brief Read the content of the given debug attribute
1768  * @param dev A pointer to an iio_device structure
1769  * @param attr A NULL-terminated string corresponding to the name of the
1770  * debug attribute
1771  * @param val A pointer to a long long variable where the value should be stored
1772  * @return On success, 0 is returned
1773  * @return On error, a negative errno code is returned */
1774 __api __check_ret int iio_device_debug_attr_read_longlong(const struct iio_device *dev,
1775 		const char *attr, long long *val);
1776 
1777 
1778 /** @brief Read the content of the given debug attribute
1779  * @param dev A pointer to an iio_device structure
1780  * @param attr A NULL-terminated string corresponding to the name of the
1781  * debug attribute
1782  * @param val A pointer to a double variable where the value should be stored
1783  * @return On success, 0 is returned
1784  * @return On error, a negative errno code is returned */
1785 __api __check_ret int iio_device_debug_attr_read_double(const struct iio_device *dev,
1786 		const char *attr, double *val);
1787 
1788 
1789 /** @brief Set the value of the given debug attribute
1790  * @param dev A pointer to an iio_device structure
1791  * @param attr A NULL-terminated string corresponding to the name of the
1792  * debug attribute
1793  * @param val A bool value to set the debug attribute to
1794  * @return On success, 0 is returned
1795  * @return On error, a negative errno code is returned */
1796 __api __check_ret int iio_device_debug_attr_write_bool(const struct iio_device *dev,
1797 		const char *attr, bool val);
1798 
1799 
1800 /** @brief Set the value of the given debug attribute
1801  * @param dev A pointer to an iio_device structure
1802  * @param attr A NULL-terminated string corresponding to the name of the
1803  * debug attribute
1804  * @param val A long long value to set the debug attribute to
1805  * @return On success, 0 is returned
1806  * @return On error, a negative errno code is returned */
1807 __api __check_ret int iio_device_debug_attr_write_longlong(const struct iio_device *dev,
1808 		const char *attr, long long val);
1809 
1810 
1811 /** @brief Set the value of the given debug attribute
1812  * @param dev A pointer to an iio_device structure
1813  * @param attr A NULL-terminated string corresponding to the name of the
1814  * debug attribute
1815  * @param val A double value to set the debug attribute to
1816  * @return On success, 0 is returned
1817  * @return On error, a negative errno code is returned */
1818 __api __check_ret int iio_device_debug_attr_write_double(const struct iio_device *dev,
1819 		const char *attr, double val);
1820 
1821 
1822 /** @brief Identify the channel or debug attribute corresponding to a filename
1823  * @param dev A pointer to an iio_device structure
1824  * @param filename A NULL-terminated string corresponding to the filename
1825  * @param chn A pointer to a pointer of an iio_channel structure. The pointed
1826  * pointer will be set to the address of the iio_channel structure if the
1827  * filename correspond to the attribute of a channel, or NULL otherwise.
1828  * @param attr A pointer to a NULL-terminated string. The pointer
1829  * pointer will be set to point to the name of the attribute corresponding to
1830  * the filename.
1831  * @return On success, 0 is returned, and *chn and *attr are modified.
1832  * @return On error, a negative errno code is returned. *chn and *attr are not
1833  * modified. */
1834 __api __check_ret int iio_device_identify_filename(const struct iio_device *dev,
1835 		const char *filename, struct iio_channel **chn,
1836 		const char **attr);
1837 
1838 
1839 /** @brief Set the value of a hardware register
1840  * @param dev A pointer to an iio_device structure
1841  * @param address The address of the register
1842  * @param value The value to set the register to
1843  * @return On success, 0 is returned
1844  * @return On error, a negative errno code is returned */
1845 __api __check_ret int iio_device_reg_write(struct iio_device *dev,
1846 		uint32_t address, uint32_t value);
1847 
1848 
1849 /** @brief Get the value of a hardware register
1850  * @param dev A pointer to an iio_device structure
1851  * @param address The address of the register
1852  * @param value A pointer to the variable where the value will be written
1853  * @return On success, 0 is returned
1854  * @return On error, a negative errno code is returned */
1855 __api __check_ret int iio_device_reg_read(struct iio_device *dev,
1856 		uint32_t address, uint32_t *value);
1857 
1858 
1859 /** @} */
1860 
1861 #ifdef __cplusplus
1862 }
1863 #endif
1864 
1865 #undef __api
1866 
1867 #endif /* __IIO_H__ */
1868