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