blob: c37e0bca6b8d428ef0077653f623a33a2e2d005c [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
Paul Cercueile45f8762014-05-02 11:19:26 +020048#define _str(x) #x
49#define __str(x) _str(x)
50
Paul Cercueil59f2aa32014-04-04 16:28:51 +020051#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 Cercueile45f8762014-05-02 11:19:26 +020063#define LIBIIO_VERSION_MAJOR 0
64#define LIBIIO_VERSION_MINOR 1
65
66#define LIBIIO_VERSION \
67 __str(LIBIIO_VERSION_MAJOR) "." __str(LIBIIO_VERSION_MINOR)
68
Paul Cercueil0b2ce712014-02-17 15:04:18 +010069struct iio_context;
70struct iio_device;
71struct iio_channel;
Paul Cercueila689cd92014-03-20 16:37:25 +010072struct iio_buffer;
Paul Cercueil0b2ce712014-02-17 15:04:18 +010073
Paul Cercueilb4afdd92014-04-08 12:37:21 +020074
Paul Cercueil306cb1c2014-04-11 14:46:45 +020075/* ---------------------------------------------------------------------------*/
Paul Cercueilb4afdd92014-04-08 12:37:21 +020076/* ------------------------- Context functions -------------------------------*/
Paul Cercueil306cb1c2014-04-11 14:46:45 +020077/** @defgroup Context Context
78 * @{
79 * @struct iio_context
80 * @brief Contains the representation of an IIO context */
Paul Cercueilb4afdd92014-04-08 12:37:21 +020081
Paul Cercueil306cb1c2014-04-11 14:46:45 +020082
83/** @brief Create a context from local IIO devices (Linux only).
84 * @return On success, A pointer to an iio_context structure
85 * @return On failure, NULL is returned */
Paul Cercueil59f2aa32014-04-04 16:28:51 +020086__api struct iio_context * iio_create_local_context(void);
Paul Cercueilb4afdd92014-04-08 12:37:21 +020087
Paul Cercueil306cb1c2014-04-11 14:46:45 +020088
89/** @brief Create a context from a XML file
90 * @param xml_file Path to the XML file to open
91 * @return On success, A pointer to an iio_context structure
92 * @return On failure, NULL is returned
93 *
94 * <b>NOTE:</b> The format of the XML must comply to the one returned by
95 * iio_context_get_xml. */
Paul Cercueil59f2aa32014-04-04 16:28:51 +020096__api struct iio_context * iio_create_xml_context(const char *xml_file);
Paul Cercueil306cb1c2014-04-11 14:46:45 +020097
98
99/** @brief Create a context from XML data in memory
100 * @param xml Pointer to the XML data in memory
101 * @param len Length of the XML string in memory (excluding the final \0)
102 * @return On success, A pointer to an iio_context structure
103 * @return On failure, NULL is returned
104 *
105 * <b>NOTE:</b> The format of the XML must comply to the one returned by
106 * iio_context_get_xml */
Paul Cercueil59f2aa32014-04-04 16:28:51 +0200107__api struct iio_context * iio_create_xml_context_mem(
108 const char *xml, size_t len);
Paul Cercueilb4afdd92014-04-08 12:37:21 +0200109
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200110
111/** @brief Create a context from the network
112 * @param host Hostname, IPv4 or IPv6 address where the IIO Daemon is running
113 * @return On success, a pointer to an iio_context structure
114 * @return On failure, NULL is returned */
Paul Cercueil59f2aa32014-04-04 16:28:51 +0200115__api struct iio_context * iio_create_network_context(const char *host);
Paul Cercueilb4afdd92014-04-08 12:37:21 +0200116
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200117
118/** @brief Destroy the given context
119 * @param ctx A pointer to an iio_context structure
120 *
121 * <b>NOTE:</b> After that function, the iio_context pointer shall be invalid. */
Paul Cercueil59f2aa32014-04-04 16:28:51 +0200122__api void iio_context_destroy(struct iio_context *ctx);
Paul Cercueil0b2ce712014-02-17 15:04:18 +0100123
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200124
Paul Cercueile45f8762014-05-02 11:19:26 +0200125/** @brief Get the version of the backend in use
126 * @param ctx A pointer to an iio_context structure
127 * @param major A pointer to an unsigned integer
128 * @param minor A pointer to an unsigned integer
129 * @return On success, 0 is returned
130 * @return On error, a negative errno code is returned */
131__api int iio_context_get_version(const struct iio_context *ctx,
132 unsigned int *major, unsigned int *minor);
133
134
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200135/** @brief Obtain a XML representation of the given context
136 * @param ctx A pointer to an iio_context structure
137 * @return A pointer to a static NULL-terminated string */
Paul Cercueilb4afdd92014-04-08 12:37:21 +0200138__api __pure const char * iio_context_get_xml(const struct iio_context *ctx);
139
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200140
141/** @brief Get the name of the given context
142 * @param ctx A pointer to an iio_context structure
143 * @return A pointer to a static NULL-terminated string
144 *
145 * <b>NOTE:</b>The returned string will be <b><i>local</i></b>,
146 * <b><i>xml</i></b> or <b><i>network</i></b> when the context has been
147 * created with the local, xml and network backends respectively.*/
Paul Cercueil59f2aa32014-04-04 16:28:51 +0200148__api __pure const char * iio_context_get_name(const struct iio_context *ctx);
Paul Cercueilb4afdd92014-04-08 12:37:21 +0200149
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200150
151/** @brief Enumerate the devices found in the given context
152 * @param ctx A pointer to an iio_context structure
153 * @return The number of devices found */
Paul Cercueil59f2aa32014-04-04 16:28:51 +0200154__api __pure unsigned int iio_context_get_devices_count(
155 const struct iio_context *ctx);
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200156
157
158/** @brief Get the device present at the given index
159 * @param ctx A pointer to an iio_context structure
160 * @param index The index corresponding to the device
161 * @return On success, a pointer to an iio_device structure
162 * @return If the index is invalid, NULL is returned */
Paul Cercueil59f2aa32014-04-04 16:28:51 +0200163__api __pure struct iio_device * iio_context_get_device(
164 const struct iio_context *ctx, unsigned int index);
Paul Cercueilb4afdd92014-04-08 12:37:21 +0200165
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200166
167/** @brief Try to find a device structure by its name of ID
168 * @param ctx A pointer to an iio_context structure
169 * @param name A NULL-terminated string corresponding to the name or the ID of
170 * the device to search for
171 * @return On success, a pointer to an iio_device structure
172 * @return If the name or ID does not correspond to any known device, NULL is
173 * returned */
Paul Cercueil59f2aa32014-04-04 16:28:51 +0200174__api __pure struct iio_device * iio_context_find_device(
175 const struct iio_context *ctx, const char *name);
Paul Cercueil0b2ce712014-02-17 15:04:18 +0100176
Paul Cercueilb4afdd92014-04-08 12:37:21 +0200177
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200178/** @} *//* ------------------------------------------------------------------*/
Paul Cercueilb4afdd92014-04-08 12:37:21 +0200179/* ------------------------- Device functions --------------------------------*/
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200180/** @defgroup Device Device
181 * @{
182 * @struct iio_device
183 * @brief Represents a device in the IIO context */
Paul Cercueilb4afdd92014-04-08 12:37:21 +0200184
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200185
186/** @brief Retrieve the device ID (e.g. <b><i>iio:device0</i></b>)
187 * @param dev A pointer to an iio_device structure
188 * @return A pointer to a static NULL-terminated string */
Paul Cercueil59f2aa32014-04-04 16:28:51 +0200189__api __pure const char * iio_device_get_id(const struct iio_device *dev);
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200190
191
192/** @brief Retrieve the device name (e.g. <b><i>xadc</i></b>)
193 * @param dev A pointer to an iio_device structure
194 * @return A pointer to a static NULL-terminated string
195 *
196 * <b>NOTE:</b> if the device has no name, NULL is returned. */
Paul Cercueil59f2aa32014-04-04 16:28:51 +0200197__api __pure const char * iio_device_get_name(const struct iio_device *dev);
Paul Cercueilb4afdd92014-04-08 12:37:21 +0200198
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200199
200/** @brief Enumerate the channels of the given device
201 * @param dev A pointer to an iio_device structure
202 * @return The number of channels found */
Paul Cercueil59f2aa32014-04-04 16:28:51 +0200203__api __pure unsigned int iio_device_get_channels_count(
204 const struct iio_device *dev);
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200205
206
207/** @brief Enumerate the device-specific attributes of the given device
208 * @param dev A pointer to an iio_device structure
209 * @return The number of device-specific attributes found */
Paul Cercueil59f2aa32014-04-04 16:28:51 +0200210__api __pure unsigned int iio_device_get_attrs_count(
211 const struct iio_device *dev);
Paul Cercueilb4afdd92014-04-08 12:37:21 +0200212
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200213
214/** @brief Get the channel present at the given index
215 * @param dev A pointer to an iio_device structure
216 * @param index The index corresponding to the channel
217 * @return On success, a pointer to an iio_channel structure
218 * @return If the index is invalid, NULL is returned */
Paul Cercueilb4afdd92014-04-08 12:37:21 +0200219__api __pure struct iio_channel * iio_device_get_channel(
220 const struct iio_device *dev, unsigned int index);
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200221
222
223/** @brief Get the device-specific attribute present at the given index
224 * @param dev A pointer to an iio_device structure
225 * @param index The index corresponding to the attribute
226 * @return On success, a pointer to a static NULL-terminated string
227 * @return If the index is invalid, NULL is returned */
Paul Cercueil59f2aa32014-04-04 16:28:51 +0200228__api __pure const char * iio_device_get_attr(
229 const struct iio_device *dev, unsigned int index);
Paul Cercueilb4afdd92014-04-08 12:37:21 +0200230
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200231
232/** @brief Try to find a channel structure by its name of ID
233 * @param dev A pointer to an iio_device structure
234 * @param name A NULL-terminated string corresponding to the name or the ID of
235 * the channel to search for
236 * @param output True if the searched channel is output, False otherwise
237 * @return On success, a pointer to an iio_channel structure
238 * @return If the name or ID does not correspond to any known channel of the
239 * given device, NULL is returned */
Paul Cercueilb4afdd92014-04-08 12:37:21 +0200240__api __pure struct iio_channel * iio_device_find_channel(
241 const struct iio_device *dev, const char *name, bool output);
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200242
243
244/** @brief Try to find a device-specific attribute by its name
245 * @param dev A pointer to an iio_device structure
Paul Cercueil30606d52014-04-14 16:04:15 +0200246 * @param name A NULL-terminated string corresponding to the name of the
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200247 * attribute
248 * @return On success, a pointer to a static NULL-terminated string
249 * @return If the name does not correspond to any known attribute of the given
250 * device, NULL is returned
251 *
252 * <b>NOTE:</b> This function is useful to detect the presence of an attribute.
253 * It can also be used to retrieve the name of an attribute as a pointer to a
254 * static string from a dynamically allocated string. */
Paul Cercueil59f2aa32014-04-04 16:28:51 +0200255__api __pure const char * iio_device_find_attr(
256 const struct iio_device *dev, const char *name);
Paul Cercueilb4afdd92014-04-08 12:37:21 +0200257
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200258
259/** @brief Read the content of the given device-specific attribute
260 * @param dev A pointer to an iio_device structure
Paul Cercueil30606d52014-04-14 16:04:15 +0200261 * @param attr A NULL-terminated string corresponding to the name of the
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200262 * attribute
263 * @param dst A pointer to the memory area where the NULL-terminated string
264 * corresponding to the value read will be stored
265 * @param len The available length of the memory area, in bytes
266 * @return On success, the number of bytes written to the buffer
267 * @return On error, a negative errno code is returned */
Paul Cercueilb4afdd92014-04-08 12:37:21 +0200268__api ssize_t iio_device_attr_read(const struct iio_device *dev,
269 const char *attr, char *dst, size_t len);
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200270
271
272/** @brief Read the content of the given device-specific attribute
273 * @param dev A pointer to an iio_device structure
Paul Cercueil30606d52014-04-14 16:04:15 +0200274 * @param attr A NULL-terminated string corresponding to the name of the
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200275 * attribute
276 * @param val A pointer to a bool variable where the value should be stored
277 * @return On success, 0 is returned
278 * @return On error, a negative errno code is returned */
Paul Cercueilb4afdd92014-04-08 12:37:21 +0200279__api int iio_device_attr_read_bool(const struct iio_device *dev,
280 const char *attr, bool *val);
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200281
282
283/** @brief Read the content of the given device-specific attribute
284 * @param dev A pointer to an iio_device structure
Paul Cercueil30606d52014-04-14 16:04:15 +0200285 * @param attr A NULL-terminated string corresponding to the name of the
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200286 * attribute
287 * @param val A pointer to a long long variable where the value should be stored
288 * @return On success, 0 is returned
289 * @return On error, a negative errno code is returned */
Paul Cercueilb4afdd92014-04-08 12:37:21 +0200290__api int iio_device_attr_read_longlong(const struct iio_device *dev,
291 const char *attr, long long *val);
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200292
293
294/** @brief Read the content of the given device-specific attribute
295 * @param dev A pointer to an iio_device structure
Paul Cercueil30606d52014-04-14 16:04:15 +0200296 * @param attr A NULL-terminated string corresponding to the name of the
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200297 * attribute
298 * @param val A pointer to a double variable where the value should be stored
299 * @return On success, 0 is returned
300 * @return On error, a negative errno code is returned */
Paul Cercueilb4afdd92014-04-08 12:37:21 +0200301__api int iio_device_attr_read_double(const struct iio_device *dev,
302 const char *attr, double *val);
303
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200304
305/** @brief Set the value of the given device-specific attribute
306 * @param dev A pointer to an iio_device structure
Paul Cercueil30606d52014-04-14 16:04:15 +0200307 * @param attr A NULL-terminated string corresponding to the name of the
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200308 * attribute
309 * @param src A NULL-terminated string to set the attribute to
310 * @return On success, the number of bytes written
311 * @return On error, a negative errno code is returned */
Paul Cercueilb4afdd92014-04-08 12:37:21 +0200312__api ssize_t iio_device_attr_write(const struct iio_device *dev,
313 const char *attr, const char *src);
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200314
315
316/** @brief Set the value of the given device-specific attribute
317 * @param dev A pointer to an iio_device structure
Paul Cercueil30606d52014-04-14 16:04:15 +0200318 * @param attr A NULL-terminated string corresponding to the name of the
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200319 * attribute
Paul Cercueilcecda352014-05-06 18:14:29 +0200320 * @param src A pointer to the data to be written
321 * @param len The number of bytes that should be written
322 * @return On success, the number of bytes written
323 * @return On error, a negative errno code is returned */
324__api ssize_t iio_device_attr_write_raw(const struct iio_device *dev,
325 const char *attr, const void *src, size_t len);
326
327
328/** @brief Set the value of the given device-specific attribute
329 * @param dev A pointer to an iio_device structure
330 * @param attr A NULL-terminated string corresponding to the name of the
331 * attribute
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200332 * @param val A bool value to set the attribute to
333 * @return On success, 0 is returned
334 * @return On error, a negative errno code is returned */
Paul Cercueilb4afdd92014-04-08 12:37:21 +0200335__api int iio_device_attr_write_bool(const struct iio_device *dev,
336 const char *attr, bool val);
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200337
338
339/** @brief Set the value of the given device-specific attribute
340 * @param dev A pointer to an iio_device structure
Paul Cercueil30606d52014-04-14 16:04:15 +0200341 * @param attr A NULL-terminated string corresponding to the name of the
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200342 * attribute
343 * @param val A long long value to set the attribute to
344 * @return On success, 0 is returned
345 * @return On error, a negative errno code is returned */
Paul Cercueilb4afdd92014-04-08 12:37:21 +0200346__api int iio_device_attr_write_longlong(const struct iio_device *dev,
347 const char *attr, long long val);
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200348
349
350/** @brief Set the value of the given device-specific attribute
351 * @param dev A pointer to an iio_device structure
Paul Cercueil30606d52014-04-14 16:04:15 +0200352 * @param attr A NULL-terminated string corresponding to the name of the
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200353 * attribute
354 * @param val A double value to set the attribute to
355 * @return On success, 0 is returned
356 * @return On error, a negative errno code is returned */
Paul Cercueilb4afdd92014-04-08 12:37:21 +0200357__api int iio_device_attr_write_double(const struct iio_device *dev,
358 const char *attr, double val);
359
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200360
361/** @brief Associate a pointer to an iio_device structure
362 * @param dev A pointer to an iio_device structure
363 * @param data The pointer to be associated */
Paul Cercueilb4afdd92014-04-08 12:37:21 +0200364__api void iio_device_set_data(struct iio_device *dev, void *data);
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200365
366
367/** @brief Retrieve a previously associated pointer of an iio_device structure
368 * @param dev A pointer to an iio_device structure
369 * @return The pointer previously associated if present, or NULL */
Paul Cercueilb4afdd92014-04-08 12:37:21 +0200370__api void * iio_device_get_data(const struct iio_device *dev);
371
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200372
373/** @brief Retrieve the trigger of a given device
374 * @param dev A pointer to an iio_device structure
375 * @param trigger a pointer to a pointer of an iio_device structure. The pointed
376 * pointer will be set to the address of the iio_device structure corresponding
377 * to the associated trigger device.
378 * @return On success, 0 is returned
379 * @return On error, a negative errno code is returned */
Paul Cercueil59f2aa32014-04-04 16:28:51 +0200380__api int iio_device_get_trigger(const struct iio_device *dev,
Paul Cercueil24ffa532014-03-10 12:39:58 +0100381 const struct iio_device **trigger);
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200382
383
384/** @brief Associate a trigger to a given device
385 * @param dev A pointer to an iio_device structure
386 * @param trigger a pointer to the iio_device structure corresponding to the
387 * trigger that should be associated.
388 * @return On success, 0 is returned
389 * @return On error, a negative errno code is returned */
Paul Cercueil59f2aa32014-04-04 16:28:51 +0200390__api int iio_device_set_trigger(const struct iio_device *dev,
Paul Cercueil24ffa532014-03-10 12:39:58 +0100391 const struct iio_device *trigger);
Paul Cercueil0b2ce712014-02-17 15:04:18 +0100392
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200393
394/** @brief Return True if the given device is a trigger
395 * @param dev A pointer to an iio_device structure
396 * @return True if the device is a trigger, False otherwise */
Paul Cercueilb4afdd92014-04-08 12:37:21 +0200397__api __pure bool iio_device_is_trigger(const struct iio_device *dev);
398
Paul Cercueilb4afdd92014-04-08 12:37:21 +0200399
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200400/** @} *//* ------------------------------------------------------------------*/
Paul Cercueilb4afdd92014-04-08 12:37:21 +0200401/* ------------------------- Channel functions -------------------------------*/
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200402/** @defgroup Channel Channel
403 * @{
404 * @struct iio_channel
405 * @brief Represents an input or output channel of a device */
Paul Cercueilb4afdd92014-04-08 12:37:21 +0200406
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200407
408/** @brief Retrieve the channel ID (e.g. <b><i>voltage0</i></b>)
409 * @param chn A pointer to an iio_channel structure
410 * @return A pointer to a static NULL-terminated string */
Paul Cercueilb4afdd92014-04-08 12:37:21 +0200411__api __pure const char * iio_channel_get_id(const struct iio_channel *chn);
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200412
413
414/** @brief Retrieve the channel name (e.g. <b><i>vccint</i></b>)
415 * @param chn A pointer to an iio_channel structure
416 * @return A pointer to a static NULL-terminated string
417 *
418 * <b>NOTE:</b> if the channel has no name, NULL is returned. */
Paul Cercueilb4afdd92014-04-08 12:37:21 +0200419__api __pure const char * iio_channel_get_name(const struct iio_channel *chn);
420
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200421
422/** @brief Return True if the given channel is an output channel
423 * @param chn A pointer to an iio_channel structure
424 * @return True if the channel is an output channel, False otherwise */
Paul Cercueilb4afdd92014-04-08 12:37:21 +0200425__api __pure bool iio_channel_is_output(const struct iio_channel *chn);
426
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200427
Paul Cercueil85aaf482014-04-24 16:39:09 +0200428/** @brief Return True if the given channel is a scan element
429 * @param chn A pointer to an iio_channel structure
430 * @return True if the channel is a scan element, False otherwise
431 *
432 * <b>NOTE:</b> a channel that is a scan element is a channel that can
433 * generate samples (for an input channel) or receive samples (for an output
434 * channel) after being enabled. */
435__api __pure bool iio_channel_is_scan_element(const struct iio_channel *chn);
436
437
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200438/** @brief Enumerate the channel-specific attributes of the given channel
439 * @param chn A pointer to an iio_channel structure
440 * @return The number of channel-specific attributes found */
Paul Cercueilb4afdd92014-04-08 12:37:21 +0200441__api __pure unsigned int iio_channel_get_attrs_count(
442 const struct iio_channel *chn);
443
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200444
445/** @brief Get the channel-specific attribute present at the given index
446 * @param chn A pointer to an iio_channel structure
447 * @param index The index corresponding to the attribute
448 * @return On success, a pointer to a static NULL-terminated string
449 * @return If the index is invalid, NULL is returned */
Paul Cercueilb4afdd92014-04-08 12:37:21 +0200450__api __pure const char * iio_channel_get_attr(
451 const struct iio_channel *chn, unsigned int index);
452
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200453
454/** @brief Try to find a channel-specific attribute by its name
455 * @param chn A pointer to an iio_channel structure
Paul Cercueil30606d52014-04-14 16:04:15 +0200456 * @param name A NULL-terminated string corresponding to the name of the
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200457 * attribute
458 * @return On success, a pointer to a static NULL-terminated string
459 * @return If the name does not correspond to any known attribute of the given
460 * channel, NULL is returned
461 *
462 * <b>NOTE:</b> This function is useful to detect the presence of an attribute.
463 * It can also be used to retrieve the name of an attribute as a pointer to a
464 * static string from a dynamically allocated string. */
Paul Cercueilb4afdd92014-04-08 12:37:21 +0200465__api __pure const char * iio_channel_find_attr(
466 const struct iio_channel *chn, const char *name);
467
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200468
Paul Cercueil6f8dbd42014-05-05 17:05:59 +0200469/** @brief Retrieve the filename of an attribute
470 * @param chn A pointer to an iio_channel structure
471 * @param attr a NULL-terminated string corresponding to the name of the
472 * attribute
473 * @return On success, a pointer to a static NULL-terminated string
474 * @return If the attribute name is unknown, NULL is returned */
475__api __pure const char * iio_channel_attr_get_filename(
476 const struct iio_channel *chn, const char *attr);
477
478
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200479/** @brief Read the content of the given channel-specific attribute
480 * @param chn A pointer to an iio_channel structure
Paul Cercueil30606d52014-04-14 16:04:15 +0200481 * @param attr A NULL-terminated string corresponding to the name of the
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200482 * attribute
483 * @param dst A pointer to the memory area where the NULL-terminated string
484 * corresponding to the value read will be stored
485 * @param len The available length of the memory area, in bytes
486 * @return On success, the number of bytes written to the buffer
487 * @return On error, a negative errno code is returned */
Paul Cercueilb4afdd92014-04-08 12:37:21 +0200488__api ssize_t iio_channel_attr_read(const struct iio_channel *chn,
489 const char *attr, char *dst, size_t len);
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200490
491
492/** @brief Read the content of the given channel-specific attribute
493 * @param chn A pointer to an iio_channel structure
Paul Cercueil30606d52014-04-14 16:04:15 +0200494 * @param attr A NULL-terminated string corresponding to the name of the
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200495 * attribute
496 * @param val A pointer to a bool variable where the value should be stored
497 * @return On success, 0 is returned
498 * @return On error, a negative errno code is returned */
Paul Cercueilb4afdd92014-04-08 12:37:21 +0200499__api int iio_channel_attr_read_bool(const struct iio_channel *chn,
500 const char *attr, bool *val);
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200501
502
503/** @brief Read the content of the given channel-specific attribute
504 * @param chn A pointer to an iio_channel structure
Paul Cercueil30606d52014-04-14 16:04:15 +0200505 * @param attr A NULL-terminated string corresponding to the name of the
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200506 * attribute
507 * @param val A pointer to a long long variable where the value should be stored
508 * @return On success, 0 is returned
509 * @return On error, a negative errno code is returned */
Paul Cercueilb4afdd92014-04-08 12:37:21 +0200510__api int iio_channel_attr_read_longlong(const struct iio_channel *chn,
511 const char *attr, long long *val);
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200512
513
514/** @brief Read the content of the given channel-specific attribute
515 * @param chn A pointer to an iio_channel structure
Paul Cercueil30606d52014-04-14 16:04:15 +0200516 * @param attr A NULL-terminated string corresponding to the name of the
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200517 * attribute
518 * @param val A pointer to a double variable where the value should be stored
519 * @return On success, 0 is returned
520 * @return On error, a negative errno code is returned */
Paul Cercueilb4afdd92014-04-08 12:37:21 +0200521__api int iio_channel_attr_read_double(const struct iio_channel *chn,
522 const char *attr, double *val);
523
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200524
525/** @brief Set the value of the given channel-specific attribute
526 * @param chn A pointer to an iio_channel structure
Paul Cercueil30606d52014-04-14 16:04:15 +0200527 * @param attr A NULL-terminated string corresponding to the name of the
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200528 * attribute
529 * @param src A NULL-terminated string to set the attribute to
530 * @return On success, the number of bytes written
531 * @return On error, a negative errno code is returned */
Paul Cercueilb4afdd92014-04-08 12:37:21 +0200532__api ssize_t iio_channel_attr_write(const struct iio_channel *chn,
533 const char *attr, const char *src);
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200534
535
536/** @brief Set the value of the given channel-specific attribute
537 * @param chn A pointer to an iio_channel structure
Paul Cercueil30606d52014-04-14 16:04:15 +0200538 * @param attr A NULL-terminated string corresponding to the name of the
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200539 * attribute
Paul Cercueilcecda352014-05-06 18:14:29 +0200540 * @param src A pointer to the data to be written
541 * @param len The number of bytes that should be written
542 * @return On success, the number of bytes written
543 * @return On error, a negative errno code is returned */
544__api ssize_t iio_channel_attr_write_raw(const struct iio_channel *chn,
545 const char *attr, const void *src, size_t len);
546
547
548/** @brief Set the value of the given channel-specific attribute
549 * @param chn A pointer to an iio_channel structure
550 * @param attr A NULL-terminated string corresponding to the name of the
551 * attribute
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200552 * @param val A bool value to set the attribute to
553 * @return On success, 0 is returned
554 * @return On error, a negative errno code is returned */
Paul Cercueilb4afdd92014-04-08 12:37:21 +0200555__api int iio_channel_attr_write_bool(const struct iio_channel *chn,
556 const char *attr, bool val);
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200557
558
559/** @brief Set the value of the given channel-specific attribute
560 * @param chn A pointer to an iio_channel structure
Paul Cercueil30606d52014-04-14 16:04:15 +0200561 * @param attr A NULL-terminated string corresponding to the name of the
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200562 * attribute
563 * @param val A long long value to set the attribute to
564 * @return On success, 0 is returned
565 * @return On error, a negative errno code is returned */
Paul Cercueilb4afdd92014-04-08 12:37:21 +0200566__api int iio_channel_attr_write_longlong(const struct iio_channel *chn,
567 const char *attr, long long val);
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200568
569
570/** @brief Set the value of the given channel-specific attribute
571 * @param chn A pointer to an iio_channel structure
Paul Cercueil30606d52014-04-14 16:04:15 +0200572 * @param attr A NULL-terminated string corresponding to the name of the
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200573 * attribute
574 * @param val A double value to set the attribute to
575 * @return On success, 0 is returned
576 * @return On error, a negative errno code is returned */
Paul Cercueilb4afdd92014-04-08 12:37:21 +0200577__api int iio_channel_attr_write_double(const struct iio_channel *chn,
578 const char *attr, double val);
579
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200580
581/** @brief Enable the given channel
582 * @param chn A pointer to an iio_channel structure
583 *
584 * <b>NOTE:</b>Before creating an iio_buffer structure with
585 * iio_device_create_buffer, it is required to enable at least one channel of
586 * the device to read from. */
Paul Cercueilb4afdd92014-04-08 12:37:21 +0200587__api void iio_channel_enable(struct iio_channel *chn);
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200588
589
590/** @brief Disable the given channel
591 * @param chn A pointer to an iio_channel structure */
Paul Cercueilb4afdd92014-04-08 12:37:21 +0200592__api void iio_channel_disable(struct iio_channel *chn);
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200593
594
595/** @brief Returns True if the channel is enabled
596 * @param chn A pointer to an iio_channel structure
597 * @return True if the channel is enabled, False otherwise */
Paul Cercueilb4afdd92014-04-08 12:37:21 +0200598__api bool iio_channel_is_enabled(const struct iio_channel *chn);
599
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200600
601/** Demultiplex the samples of a given channel
602 * @param chn A pointer to an iio_channel structure
603 * @param buffer A pointer to an iio_buffer structure
604 * @param dst A pointer to the memory area where the demultiplexed data will be
605 * stored
606 * @param len The available length of the memory area, in bytes
607 * @return The size of the demultiplexed data, in bytes */
Paul Cercueilb4afdd92014-04-08 12:37:21 +0200608__api size_t iio_channel_read_raw(const struct iio_channel *chn,
609 struct iio_buffer *buffer, void *dst, size_t len);
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200610
611
612/** Demultiplex and convert the samples of a given channel
613 * @param chn A pointer to an iio_channel structure
614 * @param buffer A pointer to an iio_buffer structure
615 * @param dst A pointer to the memory area where the converted data will be
616 * stored
617 * @param len The available length of the memory area, in bytes
618 * @return The size of the converted data, in bytes */
Paul Cercueilb4afdd92014-04-08 12:37:21 +0200619__api size_t iio_channel_read(const struct iio_channel *chn,
620 struct iio_buffer *buffer, void *dst, size_t len);
621
622
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200623/** Multiplex the samples of a given channel
624 * @param chn A pointer to an iio_channel structure
625 * @param buffer A pointer to an iio_buffer structure
626 * @param src A pointer to the memory area where the sequential data will
627 * be read from
628 * @param len The length of the memory area, in bytes
629 * @return The number of bytes actually multiplexed */
Paul Cercueilb4afdd92014-04-08 12:37:21 +0200630__api size_t iio_channel_write_raw(const struct iio_channel *chn,
631 struct iio_buffer *buffer, const void *src, size_t len);
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200632
633
634/** Convert and multiplex the samples of a given channel
635 * @param chn A pointer to an iio_channel structure
636 * @param buffer A pointer to an iio_buffer structure
637 * @param src A pointer to the memory area where the sequential data will
638 * be read from
639 * @param len The length of the memory area, in bytes
640 * @return The number of bytes actually converted and multiplexed */
Paul Cercueilb4afdd92014-04-08 12:37:21 +0200641__api size_t iio_channel_write(const struct iio_channel *chn,
642 struct iio_buffer *buffer, const void *src, size_t len);
643
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200644
645/** @brief Associate a pointer to an iio_channel structure
646 * @param chn A pointer to an iio_channel structure
647 * @param data The pointer to be associated */
Paul Cercueilb4afdd92014-04-08 12:37:21 +0200648__api void iio_channel_set_data(struct iio_channel *chn, void *data);
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200649
650
651/** @brief Retrieve a previously associated pointer of an iio_channel structure
652 * @param chn A pointer to an iio_channel structure
653 * @return The pointer previously associated if present, or NULL */
Paul Cercueilb4afdd92014-04-08 12:37:21 +0200654__api void * iio_channel_get_data(const struct iio_channel *chn);
655
656
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200657/** @} *//* ------------------------------------------------------------------*/
Paul Cercueilb4afdd92014-04-08 12:37:21 +0200658/* ------------------------- Buffer functions --------------------------------*/
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200659/** @defgroup Buffer Buffer
660 * @{
661 * @struct iio_buffer
662 * @brief An input or output buffer, used to read or write samples */
Paul Cercueilb4afdd92014-04-08 12:37:21 +0200663
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200664
665/** @brief Create an input or output buffer associated to the given device
666 * @param dev A pointer to an iio_device structure
667 * @param samples_count The number of samples that the buffer should contain
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200668 * @return On success, a pointer to an iio_buffer structure
Paul Cercueil3106e892014-04-30 11:29:51 +0200669 * @return On error, NULL is returned, and errno is set to the error code
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200670 *
671 * <b>NOTE:</b> Channels that have to be written to / read from must be enabled
Paul Cercueilb4afdd92014-04-08 12:37:21 +0200672 * before creating the buffer. */
673__api struct iio_buffer * iio_device_create_buffer(const struct iio_device *dev,
Paul Cercueileb4fb3d2014-04-25 11:33:01 +0200674 size_t samples_count);
Paul Cercueilb4afdd92014-04-08 12:37:21 +0200675
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200676
677/** @brief Destroy the given buffer
678 * @param buf A pointer to an iio_buffer structure
679 *
680 * <b>NOTE:</b> After that function, the iio_buffer pointer shall be invalid. */
Paul Cercueilb4afdd92014-04-08 12:37:21 +0200681__api void iio_buffer_destroy(struct iio_buffer *buf);
682
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200683
684/** @brief Fetch more samples from the hardware
685 * @param buf A pointer to an iio_buffer structure
686 * @return On success, the number of bytes read is returned
687 * @return On error, a negative errno code is returned
688 *
689 * <b>NOTE:</b> Only valid for input buffers */
Paul Cercueilb4afdd92014-04-08 12:37:21 +0200690__api ssize_t iio_buffer_refill(struct iio_buffer *buf);
691
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200692
693/** @brief Send the samples to the hardware
694 * @param buf A pointer to an iio_buffer structure
695 * @return On success, the number of bytes written is returned
696 * @return On error, a negative errno code is returned
697 *
698 * <b>NOTE:</b> Only valid for output buffers */
Paul Cercueilea32b042014-04-11 13:47:12 +0200699__api ssize_t iio_buffer_push(const struct iio_buffer *buf);
Paul Cercueilb4afdd92014-04-08 12:37:21 +0200700
Paul Cercueilb4afdd92014-04-08 12:37:21 +0200701
Paul Cercueil6d927162014-04-16 15:53:22 +0200702/** @brief Get the start address of the buffer
703 * @param buf A pointer to an iio_buffer structure
704 * @return A pointer corresponding to the start address of the buffer */
705__api __pure void * iio_buffer_start(const struct iio_buffer *buf);
706
707
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200708/** @brief Find the first sample of a channel in a buffer
709 * @param buf A pointer to an iio_buffer structure
710 * @param chn A pointer to an iio_channel structure
711 * @return A pointer to the first sample found, or to the end of the buffer if
712 * no sample for the given channel is present in the buffer
713 *
714 * <b>NOTE:</b> This fonction, coupled with iio_buffer_step and iio_buffer_end,
715 * can be used to iterate on all the samples of a given channel present in the
716 * buffer, doing the following:
717 *
718 * @verbatim
719 for (void *ptr = iio_buffer_first(buffer, chn); ptr < iio_buffer_end(buffer); ptr += iio_buffer_step(buffer)) {
720 ....
721 }
722 @endverbatim */
723__api void * iio_buffer_first(const struct iio_buffer *buf,
724 const struct iio_channel *chn);
725
726
727/** @brief Get the step size between two samples of one channel
728 * @param buf A pointer to an iio_buffer structure
729 * @return the difference between the addresses of two consecutive samples of
730 * one same channel */
731__api ptrdiff_t iio_buffer_step(const struct iio_buffer *buf);
732
733
734/** @brief Get the address that follows the last sample in a buffer
735 * @param buf A pointer to an iio_buffer structure
736 * @return A pointer corresponding to the address that follows the last sample
737 * present in the buffer */
738__api void * iio_buffer_end(const struct iio_buffer *buf);
739
740
741/** @brief Call the supplied callback for each sample found in a buffer
742 * @param buf A pointer to an iio_buffer structure
743 * @param callback A pointer to a function to call for each sample found
744 * @param data A user-specified pointer that will be passed to the callback
745 *
746 * <b>NOTE:</b> The callback receives four arguments:
747 * * A pointer to the iio_channel structure corresponding to the sample,
748 * * A pointer to the sample itself,
749 * * The length of the sample in bytes,
750 * * The user-specified pointer passed to iio_buffer_foreach_sample. */
Paul Cercueilb4afdd92014-04-08 12:37:21 +0200751__api ssize_t iio_buffer_foreach_sample(struct iio_buffer *buf,
752 ssize_t (*callback)(const struct iio_channel *chn,
753 void *src, size_t bytes, void *d), void *data);
754
755
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200756/** @} *//* ------------------------------------------------------------------*/
Paul Cercueilb4afdd92014-04-08 12:37:21 +0200757/* ------------------------- Low-level functions -----------------------------*/
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200758/** @defgroup Debug Debug and low-level functions
759 * @{
760 * @struct iio_data_format
761 * @brief Contains the format of a data sample.
762 *
763 * The different fields inform about the correct way to convert one sample from
764 * its raw format (as read from / generated by the hardware) to its real-world
765 * value.
766 */
767struct iio_data_format {
768 /** @brief Total length of the sample, in bits */
769 unsigned int length;
Paul Cercueilb4afdd92014-04-08 12:37:21 +0200770
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200771 /** @brief Length of valuable data in the sample, in bits */
772 unsigned int bits;
773
774 /** @brief Right-shift to apply when converting sample */
775 unsigned int shift;
776
777 /** @brief Contains True if the sample is signed */
778 bool is_signed;
779
780 /** @brief Contains True if the sample is in big-endian format */
781 bool is_be;
782
783 /** @brief Contains True if the sample should be scaled when converted */
784 bool with_scale;
785
786 /** @brief Contains the scale to apply if with_scale is set */
787 double scale;
788};
789
790
791/** @brief Open the given device
792 * @param dev A pointer to an iio_device structure
793 * @param samples_count The size of the kernel buffer, in samples
794 * @return On success, 0 is returned
795 * @return On error, a negative errno code is returned
796 *
797 * <b>NOTE:</b> This is not required when using the iio_buffer functions; it is
798 * only useful when used with iio_device_read_raw / iio_device_write_raw. */
Paul Cercueil59f2aa32014-04-04 16:28:51 +0200799__api int iio_device_open(const struct iio_device *dev, size_t samples_count);
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200800
801
802/** @brief Close the given device
803 * @param dev A pointer to an iio_device structure
804 * @return On success, 0 is returned
805 * @return On error, a negative errno code is returned
806 *
807 * <b>NOTE:</b> This is not required when using the iio_buffer functions; it is
808 * only useful when used with iio_device_read_raw / iio_device_write_raw. */
Paul Cercueil59f2aa32014-04-04 16:28:51 +0200809__api int iio_device_close(const struct iio_device *dev);
Paul Cercueilec1760d2014-02-21 11:31:20 +0100810
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200811
812/** @brief Get the current sample size
813 * @param dev A pointer to an iio_device structure
814 * @return On success, the sample size in bytes
815 * @return On error, a negative errno code is returned
816 *
817 * <b>NOTE:</b> The sample size is not constant and will change when channels
818 * get enabled or disabled. */
Paul Cercueil59f2aa32014-04-04 16:28:51 +0200819__api ssize_t iio_device_get_sample_size(const struct iio_device *dev);
Paul Cercueil1a474732014-03-17 11:38:34 +0100820
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200821
822/** @brief Get the index of the given channel
823 * @param chn A pointer to an iio_channel structure
824 * @return On success, the index of the specified channel
825 * @return On error, a negative errno code is returned */
Paul Cercueil59f2aa32014-04-04 16:28:51 +0200826__api __pure long iio_channel_get_index(const struct iio_channel *chn);
Paul Cercueilb4afdd92014-04-08 12:37:21 +0200827
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200828
829/** @brief Get a pointer to a channel's data format structure
830 * @param chn A pointer to an iio_channel structure
831 * @return A pointer to the channel's iio_data_format structure */
Paul Cercueil59f2aa32014-04-04 16:28:51 +0200832__api __cnst const struct iio_data_format * iio_channel_get_data_format(
833 const struct iio_channel *chn);
Paul Cercueil0b2ce712014-02-17 15:04:18 +0100834
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200835
836/** @brief Convert the sample from hardware format to host format
837 * @param chn A pointer to an iio_channel structure
838 * @param dst A pointer to the destination buffer where the converted sample
839 * should be written
840 * @param src A pointer to the source buffer containing the sample */
Paul Cercueil59f2aa32014-04-04 16:28:51 +0200841__api void iio_channel_convert(const struct iio_channel *chn,
Paul Cercueil2917ffb2014-03-21 15:47:12 +0100842 void *dst, const void *src);
843
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200844
845/** @brief Convert the sample from host format to hardware format
846 * @param chn A pointer to an iio_channel structure
847 * @param dst A pointer to the destination buffer where the converted sample
848 * should be written
849 * @param src A pointer to the source buffer containing the sample */
Paul Cercueild840d4c2014-04-07 19:38:58 +0200850__api void iio_channel_convert_inverse(const struct iio_channel *chn,
851 void *dst, const void *src);
852
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200853
854/** @brief Read the raw stream from the given device
855 * @param dev A pointer to an iio_device structure
856 * @param dst A pointer to the destination buffer where to write the stream
857 * @param len The length of the destination buffer, in bytes
858 * @param mask A pointer to a memory area where the channel mask will be stored
859 * @param words The number of 32-bit words composing the mask
860 * @return On success, the number of bytes read
861 * @return On error, a negative errno code is returned
862 *
863 * <b>NOTE:</b> The device must be opened first (with iio_device_open).
864 *
865 * The "words" param should correspond to (number of channels + 31) / 32.
866 * The area pointed by "mask" will be initialized like this:
867 * @verbatim
868 mask[chn.index / 32][chn.index % 32] = is_enabled
869 @endverbatim
870 * Note that the mask can change anytime between two calls, even if no channel
871 * of the specified device have been enabled or disabled in the meantime. */
Paul Cercueil59f2aa32014-04-04 16:28:51 +0200872__api ssize_t iio_device_read_raw(const struct iio_device *dev,
Paul Cercueil45c575d2014-03-20 15:14:01 +0100873 void *dst, size_t len, uint32_t *mask, size_t words);
Paul Cercueil306cb1c2014-04-11 14:46:45 +0200874
875
876/** @brief Write a raw stream to the given device
877 * @param dev A pointer to an iio_device structure
878 * @param src A pointer to the source buffer where to read the stream from
879 * @param len The length of the input buffer, in bytes
880 * @return On success, the number of bytes written
881 * @return On error, a negative errno code is returned
882 *
883 * <b>NOTE:</b> The device must be opened first (with iio_device_open). */
Paul Cercueil59f2aa32014-04-04 16:28:51 +0200884__api ssize_t iio_device_write_raw(const struct iio_device *dev,
Paul Cercueil0b2ce712014-02-17 15:04:18 +0100885 const void *src, size_t len);
886
Paul Cercueil99b07cc2014-04-14 16:07:32 +0200887
Paul Cercueil1ce35ef2014-04-15 12:28:40 +0200888/** @brief Enumerate the debug attributes of the given device
889 * @param dev A pointer to an iio_device structure
890 * @return The number of debug attributes found */
891__api __pure unsigned int iio_device_get_debug_attrs_count(
892 const struct iio_device *dev);
893
894
895/** @brief Get the debug attribute present at the given index
896 * @param dev A pointer to an iio_device structure
897 * @param index The index corresponding to the debug attribute
898 * @return On success, a pointer to a static NULL-terminated string
899 * @return If the index is invalid, NULL is returned */
900__api __pure const char * iio_device_get_debug_attr(
901 const struct iio_device *dev, unsigned int index);
902
903
Paul Cercueil99b07cc2014-04-14 16:07:32 +0200904/** @brief Read the content of the given debug attribute
905 * @param dev A pointer to an iio_device structure
906 * @param attr A NULL-terminated string corresponding to the name of the
907 * debug attribute
908 * @param dst A pointer to the memory area where the NULL-terminated string
909 * corresponding to the value read will be stored
910 * @param len The available length of the memory area, in bytes
911 * @return On success, the number of bytes written to the buffer
912 * @return On error, a negative errno code is returned */
913__api ssize_t iio_device_debug_attr_read(const struct iio_device *dev,
914 const char *attr, char *dst, size_t len);
915
916
917/** @brief Set the value of the given debug attribute
918 * @param dev A pointer to an iio_device structure
919 * @param attr A NULL-terminated string corresponding to the name of the
920 * debug attribute
921 * @param src A NULL-terminated string to set the debug attribute to
922 * @return On success, the number of bytes written
923 * @return On error, a negative errno code is returned */
924__api ssize_t iio_device_debug_attr_write(const struct iio_device *dev,
925 const char *attr, const char *src);
926
Paul Cercueile3960742014-04-15 16:00:50 +0200927
Paul Cercueilcecda352014-05-06 18:14:29 +0200928/** @brief Set the value of the given debug attribute
929 * @param dev A pointer to an iio_device structure
930 * @param attr A NULL-terminated string corresponding to the name of the
931 * debug attribute
932 * @param src A pointer to the data to be written
933 * @param len The number of bytes that should be written
934 * @return On success, the number of bytes written
935 * @return On error, a negative errno code is returned */
936__api ssize_t iio_device_debug_attr_write_raw(const struct iio_device *dev,
937 const char *attr, const void *src, size_t len);
938
939
Paul Cercueile3960742014-04-15 16:00:50 +0200940/** @brief Read the content of the given debug attribute
941 * @param dev A pointer to an iio_device structure
942 * @param attr A NULL-terminated string corresponding to the name of the
943 * debug attribute
944 * @param val A pointer to a bool variable where the value should be stored
945 * @return On success, 0 is returned
946 * @return On error, a negative errno code is returned */
947__api int iio_device_debug_attr_read_bool(const struct iio_device *dev,
948 const char *attr, bool *val);
949
950
951/** @brief Read the content of the given debug attribute
952 * @param dev A pointer to an iio_device structure
953 * @param attr A NULL-terminated string corresponding to the name of the
954 * debug attribute
955 * @param val A pointer to a long long variable where the value should be stored
956 * @return On success, 0 is returned
957 * @return On error, a negative errno code is returned */
958__api int iio_device_debug_attr_read_longlong(const struct iio_device *dev,
959 const char *attr, long long *val);
960
961
962/** @brief Read the content of the given debug attribute
963 * @param dev A pointer to an iio_device structure
964 * @param attr A NULL-terminated string corresponding to the name of the
965 * debug attribute
966 * @param val A pointer to a double variable where the value should be stored
967 * @return On success, 0 is returned
968 * @return On error, a negative errno code is returned */
969__api int iio_device_debug_attr_read_double(const struct iio_device *dev,
970 const char *attr, double *val);
971
972
973/** @brief Set the value of the given debug attribute
974 * @param dev A pointer to an iio_device structure
975 * @param attr A NULL-terminated string corresponding to the name of the
976 * debug attribute
977 * @param val A bool value to set the debug attribute to
978 * @return On success, 0 is returned
979 * @return On error, a negative errno code is returned */
980__api int iio_device_debug_attr_write_bool(const struct iio_device *dev,
981 const char *attr, bool val);
982
983
984/** @brief Set the value of the given debug attribute
985 * @param dev A pointer to an iio_device structure
986 * @param attr A NULL-terminated string corresponding to the name of the
987 * debug attribute
988 * @param val A long long value to set the debug attribute to
989 * @return On success, 0 is returned
990 * @return On error, a negative errno code is returned */
991__api int iio_device_debug_attr_write_longlong(const struct iio_device *dev,
992 const char *attr, long long val);
993
994
995/** @brief Set the value of the given debug attribute
996 * @param dev A pointer to an iio_device structure
997 * @param attr A NULL-terminated string corresponding to the name of the
998 * debug attribute
999 * @param val A double value to set the debug attribute to
1000 * @return On success, 0 is returned
1001 * @return On error, a negative errno code is returned */
1002__api int iio_device_debug_attr_write_double(const struct iio_device *dev,
1003 const char *attr, double val);
1004
Paul Cercueil108e0aa2014-05-06 14:45:14 +02001005
1006/** @brief Identify the channel or debug attribute corresponding to a filename
1007 * @param dev A pointer to an iio_device structure
1008 * @param filename A NULL-terminated string corresponding to the filename
1009 * @param chn A pointer to a pointer of an iio_channel structure. The pointed
1010 * pointer will be set to the address of the iio_channel structure if the
1011 * filename correspond to the attribute of a channel, or NULL otherwise.
1012 * @param attr A pointer to a NULL-terminated string. The pointer
1013 * pointer will be set to point to the name of the attribute corresponding to
1014 * the filename.
1015 * @return On success, 0 is returned, and *chn and *attr are modified.
1016 * @return On error, a negative errno code is returned. *chn and *attr are not
1017 * modified. */
1018__api int iio_device_identify_filename(const struct iio_device *dev,
1019 const char *filename, struct iio_channel **chn,
1020 const char **attr);
1021
1022
Paul Cercueil306cb1c2014-04-11 14:46:45 +02001023/** @} */
1024
Paul Cercueila167e0c2014-04-08 14:50:41 +02001025#ifdef __cplusplus
1026}
1027#endif
1028
Paul Cercueil0b2ce712014-02-17 15:04:18 +01001029#endif /* __IIO_H__ */