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