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 | |
Paul Cercueil | 35a0131 | 2014-02-20 10:56:57 +0100 | [diff] [blame] | 29 | #include <stdbool.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 | ecbf4ed | 2014-03-17 15:02:43 +0100 | [diff] [blame] | 32 | #include <sys/types.h> |
Paul Cercueil | 95347b9 | 2014-03-21 09:50:17 +0100 | [diff] [blame] | 33 | #include <stddef.h> |
Paul Cercueil | 0b2ce71 | 2014-02-17 15:04:18 +0100 | [diff] [blame] | 34 | |
Paul Cercueil | b669f69 | 2014-04-04 13:42:24 +0200 | [diff] [blame] | 35 | #ifdef _MSC_BUILD |
| 36 | /* Come on Microsoft, time to get some C99... */ |
| 37 | typedef long ssize_t; |
Paul Cercueil | bc2645b | 2015-12-11 11:29:21 +0100 | [diff] [blame] | 38 | #define _SSIZE_T_DEFINED |
Paul Cercueil | b669f69 | 2014-04-04 13:42:24 +0200 | [diff] [blame] | 39 | #endif |
| 40 | |
Paul Cercueil | 59f2aa3 | 2014-04-04 16:28:51 +0200 | [diff] [blame] | 41 | #ifdef __GNUC__ |
| 42 | #define __cnst __attribute__((const)) |
| 43 | #define __pure __attribute__((pure)) |
Paul Cercueil | 83f2189 | 2014-05-19 13:00:39 +0200 | [diff] [blame] | 44 | #define __notused __attribute__((unused)) |
Paul Cercueil | 59f2aa3 | 2014-04-04 16:28:51 +0200 | [diff] [blame] | 45 | #else |
| 46 | #define __cnst |
| 47 | #define __pure |
Paul Cercueil | 83f2189 | 2014-05-19 13:00:39 +0200 | [diff] [blame] | 48 | #define __notused |
Paul Cercueil | 59f2aa3 | 2014-04-04 16:28:51 +0200 | [diff] [blame] | 49 | #endif |
| 50 | |
| 51 | #ifdef _WIN32 |
| 52 | # ifdef LIBIIO_EXPORTS |
Paul Cercueil | 59f2aa3 | 2014-04-04 16:28:51 +0200 | [diff] [blame] | 53 | # define __api __declspec(dllexport) |
Paul Cercueil | 7288c33 | 2014-04-07 16:25:11 +0200 | [diff] [blame] | 54 | # else |
| 55 | # define __api __declspec(dllimport) |
Paul Cercueil | 59f2aa3 | 2014-04-04 16:28:51 +0200 | [diff] [blame] | 56 | # endif |
| 57 | #elif __GNUC__ >= 4 |
| 58 | # define __api __attribute__((visibility ("default"))) |
| 59 | #else |
| 60 | # define __api |
| 61 | #endif |
| 62 | |
Paul Cercueil | 0b2ce71 | 2014-02-17 15:04:18 +0100 | [diff] [blame] | 63 | struct iio_context; |
| 64 | struct iio_device; |
| 65 | struct iio_channel; |
Paul Cercueil | a689cd9 | 2014-03-20 16:37:25 +0100 | [diff] [blame] | 66 | struct iio_buffer; |
Paul Cercueil | 0b2ce71 | 2014-02-17 15:04:18 +0100 | [diff] [blame] | 67 | |
Paul Cercueil | b4afdd9 | 2014-04-08 12:37:21 +0200 | [diff] [blame] | 68 | |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 69 | /* ---------------------------------------------------------------------------*/ |
Paul Cercueil | 53ed943 | 2014-11-20 13:46:04 +0100 | [diff] [blame] | 70 | /* ------------------------- Top-level functions -----------------------------*/ |
| 71 | /** @defgroup TopLevel Top-level functions |
| 72 | * @{ */ |
| 73 | |
| 74 | |
| 75 | /** @brief Get the version of the libiio library |
| 76 | * @param major A pointer to an unsigned integer (NULL accepted) |
| 77 | * @param minor A pointer to an unsigned integer (NULL accepted) |
| 78 | * @param git_tag A pointer to a 8-characters buffer (NULL accepted) */ |
| 79 | __api void iio_library_get_version(unsigned int *major, |
| 80 | unsigned int *minor, char git_tag[8]); |
| 81 | |
| 82 | |
Paul Cercueil | 3fa3438 | 2015-05-22 10:54:28 +0200 | [diff] [blame] | 83 | /** @brief Get a string description of an error code |
| 84 | * @param err The error code |
| 85 | * @param dst A pointer to the memory area where the NULL-terminated string |
| 86 | * corresponding to the error message will be stored |
| 87 | * @param len The available length of the memory area, in bytes */ |
| 88 | __api void iio_strerror(int err, char *dst, size_t len); |
| 89 | |
| 90 | |
Paul Cercueil | 53ed943 | 2014-11-20 13:46:04 +0100 | [diff] [blame] | 91 | /** @} *//* ------------------------------------------------------------------*/ |
Paul Cercueil | b4afdd9 | 2014-04-08 12:37:21 +0200 | [diff] [blame] | 92 | /* ------------------------- Context functions -------------------------------*/ |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 93 | /** @defgroup Context Context |
| 94 | * @{ |
| 95 | * @struct iio_context |
| 96 | * @brief Contains the representation of an IIO context */ |
Paul Cercueil | b4afdd9 | 2014-04-08 12:37:21 +0200 | [diff] [blame] | 97 | |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 98 | |
Paul Cercueil | 8f56ea7 | 2014-10-28 15:18:18 +0100 | [diff] [blame] | 99 | /** @brief Create a context from local or remote IIO devices |
| 100 | * @return On success, A pointer to an iio_context structure |
Paul Cercueil | dfeca0d | 2015-03-16 17:18:00 +0100 | [diff] [blame] | 101 | * @return On failure, NULL is returned and errno is set appropriately |
Paul Cercueil | 8f56ea7 | 2014-10-28 15:18:18 +0100 | [diff] [blame] | 102 | * |
| 103 | * <b>NOTE:</b> This function will create a network context if the IIOD_REMOTE |
| 104 | * environment variable is set to the hostname where the IIOD server runs. If |
| 105 | * set to an empty string, the server will be discovered using ZeroConf. |
| 106 | * If the environment variable is not set, a local context will be created |
| 107 | * instead. */ |
| 108 | __api struct iio_context * iio_create_default_context(void); |
| 109 | |
| 110 | |
| 111 | /** @brief Create a context from local IIO devices (Linux only) |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 112 | * @return On success, A pointer to an iio_context structure |
Paul Cercueil | dfeca0d | 2015-03-16 17:18:00 +0100 | [diff] [blame] | 113 | * @return On failure, NULL is returned and errno is set appropriately */ |
Paul Cercueil | 59f2aa3 | 2014-04-04 16:28:51 +0200 | [diff] [blame] | 114 | __api struct iio_context * iio_create_local_context(void); |
Paul Cercueil | b4afdd9 | 2014-04-08 12:37:21 +0200 | [diff] [blame] | 115 | |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 116 | |
| 117 | /** @brief Create a context from a XML file |
| 118 | * @param xml_file Path to the XML file to open |
| 119 | * @return On success, A pointer to an iio_context structure |
Paul Cercueil | dfeca0d | 2015-03-16 17:18:00 +0100 | [diff] [blame] | 120 | * @return On failure, NULL is returned and errno is set appropriately |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 121 | * |
| 122 | * <b>NOTE:</b> The format of the XML must comply to the one returned by |
| 123 | * iio_context_get_xml. */ |
Paul Cercueil | 59f2aa3 | 2014-04-04 16:28:51 +0200 | [diff] [blame] | 124 | __api struct iio_context * iio_create_xml_context(const char *xml_file); |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 125 | |
| 126 | |
| 127 | /** @brief Create a context from XML data in memory |
| 128 | * @param xml Pointer to the XML data in memory |
| 129 | * @param len Length of the XML string in memory (excluding the final \0) |
| 130 | * @return On success, A pointer to an iio_context structure |
Paul Cercueil | dfeca0d | 2015-03-16 17:18:00 +0100 | [diff] [blame] | 131 | * @return On failure, NULL is returned and errno is set appropriately |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 132 | * |
| 133 | * <b>NOTE:</b> The format of the XML must comply to the one returned by |
| 134 | * iio_context_get_xml */ |
Paul Cercueil | 59f2aa3 | 2014-04-04 16:28:51 +0200 | [diff] [blame] | 135 | __api struct iio_context * iio_create_xml_context_mem( |
| 136 | const char *xml, size_t len); |
Paul Cercueil | b4afdd9 | 2014-04-08 12:37:21 +0200 | [diff] [blame] | 137 | |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 138 | |
| 139 | /** @brief Create a context from the network |
| 140 | * @param host Hostname, IPv4 or IPv6 address where the IIO Daemon is running |
| 141 | * @return On success, a pointer to an iio_context structure |
Paul Cercueil | dfeca0d | 2015-03-16 17:18:00 +0100 | [diff] [blame] | 142 | * @return On failure, NULL is returned and errno is set appropriately */ |
Paul Cercueil | 59f2aa3 | 2014-04-04 16:28:51 +0200 | [diff] [blame] | 143 | __api struct iio_context * iio_create_network_context(const char *host); |
Paul Cercueil | b4afdd9 | 2014-04-08 12:37:21 +0200 | [diff] [blame] | 144 | |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 145 | |
Paul Cercueil | e06f4ce | 2015-04-20 12:59:31 +0200 | [diff] [blame] | 146 | /** @brief Create a context from USB devices |
| 147 | * @param vid Vendor identification number |
| 148 | * @param pid Product identification number |
| 149 | * @return On success, a pointer to an iio_context structure |
| 150 | * @return On failure, NULL is returned and errno is set appropriately */ |
| 151 | __api struct iio_context * iio_create_usb_context( |
| 152 | unsigned short vid, unsigned short pid); |
| 153 | |
| 154 | |
Paul Cercueil | 63d5e7c | 2014-10-28 14:33:08 +0100 | [diff] [blame] | 155 | /** @brief Duplicate a pre-existing IIO context |
| 156 | * @param ctx A pointer to an iio_context structure |
| 157 | * @return On success, A pointer to an iio_context structure |
Paul Cercueil | dfeca0d | 2015-03-16 17:18:00 +0100 | [diff] [blame] | 158 | * @return On failure, NULL is returned and errno is set appropriately */ |
Paul Cercueil | 63d5e7c | 2014-10-28 14:33:08 +0100 | [diff] [blame] | 159 | __api struct iio_context * iio_context_clone(const struct iio_context *ctx); |
| 160 | |
| 161 | |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 162 | /** @brief Destroy the given context |
| 163 | * @param ctx A pointer to an iio_context structure |
| 164 | * |
| 165 | * <b>NOTE:</b> After that function, the iio_context pointer shall be invalid. */ |
Paul Cercueil | 59f2aa3 | 2014-04-04 16:28:51 +0200 | [diff] [blame] | 166 | __api void iio_context_destroy(struct iio_context *ctx); |
Paul Cercueil | 0b2ce71 | 2014-02-17 15:04:18 +0100 | [diff] [blame] | 167 | |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 168 | |
Paul Cercueil | e45f876 | 2014-05-02 11:19:26 +0200 | [diff] [blame] | 169 | /** @brief Get the version of the backend in use |
| 170 | * @param ctx A pointer to an iio_context structure |
Paul Cercueil | d15d995 | 2014-05-20 11:40:08 +0200 | [diff] [blame] | 171 | * @param major A pointer to an unsigned integer (NULL accepted) |
| 172 | * @param minor A pointer to an unsigned integer (NULL accepted) |
Paul Cercueil | 9de9e9d | 2014-05-20 13:18:19 +0200 | [diff] [blame] | 173 | * @param git_tag A pointer to a 8-characters buffer (NULL accepted) |
Paul Cercueil | e45f876 | 2014-05-02 11:19:26 +0200 | [diff] [blame] | 174 | * @return On success, 0 is returned |
| 175 | * @return On error, a negative errno code is returned */ |
| 176 | __api int iio_context_get_version(const struct iio_context *ctx, |
Paul Cercueil | 9de9e9d | 2014-05-20 13:18:19 +0200 | [diff] [blame] | 177 | unsigned int *major, unsigned int *minor, char git_tag[8]); |
Paul Cercueil | e45f876 | 2014-05-02 11:19:26 +0200 | [diff] [blame] | 178 | |
| 179 | |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 180 | /** @brief Obtain a XML representation of the given context |
| 181 | * @param ctx A pointer to an iio_context structure |
| 182 | * @return A pointer to a static NULL-terminated string */ |
Paul Cercueil | b4afdd9 | 2014-04-08 12:37:21 +0200 | [diff] [blame] | 183 | __api __pure const char * iio_context_get_xml(const struct iio_context *ctx); |
| 184 | |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 185 | |
| 186 | /** @brief Get the name of the given context |
| 187 | * @param ctx A pointer to an iio_context structure |
| 188 | * @return A pointer to a static NULL-terminated string |
| 189 | * |
| 190 | * <b>NOTE:</b>The returned string will be <b><i>local</i></b>, |
| 191 | * <b><i>xml</i></b> or <b><i>network</i></b> when the context has been |
| 192 | * created with the local, xml and network backends respectively.*/ |
Paul Cercueil | 59f2aa3 | 2014-04-04 16:28:51 +0200 | [diff] [blame] | 193 | __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] | 194 | |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 195 | |
Paul Cercueil | 3ac36c1 | 2015-01-08 14:44:00 +0100 | [diff] [blame] | 196 | /** @brief Get a description of the given context |
| 197 | * @param ctx A pointer to an iio_context structure |
| 198 | * @return A pointer to a static NULL-terminated string |
| 199 | * |
| 200 | * <b>NOTE:</b>The returned string will contain human-readable information about |
| 201 | * the current context. */ |
| 202 | __api __pure const char * iio_context_get_description( |
| 203 | const struct iio_context *ctx); |
| 204 | |
| 205 | |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 206 | /** @brief Enumerate the devices found in the given context |
| 207 | * @param ctx A pointer to an iio_context structure |
| 208 | * @return The number of devices found */ |
Paul Cercueil | 59f2aa3 | 2014-04-04 16:28:51 +0200 | [diff] [blame] | 209 | __api __pure unsigned int iio_context_get_devices_count( |
| 210 | const struct iio_context *ctx); |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 211 | |
| 212 | |
| 213 | /** @brief Get the device present at the given index |
| 214 | * @param ctx A pointer to an iio_context structure |
| 215 | * @param index The index corresponding to the device |
| 216 | * @return On success, a pointer to an iio_device structure |
| 217 | * @return If the index is invalid, NULL is returned */ |
Paul Cercueil | 59f2aa3 | 2014-04-04 16:28:51 +0200 | [diff] [blame] | 218 | __api __pure struct iio_device * iio_context_get_device( |
| 219 | const struct iio_context *ctx, unsigned int index); |
Paul Cercueil | b4afdd9 | 2014-04-08 12:37:21 +0200 | [diff] [blame] | 220 | |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 221 | |
| 222 | /** @brief Try to find a device structure by its name of ID |
| 223 | * @param ctx A pointer to an iio_context structure |
| 224 | * @param name A NULL-terminated string corresponding to the name or the ID of |
| 225 | * the device to search for |
| 226 | * @return On success, a pointer to an iio_device structure |
| 227 | * @return If the name or ID does not correspond to any known device, NULL is |
| 228 | * returned */ |
Paul Cercueil | 59f2aa3 | 2014-04-04 16:28:51 +0200 | [diff] [blame] | 229 | __api __pure struct iio_device * iio_context_find_device( |
| 230 | const struct iio_context *ctx, const char *name); |
Paul Cercueil | 0b2ce71 | 2014-02-17 15:04:18 +0100 | [diff] [blame] | 231 | |
Paul Cercueil | b4afdd9 | 2014-04-08 12:37:21 +0200 | [diff] [blame] | 232 | |
Paul Cercueil | 4ca7354 | 2014-06-10 16:23:29 +0200 | [diff] [blame] | 233 | /** @brief Set a timeout for I/O operations |
| 234 | * @param ctx A pointer to an iio_context structure |
| 235 | * @param timeout_ms A positive integer representing the time in milliseconds |
Lars-Peter Clausen | ae7b7d9 | 2016-04-21 18:22:38 +0200 | [diff] [blame^] | 236 | * after which a timeout occurs. A value of 0 is used to specify that no |
| 237 | * timeout should occur. |
Paul Cercueil | 4ca7354 | 2014-06-10 16:23:29 +0200 | [diff] [blame] | 238 | * @return On success, 0 is returned |
| 239 | * @return On error, a negative errno code is returned */ |
| 240 | __api int iio_context_set_timeout( |
| 241 | struct iio_context *ctx, unsigned int timeout_ms); |
| 242 | |
| 243 | |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 244 | /** @} *//* ------------------------------------------------------------------*/ |
Paul Cercueil | b4afdd9 | 2014-04-08 12:37:21 +0200 | [diff] [blame] | 245 | /* ------------------------- Device functions --------------------------------*/ |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 246 | /** @defgroup Device Device |
| 247 | * @{ |
| 248 | * @struct iio_device |
| 249 | * @brief Represents a device in the IIO context */ |
Paul Cercueil | b4afdd9 | 2014-04-08 12:37:21 +0200 | [diff] [blame] | 250 | |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 251 | |
Paul Cercueil | 03b6c81 | 2015-04-14 16:49:06 +0200 | [diff] [blame] | 252 | /** @brief Retrieve a pointer to the iio_context structure |
| 253 | * @param dev A pointer to an iio_device structure |
| 254 | * @return A pointer to an iio_context structure */ |
| 255 | __api __pure const struct iio_context * iio_device_get_context( |
| 256 | const struct iio_device *dev); |
| 257 | |
| 258 | |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 259 | /** @brief Retrieve the device ID (e.g. <b><i>iio:device0</i></b>) |
| 260 | * @param dev A pointer to an iio_device structure |
| 261 | * @return A pointer to a static NULL-terminated string */ |
Paul Cercueil | 59f2aa3 | 2014-04-04 16:28:51 +0200 | [diff] [blame] | 262 | __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] | 263 | |
| 264 | |
| 265 | /** @brief Retrieve the device name (e.g. <b><i>xadc</i></b>) |
| 266 | * @param dev A pointer to an iio_device structure |
| 267 | * @return A pointer to a static NULL-terminated string |
| 268 | * |
| 269 | * <b>NOTE:</b> if the device has no name, NULL is returned. */ |
Paul Cercueil | 59f2aa3 | 2014-04-04 16:28:51 +0200 | [diff] [blame] | 270 | __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] | 271 | |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 272 | |
| 273 | /** @brief Enumerate the channels of the given device |
| 274 | * @param dev A pointer to an iio_device structure |
| 275 | * @return The number of channels found */ |
Paul Cercueil | 59f2aa3 | 2014-04-04 16:28:51 +0200 | [diff] [blame] | 276 | __api __pure unsigned int iio_device_get_channels_count( |
| 277 | const struct iio_device *dev); |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 278 | |
| 279 | |
| 280 | /** @brief Enumerate the device-specific attributes of the given device |
| 281 | * @param dev A pointer to an iio_device structure |
| 282 | * @return The number of device-specific attributes found */ |
Paul Cercueil | 59f2aa3 | 2014-04-04 16:28:51 +0200 | [diff] [blame] | 283 | __api __pure unsigned int iio_device_get_attrs_count( |
| 284 | const struct iio_device *dev); |
Paul Cercueil | b4afdd9 | 2014-04-08 12:37:21 +0200 | [diff] [blame] | 285 | |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 286 | |
| 287 | /** @brief Get the channel present at the given index |
| 288 | * @param dev A pointer to an iio_device structure |
| 289 | * @param index The index corresponding to the channel |
| 290 | * @return On success, a pointer to an iio_channel structure |
| 291 | * @return If the index is invalid, NULL is returned */ |
Paul Cercueil | b4afdd9 | 2014-04-08 12:37:21 +0200 | [diff] [blame] | 292 | __api __pure struct iio_channel * iio_device_get_channel( |
| 293 | const struct iio_device *dev, unsigned int index); |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 294 | |
| 295 | |
| 296 | /** @brief Get the device-specific attribute present at the given index |
| 297 | * @param dev A pointer to an iio_device structure |
| 298 | * @param index The index corresponding to the attribute |
| 299 | * @return On success, a pointer to a static NULL-terminated string |
| 300 | * @return If the index is invalid, NULL is returned */ |
Paul Cercueil | 59f2aa3 | 2014-04-04 16:28:51 +0200 | [diff] [blame] | 301 | __api __pure const char * iio_device_get_attr( |
| 302 | const struct iio_device *dev, unsigned int index); |
Paul Cercueil | b4afdd9 | 2014-04-08 12:37:21 +0200 | [diff] [blame] | 303 | |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 304 | |
| 305 | /** @brief Try to find a channel structure by its name of ID |
| 306 | * @param dev A pointer to an iio_device structure |
| 307 | * @param name A NULL-terminated string corresponding to the name or the ID of |
| 308 | * the channel to search for |
| 309 | * @param output True if the searched channel is output, False otherwise |
| 310 | * @return On success, a pointer to an iio_channel structure |
| 311 | * @return If the name or ID does not correspond to any known channel of the |
| 312 | * given device, NULL is returned */ |
Paul Cercueil | b4afdd9 | 2014-04-08 12:37:21 +0200 | [diff] [blame] | 313 | __api __pure struct iio_channel * iio_device_find_channel( |
| 314 | const struct iio_device *dev, const char *name, bool output); |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 315 | |
| 316 | |
| 317 | /** @brief Try to find a device-specific attribute by its name |
| 318 | * @param dev A pointer to an iio_device structure |
Paul Cercueil | 30606d5 | 2014-04-14 16:04:15 +0200 | [diff] [blame] | 319 | * @param name A NULL-terminated string corresponding to the name of the |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 320 | * attribute |
| 321 | * @return On success, a pointer to a static NULL-terminated string |
| 322 | * @return If the name does not correspond to any known attribute of the given |
| 323 | * device, NULL is returned |
| 324 | * |
| 325 | * <b>NOTE:</b> This function is useful to detect the presence of an attribute. |
| 326 | * It can also be used to retrieve the name of an attribute as a pointer to a |
| 327 | * static string from a dynamically allocated string. */ |
Paul Cercueil | 59f2aa3 | 2014-04-04 16:28:51 +0200 | [diff] [blame] | 328 | __api __pure const char * iio_device_find_attr( |
| 329 | const struct iio_device *dev, const char *name); |
Paul Cercueil | b4afdd9 | 2014-04-08 12:37:21 +0200 | [diff] [blame] | 330 | |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 331 | |
| 332 | /** @brief Read the content of the given device-specific attribute |
| 333 | * @param dev A pointer to an iio_device structure |
Paul Cercueil | 30606d5 | 2014-04-14 16:04:15 +0200 | [diff] [blame] | 334 | * @param attr A NULL-terminated string corresponding to the name of the |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 335 | * attribute |
| 336 | * @param dst A pointer to the memory area where the NULL-terminated string |
| 337 | * corresponding to the value read will be stored |
| 338 | * @param len The available length of the memory area, in bytes |
| 339 | * @return On success, the number of bytes written to the buffer |
Paul Cercueil | 4ca6ddc | 2014-05-21 14:51:50 +0200 | [diff] [blame] | 340 | * @return On error, a negative errno code is returned |
| 341 | * |
| 342 | * <b>NOTE:</b>By passing NULL as the "attr" argument to iio_device_attr_read, |
| 343 | * it is now possible to read all of the attributes of a device. |
| 344 | * |
| 345 | * The buffer is filled with one block of data per attribute of the device, |
| 346 | * by the order they appear in the iio_device structure. |
| 347 | * |
| 348 | * The first four bytes of one block correspond to a 32-bit signed value in |
| 349 | * network order. If negative, it corresponds to the errno code that were |
| 350 | * returned when reading the attribute; if positive, it corresponds to the |
| 351 | * length of the data read. In that case, the rest of the block contains |
| 352 | * the data. */ |
| 353 | __api ssize_t iio_device_attr_read(const struct iio_device *dev, |
Paul Cercueil | b4afdd9 | 2014-04-08 12:37:21 +0200 | [diff] [blame] | 354 | const char *attr, char *dst, size_t len); |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 355 | |
| 356 | |
Paul Cercueil | 1b36a01 | 2014-06-05 14:39:31 +0200 | [diff] [blame] | 357 | /** @brief Read the content of all device-specific attributes |
| 358 | * @param dev A pointer to an iio_device structure |
| 359 | * @param cb A pointer to a callback function |
| 360 | * @param data A pointer that will be passed to the callback function |
| 361 | * @return On success, 0 is returned |
| 362 | * @return On error, a negative errno code is returned |
| 363 | * |
| 364 | * <b>NOTE:</b> This function is especially useful when used with the network |
| 365 | * backend, as all the device-specific attributes are read in one single |
| 366 | * command. */ |
| 367 | __api int iio_device_attr_read_all(struct iio_device *dev, |
| 368 | int (*cb)(struct iio_device *dev, const char *attr, |
| 369 | const char *value, size_t len, void *d), |
| 370 | void *data); |
| 371 | |
| 372 | |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 373 | /** @brief Read the content of the given device-specific attribute |
| 374 | * @param dev A pointer to an iio_device structure |
Paul Cercueil | 30606d5 | 2014-04-14 16:04:15 +0200 | [diff] [blame] | 375 | * @param attr A NULL-terminated string corresponding to the name of the |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 376 | * attribute |
| 377 | * @param val A pointer to a bool variable where the value should be stored |
| 378 | * @return On success, 0 is returned |
| 379 | * @return On error, a negative errno code is returned */ |
Paul Cercueil | b4afdd9 | 2014-04-08 12:37:21 +0200 | [diff] [blame] | 380 | __api int iio_device_attr_read_bool(const struct iio_device *dev, |
| 381 | const char *attr, bool *val); |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 382 | |
| 383 | |
| 384 | /** @brief Read the content of the given device-specific attribute |
| 385 | * @param dev A pointer to an iio_device structure |
Paul Cercueil | 30606d5 | 2014-04-14 16:04:15 +0200 | [diff] [blame] | 386 | * @param attr A NULL-terminated string corresponding to the name of the |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 387 | * attribute |
| 388 | * @param val A pointer to a long long variable where the value should be stored |
| 389 | * @return On success, 0 is returned |
| 390 | * @return On error, a negative errno code is returned */ |
Paul Cercueil | b4afdd9 | 2014-04-08 12:37:21 +0200 | [diff] [blame] | 391 | __api int iio_device_attr_read_longlong(const struct iio_device *dev, |
| 392 | const char *attr, long long *val); |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 393 | |
| 394 | |
| 395 | /** @brief Read the content of the given device-specific attribute |
| 396 | * @param dev A pointer to an iio_device structure |
Paul Cercueil | 30606d5 | 2014-04-14 16:04:15 +0200 | [diff] [blame] | 397 | * @param attr A NULL-terminated string corresponding to the name of the |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 398 | * attribute |
| 399 | * @param val A pointer to a double variable where the value should be stored |
| 400 | * @return On success, 0 is returned |
| 401 | * @return On error, a negative errno code is returned */ |
Paul Cercueil | b4afdd9 | 2014-04-08 12:37:21 +0200 | [diff] [blame] | 402 | __api int iio_device_attr_read_double(const struct iio_device *dev, |
| 403 | const char *attr, double *val); |
| 404 | |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 405 | |
| 406 | /** @brief Set the value of the given device-specific attribute |
| 407 | * @param dev A pointer to an iio_device structure |
Paul Cercueil | 30606d5 | 2014-04-14 16:04:15 +0200 | [diff] [blame] | 408 | * @param attr A NULL-terminated string corresponding to the name of the |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 409 | * attribute |
| 410 | * @param src A NULL-terminated string to set the attribute to |
| 411 | * @return On success, the number of bytes written |
Paul Cercueil | 1da2812 | 2014-05-22 10:59:49 +0200 | [diff] [blame] | 412 | * @return On error, a negative errno code is returned |
| 413 | * |
| 414 | * <b>NOTE:</b>By passing NULL as the "attr" argument to iio_device_attr_write, |
| 415 | * it is now possible to write all of the attributes of a device. |
| 416 | * |
| 417 | * The buffer must contain one block of data per attribute of the device, |
| 418 | * by the order they appear in the iio_device structure. |
| 419 | * |
| 420 | * The first four bytes of one block correspond to a 32-bit signed value in |
| 421 | * network order. If negative, the attribute is not written; if positive, |
| 422 | * it corresponds to the length of the data to write. In that case, the rest |
| 423 | * of the block must contain the data. */ |
Paul Cercueil | b4afdd9 | 2014-04-08 12:37:21 +0200 | [diff] [blame] | 424 | __api ssize_t iio_device_attr_write(const struct iio_device *dev, |
| 425 | const char *attr, const char *src); |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 426 | |
| 427 | |
| 428 | /** @brief Set the value of the given device-specific attribute |
| 429 | * @param dev A pointer to an iio_device structure |
Paul Cercueil | 30606d5 | 2014-04-14 16:04:15 +0200 | [diff] [blame] | 430 | * @param attr A NULL-terminated string corresponding to the name of the |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 431 | * attribute |
Paul Cercueil | cecda35 | 2014-05-06 18:14:29 +0200 | [diff] [blame] | 432 | * @param src A pointer to the data to be written |
| 433 | * @param len The number of bytes that should be written |
| 434 | * @return On success, the number of bytes written |
| 435 | * @return On error, a negative errno code is returned */ |
| 436 | __api ssize_t iio_device_attr_write_raw(const struct iio_device *dev, |
| 437 | const char *attr, const void *src, size_t len); |
| 438 | |
| 439 | |
Paul Cercueil | 1b36a01 | 2014-06-05 14:39:31 +0200 | [diff] [blame] | 440 | /** @brief Set the values of all device-specific attributes |
| 441 | * @param dev A pointer to an iio_device structure |
| 442 | * @param cb A pointer to a callback function |
| 443 | * @param data A pointer that will be passed to the callback function |
| 444 | * @return On success, 0 is returned |
| 445 | * @return On error, a negative errno code is returned |
| 446 | * |
| 447 | * <b>NOTE:</b> This function is especially useful when used with the network |
| 448 | * backend, as all the device-specific attributes are written in one single |
| 449 | * command. */ |
| 450 | __api int iio_device_attr_write_all(struct iio_device *dev, |
| 451 | ssize_t (*cb)(struct iio_device *dev, |
| 452 | const char *attr, void *buf, size_t len, void *d), |
| 453 | void *data); |
| 454 | |
| 455 | |
Paul Cercueil | cecda35 | 2014-05-06 18:14:29 +0200 | [diff] [blame] | 456 | /** @brief Set the value of the given device-specific attribute |
| 457 | * @param dev A pointer to an iio_device structure |
| 458 | * @param attr A NULL-terminated string corresponding to the name of the |
| 459 | * attribute |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 460 | * @param val A bool value to set the attribute to |
| 461 | * @return On success, 0 is returned |
| 462 | * @return On error, a negative errno code is returned */ |
Paul Cercueil | b4afdd9 | 2014-04-08 12:37:21 +0200 | [diff] [blame] | 463 | __api int iio_device_attr_write_bool(const struct iio_device *dev, |
| 464 | const char *attr, bool val); |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 465 | |
| 466 | |
| 467 | /** @brief Set the value of the given device-specific attribute |
| 468 | * @param dev A pointer to an iio_device structure |
Paul Cercueil | 30606d5 | 2014-04-14 16:04:15 +0200 | [diff] [blame] | 469 | * @param attr A NULL-terminated string corresponding to the name of the |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 470 | * attribute |
| 471 | * @param val A long long value to set the attribute to |
| 472 | * @return On success, 0 is returned |
| 473 | * @return On error, a negative errno code is returned */ |
Paul Cercueil | b4afdd9 | 2014-04-08 12:37:21 +0200 | [diff] [blame] | 474 | __api int iio_device_attr_write_longlong(const struct iio_device *dev, |
| 475 | const char *attr, long long val); |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 476 | |
| 477 | |
| 478 | /** @brief Set the value of the given device-specific attribute |
| 479 | * @param dev A pointer to an iio_device structure |
Paul Cercueil | 30606d5 | 2014-04-14 16:04:15 +0200 | [diff] [blame] | 480 | * @param attr A NULL-terminated string corresponding to the name of the |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 481 | * attribute |
| 482 | * @param val A double value to set the attribute to |
| 483 | * @return On success, 0 is returned |
| 484 | * @return On error, a negative errno code is returned */ |
Paul Cercueil | b4afdd9 | 2014-04-08 12:37:21 +0200 | [diff] [blame] | 485 | __api int iio_device_attr_write_double(const struct iio_device *dev, |
| 486 | const char *attr, double val); |
| 487 | |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 488 | |
| 489 | /** @brief Associate a pointer to an iio_device structure |
| 490 | * @param dev A pointer to an iio_device structure |
| 491 | * @param data The pointer to be associated */ |
Paul Cercueil | b4afdd9 | 2014-04-08 12:37:21 +0200 | [diff] [blame] | 492 | __api void iio_device_set_data(struct iio_device *dev, void *data); |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 493 | |
| 494 | |
| 495 | /** @brief Retrieve a previously associated pointer of an iio_device structure |
| 496 | * @param dev A pointer to an iio_device structure |
| 497 | * @return The pointer previously associated if present, or NULL */ |
Paul Cercueil | b4afdd9 | 2014-04-08 12:37:21 +0200 | [diff] [blame] | 498 | __api void * iio_device_get_data(const struct iio_device *dev); |
| 499 | |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 500 | |
| 501 | /** @brief Retrieve the trigger of a given device |
| 502 | * @param dev A pointer to an iio_device structure |
| 503 | * @param trigger a pointer to a pointer of an iio_device structure. The pointed |
| 504 | * pointer will be set to the address of the iio_device structure corresponding |
| 505 | * to the associated trigger device. |
| 506 | * @return On success, 0 is returned |
| 507 | * @return On error, a negative errno code is returned */ |
Paul Cercueil | 59f2aa3 | 2014-04-04 16:28:51 +0200 | [diff] [blame] | 508 | __api int iio_device_get_trigger(const struct iio_device *dev, |
Paul Cercueil | 24ffa53 | 2014-03-10 12:39:58 +0100 | [diff] [blame] | 509 | const struct iio_device **trigger); |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 510 | |
| 511 | |
| 512 | /** @brief Associate a trigger to a given device |
| 513 | * @param dev A pointer to an iio_device structure |
| 514 | * @param trigger a pointer to the iio_device structure corresponding to the |
| 515 | * trigger that should be associated. |
| 516 | * @return On success, 0 is returned |
| 517 | * @return On error, a negative errno code is returned */ |
Paul Cercueil | 59f2aa3 | 2014-04-04 16:28:51 +0200 | [diff] [blame] | 518 | __api int iio_device_set_trigger(const struct iio_device *dev, |
Paul Cercueil | 24ffa53 | 2014-03-10 12:39:58 +0100 | [diff] [blame] | 519 | const struct iio_device *trigger); |
Paul Cercueil | 0b2ce71 | 2014-02-17 15:04:18 +0100 | [diff] [blame] | 520 | |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 521 | |
| 522 | /** @brief Return True if the given device is a trigger |
| 523 | * @param dev A pointer to an iio_device structure |
| 524 | * @return True if the device is a trigger, False otherwise */ |
Paul Cercueil | b4afdd9 | 2014-04-08 12:37:21 +0200 | [diff] [blame] | 525 | __api __pure bool iio_device_is_trigger(const struct iio_device *dev); |
| 526 | |
Romain Roffé | 6c385d9 | 2015-06-30 13:36:05 +0200 | [diff] [blame] | 527 | /** |
| 528 | * @brief Configure the number of kernel buffers for a device |
| 529 | * |
| 530 | * This function allows to change the number of buffers on kernel side. |
| 531 | * @param dev A pointer to an iio_device structure |
| 532 | * @param nb_buffers The number of buffers |
| 533 | * @return On success, 0 is returned |
| 534 | * @return On error, a negative errno code is returned */ |
| 535 | __api int iio_device_set_kernel_buffers_count(const struct iio_device *dev, |
| 536 | unsigned int nb_buffers); |
Paul Cercueil | b4afdd9 | 2014-04-08 12:37:21 +0200 | [diff] [blame] | 537 | |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 538 | /** @} *//* ------------------------------------------------------------------*/ |
Paul Cercueil | b4afdd9 | 2014-04-08 12:37:21 +0200 | [diff] [blame] | 539 | /* ------------------------- Channel functions -------------------------------*/ |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 540 | /** @defgroup Channel Channel |
| 541 | * @{ |
| 542 | * @struct iio_channel |
| 543 | * @brief Represents an input or output channel of a device */ |
Paul Cercueil | b4afdd9 | 2014-04-08 12:37:21 +0200 | [diff] [blame] | 544 | |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 545 | |
Paul Cercueil | 03b6c81 | 2015-04-14 16:49:06 +0200 | [diff] [blame] | 546 | /** @brief Retrieve a pointer to the iio_device structure |
| 547 | * @param chn A pointer to an iio_channel structure |
| 548 | * @return A pointer to an iio_device structure */ |
| 549 | __api __pure const struct iio_device * iio_channel_get_device( |
| 550 | const struct iio_channel *chn); |
| 551 | |
| 552 | |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 553 | /** @brief Retrieve the channel ID (e.g. <b><i>voltage0</i></b>) |
| 554 | * @param chn A pointer to an iio_channel structure |
| 555 | * @return A pointer to a static NULL-terminated string */ |
Paul Cercueil | b4afdd9 | 2014-04-08 12:37:21 +0200 | [diff] [blame] | 556 | __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] | 557 | |
| 558 | |
| 559 | /** @brief Retrieve the channel name (e.g. <b><i>vccint</i></b>) |
| 560 | * @param chn A pointer to an iio_channel structure |
| 561 | * @return A pointer to a static NULL-terminated string |
| 562 | * |
| 563 | * <b>NOTE:</b> if the channel has no name, NULL is returned. */ |
Paul Cercueil | b4afdd9 | 2014-04-08 12:37:21 +0200 | [diff] [blame] | 564 | __api __pure const char * iio_channel_get_name(const struct iio_channel *chn); |
| 565 | |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 566 | |
| 567 | /** @brief Return True if the given channel is an output channel |
| 568 | * @param chn A pointer to an iio_channel structure |
| 569 | * @return True if the channel is an output channel, False otherwise */ |
Paul Cercueil | b4afdd9 | 2014-04-08 12:37:21 +0200 | [diff] [blame] | 570 | __api __pure bool iio_channel_is_output(const struct iio_channel *chn); |
| 571 | |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 572 | |
Paul Cercueil | 85aaf48 | 2014-04-24 16:39:09 +0200 | [diff] [blame] | 573 | /** @brief Return True if the given channel is a scan element |
| 574 | * @param chn A pointer to an iio_channel structure |
| 575 | * @return True if the channel is a scan element, False otherwise |
| 576 | * |
| 577 | * <b>NOTE:</b> a channel that is a scan element is a channel that can |
| 578 | * generate samples (for an input channel) or receive samples (for an output |
| 579 | * channel) after being enabled. */ |
| 580 | __api __pure bool iio_channel_is_scan_element(const struct iio_channel *chn); |
| 581 | |
| 582 | |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 583 | /** @brief Enumerate the channel-specific attributes of the given channel |
| 584 | * @param chn A pointer to an iio_channel structure |
| 585 | * @return The number of channel-specific attributes found */ |
Paul Cercueil | b4afdd9 | 2014-04-08 12:37:21 +0200 | [diff] [blame] | 586 | __api __pure unsigned int iio_channel_get_attrs_count( |
| 587 | const struct iio_channel *chn); |
| 588 | |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 589 | |
| 590 | /** @brief Get the channel-specific attribute present at the given index |
| 591 | * @param chn A pointer to an iio_channel structure |
| 592 | * @param index The index corresponding to the attribute |
| 593 | * @return On success, a pointer to a static NULL-terminated string |
| 594 | * @return If the index is invalid, NULL is returned */ |
Paul Cercueil | b4afdd9 | 2014-04-08 12:37:21 +0200 | [diff] [blame] | 595 | __api __pure const char * iio_channel_get_attr( |
| 596 | const struct iio_channel *chn, unsigned int index); |
| 597 | |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 598 | |
| 599 | /** @brief Try to find a channel-specific attribute by its name |
| 600 | * @param chn A pointer to an iio_channel structure |
Paul Cercueil | 30606d5 | 2014-04-14 16:04:15 +0200 | [diff] [blame] | 601 | * @param name A NULL-terminated string corresponding to the name of the |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 602 | * attribute |
| 603 | * @return On success, a pointer to a static NULL-terminated string |
| 604 | * @return If the name does not correspond to any known attribute of the given |
| 605 | * channel, NULL is returned |
| 606 | * |
| 607 | * <b>NOTE:</b> This function is useful to detect the presence of an attribute. |
| 608 | * It can also be used to retrieve the name of an attribute as a pointer to a |
| 609 | * static string from a dynamically allocated string. */ |
Paul Cercueil | b4afdd9 | 2014-04-08 12:37:21 +0200 | [diff] [blame] | 610 | __api __pure const char * iio_channel_find_attr( |
| 611 | const struct iio_channel *chn, const char *name); |
| 612 | |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 613 | |
Paul Cercueil | 6f8dbd4 | 2014-05-05 17:05:59 +0200 | [diff] [blame] | 614 | /** @brief Retrieve the filename of an attribute |
| 615 | * @param chn A pointer to an iio_channel structure |
| 616 | * @param attr a NULL-terminated string corresponding to the name of the |
| 617 | * attribute |
| 618 | * @return On success, a pointer to a static NULL-terminated string |
| 619 | * @return If the attribute name is unknown, NULL is returned */ |
| 620 | __api __pure const char * iio_channel_attr_get_filename( |
| 621 | const struct iio_channel *chn, const char *attr); |
| 622 | |
| 623 | |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 624 | /** @brief Read the content of the given channel-specific attribute |
| 625 | * @param chn A pointer to an iio_channel structure |
Paul Cercueil | 30606d5 | 2014-04-14 16:04:15 +0200 | [diff] [blame] | 626 | * @param attr A NULL-terminated string corresponding to the name of the |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 627 | * attribute |
| 628 | * @param dst A pointer to the memory area where the NULL-terminated string |
| 629 | * corresponding to the value read will be stored |
| 630 | * @param len The available length of the memory area, in bytes |
| 631 | * @return On success, the number of bytes written to the buffer |
Paul Cercueil | 4ca6ddc | 2014-05-21 14:51:50 +0200 | [diff] [blame] | 632 | * @return On error, a negative errno code is returned |
| 633 | * |
| 634 | * <b>NOTE:</b>By passing NULL as the "attr" argument to iio_channel_attr_read, |
| 635 | * it is now possible to read all of the attributes of a channel. |
| 636 | * |
| 637 | * The buffer is filled with one block of data per attribute of the channel, |
| 638 | * by the order they appear in the iio_channel structure. |
| 639 | * |
| 640 | * The first four bytes of one block correspond to a 32-bit signed value in |
| 641 | * network order. If negative, it corresponds to the errno code that were |
| 642 | * returned when reading the attribute; if positive, it corresponds to the |
| 643 | * length of the data read. In that case, the rest of the block contains |
| 644 | * the data. */ |
Paul Cercueil | b4afdd9 | 2014-04-08 12:37:21 +0200 | [diff] [blame] | 645 | __api ssize_t iio_channel_attr_read(const struct iio_channel *chn, |
| 646 | const char *attr, char *dst, size_t len); |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 647 | |
| 648 | |
Paul Cercueil | 47d23d0 | 2014-06-05 14:46:20 +0200 | [diff] [blame] | 649 | /** @brief Read the content of all channel-specific attributes |
| 650 | * @param chn A pointer to an iio_channel structure |
| 651 | * @param cb A pointer to a callback function |
| 652 | * @param data A pointer that will be passed to the callback function |
| 653 | * @return On success, 0 is returned |
| 654 | * @return On error, a negative errno code is returned |
| 655 | * |
| 656 | * <b>NOTE:</b> This function is especially useful when used with the network |
| 657 | * backend, as all the channel-specific attributes are read in one single |
| 658 | * command. */ |
| 659 | __api int iio_channel_attr_read_all(struct iio_channel *chn, |
| 660 | int (*cb)(struct iio_channel *chn, |
| 661 | const char *attr, const char *val, size_t len, void *d), |
| 662 | void *data); |
| 663 | |
| 664 | |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 665 | /** @brief Read the content of the given channel-specific attribute |
| 666 | * @param chn A pointer to an iio_channel structure |
Paul Cercueil | 30606d5 | 2014-04-14 16:04:15 +0200 | [diff] [blame] | 667 | * @param attr A NULL-terminated string corresponding to the name of the |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 668 | * attribute |
| 669 | * @param val A pointer to a bool variable where the value should be stored |
| 670 | * @return On success, 0 is returned |
| 671 | * @return On error, a negative errno code is returned */ |
Paul Cercueil | b4afdd9 | 2014-04-08 12:37:21 +0200 | [diff] [blame] | 672 | __api int iio_channel_attr_read_bool(const struct iio_channel *chn, |
| 673 | const char *attr, bool *val); |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 674 | |
| 675 | |
| 676 | /** @brief Read the content of the given channel-specific attribute |
| 677 | * @param chn A pointer to an iio_channel structure |
Paul Cercueil | 30606d5 | 2014-04-14 16:04:15 +0200 | [diff] [blame] | 678 | * @param attr A NULL-terminated string corresponding to the name of the |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 679 | * attribute |
| 680 | * @param val A pointer to a long long variable where the value should be stored |
| 681 | * @return On success, 0 is returned |
| 682 | * @return On error, a negative errno code is returned */ |
Paul Cercueil | b4afdd9 | 2014-04-08 12:37:21 +0200 | [diff] [blame] | 683 | __api int iio_channel_attr_read_longlong(const struct iio_channel *chn, |
| 684 | const char *attr, long long *val); |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 685 | |
| 686 | |
| 687 | /** @brief Read the content of the given channel-specific attribute |
| 688 | * @param chn A pointer to an iio_channel structure |
Paul Cercueil | 30606d5 | 2014-04-14 16:04:15 +0200 | [diff] [blame] | 689 | * @param attr A NULL-terminated string corresponding to the name of the |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 690 | * attribute |
| 691 | * @param val A pointer to a double variable where the value should be stored |
| 692 | * @return On success, 0 is returned |
| 693 | * @return On error, a negative errno code is returned */ |
Paul Cercueil | b4afdd9 | 2014-04-08 12:37:21 +0200 | [diff] [blame] | 694 | __api int iio_channel_attr_read_double(const struct iio_channel *chn, |
| 695 | const char *attr, double *val); |
| 696 | |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 697 | |
| 698 | /** @brief Set the value of the given channel-specific attribute |
| 699 | * @param chn A pointer to an iio_channel structure |
Paul Cercueil | 30606d5 | 2014-04-14 16:04:15 +0200 | [diff] [blame] | 700 | * @param attr A NULL-terminated string corresponding to the name of the |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 701 | * attribute |
| 702 | * @param src A NULL-terminated string to set the attribute to |
| 703 | * @return On success, the number of bytes written |
Paul Cercueil | 1da2812 | 2014-05-22 10:59:49 +0200 | [diff] [blame] | 704 | * @return On error, a negative errno code is returned |
| 705 | * |
| 706 | * <b>NOTE:</b>By passing NULL as the "attr" argument to iio_channel_attr_write, |
| 707 | * it is now possible to write all of the attributes of a channel. |
| 708 | * |
| 709 | * The buffer must contain one block of data per attribute of the channel, |
| 710 | * by the order they appear in the iio_channel structure. |
| 711 | * |
| 712 | * The first four bytes of one block correspond to a 32-bit signed value in |
| 713 | * network order. If negative, the attribute is not written; if positive, |
| 714 | * it corresponds to the length of the data to write. In that case, the rest |
| 715 | * of the block must contain the data. */ |
Paul Cercueil | b4afdd9 | 2014-04-08 12:37:21 +0200 | [diff] [blame] | 716 | __api ssize_t iio_channel_attr_write(const struct iio_channel *chn, |
| 717 | const char *attr, const char *src); |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 718 | |
| 719 | |
| 720 | /** @brief Set the value of the given channel-specific attribute |
| 721 | * @param chn A pointer to an iio_channel structure |
Paul Cercueil | 30606d5 | 2014-04-14 16:04:15 +0200 | [diff] [blame] | 722 | * @param attr A NULL-terminated string corresponding to the name of the |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 723 | * attribute |
Paul Cercueil | cecda35 | 2014-05-06 18:14:29 +0200 | [diff] [blame] | 724 | * @param src A pointer to the data to be written |
| 725 | * @param len The number of bytes that should be written |
| 726 | * @return On success, the number of bytes written |
| 727 | * @return On error, a negative errno code is returned */ |
| 728 | __api ssize_t iio_channel_attr_write_raw(const struct iio_channel *chn, |
| 729 | const char *attr, const void *src, size_t len); |
| 730 | |
| 731 | |
Paul Cercueil | 47d23d0 | 2014-06-05 14:46:20 +0200 | [diff] [blame] | 732 | /** @brief Set the values of all channel-specific attributes |
| 733 | * @param chn A pointer to an iio_channel structure |
| 734 | * @param cb A pointer to a callback function |
| 735 | * @param data A pointer that will be passed to the callback function |
| 736 | * @return On success, 0 is returned |
| 737 | * @return On error, a negative errno code is returned |
| 738 | * |
| 739 | * <b>NOTE:</b> This function is especially useful when used with the network |
| 740 | * backend, as all the channel-specific attributes are written in one single |
| 741 | * command. */ |
| 742 | __api int iio_channel_attr_write_all(struct iio_channel *chn, |
| 743 | ssize_t (*cb)(struct iio_channel *chn, |
| 744 | const char *attr, void *buf, size_t len, void *d), |
| 745 | void *data); |
| 746 | |
| 747 | |
Paul Cercueil | cecda35 | 2014-05-06 18:14:29 +0200 | [diff] [blame] | 748 | /** @brief Set the value of the given channel-specific attribute |
| 749 | * @param chn A pointer to an iio_channel structure |
| 750 | * @param attr A NULL-terminated string corresponding to the name of the |
| 751 | * attribute |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 752 | * @param val A bool value to set the attribute to |
| 753 | * @return On success, 0 is returned |
| 754 | * @return On error, a negative errno code is returned */ |
Paul Cercueil | b4afdd9 | 2014-04-08 12:37:21 +0200 | [diff] [blame] | 755 | __api int iio_channel_attr_write_bool(const struct iio_channel *chn, |
| 756 | const char *attr, bool val); |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 757 | |
| 758 | |
| 759 | /** @brief Set the value of the given channel-specific attribute |
| 760 | * @param chn A pointer to an iio_channel structure |
Paul Cercueil | 30606d5 | 2014-04-14 16:04:15 +0200 | [diff] [blame] | 761 | * @param attr A NULL-terminated string corresponding to the name of the |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 762 | * attribute |
| 763 | * @param val A long long value to set the attribute to |
| 764 | * @return On success, 0 is returned |
| 765 | * @return On error, a negative errno code is returned */ |
Paul Cercueil | b4afdd9 | 2014-04-08 12:37:21 +0200 | [diff] [blame] | 766 | __api int iio_channel_attr_write_longlong(const struct iio_channel *chn, |
| 767 | const char *attr, long long val); |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 768 | |
| 769 | |
| 770 | /** @brief Set the value of the given channel-specific attribute |
| 771 | * @param chn A pointer to an iio_channel structure |
Paul Cercueil | 30606d5 | 2014-04-14 16:04:15 +0200 | [diff] [blame] | 772 | * @param attr A NULL-terminated string corresponding to the name of the |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 773 | * attribute |
| 774 | * @param val A double value to set the attribute to |
| 775 | * @return On success, 0 is returned |
| 776 | * @return On error, a negative errno code is returned */ |
Paul Cercueil | b4afdd9 | 2014-04-08 12:37:21 +0200 | [diff] [blame] | 777 | __api int iio_channel_attr_write_double(const struct iio_channel *chn, |
| 778 | const char *attr, double val); |
| 779 | |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 780 | |
| 781 | /** @brief Enable the given channel |
| 782 | * @param chn A pointer to an iio_channel structure |
| 783 | * |
| 784 | * <b>NOTE:</b>Before creating an iio_buffer structure with |
| 785 | * iio_device_create_buffer, it is required to enable at least one channel of |
| 786 | * the device to read from. */ |
Paul Cercueil | b4afdd9 | 2014-04-08 12:37:21 +0200 | [diff] [blame] | 787 | __api void iio_channel_enable(struct iio_channel *chn); |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 788 | |
| 789 | |
| 790 | /** @brief Disable the given channel |
| 791 | * @param chn A pointer to an iio_channel structure */ |
Paul Cercueil | b4afdd9 | 2014-04-08 12:37:21 +0200 | [diff] [blame] | 792 | __api void iio_channel_disable(struct iio_channel *chn); |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 793 | |
| 794 | |
| 795 | /** @brief Returns True if the channel is enabled |
| 796 | * @param chn A pointer to an iio_channel structure |
| 797 | * @return True if the channel is enabled, False otherwise */ |
Paul Cercueil | b4afdd9 | 2014-04-08 12:37:21 +0200 | [diff] [blame] | 798 | __api bool iio_channel_is_enabled(const struct iio_channel *chn); |
| 799 | |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 800 | |
| 801 | /** Demultiplex the samples of a given channel |
| 802 | * @param chn A pointer to an iio_channel structure |
| 803 | * @param buffer A pointer to an iio_buffer structure |
| 804 | * @param dst A pointer to the memory area where the demultiplexed data will be |
| 805 | * stored |
| 806 | * @param len The available length of the memory area, in bytes |
| 807 | * @return The size of the demultiplexed data, in bytes */ |
Paul Cercueil | b4afdd9 | 2014-04-08 12:37:21 +0200 | [diff] [blame] | 808 | __api size_t iio_channel_read_raw(const struct iio_channel *chn, |
| 809 | struct iio_buffer *buffer, void *dst, size_t len); |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 810 | |
| 811 | |
| 812 | /** Demultiplex and convert the samples of a given channel |
| 813 | * @param chn A pointer to an iio_channel structure |
| 814 | * @param buffer A pointer to an iio_buffer structure |
| 815 | * @param dst A pointer to the memory area where the converted data will be |
| 816 | * stored |
| 817 | * @param len The available length of the memory area, in bytes |
| 818 | * @return The size of the converted data, in bytes */ |
Paul Cercueil | b4afdd9 | 2014-04-08 12:37:21 +0200 | [diff] [blame] | 819 | __api size_t iio_channel_read(const struct iio_channel *chn, |
| 820 | struct iio_buffer *buffer, void *dst, size_t len); |
| 821 | |
| 822 | |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 823 | /** Multiplex the samples of a given channel |
| 824 | * @param chn A pointer to an iio_channel structure |
| 825 | * @param buffer A pointer to an iio_buffer structure |
| 826 | * @param src A pointer to the memory area where the sequential data will |
| 827 | * be read from |
| 828 | * @param len The length of the memory area, in bytes |
| 829 | * @return The number of bytes actually multiplexed */ |
Paul Cercueil | b4afdd9 | 2014-04-08 12:37:21 +0200 | [diff] [blame] | 830 | __api size_t iio_channel_write_raw(const struct iio_channel *chn, |
| 831 | struct iio_buffer *buffer, const void *src, size_t len); |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 832 | |
| 833 | |
| 834 | /** Convert and multiplex the samples of a given channel |
| 835 | * @param chn A pointer to an iio_channel structure |
| 836 | * @param buffer A pointer to an iio_buffer structure |
| 837 | * @param src A pointer to the memory area where the sequential data will |
| 838 | * be read from |
| 839 | * @param len The length of the memory area, in bytes |
| 840 | * @return The number of bytes actually converted and multiplexed */ |
Paul Cercueil | b4afdd9 | 2014-04-08 12:37:21 +0200 | [diff] [blame] | 841 | __api size_t iio_channel_write(const struct iio_channel *chn, |
| 842 | struct iio_buffer *buffer, const void *src, size_t len); |
| 843 | |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 844 | |
| 845 | /** @brief Associate a pointer to an iio_channel structure |
| 846 | * @param chn A pointer to an iio_channel structure |
| 847 | * @param data The pointer to be associated */ |
Paul Cercueil | b4afdd9 | 2014-04-08 12:37:21 +0200 | [diff] [blame] | 848 | __api void iio_channel_set_data(struct iio_channel *chn, void *data); |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 849 | |
| 850 | |
| 851 | /** @brief Retrieve a previously associated pointer of an iio_channel structure |
| 852 | * @param chn A pointer to an iio_channel structure |
| 853 | * @return The pointer previously associated if present, or NULL */ |
Paul Cercueil | b4afdd9 | 2014-04-08 12:37:21 +0200 | [diff] [blame] | 854 | __api void * iio_channel_get_data(const struct iio_channel *chn); |
| 855 | |
| 856 | |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 857 | /** @} *//* ------------------------------------------------------------------*/ |
Paul Cercueil | b4afdd9 | 2014-04-08 12:37:21 +0200 | [diff] [blame] | 858 | /* ------------------------- Buffer functions --------------------------------*/ |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 859 | /** @defgroup Buffer Buffer |
| 860 | * @{ |
| 861 | * @struct iio_buffer |
| 862 | * @brief An input or output buffer, used to read or write samples */ |
Paul Cercueil | b4afdd9 | 2014-04-08 12:37:21 +0200 | [diff] [blame] | 863 | |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 864 | |
Paul Cercueil | 03b6c81 | 2015-04-14 16:49:06 +0200 | [diff] [blame] | 865 | /** @brief Retrieve a pointer to the iio_device structure |
| 866 | * @param buf A pointer to an iio_buffer structure |
| 867 | * @return A pointer to an iio_device structure */ |
| 868 | __api __pure const struct iio_device * iio_buffer_get_device( |
| 869 | const struct iio_buffer *buf); |
| 870 | |
| 871 | |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 872 | /** @brief Create an input or output buffer associated to the given device |
| 873 | * @param dev A pointer to an iio_device structure |
| 874 | * @param samples_count The number of samples that the buffer should contain |
Paul Cercueil | 2004eaa | 2014-05-22 14:04:39 +0200 | [diff] [blame] | 875 | * @param cyclic If True, enable cyclic mode |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 876 | * @return On success, a pointer to an iio_buffer structure |
Paul Cercueil | 3106e89 | 2014-04-30 11:29:51 +0200 | [diff] [blame] | 877 | * @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] | 878 | * |
| 879 | * <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] | 880 | * before creating the buffer. */ |
| 881 | __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] | 882 | size_t samples_count, bool cyclic); |
Paul Cercueil | b4afdd9 | 2014-04-08 12:37:21 +0200 | [diff] [blame] | 883 | |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 884 | |
| 885 | /** @brief Destroy the given buffer |
| 886 | * @param buf A pointer to an iio_buffer structure |
| 887 | * |
| 888 | * <b>NOTE:</b> After that function, the iio_buffer pointer shall be invalid. */ |
Paul Cercueil | b4afdd9 | 2014-04-08 12:37:21 +0200 | [diff] [blame] | 889 | __api void iio_buffer_destroy(struct iio_buffer *buf); |
| 890 | |
Romain Roffé | 6a88170 | 2015-06-30 16:25:43 +0200 | [diff] [blame] | 891 | /** @brief Get a pollable file descriptor |
| 892 | * |
| 893 | * Can be used to know when iio_buffer_refill() or iio_buffer_push() can be |
| 894 | * called |
| 895 | * @param buf A pointer to an iio_buffer structure |
| 896 | * @return On success, valid file descriptor |
| 897 | * @return On error, a negative errno code is returned |
| 898 | */ |
| 899 | __api int iio_buffer_get_poll_fd(struct iio_buffer *buf); |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 900 | |
Romain Roffé | 0ea038d | 2015-06-30 13:35:38 +0200 | [diff] [blame] | 901 | /** @brief Make iio_buffer_refill() and iio_buffer_push() blocking or not |
| 902 | * |
Paul Cercueil | 10ff757 | 2015-11-19 17:12:34 +0100 | [diff] [blame] | 903 | * After this function has been called with blocking == true, |
Romain Roffé | 0ea038d | 2015-06-30 13:35:38 +0200 | [diff] [blame] | 904 | * iio_buffer_refill() and iio_buffer_push() will return -EAGAIN if no data is |
| 905 | * ready. |
| 906 | * A device is blocking by default. |
| 907 | * @param buf A pointer to an iio_buffer structure |
| 908 | * @param blocking true if the buffer API should be blocking, else false |
| 909 | * @return On success, 0 |
| 910 | * @return On error, a negative errno code is returned |
| 911 | */ |
| 912 | __api int iio_buffer_set_blocking_mode(struct iio_buffer *buf, bool blocking); |
| 913 | |
| 914 | |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 915 | /** @brief Fetch more samples from the hardware |
| 916 | * @param buf A pointer to an iio_buffer structure |
| 917 | * @return On success, the number of bytes read is returned |
| 918 | * @return On error, a negative errno code is returned |
| 919 | * |
| 920 | * <b>NOTE:</b> Only valid for input buffers */ |
Paul Cercueil | b4afdd9 | 2014-04-08 12:37:21 +0200 | [diff] [blame] | 921 | __api ssize_t iio_buffer_refill(struct iio_buffer *buf); |
| 922 | |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 923 | |
| 924 | /** @brief Send the samples to the hardware |
| 925 | * @param buf A pointer to an iio_buffer structure |
| 926 | * @return On success, the number of bytes written is returned |
| 927 | * @return On error, a negative errno code is returned |
| 928 | * |
| 929 | * <b>NOTE:</b> Only valid for output buffers */ |
Paul Cercueil | 0183b6e | 2014-05-20 13:21:46 +0200 | [diff] [blame] | 930 | __api ssize_t iio_buffer_push(struct iio_buffer *buf); |
Paul Cercueil | b4afdd9 | 2014-04-08 12:37:21 +0200 | [diff] [blame] | 931 | |
Paul Cercueil | b4afdd9 | 2014-04-08 12:37:21 +0200 | [diff] [blame] | 932 | |
Paul Cercueil | 8e7b419 | 2015-08-05 13:03:35 +0200 | [diff] [blame] | 933 | /** @brief Send a given number of samples to the hardware |
| 934 | * @param buf A pointer to an iio_buffer structure |
| 935 | * @param samples_count The number of samples to submit |
| 936 | * @return On success, the number of bytes written is returned |
| 937 | * @return On error, a negative errno code is returned |
| 938 | * |
| 939 | * <b>NOTE:</b> Only valid for output buffers */ |
| 940 | __api ssize_t iio_buffer_push_partial(struct iio_buffer *buf, |
| 941 | size_t samples_count); |
| 942 | |
| 943 | |
Paul Cercueil | 6d92716 | 2014-04-16 15:53:22 +0200 | [diff] [blame] | 944 | /** @brief Get the start address of the buffer |
| 945 | * @param buf A pointer to an iio_buffer structure |
| 946 | * @return A pointer corresponding to the start address of the buffer */ |
Paul Cercueil | 4910600 | 2015-03-04 13:19:20 +0100 | [diff] [blame] | 947 | __api void * iio_buffer_start(const struct iio_buffer *buf); |
Paul Cercueil | 6d92716 | 2014-04-16 15:53:22 +0200 | [diff] [blame] | 948 | |
| 949 | |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 950 | /** @brief Find the first sample of a channel in a buffer |
| 951 | * @param buf A pointer to an iio_buffer structure |
| 952 | * @param chn A pointer to an iio_channel structure |
| 953 | * @return A pointer to the first sample found, or to the end of the buffer if |
| 954 | * no sample for the given channel is present in the buffer |
| 955 | * |
| 956 | * <b>NOTE:</b> This fonction, coupled with iio_buffer_step and iio_buffer_end, |
| 957 | * can be used to iterate on all the samples of a given channel present in the |
| 958 | * buffer, doing the following: |
| 959 | * |
| 960 | * @verbatim |
| 961 | for (void *ptr = iio_buffer_first(buffer, chn); ptr < iio_buffer_end(buffer); ptr += iio_buffer_step(buffer)) { |
| 962 | .... |
| 963 | } |
| 964 | @endverbatim */ |
| 965 | __api void * iio_buffer_first(const struct iio_buffer *buf, |
| 966 | const struct iio_channel *chn); |
| 967 | |
| 968 | |
| 969 | /** @brief Get the step size between two samples of one channel |
| 970 | * @param buf A pointer to an iio_buffer structure |
| 971 | * @return the difference between the addresses of two consecutive samples of |
| 972 | * one same channel */ |
| 973 | __api ptrdiff_t iio_buffer_step(const struct iio_buffer *buf); |
| 974 | |
| 975 | |
| 976 | /** @brief Get the address that follows the last sample in a buffer |
| 977 | * @param buf A pointer to an iio_buffer structure |
| 978 | * @return A pointer corresponding to the address that follows the last sample |
| 979 | * present in the buffer */ |
| 980 | __api void * iio_buffer_end(const struct iio_buffer *buf); |
| 981 | |
| 982 | |
| 983 | /** @brief Call the supplied callback for each sample found in a buffer |
| 984 | * @param buf A pointer to an iio_buffer structure |
| 985 | * @param callback A pointer to a function to call for each sample found |
| 986 | * @param data A user-specified pointer that will be passed to the callback |
| 987 | * |
| 988 | * <b>NOTE:</b> The callback receives four arguments: |
| 989 | * * A pointer to the iio_channel structure corresponding to the sample, |
| 990 | * * A pointer to the sample itself, |
| 991 | * * The length of the sample in bytes, |
| 992 | * * The user-specified pointer passed to iio_buffer_foreach_sample. */ |
Paul Cercueil | b4afdd9 | 2014-04-08 12:37:21 +0200 | [diff] [blame] | 993 | __api ssize_t iio_buffer_foreach_sample(struct iio_buffer *buf, |
| 994 | ssize_t (*callback)(const struct iio_channel *chn, |
| 995 | void *src, size_t bytes, void *d), void *data); |
| 996 | |
| 997 | |
Paul Cercueil | a2d4bad | 2014-05-27 10:15:29 +0200 | [diff] [blame] | 998 | /** @brief Associate a pointer to an iio_buffer structure |
| 999 | * @param buf A pointer to an iio_buffer structure |
| 1000 | * @param data The pointer to be associated */ |
| 1001 | __api void iio_buffer_set_data(struct iio_buffer *buf, void *data); |
| 1002 | |
| 1003 | |
| 1004 | /** @brief Retrieve a previously associated pointer of an iio_buffer structure |
| 1005 | * @param buf A pointer to an iio_buffer structure |
| 1006 | * @return The pointer previously associated if present, or NULL */ |
| 1007 | __api void * iio_buffer_get_data(const struct iio_buffer *buf); |
| 1008 | |
| 1009 | |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 1010 | /** @} *//* ------------------------------------------------------------------*/ |
Paul Cercueil | b4afdd9 | 2014-04-08 12:37:21 +0200 | [diff] [blame] | 1011 | /* ------------------------- Low-level functions -----------------------------*/ |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 1012 | /** @defgroup Debug Debug and low-level functions |
| 1013 | * @{ |
| 1014 | * @struct iio_data_format |
| 1015 | * @brief Contains the format of a data sample. |
| 1016 | * |
| 1017 | * The different fields inform about the correct way to convert one sample from |
| 1018 | * its raw format (as read from / generated by the hardware) to its real-world |
| 1019 | * value. |
| 1020 | */ |
| 1021 | struct iio_data_format { |
| 1022 | /** @brief Total length of the sample, in bits */ |
| 1023 | unsigned int length; |
Paul Cercueil | b4afdd9 | 2014-04-08 12:37:21 +0200 | [diff] [blame] | 1024 | |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 1025 | /** @brief Length of valuable data in the sample, in bits */ |
| 1026 | unsigned int bits; |
| 1027 | |
| 1028 | /** @brief Right-shift to apply when converting sample */ |
| 1029 | unsigned int shift; |
| 1030 | |
| 1031 | /** @brief Contains True if the sample is signed */ |
| 1032 | bool is_signed; |
| 1033 | |
Michael Hennerich | fa3c6f6 | 2014-08-13 11:21:23 +0200 | [diff] [blame] | 1034 | /** @brief Contains True if the sample is fully defined, sign extended, etc. */ |
| 1035 | bool is_fully_defined; |
| 1036 | |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 1037 | /** @brief Contains True if the sample is in big-endian format */ |
| 1038 | bool is_be; |
| 1039 | |
| 1040 | /** @brief Contains True if the sample should be scaled when converted */ |
| 1041 | bool with_scale; |
| 1042 | |
| 1043 | /** @brief Contains the scale to apply if with_scale is set */ |
| 1044 | double scale; |
| 1045 | }; |
| 1046 | |
| 1047 | |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 1048 | /** @brief Get the current sample size |
| 1049 | * @param dev A pointer to an iio_device structure |
| 1050 | * @return On success, the sample size in bytes |
| 1051 | * @return On error, a negative errno code is returned |
| 1052 | * |
| 1053 | * <b>NOTE:</b> The sample size is not constant and will change when channels |
| 1054 | * get enabled or disabled. */ |
Paul Cercueil | 59f2aa3 | 2014-04-04 16:28:51 +0200 | [diff] [blame] | 1055 | __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] | 1056 | |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 1057 | |
| 1058 | /** @brief Get the index of the given channel |
| 1059 | * @param chn A pointer to an iio_channel structure |
| 1060 | * @return On success, the index of the specified channel |
| 1061 | * @return On error, a negative errno code is returned */ |
Paul Cercueil | 59f2aa3 | 2014-04-04 16:28:51 +0200 | [diff] [blame] | 1062 | __api __pure long iio_channel_get_index(const struct iio_channel *chn); |
Paul Cercueil | b4afdd9 | 2014-04-08 12:37:21 +0200 | [diff] [blame] | 1063 | |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 1064 | |
| 1065 | /** @brief Get a pointer to a channel's data format structure |
| 1066 | * @param chn A pointer to an iio_channel structure |
| 1067 | * @return A pointer to the channel's iio_data_format structure */ |
Paul Cercueil | 59f2aa3 | 2014-04-04 16:28:51 +0200 | [diff] [blame] | 1068 | __api __cnst const struct iio_data_format * iio_channel_get_data_format( |
| 1069 | const struct iio_channel *chn); |
Paul Cercueil | 0b2ce71 | 2014-02-17 15:04:18 +0100 | [diff] [blame] | 1070 | |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 1071 | |
| 1072 | /** @brief Convert the sample from hardware format to host format |
| 1073 | * @param chn A pointer to an iio_channel structure |
| 1074 | * @param dst A pointer to the destination buffer where the converted sample |
| 1075 | * should be written |
| 1076 | * @param src A pointer to the source buffer containing the sample */ |
Paul Cercueil | 59f2aa3 | 2014-04-04 16:28:51 +0200 | [diff] [blame] | 1077 | __api void iio_channel_convert(const struct iio_channel *chn, |
Paul Cercueil | 2917ffb | 2014-03-21 15:47:12 +0100 | [diff] [blame] | 1078 | void *dst, const void *src); |
| 1079 | |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 1080 | |
| 1081 | /** @brief Convert the sample from host format to hardware format |
| 1082 | * @param chn A pointer to an iio_channel structure |
| 1083 | * @param dst A pointer to the destination buffer where the converted sample |
| 1084 | * should be written |
| 1085 | * @param src A pointer to the source buffer containing the sample */ |
Paul Cercueil | d840d4c | 2014-04-07 19:38:58 +0200 | [diff] [blame] | 1086 | __api void iio_channel_convert_inverse(const struct iio_channel *chn, |
| 1087 | void *dst, const void *src); |
| 1088 | |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 1089 | |
Paul Cercueil | 1ce35ef | 2014-04-15 12:28:40 +0200 | [diff] [blame] | 1090 | /** @brief Enumerate the debug attributes of the given device |
| 1091 | * @param dev A pointer to an iio_device structure |
| 1092 | * @return The number of debug attributes found */ |
| 1093 | __api __pure unsigned int iio_device_get_debug_attrs_count( |
| 1094 | const struct iio_device *dev); |
| 1095 | |
| 1096 | |
| 1097 | /** @brief Get the debug attribute present at the given index |
| 1098 | * @param dev A pointer to an iio_device structure |
| 1099 | * @param index The index corresponding to the debug attribute |
| 1100 | * @return On success, a pointer to a static NULL-terminated string |
| 1101 | * @return If the index is invalid, NULL is returned */ |
| 1102 | __api __pure const char * iio_device_get_debug_attr( |
| 1103 | const struct iio_device *dev, unsigned int index); |
| 1104 | |
| 1105 | |
Paul Cercueil | 001d215 | 2014-06-03 15:24:44 +0200 | [diff] [blame] | 1106 | /** @brief Try to find a debug attribute by its name |
| 1107 | * @param dev A pointer to an iio_device structure |
| 1108 | * @param name A NULL-terminated string corresponding to the name of the |
| 1109 | * debug attribute |
| 1110 | * @return On success, a pointer to a static NULL-terminated string |
| 1111 | * @return If the name does not correspond to any known debug attribute of the |
| 1112 | * given device, NULL is returned |
| 1113 | * |
| 1114 | * <b>NOTE:</b> This function is useful to detect the presence of a debug |
| 1115 | * attribute. |
| 1116 | * It can also be used to retrieve the name of a debug attribute as a pointer |
| 1117 | * to a static string from a dynamically allocated string. */ |
| 1118 | __api __pure const char * iio_device_find_debug_attr( |
| 1119 | const struct iio_device *dev, const char *name); |
| 1120 | |
| 1121 | |
Paul Cercueil | 99b07cc | 2014-04-14 16:07:32 +0200 | [diff] [blame] | 1122 | /** @brief Read the content of the given debug attribute |
| 1123 | * @param dev A pointer to an iio_device structure |
| 1124 | * @param attr A NULL-terminated string corresponding to the name of the |
| 1125 | * debug attribute |
| 1126 | * @param dst A pointer to the memory area where the NULL-terminated string |
| 1127 | * corresponding to the value read will be stored |
| 1128 | * @param len The available length of the memory area, in bytes |
| 1129 | * @return On success, the number of bytes written to the buffer |
Paul Cercueil | 4ca6ddc | 2014-05-21 14:51:50 +0200 | [diff] [blame] | 1130 | * @return On error, a negative errno code is returned |
| 1131 | * |
| 1132 | * <b>NOTE:</b>By passing NULL as the "attr" argument to |
| 1133 | * iio_device_debug_attr_read, it is now possible to read all of the debug |
| 1134 | * attributes of a device. |
| 1135 | * |
| 1136 | * The buffer is filled with one block of data per debug attribute of the |
| 1137 | * device, by the order they appear in the iio_device structure. |
| 1138 | * |
| 1139 | * The first four bytes of one block correspond to a 32-bit signed value in |
| 1140 | * network order. If negative, it corresponds to the errno code that were |
| 1141 | * returned when reading the debug attribute; if positive, it corresponds |
| 1142 | * to the length of the data read. In that case, the rest of the block contains |
| 1143 | * the data. */ |
Paul Cercueil | 99b07cc | 2014-04-14 16:07:32 +0200 | [diff] [blame] | 1144 | __api ssize_t iio_device_debug_attr_read(const struct iio_device *dev, |
| 1145 | const char *attr, char *dst, size_t len); |
| 1146 | |
| 1147 | |
Paul Cercueil | 1b36a01 | 2014-06-05 14:39:31 +0200 | [diff] [blame] | 1148 | /** @brief Read the content of all debug attributes |
| 1149 | * @param dev A pointer to an iio_device structure |
| 1150 | * @param cb A pointer to a callback function |
| 1151 | * @param data A pointer that will be passed to the callback function |
| 1152 | * @return On success, 0 is returned |
| 1153 | * @return On error, a negative errno code is returned |
| 1154 | * |
| 1155 | * <b>NOTE:</b> This function is especially useful when used with the network |
| 1156 | * backend, as all the debug attributes are read in one single command. */ |
| 1157 | __api int iio_device_debug_attr_read_all(struct iio_device *dev, |
| 1158 | int (*cb)(struct iio_device *dev, const char *attr, |
| 1159 | const char *value, size_t len, void *d), |
| 1160 | void *data); |
| 1161 | |
| 1162 | |
Paul Cercueil | 99b07cc | 2014-04-14 16:07:32 +0200 | [diff] [blame] | 1163 | /** @brief Set the value of the given debug attribute |
| 1164 | * @param dev A pointer to an iio_device structure |
| 1165 | * @param attr A NULL-terminated string corresponding to the name of the |
| 1166 | * debug attribute |
| 1167 | * @param src A NULL-terminated string to set the debug attribute to |
| 1168 | * @return On success, the number of bytes written |
Paul Cercueil | 1da2812 | 2014-05-22 10:59:49 +0200 | [diff] [blame] | 1169 | * @return On error, a negative errno code is returned |
| 1170 | * |
| 1171 | * <b>NOTE:</b>By passing NULL as the "attr" argument to |
| 1172 | * iio_device_debug_attr_write, it is now possible to write all of the |
| 1173 | * debug attributes of a device. |
| 1174 | * |
| 1175 | * The buffer must contain one block of data per debug attribute of the device, |
| 1176 | * by the order they appear in the iio_device structure. |
| 1177 | * |
| 1178 | * The first four bytes of one block correspond to a 32-bit signed value in |
| 1179 | * network order. If negative, the debug attribute is not written; if positive, |
| 1180 | * it corresponds to the length of the data to write. In that case, the rest |
| 1181 | * of the block must contain the data. */ |
Paul Cercueil | 99b07cc | 2014-04-14 16:07:32 +0200 | [diff] [blame] | 1182 | __api ssize_t iio_device_debug_attr_write(const struct iio_device *dev, |
| 1183 | const char *attr, const char *src); |
| 1184 | |
Paul Cercueil | e396074 | 2014-04-15 16:00:50 +0200 | [diff] [blame] | 1185 | |
Paul Cercueil | cecda35 | 2014-05-06 18:14:29 +0200 | [diff] [blame] | 1186 | /** @brief Set the value of the given debug attribute |
| 1187 | * @param dev A pointer to an iio_device structure |
| 1188 | * @param attr A NULL-terminated string corresponding to the name of the |
| 1189 | * debug attribute |
| 1190 | * @param src A pointer to the data to be written |
| 1191 | * @param len The number of bytes that should be written |
| 1192 | * @return On success, the number of bytes written |
| 1193 | * @return On error, a negative errno code is returned */ |
| 1194 | __api ssize_t iio_device_debug_attr_write_raw(const struct iio_device *dev, |
| 1195 | const char *attr, const void *src, size_t len); |
| 1196 | |
| 1197 | |
Paul Cercueil | 1b36a01 | 2014-06-05 14:39:31 +0200 | [diff] [blame] | 1198 | /** @brief Set the values of all debug attributes |
| 1199 | * @param dev A pointer to an iio_device structure |
| 1200 | * @param cb A pointer to a callback function |
| 1201 | * @param data A pointer that will be passed to the callback function |
| 1202 | * @return On success, 0 is returned |
| 1203 | * @return On error, a negative errno code is returned |
| 1204 | * |
| 1205 | * <b>NOTE:</b> This function is especially useful when used with the network |
| 1206 | * backend, as all the debug attributes are written in one single command. */ |
| 1207 | __api int iio_device_debug_attr_write_all(struct iio_device *dev, |
| 1208 | ssize_t (*cb)(struct iio_device *dev, |
| 1209 | const char *attr, void *buf, size_t len, void *d), |
| 1210 | void *data); |
| 1211 | |
| 1212 | |
Paul Cercueil | e396074 | 2014-04-15 16:00:50 +0200 | [diff] [blame] | 1213 | /** @brief Read the content of the given debug attribute |
| 1214 | * @param dev A pointer to an iio_device structure |
| 1215 | * @param attr A NULL-terminated string corresponding to the name of the |
| 1216 | * debug attribute |
| 1217 | * @param val A pointer to a bool variable where the value should be stored |
| 1218 | * @return On success, 0 is returned |
| 1219 | * @return On error, a negative errno code is returned */ |
| 1220 | __api int iio_device_debug_attr_read_bool(const struct iio_device *dev, |
| 1221 | const char *attr, bool *val); |
| 1222 | |
| 1223 | |
| 1224 | /** @brief Read the content of the given debug attribute |
| 1225 | * @param dev A pointer to an iio_device structure |
| 1226 | * @param attr A NULL-terminated string corresponding to the name of the |
| 1227 | * debug attribute |
| 1228 | * @param val A pointer to a long long variable where the value should be stored |
| 1229 | * @return On success, 0 is returned |
| 1230 | * @return On error, a negative errno code is returned */ |
| 1231 | __api int iio_device_debug_attr_read_longlong(const struct iio_device *dev, |
| 1232 | const char *attr, long long *val); |
| 1233 | |
| 1234 | |
| 1235 | /** @brief Read the content of the given debug attribute |
| 1236 | * @param dev A pointer to an iio_device structure |
| 1237 | * @param attr A NULL-terminated string corresponding to the name of the |
| 1238 | * debug attribute |
| 1239 | * @param val A pointer to a double variable where the value should be stored |
| 1240 | * @return On success, 0 is returned |
| 1241 | * @return On error, a negative errno code is returned */ |
| 1242 | __api int iio_device_debug_attr_read_double(const struct iio_device *dev, |
| 1243 | const char *attr, double *val); |
| 1244 | |
| 1245 | |
| 1246 | /** @brief Set the value of the given debug attribute |
| 1247 | * @param dev A pointer to an iio_device structure |
| 1248 | * @param attr A NULL-terminated string corresponding to the name of the |
| 1249 | * debug attribute |
| 1250 | * @param val A bool value to set the debug attribute to |
| 1251 | * @return On success, 0 is returned |
| 1252 | * @return On error, a negative errno code is returned */ |
| 1253 | __api int iio_device_debug_attr_write_bool(const struct iio_device *dev, |
| 1254 | const char *attr, bool val); |
| 1255 | |
| 1256 | |
| 1257 | /** @brief Set the value of the given debug attribute |
| 1258 | * @param dev A pointer to an iio_device structure |
| 1259 | * @param attr A NULL-terminated string corresponding to the name of the |
| 1260 | * debug attribute |
| 1261 | * @param val A long long value to set the debug attribute to |
| 1262 | * @return On success, 0 is returned |
| 1263 | * @return On error, a negative errno code is returned */ |
| 1264 | __api int iio_device_debug_attr_write_longlong(const struct iio_device *dev, |
| 1265 | const char *attr, long long val); |
| 1266 | |
| 1267 | |
| 1268 | /** @brief Set the value of the given debug attribute |
| 1269 | * @param dev A pointer to an iio_device structure |
| 1270 | * @param attr A NULL-terminated string corresponding to the name of the |
| 1271 | * debug attribute |
| 1272 | * @param val A double value to set the debug attribute to |
| 1273 | * @return On success, 0 is returned |
| 1274 | * @return On error, a negative errno code is returned */ |
| 1275 | __api int iio_device_debug_attr_write_double(const struct iio_device *dev, |
| 1276 | const char *attr, double val); |
| 1277 | |
Paul Cercueil | 108e0aa | 2014-05-06 14:45:14 +0200 | [diff] [blame] | 1278 | |
| 1279 | /** @brief Identify the channel or debug attribute corresponding to a filename |
| 1280 | * @param dev A pointer to an iio_device structure |
| 1281 | * @param filename A NULL-terminated string corresponding to the filename |
| 1282 | * @param chn A pointer to a pointer of an iio_channel structure. The pointed |
| 1283 | * pointer will be set to the address of the iio_channel structure if the |
| 1284 | * filename correspond to the attribute of a channel, or NULL otherwise. |
| 1285 | * @param attr A pointer to a NULL-terminated string. The pointer |
| 1286 | * pointer will be set to point to the name of the attribute corresponding to |
| 1287 | * the filename. |
| 1288 | * @return On success, 0 is returned, and *chn and *attr are modified. |
| 1289 | * @return On error, a negative errno code is returned. *chn and *attr are not |
| 1290 | * modified. */ |
| 1291 | __api int iio_device_identify_filename(const struct iio_device *dev, |
| 1292 | const char *filename, struct iio_channel **chn, |
| 1293 | const char **attr); |
| 1294 | |
| 1295 | |
Paul Cercueil | 1440587 | 2014-05-07 14:00:32 +0200 | [diff] [blame] | 1296 | /** @brief Set the value of a hardware register |
| 1297 | * @param dev A pointer to an iio_device structure |
| 1298 | * @param address The address of the register |
| 1299 | * @param value The value to set the register to |
| 1300 | * @return On success, 0 is returned |
| 1301 | * @return On error, a negative errno code is returned */ |
| 1302 | __api int iio_device_reg_write(struct iio_device *dev, |
| 1303 | uint32_t address, uint32_t value); |
| 1304 | |
| 1305 | |
| 1306 | /** @brief Get the value of a hardware register |
| 1307 | * @param dev A pointer to an iio_device structure |
| 1308 | * @param address The address of the register |
| 1309 | * @param value A pointer to the variable where the value will be written |
| 1310 | * @return On success, 0 is returned |
| 1311 | * @return On error, a negative errno code is returned */ |
| 1312 | __api int iio_device_reg_read(struct iio_device *dev, |
| 1313 | uint32_t address, uint32_t *value); |
| 1314 | |
| 1315 | |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 1316 | /** @} */ |
| 1317 | |
Paul Cercueil | a167e0c | 2014-04-08 14:50:41 +0200 | [diff] [blame] | 1318 | #ifdef __cplusplus |
| 1319 | } |
| 1320 | #endif |
| 1321 | |
Paul Cercueil | ddf35ec | 2016-02-25 15:36:58 +0100 | [diff] [blame] | 1322 | #undef __api |
| 1323 | |
Paul Cercueil | 0b2ce71 | 2014-02-17 15:04:18 +0100 | [diff] [blame] | 1324 | #endif /* __IIO_H__ */ |