blob: 30fdb84ea3685767aa9add4077f67c2d74744925 [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 Cercueilbc2645b2015-12-11 11:29:21 +010038#define _SSIZE_T_DEFINED
Paul Cercueilb669f692014-04-04 13:42:24 +020039#endif
40
Paul Cercueil59f2aa32014-04-04 16:28:51 +020041#ifdef __GNUC__
42#define __cnst __attribute__((const))
43#define __pure __attribute__((pure))
Paul Cercueil83f21892014-05-19 13:00:39 +020044#define __notused __attribute__((unused))
Paul Cercueil59f2aa32014-04-04 16:28:51 +020045#else
46#define __cnst
47#define __pure
Paul Cercueil83f21892014-05-19 13:00:39 +020048#define __notused
Paul Cercueil59f2aa32014-04-04 16:28:51 +020049#endif
50
51#ifdef _WIN32
52# ifdef LIBIIO_EXPORTS
Paul Cercueil59f2aa32014-04-04 16:28:51 +020053# define __api __declspec(dllexport)
Paul Cercueil7288c332014-04-07 16:25:11 +020054# else
55# define __api __declspec(dllimport)
Paul Cercueil59f2aa32014-04-04 16:28:51 +020056# endif
57#elif __GNUC__ >= 4
58# define __api __attribute__((visibility ("default")))
59#else
60# define __api
61#endif
62
Paul Cercueil0b2ce712014-02-17 15:04:18 +010063struct iio_context;
64struct iio_device;
65struct iio_channel;
Paul Cercueila689cd92014-03-20 16:37:25 +010066struct iio_buffer;
Paul Cercueil0b2ce712014-02-17 15:04:18 +010067
Paul Cercueilb4afdd92014-04-08 12:37:21 +020068
Paul Cercueil306cb1c2014-04-11 14:46:45 +020069/* ---------------------------------------------------------------------------*/
Paul Cercueil53ed9432014-11-20 13:46:04 +010070/* ------------------------- Top-level functions -----------------------------*/
71/** @defgroup TopLevel Top-level functions
72 * @{ */
73
74
75/** @brief Get the version of the libiio library
76 * @param major A pointer to an unsigned integer (NULL accepted)
77 * @param minor A pointer to an unsigned integer (NULL accepted)
78 * @param git_tag A pointer to a 8-characters buffer (NULL accepted) */
79__api void iio_library_get_version(unsigned int *major,
80 unsigned int *minor, char git_tag[8]);
81
82
Paul Cercueil3fa34382015-05-22 10:54:28 +020083/** @brief Get a string description of an error code
84 * @param err The error code
85 * @param dst A pointer to the memory area where the NULL-terminated string
86 * corresponding to the error message will be stored
87 * @param len The available length of the memory area, in bytes */
88__api void iio_strerror(int err, char *dst, size_t len);
89
90
Paul Cercueil53ed9432014-11-20 13:46:04 +010091/** @} *//* ------------------------------------------------------------------*/
Paul Cercueilb4afdd92014-04-08 12:37:21 +020092/* ------------------------- Context functions -------------------------------*/
Paul Cercueil306cb1c2014-04-11 14:46:45 +020093/** @defgroup Context Context
94 * @{
95 * @struct iio_context
96 * @brief Contains the representation of an IIO context */
Paul Cercueilb4afdd92014-04-08 12:37:21 +020097
Paul Cercueil306cb1c2014-04-11 14:46:45 +020098
Paul Cercueil8f56ea72014-10-28 15:18:18 +010099/** @brief Create a context from local or remote IIO devices
100 * @return On success, A pointer to an iio_context structure
Paul Cercueildfeca0d2015-03-16 17:18:00 +0100101 * @return On failure, NULL is returned and errno is set appropriately
Paul Cercueil8f56ea72014-10-28 15:18:18 +0100102 *
103 * <b>NOTE:</b> This function will create a network context if the IIOD_REMOTE
104 * environment variable is set to the hostname where the IIOD server runs. If
105 * set to an empty string, the server will be discovered using ZeroConf.
106 * If the environment variable is not set, a local context will be created
107 * instead. */
108__api struct iio_context * iio_create_default_context(void);
109
110
111/** @brief Create a context from local IIO devices (Linux only)
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200112 * @return On success, A pointer to an iio_context structure
Paul Cercueildfeca0d2015-03-16 17:18:00 +0100113 * @return On failure, NULL is returned and errno is set appropriately */
Paul Cercueil59f2aa32014-04-04 16:28:51 +0200114__api struct iio_context * iio_create_local_context(void);
Paul Cercueilb4afdd92014-04-08 12:37:21 +0200115
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200116
117/** @brief Create a context from a XML file
118 * @param xml_file Path to the XML file to open
119 * @return On success, A pointer to an iio_context structure
Paul Cercueildfeca0d2015-03-16 17:18:00 +0100120 * @return On failure, NULL is returned and errno is set appropriately
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200121 *
122 * <b>NOTE:</b> The format of the XML must comply to the one returned by
123 * iio_context_get_xml. */
Paul Cercueil59f2aa32014-04-04 16:28:51 +0200124__api struct iio_context * iio_create_xml_context(const char *xml_file);
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200125
126
127/** @brief Create a context from XML data in memory
128 * @param xml Pointer to the XML data in memory
129 * @param len Length of the XML string in memory (excluding the final \0)
130 * @return On success, A pointer to an iio_context structure
Paul Cercueildfeca0d2015-03-16 17:18:00 +0100131 * @return On failure, NULL is returned and errno is set appropriately
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200132 *
133 * <b>NOTE:</b> The format of the XML must comply to the one returned by
134 * iio_context_get_xml */
Paul Cercueil59f2aa32014-04-04 16:28:51 +0200135__api struct iio_context * iio_create_xml_context_mem(
136 const char *xml, size_t len);
Paul Cercueilb4afdd92014-04-08 12:37:21 +0200137
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200138
139/** @brief Create a context from the network
140 * @param host Hostname, IPv4 or IPv6 address where the IIO Daemon is running
141 * @return On success, a pointer to an iio_context structure
Paul Cercueildfeca0d2015-03-16 17:18:00 +0100142 * @return On failure, NULL is returned and errno is set appropriately */
Paul Cercueil59f2aa32014-04-04 16:28:51 +0200143__api struct iio_context * iio_create_network_context(const char *host);
Paul Cercueilb4afdd92014-04-08 12:37:21 +0200144
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200145
Paul Cercueile06f4ce2015-04-20 12:59:31 +0200146/** @brief Create a context from USB devices
147 * @param vid Vendor identification number
148 * @param pid Product identification number
149 * @return On success, a pointer to an iio_context structure
150 * @return On failure, NULL is returned and errno is set appropriately */
151__api struct iio_context * iio_create_usb_context(
152 unsigned short vid, unsigned short pid);
153
154
Paul Cercueil63d5e7c2014-10-28 14:33:08 +0100155/** @brief Duplicate a pre-existing IIO context
156 * @param ctx A pointer to an iio_context structure
157 * @return On success, A pointer to an iio_context structure
Paul Cercueildfeca0d2015-03-16 17:18:00 +0100158 * @return On failure, NULL is returned and errno is set appropriately */
Paul Cercueil63d5e7c2014-10-28 14:33:08 +0100159__api struct iio_context * iio_context_clone(const struct iio_context *ctx);
160
161
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200162/** @brief Destroy the given context
163 * @param ctx A pointer to an iio_context structure
164 *
165 * <b>NOTE:</b> After that function, the iio_context pointer shall be invalid. */
Paul Cercueil59f2aa32014-04-04 16:28:51 +0200166__api void iio_context_destroy(struct iio_context *ctx);
Paul Cercueil0b2ce712014-02-17 15:04:18 +0100167
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200168
Paul Cercueile45f8762014-05-02 11:19:26 +0200169/** @brief Get the version of the backend in use
170 * @param ctx A pointer to an iio_context structure
Paul Cercueild15d9952014-05-20 11:40:08 +0200171 * @param major A pointer to an unsigned integer (NULL accepted)
172 * @param minor A pointer to an unsigned integer (NULL accepted)
Paul Cercueil9de9e9d2014-05-20 13:18:19 +0200173 * @param git_tag A pointer to a 8-characters buffer (NULL accepted)
Paul Cercueile45f8762014-05-02 11:19:26 +0200174 * @return On success, 0 is returned
175 * @return On error, a negative errno code is returned */
176__api int iio_context_get_version(const struct iio_context *ctx,
Paul Cercueil9de9e9d2014-05-20 13:18:19 +0200177 unsigned int *major, unsigned int *minor, char git_tag[8]);
Paul Cercueile45f8762014-05-02 11:19:26 +0200178
179
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200180/** @brief Obtain a XML representation of the given context
181 * @param ctx A pointer to an iio_context structure
182 * @return A pointer to a static NULL-terminated string */
Paul Cercueilb4afdd92014-04-08 12:37:21 +0200183__api __pure const char * iio_context_get_xml(const struct iio_context *ctx);
184
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200185
186/** @brief Get the name of the given context
187 * @param ctx A pointer to an iio_context structure
188 * @return A pointer to a static NULL-terminated string
189 *
190 * <b>NOTE:</b>The returned string will be <b><i>local</i></b>,
191 * <b><i>xml</i></b> or <b><i>network</i></b> when the context has been
192 * created with the local, xml and network backends respectively.*/
Paul Cercueil59f2aa32014-04-04 16:28:51 +0200193__api __pure const char * iio_context_get_name(const struct iio_context *ctx);
Paul Cercueilb4afdd92014-04-08 12:37:21 +0200194
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200195
Paul Cercueil3ac36c12015-01-08 14:44:00 +0100196/** @brief Get a description of the given context
197 * @param ctx A pointer to an iio_context structure
198 * @return A pointer to a static NULL-terminated string
199 *
200 * <b>NOTE:</b>The returned string will contain human-readable information about
201 * the current context. */
202__api __pure const char * iio_context_get_description(
203 const struct iio_context *ctx);
204
205
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200206/** @brief Enumerate the devices found in the given context
207 * @param ctx A pointer to an iio_context structure
208 * @return The number of devices found */
Paul Cercueil59f2aa32014-04-04 16:28:51 +0200209__api __pure unsigned int iio_context_get_devices_count(
210 const struct iio_context *ctx);
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200211
212
213/** @brief Get the device present at the given index
214 * @param ctx A pointer to an iio_context structure
215 * @param index The index corresponding to the device
216 * @return On success, a pointer to an iio_device structure
217 * @return If the index is invalid, NULL is returned */
Paul Cercueil59f2aa32014-04-04 16:28:51 +0200218__api __pure struct iio_device * iio_context_get_device(
219 const struct iio_context *ctx, unsigned int index);
Paul Cercueilb4afdd92014-04-08 12:37:21 +0200220
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200221
222/** @brief Try to find a device structure by its name of ID
223 * @param ctx A pointer to an iio_context structure
224 * @param name A NULL-terminated string corresponding to the name or the ID of
225 * the device to search for
226 * @return On success, a pointer to an iio_device structure
227 * @return If the name or ID does not correspond to any known device, NULL is
228 * returned */
Paul Cercueil59f2aa32014-04-04 16:28:51 +0200229__api __pure struct iio_device * iio_context_find_device(
230 const struct iio_context *ctx, const char *name);
Paul Cercueil0b2ce712014-02-17 15:04:18 +0100231
Paul Cercueilb4afdd92014-04-08 12:37:21 +0200232
Paul Cercueil4ca73542014-06-10 16:23:29 +0200233/** @brief Set a timeout for I/O operations
234 * @param ctx A pointer to an iio_context structure
235 * @param timeout_ms A positive integer representing the time in milliseconds
Lars-Peter Clausenae7b7d92016-04-21 18:22:38 +0200236 * after which a timeout occurs. A value of 0 is used to specify that no
237 * timeout should occur.
Paul Cercueil4ca73542014-06-10 16:23:29 +0200238 * @return On success, 0 is returned
239 * @return On error, a negative errno code is returned */
240__api int iio_context_set_timeout(
241 struct iio_context *ctx, unsigned int timeout_ms);
242
243
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200244/** @} *//* ------------------------------------------------------------------*/
Paul Cercueilb4afdd92014-04-08 12:37:21 +0200245/* ------------------------- Device functions --------------------------------*/
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200246/** @defgroup Device Device
247 * @{
248 * @struct iio_device
249 * @brief Represents a device in the IIO context */
Paul Cercueilb4afdd92014-04-08 12:37:21 +0200250
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200251
Paul Cercueil03b6c812015-04-14 16:49:06 +0200252/** @brief Retrieve a pointer to the iio_context structure
253 * @param dev A pointer to an iio_device structure
254 * @return A pointer to an iio_context structure */
255__api __pure const struct iio_context * iio_device_get_context(
256 const struct iio_device *dev);
257
258
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200259/** @brief Retrieve the device ID (e.g. <b><i>iio:device0</i></b>)
260 * @param dev A pointer to an iio_device structure
261 * @return A pointer to a static NULL-terminated string */
Paul Cercueil59f2aa32014-04-04 16:28:51 +0200262__api __pure const char * iio_device_get_id(const struct iio_device *dev);
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200263
264
265/** @brief Retrieve the device name (e.g. <b><i>xadc</i></b>)
266 * @param dev A pointer to an iio_device structure
267 * @return A pointer to a static NULL-terminated string
268 *
269 * <b>NOTE:</b> if the device has no name, NULL is returned. */
Paul Cercueil59f2aa32014-04-04 16:28:51 +0200270__api __pure const char * iio_device_get_name(const struct iio_device *dev);
Paul Cercueilb4afdd92014-04-08 12:37:21 +0200271
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200272
273/** @brief Enumerate the channels of the given device
274 * @param dev A pointer to an iio_device structure
275 * @return The number of channels found */
Paul Cercueil59f2aa32014-04-04 16:28:51 +0200276__api __pure unsigned int iio_device_get_channels_count(
277 const struct iio_device *dev);
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200278
279
280/** @brief Enumerate the device-specific attributes of the given device
281 * @param dev A pointer to an iio_device structure
282 * @return The number of device-specific attributes found */
Paul Cercueil59f2aa32014-04-04 16:28:51 +0200283__api __pure unsigned int iio_device_get_attrs_count(
284 const struct iio_device *dev);
Paul Cercueilb4afdd92014-04-08 12:37:21 +0200285
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200286
287/** @brief Get the channel present at the given index
288 * @param dev A pointer to an iio_device structure
289 * @param index The index corresponding to the channel
290 * @return On success, a pointer to an iio_channel structure
291 * @return If the index is invalid, NULL is returned */
Paul Cercueilb4afdd92014-04-08 12:37:21 +0200292__api __pure struct iio_channel * iio_device_get_channel(
293 const struct iio_device *dev, unsigned int index);
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200294
295
296/** @brief Get the device-specific attribute present at the given index
297 * @param dev A pointer to an iio_device structure
298 * @param index The index corresponding to the attribute
299 * @return On success, a pointer to a static NULL-terminated string
300 * @return If the index is invalid, NULL is returned */
Paul Cercueil59f2aa32014-04-04 16:28:51 +0200301__api __pure const char * iio_device_get_attr(
302 const struct iio_device *dev, unsigned int index);
Paul Cercueilb4afdd92014-04-08 12:37:21 +0200303
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200304
305/** @brief Try to find a channel structure by its name of ID
306 * @param dev A pointer to an iio_device structure
307 * @param name A NULL-terminated string corresponding to the name or the ID of
308 * the channel to search for
309 * @param output True if the searched channel is output, False otherwise
310 * @return On success, a pointer to an iio_channel structure
311 * @return If the name or ID does not correspond to any known channel of the
312 * given device, NULL is returned */
Paul Cercueilb4afdd92014-04-08 12:37:21 +0200313__api __pure struct iio_channel * iio_device_find_channel(
314 const struct iio_device *dev, const char *name, bool output);
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200315
316
317/** @brief Try to find a device-specific attribute by its name
318 * @param dev A pointer to an iio_device structure
Paul Cercueil30606d52014-04-14 16:04:15 +0200319 * @param name A NULL-terminated string corresponding to the name of the
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200320 * attribute
321 * @return On success, a pointer to a static NULL-terminated string
322 * @return If the name does not correspond to any known attribute of the given
323 * device, NULL is returned
324 *
325 * <b>NOTE:</b> This function is useful to detect the presence of an attribute.
326 * It can also be used to retrieve the name of an attribute as a pointer to a
327 * static string from a dynamically allocated string. */
Paul Cercueil59f2aa32014-04-04 16:28:51 +0200328__api __pure const char * iio_device_find_attr(
329 const struct iio_device *dev, const char *name);
Paul Cercueilb4afdd92014-04-08 12:37:21 +0200330
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200331
332/** @brief Read the content of the given device-specific attribute
333 * @param dev A pointer to an iio_device structure
Paul Cercueil30606d52014-04-14 16:04:15 +0200334 * @param attr A NULL-terminated string corresponding to the name of the
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200335 * attribute
336 * @param dst A pointer to the memory area where the NULL-terminated string
337 * corresponding to the value read will be stored
338 * @param len The available length of the memory area, in bytes
339 * @return On success, the number of bytes written to the buffer
Paul Cercueil4ca6ddc2014-05-21 14:51:50 +0200340 * @return On error, a negative errno code is returned
341 *
342 * <b>NOTE:</b>By passing NULL as the "attr" argument to iio_device_attr_read,
343 * it is now possible to read all of the attributes of a device.
344 *
345 * The buffer is filled with one block of data per attribute of the device,
346 * by the order they appear in the iio_device structure.
347 *
348 * The first four bytes of one block correspond to a 32-bit signed value in
349 * network order. If negative, it corresponds to the errno code that were
350 * returned when reading the attribute; if positive, it corresponds to the
351 * length of the data read. In that case, the rest of the block contains
352 * the data. */
353 __api ssize_t iio_device_attr_read(const struct iio_device *dev,
Paul Cercueilb4afdd92014-04-08 12:37:21 +0200354 const char *attr, char *dst, size_t len);
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200355
356
Paul Cercueil1b36a012014-06-05 14:39:31 +0200357/** @brief Read the content of all device-specific attributes
358 * @param dev A pointer to an iio_device structure
359 * @param cb A pointer to a callback function
360 * @param data A pointer that will be passed to the callback function
361 * @return On success, 0 is returned
362 * @return On error, a negative errno code is returned
363 *
364 * <b>NOTE:</b> This function is especially useful when used with the network
365 * backend, as all the device-specific attributes are read in one single
366 * command. */
367__api int iio_device_attr_read_all(struct iio_device *dev,
368 int (*cb)(struct iio_device *dev, const char *attr,
369 const char *value, size_t len, void *d),
370 void *data);
371
372
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200373/** @brief Read the content of the given device-specific attribute
374 * @param dev A pointer to an iio_device structure
Paul Cercueil30606d52014-04-14 16:04:15 +0200375 * @param attr A NULL-terminated string corresponding to the name of the
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200376 * attribute
377 * @param val A pointer to a bool variable where the value should be stored
378 * @return On success, 0 is returned
379 * @return On error, a negative errno code is returned */
Paul Cercueilb4afdd92014-04-08 12:37:21 +0200380__api int iio_device_attr_read_bool(const struct iio_device *dev,
381 const char *attr, bool *val);
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200382
383
384/** @brief Read the content of the given device-specific attribute
385 * @param dev A pointer to an iio_device structure
Paul Cercueil30606d52014-04-14 16:04:15 +0200386 * @param attr A NULL-terminated string corresponding to the name of the
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200387 * attribute
388 * @param val A pointer to a long long variable where the value should be stored
389 * @return On success, 0 is returned
390 * @return On error, a negative errno code is returned */
Paul Cercueilb4afdd92014-04-08 12:37:21 +0200391__api int iio_device_attr_read_longlong(const struct iio_device *dev,
392 const char *attr, long long *val);
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200393
394
395/** @brief Read the content of the given device-specific attribute
396 * @param dev A pointer to an iio_device structure
Paul Cercueil30606d52014-04-14 16:04:15 +0200397 * @param attr A NULL-terminated string corresponding to the name of the
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200398 * attribute
399 * @param val A pointer to a double variable where the value should be stored
400 * @return On success, 0 is returned
401 * @return On error, a negative errno code is returned */
Paul Cercueilb4afdd92014-04-08 12:37:21 +0200402__api int iio_device_attr_read_double(const struct iio_device *dev,
403 const char *attr, double *val);
404
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200405
406/** @brief Set the value of the given device-specific attribute
407 * @param dev A pointer to an iio_device structure
Paul Cercueil30606d52014-04-14 16:04:15 +0200408 * @param attr A NULL-terminated string corresponding to the name of the
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200409 * attribute
410 * @param src A NULL-terminated string to set the attribute to
411 * @return On success, the number of bytes written
Paul Cercueil1da28122014-05-22 10:59:49 +0200412 * @return On error, a negative errno code is returned
413 *
414 * <b>NOTE:</b>By passing NULL as the "attr" argument to iio_device_attr_write,
415 * it is now possible to write all of the attributes of a device.
416 *
417 * The buffer must contain one block of data per attribute of the device,
418 * by the order they appear in the iio_device structure.
419 *
420 * The first four bytes of one block correspond to a 32-bit signed value in
421 * network order. If negative, the attribute is not written; if positive,
422 * it corresponds to the length of the data to write. In that case, the rest
423 * of the block must contain the data. */
Paul Cercueilb4afdd92014-04-08 12:37:21 +0200424__api ssize_t iio_device_attr_write(const struct iio_device *dev,
425 const char *attr, const char *src);
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200426
427
428/** @brief Set the value of the given device-specific attribute
429 * @param dev A pointer to an iio_device structure
Paul Cercueil30606d52014-04-14 16:04:15 +0200430 * @param attr A NULL-terminated string corresponding to the name of the
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200431 * attribute
Paul Cercueilcecda352014-05-06 18:14:29 +0200432 * @param src A pointer to the data to be written
433 * @param len The number of bytes that should be written
434 * @return On success, the number of bytes written
435 * @return On error, a negative errno code is returned */
436__api ssize_t iio_device_attr_write_raw(const struct iio_device *dev,
437 const char *attr, const void *src, size_t len);
438
439
Paul Cercueil1b36a012014-06-05 14:39:31 +0200440/** @brief Set the values of all device-specific attributes
441 * @param dev A pointer to an iio_device structure
442 * @param cb A pointer to a callback function
443 * @param data A pointer that will be passed to the callback function
444 * @return On success, 0 is returned
445 * @return On error, a negative errno code is returned
446 *
447 * <b>NOTE:</b> This function is especially useful when used with the network
448 * backend, as all the device-specific attributes are written in one single
449 * command. */
450__api int iio_device_attr_write_all(struct iio_device *dev,
451 ssize_t (*cb)(struct iio_device *dev,
452 const char *attr, void *buf, size_t len, void *d),
453 void *data);
454
455
Paul Cercueilcecda352014-05-06 18:14:29 +0200456/** @brief Set the value of the given device-specific attribute
457 * @param dev A pointer to an iio_device structure
458 * @param attr A NULL-terminated string corresponding to the name of the
459 * attribute
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200460 * @param val A bool value to set the attribute to
461 * @return On success, 0 is returned
462 * @return On error, a negative errno code is returned */
Paul Cercueilb4afdd92014-04-08 12:37:21 +0200463__api int iio_device_attr_write_bool(const struct iio_device *dev,
464 const char *attr, bool val);
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200465
466
467/** @brief Set the value of the given device-specific attribute
468 * @param dev A pointer to an iio_device structure
Paul Cercueil30606d52014-04-14 16:04:15 +0200469 * @param attr A NULL-terminated string corresponding to the name of the
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200470 * attribute
471 * @param val A long long value to set the attribute to
472 * @return On success, 0 is returned
473 * @return On error, a negative errno code is returned */
Paul Cercueilb4afdd92014-04-08 12:37:21 +0200474__api int iio_device_attr_write_longlong(const struct iio_device *dev,
475 const char *attr, long long val);
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200476
477
478/** @brief Set the value of the given device-specific attribute
479 * @param dev A pointer to an iio_device structure
Paul Cercueil30606d52014-04-14 16:04:15 +0200480 * @param attr A NULL-terminated string corresponding to the name of the
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200481 * attribute
482 * @param val A double value to set the attribute to
483 * @return On success, 0 is returned
484 * @return On error, a negative errno code is returned */
Paul Cercueilb4afdd92014-04-08 12:37:21 +0200485__api int iio_device_attr_write_double(const struct iio_device *dev,
486 const char *attr, double val);
487
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200488
489/** @brief Associate a pointer to an iio_device structure
490 * @param dev A pointer to an iio_device structure
491 * @param data The pointer to be associated */
Paul Cercueilb4afdd92014-04-08 12:37:21 +0200492__api void iio_device_set_data(struct iio_device *dev, void *data);
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200493
494
495/** @brief Retrieve a previously associated pointer of an iio_device structure
496 * @param dev A pointer to an iio_device structure
497 * @return The pointer previously associated if present, or NULL */
Paul Cercueilb4afdd92014-04-08 12:37:21 +0200498__api void * iio_device_get_data(const struct iio_device *dev);
499
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200500
501/** @brief Retrieve the trigger of a given device
502 * @param dev A pointer to an iio_device structure
503 * @param trigger a pointer to a pointer of an iio_device structure. The pointed
504 * pointer will be set to the address of the iio_device structure corresponding
505 * to the associated trigger device.
506 * @return On success, 0 is returned
507 * @return On error, a negative errno code is returned */
Paul Cercueil59f2aa32014-04-04 16:28:51 +0200508__api int iio_device_get_trigger(const struct iio_device *dev,
Paul Cercueil24ffa532014-03-10 12:39:58 +0100509 const struct iio_device **trigger);
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200510
511
512/** @brief Associate a trigger to a given device
513 * @param dev A pointer to an iio_device structure
514 * @param trigger a pointer to the iio_device structure corresponding to the
515 * trigger that should be associated.
516 * @return On success, 0 is returned
517 * @return On error, a negative errno code is returned */
Paul Cercueil59f2aa32014-04-04 16:28:51 +0200518__api int iio_device_set_trigger(const struct iio_device *dev,
Paul Cercueil24ffa532014-03-10 12:39:58 +0100519 const struct iio_device *trigger);
Paul Cercueil0b2ce712014-02-17 15:04:18 +0100520
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200521
522/** @brief Return True if the given device is a trigger
523 * @param dev A pointer to an iio_device structure
524 * @return True if the device is a trigger, False otherwise */
Paul Cercueilb4afdd92014-04-08 12:37:21 +0200525__api __pure bool iio_device_is_trigger(const struct iio_device *dev);
526
Romain Roffé6c385d92015-06-30 13:36:05 +0200527/**
528 * @brief Configure the number of kernel buffers for a device
529 *
530 * This function allows to change the number of buffers on kernel side.
531 * @param dev A pointer to an iio_device structure
532 * @param nb_buffers The number of buffers
533 * @return On success, 0 is returned
534 * @return On error, a negative errno code is returned */
535__api int iio_device_set_kernel_buffers_count(const struct iio_device *dev,
536 unsigned int nb_buffers);
Paul Cercueilb4afdd92014-04-08 12:37:21 +0200537
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200538/** @} *//* ------------------------------------------------------------------*/
Paul Cercueilb4afdd92014-04-08 12:37:21 +0200539/* ------------------------- Channel functions -------------------------------*/
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200540/** @defgroup Channel Channel
541 * @{
542 * @struct iio_channel
543 * @brief Represents an input or output channel of a device */
Paul Cercueilb4afdd92014-04-08 12:37:21 +0200544
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200545
Paul Cercueil03b6c812015-04-14 16:49:06 +0200546/** @brief Retrieve a pointer to the iio_device structure
547 * @param chn A pointer to an iio_channel structure
548 * @return A pointer to an iio_device structure */
549__api __pure const struct iio_device * iio_channel_get_device(
550 const struct iio_channel *chn);
551
552
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200553/** @brief Retrieve the channel ID (e.g. <b><i>voltage0</i></b>)
554 * @param chn A pointer to an iio_channel structure
555 * @return A pointer to a static NULL-terminated string */
Paul Cercueilb4afdd92014-04-08 12:37:21 +0200556__api __pure const char * iio_channel_get_id(const struct iio_channel *chn);
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200557
558
559/** @brief Retrieve the channel name (e.g. <b><i>vccint</i></b>)
560 * @param chn A pointer to an iio_channel structure
561 * @return A pointer to a static NULL-terminated string
562 *
563 * <b>NOTE:</b> if the channel has no name, NULL is returned. */
Paul Cercueilb4afdd92014-04-08 12:37:21 +0200564__api __pure const char * iio_channel_get_name(const struct iio_channel *chn);
565
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200566
567/** @brief Return True if the given channel is an output channel
568 * @param chn A pointer to an iio_channel structure
569 * @return True if the channel is an output channel, False otherwise */
Paul Cercueilb4afdd92014-04-08 12:37:21 +0200570__api __pure bool iio_channel_is_output(const struct iio_channel *chn);
571
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200572
Paul Cercueil85aaf482014-04-24 16:39:09 +0200573/** @brief Return True if the given channel is a scan element
574 * @param chn A pointer to an iio_channel structure
575 * @return True if the channel is a scan element, False otherwise
576 *
577 * <b>NOTE:</b> a channel that is a scan element is a channel that can
578 * generate samples (for an input channel) or receive samples (for an output
579 * channel) after being enabled. */
580__api __pure bool iio_channel_is_scan_element(const struct iio_channel *chn);
581
582
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200583/** @brief Enumerate the channel-specific attributes of the given channel
584 * @param chn A pointer to an iio_channel structure
585 * @return The number of channel-specific attributes found */
Paul Cercueilb4afdd92014-04-08 12:37:21 +0200586__api __pure unsigned int iio_channel_get_attrs_count(
587 const struct iio_channel *chn);
588
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200589
590/** @brief Get the channel-specific attribute present at the given index
591 * @param chn A pointer to an iio_channel structure
592 * @param index The index corresponding to the attribute
593 * @return On success, a pointer to a static NULL-terminated string
594 * @return If the index is invalid, NULL is returned */
Paul Cercueilb4afdd92014-04-08 12:37:21 +0200595__api __pure const char * iio_channel_get_attr(
596 const struct iio_channel *chn, unsigned int index);
597
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200598
599/** @brief Try to find a channel-specific attribute by its name
600 * @param chn A pointer to an iio_channel structure
Paul Cercueil30606d52014-04-14 16:04:15 +0200601 * @param name A NULL-terminated string corresponding to the name of the
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200602 * attribute
603 * @return On success, a pointer to a static NULL-terminated string
604 * @return If the name does not correspond to any known attribute of the given
605 * channel, NULL is returned
606 *
607 * <b>NOTE:</b> This function is useful to detect the presence of an attribute.
608 * It can also be used to retrieve the name of an attribute as a pointer to a
609 * static string from a dynamically allocated string. */
Paul Cercueilb4afdd92014-04-08 12:37:21 +0200610__api __pure const char * iio_channel_find_attr(
611 const struct iio_channel *chn, const char *name);
612
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200613
Paul Cercueil6f8dbd42014-05-05 17:05:59 +0200614/** @brief Retrieve the filename of an attribute
615 * @param chn A pointer to an iio_channel structure
616 * @param attr a NULL-terminated string corresponding to the name of the
617 * attribute
618 * @return On success, a pointer to a static NULL-terminated string
619 * @return If the attribute name is unknown, NULL is returned */
620__api __pure const char * iio_channel_attr_get_filename(
621 const struct iio_channel *chn, const char *attr);
622
623
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200624/** @brief Read the content of the given channel-specific attribute
625 * @param chn A pointer to an iio_channel structure
Paul Cercueil30606d52014-04-14 16:04:15 +0200626 * @param attr A NULL-terminated string corresponding to the name of the
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200627 * attribute
628 * @param dst A pointer to the memory area where the NULL-terminated string
629 * corresponding to the value read will be stored
630 * @param len The available length of the memory area, in bytes
631 * @return On success, the number of bytes written to the buffer
Paul Cercueil4ca6ddc2014-05-21 14:51:50 +0200632 * @return On error, a negative errno code is returned
633 *
634 * <b>NOTE:</b>By passing NULL as the "attr" argument to iio_channel_attr_read,
635 * it is now possible to read all of the attributes of a channel.
636 *
637 * The buffer is filled with one block of data per attribute of the channel,
638 * by the order they appear in the iio_channel structure.
639 *
640 * The first four bytes of one block correspond to a 32-bit signed value in
641 * network order. If negative, it corresponds to the errno code that were
642 * returned when reading the attribute; if positive, it corresponds to the
643 * length of the data read. In that case, the rest of the block contains
644 * the data. */
Paul Cercueilb4afdd92014-04-08 12:37:21 +0200645__api ssize_t iio_channel_attr_read(const struct iio_channel *chn,
646 const char *attr, char *dst, size_t len);
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200647
648
Paul Cercueil47d23d02014-06-05 14:46:20 +0200649/** @brief Read the content of all channel-specific attributes
650 * @param chn A pointer to an iio_channel structure
651 * @param cb A pointer to a callback function
652 * @param data A pointer that will be passed to the callback function
653 * @return On success, 0 is returned
654 * @return On error, a negative errno code is returned
655 *
656 * <b>NOTE:</b> This function is especially useful when used with the network
657 * backend, as all the channel-specific attributes are read in one single
658 * command. */
659__api int iio_channel_attr_read_all(struct iio_channel *chn,
660 int (*cb)(struct iio_channel *chn,
661 const char *attr, const char *val, size_t len, void *d),
662 void *data);
663
664
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200665/** @brief Read the content of the given channel-specific attribute
666 * @param chn A pointer to an iio_channel structure
Paul Cercueil30606d52014-04-14 16:04:15 +0200667 * @param attr A NULL-terminated string corresponding to the name of the
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200668 * attribute
669 * @param val A pointer to a bool variable where the value should be stored
670 * @return On success, 0 is returned
671 * @return On error, a negative errno code is returned */
Paul Cercueilb4afdd92014-04-08 12:37:21 +0200672__api int iio_channel_attr_read_bool(const struct iio_channel *chn,
673 const char *attr, bool *val);
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200674
675
676/** @brief Read the content of the given channel-specific attribute
677 * @param chn A pointer to an iio_channel structure
Paul Cercueil30606d52014-04-14 16:04:15 +0200678 * @param attr A NULL-terminated string corresponding to the name of the
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200679 * attribute
680 * @param val A pointer to a long long variable where the value should be stored
681 * @return On success, 0 is returned
682 * @return On error, a negative errno code is returned */
Paul Cercueilb4afdd92014-04-08 12:37:21 +0200683__api int iio_channel_attr_read_longlong(const struct iio_channel *chn,
684 const char *attr, long long *val);
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200685
686
687/** @brief Read the content of the given channel-specific attribute
688 * @param chn A pointer to an iio_channel structure
Paul Cercueil30606d52014-04-14 16:04:15 +0200689 * @param attr A NULL-terminated string corresponding to the name of the
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200690 * attribute
691 * @param val A pointer to a double variable where the value should be stored
692 * @return On success, 0 is returned
693 * @return On error, a negative errno code is returned */
Paul Cercueilb4afdd92014-04-08 12:37:21 +0200694__api int iio_channel_attr_read_double(const struct iio_channel *chn,
695 const char *attr, double *val);
696
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200697
698/** @brief Set the value of the given channel-specific attribute
699 * @param chn A pointer to an iio_channel structure
Paul Cercueil30606d52014-04-14 16:04:15 +0200700 * @param attr A NULL-terminated string corresponding to the name of the
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200701 * attribute
702 * @param src A NULL-terminated string to set the attribute to
703 * @return On success, the number of bytes written
Paul Cercueil1da28122014-05-22 10:59:49 +0200704 * @return On error, a negative errno code is returned
705 *
706 * <b>NOTE:</b>By passing NULL as the "attr" argument to iio_channel_attr_write,
707 * it is now possible to write all of the attributes of a channel.
708 *
709 * The buffer must contain one block of data per attribute of the channel,
710 * by the order they appear in the iio_channel structure.
711 *
712 * The first four bytes of one block correspond to a 32-bit signed value in
713 * network order. If negative, the attribute is not written; if positive,
714 * it corresponds to the length of the data to write. In that case, the rest
715 * of the block must contain the data. */
Paul Cercueilb4afdd92014-04-08 12:37:21 +0200716__api ssize_t iio_channel_attr_write(const struct iio_channel *chn,
717 const char *attr, const char *src);
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200718
719
720/** @brief Set the value of the given channel-specific attribute
721 * @param chn A pointer to an iio_channel structure
Paul Cercueil30606d52014-04-14 16:04:15 +0200722 * @param attr A NULL-terminated string corresponding to the name of the
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200723 * attribute
Paul Cercueilcecda352014-05-06 18:14:29 +0200724 * @param src A pointer to the data to be written
725 * @param len The number of bytes that should be written
726 * @return On success, the number of bytes written
727 * @return On error, a negative errno code is returned */
728__api ssize_t iio_channel_attr_write_raw(const struct iio_channel *chn,
729 const char *attr, const void *src, size_t len);
730
731
Paul Cercueil47d23d02014-06-05 14:46:20 +0200732/** @brief Set the values of all channel-specific attributes
733 * @param chn A pointer to an iio_channel structure
734 * @param cb A pointer to a callback function
735 * @param data A pointer that will be passed to the callback function
736 * @return On success, 0 is returned
737 * @return On error, a negative errno code is returned
738 *
739 * <b>NOTE:</b> This function is especially useful when used with the network
740 * backend, as all the channel-specific attributes are written in one single
741 * command. */
742__api int iio_channel_attr_write_all(struct iio_channel *chn,
743 ssize_t (*cb)(struct iio_channel *chn,
744 const char *attr, void *buf, size_t len, void *d),
745 void *data);
746
747
Paul Cercueilcecda352014-05-06 18:14:29 +0200748/** @brief Set the value of the given channel-specific attribute
749 * @param chn A pointer to an iio_channel structure
750 * @param attr A NULL-terminated string corresponding to the name of the
751 * attribute
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200752 * @param val A bool value to set the attribute to
753 * @return On success, 0 is returned
754 * @return On error, a negative errno code is returned */
Paul Cercueilb4afdd92014-04-08 12:37:21 +0200755__api int iio_channel_attr_write_bool(const struct iio_channel *chn,
756 const char *attr, bool val);
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200757
758
759/** @brief Set the value of the given channel-specific attribute
760 * @param chn A pointer to an iio_channel structure
Paul Cercueil30606d52014-04-14 16:04:15 +0200761 * @param attr A NULL-terminated string corresponding to the name of the
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200762 * attribute
763 * @param val A long long value to set the attribute to
764 * @return On success, 0 is returned
765 * @return On error, a negative errno code is returned */
Paul Cercueilb4afdd92014-04-08 12:37:21 +0200766__api int iio_channel_attr_write_longlong(const struct iio_channel *chn,
767 const char *attr, long long val);
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200768
769
770/** @brief Set the value of the given channel-specific attribute
771 * @param chn A pointer to an iio_channel structure
Paul Cercueil30606d52014-04-14 16:04:15 +0200772 * @param attr A NULL-terminated string corresponding to the name of the
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200773 * attribute
774 * @param val A double value to set the attribute to
775 * @return On success, 0 is returned
776 * @return On error, a negative errno code is returned */
Paul Cercueilb4afdd92014-04-08 12:37:21 +0200777__api int iio_channel_attr_write_double(const struct iio_channel *chn,
778 const char *attr, double val);
779
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200780
781/** @brief Enable the given channel
782 * @param chn A pointer to an iio_channel structure
783 *
784 * <b>NOTE:</b>Before creating an iio_buffer structure with
785 * iio_device_create_buffer, it is required to enable at least one channel of
786 * the device to read from. */
Paul Cercueilb4afdd92014-04-08 12:37:21 +0200787__api void iio_channel_enable(struct iio_channel *chn);
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200788
789
790/** @brief Disable the given channel
791 * @param chn A pointer to an iio_channel structure */
Paul Cercueilb4afdd92014-04-08 12:37:21 +0200792__api void iio_channel_disable(struct iio_channel *chn);
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200793
794
795/** @brief Returns True if the channel is enabled
796 * @param chn A pointer to an iio_channel structure
797 * @return True if the channel is enabled, False otherwise */
Paul Cercueilb4afdd92014-04-08 12:37:21 +0200798__api bool iio_channel_is_enabled(const struct iio_channel *chn);
799
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200800
801/** Demultiplex the samples of a given channel
802 * @param chn A pointer to an iio_channel structure
803 * @param buffer A pointer to an iio_buffer structure
804 * @param dst A pointer to the memory area where the demultiplexed data will be
805 * stored
806 * @param len The available length of the memory area, in bytes
807 * @return The size of the demultiplexed data, in bytes */
Paul Cercueilb4afdd92014-04-08 12:37:21 +0200808__api size_t iio_channel_read_raw(const struct iio_channel *chn,
809 struct iio_buffer *buffer, void *dst, size_t len);
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200810
811
812/** Demultiplex and convert the samples of a given channel
813 * @param chn A pointer to an iio_channel structure
814 * @param buffer A pointer to an iio_buffer structure
815 * @param dst A pointer to the memory area where the converted data will be
816 * stored
817 * @param len The available length of the memory area, in bytes
818 * @return The size of the converted data, in bytes */
Paul Cercueilb4afdd92014-04-08 12:37:21 +0200819__api size_t iio_channel_read(const struct iio_channel *chn,
820 struct iio_buffer *buffer, void *dst, size_t len);
821
822
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200823/** Multiplex the samples of a given channel
824 * @param chn A pointer to an iio_channel structure
825 * @param buffer A pointer to an iio_buffer structure
826 * @param src A pointer to the memory area where the sequential data will
827 * be read from
828 * @param len The length of the memory area, in bytes
829 * @return The number of bytes actually multiplexed */
Paul Cercueilb4afdd92014-04-08 12:37:21 +0200830__api size_t iio_channel_write_raw(const struct iio_channel *chn,
831 struct iio_buffer *buffer, const void *src, size_t len);
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200832
833
834/** Convert and multiplex the samples of a given channel
835 * @param chn A pointer to an iio_channel structure
836 * @param buffer A pointer to an iio_buffer structure
837 * @param src A pointer to the memory area where the sequential data will
838 * be read from
839 * @param len The length of the memory area, in bytes
840 * @return The number of bytes actually converted and multiplexed */
Paul Cercueilb4afdd92014-04-08 12:37:21 +0200841__api size_t iio_channel_write(const struct iio_channel *chn,
842 struct iio_buffer *buffer, const void *src, size_t len);
843
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200844
845/** @brief Associate a pointer to an iio_channel structure
846 * @param chn A pointer to an iio_channel structure
847 * @param data The pointer to be associated */
Paul Cercueilb4afdd92014-04-08 12:37:21 +0200848__api void iio_channel_set_data(struct iio_channel *chn, void *data);
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200849
850
851/** @brief Retrieve a previously associated pointer of an iio_channel structure
852 * @param chn A pointer to an iio_channel structure
853 * @return The pointer previously associated if present, or NULL */
Paul Cercueilb4afdd92014-04-08 12:37:21 +0200854__api void * iio_channel_get_data(const struct iio_channel *chn);
855
856
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200857/** @} *//* ------------------------------------------------------------------*/
Paul Cercueilb4afdd92014-04-08 12:37:21 +0200858/* ------------------------- Buffer functions --------------------------------*/
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200859/** @defgroup Buffer Buffer
860 * @{
861 * @struct iio_buffer
862 * @brief An input or output buffer, used to read or write samples */
Paul Cercueilb4afdd92014-04-08 12:37:21 +0200863
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200864
Paul Cercueil03b6c812015-04-14 16:49:06 +0200865/** @brief Retrieve a pointer to the iio_device structure
866 * @param buf A pointer to an iio_buffer structure
867 * @return A pointer to an iio_device structure */
868__api __pure const struct iio_device * iio_buffer_get_device(
869 const struct iio_buffer *buf);
870
871
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200872/** @brief Create an input or output buffer associated to the given device
873 * @param dev A pointer to an iio_device structure
874 * @param samples_count The number of samples that the buffer should contain
Paul Cercueil2004eaa2014-05-22 14:04:39 +0200875 * @param cyclic If True, enable cyclic mode
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200876 * @return On success, a pointer to an iio_buffer structure
Paul Cercueil3106e892014-04-30 11:29:51 +0200877 * @return On error, NULL is returned, and errno is set to the error code
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200878 *
879 * <b>NOTE:</b> Channels that have to be written to / read from must be enabled
Paul Cercueilb4afdd92014-04-08 12:37:21 +0200880 * before creating the buffer. */
881__api struct iio_buffer * iio_device_create_buffer(const struct iio_device *dev,
Paul Cercueil2004eaa2014-05-22 14:04:39 +0200882 size_t samples_count, bool cyclic);
Paul Cercueilb4afdd92014-04-08 12:37:21 +0200883
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200884
885/** @brief Destroy the given buffer
886 * @param buf A pointer to an iio_buffer structure
887 *
888 * <b>NOTE:</b> After that function, the iio_buffer pointer shall be invalid. */
Paul Cercueilb4afdd92014-04-08 12:37:21 +0200889__api void iio_buffer_destroy(struct iio_buffer *buf);
890
Romain Roffé6a881702015-06-30 16:25:43 +0200891/** @brief Get a pollable file descriptor
892 *
893 * Can be used to know when iio_buffer_refill() or iio_buffer_push() can be
894 * called
895 * @param buf A pointer to an iio_buffer structure
896 * @return On success, valid file descriptor
897 * @return On error, a negative errno code is returned
898 */
899__api int iio_buffer_get_poll_fd(struct iio_buffer *buf);
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200900
Romain Roffé0ea038d2015-06-30 13:35:38 +0200901/** @brief Make iio_buffer_refill() and iio_buffer_push() blocking or not
902 *
Paul Cercueil10ff7572015-11-19 17:12:34 +0100903 * After this function has been called with blocking == true,
Romain Roffé0ea038d2015-06-30 13:35:38 +0200904 * iio_buffer_refill() and iio_buffer_push() will return -EAGAIN if no data is
905 * ready.
906 * A device is blocking by default.
907 * @param buf A pointer to an iio_buffer structure
908 * @param blocking true if the buffer API should be blocking, else false
909 * @return On success, 0
910 * @return On error, a negative errno code is returned
911 */
912__api int iio_buffer_set_blocking_mode(struct iio_buffer *buf, bool blocking);
913
914
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200915/** @brief Fetch more samples from the hardware
916 * @param buf A pointer to an iio_buffer structure
917 * @return On success, the number of bytes read is returned
918 * @return On error, a negative errno code is returned
919 *
920 * <b>NOTE:</b> Only valid for input buffers */
Paul Cercueilb4afdd92014-04-08 12:37:21 +0200921__api ssize_t iio_buffer_refill(struct iio_buffer *buf);
922
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200923
924/** @brief Send the samples to the hardware
925 * @param buf A pointer to an iio_buffer structure
926 * @return On success, the number of bytes written is returned
927 * @return On error, a negative errno code is returned
928 *
929 * <b>NOTE:</b> Only valid for output buffers */
Paul Cercueil0183b6e2014-05-20 13:21:46 +0200930__api ssize_t iio_buffer_push(struct iio_buffer *buf);
Paul Cercueilb4afdd92014-04-08 12:37:21 +0200931
Paul Cercueilb4afdd92014-04-08 12:37:21 +0200932
Paul Cercueil8e7b4192015-08-05 13:03:35 +0200933/** @brief Send a given number of samples to the hardware
934 * @param buf A pointer to an iio_buffer structure
935 * @param samples_count The number of samples to submit
936 * @return On success, the number of bytes written is returned
937 * @return On error, a negative errno code is returned
938 *
939 * <b>NOTE:</b> Only valid for output buffers */
940__api ssize_t iio_buffer_push_partial(struct iio_buffer *buf,
941 size_t samples_count);
942
943
Paul Cercueil6d927162014-04-16 15:53:22 +0200944/** @brief Get the start address of the buffer
945 * @param buf A pointer to an iio_buffer structure
946 * @return A pointer corresponding to the start address of the buffer */
Paul Cercueil49106002015-03-04 13:19:20 +0100947__api void * iio_buffer_start(const struct iio_buffer *buf);
Paul Cercueil6d927162014-04-16 15:53:22 +0200948
949
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200950/** @brief Find the first sample of a channel in a buffer
951 * @param buf A pointer to an iio_buffer structure
952 * @param chn A pointer to an iio_channel structure
953 * @return A pointer to the first sample found, or to the end of the buffer if
954 * no sample for the given channel is present in the buffer
955 *
956 * <b>NOTE:</b> This fonction, coupled with iio_buffer_step and iio_buffer_end,
957 * can be used to iterate on all the samples of a given channel present in the
958 * buffer, doing the following:
959 *
960 * @verbatim
961 for (void *ptr = iio_buffer_first(buffer, chn); ptr < iio_buffer_end(buffer); ptr += iio_buffer_step(buffer)) {
962 ....
963 }
964 @endverbatim */
965__api void * iio_buffer_first(const struct iio_buffer *buf,
966 const struct iio_channel *chn);
967
968
969/** @brief Get the step size between two samples of one channel
970 * @param buf A pointer to an iio_buffer structure
971 * @return the difference between the addresses of two consecutive samples of
972 * one same channel */
973__api ptrdiff_t iio_buffer_step(const struct iio_buffer *buf);
974
975
976/** @brief Get the address that follows the last sample in a buffer
977 * @param buf A pointer to an iio_buffer structure
978 * @return A pointer corresponding to the address that follows the last sample
979 * present in the buffer */
980__api void * iio_buffer_end(const struct iio_buffer *buf);
981
982
983/** @brief Call the supplied callback for each sample found in a buffer
984 * @param buf A pointer to an iio_buffer structure
985 * @param callback A pointer to a function to call for each sample found
986 * @param data A user-specified pointer that will be passed to the callback
987 *
988 * <b>NOTE:</b> The callback receives four arguments:
989 * * A pointer to the iio_channel structure corresponding to the sample,
990 * * A pointer to the sample itself,
991 * * The length of the sample in bytes,
992 * * The user-specified pointer passed to iio_buffer_foreach_sample. */
Paul Cercueilb4afdd92014-04-08 12:37:21 +0200993__api ssize_t iio_buffer_foreach_sample(struct iio_buffer *buf,
994 ssize_t (*callback)(const struct iio_channel *chn,
995 void *src, size_t bytes, void *d), void *data);
996
997
Paul Cercueila2d4bad2014-05-27 10:15:29 +0200998/** @brief Associate a pointer to an iio_buffer structure
999 * @param buf A pointer to an iio_buffer structure
1000 * @param data The pointer to be associated */
1001__api void iio_buffer_set_data(struct iio_buffer *buf, void *data);
1002
1003
1004/** @brief Retrieve a previously associated pointer of an iio_buffer structure
1005 * @param buf A pointer to an iio_buffer structure
1006 * @return The pointer previously associated if present, or NULL */
1007__api void * iio_buffer_get_data(const struct iio_buffer *buf);
1008
1009
Paul Cercueil306cb1c2014-04-11 14:46:45 +02001010/** @} *//* ------------------------------------------------------------------*/
Paul Cercueilb4afdd92014-04-08 12:37:21 +02001011/* ------------------------- Low-level functions -----------------------------*/
Paul Cercueil306cb1c2014-04-11 14:46:45 +02001012/** @defgroup Debug Debug and low-level functions
1013 * @{
1014 * @struct iio_data_format
1015 * @brief Contains the format of a data sample.
1016 *
1017 * The different fields inform about the correct way to convert one sample from
1018 * its raw format (as read from / generated by the hardware) to its real-world
1019 * value.
1020 */
1021struct iio_data_format {
1022 /** @brief Total length of the sample, in bits */
1023 unsigned int length;
Paul Cercueilb4afdd92014-04-08 12:37:21 +02001024
Paul Cercueil306cb1c2014-04-11 14:46:45 +02001025 /** @brief Length of valuable data in the sample, in bits */
1026 unsigned int bits;
1027
1028 /** @brief Right-shift to apply when converting sample */
1029 unsigned int shift;
1030
1031 /** @brief Contains True if the sample is signed */
1032 bool is_signed;
1033
Michael Hennerichfa3c6f62014-08-13 11:21:23 +02001034 /** @brief Contains True if the sample is fully defined, sign extended, etc. */
1035 bool is_fully_defined;
1036
Paul Cercueil306cb1c2014-04-11 14:46:45 +02001037 /** @brief Contains True if the sample is in big-endian format */
1038 bool is_be;
1039
1040 /** @brief Contains True if the sample should be scaled when converted */
1041 bool with_scale;
1042
1043 /** @brief Contains the scale to apply if with_scale is set */
1044 double scale;
1045};
1046
1047
Paul Cercueil306cb1c2014-04-11 14:46:45 +02001048/** @brief Get the current sample size
1049 * @param dev A pointer to an iio_device structure
1050 * @return On success, the sample size in bytes
1051 * @return On error, a negative errno code is returned
1052 *
1053 * <b>NOTE:</b> The sample size is not constant and will change when channels
1054 * get enabled or disabled. */
Paul Cercueil59f2aa32014-04-04 16:28:51 +02001055__api ssize_t iio_device_get_sample_size(const struct iio_device *dev);
Paul Cercueil1a474732014-03-17 11:38:34 +01001056
Paul Cercueil306cb1c2014-04-11 14:46:45 +02001057
1058/** @brief Get the index of the given channel
1059 * @param chn A pointer to an iio_channel structure
1060 * @return On success, the index of the specified channel
1061 * @return On error, a negative errno code is returned */
Paul Cercueil59f2aa32014-04-04 16:28:51 +02001062__api __pure long iio_channel_get_index(const struct iio_channel *chn);
Paul Cercueilb4afdd92014-04-08 12:37:21 +02001063
Paul Cercueil306cb1c2014-04-11 14:46:45 +02001064
1065/** @brief Get a pointer to a channel's data format structure
1066 * @param chn A pointer to an iio_channel structure
1067 * @return A pointer to the channel's iio_data_format structure */
Paul Cercueil59f2aa32014-04-04 16:28:51 +02001068__api __cnst const struct iio_data_format * iio_channel_get_data_format(
1069 const struct iio_channel *chn);
Paul Cercueil0b2ce712014-02-17 15:04:18 +01001070
Paul Cercueil306cb1c2014-04-11 14:46:45 +02001071
1072/** @brief Convert the sample from hardware format to host format
1073 * @param chn A pointer to an iio_channel structure
1074 * @param dst A pointer to the destination buffer where the converted sample
1075 * should be written
1076 * @param src A pointer to the source buffer containing the sample */
Paul Cercueil59f2aa32014-04-04 16:28:51 +02001077__api void iio_channel_convert(const struct iio_channel *chn,
Paul Cercueil2917ffb2014-03-21 15:47:12 +01001078 void *dst, const void *src);
1079
Paul Cercueil306cb1c2014-04-11 14:46:45 +02001080
1081/** @brief Convert the sample from host format to hardware format
1082 * @param chn A pointer to an iio_channel structure
1083 * @param dst A pointer to the destination buffer where the converted sample
1084 * should be written
1085 * @param src A pointer to the source buffer containing the sample */
Paul Cercueild840d4c2014-04-07 19:38:58 +02001086__api void iio_channel_convert_inverse(const struct iio_channel *chn,
1087 void *dst, const void *src);
1088
Paul Cercueil306cb1c2014-04-11 14:46:45 +02001089
Paul Cercueil1ce35ef2014-04-15 12:28:40 +02001090/** @brief Enumerate the debug attributes of the given device
1091 * @param dev A pointer to an iio_device structure
1092 * @return The number of debug attributes found */
1093__api __pure unsigned int iio_device_get_debug_attrs_count(
1094 const struct iio_device *dev);
1095
1096
1097/** @brief Get the debug attribute present at the given index
1098 * @param dev A pointer to an iio_device structure
1099 * @param index The index corresponding to the debug attribute
1100 * @return On success, a pointer to a static NULL-terminated string
1101 * @return If the index is invalid, NULL is returned */
1102__api __pure const char * iio_device_get_debug_attr(
1103 const struct iio_device *dev, unsigned int index);
1104
1105
Paul Cercueil001d2152014-06-03 15:24:44 +02001106/** @brief Try to find a debug attribute by its name
1107 * @param dev A pointer to an iio_device structure
1108 * @param name A NULL-terminated string corresponding to the name of the
1109 * debug attribute
1110 * @return On success, a pointer to a static NULL-terminated string
1111 * @return If the name does not correspond to any known debug attribute of the
1112 * given device, NULL is returned
1113 *
1114 * <b>NOTE:</b> This function is useful to detect the presence of a debug
1115 * attribute.
1116 * It can also be used to retrieve the name of a debug attribute as a pointer
1117 * to a static string from a dynamically allocated string. */
1118__api __pure const char * iio_device_find_debug_attr(
1119 const struct iio_device *dev, const char *name);
1120
1121
Paul Cercueil99b07cc2014-04-14 16:07:32 +02001122/** @brief Read the content of the given debug attribute
1123 * @param dev A pointer to an iio_device structure
1124 * @param attr A NULL-terminated string corresponding to the name of the
1125 * debug attribute
1126 * @param dst A pointer to the memory area where the NULL-terminated string
1127 * corresponding to the value read will be stored
1128 * @param len The available length of the memory area, in bytes
1129 * @return On success, the number of bytes written to the buffer
Paul Cercueil4ca6ddc2014-05-21 14:51:50 +02001130 * @return On error, a negative errno code is returned
1131 *
1132 * <b>NOTE:</b>By passing NULL as the "attr" argument to
1133 * iio_device_debug_attr_read, it is now possible to read all of the debug
1134 * attributes of a device.
1135 *
1136 * The buffer is filled with one block of data per debug attribute of the
1137 * device, by the order they appear in the iio_device structure.
1138 *
1139 * The first four bytes of one block correspond to a 32-bit signed value in
1140 * network order. If negative, it corresponds to the errno code that were
1141 * returned when reading the debug attribute; if positive, it corresponds
1142 * to the length of the data read. In that case, the rest of the block contains
1143 * the data. */
Paul Cercueil99b07cc2014-04-14 16:07:32 +02001144__api ssize_t iio_device_debug_attr_read(const struct iio_device *dev,
1145 const char *attr, char *dst, size_t len);
1146
1147
Paul Cercueil1b36a012014-06-05 14:39:31 +02001148/** @brief Read the content of all debug attributes
1149 * @param dev A pointer to an iio_device structure
1150 * @param cb A pointer to a callback function
1151 * @param data A pointer that will be passed to the callback function
1152 * @return On success, 0 is returned
1153 * @return On error, a negative errno code is returned
1154 *
1155 * <b>NOTE:</b> This function is especially useful when used with the network
1156 * backend, as all the debug attributes are read in one single command. */
1157__api int iio_device_debug_attr_read_all(struct iio_device *dev,
1158 int (*cb)(struct iio_device *dev, const char *attr,
1159 const char *value, size_t len, void *d),
1160 void *data);
1161
1162
Paul Cercueil99b07cc2014-04-14 16:07:32 +02001163/** @brief Set the value of the given debug attribute
1164 * @param dev A pointer to an iio_device structure
1165 * @param attr A NULL-terminated string corresponding to the name of the
1166 * debug attribute
1167 * @param src A NULL-terminated string to set the debug attribute to
1168 * @return On success, the number of bytes written
Paul Cercueil1da28122014-05-22 10:59:49 +02001169 * @return On error, a negative errno code is returned
1170 *
1171 * <b>NOTE:</b>By passing NULL as the "attr" argument to
1172 * iio_device_debug_attr_write, it is now possible to write all of the
1173 * debug attributes of a device.
1174 *
1175 * The buffer must contain one block of data per debug attribute of the device,
1176 * by the order they appear in the iio_device structure.
1177 *
1178 * The first four bytes of one block correspond to a 32-bit signed value in
1179 * network order. If negative, the debug attribute is not written; if positive,
1180 * it corresponds to the length of the data to write. In that case, the rest
1181 * of the block must contain the data. */
Paul Cercueil99b07cc2014-04-14 16:07:32 +02001182__api ssize_t iio_device_debug_attr_write(const struct iio_device *dev,
1183 const char *attr, const char *src);
1184
Paul Cercueile3960742014-04-15 16:00:50 +02001185
Paul Cercueilcecda352014-05-06 18:14:29 +02001186/** @brief Set the value of the given debug attribute
1187 * @param dev A pointer to an iio_device structure
1188 * @param attr A NULL-terminated string corresponding to the name of the
1189 * debug attribute
1190 * @param src A pointer to the data to be written
1191 * @param len The number of bytes that should be written
1192 * @return On success, the number of bytes written
1193 * @return On error, a negative errno code is returned */
1194__api ssize_t iio_device_debug_attr_write_raw(const struct iio_device *dev,
1195 const char *attr, const void *src, size_t len);
1196
1197
Paul Cercueil1b36a012014-06-05 14:39:31 +02001198/** @brief Set the values of all debug attributes
1199 * @param dev A pointer to an iio_device structure
1200 * @param cb A pointer to a callback function
1201 * @param data A pointer that will be passed to the callback function
1202 * @return On success, 0 is returned
1203 * @return On error, a negative errno code is returned
1204 *
1205 * <b>NOTE:</b> This function is especially useful when used with the network
1206 * backend, as all the debug attributes are written in one single command. */
1207__api int iio_device_debug_attr_write_all(struct iio_device *dev,
1208 ssize_t (*cb)(struct iio_device *dev,
1209 const char *attr, void *buf, size_t len, void *d),
1210 void *data);
1211
1212
Paul Cercueile3960742014-04-15 16:00:50 +02001213/** @brief Read the content of the given debug attribute
1214 * @param dev A pointer to an iio_device structure
1215 * @param attr A NULL-terminated string corresponding to the name of the
1216 * debug attribute
1217 * @param val A pointer to a bool variable where the value should be stored
1218 * @return On success, 0 is returned
1219 * @return On error, a negative errno code is returned */
1220__api int iio_device_debug_attr_read_bool(const struct iio_device *dev,
1221 const char *attr, bool *val);
1222
1223
1224/** @brief Read the content of the given debug attribute
1225 * @param dev A pointer to an iio_device structure
1226 * @param attr A NULL-terminated string corresponding to the name of the
1227 * debug attribute
1228 * @param val A pointer to a long long variable where the value should be stored
1229 * @return On success, 0 is returned
1230 * @return On error, a negative errno code is returned */
1231__api int iio_device_debug_attr_read_longlong(const struct iio_device *dev,
1232 const char *attr, long long *val);
1233
1234
1235/** @brief Read the content of the given debug attribute
1236 * @param dev A pointer to an iio_device structure
1237 * @param attr A NULL-terminated string corresponding to the name of the
1238 * debug attribute
1239 * @param val A pointer to a double variable where the value should be stored
1240 * @return On success, 0 is returned
1241 * @return On error, a negative errno code is returned */
1242__api int iio_device_debug_attr_read_double(const struct iio_device *dev,
1243 const char *attr, double *val);
1244
1245
1246/** @brief Set the value of the given debug attribute
1247 * @param dev A pointer to an iio_device structure
1248 * @param attr A NULL-terminated string corresponding to the name of the
1249 * debug attribute
1250 * @param val A bool value to set the debug attribute to
1251 * @return On success, 0 is returned
1252 * @return On error, a negative errno code is returned */
1253__api int iio_device_debug_attr_write_bool(const struct iio_device *dev,
1254 const char *attr, bool val);
1255
1256
1257/** @brief Set the value of the given debug attribute
1258 * @param dev A pointer to an iio_device structure
1259 * @param attr A NULL-terminated string corresponding to the name of the
1260 * debug attribute
1261 * @param val A long long value to set the debug attribute to
1262 * @return On success, 0 is returned
1263 * @return On error, a negative errno code is returned */
1264__api int iio_device_debug_attr_write_longlong(const struct iio_device *dev,
1265 const char *attr, long long val);
1266
1267
1268/** @brief Set the value of the given debug attribute
1269 * @param dev A pointer to an iio_device structure
1270 * @param attr A NULL-terminated string corresponding to the name of the
1271 * debug attribute
1272 * @param val A double value to set the debug attribute to
1273 * @return On success, 0 is returned
1274 * @return On error, a negative errno code is returned */
1275__api int iio_device_debug_attr_write_double(const struct iio_device *dev,
1276 const char *attr, double val);
1277
Paul Cercueil108e0aa2014-05-06 14:45:14 +02001278
1279/** @brief Identify the channel or debug attribute corresponding to a filename
1280 * @param dev A pointer to an iio_device structure
1281 * @param filename A NULL-terminated string corresponding to the filename
1282 * @param chn A pointer to a pointer of an iio_channel structure. The pointed
1283 * pointer will be set to the address of the iio_channel structure if the
1284 * filename correspond to the attribute of a channel, or NULL otherwise.
1285 * @param attr A pointer to a NULL-terminated string. The pointer
1286 * pointer will be set to point to the name of the attribute corresponding to
1287 * the filename.
1288 * @return On success, 0 is returned, and *chn and *attr are modified.
1289 * @return On error, a negative errno code is returned. *chn and *attr are not
1290 * modified. */
1291__api int iio_device_identify_filename(const struct iio_device *dev,
1292 const char *filename, struct iio_channel **chn,
1293 const char **attr);
1294
1295
Paul Cercueil14405872014-05-07 14:00:32 +02001296/** @brief Set the value of a hardware register
1297 * @param dev A pointer to an iio_device structure
1298 * @param address The address of the register
1299 * @param value The value to set the register to
1300 * @return On success, 0 is returned
1301 * @return On error, a negative errno code is returned */
1302__api int iio_device_reg_write(struct iio_device *dev,
1303 uint32_t address, uint32_t value);
1304
1305
1306/** @brief Get the value of a hardware register
1307 * @param dev A pointer to an iio_device structure
1308 * @param address The address of the register
1309 * @param value A pointer to the variable where the value will be written
1310 * @return On success, 0 is returned
1311 * @return On error, a negative errno code is returned */
1312__api int iio_device_reg_read(struct iio_device *dev,
1313 uint32_t address, uint32_t *value);
1314
1315
Paul Cercueil306cb1c2014-04-11 14:46:45 +02001316/** @} */
1317
Paul Cercueila167e0c2014-04-08 14:50:41 +02001318#ifdef __cplusplus
1319}
1320#endif
1321
Paul Cercueilddf35ec2016-02-25 15:36:58 +01001322#undef __api
1323
Paul Cercueil0b2ce712014-02-17 15:04:18 +01001324#endif /* __IIO_H__ */