blob: 614b277c50bcdaa7de1822871d299597e850f6d4 [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
Paul Cercueil85aaf482014-04-24 16:39:09 +0200407/** @brief Return True if the given channel is a scan element
408 * @param chn A pointer to an iio_channel structure
409 * @return True if the channel is a scan element, False otherwise
410 *
411 * <b>NOTE:</b> a channel that is a scan element is a channel that can
412 * generate samples (for an input channel) or receive samples (for an output
413 * channel) after being enabled. */
414__api __pure bool iio_channel_is_scan_element(const struct iio_channel *chn);
415
416
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200417/** @brief Enumerate the channel-specific attributes of the given channel
418 * @param chn A pointer to an iio_channel structure
419 * @return The number of channel-specific attributes found */
Paul Cercueilb4afdd92014-04-08 12:37:21 +0200420__api __pure unsigned int iio_channel_get_attrs_count(
421 const struct iio_channel *chn);
422
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200423
424/** @brief Get the channel-specific attribute present at the given index
425 * @param chn A pointer to an iio_channel structure
426 * @param index The index corresponding to the attribute
427 * @return On success, a pointer to a static NULL-terminated string
428 * @return If the index is invalid, NULL is returned */
Paul Cercueilb4afdd92014-04-08 12:37:21 +0200429__api __pure const char * iio_channel_get_attr(
430 const struct iio_channel *chn, unsigned int index);
431
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200432
433/** @brief Try to find a channel-specific attribute by its name
434 * @param chn A pointer to an iio_channel structure
Paul Cercueil30606d52014-04-14 16:04:15 +0200435 * @param name A NULL-terminated string corresponding to the name of the
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200436 * attribute
437 * @return On success, a pointer to a static NULL-terminated string
438 * @return If the name does not correspond to any known attribute of the given
439 * channel, NULL is returned
440 *
441 * <b>NOTE:</b> This function is useful to detect the presence of an attribute.
442 * It can also be used to retrieve the name of an attribute as a pointer to a
443 * static string from a dynamically allocated string. */
Paul Cercueilb4afdd92014-04-08 12:37:21 +0200444__api __pure const char * iio_channel_find_attr(
445 const struct iio_channel *chn, const char *name);
446
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200447
448/** @brief Read the content of the given channel-specific attribute
449 * @param chn A pointer to an iio_channel structure
Paul Cercueil30606d52014-04-14 16:04:15 +0200450 * @param attr A NULL-terminated string corresponding to the name of the
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200451 * attribute
452 * @param dst A pointer to the memory area where the NULL-terminated string
453 * corresponding to the value read will be stored
454 * @param len The available length of the memory area, in bytes
455 * @return On success, the number of bytes written to the buffer
456 * @return On error, a negative errno code is returned */
Paul Cercueilb4afdd92014-04-08 12:37:21 +0200457__api ssize_t iio_channel_attr_read(const struct iio_channel *chn,
458 const char *attr, char *dst, size_t len);
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200459
460
461/** @brief Read the content of the given channel-specific attribute
462 * @param chn A pointer to an iio_channel structure
Paul Cercueil30606d52014-04-14 16:04:15 +0200463 * @param attr A NULL-terminated string corresponding to the name of the
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200464 * attribute
465 * @param val A pointer to a bool variable where the value should be stored
466 * @return On success, 0 is returned
467 * @return On error, a negative errno code is returned */
Paul Cercueilb4afdd92014-04-08 12:37:21 +0200468__api int iio_channel_attr_read_bool(const struct iio_channel *chn,
469 const char *attr, bool *val);
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200470
471
472/** @brief Read the content of the given channel-specific attribute
473 * @param chn A pointer to an iio_channel structure
Paul Cercueil30606d52014-04-14 16:04:15 +0200474 * @param attr A NULL-terminated string corresponding to the name of the
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200475 * attribute
476 * @param val A pointer to a long long variable where the value should be stored
477 * @return On success, 0 is returned
478 * @return On error, a negative errno code is returned */
Paul Cercueilb4afdd92014-04-08 12:37:21 +0200479__api int iio_channel_attr_read_longlong(const struct iio_channel *chn,
480 const char *attr, long long *val);
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200481
482
483/** @brief Read the content of the given channel-specific attribute
484 * @param chn A pointer to an iio_channel structure
Paul Cercueil30606d52014-04-14 16:04:15 +0200485 * @param attr A NULL-terminated string corresponding to the name of the
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200486 * attribute
487 * @param val A pointer to a double variable where the value should be stored
488 * @return On success, 0 is returned
489 * @return On error, a negative errno code is returned */
Paul Cercueilb4afdd92014-04-08 12:37:21 +0200490__api int iio_channel_attr_read_double(const struct iio_channel *chn,
491 const char *attr, double *val);
492
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200493
494/** @brief Set the value of the given channel-specific attribute
495 * @param chn A pointer to an iio_channel structure
Paul Cercueil30606d52014-04-14 16:04:15 +0200496 * @param attr A NULL-terminated string corresponding to the name of the
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200497 * attribute
498 * @param src A NULL-terminated string to set the attribute to
499 * @return On success, the number of bytes written
500 * @return On error, a negative errno code is returned */
Paul Cercueilb4afdd92014-04-08 12:37:21 +0200501__api ssize_t iio_channel_attr_write(const struct iio_channel *chn,
502 const char *attr, const char *src);
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200503
504
505/** @brief Set the value of the given channel-specific attribute
506 * @param chn A pointer to an iio_channel structure
Paul Cercueil30606d52014-04-14 16:04:15 +0200507 * @param attr A NULL-terminated string corresponding to the name of the
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200508 * attribute
509 * @param val A bool value to set the attribute to
510 * @return On success, 0 is returned
511 * @return On error, a negative errno code is returned */
Paul Cercueilb4afdd92014-04-08 12:37:21 +0200512__api int iio_channel_attr_write_bool(const struct iio_channel *chn,
513 const char *attr, bool val);
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200514
515
516/** @brief Set the value of the given channel-specific attribute
517 * @param chn A pointer to an iio_channel structure
Paul Cercueil30606d52014-04-14 16:04:15 +0200518 * @param attr A NULL-terminated string corresponding to the name of the
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200519 * attribute
520 * @param val A long long value to set the attribute to
521 * @return On success, 0 is returned
522 * @return On error, a negative errno code is returned */
Paul Cercueilb4afdd92014-04-08 12:37:21 +0200523__api int iio_channel_attr_write_longlong(const struct iio_channel *chn,
524 const char *attr, long long val);
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200525
526
527/** @brief Set the value of the given channel-specific attribute
528 * @param chn A pointer to an iio_channel structure
Paul Cercueil30606d52014-04-14 16:04:15 +0200529 * @param attr A NULL-terminated string corresponding to the name of the
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200530 * attribute
531 * @param val A double value to set the attribute to
532 * @return On success, 0 is returned
533 * @return On error, a negative errno code is returned */
Paul Cercueilb4afdd92014-04-08 12:37:21 +0200534__api int iio_channel_attr_write_double(const struct iio_channel *chn,
535 const char *attr, double val);
536
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200537
538/** @brief Enable the given channel
539 * @param chn A pointer to an iio_channel structure
540 *
541 * <b>NOTE:</b>Before creating an iio_buffer structure with
542 * iio_device_create_buffer, it is required to enable at least one channel of
543 * the device to read from. */
Paul Cercueilb4afdd92014-04-08 12:37:21 +0200544__api void iio_channel_enable(struct iio_channel *chn);
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200545
546
547/** @brief Disable the given channel
548 * @param chn A pointer to an iio_channel structure */
Paul Cercueilb4afdd92014-04-08 12:37:21 +0200549__api void iio_channel_disable(struct iio_channel *chn);
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200550
551
552/** @brief Returns True if the channel is enabled
553 * @param chn A pointer to an iio_channel structure
554 * @return True if the channel is enabled, False otherwise */
Paul Cercueilb4afdd92014-04-08 12:37:21 +0200555__api bool iio_channel_is_enabled(const struct iio_channel *chn);
556
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200557
558/** Demultiplex the samples of a given channel
559 * @param chn A pointer to an iio_channel structure
560 * @param buffer A pointer to an iio_buffer structure
561 * @param dst A pointer to the memory area where the demultiplexed data will be
562 * stored
563 * @param len The available length of the memory area, in bytes
564 * @return The size of the demultiplexed data, in bytes */
Paul Cercueilb4afdd92014-04-08 12:37:21 +0200565__api size_t iio_channel_read_raw(const struct iio_channel *chn,
566 struct iio_buffer *buffer, void *dst, size_t len);
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200567
568
569/** Demultiplex and convert the samples of a given channel
570 * @param chn A pointer to an iio_channel structure
571 * @param buffer A pointer to an iio_buffer structure
572 * @param dst A pointer to the memory area where the converted data will be
573 * stored
574 * @param len The available length of the memory area, in bytes
575 * @return The size of the converted data, in bytes */
Paul Cercueilb4afdd92014-04-08 12:37:21 +0200576__api size_t iio_channel_read(const struct iio_channel *chn,
577 struct iio_buffer *buffer, void *dst, size_t len);
578
579
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200580/** Multiplex the samples of a given channel
581 * @param chn A pointer to an iio_channel structure
582 * @param buffer A pointer to an iio_buffer structure
583 * @param src A pointer to the memory area where the sequential data will
584 * be read from
585 * @param len The length of the memory area, in bytes
586 * @return The number of bytes actually multiplexed */
Paul Cercueilb4afdd92014-04-08 12:37:21 +0200587__api size_t iio_channel_write_raw(const struct iio_channel *chn,
588 struct iio_buffer *buffer, const void *src, size_t len);
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200589
590
591/** Convert and multiplex the samples of a given channel
592 * @param chn A pointer to an iio_channel structure
593 * @param buffer A pointer to an iio_buffer structure
594 * @param src A pointer to the memory area where the sequential data will
595 * be read from
596 * @param len The length of the memory area, in bytes
597 * @return The number of bytes actually converted and multiplexed */
Paul Cercueilb4afdd92014-04-08 12:37:21 +0200598__api size_t iio_channel_write(const struct iio_channel *chn,
599 struct iio_buffer *buffer, const void *src, size_t len);
600
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200601
602/** @brief Associate a pointer to an iio_channel structure
603 * @param chn A pointer to an iio_channel structure
604 * @param data The pointer to be associated */
Paul Cercueilb4afdd92014-04-08 12:37:21 +0200605__api void iio_channel_set_data(struct iio_channel *chn, void *data);
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200606
607
608/** @brief Retrieve a previously associated pointer of an iio_channel structure
609 * @param chn A pointer to an iio_channel structure
610 * @return The pointer previously associated if present, or NULL */
Paul Cercueilb4afdd92014-04-08 12:37:21 +0200611__api void * iio_channel_get_data(const struct iio_channel *chn);
612
613
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200614/** @} *//* ------------------------------------------------------------------*/
Paul Cercueilb4afdd92014-04-08 12:37:21 +0200615/* ------------------------- Buffer functions --------------------------------*/
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200616/** @defgroup Buffer Buffer
617 * @{
618 * @struct iio_buffer
619 * @brief An input or output buffer, used to read or write samples */
Paul Cercueilb4afdd92014-04-08 12:37:21 +0200620
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200621
622/** @brief Create an input or output buffer associated to the given device
623 * @param dev A pointer to an iio_device structure
624 * @param samples_count The number of samples that the buffer should contain
625 * @param is_output A boolean value which should be True if the buffer is an
626 * output buffer (to write samples to the hardware) or False if the buffer is an
627 * input buffer (to read samples from the hardware)
628 * @return On success, a pointer to an iio_buffer structure
629 * @return On error, NULL is returned
630 *
631 * <b>NOTE:</b> Channels that have to be written to / read from must be enabled
Paul Cercueilb4afdd92014-04-08 12:37:21 +0200632 * before creating the buffer. */
633__api struct iio_buffer * iio_device_create_buffer(const struct iio_device *dev,
634 size_t samples_count, bool is_output);
635
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200636
637/** @brief Destroy the given buffer
638 * @param buf A pointer to an iio_buffer structure
639 *
640 * <b>NOTE:</b> After that function, the iio_buffer pointer shall be invalid. */
Paul Cercueilb4afdd92014-04-08 12:37:21 +0200641__api void iio_buffer_destroy(struct iio_buffer *buf);
642
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200643
644/** @brief Fetch more samples from the hardware
645 * @param buf A pointer to an iio_buffer structure
646 * @return On success, the number of bytes read is returned
647 * @return On error, a negative errno code is returned
648 *
649 * <b>NOTE:</b> Only valid for input buffers */
Paul Cercueilb4afdd92014-04-08 12:37:21 +0200650__api ssize_t iio_buffer_refill(struct iio_buffer *buf);
651
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200652
653/** @brief Send the samples to the hardware
654 * @param buf A pointer to an iio_buffer structure
655 * @return On success, the number of bytes written is returned
656 * @return On error, a negative errno code is returned
657 *
658 * <b>NOTE:</b> Only valid for output buffers */
Paul Cercueilea32b042014-04-11 13:47:12 +0200659__api ssize_t iio_buffer_push(const struct iio_buffer *buf);
Paul Cercueilb4afdd92014-04-08 12:37:21 +0200660
Paul Cercueilb4afdd92014-04-08 12:37:21 +0200661
Paul Cercueil6d927162014-04-16 15:53:22 +0200662/** @brief Get the start address of the buffer
663 * @param buf A pointer to an iio_buffer structure
664 * @return A pointer corresponding to the start address of the buffer */
665__api __pure void * iio_buffer_start(const struct iio_buffer *buf);
666
667
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200668/** @brief Find the first sample of a channel in a buffer
669 * @param buf A pointer to an iio_buffer structure
670 * @param chn A pointer to an iio_channel structure
671 * @return A pointer to the first sample found, or to the end of the buffer if
672 * no sample for the given channel is present in the buffer
673 *
674 * <b>NOTE:</b> This fonction, coupled with iio_buffer_step and iio_buffer_end,
675 * can be used to iterate on all the samples of a given channel present in the
676 * buffer, doing the following:
677 *
678 * @verbatim
679 for (void *ptr = iio_buffer_first(buffer, chn); ptr < iio_buffer_end(buffer); ptr += iio_buffer_step(buffer)) {
680 ....
681 }
682 @endverbatim */
683__api void * iio_buffer_first(const struct iio_buffer *buf,
684 const struct iio_channel *chn);
685
686
687/** @brief Get the step size between two samples of one channel
688 * @param buf A pointer to an iio_buffer structure
689 * @return the difference between the addresses of two consecutive samples of
690 * one same channel */
691__api ptrdiff_t iio_buffer_step(const struct iio_buffer *buf);
692
693
694/** @brief Get the address that follows the last sample in a buffer
695 * @param buf A pointer to an iio_buffer structure
696 * @return A pointer corresponding to the address that follows the last sample
697 * present in the buffer */
698__api void * iio_buffer_end(const struct iio_buffer *buf);
699
700
701/** @brief Call the supplied callback for each sample found in a buffer
702 * @param buf A pointer to an iio_buffer structure
703 * @param callback A pointer to a function to call for each sample found
704 * @param data A user-specified pointer that will be passed to the callback
705 *
706 * <b>NOTE:</b> The callback receives four arguments:
707 * * A pointer to the iio_channel structure corresponding to the sample,
708 * * A pointer to the sample itself,
709 * * The length of the sample in bytes,
710 * * The user-specified pointer passed to iio_buffer_foreach_sample. */
Paul Cercueilb4afdd92014-04-08 12:37:21 +0200711__api ssize_t iio_buffer_foreach_sample(struct iio_buffer *buf,
712 ssize_t (*callback)(const struct iio_channel *chn,
713 void *src, size_t bytes, void *d), void *data);
714
715
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200716/** @} *//* ------------------------------------------------------------------*/
Paul Cercueilb4afdd92014-04-08 12:37:21 +0200717/* ------------------------- Low-level functions -----------------------------*/
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200718/** @defgroup Debug Debug and low-level functions
719 * @{
720 * @struct iio_data_format
721 * @brief Contains the format of a data sample.
722 *
723 * The different fields inform about the correct way to convert one sample from
724 * its raw format (as read from / generated by the hardware) to its real-world
725 * value.
726 */
727struct iio_data_format {
728 /** @brief Total length of the sample, in bits */
729 unsigned int length;
Paul Cercueilb4afdd92014-04-08 12:37:21 +0200730
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200731 /** @brief Length of valuable data in the sample, in bits */
732 unsigned int bits;
733
734 /** @brief Right-shift to apply when converting sample */
735 unsigned int shift;
736
737 /** @brief Contains True if the sample is signed */
738 bool is_signed;
739
740 /** @brief Contains True if the sample is in big-endian format */
741 bool is_be;
742
743 /** @brief Contains True if the sample should be scaled when converted */
744 bool with_scale;
745
746 /** @brief Contains the scale to apply if with_scale is set */
747 double scale;
748};
749
750
751/** @brief Open the given device
752 * @param dev A pointer to an iio_device structure
753 * @param samples_count The size of the kernel buffer, in samples
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_open(const struct iio_device *dev, size_t samples_count);
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200760
761
762/** @brief Close the given device
763 * @param dev A pointer to an iio_device structure
764 * @return On success, 0 is returned
765 * @return On error, a negative errno code is returned
766 *
767 * <b>NOTE:</b> This is not required when using the iio_buffer functions; it is
768 * only useful when used with iio_device_read_raw / iio_device_write_raw. */
Paul Cercueil59f2aa32014-04-04 16:28:51 +0200769__api int iio_device_close(const struct iio_device *dev);
Paul Cercueilec1760d2014-02-21 11:31:20 +0100770
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200771
772/** @brief Get the current sample size
773 * @param dev A pointer to an iio_device structure
774 * @return On success, the sample size in bytes
775 * @return On error, a negative errno code is returned
776 *
777 * <b>NOTE:</b> The sample size is not constant and will change when channels
778 * get enabled or disabled. */
Paul Cercueil59f2aa32014-04-04 16:28:51 +0200779__api ssize_t iio_device_get_sample_size(const struct iio_device *dev);
Paul Cercueil1a474732014-03-17 11:38:34 +0100780
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200781
782/** @brief Get the index of the given channel
783 * @param chn A pointer to an iio_channel structure
784 * @return On success, the index of the specified channel
785 * @return On error, a negative errno code is returned */
Paul Cercueil59f2aa32014-04-04 16:28:51 +0200786__api __pure long iio_channel_get_index(const struct iio_channel *chn);
Paul Cercueilb4afdd92014-04-08 12:37:21 +0200787
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200788
789/** @brief Get a pointer to a channel's data format structure
790 * @param chn A pointer to an iio_channel structure
791 * @return A pointer to the channel's iio_data_format structure */
Paul Cercueil59f2aa32014-04-04 16:28:51 +0200792__api __cnst const struct iio_data_format * iio_channel_get_data_format(
793 const struct iio_channel *chn);
Paul Cercueil0b2ce712014-02-17 15:04:18 +0100794
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200795
796/** @brief Convert the sample from hardware format to host format
797 * @param chn A pointer to an iio_channel structure
798 * @param dst A pointer to the destination buffer where the converted sample
799 * should be written
800 * @param src A pointer to the source buffer containing the sample */
Paul Cercueil59f2aa32014-04-04 16:28:51 +0200801__api void iio_channel_convert(const struct iio_channel *chn,
Paul Cercueil2917ffb2014-03-21 15:47:12 +0100802 void *dst, const void *src);
803
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200804
805/** @brief Convert the sample from host format to hardware format
806 * @param chn A pointer to an iio_channel structure
807 * @param dst A pointer to the destination buffer where the converted sample
808 * should be written
809 * @param src A pointer to the source buffer containing the sample */
Paul Cercueild840d4c2014-04-07 19:38:58 +0200810__api void iio_channel_convert_inverse(const struct iio_channel *chn,
811 void *dst, const void *src);
812
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200813
814/** @brief Read the raw stream from the given device
815 * @param dev A pointer to an iio_device structure
816 * @param dst A pointer to the destination buffer where to write the stream
817 * @param len The length of the destination buffer, in bytes
818 * @param mask A pointer to a memory area where the channel mask will be stored
819 * @param words The number of 32-bit words composing the mask
820 * @return On success, the number of bytes read
821 * @return On error, a negative errno code is returned
822 *
823 * <b>NOTE:</b> The device must be opened first (with iio_device_open).
824 *
825 * The "words" param should correspond to (number of channels + 31) / 32.
826 * The area pointed by "mask" will be initialized like this:
827 * @verbatim
828 mask[chn.index / 32][chn.index % 32] = is_enabled
829 @endverbatim
830 * Note that the mask can change anytime between two calls, even if no channel
831 * of the specified device have been enabled or disabled in the meantime. */
Paul Cercueil59f2aa32014-04-04 16:28:51 +0200832__api ssize_t iio_device_read_raw(const struct iio_device *dev,
Paul Cercueil45c575d2014-03-20 15:14:01 +0100833 void *dst, size_t len, uint32_t *mask, size_t words);
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200834
835
836/** @brief Write a raw stream to the given device
837 * @param dev A pointer to an iio_device structure
838 * @param src A pointer to the source buffer where to read the stream from
839 * @param len The length of the input buffer, in bytes
840 * @return On success, the number of bytes written
841 * @return On error, a negative errno code is returned
842 *
843 * <b>NOTE:</b> The device must be opened first (with iio_device_open). */
Paul Cercueil59f2aa32014-04-04 16:28:51 +0200844__api ssize_t iio_device_write_raw(const struct iio_device *dev,
Paul Cercueil0b2ce712014-02-17 15:04:18 +0100845 const void *src, size_t len);
846
Paul Cercueil99b07cc2014-04-14 16:07:32 +0200847
Paul Cercueil1ce35ef2014-04-15 12:28:40 +0200848/** @brief Enumerate the debug attributes of the given device
849 * @param dev A pointer to an iio_device structure
850 * @return The number of debug attributes found */
851__api __pure unsigned int iio_device_get_debug_attrs_count(
852 const struct iio_device *dev);
853
854
855/** @brief Get the debug attribute present at the given index
856 * @param dev A pointer to an iio_device structure
857 * @param index The index corresponding to the debug attribute
858 * @return On success, a pointer to a static NULL-terminated string
859 * @return If the index is invalid, NULL is returned */
860__api __pure const char * iio_device_get_debug_attr(
861 const struct iio_device *dev, unsigned int index);
862
863
Paul Cercueil99b07cc2014-04-14 16:07:32 +0200864/** @brief Read the content of the given debug attribute
865 * @param dev A pointer to an iio_device structure
866 * @param attr A NULL-terminated string corresponding to the name of the
867 * debug attribute
868 * @param dst A pointer to the memory area where the NULL-terminated string
869 * corresponding to the value read will be stored
870 * @param len The available length of the memory area, in bytes
871 * @return On success, the number of bytes written to the buffer
872 * @return On error, a negative errno code is returned */
873__api ssize_t iio_device_debug_attr_read(const struct iio_device *dev,
874 const char *attr, char *dst, size_t len);
875
876
877/** @brief Set the value of the given debug attribute
878 * @param dev A pointer to an iio_device structure
879 * @param attr A NULL-terminated string corresponding to the name of the
880 * debug attribute
881 * @param src A NULL-terminated string to set the debug attribute to
882 * @return On success, the number of bytes written
883 * @return On error, a negative errno code is returned */
884__api ssize_t iio_device_debug_attr_write(const struct iio_device *dev,
885 const char *attr, const char *src);
886
Paul Cercueile3960742014-04-15 16:00:50 +0200887
888/** @brief Read the content of the given debug attribute
889 * @param dev A pointer to an iio_device structure
890 * @param attr A NULL-terminated string corresponding to the name of the
891 * debug attribute
892 * @param val A pointer to a bool variable where the value should be stored
893 * @return On success, 0 is returned
894 * @return On error, a negative errno code is returned */
895__api int iio_device_debug_attr_read_bool(const struct iio_device *dev,
896 const char *attr, bool *val);
897
898
899/** @brief Read the content of the given debug attribute
900 * @param dev A pointer to an iio_device structure
901 * @param attr A NULL-terminated string corresponding to the name of the
902 * debug attribute
903 * @param val A pointer to a long long variable where the value should be stored
904 * @return On success, 0 is returned
905 * @return On error, a negative errno code is returned */
906__api int iio_device_debug_attr_read_longlong(const struct iio_device *dev,
907 const char *attr, long long *val);
908
909
910/** @brief Read the content of the given debug attribute
911 * @param dev A pointer to an iio_device structure
912 * @param attr A NULL-terminated string corresponding to the name of the
913 * debug attribute
914 * @param val A pointer to a double variable where the value should be stored
915 * @return On success, 0 is returned
916 * @return On error, a negative errno code is returned */
917__api int iio_device_debug_attr_read_double(const struct iio_device *dev,
918 const char *attr, double *val);
919
920
921/** @brief Set the value of the given debug attribute
922 * @param dev A pointer to an iio_device structure
923 * @param attr A NULL-terminated string corresponding to the name of the
924 * debug attribute
925 * @param val A bool value to set the debug attribute to
926 * @return On success, 0 is returned
927 * @return On error, a negative errno code is returned */
928__api int iio_device_debug_attr_write_bool(const struct iio_device *dev,
929 const char *attr, bool val);
930
931
932/** @brief Set the value of the given debug attribute
933 * @param dev A pointer to an iio_device structure
934 * @param attr A NULL-terminated string corresponding to the name of the
935 * debug attribute
936 * @param val A long long value to set the debug attribute to
937 * @return On success, 0 is returned
938 * @return On error, a negative errno code is returned */
939__api int iio_device_debug_attr_write_longlong(const struct iio_device *dev,
940 const char *attr, long long val);
941
942
943/** @brief Set the value of the given debug attribute
944 * @param dev A pointer to an iio_device structure
945 * @param attr A NULL-terminated string corresponding to the name of the
946 * debug attribute
947 * @param val A double value to set the debug attribute to
948 * @return On success, 0 is returned
949 * @return On error, a negative errno code is returned */
950__api int iio_device_debug_attr_write_double(const struct iio_device *dev,
951 const char *attr, double val);
952
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200953/** @} */
954
Paul Cercueila167e0c2014-04-08 14:50:41 +0200955#ifdef __cplusplus
956}
957#endif
958
Paul Cercueil0b2ce712014-02-17 15:04:18 +0100959#endif /* __IIO_H__ */