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