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)) |
| 43 | #else |
| 44 | #define __cnst |
| 45 | #define __pure |
| 46 | #endif |
| 47 | |
| 48 | #ifdef _WIN32 |
| 49 | # ifdef LIBIIO_EXPORTS |
Paul Cercueil | 59f2aa3 | 2014-04-04 16:28:51 +0200 | [diff] [blame] | 50 | # define __api __declspec(dllexport) |
Paul Cercueil | 7288c33 | 2014-04-07 16:25:11 +0200 | [diff] [blame] | 51 | # else |
| 52 | # define __api __declspec(dllimport) |
Paul Cercueil | 59f2aa3 | 2014-04-04 16:28:51 +0200 | [diff] [blame] | 53 | # endif |
| 54 | #elif __GNUC__ >= 4 |
| 55 | # define __api __attribute__((visibility ("default"))) |
| 56 | #else |
| 57 | # define __api |
| 58 | #endif |
| 59 | |
Paul Cercueil | 0b2ce71 | 2014-02-17 15:04:18 +0100 | [diff] [blame] | 60 | struct iio_context; |
| 61 | struct iio_device; |
| 62 | struct iio_channel; |
Paul Cercueil | a689cd9 | 2014-03-20 16:37:25 +0100 | [diff] [blame] | 63 | struct iio_buffer; |
Paul Cercueil | 0b2ce71 | 2014-02-17 15:04:18 +0100 | [diff] [blame] | 64 | |
Paul Cercueil | b4afdd9 | 2014-04-08 12:37:21 +0200 | [diff] [blame] | 65 | |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 66 | /* ---------------------------------------------------------------------------*/ |
Paul Cercueil | b4afdd9 | 2014-04-08 12:37:21 +0200 | [diff] [blame] | 67 | /* ------------------------- Context functions -------------------------------*/ |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 68 | /** @defgroup Context Context |
| 69 | * @{ |
| 70 | * @struct iio_context |
| 71 | * @brief Contains the representation of an IIO context */ |
Paul Cercueil | b4afdd9 | 2014-04-08 12:37:21 +0200 | [diff] [blame] | 72 | |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 73 | |
| 74 | /** @brief Create a context from local IIO devices (Linux only). |
| 75 | * @return On success, A pointer to an iio_context structure |
| 76 | * @return On failure, NULL is returned */ |
Paul Cercueil | 59f2aa3 | 2014-04-04 16:28:51 +0200 | [diff] [blame] | 77 | __api struct iio_context * iio_create_local_context(void); |
Paul Cercueil | b4afdd9 | 2014-04-08 12:37:21 +0200 | [diff] [blame] | 78 | |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 79 | |
Paul Cercueil | 20407c2 | 2014-04-23 17:02:21 +0200 | [diff] [blame] | 80 | /** @brief Create a context from local IIO devices (Linux only). |
| 81 | * @return On success, A pointer to an iio_context structure |
| 82 | * @return On failure, NULL is returned |
| 83 | * |
| 84 | * <b>NOTE:</b> This backend uses mmap() to access the kernel buffers. |
| 85 | * It should be preferred over iio_create_local_context() for high-speed |
| 86 | * devices. */ |
| 87 | __api struct iio_context * iio_create_local_mmap_context(void); |
| 88 | |
| 89 | |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 90 | /** @brief Create a context from a XML file |
| 91 | * @param xml_file Path to the XML file to open |
| 92 | * @return On success, A pointer to an iio_context structure |
| 93 | * @return On failure, NULL is returned |
| 94 | * |
| 95 | * <b>NOTE:</b> The format of the XML must comply to the one returned by |
| 96 | * iio_context_get_xml. */ |
Paul Cercueil | 59f2aa3 | 2014-04-04 16:28:51 +0200 | [diff] [blame] | 97 | __api struct iio_context * iio_create_xml_context(const char *xml_file); |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 98 | |
| 99 | |
| 100 | /** @brief Create a context from XML data in memory |
| 101 | * @param xml Pointer to the XML data in memory |
| 102 | * @param len Length of the XML string in memory (excluding the final \0) |
| 103 | * @return On success, A pointer to an iio_context structure |
| 104 | * @return On failure, NULL is returned |
| 105 | * |
| 106 | * <b>NOTE:</b> The format of the XML must comply to the one returned by |
| 107 | * iio_context_get_xml */ |
Paul Cercueil | 59f2aa3 | 2014-04-04 16:28:51 +0200 | [diff] [blame] | 108 | __api struct iio_context * iio_create_xml_context_mem( |
| 109 | const char *xml, size_t len); |
Paul Cercueil | b4afdd9 | 2014-04-08 12:37:21 +0200 | [diff] [blame] | 110 | |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 111 | |
| 112 | /** @brief Create a context from the network |
| 113 | * @param host Hostname, IPv4 or IPv6 address where the IIO Daemon is running |
| 114 | * @return On success, a pointer to an iio_context structure |
| 115 | * @return On failure, NULL is returned */ |
Paul Cercueil | 59f2aa3 | 2014-04-04 16:28:51 +0200 | [diff] [blame] | 116 | __api struct iio_context * iio_create_network_context(const char *host); |
Paul Cercueil | b4afdd9 | 2014-04-08 12:37:21 +0200 | [diff] [blame] | 117 | |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 118 | |
| 119 | /** @brief Destroy the given context |
| 120 | * @param ctx A pointer to an iio_context structure |
| 121 | * |
| 122 | * <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] | 123 | __api void iio_context_destroy(struct iio_context *ctx); |
Paul Cercueil | 0b2ce71 | 2014-02-17 15:04:18 +0100 | [diff] [blame] | 124 | |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 125 | |
| 126 | /** @brief Obtain a XML representation of the given context |
| 127 | * @param ctx A pointer to an iio_context structure |
| 128 | * @return A pointer to a static NULL-terminated string */ |
Paul Cercueil | b4afdd9 | 2014-04-08 12:37:21 +0200 | [diff] [blame] | 129 | __api __pure const char * iio_context_get_xml(const struct iio_context *ctx); |
| 130 | |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 131 | |
| 132 | /** @brief Get the name of the given context |
| 133 | * @param ctx A pointer to an iio_context structure |
| 134 | * @return A pointer to a static NULL-terminated string |
| 135 | * |
| 136 | * <b>NOTE:</b>The returned string will be <b><i>local</i></b>, |
| 137 | * <b><i>xml</i></b> or <b><i>network</i></b> when the context has been |
| 138 | * created with the local, xml and network backends respectively.*/ |
Paul Cercueil | 59f2aa3 | 2014-04-04 16:28:51 +0200 | [diff] [blame] | 139 | __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] | 140 | |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 141 | |
| 142 | /** @brief Enumerate the devices found in the given context |
| 143 | * @param ctx A pointer to an iio_context structure |
| 144 | * @return The number of devices found */ |
Paul Cercueil | 59f2aa3 | 2014-04-04 16:28:51 +0200 | [diff] [blame] | 145 | __api __pure unsigned int iio_context_get_devices_count( |
| 146 | const struct iio_context *ctx); |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 147 | |
| 148 | |
| 149 | /** @brief Get the device present at the given index |
| 150 | * @param ctx A pointer to an iio_context structure |
| 151 | * @param index The index corresponding to the device |
| 152 | * @return On success, a pointer to an iio_device structure |
| 153 | * @return If the index is invalid, NULL is returned */ |
Paul Cercueil | 59f2aa3 | 2014-04-04 16:28:51 +0200 | [diff] [blame] | 154 | __api __pure struct iio_device * iio_context_get_device( |
| 155 | const struct iio_context *ctx, unsigned int index); |
Paul Cercueil | b4afdd9 | 2014-04-08 12:37:21 +0200 | [diff] [blame] | 156 | |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 157 | |
| 158 | /** @brief Try to find a device structure by its name of ID |
| 159 | * @param ctx A pointer to an iio_context structure |
| 160 | * @param name A NULL-terminated string corresponding to the name or the ID of |
| 161 | * the device to search for |
| 162 | * @return On success, a pointer to an iio_device structure |
| 163 | * @return If the name or ID does not correspond to any known device, NULL is |
| 164 | * returned */ |
Paul Cercueil | 59f2aa3 | 2014-04-04 16:28:51 +0200 | [diff] [blame] | 165 | __api __pure struct iio_device * iio_context_find_device( |
| 166 | const struct iio_context *ctx, const char *name); |
Paul Cercueil | 0b2ce71 | 2014-02-17 15:04:18 +0100 | [diff] [blame] | 167 | |
Paul Cercueil | b4afdd9 | 2014-04-08 12:37:21 +0200 | [diff] [blame] | 168 | |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 169 | /** @} *//* ------------------------------------------------------------------*/ |
Paul Cercueil | b4afdd9 | 2014-04-08 12:37:21 +0200 | [diff] [blame] | 170 | /* ------------------------- Device functions --------------------------------*/ |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 171 | /** @defgroup Device Device |
| 172 | * @{ |
| 173 | * @struct iio_device |
| 174 | * @brief Represents a device in the IIO context */ |
Paul Cercueil | b4afdd9 | 2014-04-08 12:37:21 +0200 | [diff] [blame] | 175 | |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 176 | |
| 177 | /** @brief Retrieve the device ID (e.g. <b><i>iio:device0</i></b>) |
| 178 | * @param dev A pointer to an iio_device structure |
| 179 | * @return A pointer to a static NULL-terminated string */ |
Paul Cercueil | 59f2aa3 | 2014-04-04 16:28:51 +0200 | [diff] [blame] | 180 | __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] | 181 | |
| 182 | |
| 183 | /** @brief Retrieve the device name (e.g. <b><i>xadc</i></b>) |
| 184 | * @param dev A pointer to an iio_device structure |
| 185 | * @return A pointer to a static NULL-terminated string |
| 186 | * |
| 187 | * <b>NOTE:</b> if the device has no name, NULL is returned. */ |
Paul Cercueil | 59f2aa3 | 2014-04-04 16:28:51 +0200 | [diff] [blame] | 188 | __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] | 189 | |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 190 | |
| 191 | /** @brief Enumerate the channels of the given device |
| 192 | * @param dev A pointer to an iio_device structure |
| 193 | * @return The number of channels found */ |
Paul Cercueil | 59f2aa3 | 2014-04-04 16:28:51 +0200 | [diff] [blame] | 194 | __api __pure unsigned int iio_device_get_channels_count( |
| 195 | const struct iio_device *dev); |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 196 | |
| 197 | |
| 198 | /** @brief Enumerate the device-specific attributes of the given device |
| 199 | * @param dev A pointer to an iio_device structure |
| 200 | * @return The number of device-specific attributes found */ |
Paul Cercueil | 59f2aa3 | 2014-04-04 16:28:51 +0200 | [diff] [blame] | 201 | __api __pure unsigned int iio_device_get_attrs_count( |
| 202 | const struct iio_device *dev); |
Paul Cercueil | b4afdd9 | 2014-04-08 12:37:21 +0200 | [diff] [blame] | 203 | |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 204 | |
| 205 | /** @brief Get the channel present at the given index |
| 206 | * @param dev A pointer to an iio_device structure |
| 207 | * @param index The index corresponding to the channel |
| 208 | * @return On success, a pointer to an iio_channel structure |
| 209 | * @return If the index is invalid, NULL is returned */ |
Paul Cercueil | b4afdd9 | 2014-04-08 12:37:21 +0200 | [diff] [blame] | 210 | __api __pure struct iio_channel * iio_device_get_channel( |
| 211 | const struct iio_device *dev, unsigned int index); |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 212 | |
| 213 | |
| 214 | /** @brief Get the device-specific attribute present at the given index |
| 215 | * @param dev A pointer to an iio_device structure |
| 216 | * @param index The index corresponding to the attribute |
| 217 | * @return On success, a pointer to a static NULL-terminated string |
| 218 | * @return If the index is invalid, NULL is returned */ |
Paul Cercueil | 59f2aa3 | 2014-04-04 16:28:51 +0200 | [diff] [blame] | 219 | __api __pure const char * iio_device_get_attr( |
| 220 | const struct iio_device *dev, unsigned int index); |
Paul Cercueil | b4afdd9 | 2014-04-08 12:37:21 +0200 | [diff] [blame] | 221 | |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 222 | |
| 223 | /** @brief Try to find a channel structure by its name of ID |
| 224 | * @param dev A pointer to an iio_device structure |
| 225 | * @param name A NULL-terminated string corresponding to the name or the ID of |
| 226 | * the channel to search for |
| 227 | * @param output True if the searched channel is output, False otherwise |
| 228 | * @return On success, a pointer to an iio_channel structure |
| 229 | * @return If the name or ID does not correspond to any known channel of the |
| 230 | * given device, NULL is returned */ |
Paul Cercueil | b4afdd9 | 2014-04-08 12:37:21 +0200 | [diff] [blame] | 231 | __api __pure struct iio_channel * iio_device_find_channel( |
| 232 | const struct iio_device *dev, const char *name, bool output); |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 233 | |
| 234 | |
| 235 | /** @brief Try to find a device-specific attribute by its name |
| 236 | * @param dev A pointer to an iio_device structure |
Paul Cercueil | 30606d5 | 2014-04-14 16:04:15 +0200 | [diff] [blame] | 237 | * @param name A NULL-terminated string corresponding to the name of the |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 238 | * attribute |
| 239 | * @return On success, a pointer to a static NULL-terminated string |
| 240 | * @return If the name does not correspond to any known attribute of the given |
| 241 | * device, NULL is returned |
| 242 | * |
| 243 | * <b>NOTE:</b> This function is useful to detect the presence of an attribute. |
| 244 | * It can also be used to retrieve the name of an attribute as a pointer to a |
| 245 | * static string from a dynamically allocated string. */ |
Paul Cercueil | 59f2aa3 | 2014-04-04 16:28:51 +0200 | [diff] [blame] | 246 | __api __pure const char * iio_device_find_attr( |
| 247 | const struct iio_device *dev, const char *name); |
Paul Cercueil | b4afdd9 | 2014-04-08 12:37:21 +0200 | [diff] [blame] | 248 | |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 249 | |
| 250 | /** @brief Read the content of the given device-specific attribute |
| 251 | * @param dev A pointer to an iio_device structure |
Paul Cercueil | 30606d5 | 2014-04-14 16:04:15 +0200 | [diff] [blame] | 252 | * @param attr A NULL-terminated string corresponding to the name of the |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 253 | * attribute |
| 254 | * @param dst A pointer to the memory area where the NULL-terminated string |
| 255 | * corresponding to the value read will be stored |
| 256 | * @param len The available length of the memory area, in bytes |
| 257 | * @return On success, the number of bytes written to the buffer |
| 258 | * @return On error, a negative errno code is returned */ |
Paul Cercueil | b4afdd9 | 2014-04-08 12:37:21 +0200 | [diff] [blame] | 259 | __api ssize_t iio_device_attr_read(const struct iio_device *dev, |
| 260 | const char *attr, char *dst, size_t len); |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 261 | |
| 262 | |
| 263 | /** @brief Read the content of the given device-specific attribute |
| 264 | * @param dev A pointer to an iio_device structure |
Paul Cercueil | 30606d5 | 2014-04-14 16:04:15 +0200 | [diff] [blame] | 265 | * @param attr A NULL-terminated string corresponding to the name of the |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 266 | * attribute |
| 267 | * @param val A pointer to a bool variable where the value should be stored |
| 268 | * @return On success, 0 is returned |
| 269 | * @return On error, a negative errno code is returned */ |
Paul Cercueil | b4afdd9 | 2014-04-08 12:37:21 +0200 | [diff] [blame] | 270 | __api int iio_device_attr_read_bool(const struct iio_device *dev, |
| 271 | const char *attr, bool *val); |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 272 | |
| 273 | |
| 274 | /** @brief Read the content of the given device-specific attribute |
| 275 | * @param dev A pointer to an iio_device structure |
Paul Cercueil | 30606d5 | 2014-04-14 16:04:15 +0200 | [diff] [blame] | 276 | * @param attr A NULL-terminated string corresponding to the name of the |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 277 | * attribute |
| 278 | * @param val A pointer to a long long variable where the value should be stored |
| 279 | * @return On success, 0 is returned |
| 280 | * @return On error, a negative errno code is returned */ |
Paul Cercueil | b4afdd9 | 2014-04-08 12:37:21 +0200 | [diff] [blame] | 281 | __api int iio_device_attr_read_longlong(const struct iio_device *dev, |
| 282 | const char *attr, long long *val); |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 283 | |
| 284 | |
| 285 | /** @brief Read the content of the given device-specific attribute |
| 286 | * @param dev A pointer to an iio_device structure |
Paul Cercueil | 30606d5 | 2014-04-14 16:04:15 +0200 | [diff] [blame] | 287 | * @param attr A NULL-terminated string corresponding to the name of the |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 288 | * attribute |
| 289 | * @param val A pointer to a double variable where the value should be stored |
| 290 | * @return On success, 0 is returned |
| 291 | * @return On error, a negative errno code is returned */ |
Paul Cercueil | b4afdd9 | 2014-04-08 12:37:21 +0200 | [diff] [blame] | 292 | __api int iio_device_attr_read_double(const struct iio_device *dev, |
| 293 | const char *attr, double *val); |
| 294 | |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 295 | |
| 296 | /** @brief Set the value of the given device-specific attribute |
| 297 | * @param dev A pointer to an iio_device structure |
Paul Cercueil | 30606d5 | 2014-04-14 16:04:15 +0200 | [diff] [blame] | 298 | * @param attr A NULL-terminated string corresponding to the name of the |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 299 | * attribute |
| 300 | * @param src A NULL-terminated string to set the attribute to |
| 301 | * @return On success, the number of bytes written |
| 302 | * @return On error, a negative errno code is returned */ |
Paul Cercueil | b4afdd9 | 2014-04-08 12:37:21 +0200 | [diff] [blame] | 303 | __api ssize_t iio_device_attr_write(const struct iio_device *dev, |
| 304 | const char *attr, const char *src); |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 305 | |
| 306 | |
| 307 | /** @brief Set the value of the given device-specific attribute |
| 308 | * @param dev A pointer to an iio_device structure |
Paul Cercueil | 30606d5 | 2014-04-14 16:04:15 +0200 | [diff] [blame] | 309 | * @param attr A NULL-terminated string corresponding to the name of the |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 310 | * attribute |
| 311 | * @param val A bool value to set the attribute to |
| 312 | * @return On success, 0 is returned |
| 313 | * @return On error, a negative errno code is returned */ |
Paul Cercueil | b4afdd9 | 2014-04-08 12:37:21 +0200 | [diff] [blame] | 314 | __api int iio_device_attr_write_bool(const struct iio_device *dev, |
| 315 | const char *attr, bool val); |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 316 | |
| 317 | |
| 318 | /** @brief Set the value of the given device-specific attribute |
| 319 | * @param dev A pointer to an iio_device structure |
Paul Cercueil | 30606d5 | 2014-04-14 16:04:15 +0200 | [diff] [blame] | 320 | * @param attr A NULL-terminated string corresponding to the name of the |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 321 | * attribute |
| 322 | * @param val A long long value to set the attribute to |
| 323 | * @return On success, 0 is returned |
| 324 | * @return On error, a negative errno code is returned */ |
Paul Cercueil | b4afdd9 | 2014-04-08 12:37:21 +0200 | [diff] [blame] | 325 | __api int iio_device_attr_write_longlong(const struct iio_device *dev, |
| 326 | const char *attr, long long val); |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 327 | |
| 328 | |
| 329 | /** @brief Set the value of the given device-specific attribute |
| 330 | * @param dev A pointer to an iio_device structure |
Paul Cercueil | 30606d5 | 2014-04-14 16:04:15 +0200 | [diff] [blame] | 331 | * @param attr A NULL-terminated string corresponding to the name of the |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 332 | * attribute |
| 333 | * @param val A double value to set the attribute to |
| 334 | * @return On success, 0 is returned |
| 335 | * @return On error, a negative errno code is returned */ |
Paul Cercueil | b4afdd9 | 2014-04-08 12:37:21 +0200 | [diff] [blame] | 336 | __api int iio_device_attr_write_double(const struct iio_device *dev, |
| 337 | const char *attr, double val); |
| 338 | |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 339 | |
| 340 | /** @brief Associate a pointer to an iio_device structure |
| 341 | * @param dev A pointer to an iio_device structure |
| 342 | * @param data The pointer to be associated */ |
Paul Cercueil | b4afdd9 | 2014-04-08 12:37:21 +0200 | [diff] [blame] | 343 | __api void iio_device_set_data(struct iio_device *dev, void *data); |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 344 | |
| 345 | |
| 346 | /** @brief Retrieve a previously associated pointer of an iio_device structure |
| 347 | * @param dev A pointer to an iio_device structure |
| 348 | * @return The pointer previously associated if present, or NULL */ |
Paul Cercueil | b4afdd9 | 2014-04-08 12:37:21 +0200 | [diff] [blame] | 349 | __api void * iio_device_get_data(const struct iio_device *dev); |
| 350 | |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 351 | |
| 352 | /** @brief Retrieve the trigger of a given device |
| 353 | * @param dev A pointer to an iio_device structure |
| 354 | * @param trigger a pointer to a pointer of an iio_device structure. The pointed |
| 355 | * pointer will be set to the address of the iio_device structure corresponding |
| 356 | * to the associated trigger device. |
| 357 | * @return On success, 0 is returned |
| 358 | * @return On error, a negative errno code is returned */ |
Paul Cercueil | 59f2aa3 | 2014-04-04 16:28:51 +0200 | [diff] [blame] | 359 | __api int iio_device_get_trigger(const struct iio_device *dev, |
Paul Cercueil | 24ffa53 | 2014-03-10 12:39:58 +0100 | [diff] [blame] | 360 | const struct iio_device **trigger); |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 361 | |
| 362 | |
| 363 | /** @brief Associate a trigger to a given device |
| 364 | * @param dev A pointer to an iio_device structure |
| 365 | * @param trigger a pointer to the iio_device structure corresponding to the |
| 366 | * trigger that should be associated. |
| 367 | * @return On success, 0 is returned |
| 368 | * @return On error, a negative errno code is returned */ |
Paul Cercueil | 59f2aa3 | 2014-04-04 16:28:51 +0200 | [diff] [blame] | 369 | __api int iio_device_set_trigger(const struct iio_device *dev, |
Paul Cercueil | 24ffa53 | 2014-03-10 12:39:58 +0100 | [diff] [blame] | 370 | const struct iio_device *trigger); |
Paul Cercueil | 0b2ce71 | 2014-02-17 15:04:18 +0100 | [diff] [blame] | 371 | |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 372 | |
| 373 | /** @brief Return True if the given device is a trigger |
| 374 | * @param dev A pointer to an iio_device structure |
| 375 | * @return True if the device is a trigger, False otherwise */ |
Paul Cercueil | b4afdd9 | 2014-04-08 12:37:21 +0200 | [diff] [blame] | 376 | __api __pure bool iio_device_is_trigger(const struct iio_device *dev); |
| 377 | |
Paul Cercueil | b4afdd9 | 2014-04-08 12:37:21 +0200 | [diff] [blame] | 378 | |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 379 | /** @} *//* ------------------------------------------------------------------*/ |
Paul Cercueil | b4afdd9 | 2014-04-08 12:37:21 +0200 | [diff] [blame] | 380 | /* ------------------------- Channel functions -------------------------------*/ |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 381 | /** @defgroup Channel Channel |
| 382 | * @{ |
| 383 | * @struct iio_channel |
| 384 | * @brief Represents an input or output channel of a device */ |
Paul Cercueil | b4afdd9 | 2014-04-08 12:37:21 +0200 | [diff] [blame] | 385 | |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 386 | |
| 387 | /** @brief Retrieve the channel ID (e.g. <b><i>voltage0</i></b>) |
| 388 | * @param chn A pointer to an iio_channel structure |
| 389 | * @return A pointer to a static NULL-terminated string */ |
Paul Cercueil | b4afdd9 | 2014-04-08 12:37:21 +0200 | [diff] [blame] | 390 | __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] | 391 | |
| 392 | |
| 393 | /** @brief Retrieve the channel name (e.g. <b><i>vccint</i></b>) |
| 394 | * @param chn A pointer to an iio_channel structure |
| 395 | * @return A pointer to a static NULL-terminated string |
| 396 | * |
| 397 | * <b>NOTE:</b> if the channel has no name, NULL is returned. */ |
Paul Cercueil | b4afdd9 | 2014-04-08 12:37:21 +0200 | [diff] [blame] | 398 | __api __pure const char * iio_channel_get_name(const struct iio_channel *chn); |
| 399 | |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 400 | |
| 401 | /** @brief Return True if the given channel is an output channel |
| 402 | * @param chn A pointer to an iio_channel structure |
| 403 | * @return True if the channel is an output channel, False otherwise */ |
Paul Cercueil | b4afdd9 | 2014-04-08 12:37:21 +0200 | [diff] [blame] | 404 | __api __pure bool iio_channel_is_output(const struct iio_channel *chn); |
| 405 | |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 406 | |
Paul Cercueil | 85aaf48 | 2014-04-24 16:39:09 +0200 | [diff] [blame^] | 407 | /** @brief Return True if the given channel is a scan element |
| 408 | * @param chn A pointer to an iio_channel structure |
| 409 | * @return True if the channel is a scan element, False otherwise |
| 410 | * |
| 411 | * <b>NOTE:</b> a channel that is a scan element is a channel that can |
| 412 | * generate samples (for an input channel) or receive samples (for an output |
| 413 | * channel) after being enabled. */ |
| 414 | __api __pure bool iio_channel_is_scan_element(const struct iio_channel *chn); |
| 415 | |
| 416 | |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 417 | /** @brief Enumerate the channel-specific attributes of the given channel |
| 418 | * @param chn A pointer to an iio_channel structure |
| 419 | * @return The number of channel-specific attributes found */ |
Paul Cercueil | b4afdd9 | 2014-04-08 12:37:21 +0200 | [diff] [blame] | 420 | __api __pure unsigned int iio_channel_get_attrs_count( |
| 421 | const struct iio_channel *chn); |
| 422 | |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 423 | |
| 424 | /** @brief Get the channel-specific attribute present at the given index |
| 425 | * @param chn A pointer to an iio_channel structure |
| 426 | * @param index The index corresponding to the attribute |
| 427 | * @return On success, a pointer to a static NULL-terminated string |
| 428 | * @return If the index is invalid, NULL is returned */ |
Paul Cercueil | b4afdd9 | 2014-04-08 12:37:21 +0200 | [diff] [blame] | 429 | __api __pure const char * iio_channel_get_attr( |
| 430 | const struct iio_channel *chn, unsigned int index); |
| 431 | |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 432 | |
| 433 | /** @brief Try to find a channel-specific attribute by its name |
| 434 | * @param chn A pointer to an iio_channel structure |
Paul Cercueil | 30606d5 | 2014-04-14 16:04:15 +0200 | [diff] [blame] | 435 | * @param name A NULL-terminated string corresponding to the name of the |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 436 | * attribute |
| 437 | * @return On success, a pointer to a static NULL-terminated string |
| 438 | * @return If the name does not correspond to any known attribute of the given |
| 439 | * channel, NULL is returned |
| 440 | * |
| 441 | * <b>NOTE:</b> This function is useful to detect the presence of an attribute. |
| 442 | * It can also be used to retrieve the name of an attribute as a pointer to a |
| 443 | * static string from a dynamically allocated string. */ |
Paul Cercueil | b4afdd9 | 2014-04-08 12:37:21 +0200 | [diff] [blame] | 444 | __api __pure const char * iio_channel_find_attr( |
| 445 | const struct iio_channel *chn, const char *name); |
| 446 | |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 447 | |
| 448 | /** @brief Read the content of the given channel-specific attribute |
| 449 | * @param chn A pointer to an iio_channel structure |
Paul Cercueil | 30606d5 | 2014-04-14 16:04:15 +0200 | [diff] [blame] | 450 | * @param attr A NULL-terminated string corresponding to the name of the |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 451 | * attribute |
| 452 | * @param dst A pointer to the memory area where the NULL-terminated string |
| 453 | * corresponding to the value read will be stored |
| 454 | * @param len The available length of the memory area, in bytes |
| 455 | * @return On success, the number of bytes written to the buffer |
| 456 | * @return On error, a negative errno code is returned */ |
Paul Cercueil | b4afdd9 | 2014-04-08 12:37:21 +0200 | [diff] [blame] | 457 | __api ssize_t iio_channel_attr_read(const struct iio_channel *chn, |
| 458 | const char *attr, char *dst, size_t len); |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 459 | |
| 460 | |
| 461 | /** @brief Read the content of the given channel-specific attribute |
| 462 | * @param chn A pointer to an iio_channel structure |
Paul Cercueil | 30606d5 | 2014-04-14 16:04:15 +0200 | [diff] [blame] | 463 | * @param attr A NULL-terminated string corresponding to the name of the |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 464 | * attribute |
| 465 | * @param val A pointer to a bool variable where the value should be stored |
| 466 | * @return On success, 0 is returned |
| 467 | * @return On error, a negative errno code is returned */ |
Paul Cercueil | b4afdd9 | 2014-04-08 12:37:21 +0200 | [diff] [blame] | 468 | __api int iio_channel_attr_read_bool(const struct iio_channel *chn, |
| 469 | const char *attr, bool *val); |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 470 | |
| 471 | |
| 472 | /** @brief Read the content of the given channel-specific attribute |
| 473 | * @param chn A pointer to an iio_channel structure |
Paul Cercueil | 30606d5 | 2014-04-14 16:04:15 +0200 | [diff] [blame] | 474 | * @param attr A NULL-terminated string corresponding to the name of the |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 475 | * attribute |
| 476 | * @param val A pointer to a long long variable where the value should be stored |
| 477 | * @return On success, 0 is returned |
| 478 | * @return On error, a negative errno code is returned */ |
Paul Cercueil | b4afdd9 | 2014-04-08 12:37:21 +0200 | [diff] [blame] | 479 | __api int iio_channel_attr_read_longlong(const struct iio_channel *chn, |
| 480 | const char *attr, long long *val); |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 481 | |
| 482 | |
| 483 | /** @brief Read the content of the given channel-specific attribute |
| 484 | * @param chn A pointer to an iio_channel structure |
Paul Cercueil | 30606d5 | 2014-04-14 16:04:15 +0200 | [diff] [blame] | 485 | * @param attr A NULL-terminated string corresponding to the name of the |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 486 | * attribute |
| 487 | * @param val A pointer to a double variable where the value should be stored |
| 488 | * @return On success, 0 is returned |
| 489 | * @return On error, a negative errno code is returned */ |
Paul Cercueil | b4afdd9 | 2014-04-08 12:37:21 +0200 | [diff] [blame] | 490 | __api int iio_channel_attr_read_double(const struct iio_channel *chn, |
| 491 | const char *attr, double *val); |
| 492 | |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 493 | |
| 494 | /** @brief Set the value of the given channel-specific attribute |
| 495 | * @param chn A pointer to an iio_channel structure |
Paul Cercueil | 30606d5 | 2014-04-14 16:04:15 +0200 | [diff] [blame] | 496 | * @param attr A NULL-terminated string corresponding to the name of the |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 497 | * attribute |
| 498 | * @param src A NULL-terminated string to set the attribute to |
| 499 | * @return On success, the number of bytes written |
| 500 | * @return On error, a negative errno code is returned */ |
Paul Cercueil | b4afdd9 | 2014-04-08 12:37:21 +0200 | [diff] [blame] | 501 | __api ssize_t iio_channel_attr_write(const struct iio_channel *chn, |
| 502 | const char *attr, const char *src); |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 503 | |
| 504 | |
| 505 | /** @brief Set the value of the given channel-specific attribute |
| 506 | * @param chn A pointer to an iio_channel structure |
Paul Cercueil | 30606d5 | 2014-04-14 16:04:15 +0200 | [diff] [blame] | 507 | * @param attr A NULL-terminated string corresponding to the name of the |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 508 | * attribute |
| 509 | * @param val A bool value to set the attribute to |
| 510 | * @return On success, 0 is returned |
| 511 | * @return On error, a negative errno code is returned */ |
Paul Cercueil | b4afdd9 | 2014-04-08 12:37:21 +0200 | [diff] [blame] | 512 | __api int iio_channel_attr_write_bool(const struct iio_channel *chn, |
| 513 | const char *attr, bool val); |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 514 | |
| 515 | |
| 516 | /** @brief Set the value of the given channel-specific attribute |
| 517 | * @param chn A pointer to an iio_channel structure |
Paul Cercueil | 30606d5 | 2014-04-14 16:04:15 +0200 | [diff] [blame] | 518 | * @param attr A NULL-terminated string corresponding to the name of the |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 519 | * attribute |
| 520 | * @param val A long long value to set the attribute to |
| 521 | * @return On success, 0 is returned |
| 522 | * @return On error, a negative errno code is returned */ |
Paul Cercueil | b4afdd9 | 2014-04-08 12:37:21 +0200 | [diff] [blame] | 523 | __api int iio_channel_attr_write_longlong(const struct iio_channel *chn, |
| 524 | const char *attr, long long val); |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 525 | |
| 526 | |
| 527 | /** @brief Set the value of the given channel-specific attribute |
| 528 | * @param chn A pointer to an iio_channel structure |
Paul Cercueil | 30606d5 | 2014-04-14 16:04:15 +0200 | [diff] [blame] | 529 | * @param attr A NULL-terminated string corresponding to the name of the |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 530 | * attribute |
| 531 | * @param val A double value to set the attribute to |
| 532 | * @return On success, 0 is returned |
| 533 | * @return On error, a negative errno code is returned */ |
Paul Cercueil | b4afdd9 | 2014-04-08 12:37:21 +0200 | [diff] [blame] | 534 | __api int iio_channel_attr_write_double(const struct iio_channel *chn, |
| 535 | const char *attr, double val); |
| 536 | |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 537 | |
| 538 | /** @brief Enable the given channel |
| 539 | * @param chn A pointer to an iio_channel structure |
| 540 | * |
| 541 | * <b>NOTE:</b>Before creating an iio_buffer structure with |
| 542 | * iio_device_create_buffer, it is required to enable at least one channel of |
| 543 | * the device to read from. */ |
Paul Cercueil | b4afdd9 | 2014-04-08 12:37:21 +0200 | [diff] [blame] | 544 | __api void iio_channel_enable(struct iio_channel *chn); |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 545 | |
| 546 | |
| 547 | /** @brief Disable the given channel |
| 548 | * @param chn A pointer to an iio_channel structure */ |
Paul Cercueil | b4afdd9 | 2014-04-08 12:37:21 +0200 | [diff] [blame] | 549 | __api void iio_channel_disable(struct iio_channel *chn); |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 550 | |
| 551 | |
| 552 | /** @brief Returns True if the channel is enabled |
| 553 | * @param chn A pointer to an iio_channel structure |
| 554 | * @return True if the channel is enabled, False otherwise */ |
Paul Cercueil | b4afdd9 | 2014-04-08 12:37:21 +0200 | [diff] [blame] | 555 | __api bool iio_channel_is_enabled(const struct iio_channel *chn); |
| 556 | |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 557 | |
| 558 | /** Demultiplex the samples of a given channel |
| 559 | * @param chn A pointer to an iio_channel structure |
| 560 | * @param buffer A pointer to an iio_buffer structure |
| 561 | * @param dst A pointer to the memory area where the demultiplexed data will be |
| 562 | * stored |
| 563 | * @param len The available length of the memory area, in bytes |
| 564 | * @return The size of the demultiplexed data, in bytes */ |
Paul Cercueil | b4afdd9 | 2014-04-08 12:37:21 +0200 | [diff] [blame] | 565 | __api size_t iio_channel_read_raw(const struct iio_channel *chn, |
| 566 | struct iio_buffer *buffer, void *dst, size_t len); |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 567 | |
| 568 | |
| 569 | /** Demultiplex and convert the samples of a given channel |
| 570 | * @param chn A pointer to an iio_channel structure |
| 571 | * @param buffer A pointer to an iio_buffer structure |
| 572 | * @param dst A pointer to the memory area where the converted data will be |
| 573 | * stored |
| 574 | * @param len The available length of the memory area, in bytes |
| 575 | * @return The size of the converted data, in bytes */ |
Paul Cercueil | b4afdd9 | 2014-04-08 12:37:21 +0200 | [diff] [blame] | 576 | __api size_t iio_channel_read(const struct iio_channel *chn, |
| 577 | struct iio_buffer *buffer, void *dst, size_t len); |
| 578 | |
| 579 | |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 580 | /** Multiplex the samples of a given channel |
| 581 | * @param chn A pointer to an iio_channel structure |
| 582 | * @param buffer A pointer to an iio_buffer structure |
| 583 | * @param src A pointer to the memory area where the sequential data will |
| 584 | * be read from |
| 585 | * @param len The length of the memory area, in bytes |
| 586 | * @return The number of bytes actually multiplexed */ |
Paul Cercueil | b4afdd9 | 2014-04-08 12:37:21 +0200 | [diff] [blame] | 587 | __api size_t iio_channel_write_raw(const struct iio_channel *chn, |
| 588 | struct iio_buffer *buffer, const void *src, size_t len); |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 589 | |
| 590 | |
| 591 | /** Convert and multiplex the samples of a given channel |
| 592 | * @param chn A pointer to an iio_channel structure |
| 593 | * @param buffer A pointer to an iio_buffer structure |
| 594 | * @param src A pointer to the memory area where the sequential data will |
| 595 | * be read from |
| 596 | * @param len The length of the memory area, in bytes |
| 597 | * @return The number of bytes actually converted and multiplexed */ |
Paul Cercueil | b4afdd9 | 2014-04-08 12:37:21 +0200 | [diff] [blame] | 598 | __api size_t iio_channel_write(const struct iio_channel *chn, |
| 599 | struct iio_buffer *buffer, const void *src, size_t len); |
| 600 | |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 601 | |
| 602 | /** @brief Associate a pointer to an iio_channel structure |
| 603 | * @param chn A pointer to an iio_channel structure |
| 604 | * @param data The pointer to be associated */ |
Paul Cercueil | b4afdd9 | 2014-04-08 12:37:21 +0200 | [diff] [blame] | 605 | __api void iio_channel_set_data(struct iio_channel *chn, void *data); |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 606 | |
| 607 | |
| 608 | /** @brief Retrieve a previously associated pointer of an iio_channel structure |
| 609 | * @param chn A pointer to an iio_channel structure |
| 610 | * @return The pointer previously associated if present, or NULL */ |
Paul Cercueil | b4afdd9 | 2014-04-08 12:37:21 +0200 | [diff] [blame] | 611 | __api void * iio_channel_get_data(const struct iio_channel *chn); |
| 612 | |
| 613 | |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 614 | /** @} *//* ------------------------------------------------------------------*/ |
Paul Cercueil | b4afdd9 | 2014-04-08 12:37:21 +0200 | [diff] [blame] | 615 | /* ------------------------- Buffer functions --------------------------------*/ |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 616 | /** @defgroup Buffer Buffer |
| 617 | * @{ |
| 618 | * @struct iio_buffer |
| 619 | * @brief An input or output buffer, used to read or write samples */ |
Paul Cercueil | b4afdd9 | 2014-04-08 12:37:21 +0200 | [diff] [blame] | 620 | |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 621 | |
| 622 | /** @brief Create an input or output buffer associated to the given device |
| 623 | * @param dev A pointer to an iio_device structure |
| 624 | * @param samples_count The number of samples that the buffer should contain |
| 625 | * @param is_output A boolean value which should be True if the buffer is an |
| 626 | * output buffer (to write samples to the hardware) or False if the buffer is an |
| 627 | * input buffer (to read samples from the hardware) |
| 628 | * @return On success, a pointer to an iio_buffer structure |
| 629 | * @return On error, NULL is returned |
| 630 | * |
| 631 | * <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] | 632 | * before creating the buffer. */ |
| 633 | __api struct iio_buffer * iio_device_create_buffer(const struct iio_device *dev, |
| 634 | size_t samples_count, bool is_output); |
| 635 | |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 636 | |
| 637 | /** @brief Destroy the given buffer |
| 638 | * @param buf A pointer to an iio_buffer structure |
| 639 | * |
| 640 | * <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] | 641 | __api void iio_buffer_destroy(struct iio_buffer *buf); |
| 642 | |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 643 | |
| 644 | /** @brief Fetch more samples from the hardware |
| 645 | * @param buf A pointer to an iio_buffer structure |
| 646 | * @return On success, the number of bytes read is returned |
| 647 | * @return On error, a negative errno code is returned |
| 648 | * |
| 649 | * <b>NOTE:</b> Only valid for input buffers */ |
Paul Cercueil | b4afdd9 | 2014-04-08 12:37:21 +0200 | [diff] [blame] | 650 | __api ssize_t iio_buffer_refill(struct iio_buffer *buf); |
| 651 | |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 652 | |
| 653 | /** @brief Send the samples to the hardware |
| 654 | * @param buf A pointer to an iio_buffer structure |
| 655 | * @return On success, the number of bytes written is returned |
| 656 | * @return On error, a negative errno code is returned |
| 657 | * |
| 658 | * <b>NOTE:</b> Only valid for output buffers */ |
Paul Cercueil | ea32b04 | 2014-04-11 13:47:12 +0200 | [diff] [blame] | 659 | __api ssize_t iio_buffer_push(const struct iio_buffer *buf); |
Paul Cercueil | b4afdd9 | 2014-04-08 12:37:21 +0200 | [diff] [blame] | 660 | |
Paul Cercueil | b4afdd9 | 2014-04-08 12:37:21 +0200 | [diff] [blame] | 661 | |
Paul Cercueil | 6d92716 | 2014-04-16 15:53:22 +0200 | [diff] [blame] | 662 | /** @brief Get the start address of the buffer |
| 663 | * @param buf A pointer to an iio_buffer structure |
| 664 | * @return A pointer corresponding to the start address of the buffer */ |
| 665 | __api __pure void * iio_buffer_start(const struct iio_buffer *buf); |
| 666 | |
| 667 | |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 668 | /** @brief Find the first sample of a channel in a buffer |
| 669 | * @param buf A pointer to an iio_buffer structure |
| 670 | * @param chn A pointer to an iio_channel structure |
| 671 | * @return A pointer to the first sample found, or to the end of the buffer if |
| 672 | * no sample for the given channel is present in the buffer |
| 673 | * |
| 674 | * <b>NOTE:</b> This fonction, coupled with iio_buffer_step and iio_buffer_end, |
| 675 | * can be used to iterate on all the samples of a given channel present in the |
| 676 | * buffer, doing the following: |
| 677 | * |
| 678 | * @verbatim |
| 679 | for (void *ptr = iio_buffer_first(buffer, chn); ptr < iio_buffer_end(buffer); ptr += iio_buffer_step(buffer)) { |
| 680 | .... |
| 681 | } |
| 682 | @endverbatim */ |
| 683 | __api void * iio_buffer_first(const struct iio_buffer *buf, |
| 684 | const struct iio_channel *chn); |
| 685 | |
| 686 | |
| 687 | /** @brief Get the step size between two samples of one channel |
| 688 | * @param buf A pointer to an iio_buffer structure |
| 689 | * @return the difference between the addresses of two consecutive samples of |
| 690 | * one same channel */ |
| 691 | __api ptrdiff_t iio_buffer_step(const struct iio_buffer *buf); |
| 692 | |
| 693 | |
| 694 | /** @brief Get the address that follows the last sample in a buffer |
| 695 | * @param buf A pointer to an iio_buffer structure |
| 696 | * @return A pointer corresponding to the address that follows the last sample |
| 697 | * present in the buffer */ |
| 698 | __api void * iio_buffer_end(const struct iio_buffer *buf); |
| 699 | |
| 700 | |
| 701 | /** @brief Call the supplied callback for each sample found in a buffer |
| 702 | * @param buf A pointer to an iio_buffer structure |
| 703 | * @param callback A pointer to a function to call for each sample found |
| 704 | * @param data A user-specified pointer that will be passed to the callback |
| 705 | * |
| 706 | * <b>NOTE:</b> The callback receives four arguments: |
| 707 | * * A pointer to the iio_channel structure corresponding to the sample, |
| 708 | * * A pointer to the sample itself, |
| 709 | * * The length of the sample in bytes, |
| 710 | * * The user-specified pointer passed to iio_buffer_foreach_sample. */ |
Paul Cercueil | b4afdd9 | 2014-04-08 12:37:21 +0200 | [diff] [blame] | 711 | __api ssize_t iio_buffer_foreach_sample(struct iio_buffer *buf, |
| 712 | ssize_t (*callback)(const struct iio_channel *chn, |
| 713 | void *src, size_t bytes, void *d), void *data); |
| 714 | |
| 715 | |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 716 | /** @} *//* ------------------------------------------------------------------*/ |
Paul Cercueil | b4afdd9 | 2014-04-08 12:37:21 +0200 | [diff] [blame] | 717 | /* ------------------------- Low-level functions -----------------------------*/ |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 718 | /** @defgroup Debug Debug and low-level functions |
| 719 | * @{ |
| 720 | * @struct iio_data_format |
| 721 | * @brief Contains the format of a data sample. |
| 722 | * |
| 723 | * The different fields inform about the correct way to convert one sample from |
| 724 | * its raw format (as read from / generated by the hardware) to its real-world |
| 725 | * value. |
| 726 | */ |
| 727 | struct iio_data_format { |
| 728 | /** @brief Total length of the sample, in bits */ |
| 729 | unsigned int length; |
Paul Cercueil | b4afdd9 | 2014-04-08 12:37:21 +0200 | [diff] [blame] | 730 | |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 731 | /** @brief Length of valuable data in the sample, in bits */ |
| 732 | unsigned int bits; |
| 733 | |
| 734 | /** @brief Right-shift to apply when converting sample */ |
| 735 | unsigned int shift; |
| 736 | |
| 737 | /** @brief Contains True if the sample is signed */ |
| 738 | bool is_signed; |
| 739 | |
| 740 | /** @brief Contains True if the sample is in big-endian format */ |
| 741 | bool is_be; |
| 742 | |
| 743 | /** @brief Contains True if the sample should be scaled when converted */ |
| 744 | bool with_scale; |
| 745 | |
| 746 | /** @brief Contains the scale to apply if with_scale is set */ |
| 747 | double scale; |
| 748 | }; |
| 749 | |
| 750 | |
| 751 | /** @brief Open the given device |
| 752 | * @param dev A pointer to an iio_device structure |
| 753 | * @param samples_count The size of the kernel buffer, in samples |
| 754 | * @return On success, 0 is returned |
| 755 | * @return On error, a negative errno code is returned |
| 756 | * |
| 757 | * <b>NOTE:</b> This is not required when using the iio_buffer functions; it is |
| 758 | * only useful when used with iio_device_read_raw / iio_device_write_raw. */ |
Paul Cercueil | 59f2aa3 | 2014-04-04 16:28:51 +0200 | [diff] [blame] | 759 | __api int iio_device_open(const struct iio_device *dev, size_t samples_count); |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 760 | |
| 761 | |
| 762 | /** @brief Close the given device |
| 763 | * @param dev A pointer to an iio_device structure |
| 764 | * @return On success, 0 is returned |
| 765 | * @return On error, a negative errno code is returned |
| 766 | * |
| 767 | * <b>NOTE:</b> This is not required when using the iio_buffer functions; it is |
| 768 | * only useful when used with iio_device_read_raw / iio_device_write_raw. */ |
Paul Cercueil | 59f2aa3 | 2014-04-04 16:28:51 +0200 | [diff] [blame] | 769 | __api int iio_device_close(const struct iio_device *dev); |
Paul Cercueil | ec1760d | 2014-02-21 11:31:20 +0100 | [diff] [blame] | 770 | |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 771 | |
| 772 | /** @brief Get the current sample size |
| 773 | * @param dev A pointer to an iio_device structure |
| 774 | * @return On success, the sample size in bytes |
| 775 | * @return On error, a negative errno code is returned |
| 776 | * |
| 777 | * <b>NOTE:</b> The sample size is not constant and will change when channels |
| 778 | * get enabled or disabled. */ |
Paul Cercueil | 59f2aa3 | 2014-04-04 16:28:51 +0200 | [diff] [blame] | 779 | __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] | 780 | |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 781 | |
| 782 | /** @brief Get the index of the given channel |
| 783 | * @param chn A pointer to an iio_channel structure |
| 784 | * @return On success, the index of the specified channel |
| 785 | * @return On error, a negative errno code is returned */ |
Paul Cercueil | 59f2aa3 | 2014-04-04 16:28:51 +0200 | [diff] [blame] | 786 | __api __pure long iio_channel_get_index(const struct iio_channel *chn); |
Paul Cercueil | b4afdd9 | 2014-04-08 12:37:21 +0200 | [diff] [blame] | 787 | |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 788 | |
| 789 | /** @brief Get a pointer to a channel's data format structure |
| 790 | * @param chn A pointer to an iio_channel structure |
| 791 | * @return A pointer to the channel's iio_data_format structure */ |
Paul Cercueil | 59f2aa3 | 2014-04-04 16:28:51 +0200 | [diff] [blame] | 792 | __api __cnst const struct iio_data_format * iio_channel_get_data_format( |
| 793 | const struct iio_channel *chn); |
Paul Cercueil | 0b2ce71 | 2014-02-17 15:04:18 +0100 | [diff] [blame] | 794 | |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 795 | |
| 796 | /** @brief Convert the sample from hardware format to host format |
| 797 | * @param chn A pointer to an iio_channel structure |
| 798 | * @param dst A pointer to the destination buffer where the converted sample |
| 799 | * should be written |
| 800 | * @param src A pointer to the source buffer containing the sample */ |
Paul Cercueil | 59f2aa3 | 2014-04-04 16:28:51 +0200 | [diff] [blame] | 801 | __api void iio_channel_convert(const struct iio_channel *chn, |
Paul Cercueil | 2917ffb | 2014-03-21 15:47:12 +0100 | [diff] [blame] | 802 | void *dst, const void *src); |
| 803 | |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 804 | |
| 805 | /** @brief Convert the sample from host format to hardware format |
| 806 | * @param chn A pointer to an iio_channel structure |
| 807 | * @param dst A pointer to the destination buffer where the converted sample |
| 808 | * should be written |
| 809 | * @param src A pointer to the source buffer containing the sample */ |
Paul Cercueil | d840d4c | 2014-04-07 19:38:58 +0200 | [diff] [blame] | 810 | __api void iio_channel_convert_inverse(const struct iio_channel *chn, |
| 811 | void *dst, const void *src); |
| 812 | |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 813 | |
| 814 | /** @brief Read the raw stream from the given device |
| 815 | * @param dev A pointer to an iio_device structure |
| 816 | * @param dst A pointer to the destination buffer where to write the stream |
| 817 | * @param len The length of the destination buffer, in bytes |
| 818 | * @param mask A pointer to a memory area where the channel mask will be stored |
| 819 | * @param words The number of 32-bit words composing the mask |
| 820 | * @return On success, the number of bytes read |
| 821 | * @return On error, a negative errno code is returned |
| 822 | * |
| 823 | * <b>NOTE:</b> The device must be opened first (with iio_device_open). |
| 824 | * |
| 825 | * The "words" param should correspond to (number of channels + 31) / 32. |
| 826 | * The area pointed by "mask" will be initialized like this: |
| 827 | * @verbatim |
| 828 | mask[chn.index / 32][chn.index % 32] = is_enabled |
| 829 | @endverbatim |
| 830 | * Note that the mask can change anytime between two calls, even if no channel |
| 831 | * of the specified device have been enabled or disabled in the meantime. */ |
Paul Cercueil | 59f2aa3 | 2014-04-04 16:28:51 +0200 | [diff] [blame] | 832 | __api ssize_t iio_device_read_raw(const struct iio_device *dev, |
Paul Cercueil | 45c575d | 2014-03-20 15:14:01 +0100 | [diff] [blame] | 833 | void *dst, size_t len, uint32_t *mask, size_t words); |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 834 | |
| 835 | |
| 836 | /** @brief Write a raw stream to the given device |
| 837 | * @param dev A pointer to an iio_device structure |
| 838 | * @param src A pointer to the source buffer where to read the stream from |
| 839 | * @param len The length of the input buffer, in bytes |
| 840 | * @return On success, the number of bytes written |
| 841 | * @return On error, a negative errno code is returned |
| 842 | * |
| 843 | * <b>NOTE:</b> The device must be opened first (with iio_device_open). */ |
Paul Cercueil | 59f2aa3 | 2014-04-04 16:28:51 +0200 | [diff] [blame] | 844 | __api ssize_t iio_device_write_raw(const struct iio_device *dev, |
Paul Cercueil | 0b2ce71 | 2014-02-17 15:04:18 +0100 | [diff] [blame] | 845 | const void *src, size_t len); |
| 846 | |
Paul Cercueil | 99b07cc | 2014-04-14 16:07:32 +0200 | [diff] [blame] | 847 | |
Paul Cercueil | 1ce35ef | 2014-04-15 12:28:40 +0200 | [diff] [blame] | 848 | /** @brief Enumerate the debug attributes of the given device |
| 849 | * @param dev A pointer to an iio_device structure |
| 850 | * @return The number of debug attributes found */ |
| 851 | __api __pure unsigned int iio_device_get_debug_attrs_count( |
| 852 | const struct iio_device *dev); |
| 853 | |
| 854 | |
| 855 | /** @brief Get the debug attribute present at the given index |
| 856 | * @param dev A pointer to an iio_device structure |
| 857 | * @param index The index corresponding to the debug attribute |
| 858 | * @return On success, a pointer to a static NULL-terminated string |
| 859 | * @return If the index is invalid, NULL is returned */ |
| 860 | __api __pure const char * iio_device_get_debug_attr( |
| 861 | const struct iio_device *dev, unsigned int index); |
| 862 | |
| 863 | |
Paul Cercueil | 99b07cc | 2014-04-14 16:07:32 +0200 | [diff] [blame] | 864 | /** @brief Read the content of the given debug attribute |
| 865 | * @param dev A pointer to an iio_device structure |
| 866 | * @param attr A NULL-terminated string corresponding to the name of the |
| 867 | * debug attribute |
| 868 | * @param dst A pointer to the memory area where the NULL-terminated string |
| 869 | * corresponding to the value read will be stored |
| 870 | * @param len The available length of the memory area, in bytes |
| 871 | * @return On success, the number of bytes written to the buffer |
| 872 | * @return On error, a negative errno code is returned */ |
| 873 | __api ssize_t iio_device_debug_attr_read(const struct iio_device *dev, |
| 874 | const char *attr, char *dst, size_t len); |
| 875 | |
| 876 | |
| 877 | /** @brief Set the value of the given debug attribute |
| 878 | * @param dev A pointer to an iio_device structure |
| 879 | * @param attr A NULL-terminated string corresponding to the name of the |
| 880 | * debug attribute |
| 881 | * @param src A NULL-terminated string to set the debug attribute to |
| 882 | * @return On success, the number of bytes written |
| 883 | * @return On error, a negative errno code is returned */ |
| 884 | __api ssize_t iio_device_debug_attr_write(const struct iio_device *dev, |
| 885 | const char *attr, const char *src); |
| 886 | |
Paul Cercueil | e396074 | 2014-04-15 16:00:50 +0200 | [diff] [blame] | 887 | |
| 888 | /** @brief Read the content of the given debug attribute |
| 889 | * @param dev A pointer to an iio_device structure |
| 890 | * @param attr A NULL-terminated string corresponding to the name of the |
| 891 | * debug attribute |
| 892 | * @param val A pointer to a bool variable where the value should be stored |
| 893 | * @return On success, 0 is returned |
| 894 | * @return On error, a negative errno code is returned */ |
| 895 | __api int iio_device_debug_attr_read_bool(const struct iio_device *dev, |
| 896 | const char *attr, bool *val); |
| 897 | |
| 898 | |
| 899 | /** @brief Read the content of the given debug attribute |
| 900 | * @param dev A pointer to an iio_device structure |
| 901 | * @param attr A NULL-terminated string corresponding to the name of the |
| 902 | * debug attribute |
| 903 | * @param val A pointer to a long long variable where the value should be stored |
| 904 | * @return On success, 0 is returned |
| 905 | * @return On error, a negative errno code is returned */ |
| 906 | __api int iio_device_debug_attr_read_longlong(const struct iio_device *dev, |
| 907 | const char *attr, long long *val); |
| 908 | |
| 909 | |
| 910 | /** @brief Read the content of the given debug attribute |
| 911 | * @param dev A pointer to an iio_device structure |
| 912 | * @param attr A NULL-terminated string corresponding to the name of the |
| 913 | * debug attribute |
| 914 | * @param val A pointer to a double variable where the value should be stored |
| 915 | * @return On success, 0 is returned |
| 916 | * @return On error, a negative errno code is returned */ |
| 917 | __api int iio_device_debug_attr_read_double(const struct iio_device *dev, |
| 918 | const char *attr, double *val); |
| 919 | |
| 920 | |
| 921 | /** @brief Set the value of the given debug attribute |
| 922 | * @param dev A pointer to an iio_device structure |
| 923 | * @param attr A NULL-terminated string corresponding to the name of the |
| 924 | * debug attribute |
| 925 | * @param val A bool value to set the debug attribute to |
| 926 | * @return On success, 0 is returned |
| 927 | * @return On error, a negative errno code is returned */ |
| 928 | __api int iio_device_debug_attr_write_bool(const struct iio_device *dev, |
| 929 | const char *attr, bool val); |
| 930 | |
| 931 | |
| 932 | /** @brief Set the value of the given debug attribute |
| 933 | * @param dev A pointer to an iio_device structure |
| 934 | * @param attr A NULL-terminated string corresponding to the name of the |
| 935 | * debug attribute |
| 936 | * @param val A long long value to set the debug attribute to |
| 937 | * @return On success, 0 is returned |
| 938 | * @return On error, a negative errno code is returned */ |
| 939 | __api int iio_device_debug_attr_write_longlong(const struct iio_device *dev, |
| 940 | const char *attr, long long val); |
| 941 | |
| 942 | |
| 943 | /** @brief Set the value of the given debug attribute |
| 944 | * @param dev A pointer to an iio_device structure |
| 945 | * @param attr A NULL-terminated string corresponding to the name of the |
| 946 | * debug attribute |
| 947 | * @param val A double value to set the debug attribute to |
| 948 | * @return On success, 0 is returned |
| 949 | * @return On error, a negative errno code is returned */ |
| 950 | __api int iio_device_debug_attr_write_double(const struct iio_device *dev, |
| 951 | const char *attr, double val); |
| 952 | |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 953 | /** @} */ |
| 954 | |
Paul Cercueil | a167e0c | 2014-04-08 14:50:41 +0200 | [diff] [blame] | 955 | #ifdef __cplusplus |
| 956 | } |
| 957 | #endif |
| 958 | |
Paul Cercueil | 0b2ce71 | 2014-02-17 15:04:18 +0100 | [diff] [blame] | 959 | #endif /* __IIO_H__ */ |