blob: b0214ecef2603a33d8fcef4d5c210a697962f673 [file] [log] [blame]
Paul Cercueilbb4401d2014-02-28 16:10:49 +01001/*
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
Paul Cercueil306cb1c2014-04-11 14:46:45 +020019/** @file iio.h
20 * @brief Public interface */
21
Paul Cercueil0b2ce712014-02-17 15:04:18 +010022#ifndef __IIO_H__
23#define __IIO_H__
24
Paul Cercueila167e0c2014-04-08 14:50:41 +020025#ifdef __cplusplus
26extern "C" {
27#endif
28
Paul Cercueil35a01312014-02-20 10:56:57 +010029#include <stdbool.h>
Paul Cercueile1311222014-03-12 15:46:16 +010030#include <stdint.h>
Paul Cercueil0b2ce712014-02-17 15:04:18 +010031#include <stdlib.h>
Paul Cercueilecbf4ed2014-03-17 15:02:43 +010032#include <sys/types.h>
Paul Cercueil95347b92014-03-21 09:50:17 +010033#include <stddef.h>
Paul Cercueil0b2ce712014-02-17 15:04:18 +010034
Paul Cercueilb669f692014-04-04 13:42:24 +020035#ifdef _MSC_BUILD
36/* Come on Microsoft, time to get some C99... */
37typedef long ssize_t;
Paul Cercueilb669f692014-04-04 13:42:24 +020038#endif
39
Paul Cercueil59f2aa32014-04-04 16:28:51 +020040#ifdef __GNUC__
41#define __cnst __attribute__((const))
42#define __pure __attribute__((pure))
43#else
44#define __cnst
45#define __pure
46#endif
47
48#ifdef _WIN32
49# ifdef LIBIIO_EXPORTS
Paul Cercueil59f2aa32014-04-04 16:28:51 +020050# define __api __declspec(dllexport)
Paul Cercueil7288c332014-04-07 16:25:11 +020051# else
52# define __api __declspec(dllimport)
Paul Cercueil59f2aa32014-04-04 16:28:51 +020053# endif
54#elif __GNUC__ >= 4
55# define __api __attribute__((visibility ("default")))
56#else
57# define __api
58#endif
59
Paul Cercueil0b2ce712014-02-17 15:04:18 +010060struct iio_context;
61struct iio_device;
62struct iio_channel;
Paul Cercueila689cd92014-03-20 16:37:25 +010063struct iio_buffer;
Paul Cercueil0b2ce712014-02-17 15:04:18 +010064
Paul Cercueilb4afdd92014-04-08 12:37:21 +020065
Paul Cercueil306cb1c2014-04-11 14:46:45 +020066/* ---------------------------------------------------------------------------*/
Paul Cercueilb4afdd92014-04-08 12:37:21 +020067/* ------------------------- Context functions -------------------------------*/
Paul Cercueil306cb1c2014-04-11 14:46:45 +020068/** @defgroup Context Context
69 * @{
70 * @struct iio_context
71 * @brief Contains the representation of an IIO context */
Paul Cercueilb4afdd92014-04-08 12:37:21 +020072
Paul Cercueil306cb1c2014-04-11 14:46:45 +020073
74/** @brief Create a context from local IIO devices (Linux only).
75 * @return On success, A pointer to an iio_context structure
76 * @return On failure, NULL is returned */
Paul Cercueil59f2aa32014-04-04 16:28:51 +020077__api struct iio_context * iio_create_local_context(void);
Paul Cercueilb4afdd92014-04-08 12:37:21 +020078
Paul Cercueil306cb1c2014-04-11 14:46:45 +020079
Paul Cercueil20407c22014-04-23 17:02:21 +020080/** @brief Create a context from local IIO devices (Linux only).
81 * @return On success, A pointer to an iio_context structure
82 * @return On failure, NULL is returned
83 *
84 * <b>NOTE:</b> This backend uses mmap() to access the kernel buffers.
85 * It should be preferred over iio_create_local_context() for high-speed
86 * devices. */
87__api struct iio_context * iio_create_local_mmap_context(void);
88
89
Paul Cercueil306cb1c2014-04-11 14:46:45 +020090/** @brief Create a context from a XML file
91 * @param xml_file Path to the XML file to open
92 * @return On success, A pointer to an iio_context structure
93 * @return On failure, NULL is returned
94 *
95 * <b>NOTE:</b> The format of the XML must comply to the one returned by
96 * iio_context_get_xml. */
Paul Cercueil59f2aa32014-04-04 16:28:51 +020097__api struct iio_context * iio_create_xml_context(const char *xml_file);
Paul Cercueil306cb1c2014-04-11 14:46:45 +020098
99
100/** @brief Create a context from XML data in memory
101 * @param xml Pointer to the XML data in memory
102 * @param len Length of the XML string in memory (excluding the final \0)
103 * @return On success, A pointer to an iio_context structure
104 * @return On failure, NULL is returned
105 *
106 * <b>NOTE:</b> The format of the XML must comply to the one returned by
107 * iio_context_get_xml */
Paul Cercueil59f2aa32014-04-04 16:28:51 +0200108__api struct iio_context * iio_create_xml_context_mem(
109 const char *xml, size_t len);
Paul Cercueilb4afdd92014-04-08 12:37:21 +0200110
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200111
112/** @brief Create a context from the network
113 * @param host Hostname, IPv4 or IPv6 address where the IIO Daemon is running
114 * @return On success, a pointer to an iio_context structure
115 * @return On failure, NULL is returned */
Paul Cercueil59f2aa32014-04-04 16:28:51 +0200116__api struct iio_context * iio_create_network_context(const char *host);
Paul Cercueilb4afdd92014-04-08 12:37:21 +0200117
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200118
119/** @brief Destroy the given context
120 * @param ctx A pointer to an iio_context structure
121 *
122 * <b>NOTE:</b> After that function, the iio_context pointer shall be invalid. */
Paul Cercueil59f2aa32014-04-04 16:28:51 +0200123__api void iio_context_destroy(struct iio_context *ctx);
Paul Cercueil0b2ce712014-02-17 15:04:18 +0100124
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200125
126/** @brief Obtain a XML representation of the given context
127 * @param ctx A pointer to an iio_context structure
128 * @return A pointer to a static NULL-terminated string */
Paul Cercueilb4afdd92014-04-08 12:37:21 +0200129__api __pure const char * iio_context_get_xml(const struct iio_context *ctx);
130
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200131
132/** @brief Get the name of the given context
133 * @param ctx A pointer to an iio_context structure
134 * @return A pointer to a static NULL-terminated string
135 *
136 * <b>NOTE:</b>The returned string will be <b><i>local</i></b>,
137 * <b><i>xml</i></b> or <b><i>network</i></b> when the context has been
138 * created with the local, xml and network backends respectively.*/
Paul Cercueil59f2aa32014-04-04 16:28:51 +0200139__api __pure const char * iio_context_get_name(const struct iio_context *ctx);
Paul Cercueilb4afdd92014-04-08 12:37:21 +0200140
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200141
142/** @brief Enumerate the devices found in the given context
143 * @param ctx A pointer to an iio_context structure
144 * @return The number of devices found */
Paul Cercueil59f2aa32014-04-04 16:28:51 +0200145__api __pure unsigned int iio_context_get_devices_count(
146 const struct iio_context *ctx);
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200147
148
149/** @brief Get the device present at the given index
150 * @param ctx A pointer to an iio_context structure
151 * @param index The index corresponding to the device
152 * @return On success, a pointer to an iio_device structure
153 * @return If the index is invalid, NULL is returned */
Paul Cercueil59f2aa32014-04-04 16:28:51 +0200154__api __pure struct iio_device * iio_context_get_device(
155 const struct iio_context *ctx, unsigned int index);
Paul Cercueilb4afdd92014-04-08 12:37:21 +0200156
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200157
158/** @brief Try to find a device structure by its name of ID
159 * @param ctx A pointer to an iio_context structure
160 * @param name A NULL-terminated string corresponding to the name or the ID of
161 * the device to search for
162 * @return On success, a pointer to an iio_device structure
163 * @return If the name or ID does not correspond to any known device, NULL is
164 * returned */
Paul Cercueil59f2aa32014-04-04 16:28:51 +0200165__api __pure struct iio_device * iio_context_find_device(
166 const struct iio_context *ctx, const char *name);
Paul Cercueil0b2ce712014-02-17 15:04:18 +0100167
Paul Cercueilb4afdd92014-04-08 12:37:21 +0200168
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200169/** @} *//* ------------------------------------------------------------------*/
Paul Cercueilb4afdd92014-04-08 12:37:21 +0200170/* ------------------------- Device functions --------------------------------*/
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200171/** @defgroup Device Device
172 * @{
173 * @struct iio_device
174 * @brief Represents a device in the IIO context */
Paul Cercueilb4afdd92014-04-08 12:37:21 +0200175
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200176
177/** @brief Retrieve the device ID (e.g. <b><i>iio:device0</i></b>)
178 * @param dev A pointer to an iio_device structure
179 * @return A pointer to a static NULL-terminated string */
Paul Cercueil59f2aa32014-04-04 16:28:51 +0200180__api __pure const char * iio_device_get_id(const struct iio_device *dev);
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200181
182
183/** @brief Retrieve the device name (e.g. <b><i>xadc</i></b>)
184 * @param dev A pointer to an iio_device structure
185 * @return A pointer to a static NULL-terminated string
186 *
187 * <b>NOTE:</b> if the device has no name, NULL is returned. */
Paul Cercueil59f2aa32014-04-04 16:28:51 +0200188__api __pure const char * iio_device_get_name(const struct iio_device *dev);
Paul Cercueilb4afdd92014-04-08 12:37:21 +0200189
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200190
191/** @brief Enumerate the channels of the given device
192 * @param dev A pointer to an iio_device structure
193 * @return The number of channels found */
Paul Cercueil59f2aa32014-04-04 16:28:51 +0200194__api __pure unsigned int iio_device_get_channels_count(
195 const struct iio_device *dev);
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200196
197
198/** @brief Enumerate the device-specific attributes of the given device
199 * @param dev A pointer to an iio_device structure
200 * @return The number of device-specific attributes found */
Paul Cercueil59f2aa32014-04-04 16:28:51 +0200201__api __pure unsigned int iio_device_get_attrs_count(
202 const struct iio_device *dev);
Paul Cercueilb4afdd92014-04-08 12:37:21 +0200203
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200204
205/** @brief Get the channel present at the given index
206 * @param dev A pointer to an iio_device structure
207 * @param index The index corresponding to the channel
208 * @return On success, a pointer to an iio_channel structure
209 * @return If the index is invalid, NULL is returned */
Paul Cercueilb4afdd92014-04-08 12:37:21 +0200210__api __pure struct iio_channel * iio_device_get_channel(
211 const struct iio_device *dev, unsigned int index);
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200212
213
214/** @brief Get the device-specific attribute present at the given index
215 * @param dev A pointer to an iio_device structure
216 * @param index The index corresponding to the attribute
217 * @return On success, a pointer to a static NULL-terminated string
218 * @return If the index is invalid, NULL is returned */
Paul Cercueil59f2aa32014-04-04 16:28:51 +0200219__api __pure const char * iio_device_get_attr(
220 const struct iio_device *dev, unsigned int index);
Paul Cercueilb4afdd92014-04-08 12:37:21 +0200221
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200222
223/** @brief Try to find a channel structure by its name of ID
224 * @param dev A pointer to an iio_device structure
225 * @param name A NULL-terminated string corresponding to the name or the ID of
226 * the channel to search for
227 * @param output True if the searched channel is output, False otherwise
228 * @return On success, a pointer to an iio_channel structure
229 * @return If the name or ID does not correspond to any known channel of the
230 * given device, NULL is returned */
Paul Cercueilb4afdd92014-04-08 12:37:21 +0200231__api __pure struct iio_channel * iio_device_find_channel(
232 const struct iio_device *dev, const char *name, bool output);
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200233
234
235/** @brief Try to find a device-specific attribute by its name
236 * @param dev A pointer to an iio_device structure
Paul Cercueil30606d52014-04-14 16:04:15 +0200237 * @param name A NULL-terminated string corresponding to the name of the
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200238 * attribute
239 * @return On success, a pointer to a static NULL-terminated string
240 * @return If the name does not correspond to any known attribute of the given
241 * device, NULL is returned
242 *
243 * <b>NOTE:</b> This function is useful to detect the presence of an attribute.
244 * It can also be used to retrieve the name of an attribute as a pointer to a
245 * static string from a dynamically allocated string. */
Paul Cercueil59f2aa32014-04-04 16:28:51 +0200246__api __pure const char * iio_device_find_attr(
247 const struct iio_device *dev, const char *name);
Paul Cercueilb4afdd92014-04-08 12:37:21 +0200248
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200249
250/** @brief Read the content of the given device-specific attribute
251 * @param dev A pointer to an iio_device structure
Paul Cercueil30606d52014-04-14 16:04:15 +0200252 * @param attr A NULL-terminated string corresponding to the name of the
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200253 * attribute
254 * @param dst A pointer to the memory area where the NULL-terminated string
255 * corresponding to the value read will be stored
256 * @param len The available length of the memory area, in bytes
257 * @return On success, the number of bytes written to the buffer
258 * @return On error, a negative errno code is returned */
Paul Cercueilb4afdd92014-04-08 12:37:21 +0200259__api ssize_t iio_device_attr_read(const struct iio_device *dev,
260 const char *attr, char *dst, size_t len);
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200261
262
263/** @brief Read the content of the given device-specific attribute
264 * @param dev A pointer to an iio_device structure
Paul Cercueil30606d52014-04-14 16:04:15 +0200265 * @param attr A NULL-terminated string corresponding to the name of the
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200266 * attribute
267 * @param val A pointer to a bool variable where the value should be stored
268 * @return On success, 0 is returned
269 * @return On error, a negative errno code is returned */
Paul Cercueilb4afdd92014-04-08 12:37:21 +0200270__api int iio_device_attr_read_bool(const struct iio_device *dev,
271 const char *attr, bool *val);
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200272
273
274/** @brief Read the content of the given device-specific attribute
275 * @param dev A pointer to an iio_device structure
Paul Cercueil30606d52014-04-14 16:04:15 +0200276 * @param attr A NULL-terminated string corresponding to the name of the
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200277 * attribute
278 * @param val A pointer to a long long variable where the value should be stored
279 * @return On success, 0 is returned
280 * @return On error, a negative errno code is returned */
Paul Cercueilb4afdd92014-04-08 12:37:21 +0200281__api int iio_device_attr_read_longlong(const struct iio_device *dev,
282 const char *attr, long long *val);
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200283
284
285/** @brief Read the content of the given device-specific attribute
286 * @param dev A pointer to an iio_device structure
Paul Cercueil30606d52014-04-14 16:04:15 +0200287 * @param attr A NULL-terminated string corresponding to the name of the
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200288 * attribute
289 * @param val A pointer to a double variable where the value should be stored
290 * @return On success, 0 is returned
291 * @return On error, a negative errno code is returned */
Paul Cercueilb4afdd92014-04-08 12:37:21 +0200292__api int iio_device_attr_read_double(const struct iio_device *dev,
293 const char *attr, double *val);
294
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200295
296/** @brief Set the value of the given device-specific attribute
297 * @param dev A pointer to an iio_device structure
Paul Cercueil30606d52014-04-14 16:04:15 +0200298 * @param attr A NULL-terminated string corresponding to the name of the
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200299 * attribute
300 * @param src A NULL-terminated string to set the attribute to
301 * @return On success, the number of bytes written
302 * @return On error, a negative errno code is returned */
Paul Cercueilb4afdd92014-04-08 12:37:21 +0200303__api ssize_t iio_device_attr_write(const struct iio_device *dev,
304 const char *attr, const char *src);
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200305
306
307/** @brief Set the value of the given device-specific attribute
308 * @param dev A pointer to an iio_device structure
Paul Cercueil30606d52014-04-14 16:04:15 +0200309 * @param attr A NULL-terminated string corresponding to the name of the
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200310 * attribute
311 * @param val A bool value to set the attribute to
312 * @return On success, 0 is returned
313 * @return On error, a negative errno code is returned */
Paul Cercueilb4afdd92014-04-08 12:37:21 +0200314__api int iio_device_attr_write_bool(const struct iio_device *dev,
315 const char *attr, bool val);
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200316
317
318/** @brief Set the value of the given device-specific attribute
319 * @param dev A pointer to an iio_device structure
Paul Cercueil30606d52014-04-14 16:04:15 +0200320 * @param attr A NULL-terminated string corresponding to the name of the
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200321 * attribute
322 * @param val A long long value to set the attribute to
323 * @return On success, 0 is returned
324 * @return On error, a negative errno code is returned */
Paul Cercueilb4afdd92014-04-08 12:37:21 +0200325__api int iio_device_attr_write_longlong(const struct iio_device *dev,
326 const char *attr, long long val);
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200327
328
329/** @brief Set the value of the given device-specific attribute
330 * @param dev A pointer to an iio_device structure
Paul Cercueil30606d52014-04-14 16:04:15 +0200331 * @param attr A NULL-terminated string corresponding to the name of the
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200332 * attribute
333 * @param val A double value to set the attribute to
334 * @return On success, 0 is returned
335 * @return On error, a negative errno code is returned */
Paul Cercueilb4afdd92014-04-08 12:37:21 +0200336__api int iio_device_attr_write_double(const struct iio_device *dev,
337 const char *attr, double val);
338
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200339
340/** @brief Associate a pointer to an iio_device structure
341 * @param dev A pointer to an iio_device structure
342 * @param data The pointer to be associated */
Paul Cercueilb4afdd92014-04-08 12:37:21 +0200343__api void iio_device_set_data(struct iio_device *dev, void *data);
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200344
345
346/** @brief Retrieve a previously associated pointer of an iio_device structure
347 * @param dev A pointer to an iio_device structure
348 * @return The pointer previously associated if present, or NULL */
Paul Cercueilb4afdd92014-04-08 12:37:21 +0200349__api void * iio_device_get_data(const struct iio_device *dev);
350
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200351
352/** @brief Retrieve the trigger of a given device
353 * @param dev A pointer to an iio_device structure
354 * @param trigger a pointer to a pointer of an iio_device structure. The pointed
355 * pointer will be set to the address of the iio_device structure corresponding
356 * to the associated trigger device.
357 * @return On success, 0 is returned
358 * @return On error, a negative errno code is returned */
Paul Cercueil59f2aa32014-04-04 16:28:51 +0200359__api int iio_device_get_trigger(const struct iio_device *dev,
Paul Cercueil24ffa532014-03-10 12:39:58 +0100360 const struct iio_device **trigger);
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200361
362
363/** @brief Associate a trigger to a given device
364 * @param dev A pointer to an iio_device structure
365 * @param trigger a pointer to the iio_device structure corresponding to the
366 * trigger that should be associated.
367 * @return On success, 0 is returned
368 * @return On error, a negative errno code is returned */
Paul Cercueil59f2aa32014-04-04 16:28:51 +0200369__api int iio_device_set_trigger(const struct iio_device *dev,
Paul Cercueil24ffa532014-03-10 12:39:58 +0100370 const struct iio_device *trigger);
Paul Cercueil0b2ce712014-02-17 15:04:18 +0100371
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200372
373/** @brief Return True if the given device is a trigger
374 * @param dev A pointer to an iio_device structure
375 * @return True if the device is a trigger, False otherwise */
Paul Cercueilb4afdd92014-04-08 12:37:21 +0200376__api __pure bool iio_device_is_trigger(const struct iio_device *dev);
377
Paul Cercueilb4afdd92014-04-08 12:37:21 +0200378
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200379/** @} *//* ------------------------------------------------------------------*/
Paul Cercueilb4afdd92014-04-08 12:37:21 +0200380/* ------------------------- Channel functions -------------------------------*/
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200381/** @defgroup Channel Channel
382 * @{
383 * @struct iio_channel
384 * @brief Represents an input or output channel of a device */
Paul Cercueilb4afdd92014-04-08 12:37:21 +0200385
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200386
387/** @brief Retrieve the channel ID (e.g. <b><i>voltage0</i></b>)
388 * @param chn A pointer to an iio_channel structure
389 * @return A pointer to a static NULL-terminated string */
Paul Cercueilb4afdd92014-04-08 12:37:21 +0200390__api __pure const char * iio_channel_get_id(const struct iio_channel *chn);
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200391
392
393/** @brief Retrieve the channel name (e.g. <b><i>vccint</i></b>)
394 * @param chn A pointer to an iio_channel structure
395 * @return A pointer to a static NULL-terminated string
396 *
397 * <b>NOTE:</b> if the channel has no name, NULL is returned. */
Paul Cercueilb4afdd92014-04-08 12:37:21 +0200398__api __pure const char * iio_channel_get_name(const struct iio_channel *chn);
399
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200400
401/** @brief Return True if the given channel is an output channel
402 * @param chn A pointer to an iio_channel structure
403 * @return True if the channel is an output channel, False otherwise */
Paul Cercueilb4afdd92014-04-08 12:37:21 +0200404__api __pure bool iio_channel_is_output(const struct iio_channel *chn);
405
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200406
407/** @brief Enumerate the channel-specific attributes of the given channel
408 * @param chn A pointer to an iio_channel structure
409 * @return The number of channel-specific attributes found */
Paul Cercueilb4afdd92014-04-08 12:37:21 +0200410__api __pure unsigned int iio_channel_get_attrs_count(
411 const struct iio_channel *chn);
412
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200413
414/** @brief Get the channel-specific attribute present at the given index
415 * @param chn A pointer to an iio_channel structure
416 * @param index The index corresponding to the attribute
417 * @return On success, a pointer to a static NULL-terminated string
418 * @return If the index is invalid, NULL is returned */
Paul Cercueilb4afdd92014-04-08 12:37:21 +0200419__api __pure const char * iio_channel_get_attr(
420 const struct iio_channel *chn, unsigned int index);
421
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200422
423/** @brief Try to find a channel-specific attribute by its name
424 * @param chn A pointer to an iio_channel structure
Paul Cercueil30606d52014-04-14 16:04:15 +0200425 * @param name A NULL-terminated string corresponding to the name of the
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200426 * attribute
427 * @return On success, a pointer to a static NULL-terminated string
428 * @return If the name does not correspond to any known attribute of the given
429 * channel, NULL is returned
430 *
431 * <b>NOTE:</b> This function is useful to detect the presence of an attribute.
432 * It can also be used to retrieve the name of an attribute as a pointer to a
433 * static string from a dynamically allocated string. */
Paul Cercueilb4afdd92014-04-08 12:37:21 +0200434__api __pure const char * iio_channel_find_attr(
435 const struct iio_channel *chn, const char *name);
436
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200437
438/** @brief Read the content of the given channel-specific attribute
439 * @param chn A pointer to an iio_channel structure
Paul Cercueil30606d52014-04-14 16:04:15 +0200440 * @param attr A NULL-terminated string corresponding to the name of the
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200441 * attribute
442 * @param dst A pointer to the memory area where the NULL-terminated string
443 * corresponding to the value read will be stored
444 * @param len The available length of the memory area, in bytes
445 * @return On success, the number of bytes written to the buffer
446 * @return On error, a negative errno code is returned */
Paul Cercueilb4afdd92014-04-08 12:37:21 +0200447__api ssize_t iio_channel_attr_read(const struct iio_channel *chn,
448 const char *attr, char *dst, size_t len);
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200449
450
451/** @brief Read the content of the given channel-specific attribute
452 * @param chn A pointer to an iio_channel structure
Paul Cercueil30606d52014-04-14 16:04:15 +0200453 * @param attr A NULL-terminated string corresponding to the name of the
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200454 * attribute
455 * @param val A pointer to a bool variable where the value should be stored
456 * @return On success, 0 is returned
457 * @return On error, a negative errno code is returned */
Paul Cercueilb4afdd92014-04-08 12:37:21 +0200458__api int iio_channel_attr_read_bool(const struct iio_channel *chn,
459 const char *attr, bool *val);
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200460
461
462/** @brief Read the content of the given channel-specific attribute
463 * @param chn A pointer to an iio_channel structure
Paul Cercueil30606d52014-04-14 16:04:15 +0200464 * @param attr A NULL-terminated string corresponding to the name of the
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200465 * attribute
466 * @param val A pointer to a long long variable where the value should be stored
467 * @return On success, 0 is returned
468 * @return On error, a negative errno code is returned */
Paul Cercueilb4afdd92014-04-08 12:37:21 +0200469__api int iio_channel_attr_read_longlong(const struct iio_channel *chn,
470 const char *attr, long long *val);
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200471
472
473/** @brief Read the content of the given channel-specific attribute
474 * @param chn A pointer to an iio_channel structure
Paul Cercueil30606d52014-04-14 16:04:15 +0200475 * @param attr A NULL-terminated string corresponding to the name of the
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200476 * attribute
477 * @param val A pointer to a double variable where the value should be stored
478 * @return On success, 0 is returned
479 * @return On error, a negative errno code is returned */
Paul Cercueilb4afdd92014-04-08 12:37:21 +0200480__api int iio_channel_attr_read_double(const struct iio_channel *chn,
481 const char *attr, double *val);
482
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200483
484/** @brief Set the value of the given channel-specific attribute
485 * @param chn A pointer to an iio_channel structure
Paul Cercueil30606d52014-04-14 16:04:15 +0200486 * @param attr A NULL-terminated string corresponding to the name of the
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200487 * attribute
488 * @param src A NULL-terminated string to set the attribute to
489 * @return On success, the number of bytes written
490 * @return On error, a negative errno code is returned */
Paul Cercueilb4afdd92014-04-08 12:37:21 +0200491__api ssize_t iio_channel_attr_write(const struct iio_channel *chn,
492 const char *attr, const char *src);
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200493
494
495/** @brief Set the value of the given channel-specific attribute
496 * @param chn A pointer to an iio_channel structure
Paul Cercueil30606d52014-04-14 16:04:15 +0200497 * @param attr A NULL-terminated string corresponding to the name of the
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200498 * attribute
499 * @param val A bool value to set the attribute to
500 * @return On success, 0 is returned
501 * @return On error, a negative errno code is returned */
Paul Cercueilb4afdd92014-04-08 12:37:21 +0200502__api int iio_channel_attr_write_bool(const struct iio_channel *chn,
503 const char *attr, bool val);
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200504
505
506/** @brief Set the value of the given channel-specific attribute
507 * @param chn A pointer to an iio_channel structure
Paul Cercueil30606d52014-04-14 16:04:15 +0200508 * @param attr A NULL-terminated string corresponding to the name of the
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200509 * attribute
510 * @param val A long long value to set the attribute to
511 * @return On success, 0 is returned
512 * @return On error, a negative errno code is returned */
Paul Cercueilb4afdd92014-04-08 12:37:21 +0200513__api int iio_channel_attr_write_longlong(const struct iio_channel *chn,
514 const char *attr, long long val);
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200515
516
517/** @brief Set the value of the given channel-specific attribute
518 * @param chn A pointer to an iio_channel structure
Paul Cercueil30606d52014-04-14 16:04:15 +0200519 * @param attr A NULL-terminated string corresponding to the name of the
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200520 * attribute
521 * @param val A double value to set the attribute to
522 * @return On success, 0 is returned
523 * @return On error, a negative errno code is returned */
Paul Cercueilb4afdd92014-04-08 12:37:21 +0200524__api int iio_channel_attr_write_double(const struct iio_channel *chn,
525 const char *attr, double val);
526
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200527
528/** @brief Enable the given channel
529 * @param chn A pointer to an iio_channel structure
530 *
531 * <b>NOTE:</b>Before creating an iio_buffer structure with
532 * iio_device_create_buffer, it is required to enable at least one channel of
533 * the device to read from. */
Paul Cercueilb4afdd92014-04-08 12:37:21 +0200534__api void iio_channel_enable(struct iio_channel *chn);
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200535
536
537/** @brief Disable the given channel
538 * @param chn A pointer to an iio_channel structure */
Paul Cercueilb4afdd92014-04-08 12:37:21 +0200539__api void iio_channel_disable(struct iio_channel *chn);
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200540
541
542/** @brief Returns True if the channel is enabled
543 * @param chn A pointer to an iio_channel structure
544 * @return True if the channel is enabled, False otherwise */
Paul Cercueilb4afdd92014-04-08 12:37:21 +0200545__api bool iio_channel_is_enabled(const struct iio_channel *chn);
546
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200547
548/** Demultiplex the samples of a given channel
549 * @param chn A pointer to an iio_channel structure
550 * @param buffer A pointer to an iio_buffer structure
551 * @param dst A pointer to the memory area where the demultiplexed data will be
552 * stored
553 * @param len The available length of the memory area, in bytes
554 * @return The size of the demultiplexed data, in bytes */
Paul Cercueilb4afdd92014-04-08 12:37:21 +0200555__api size_t iio_channel_read_raw(const struct iio_channel *chn,
556 struct iio_buffer *buffer, void *dst, size_t len);
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200557
558
559/** Demultiplex and convert the samples of a given channel
560 * @param chn A pointer to an iio_channel structure
561 * @param buffer A pointer to an iio_buffer structure
562 * @param dst A pointer to the memory area where the converted data will be
563 * stored
564 * @param len The available length of the memory area, in bytes
565 * @return The size of the converted data, in bytes */
Paul Cercueilb4afdd92014-04-08 12:37:21 +0200566__api size_t iio_channel_read(const struct iio_channel *chn,
567 struct iio_buffer *buffer, void *dst, size_t len);
568
569
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200570/** Multiplex the samples of a given channel
571 * @param chn A pointer to an iio_channel structure
572 * @param buffer A pointer to an iio_buffer structure
573 * @param src A pointer to the memory area where the sequential data will
574 * be read from
575 * @param len The length of the memory area, in bytes
576 * @return The number of bytes actually multiplexed */
Paul Cercueilb4afdd92014-04-08 12:37:21 +0200577__api size_t iio_channel_write_raw(const struct iio_channel *chn,
578 struct iio_buffer *buffer, const void *src, size_t len);
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200579
580
581/** Convert and multiplex the samples of a given channel
582 * @param chn A pointer to an iio_channel structure
583 * @param buffer A pointer to an iio_buffer structure
584 * @param src A pointer to the memory area where the sequential data will
585 * be read from
586 * @param len The length of the memory area, in bytes
587 * @return The number of bytes actually converted and multiplexed */
Paul Cercueilb4afdd92014-04-08 12:37:21 +0200588__api size_t iio_channel_write(const struct iio_channel *chn,
589 struct iio_buffer *buffer, const void *src, size_t len);
590
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200591
592/** @brief Associate a pointer to an iio_channel structure
593 * @param chn A pointer to an iio_channel structure
594 * @param data The pointer to be associated */
Paul Cercueilb4afdd92014-04-08 12:37:21 +0200595__api void iio_channel_set_data(struct iio_channel *chn, void *data);
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200596
597
598/** @brief Retrieve a previously associated pointer of an iio_channel structure
599 * @param chn A pointer to an iio_channel structure
600 * @return The pointer previously associated if present, or NULL */
Paul Cercueilb4afdd92014-04-08 12:37:21 +0200601__api void * iio_channel_get_data(const struct iio_channel *chn);
602
603
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200604/** @} *//* ------------------------------------------------------------------*/
Paul Cercueilb4afdd92014-04-08 12:37:21 +0200605/* ------------------------- Buffer functions --------------------------------*/
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200606/** @defgroup Buffer Buffer
607 * @{
608 * @struct iio_buffer
609 * @brief An input or output buffer, used to read or write samples */
Paul Cercueilb4afdd92014-04-08 12:37:21 +0200610
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200611
612/** @brief Create an input or output buffer associated to the given device
613 * @param dev A pointer to an iio_device structure
614 * @param samples_count The number of samples that the buffer should contain
615 * @param is_output A boolean value which should be True if the buffer is an
616 * output buffer (to write samples to the hardware) or False if the buffer is an
617 * input buffer (to read samples from the hardware)
618 * @return On success, a pointer to an iio_buffer structure
619 * @return On error, NULL is returned
620 *
621 * <b>NOTE:</b> Channels that have to be written to / read from must be enabled
Paul Cercueilb4afdd92014-04-08 12:37:21 +0200622 * before creating the buffer. */
623__api struct iio_buffer * iio_device_create_buffer(const struct iio_device *dev,
624 size_t samples_count, bool is_output);
625
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200626
627/** @brief Destroy the given buffer
628 * @param buf A pointer to an iio_buffer structure
629 *
630 * <b>NOTE:</b> After that function, the iio_buffer pointer shall be invalid. */
Paul Cercueilb4afdd92014-04-08 12:37:21 +0200631__api void iio_buffer_destroy(struct iio_buffer *buf);
632
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200633
634/** @brief Fetch more samples from the hardware
635 * @param buf A pointer to an iio_buffer structure
636 * @return On success, the number of bytes read is returned
637 * @return On error, a negative errno code is returned
638 *
639 * <b>NOTE:</b> Only valid for input buffers */
Paul Cercueilb4afdd92014-04-08 12:37:21 +0200640__api ssize_t iio_buffer_refill(struct iio_buffer *buf);
641
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200642
643/** @brief Send the samples to the hardware
644 * @param buf A pointer to an iio_buffer structure
645 * @return On success, the number of bytes written is returned
646 * @return On error, a negative errno code is returned
647 *
648 * <b>NOTE:</b> Only valid for output buffers */
Paul Cercueilea32b042014-04-11 13:47:12 +0200649__api ssize_t iio_buffer_push(const struct iio_buffer *buf);
Paul Cercueilb4afdd92014-04-08 12:37:21 +0200650
Paul Cercueilb4afdd92014-04-08 12:37:21 +0200651
Paul Cercueil6d927162014-04-16 15:53:22 +0200652/** @brief Get the start address of the buffer
653 * @param buf A pointer to an iio_buffer structure
654 * @return A pointer corresponding to the start address of the buffer */
655__api __pure void * iio_buffer_start(const struct iio_buffer *buf);
656
657
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200658/** @brief Find the first sample of a channel in a buffer
659 * @param buf A pointer to an iio_buffer structure
660 * @param chn A pointer to an iio_channel structure
661 * @return A pointer to the first sample found, or to the end of the buffer if
662 * no sample for the given channel is present in the buffer
663 *
664 * <b>NOTE:</b> This fonction, coupled with iio_buffer_step and iio_buffer_end,
665 * can be used to iterate on all the samples of a given channel present in the
666 * buffer, doing the following:
667 *
668 * @verbatim
669 for (void *ptr = iio_buffer_first(buffer, chn); ptr < iio_buffer_end(buffer); ptr += iio_buffer_step(buffer)) {
670 ....
671 }
672 @endverbatim */
673__api void * iio_buffer_first(const struct iio_buffer *buf,
674 const struct iio_channel *chn);
675
676
677/** @brief Get the step size between two samples of one channel
678 * @param buf A pointer to an iio_buffer structure
679 * @return the difference between the addresses of two consecutive samples of
680 * one same channel */
681__api ptrdiff_t iio_buffer_step(const struct iio_buffer *buf);
682
683
684/** @brief Get the address that follows the last sample in a buffer
685 * @param buf A pointer to an iio_buffer structure
686 * @return A pointer corresponding to the address that follows the last sample
687 * present in the buffer */
688__api void * iio_buffer_end(const struct iio_buffer *buf);
689
690
691/** @brief Call the supplied callback for each sample found in a buffer
692 * @param buf A pointer to an iio_buffer structure
693 * @param callback A pointer to a function to call for each sample found
694 * @param data A user-specified pointer that will be passed to the callback
695 *
696 * <b>NOTE:</b> The callback receives four arguments:
697 * * A pointer to the iio_channel structure corresponding to the sample,
698 * * A pointer to the sample itself,
699 * * The length of the sample in bytes,
700 * * The user-specified pointer passed to iio_buffer_foreach_sample. */
Paul Cercueilb4afdd92014-04-08 12:37:21 +0200701__api ssize_t iio_buffer_foreach_sample(struct iio_buffer *buf,
702 ssize_t (*callback)(const struct iio_channel *chn,
703 void *src, size_t bytes, void *d), void *data);
704
705
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200706/** @} *//* ------------------------------------------------------------------*/
Paul Cercueilb4afdd92014-04-08 12:37:21 +0200707/* ------------------------- Low-level functions -----------------------------*/
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200708/** @defgroup Debug Debug and low-level functions
709 * @{
710 * @struct iio_data_format
711 * @brief Contains the format of a data sample.
712 *
713 * The different fields inform about the correct way to convert one sample from
714 * its raw format (as read from / generated by the hardware) to its real-world
715 * value.
716 */
717struct iio_data_format {
718 /** @brief Total length of the sample, in bits */
719 unsigned int length;
Paul Cercueilb4afdd92014-04-08 12:37:21 +0200720
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200721 /** @brief Length of valuable data in the sample, in bits */
722 unsigned int bits;
723
724 /** @brief Right-shift to apply when converting sample */
725 unsigned int shift;
726
727 /** @brief Contains True if the sample is signed */
728 bool is_signed;
729
730 /** @brief Contains True if the sample is in big-endian format */
731 bool is_be;
732
733 /** @brief Contains True if the sample should be scaled when converted */
734 bool with_scale;
735
736 /** @brief Contains the scale to apply if with_scale is set */
737 double scale;
738};
739
740
741/** @brief Open the given device
742 * @param dev A pointer to an iio_device structure
743 * @param samples_count The size of the kernel buffer, in samples
744 * @return On success, 0 is returned
745 * @return On error, a negative errno code is returned
746 *
747 * <b>NOTE:</b> This is not required when using the iio_buffer functions; it is
748 * only useful when used with iio_device_read_raw / iio_device_write_raw. */
Paul Cercueil59f2aa32014-04-04 16:28:51 +0200749__api int iio_device_open(const struct iio_device *dev, size_t samples_count);
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200750
751
752/** @brief Close the given device
753 * @param dev A pointer to an iio_device structure
754 * @return On success, 0 is returned
755 * @return On error, a negative errno code is returned
756 *
757 * <b>NOTE:</b> This is not required when using the iio_buffer functions; it is
758 * only useful when used with iio_device_read_raw / iio_device_write_raw. */
Paul Cercueil59f2aa32014-04-04 16:28:51 +0200759__api int iio_device_close(const struct iio_device *dev);
Paul Cercueilec1760d2014-02-21 11:31:20 +0100760
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200761
762/** @brief Get the current sample size
763 * @param dev A pointer to an iio_device structure
764 * @return On success, the sample size in bytes
765 * @return On error, a negative errno code is returned
766 *
767 * <b>NOTE:</b> The sample size is not constant and will change when channels
768 * get enabled or disabled. */
Paul Cercueil59f2aa32014-04-04 16:28:51 +0200769__api ssize_t iio_device_get_sample_size(const struct iio_device *dev);
Paul Cercueil1a474732014-03-17 11:38:34 +0100770
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200771
772/** @brief Get the index of the given channel
773 * @param chn A pointer to an iio_channel structure
774 * @return On success, the index of the specified channel
775 * @return On error, a negative errno code is returned */
Paul Cercueil59f2aa32014-04-04 16:28:51 +0200776__api __pure long iio_channel_get_index(const struct iio_channel *chn);
Paul Cercueilb4afdd92014-04-08 12:37:21 +0200777
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200778
779/** @brief Get a pointer to a channel's data format structure
780 * @param chn A pointer to an iio_channel structure
781 * @return A pointer to the channel's iio_data_format structure */
Paul Cercueil59f2aa32014-04-04 16:28:51 +0200782__api __cnst const struct iio_data_format * iio_channel_get_data_format(
783 const struct iio_channel *chn);
Paul Cercueil0b2ce712014-02-17 15:04:18 +0100784
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200785
786/** @brief Convert the sample from hardware format to host format
787 * @param chn A pointer to an iio_channel structure
788 * @param dst A pointer to the destination buffer where the converted sample
789 * should be written
790 * @param src A pointer to the source buffer containing the sample */
Paul Cercueil59f2aa32014-04-04 16:28:51 +0200791__api void iio_channel_convert(const struct iio_channel *chn,
Paul Cercueil2917ffb2014-03-21 15:47:12 +0100792 void *dst, const void *src);
793
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200794
795/** @brief Convert the sample from host format to hardware format
796 * @param chn A pointer to an iio_channel structure
797 * @param dst A pointer to the destination buffer where the converted sample
798 * should be written
799 * @param src A pointer to the source buffer containing the sample */
Paul Cercueild840d4c2014-04-07 19:38:58 +0200800__api void iio_channel_convert_inverse(const struct iio_channel *chn,
801 void *dst, const void *src);
802
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200803
804/** @brief Read the raw stream from the given device
805 * @param dev A pointer to an iio_device structure
806 * @param dst A pointer to the destination buffer where to write the stream
807 * @param len The length of the destination buffer, in bytes
808 * @param mask A pointer to a memory area where the channel mask will be stored
809 * @param words The number of 32-bit words composing the mask
810 * @return On success, the number of bytes read
811 * @return On error, a negative errno code is returned
812 *
813 * <b>NOTE:</b> The device must be opened first (with iio_device_open).
814 *
815 * The "words" param should correspond to (number of channels + 31) / 32.
816 * The area pointed by "mask" will be initialized like this:
817 * @verbatim
818 mask[chn.index / 32][chn.index % 32] = is_enabled
819 @endverbatim
820 * Note that the mask can change anytime between two calls, even if no channel
821 * of the specified device have been enabled or disabled in the meantime. */
Paul Cercueil59f2aa32014-04-04 16:28:51 +0200822__api ssize_t iio_device_read_raw(const struct iio_device *dev,
Paul Cercueil45c575d2014-03-20 15:14:01 +0100823 void *dst, size_t len, uint32_t *mask, size_t words);
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200824
825
826/** @brief Write a raw stream to the given device
827 * @param dev A pointer to an iio_device structure
828 * @param src A pointer to the source buffer where to read the stream from
829 * @param len The length of the input buffer, in bytes
830 * @return On success, the number of bytes written
831 * @return On error, a negative errno code is returned
832 *
833 * <b>NOTE:</b> The device must be opened first (with iio_device_open). */
Paul Cercueil59f2aa32014-04-04 16:28:51 +0200834__api ssize_t iio_device_write_raw(const struct iio_device *dev,
Paul Cercueil0b2ce712014-02-17 15:04:18 +0100835 const void *src, size_t len);
836
Paul Cercueil99b07cc2014-04-14 16:07:32 +0200837
Paul Cercueil1ce35ef2014-04-15 12:28:40 +0200838/** @brief Enumerate the debug attributes of the given device
839 * @param dev A pointer to an iio_device structure
840 * @return The number of debug attributes found */
841__api __pure unsigned int iio_device_get_debug_attrs_count(
842 const struct iio_device *dev);
843
844
845/** @brief Get the debug attribute present at the given index
846 * @param dev A pointer to an iio_device structure
847 * @param index The index corresponding to the debug attribute
848 * @return On success, a pointer to a static NULL-terminated string
849 * @return If the index is invalid, NULL is returned */
850__api __pure const char * iio_device_get_debug_attr(
851 const struct iio_device *dev, unsigned int index);
852
853
Paul Cercueil99b07cc2014-04-14 16:07:32 +0200854/** @brief Read the content of the given debug attribute
855 * @param dev A pointer to an iio_device structure
856 * @param attr A NULL-terminated string corresponding to the name of the
857 * debug attribute
858 * @param dst A pointer to the memory area where the NULL-terminated string
859 * corresponding to the value read will be stored
860 * @param len The available length of the memory area, in bytes
861 * @return On success, the number of bytes written to the buffer
862 * @return On error, a negative errno code is returned */
863__api ssize_t iio_device_debug_attr_read(const struct iio_device *dev,
864 const char *attr, char *dst, size_t len);
865
866
867/** @brief Set the value of the given debug attribute
868 * @param dev A pointer to an iio_device structure
869 * @param attr A NULL-terminated string corresponding to the name of the
870 * debug attribute
871 * @param src A NULL-terminated string to set the debug attribute to
872 * @return On success, the number of bytes written
873 * @return On error, a negative errno code is returned */
874__api ssize_t iio_device_debug_attr_write(const struct iio_device *dev,
875 const char *attr, const char *src);
876
Paul Cercueile3960742014-04-15 16:00:50 +0200877
878/** @brief Read the content of the given debug attribute
879 * @param dev A pointer to an iio_device structure
880 * @param attr A NULL-terminated string corresponding to the name of the
881 * debug attribute
882 * @param val A pointer to a bool variable where the value should be stored
883 * @return On success, 0 is returned
884 * @return On error, a negative errno code is returned */
885__api int iio_device_debug_attr_read_bool(const struct iio_device *dev,
886 const char *attr, bool *val);
887
888
889/** @brief Read the content of the given debug attribute
890 * @param dev A pointer to an iio_device structure
891 * @param attr A NULL-terminated string corresponding to the name of the
892 * debug attribute
893 * @param val A pointer to a long long variable where the value should be stored
894 * @return On success, 0 is returned
895 * @return On error, a negative errno code is returned */
896__api int iio_device_debug_attr_read_longlong(const struct iio_device *dev,
897 const char *attr, long long *val);
898
899
900/** @brief Read the content of the given debug attribute
901 * @param dev A pointer to an iio_device structure
902 * @param attr A NULL-terminated string corresponding to the name of the
903 * debug attribute
904 * @param val A pointer to a double variable where the value should be stored
905 * @return On success, 0 is returned
906 * @return On error, a negative errno code is returned */
907__api int iio_device_debug_attr_read_double(const struct iio_device *dev,
908 const char *attr, double *val);
909
910
911/** @brief Set the value of the given debug attribute
912 * @param dev A pointer to an iio_device structure
913 * @param attr A NULL-terminated string corresponding to the name of the
914 * debug attribute
915 * @param val A bool value to set the debug attribute to
916 * @return On success, 0 is returned
917 * @return On error, a negative errno code is returned */
918__api int iio_device_debug_attr_write_bool(const struct iio_device *dev,
919 const char *attr, bool val);
920
921
922/** @brief Set the value of the given debug attribute
923 * @param dev A pointer to an iio_device structure
924 * @param attr A NULL-terminated string corresponding to the name of the
925 * debug attribute
926 * @param val A long long value to set the debug attribute to
927 * @return On success, 0 is returned
928 * @return On error, a negative errno code is returned */
929__api int iio_device_debug_attr_write_longlong(const struct iio_device *dev,
930 const char *attr, long long val);
931
932
933/** @brief Set the value of the given debug attribute
934 * @param dev A pointer to an iio_device structure
935 * @param attr A NULL-terminated string corresponding to the name of the
936 * debug attribute
937 * @param val A double value to set the debug attribute to
938 * @return On success, 0 is returned
939 * @return On error, a negative errno code is returned */
940__api int iio_device_debug_attr_write_double(const struct iio_device *dev,
941 const char *attr, double val);
942
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200943/** @} */
944
Paul Cercueila167e0c2014-04-08 14:50:41 +0200945#ifdef __cplusplus
946}
947#endif
948
Paul Cercueil0b2ce712014-02-17 15:04:18 +0100949#endif /* __IIO_H__ */