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 | |
| 407 | /** @brief Enumerate the channel-specific attributes of the given channel |
| 408 | * @param chn A pointer to an iio_channel structure |
| 409 | * @return The number of channel-specific attributes found */ |
Paul Cercueil | b4afdd9 | 2014-04-08 12:37:21 +0200 | [diff] [blame] | 410 | __api __pure unsigned int iio_channel_get_attrs_count( |
| 411 | const struct iio_channel *chn); |
| 412 | |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 413 | |
| 414 | /** @brief Get the channel-specific attribute present at the given index |
| 415 | * @param chn A pointer to an iio_channel structure |
| 416 | * @param index The index corresponding to the attribute |
| 417 | * @return On success, a pointer to a static NULL-terminated string |
| 418 | * @return If the index is invalid, NULL is returned */ |
Paul Cercueil | b4afdd9 | 2014-04-08 12:37:21 +0200 | [diff] [blame] | 419 | __api __pure const char * iio_channel_get_attr( |
| 420 | const struct iio_channel *chn, unsigned int index); |
| 421 | |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 422 | |
| 423 | /** @brief Try to find a channel-specific attribute by its name |
| 424 | * @param chn A pointer to an iio_channel structure |
Paul Cercueil | 30606d5 | 2014-04-14 16:04:15 +0200 | [diff] [blame] | 425 | * @param name A NULL-terminated string corresponding to the name of the |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 426 | * attribute |
| 427 | * @return On success, a pointer to a static NULL-terminated string |
| 428 | * @return If the name does not correspond to any known attribute of the given |
| 429 | * channel, NULL is returned |
| 430 | * |
| 431 | * <b>NOTE:</b> This function is useful to detect the presence of an attribute. |
| 432 | * It can also be used to retrieve the name of an attribute as a pointer to a |
| 433 | * static string from a dynamically allocated string. */ |
Paul Cercueil | b4afdd9 | 2014-04-08 12:37:21 +0200 | [diff] [blame] | 434 | __api __pure const char * iio_channel_find_attr( |
| 435 | const struct iio_channel *chn, const char *name); |
| 436 | |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 437 | |
| 438 | /** @brief Read the content of the given channel-specific attribute |
| 439 | * @param chn A pointer to an iio_channel structure |
Paul Cercueil | 30606d5 | 2014-04-14 16:04:15 +0200 | [diff] [blame] | 440 | * @param attr A NULL-terminated string corresponding to the name of the |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 441 | * attribute |
| 442 | * @param dst A pointer to the memory area where the NULL-terminated string |
| 443 | * corresponding to the value read will be stored |
| 444 | * @param len The available length of the memory area, in bytes |
| 445 | * @return On success, the number of bytes written to the buffer |
| 446 | * @return On error, a negative errno code is returned */ |
Paul Cercueil | b4afdd9 | 2014-04-08 12:37:21 +0200 | [diff] [blame] | 447 | __api ssize_t iio_channel_attr_read(const struct iio_channel *chn, |
| 448 | const char *attr, char *dst, size_t len); |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 449 | |
| 450 | |
| 451 | /** @brief Read the content of the given channel-specific attribute |
| 452 | * @param chn A pointer to an iio_channel structure |
Paul Cercueil | 30606d5 | 2014-04-14 16:04:15 +0200 | [diff] [blame] | 453 | * @param attr A NULL-terminated string corresponding to the name of the |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 454 | * attribute |
| 455 | * @param val A pointer to a bool variable where the value should be stored |
| 456 | * @return On success, 0 is returned |
| 457 | * @return On error, a negative errno code is returned */ |
Paul Cercueil | b4afdd9 | 2014-04-08 12:37:21 +0200 | [diff] [blame] | 458 | __api int iio_channel_attr_read_bool(const struct iio_channel *chn, |
| 459 | const char *attr, bool *val); |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 460 | |
| 461 | |
| 462 | /** @brief Read the content of the given channel-specific attribute |
| 463 | * @param chn A pointer to an iio_channel structure |
Paul Cercueil | 30606d5 | 2014-04-14 16:04:15 +0200 | [diff] [blame] | 464 | * @param attr A NULL-terminated string corresponding to the name of the |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 465 | * attribute |
| 466 | * @param val A pointer to a long long variable where the value should be stored |
| 467 | * @return On success, 0 is returned |
| 468 | * @return On error, a negative errno code is returned */ |
Paul Cercueil | b4afdd9 | 2014-04-08 12:37:21 +0200 | [diff] [blame] | 469 | __api int iio_channel_attr_read_longlong(const struct iio_channel *chn, |
| 470 | const char *attr, long long *val); |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 471 | |
| 472 | |
| 473 | /** @brief Read the content of the given channel-specific attribute |
| 474 | * @param chn A pointer to an iio_channel structure |
Paul Cercueil | 30606d5 | 2014-04-14 16:04:15 +0200 | [diff] [blame] | 475 | * @param attr A NULL-terminated string corresponding to the name of the |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 476 | * attribute |
| 477 | * @param val A pointer to a double variable where the value should be stored |
| 478 | * @return On success, 0 is returned |
| 479 | * @return On error, a negative errno code is returned */ |
Paul Cercueil | b4afdd9 | 2014-04-08 12:37:21 +0200 | [diff] [blame] | 480 | __api int iio_channel_attr_read_double(const struct iio_channel *chn, |
| 481 | const char *attr, double *val); |
| 482 | |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 483 | |
| 484 | /** @brief Set the value of the given channel-specific attribute |
| 485 | * @param chn A pointer to an iio_channel structure |
Paul Cercueil | 30606d5 | 2014-04-14 16:04:15 +0200 | [diff] [blame] | 486 | * @param attr A NULL-terminated string corresponding to the name of the |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 487 | * attribute |
| 488 | * @param src A NULL-terminated string to set the attribute to |
| 489 | * @return On success, the number of bytes written |
| 490 | * @return On error, a negative errno code is returned */ |
Paul Cercueil | b4afdd9 | 2014-04-08 12:37:21 +0200 | [diff] [blame] | 491 | __api ssize_t iio_channel_attr_write(const struct iio_channel *chn, |
| 492 | const char *attr, const char *src); |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 493 | |
| 494 | |
| 495 | /** @brief Set the value of the given channel-specific attribute |
| 496 | * @param chn A pointer to an iio_channel structure |
Paul Cercueil | 30606d5 | 2014-04-14 16:04:15 +0200 | [diff] [blame] | 497 | * @param attr A NULL-terminated string corresponding to the name of the |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 498 | * attribute |
| 499 | * @param val A bool value to set the attribute to |
| 500 | * @return On success, 0 is returned |
| 501 | * @return On error, a negative errno code is returned */ |
Paul Cercueil | b4afdd9 | 2014-04-08 12:37:21 +0200 | [diff] [blame] | 502 | __api int iio_channel_attr_write_bool(const struct iio_channel *chn, |
| 503 | const char *attr, bool val); |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 504 | |
| 505 | |
| 506 | /** @brief Set the value of the given channel-specific attribute |
| 507 | * @param chn A pointer to an iio_channel structure |
Paul Cercueil | 30606d5 | 2014-04-14 16:04:15 +0200 | [diff] [blame] | 508 | * @param attr A NULL-terminated string corresponding to the name of the |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 509 | * attribute |
| 510 | * @param val A long long value to set the attribute to |
| 511 | * @return On success, 0 is returned |
| 512 | * @return On error, a negative errno code is returned */ |
Paul Cercueil | b4afdd9 | 2014-04-08 12:37:21 +0200 | [diff] [blame] | 513 | __api int iio_channel_attr_write_longlong(const struct iio_channel *chn, |
| 514 | const char *attr, long long val); |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 515 | |
| 516 | |
| 517 | /** @brief Set the value of the given channel-specific attribute |
| 518 | * @param chn A pointer to an iio_channel structure |
Paul Cercueil | 30606d5 | 2014-04-14 16:04:15 +0200 | [diff] [blame] | 519 | * @param attr A NULL-terminated string corresponding to the name of the |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 520 | * attribute |
| 521 | * @param val A double value to set the attribute to |
| 522 | * @return On success, 0 is returned |
| 523 | * @return On error, a negative errno code is returned */ |
Paul Cercueil | b4afdd9 | 2014-04-08 12:37:21 +0200 | [diff] [blame] | 524 | __api int iio_channel_attr_write_double(const struct iio_channel *chn, |
| 525 | const char *attr, double val); |
| 526 | |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 527 | |
| 528 | /** @brief Enable the given channel |
| 529 | * @param chn A pointer to an iio_channel structure |
| 530 | * |
| 531 | * <b>NOTE:</b>Before creating an iio_buffer structure with |
| 532 | * iio_device_create_buffer, it is required to enable at least one channel of |
| 533 | * the device to read from. */ |
Paul Cercueil | b4afdd9 | 2014-04-08 12:37:21 +0200 | [diff] [blame] | 534 | __api void iio_channel_enable(struct iio_channel *chn); |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 535 | |
| 536 | |
| 537 | /** @brief Disable the given channel |
| 538 | * @param chn A pointer to an iio_channel structure */ |
Paul Cercueil | b4afdd9 | 2014-04-08 12:37:21 +0200 | [diff] [blame] | 539 | __api void iio_channel_disable(struct iio_channel *chn); |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 540 | |
| 541 | |
| 542 | /** @brief Returns True if the channel is enabled |
| 543 | * @param chn A pointer to an iio_channel structure |
| 544 | * @return True if the channel is enabled, False otherwise */ |
Paul Cercueil | b4afdd9 | 2014-04-08 12:37:21 +0200 | [diff] [blame] | 545 | __api bool iio_channel_is_enabled(const struct iio_channel *chn); |
| 546 | |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 547 | |
| 548 | /** Demultiplex the samples of a given channel |
| 549 | * @param chn A pointer to an iio_channel structure |
| 550 | * @param buffer A pointer to an iio_buffer structure |
| 551 | * @param dst A pointer to the memory area where the demultiplexed data will be |
| 552 | * stored |
| 553 | * @param len The available length of the memory area, in bytes |
| 554 | * @return The size of the demultiplexed data, in bytes */ |
Paul Cercueil | b4afdd9 | 2014-04-08 12:37:21 +0200 | [diff] [blame] | 555 | __api size_t iio_channel_read_raw(const struct iio_channel *chn, |
| 556 | struct iio_buffer *buffer, void *dst, size_t len); |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 557 | |
| 558 | |
| 559 | /** Demultiplex and convert the samples of a given channel |
| 560 | * @param chn A pointer to an iio_channel structure |
| 561 | * @param buffer A pointer to an iio_buffer structure |
| 562 | * @param dst A pointer to the memory area where the converted data will be |
| 563 | * stored |
| 564 | * @param len The available length of the memory area, in bytes |
| 565 | * @return The size of the converted data, in bytes */ |
Paul Cercueil | b4afdd9 | 2014-04-08 12:37:21 +0200 | [diff] [blame] | 566 | __api size_t iio_channel_read(const struct iio_channel *chn, |
| 567 | struct iio_buffer *buffer, void *dst, size_t len); |
| 568 | |
| 569 | |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 570 | /** Multiplex the samples of a given channel |
| 571 | * @param chn A pointer to an iio_channel structure |
| 572 | * @param buffer A pointer to an iio_buffer structure |
| 573 | * @param src A pointer to the memory area where the sequential data will |
| 574 | * be read from |
| 575 | * @param len The length of the memory area, in bytes |
| 576 | * @return The number of bytes actually multiplexed */ |
Paul Cercueil | b4afdd9 | 2014-04-08 12:37:21 +0200 | [diff] [blame] | 577 | __api size_t iio_channel_write_raw(const struct iio_channel *chn, |
| 578 | struct iio_buffer *buffer, const void *src, size_t len); |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 579 | |
| 580 | |
| 581 | /** Convert and multiplex the samples of a given channel |
| 582 | * @param chn A pointer to an iio_channel structure |
| 583 | * @param buffer A pointer to an iio_buffer structure |
| 584 | * @param src A pointer to the memory area where the sequential data will |
| 585 | * be read from |
| 586 | * @param len The length of the memory area, in bytes |
| 587 | * @return The number of bytes actually converted and multiplexed */ |
Paul Cercueil | b4afdd9 | 2014-04-08 12:37:21 +0200 | [diff] [blame] | 588 | __api size_t iio_channel_write(const struct iio_channel *chn, |
| 589 | struct iio_buffer *buffer, const void *src, size_t len); |
| 590 | |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 591 | |
| 592 | /** @brief Associate a pointer to an iio_channel structure |
| 593 | * @param chn A pointer to an iio_channel structure |
| 594 | * @param data The pointer to be associated */ |
Paul Cercueil | b4afdd9 | 2014-04-08 12:37:21 +0200 | [diff] [blame] | 595 | __api void iio_channel_set_data(struct iio_channel *chn, void *data); |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 596 | |
| 597 | |
| 598 | /** @brief Retrieve a previously associated pointer of an iio_channel structure |
| 599 | * @param chn A pointer to an iio_channel structure |
| 600 | * @return The pointer previously associated if present, or NULL */ |
Paul Cercueil | b4afdd9 | 2014-04-08 12:37:21 +0200 | [diff] [blame] | 601 | __api void * iio_channel_get_data(const struct iio_channel *chn); |
| 602 | |
| 603 | |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 604 | /** @} *//* ------------------------------------------------------------------*/ |
Paul Cercueil | b4afdd9 | 2014-04-08 12:37:21 +0200 | [diff] [blame] | 605 | /* ------------------------- Buffer functions --------------------------------*/ |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 606 | /** @defgroup Buffer Buffer |
| 607 | * @{ |
| 608 | * @struct iio_buffer |
| 609 | * @brief An input or output buffer, used to read or write samples */ |
Paul Cercueil | b4afdd9 | 2014-04-08 12:37:21 +0200 | [diff] [blame] | 610 | |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 611 | |
| 612 | /** @brief Create an input or output buffer associated to the given device |
| 613 | * @param dev A pointer to an iio_device structure |
| 614 | * @param samples_count The number of samples that the buffer should contain |
| 615 | * @param is_output A boolean value which should be True if the buffer is an |
| 616 | * output buffer (to write samples to the hardware) or False if the buffer is an |
| 617 | * input buffer (to read samples from the hardware) |
| 618 | * @return On success, a pointer to an iio_buffer structure |
| 619 | * @return On error, NULL is returned |
| 620 | * |
| 621 | * <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] | 622 | * before creating the buffer. */ |
| 623 | __api struct iio_buffer * iio_device_create_buffer(const struct iio_device *dev, |
| 624 | size_t samples_count, bool is_output); |
| 625 | |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 626 | |
| 627 | /** @brief Destroy the given buffer |
| 628 | * @param buf A pointer to an iio_buffer structure |
| 629 | * |
| 630 | * <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] | 631 | __api void iio_buffer_destroy(struct iio_buffer *buf); |
| 632 | |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 633 | |
| 634 | /** @brief Fetch more samples from the hardware |
| 635 | * @param buf A pointer to an iio_buffer structure |
| 636 | * @return On success, the number of bytes read is returned |
| 637 | * @return On error, a negative errno code is returned |
| 638 | * |
| 639 | * <b>NOTE:</b> Only valid for input buffers */ |
Paul Cercueil | b4afdd9 | 2014-04-08 12:37:21 +0200 | [diff] [blame] | 640 | __api ssize_t iio_buffer_refill(struct iio_buffer *buf); |
| 641 | |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 642 | |
| 643 | /** @brief Send the samples to the hardware |
| 644 | * @param buf A pointer to an iio_buffer structure |
| 645 | * @return On success, the number of bytes written is returned |
| 646 | * @return On error, a negative errno code is returned |
| 647 | * |
| 648 | * <b>NOTE:</b> Only valid for output buffers */ |
Paul Cercueil | ea32b04 | 2014-04-11 13:47:12 +0200 | [diff] [blame] | 649 | __api ssize_t iio_buffer_push(const struct iio_buffer *buf); |
Paul Cercueil | b4afdd9 | 2014-04-08 12:37:21 +0200 | [diff] [blame] | 650 | |
Paul Cercueil | b4afdd9 | 2014-04-08 12:37:21 +0200 | [diff] [blame] | 651 | |
Paul Cercueil | 6d92716 | 2014-04-16 15:53:22 +0200 | [diff] [blame] | 652 | /** @brief Get the start address of the buffer |
| 653 | * @param buf A pointer to an iio_buffer structure |
| 654 | * @return A pointer corresponding to the start address of the buffer */ |
| 655 | __api __pure void * iio_buffer_start(const struct iio_buffer *buf); |
| 656 | |
| 657 | |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 658 | /** @brief Find the first sample of a channel in a buffer |
| 659 | * @param buf A pointer to an iio_buffer structure |
| 660 | * @param chn A pointer to an iio_channel structure |
| 661 | * @return A pointer to the first sample found, or to the end of the buffer if |
| 662 | * no sample for the given channel is present in the buffer |
| 663 | * |
| 664 | * <b>NOTE:</b> This fonction, coupled with iio_buffer_step and iio_buffer_end, |
| 665 | * can be used to iterate on all the samples of a given channel present in the |
| 666 | * buffer, doing the following: |
| 667 | * |
| 668 | * @verbatim |
| 669 | for (void *ptr = iio_buffer_first(buffer, chn); ptr < iio_buffer_end(buffer); ptr += iio_buffer_step(buffer)) { |
| 670 | .... |
| 671 | } |
| 672 | @endverbatim */ |
| 673 | __api void * iio_buffer_first(const struct iio_buffer *buf, |
| 674 | const struct iio_channel *chn); |
| 675 | |
| 676 | |
| 677 | /** @brief Get the step size between two samples of one channel |
| 678 | * @param buf A pointer to an iio_buffer structure |
| 679 | * @return the difference between the addresses of two consecutive samples of |
| 680 | * one same channel */ |
| 681 | __api ptrdiff_t iio_buffer_step(const struct iio_buffer *buf); |
| 682 | |
| 683 | |
| 684 | /** @brief Get the address that follows the last sample in a buffer |
| 685 | * @param buf A pointer to an iio_buffer structure |
| 686 | * @return A pointer corresponding to the address that follows the last sample |
| 687 | * present in the buffer */ |
| 688 | __api void * iio_buffer_end(const struct iio_buffer *buf); |
| 689 | |
| 690 | |
| 691 | /** @brief Call the supplied callback for each sample found in a buffer |
| 692 | * @param buf A pointer to an iio_buffer structure |
| 693 | * @param callback A pointer to a function to call for each sample found |
| 694 | * @param data A user-specified pointer that will be passed to the callback |
| 695 | * |
| 696 | * <b>NOTE:</b> The callback receives four arguments: |
| 697 | * * A pointer to the iio_channel structure corresponding to the sample, |
| 698 | * * A pointer to the sample itself, |
| 699 | * * The length of the sample in bytes, |
| 700 | * * The user-specified pointer passed to iio_buffer_foreach_sample. */ |
Paul Cercueil | b4afdd9 | 2014-04-08 12:37:21 +0200 | [diff] [blame] | 701 | __api ssize_t iio_buffer_foreach_sample(struct iio_buffer *buf, |
| 702 | ssize_t (*callback)(const struct iio_channel *chn, |
| 703 | void *src, size_t bytes, void *d), void *data); |
| 704 | |
| 705 | |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 706 | /** @} *//* ------------------------------------------------------------------*/ |
Paul Cercueil | b4afdd9 | 2014-04-08 12:37:21 +0200 | [diff] [blame] | 707 | /* ------------------------- Low-level functions -----------------------------*/ |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 708 | /** @defgroup Debug Debug and low-level functions |
| 709 | * @{ |
| 710 | * @struct iio_data_format |
| 711 | * @brief Contains the format of a data sample. |
| 712 | * |
| 713 | * The different fields inform about the correct way to convert one sample from |
| 714 | * its raw format (as read from / generated by the hardware) to its real-world |
| 715 | * value. |
| 716 | */ |
| 717 | struct iio_data_format { |
| 718 | /** @brief Total length of the sample, in bits */ |
| 719 | unsigned int length; |
Paul Cercueil | b4afdd9 | 2014-04-08 12:37:21 +0200 | [diff] [blame] | 720 | |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 721 | /** @brief Length of valuable data in the sample, in bits */ |
| 722 | unsigned int bits; |
| 723 | |
| 724 | /** @brief Right-shift to apply when converting sample */ |
| 725 | unsigned int shift; |
| 726 | |
| 727 | /** @brief Contains True if the sample is signed */ |
| 728 | bool is_signed; |
| 729 | |
| 730 | /** @brief Contains True if the sample is in big-endian format */ |
| 731 | bool is_be; |
| 732 | |
| 733 | /** @brief Contains True if the sample should be scaled when converted */ |
| 734 | bool with_scale; |
| 735 | |
| 736 | /** @brief Contains the scale to apply if with_scale is set */ |
| 737 | double scale; |
| 738 | }; |
| 739 | |
| 740 | |
| 741 | /** @brief Open the given device |
| 742 | * @param dev A pointer to an iio_device structure |
| 743 | * @param samples_count The size of the kernel buffer, in samples |
| 744 | * @return On success, 0 is returned |
| 745 | * @return On error, a negative errno code is returned |
| 746 | * |
| 747 | * <b>NOTE:</b> This is not required when using the iio_buffer functions; it is |
| 748 | * 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] | 749 | __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] | 750 | |
| 751 | |
| 752 | /** @brief Close the given device |
| 753 | * @param dev A pointer to an iio_device structure |
| 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_close(const struct iio_device *dev); |
Paul Cercueil | ec1760d | 2014-02-21 11:31:20 +0100 | [diff] [blame] | 760 | |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 761 | |
| 762 | /** @brief Get the current sample size |
| 763 | * @param dev A pointer to an iio_device structure |
| 764 | * @return On success, the sample size in bytes |
| 765 | * @return On error, a negative errno code is returned |
| 766 | * |
| 767 | * <b>NOTE:</b> The sample size is not constant and will change when channels |
| 768 | * get enabled or disabled. */ |
Paul Cercueil | 59f2aa3 | 2014-04-04 16:28:51 +0200 | [diff] [blame] | 769 | __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] | 770 | |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 771 | |
| 772 | /** @brief Get the index of the given channel |
| 773 | * @param chn A pointer to an iio_channel structure |
| 774 | * @return On success, the index of the specified channel |
| 775 | * @return On error, a negative errno code is returned */ |
Paul Cercueil | 59f2aa3 | 2014-04-04 16:28:51 +0200 | [diff] [blame] | 776 | __api __pure long iio_channel_get_index(const struct iio_channel *chn); |
Paul Cercueil | b4afdd9 | 2014-04-08 12:37:21 +0200 | [diff] [blame] | 777 | |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 778 | |
| 779 | /** @brief Get a pointer to a channel's data format structure |
| 780 | * @param chn A pointer to an iio_channel structure |
| 781 | * @return A pointer to the channel's iio_data_format structure */ |
Paul Cercueil | 59f2aa3 | 2014-04-04 16:28:51 +0200 | [diff] [blame] | 782 | __api __cnst const struct iio_data_format * iio_channel_get_data_format( |
| 783 | const struct iio_channel *chn); |
Paul Cercueil | 0b2ce71 | 2014-02-17 15:04:18 +0100 | [diff] [blame] | 784 | |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 785 | |
| 786 | /** @brief Convert the sample from hardware format to host format |
| 787 | * @param chn A pointer to an iio_channel structure |
| 788 | * @param dst A pointer to the destination buffer where the converted sample |
| 789 | * should be written |
| 790 | * @param src A pointer to the source buffer containing the sample */ |
Paul Cercueil | 59f2aa3 | 2014-04-04 16:28:51 +0200 | [diff] [blame] | 791 | __api void iio_channel_convert(const struct iio_channel *chn, |
Paul Cercueil | 2917ffb | 2014-03-21 15:47:12 +0100 | [diff] [blame] | 792 | void *dst, const void *src); |
| 793 | |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 794 | |
| 795 | /** @brief Convert the sample from host format to hardware format |
| 796 | * @param chn A pointer to an iio_channel structure |
| 797 | * @param dst A pointer to the destination buffer where the converted sample |
| 798 | * should be written |
| 799 | * @param src A pointer to the source buffer containing the sample */ |
Paul Cercueil | d840d4c | 2014-04-07 19:38:58 +0200 | [diff] [blame] | 800 | __api void iio_channel_convert_inverse(const struct iio_channel *chn, |
| 801 | void *dst, const void *src); |
| 802 | |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 803 | |
| 804 | /** @brief Read the raw stream from the given device |
| 805 | * @param dev A pointer to an iio_device structure |
| 806 | * @param dst A pointer to the destination buffer where to write the stream |
| 807 | * @param len The length of the destination buffer, in bytes |
| 808 | * @param mask A pointer to a memory area where the channel mask will be stored |
| 809 | * @param words The number of 32-bit words composing the mask |
| 810 | * @return On success, the number of bytes read |
| 811 | * @return On error, a negative errno code is returned |
| 812 | * |
| 813 | * <b>NOTE:</b> The device must be opened first (with iio_device_open). |
| 814 | * |
| 815 | * The "words" param should correspond to (number of channels + 31) / 32. |
| 816 | * The area pointed by "mask" will be initialized like this: |
| 817 | * @verbatim |
| 818 | mask[chn.index / 32][chn.index % 32] = is_enabled |
| 819 | @endverbatim |
| 820 | * Note that the mask can change anytime between two calls, even if no channel |
| 821 | * of the specified device have been enabled or disabled in the meantime. */ |
Paul Cercueil | 59f2aa3 | 2014-04-04 16:28:51 +0200 | [diff] [blame] | 822 | __api ssize_t iio_device_read_raw(const struct iio_device *dev, |
Paul Cercueil | 45c575d | 2014-03-20 15:14:01 +0100 | [diff] [blame] | 823 | void *dst, size_t len, uint32_t *mask, size_t words); |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 824 | |
| 825 | |
| 826 | /** @brief Write a raw stream to the given device |
| 827 | * @param dev A pointer to an iio_device structure |
| 828 | * @param src A pointer to the source buffer where to read the stream from |
| 829 | * @param len The length of the input buffer, in bytes |
| 830 | * @return On success, the number of bytes written |
| 831 | * @return On error, a negative errno code is returned |
| 832 | * |
| 833 | * <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] | 834 | __api ssize_t iio_device_write_raw(const struct iio_device *dev, |
Paul Cercueil | 0b2ce71 | 2014-02-17 15:04:18 +0100 | [diff] [blame] | 835 | const void *src, size_t len); |
| 836 | |
Paul Cercueil | 99b07cc | 2014-04-14 16:07:32 +0200 | [diff] [blame] | 837 | |
Paul Cercueil | 1ce35ef | 2014-04-15 12:28:40 +0200 | [diff] [blame] | 838 | /** @brief Enumerate the debug attributes of the given device |
| 839 | * @param dev A pointer to an iio_device structure |
| 840 | * @return The number of debug attributes found */ |
| 841 | __api __pure unsigned int iio_device_get_debug_attrs_count( |
| 842 | const struct iio_device *dev); |
| 843 | |
| 844 | |
| 845 | /** @brief Get the debug attribute present at the given index |
| 846 | * @param dev A pointer to an iio_device structure |
| 847 | * @param index The index corresponding to the debug attribute |
| 848 | * @return On success, a pointer to a static NULL-terminated string |
| 849 | * @return If the index is invalid, NULL is returned */ |
| 850 | __api __pure const char * iio_device_get_debug_attr( |
| 851 | const struct iio_device *dev, unsigned int index); |
| 852 | |
| 853 | |
Paul Cercueil | 99b07cc | 2014-04-14 16:07:32 +0200 | [diff] [blame] | 854 | /** @brief Read the content of the given debug attribute |
| 855 | * @param dev A pointer to an iio_device structure |
| 856 | * @param attr A NULL-terminated string corresponding to the name of the |
| 857 | * debug attribute |
| 858 | * @param dst A pointer to the memory area where the NULL-terminated string |
| 859 | * corresponding to the value read will be stored |
| 860 | * @param len The available length of the memory area, in bytes |
| 861 | * @return On success, the number of bytes written to the buffer |
| 862 | * @return On error, a negative errno code is returned */ |
| 863 | __api ssize_t iio_device_debug_attr_read(const struct iio_device *dev, |
| 864 | const char *attr, char *dst, size_t len); |
| 865 | |
| 866 | |
| 867 | /** @brief Set the value of the given debug attribute |
| 868 | * @param dev A pointer to an iio_device structure |
| 869 | * @param attr A NULL-terminated string corresponding to the name of the |
| 870 | * debug attribute |
| 871 | * @param src A NULL-terminated string to set the debug attribute to |
| 872 | * @return On success, the number of bytes written |
| 873 | * @return On error, a negative errno code is returned */ |
| 874 | __api ssize_t iio_device_debug_attr_write(const struct iio_device *dev, |
| 875 | const char *attr, const char *src); |
| 876 | |
Paul Cercueil | e396074 | 2014-04-15 16:00:50 +0200 | [diff] [blame] | 877 | |
| 878 | /** @brief Read the content of the given debug attribute |
| 879 | * @param dev A pointer to an iio_device structure |
| 880 | * @param attr A NULL-terminated string corresponding to the name of the |
| 881 | * debug attribute |
| 882 | * @param val A pointer to a bool variable where the value should be stored |
| 883 | * @return On success, 0 is returned |
| 884 | * @return On error, a negative errno code is returned */ |
| 885 | __api int iio_device_debug_attr_read_bool(const struct iio_device *dev, |
| 886 | const char *attr, bool *val); |
| 887 | |
| 888 | |
| 889 | /** @brief Read the content of the given debug attribute |
| 890 | * @param dev A pointer to an iio_device structure |
| 891 | * @param attr A NULL-terminated string corresponding to the name of the |
| 892 | * debug attribute |
| 893 | * @param val A pointer to a long long variable where the value should be stored |
| 894 | * @return On success, 0 is returned |
| 895 | * @return On error, a negative errno code is returned */ |
| 896 | __api int iio_device_debug_attr_read_longlong(const struct iio_device *dev, |
| 897 | const char *attr, long long *val); |
| 898 | |
| 899 | |
| 900 | /** @brief Read the content of the given debug attribute |
| 901 | * @param dev A pointer to an iio_device structure |
| 902 | * @param attr A NULL-terminated string corresponding to the name of the |
| 903 | * debug attribute |
| 904 | * @param val A pointer to a double variable where the value should be stored |
| 905 | * @return On success, 0 is returned |
| 906 | * @return On error, a negative errno code is returned */ |
| 907 | __api int iio_device_debug_attr_read_double(const struct iio_device *dev, |
| 908 | const char *attr, double *val); |
| 909 | |
| 910 | |
| 911 | /** @brief Set the value of the given debug attribute |
| 912 | * @param dev A pointer to an iio_device structure |
| 913 | * @param attr A NULL-terminated string corresponding to the name of the |
| 914 | * debug attribute |
| 915 | * @param val A bool value to set the debug attribute to |
| 916 | * @return On success, 0 is returned |
| 917 | * @return On error, a negative errno code is returned */ |
| 918 | __api int iio_device_debug_attr_write_bool(const struct iio_device *dev, |
| 919 | const char *attr, bool val); |
| 920 | |
| 921 | |
| 922 | /** @brief Set the value of the given debug attribute |
| 923 | * @param dev A pointer to an iio_device structure |
| 924 | * @param attr A NULL-terminated string corresponding to the name of the |
| 925 | * debug attribute |
| 926 | * @param val A long long value to set the debug attribute to |
| 927 | * @return On success, 0 is returned |
| 928 | * @return On error, a negative errno code is returned */ |
| 929 | __api int iio_device_debug_attr_write_longlong(const struct iio_device *dev, |
| 930 | const char *attr, long long val); |
| 931 | |
| 932 | |
| 933 | /** @brief Set the value of the given debug attribute |
| 934 | * @param dev A pointer to an iio_device structure |
| 935 | * @param attr A NULL-terminated string corresponding to the name of the |
| 936 | * debug attribute |
| 937 | * @param val A double value to set the debug attribute to |
| 938 | * @return On success, 0 is returned |
| 939 | * @return On error, a negative errno code is returned */ |
| 940 | __api int iio_device_debug_attr_write_double(const struct iio_device *dev, |
| 941 | const char *attr, double val); |
| 942 | |
Paul Cercueil | 306cb1c | 2014-04-11 14:46:45 +0200 | [diff] [blame] | 943 | /** @} */ |
| 944 | |
Paul Cercueil | a167e0c | 2014-04-08 14:50:41 +0200 | [diff] [blame] | 945 | #ifdef __cplusplus |
| 946 | } |
| 947 | #endif |
| 948 | |
Paul Cercueil | 0b2ce71 | 2014-02-17 15:04:18 +0100 | [diff] [blame] | 949 | #endif /* __IIO_H__ */ |