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