Go-based FM stereo transmitter with RDS, Windows-first and cross-platform
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

1987 lines
78KB

  1. /* SPDX-License-Identifier: LGPL-2.1-or-later */
  2. /*
  3. * libiio - Library for interfacing industrial I/O (IIO) devices
  4. *
  5. * Copyright (C) 2014 Analog Devices, Inc.
  6. * Author: Paul Cercueil <paul.cercueil@analog.com>
  7. */
  8. /** @file iio.h
  9. * @brief Public interface */
  10. #ifndef __IIO_H__
  11. #define __IIO_H__
  12. #ifdef __cplusplus
  13. extern "C" {
  14. #endif
  15. #include <limits.h>
  16. #include <stdint.h>
  17. #include <stdlib.h>
  18. #include <stddef.h>
  19. #if (defined(_WIN32) || defined(__MBED__))
  20. #ifndef _SSIZE_T_DEFINED
  21. typedef ptrdiff_t ssize_t;
  22. #define _SSIZE_T_DEFINED
  23. #endif
  24. #else
  25. #include <sys/types.h>
  26. #endif
  27. #if defined(_MSC_VER) && (_MSC_VER < 1800) && !defined(__BOOL_DEFINED)
  28. #undef bool
  29. #undef false
  30. #undef true
  31. #define bool char
  32. #define false 0
  33. #define true 1
  34. #else
  35. #include <stdbool.h>
  36. #endif
  37. #if defined(__GNUC__) && !defined(MATLAB_MEX_FILE) && !defined(MATLAB_LOADLIBRARY)
  38. #ifndef __cnst
  39. #define __cnst __attribute__((const))
  40. #endif
  41. #ifndef __pure
  42. #define __pure __attribute__((pure))
  43. #endif
  44. #define __notused __attribute__((unused))
  45. #ifdef IIO_CHECK_RET
  46. #define __check_ret __attribute__((warn_unused_result))
  47. #else
  48. #define __check_ret
  49. #endif
  50. #else
  51. #define __cnst
  52. #define __pure
  53. #define __notused
  54. #define __check_ret
  55. #endif
  56. #ifdef _WIN32
  57. # ifdef LIBIIO_STATIC
  58. # define __api
  59. # elif defined(LIBIIO_EXPORTS)
  60. # define __api __declspec(dllexport)
  61. # else
  62. # define __api __declspec(dllimport)
  63. # endif
  64. #elif __GNUC__ >= 4 && !defined(MATLAB_MEX_FILE) && !defined(MATLAB_LOADLIBRARY)
  65. # define __api __attribute__((visibility ("default")))
  66. #else
  67. # define __api
  68. #endif
  69. struct iio_context;
  70. struct iio_device;
  71. struct iio_channel;
  72. struct iio_buffer;
  73. struct iio_context_info;
  74. struct iio_scan_context;
  75. struct iio_scan_block;
  76. /*
  77. * <linux/iio/types.h> header guard to protect these enums from being defined
  78. * twice
  79. */
  80. #ifndef _IIO_TYPES_H_
  81. #define _IIO_TYPES_H_
  82. /**
  83. * @enum iio_chan_type
  84. * @brief IIO channel type
  85. *
  86. * A IIO channel has a type specifying the type of data associated with the
  87. * channel.
  88. */
  89. enum iio_chan_type {
  90. IIO_VOLTAGE,
  91. IIO_CURRENT,
  92. IIO_POWER,
  93. IIO_ACCEL,
  94. IIO_ANGL_VEL,
  95. IIO_MAGN,
  96. IIO_LIGHT,
  97. IIO_INTENSITY,
  98. IIO_PROXIMITY,
  99. IIO_TEMP,
  100. IIO_INCLI,
  101. IIO_ROT,
  102. IIO_ANGL,
  103. IIO_TIMESTAMP,
  104. IIO_CAPACITANCE,
  105. IIO_ALTVOLTAGE,
  106. IIO_CCT,
  107. IIO_PRESSURE,
  108. IIO_HUMIDITYRELATIVE,
  109. IIO_ACTIVITY,
  110. IIO_STEPS,
  111. IIO_ENERGY,
  112. IIO_DISTANCE,
  113. IIO_VELOCITY,
  114. IIO_CONCENTRATION,
  115. IIO_RESISTANCE,
  116. IIO_PH,
  117. IIO_UVINDEX,
  118. IIO_ELECTRICALCONDUCTIVITY,
  119. IIO_COUNT,
  120. IIO_INDEX,
  121. IIO_GRAVITY,
  122. IIO_POSITIONRELATIVE,
  123. IIO_PHASE,
  124. IIO_MASSCONCENTRATION,
  125. IIO_CHAN_TYPE_UNKNOWN = INT_MAX
  126. };
  127. /**
  128. * @enum iio_modifier
  129. * @brief IIO channel modifier
  130. *
  131. * In a addition to a type a IIO channel can optionally have a channel modifier
  132. * further specifying the data type of of the channel.
  133. */
  134. enum iio_modifier {
  135. IIO_NO_MOD,
  136. IIO_MOD_X,
  137. IIO_MOD_Y,
  138. IIO_MOD_Z,
  139. IIO_MOD_X_AND_Y,
  140. IIO_MOD_X_AND_Z,
  141. IIO_MOD_Y_AND_Z,
  142. IIO_MOD_X_AND_Y_AND_Z,
  143. IIO_MOD_X_OR_Y,
  144. IIO_MOD_X_OR_Z,
  145. IIO_MOD_Y_OR_Z,
  146. IIO_MOD_X_OR_Y_OR_Z,
  147. IIO_MOD_LIGHT_BOTH,
  148. IIO_MOD_LIGHT_IR,
  149. IIO_MOD_ROOT_SUM_SQUARED_X_Y,
  150. IIO_MOD_SUM_SQUARED_X_Y_Z,
  151. IIO_MOD_LIGHT_CLEAR,
  152. IIO_MOD_LIGHT_RED,
  153. IIO_MOD_LIGHT_GREEN,
  154. IIO_MOD_LIGHT_BLUE,
  155. IIO_MOD_QUATERNION,
  156. IIO_MOD_TEMP_AMBIENT,
  157. IIO_MOD_TEMP_OBJECT,
  158. IIO_MOD_NORTH_MAGN,
  159. IIO_MOD_NORTH_TRUE,
  160. IIO_MOD_NORTH_MAGN_TILT_COMP,
  161. IIO_MOD_NORTH_TRUE_TILT_COMP,
  162. IIO_MOD_RUNNING,
  163. IIO_MOD_JOGGING,
  164. IIO_MOD_WALKING,
  165. IIO_MOD_STILL,
  166. IIO_MOD_ROOT_SUM_SQUARED_X_Y_Z,
  167. IIO_MOD_I,
  168. IIO_MOD_Q,
  169. IIO_MOD_CO2,
  170. IIO_MOD_VOC,
  171. IIO_MOD_LIGHT_UV,
  172. IIO_MOD_LIGHT_DUV,
  173. IIO_MOD_PM1,
  174. IIO_MOD_PM2P5,
  175. IIO_MOD_PM4,
  176. IIO_MOD_PM10,
  177. IIO_MOD_ETHANOL,
  178. IIO_MOD_H2,
  179. IIO_MOD_O2,
  180. IIO_MOD_LINEAR_X,
  181. IIO_MOD_LINEAR_Y,
  182. IIO_MOD_LINEAR_Z,
  183. IIO_MOD_PITCH,
  184. IIO_MOD_YAW,
  185. IIO_MOD_ROLL,
  186. };
  187. /**
  188. * @enum iio_event_type
  189. * @brief IIO event type
  190. *
  191. * Some IIO devices can deliver events. The type of the event can be specified
  192. * by one of the iio_event_type values.
  193. */
  194. enum iio_event_type {
  195. IIO_EV_TYPE_THRESH,
  196. IIO_EV_TYPE_MAG,
  197. IIO_EV_TYPE_ROC,
  198. IIO_EV_TYPE_THRESH_ADAPTIVE,
  199. IIO_EV_TYPE_MAG_ADAPTIVE,
  200. IIO_EV_TYPE_CHANGE,
  201. IIO_EV_TYPE_MAG_REFERENCED,
  202. IIO_EV_TYPE_GESTURE,
  203. };
  204. /**
  205. * @enum iio_event_direction
  206. * @brief IIO event direction
  207. *
  208. * When applicable, this enum specifies the direction of the iio_event_type.
  209. */
  210. enum iio_event_direction {
  211. IIO_EV_DIR_EITHER,
  212. IIO_EV_DIR_RISING,
  213. IIO_EV_DIR_FALLING,
  214. IIO_EV_DIR_NONE,
  215. IIO_EV_DIR_SINGLETAP,
  216. IIO_EV_DIR_DOUBLETAP,
  217. };
  218. #endif /* _IIO_TYPES_H_ */
  219. /* ---------------------------------------------------------------------------*/
  220. /* ------------------------- Scan functions ----------------------------------*/
  221. /** @defgroup Scan Functions for scanning available contexts
  222. * @{
  223. * @struct iio_scan_context
  224. * @brief The scanning context
  225. *
  226. * @struct iio_context_info
  227. * @brief The information related to a discovered context
  228. */
  229. /** @brief Create a scan context
  230. * @param backend A NULL-terminated string containing a comma-separated
  231. * list of the backend(s) to use for scanning.
  232. * @param flags Unused for now. Set to 0.
  233. * @return on success, a pointer to a iio_scan_context structure
  234. * @return On failure, NULL is returned and errno is set appropriately
  235. *
  236. * <b>NOTE:</b> Libiio version 0.20 and above can handle multiple
  237. * strings, for instance "local:usb:", "ip:usb:", "local:usb:ip:", and
  238. * require a colon as the delimiter.
  239. * Libiio version 0.24 and above prefer a comma instead of colon as the
  240. * delimiter, and handle specifying backend-specific information. For
  241. * instance, "local,usb=0456:*" will scan the local backend and limit
  242. * scans on USB to vendor ID 0x0456, and accept all product IDs. The
  243. * "usb=0456:b673" string would limit the scan to the device with this
  244. * particular VID/PID. Both IDs are expected in hexadecimal, no 0x
  245. * prefix needed. */
  246. __api __check_ret struct iio_scan_context * iio_create_scan_context(
  247. const char *backend, unsigned int flags);
  248. /** @brief Destroy the given scan context
  249. * @param ctx A pointer to an iio_scan_context structure
  250. *
  251. * <b>NOTE:</b> After that function, the iio_scan_context pointer shall be invalid. */
  252. __api void iio_scan_context_destroy(struct iio_scan_context *ctx);
  253. /** @brief Enumerate available contexts
  254. * @param ctx A pointer to an iio_scan_context structure
  255. * @param info A pointer to a 'const struct iio_context_info **' typed variable.
  256. * The pointed variable will be initialized on success.
  257. * @returns On success, the number of contexts found.
  258. * @returns On failure, a negative error number.
  259. */
  260. __api __check_ret ssize_t iio_scan_context_get_info_list(struct iio_scan_context *ctx,
  261. struct iio_context_info ***info);
  262. /** @brief Free a context info list
  263. * @param info A pointer to a 'const struct iio_context_info *' typed variable
  264. */
  265. __api void iio_context_info_list_free(struct iio_context_info **info);
  266. /** @brief Get a description of a discovered context
  267. * @param info A pointer to an iio_context_info structure
  268. * @return A pointer to a static NULL-terminated string
  269. */
  270. __api __check_ret __pure const char * iio_context_info_get_description(
  271. const struct iio_context_info *info);
  272. /** @brief Get the URI of a discovered context
  273. * @param info A pointer to an iio_context_info structure
  274. * @return A pointer to a static NULL-terminated string
  275. */
  276. __api __check_ret __pure const char * iio_context_info_get_uri(
  277. const struct iio_context_info *info);
  278. /** @brief Create a scan block
  279. * @param backend A NULL-terminated string containing the backend to use for
  280. * scanning. If NULL, all the available backends are used.
  281. * @param flags Unused for now. Set to 0.
  282. * @return on success, a pointer to a iio_scan_block structure
  283. * @return On failure, NULL is returned and errno is set appropriately
  284. *
  285. * Introduced in version 0.20. */
  286. __api struct iio_scan_block * iio_create_scan_block(
  287. const char *backend, unsigned int flags);
  288. /** @brief Destroy the given scan block
  289. * @param blk A pointer to an iio_scan_block structure
  290. *
  291. * <b>NOTE:</b> After that function, the iio_scan_block pointer shall be invalid.
  292. *
  293. * Introduced in version 0.20. */
  294. __api void iio_scan_block_destroy(struct iio_scan_block *blk);
  295. /** @brief Enumerate available contexts via scan block
  296. * @param blk A pointer to a iio_scan_block structure.
  297. * @returns On success, the number of contexts found.
  298. * @returns On failure, a negative error number.
  299. *
  300. * Introduced in version 0.20. */
  301. __api ssize_t iio_scan_block_scan(struct iio_scan_block *blk);
  302. /** @brief Get the iio_context_info for a particular context
  303. * @param blk A pointer to an iio_scan_block structure
  304. * @param index The index corresponding to the context.
  305. * @return A pointer to the iio_context_info for the context
  306. * @returns On success, a pointer to the specified iio_context_info
  307. * @returns On failure, NULL is returned and errno is set appropriately
  308. *
  309. * Introduced in version 0.20. */
  310. __api struct iio_context_info *iio_scan_block_get_info(
  311. struct iio_scan_block *blk, unsigned int index);
  312. /** @} *//* ------------------------------------------------------------------*/
  313. /* ------------------------- Top-level functions -----------------------------*/
  314. /** @defgroup TopLevel Top-level functions
  315. * @{ */
  316. /** @brief Get the version of the libiio library
  317. * @param major A pointer to an unsigned integer (NULL accepted)
  318. * @param minor A pointer to an unsigned integer (NULL accepted)
  319. * @param git_tag A pointer to a 8-characters buffer (NULL accepted) */
  320. __api void iio_library_get_version(unsigned int *major,
  321. unsigned int *minor, char git_tag[8]);
  322. /** @brief Get a string description of an error code
  323. * @param err The error code
  324. * @param dst A pointer to the memory area where the NULL-terminated string
  325. * corresponding to the error message will be stored
  326. * @param len The available length of the memory area, in bytes */
  327. __api void iio_strerror(int err, char *dst, size_t len);
  328. /** @brief Check if the specified backend is available
  329. * @param backend The name of the backend to query
  330. * @return True if the backend is available, false otherwise
  331. *
  332. * Introduced in version 0.9. */
  333. __api __check_ret __cnst bool iio_has_backend(const char *backend);
  334. /** @brief Get the number of available backends
  335. * @return The number of available backends
  336. *
  337. * Introduced in version 0.9. */
  338. __api __check_ret __cnst unsigned int iio_get_backends_count(void);
  339. /** @brief Retrieve the name of a given backend
  340. * @param index The index corresponding to the attribute
  341. * @return On success, a pointer to a static NULL-terminated string
  342. * @return If the index is invalid, NULL is returned
  343. *
  344. * Introduced in version 0.9. */
  345. __api __check_ret __cnst const char * iio_get_backend(unsigned int index);
  346. /** @} *//* ------------------------------------------------------------------*/
  347. /* ------------------------- Context functions -------------------------------*/
  348. /** @defgroup Context Context
  349. * @{
  350. * @struct iio_context
  351. * @brief Contains the representation of an IIO context */
  352. /** @brief Create a context from local or remote IIO devices
  353. * @return On success, A pointer to an iio_context structure
  354. * @return On failure, NULL is returned and errno is set appropriately
  355. *
  356. * <b>NOTE:</b> This function will create a context with the URI
  357. * provided in the IIOD_REMOTE environment variable. If not set, a local
  358. * context will be created instead. */
  359. __api __check_ret struct iio_context * iio_create_default_context(void);
  360. /** @brief Create a context from local IIO devices (Linux only)
  361. * @return On success, A pointer to an iio_context structure
  362. * @return On failure, NULL is returned and errno is set appropriately */
  363. __api __check_ret struct iio_context * iio_create_local_context(void);
  364. /** @brief Create a context from a XML file
  365. * @param xml_file Path to the XML file to open
  366. * @return On success, A pointer to an iio_context structure
  367. * @return On failure, NULL is returned and errno is set appropriately
  368. *
  369. * <b>NOTE:</b> The format of the XML must comply to the one returned by
  370. * iio_context_get_xml. */
  371. __api __check_ret struct iio_context * iio_create_xml_context(const char *xml_file);
  372. /** @brief Create a context from XML data in memory
  373. * @param xml Pointer to the XML data in memory
  374. * @param len Length of the XML string in memory (excluding the final \0)
  375. * @return On success, A pointer to an iio_context structure
  376. * @return On failure, NULL is returned and errno is set appropriately
  377. *
  378. * <b>NOTE:</b> The format of the XML must comply to the one returned by
  379. * iio_context_get_xml */
  380. __api __check_ret struct iio_context * iio_create_xml_context_mem(
  381. const char *xml, size_t len);
  382. /** @brief Create a context from the network
  383. * @param host Hostname, IPv4 or IPv6 address where the IIO Daemon is running
  384. * @return On success, a pointer to an iio_context structure
  385. * @return On failure, NULL is returned and errno is set appropriately */
  386. __api __check_ret struct iio_context * iio_create_network_context(const char *host);
  387. /** @brief Create a context from a URI description
  388. * @param uri A URI describing the context location
  389. * @return On success, a pointer to a iio_context structure
  390. * @return On failure, NULL is returned and errno is set appropriately
  391. *
  392. * <b>NOTE:</b> The following URIs are supported based on compile time backend
  393. * support:
  394. * - Local backend, "local:"\n
  395. * Does not have an address part. For example <i>"local:"</i>
  396. * - XML backend, "xml:"\n Requires a path to the XML file for the address part.
  397. * For example <i>"xml:/home/user/file.xml"</i>
  398. * - Network backend, "ip:"\n Requires a hostname, IPv4, or IPv6 to connect to
  399. * a specific running IIO Daemon or no address part for automatic discovery
  400. * when library is compiled with ZeroConf support. For example
  401. * <i>"ip:192.168.2.1"</i>, <b>or</b> <i>"ip:localhost"</i>, <b>or</b> <i>"ip:"</i>
  402. * <b>or</b> <i>"ip:plutosdr.local"</i>. To support alternative port numbers the
  403. * standard <i>ip:host:port</i> format is used. A special format is required as
  404. * defined in RFC2732 for IPv6 literal hostnames, (adding '[]' around the host)
  405. * to use a <i>ip:[x:x:x:x:x:x:x:x]:port</i> format.
  406. * Valid examples would be:
  407. * - ip: Any host on default port
  408. * - ip::40000 Any host on port 40000
  409. * - ip:analog.local Default port
  410. * - ip:brain.local:40000 Port 40000
  411. * - ip:192.168.1.119 Default Port
  412. * - ip:192.168.1.119:40000 Port 40000
  413. * - ip:2601:190:400:da:47b3:55ab:3914:bff1 Default Port
  414. * - ip:[2601:190:400:da:9a90:96ff:feb5:acaa]:40000 Port 40000
  415. * - ip:fe80::f14d:3728:501e:1f94%eth0 Link-local through eth0, default port
  416. * - ip:[fe80::f14d:3728:501e:1f94%eth0]:40000 Link-local through eth0, port 40000
  417. * - USB backend, "usb:"\n When more than one usb device is attached, requires
  418. * bus, address, and interface parts separated with a dot. For example
  419. * <i>"usb:3.32.5"</i>. Where there is only one USB device attached, the shorthand
  420. * <i>"usb:"</i> can be used.
  421. * - Serial backend, "serial:"\n Requires:
  422. * - a port (/dev/ttyUSB0),
  423. * - baud_rate (default <b>115200</b>)
  424. * - serial port configuration
  425. * - data bits (5 6 7 <b>8</b> 9)
  426. * - parity ('<b>n</b>' none, 'o' odd, 'e' even, 'm' mark, 's' space)
  427. * - stop bits (<b>1</b> 2)
  428. * - flow control ('<b>\0</b>' none, 'x' Xon Xoff, 'r' RTSCTS, 'd' DTRDSR)
  429. *
  430. * For example <i>"serial:/dev/ttyUSB0,115200"</i> <b>or</b> <i>"serial:/dev/ttyUSB0,115200,8n1"</i>*/
  431. __api __check_ret struct iio_context * iio_create_context_from_uri(const char *uri);
  432. /** @brief Duplicate a pre-existing IIO context
  433. * @param ctx A pointer to an iio_context structure
  434. * @return On success, A pointer to an iio_context structure
  435. * @return On failure, NULL is returned and errno is set appropriately
  436. *
  437. * <b>NOTE:</b> This function is not supported on 'usb:' contexts, since libusb
  438. * can only claim the interface once. "Function not implemented" is the expected errno.
  439. * Any context which is cloned, must be destroyed via calling iio_context_destroy() */
  440. __api __check_ret struct iio_context * iio_context_clone(const struct iio_context *ctx);
  441. /** @brief Destroy the given context
  442. * @param ctx A pointer to an iio_context structure
  443. *
  444. * <b>NOTE:</b> After that function, the iio_context pointer shall be invalid. */
  445. __api void iio_context_destroy(struct iio_context *ctx);
  446. /** @brief Get the version of the backend in use
  447. * @param ctx A pointer to an iio_context structure
  448. * @param major A pointer to an unsigned integer (NULL accepted)
  449. * @param minor A pointer to an unsigned integer (NULL accepted)
  450. * @param git_tag A pointer to a 8-characters buffer (NULL accepted)
  451. * @return On success, 0 is returned
  452. * @return On error, a negative errno code is returned */
  453. __api __check_ret int iio_context_get_version(const struct iio_context *ctx,
  454. unsigned int *major, unsigned int *minor, char git_tag[8]);
  455. /** @brief Obtain a XML representation of the given context
  456. * @param ctx A pointer to an iio_context structure
  457. * @return A pointer to a static NULL-terminated string */
  458. __api __check_ret __pure const char * iio_context_get_xml(const struct iio_context *ctx);
  459. /** @brief Get the name of the given context
  460. * @param ctx A pointer to an iio_context structure
  461. * @return A pointer to a static NULL-terminated string
  462. *
  463. * <b>NOTE:</b>The returned string will be <b><i>local</i></b>,
  464. * <b><i>xml</i></b> or <b><i>network</i></b> when the context has been
  465. * created with the local, xml and network backends respectively.*/
  466. __api __check_ret __pure const char * iio_context_get_name(const struct iio_context *ctx);
  467. /** @brief Get a description of the given context
  468. * @param ctx A pointer to an iio_context structure
  469. * @return A pointer to a static NULL-terminated string
  470. *
  471. * <b>NOTE:</b>The returned string will contain human-readable information about
  472. * the current context. */
  473. __api __check_ret __pure const char * iio_context_get_description(
  474. const struct iio_context *ctx);
  475. /** @brief Get the number of context-specific attributes
  476. * @param ctx A pointer to an iio_context structure
  477. * @return The number of context-specific attributes
  478. *
  479. * Introduced in version 0.9. */
  480. __api __check_ret __pure unsigned int iio_context_get_attrs_count(
  481. const struct iio_context *ctx);
  482. /** @brief Retrieve the name and value of a context-specific attribute
  483. * @param ctx A pointer to an iio_context structure
  484. * @param index The index corresponding to the attribute
  485. * @param name A pointer to a const char * pointer (NULL accepted)
  486. * @param value A pointer to a const char * pointer (NULL accepted)
  487. * @return On success, 0 is returned
  488. * @return On error, a negative errno code is returned
  489. *
  490. * Introduced in version 0.9. */
  491. __api __check_ret int iio_context_get_attr(
  492. const struct iio_context *ctx, unsigned int index,
  493. const char **name, const char **value);
  494. /** @brief Retrieve the value of a context-specific attribute
  495. * @param ctx A pointer to an iio_context structure
  496. * @param name The name of the context attribute to read
  497. * @return On success, a pointer to a static NULL-terminated string
  498. * @return If the name does not correspond to any attribute, NULL is
  499. * returned
  500. *
  501. * Introduced in version 0.9. */
  502. __api __check_ret const char * iio_context_get_attr_value(
  503. const struct iio_context *ctx, const char *name);
  504. /** @brief Enumerate the devices found in the given context
  505. * @param ctx A pointer to an iio_context structure
  506. * @return The number of devices found */
  507. __api __check_ret __pure unsigned int iio_context_get_devices_count(
  508. const struct iio_context *ctx);
  509. /** @brief Get the device present at the given index
  510. * @param ctx A pointer to an iio_context structure
  511. * @param index The index corresponding to the device
  512. * @return On success, a pointer to an iio_device structure
  513. * @return If the index is invalid, NULL is returned */
  514. __api __check_ret __pure struct iio_device * iio_context_get_device(
  515. const struct iio_context *ctx, unsigned int index);
  516. /** @brief Try to find a device structure by its ID, label or name
  517. * @param ctx A pointer to an iio_context structure
  518. * @param name A NULL-terminated string corresponding to the ID, label or name
  519. * of the device to search for
  520. * @return On success, a pointer to an iio_device structure
  521. * @return If the parameter does not correspond to the ID, label or name of
  522. * any known device, NULL is returned */
  523. __api __check_ret __pure struct iio_device * iio_context_find_device(
  524. const struct iio_context *ctx, const char *name);
  525. /** @brief Set a timeout for I/O operations
  526. * @param ctx A pointer to an iio_context structure
  527. * @param timeout_ms A positive integer representing the time in milliseconds
  528. * after which a timeout occurs. A value of 0 is used to specify that no
  529. * timeout should occur.
  530. * @return On success, 0 is returned
  531. * @return On error, a negative errno code is returned */
  532. __api __check_ret int iio_context_set_timeout(
  533. struct iio_context *ctx, unsigned int timeout_ms);
  534. /** @} *//* ------------------------------------------------------------------*/
  535. /* ------------------------- Device functions --------------------------------*/
  536. /** @defgroup Device Device
  537. * @{
  538. * @struct iio_device
  539. * @brief Represents a device in the IIO context */
  540. /** @brief Retrieve a pointer to the iio_context structure
  541. * @param dev A pointer to an iio_device structure
  542. * @return A pointer to an iio_context structure */
  543. __api __check_ret __pure const struct iio_context * iio_device_get_context(
  544. const struct iio_device *dev);
  545. /** @brief Retrieve the device ID (e.g. <b><i>iio:device0</i></b>)
  546. * @param dev A pointer to an iio_device structure
  547. * @return A pointer to a static NULL-terminated string */
  548. __api __check_ret __pure const char * iio_device_get_id(const struct iio_device *dev);
  549. /** @brief Retrieve the device name (e.g. <b><i>xadc</i></b>)
  550. * @param dev A pointer to an iio_device structure
  551. * @return A pointer to a static NULL-terminated string
  552. *
  553. * <b>NOTE:</b> if the device has no name, NULL is returned. */
  554. __api __check_ret __pure const char * iio_device_get_name(const struct iio_device *dev);
  555. /** @brief Retrieve the device label (e.g. <b><i>lo_pll0_rx_adf4351</i></b>)
  556. * @param dev A pointer to an iio_device structure
  557. * @return A pointer to a static NULL-terminated string
  558. *
  559. * <b>NOTE:</b> if the device has no label, NULL is returned. */
  560. __api __check_ret __pure const char * iio_device_get_label(const struct iio_device *dev);
  561. /** @brief Enumerate the channels of the given device
  562. * @param dev A pointer to an iio_device structure
  563. * @return The number of channels found */
  564. __api __check_ret __pure unsigned int iio_device_get_channels_count(
  565. const struct iio_device *dev);
  566. /** @brief Enumerate the device-specific attributes of the given device
  567. * @param dev A pointer to an iio_device structure
  568. * @return The number of device-specific attributes found */
  569. __api __check_ret __pure unsigned int iio_device_get_attrs_count(
  570. const struct iio_device *dev);
  571. /** @brief Enumerate the buffer-specific attributes of the given device
  572. * @param dev A pointer to an iio_device structure
  573. * @return The number of buffer-specific attributes found */
  574. __api __check_ret __pure unsigned int iio_device_get_buffer_attrs_count(
  575. const struct iio_device *dev);
  576. /** @brief Get the channel present at the given index
  577. * @param dev A pointer to an iio_device structure
  578. * @param index The index corresponding to the channel
  579. * @return On success, a pointer to an iio_channel structure
  580. * @return If the index is invalid, NULL is returned */
  581. __api __check_ret __pure struct iio_channel * iio_device_get_channel(
  582. const struct iio_device *dev, unsigned int index);
  583. /** @brief Get the device-specific attribute present at the given index
  584. * @param dev A pointer to an iio_device structure
  585. * @param index The index corresponding to the attribute
  586. * @return On success, a pointer to a static NULL-terminated string
  587. * @return If the index is invalid, NULL is returned */
  588. __api __check_ret __pure const char * iio_device_get_attr(
  589. const struct iio_device *dev, unsigned int index);
  590. /** @brief Get the buffer-specific attribute present at the given index
  591. * @param dev A pointer to an iio_device structure
  592. * @param index The index corresponding to the attribute
  593. * @return On success, a pointer to a static NULL-terminated string
  594. * @return If the index is invalid, NULL is returned */
  595. __api __check_ret __pure const char * iio_device_get_buffer_attr(
  596. const struct iio_device *dev, unsigned int index);
  597. /** @brief Try to find a channel structure by its name of ID
  598. * @param dev A pointer to an iio_device structure
  599. * @param name A NULL-terminated string corresponding to the name or the ID of
  600. * the channel to search for
  601. * @param output True if the searched channel is output, False otherwise
  602. * @return On success, a pointer to an iio_channel structure
  603. * @return If the name or ID does not correspond to any known channel of the
  604. * given device, NULL is returned */
  605. __api __check_ret __pure struct iio_channel * iio_device_find_channel(
  606. const struct iio_device *dev, const char *name, bool output);
  607. /** @brief Try to find a device-specific attribute by its name
  608. * @param dev A pointer to an iio_device structure
  609. * @param name A NULL-terminated string corresponding to the name of the
  610. * attribute
  611. * @return On success, a pointer to a static NULL-terminated string
  612. * @return If the name does not correspond to any known attribute of the given
  613. * device, NULL is returned
  614. *
  615. * <b>NOTE:</b> This function is useful to detect the presence of an attribute.
  616. * It can also be used to retrieve the name of an attribute as a pointer to a
  617. * static string from a dynamically allocated string. */
  618. __api __check_ret __pure const char * iio_device_find_attr(
  619. const struct iio_device *dev, const char *name);
  620. /** @brief Try to find a buffer-specific attribute by its name
  621. * @param dev A pointer to an iio_device structure
  622. * @param name A NULL-terminated string corresponding to the name of the
  623. * attribute
  624. * @return On success, a pointer to a static NULL-terminated string
  625. * @return If the name does not correspond to any known attribute of the given
  626. * device, NULL is returned
  627. *
  628. * <b>NOTE:</b> This function is useful to detect the presence of an attribute.
  629. * It can also be used to retrieve the name of an attribute as a pointer to a
  630. * static string from a dynamically allocated string. */
  631. __api __check_ret __pure const char * iio_device_find_buffer_attr(
  632. const struct iio_device *dev, const char *name);
  633. /** @brief Read the content of the given device-specific attribute
  634. * @param dev A pointer to an iio_device structure
  635. * @param attr A NULL-terminated string corresponding to the name of the
  636. * attribute
  637. * @param dst A pointer to the memory area where the NULL-terminated string
  638. * corresponding to the value read will be stored
  639. * @param len The available length of the memory area, in bytes
  640. * @return On success, the number of bytes written to the buffer
  641. * @return On error, a negative errno code is returned
  642. *
  643. * <b>NOTE:</b>By passing NULL as the "attr" argument to iio_device_attr_read,
  644. * it is now possible to read all of the attributes of a device.
  645. *
  646. * The buffer is filled with one block of data per attribute of the device,
  647. * by the order they appear in the iio_device structure.
  648. *
  649. * The first four bytes of one block correspond to a 32-bit signed value in
  650. * network order. If negative, it corresponds to the errno code that were
  651. * returned when reading the attribute; if positive, it corresponds to the
  652. * length of the data read. In that case, the rest of the block contains
  653. * the data. */
  654. __api __check_ret ssize_t iio_device_attr_read(const struct iio_device *dev,
  655. const char *attr, char *dst, size_t len);
  656. /** @brief Read the content of all device-specific attributes
  657. * @param dev A pointer to an iio_device structure
  658. * @param cb A pointer to a callback function
  659. * @param data A pointer that will be passed to the callback function
  660. * @return On success, 0 is returned
  661. * @return On error, a negative errno code is returned
  662. *
  663. * <b>NOTE:</b> This function is especially useful when used with the network
  664. * backend, as all the device-specific attributes are read in one single
  665. * command. */
  666. __api __check_ret int iio_device_attr_read_all(struct iio_device *dev,
  667. int (*cb)(struct iio_device *dev, const char *attr,
  668. const char *value, size_t len, void *d),
  669. void *data);
  670. /** @brief Read the content of the given device-specific attribute
  671. * @param dev A pointer to an iio_device structure
  672. * @param attr A NULL-terminated string corresponding to the name of the
  673. * attribute
  674. * @param val A pointer to a bool variable where the value should be stored
  675. * @return On success, 0 is returned
  676. * @return On error, a negative errno code is returned */
  677. __api __check_ret int iio_device_attr_read_bool(const struct iio_device *dev,
  678. const char *attr, bool *val);
  679. /** @brief Read the content of the given device-specific attribute
  680. * @param dev A pointer to an iio_device structure
  681. * @param attr A NULL-terminated string corresponding to the name of the
  682. * attribute
  683. * @param val A pointer to a long long variable where the value should be stored
  684. * @return On success, 0 is returned
  685. * @return On error, a negative errno code is returned */
  686. __api __check_ret int iio_device_attr_read_longlong(const struct iio_device *dev,
  687. const char *attr, long long *val);
  688. /** @brief Read the content of the given device-specific attribute
  689. * @param dev A pointer to an iio_device structure
  690. * @param attr A NULL-terminated string corresponding to the name of the
  691. * attribute
  692. * @param val A pointer to a double variable where the value should be stored
  693. * @return On success, 0 is returned
  694. * @return On error, a negative errno code is returned */
  695. __api __check_ret int iio_device_attr_read_double(const struct iio_device *dev,
  696. const char *attr, double *val);
  697. /** @brief Set the value of the given device-specific attribute
  698. * @param dev A pointer to an iio_device structure
  699. * @param attr A NULL-terminated string corresponding to the name of the
  700. * attribute
  701. * @param src A NULL-terminated string to set the attribute to
  702. * @return On success, the number of bytes written
  703. * @return On error, a negative errno code is returned
  704. *
  705. * <b>NOTE:</b>By passing NULL as the "attr" argument to iio_device_attr_write,
  706. * it is now possible to write all of the attributes of a device.
  707. *
  708. * The buffer must contain one block of data per attribute of the device,
  709. * by the order they appear in the iio_device structure.
  710. *
  711. * The first four bytes of one block correspond to a 32-bit signed value in
  712. * network order. If negative, the attribute is not written; if positive,
  713. * it corresponds to the length of the data to write. In that case, the rest
  714. * of the block must contain the data. */
  715. __api __check_ret ssize_t iio_device_attr_write(const struct iio_device *dev,
  716. const char *attr, const char *src);
  717. /** @brief Set the value of the given device-specific attribute
  718. * @param dev A pointer to an iio_device structure
  719. * @param attr A NULL-terminated string corresponding to the name of the
  720. * attribute
  721. * @param src A pointer to the data to be written
  722. * @param len The number of bytes that should be written
  723. * @return On success, the number of bytes written
  724. * @return On error, a negative errno code is returned */
  725. __api __check_ret ssize_t iio_device_attr_write_raw(const struct iio_device *dev,
  726. const char *attr, const void *src, size_t len);
  727. /** @brief Set the values of all device-specific attributes
  728. * @param dev A pointer to an iio_device structure
  729. * @param cb A pointer to a callback function
  730. * @param data A pointer that will be passed to the callback function
  731. * @return On success, 0 is returned
  732. * @return On error, a negative errno code is returned
  733. *
  734. * <b>NOTE:</b> This function is especially useful when used with the network
  735. * backend, as all the device-specific attributes are written in one single
  736. * command. */
  737. __api __check_ret int iio_device_attr_write_all(struct iio_device *dev,
  738. ssize_t (*cb)(struct iio_device *dev,
  739. const char *attr, void *buf, size_t len, void *d),
  740. void *data);
  741. /** @brief Set the value of the given device-specific attribute
  742. * @param dev A pointer to an iio_device structure
  743. * @param attr A NULL-terminated string corresponding to the name of the
  744. * attribute
  745. * @param val A bool value to set the attribute to
  746. * @return On success, 0 is returned
  747. * @return On error, a negative errno code is returned */
  748. __api __check_ret int iio_device_attr_write_bool(const struct iio_device *dev,
  749. const char *attr, bool val);
  750. /** @brief Set the value of the given device-specific attribute
  751. * @param dev A pointer to an iio_device structure
  752. * @param attr A NULL-terminated string corresponding to the name of the
  753. * attribute
  754. * @param val A long long value to set the attribute to
  755. * @return On success, 0 is returned
  756. * @return On error, a negative errno code is returned */
  757. __api __check_ret int iio_device_attr_write_longlong(const struct iio_device *dev,
  758. const char *attr, long long val);
  759. /** @brief Set the value of the given device-specific attribute
  760. * @param dev A pointer to an iio_device structure
  761. * @param attr A NULL-terminated string corresponding to the name of the
  762. * attribute
  763. * @param val A double value to set the attribute to
  764. * @return On success, 0 is returned
  765. * @return On error, a negative errno code is returned */
  766. __api __check_ret int iio_device_attr_write_double(const struct iio_device *dev,
  767. const char *attr, double val);
  768. /** @brief Read the content of the given buffer-specific attribute
  769. * @param dev A pointer to an iio_device structure
  770. * @param attr A NULL-terminated string corresponding to the name of the
  771. * attribute
  772. * @param dst A pointer to the memory area where the NULL-terminated string
  773. * corresponding to the value read will be stored
  774. * @param len The available length of the memory area, in bytes
  775. * @return On success, the number of bytes written to the buffer
  776. * @return On error, a negative errno code is returned
  777. *
  778. * <b>NOTE:</b>By passing NULL as the "attr" argument to
  779. * iio_device_buffer_attr_read, it is now possible to read all of the attributes
  780. * of a device.
  781. *
  782. * The buffer is filled with one block of data per attribute of the buffer,
  783. * by the order they appear in the iio_device structure.
  784. *
  785. * The first four bytes of one block correspond to a 32-bit signed value in
  786. * network order. If negative, it corresponds to the errno code that were
  787. * returned when reading the attribute; if positive, it corresponds to the
  788. * length of the data read. In that case, the rest of the block contains
  789. * the data. */
  790. __api __check_ret ssize_t iio_device_buffer_attr_read(const struct iio_device *dev,
  791. const char *attr, char *dst, size_t len);
  792. /** @brief Read the content of all buffer-specific attributes
  793. * @param dev A pointer to an iio_device structure
  794. * @param cb A pointer to a callback function
  795. * @param data A pointer that will be passed to the callback function
  796. * @return On success, 0 is returned
  797. * @return On error, a negative errno code is returned
  798. *
  799. * <b>NOTE:</b> This function is especially useful when used with the network
  800. * backend, as all the buffer-specific attributes are read in one single
  801. * command. */
  802. __api __check_ret int iio_device_buffer_attr_read_all(struct iio_device *dev,
  803. int (*cb)(struct iio_device *dev, const char *attr,
  804. const char *value, size_t len, void *d),
  805. void *data);
  806. /** @brief Read the content of the given buffer-specific attribute
  807. * @param dev A pointer to an iio_device structure
  808. * @param attr A NULL-terminated string corresponding to the name of the
  809. * attribute
  810. * @param val A pointer to a bool variable where the value should be stored
  811. * @return On success, 0 is returned
  812. * @return On error, a negative errno code is returned */
  813. __api __check_ret int iio_device_buffer_attr_read_bool(const struct iio_device *dev,
  814. const char *attr, bool *val);
  815. /** @brief Read the content of the given buffer-specific attribute
  816. * @param dev A pointer to an iio_device structure
  817. * @param attr A NULL-terminated string corresponding to the name of the
  818. * attribute
  819. * @param val A pointer to a long long variable where the value should be stored
  820. * @return On success, 0 is returned
  821. * @return On error, a negative errno code is returned */
  822. __api __check_ret int iio_device_buffer_attr_read_longlong(const struct iio_device *dev,
  823. const char *attr, long long *val);
  824. /** @brief Read the content of the given buffer-specific attribute
  825. * @param dev A pointer to an iio_device structure
  826. * @param attr A NULL-terminated string corresponding to the name of the
  827. * attribute
  828. * @param val A pointer to a double variable where the value should be stored
  829. * @return On success, 0 is returned
  830. * @return On error, a negative errno code is returned */
  831. __api __check_ret int iio_device_buffer_attr_read_double(const struct iio_device *dev,
  832. const char *attr, double *val);
  833. /** @brief Set the value of the given buffer-specific attribute
  834. * @param dev A pointer to an iio_device structure
  835. * @param attr A NULL-terminated string corresponding to the name of the
  836. * attribute
  837. * @param src A NULL-terminated string to set the attribute to
  838. * @return On success, the number of bytes written
  839. * @return On error, a negative errno code is returned
  840. *
  841. * <b>NOTE:</b>By passing NULL as the "attr" argument to
  842. * iio_device_buffer_attr_write, it is now possible to write all of the
  843. * attributes of a device.
  844. *
  845. * The buffer must contain one block of data per attribute of the buffer,
  846. * by the order they appear in the iio_device structure.
  847. *
  848. * The first four bytes of one block correspond to a 32-bit signed value in
  849. * network order. If negative, the attribute is not written; if positive,
  850. * it corresponds to the length of the data to write. In that case, the rest
  851. * of the block must contain the data. */
  852. __api __check_ret ssize_t iio_device_buffer_attr_write(const struct iio_device *dev,
  853. const char *attr, const char *src);
  854. /** @brief Set the value of the given buffer-specific 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. * attribute
  858. * @param src A pointer to the data to be written
  859. * @param len The number of bytes that should be written
  860. * @return On success, the number of bytes written
  861. * @return On error, a negative errno code is returned */
  862. __api __check_ret ssize_t iio_device_buffer_attr_write_raw(const struct iio_device *dev,
  863. const char *attr, const void *src, size_t len);
  864. /** @brief Set the values of all buffer-specific attributes
  865. * @param dev A pointer to an iio_device structure
  866. * @param cb A pointer to a callback function
  867. * @param data A pointer that will be passed to the callback function
  868. * @return On success, 0 is returned
  869. * @return On error, a negative errno code is returned
  870. *
  871. * <b>NOTE:</b> This function is especially useful when used with the network
  872. * backend, as all the buffer-specific attributes are written in one single
  873. * command. */
  874. __api __check_ret int iio_device_buffer_attr_write_all(struct iio_device *dev,
  875. ssize_t (*cb)(struct iio_device *dev,
  876. const char *attr, void *buf, size_t len, void *d),
  877. void *data);
  878. /** @brief Set the value of the given buffer-specific 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. * attribute
  882. * @param val A bool value to set the attribute to
  883. * @return On success, 0 is returned
  884. * @return On error, a negative errno code is returned */
  885. __api __check_ret int iio_device_buffer_attr_write_bool(const struct iio_device *dev,
  886. const char *attr, bool val);
  887. /** @brief Set the value of the given buffer-specific attribute
  888. * @param dev A pointer to an iio_device structure
  889. * @param attr A NULL-terminated string corresponding to the name of the
  890. * attribute
  891. * @param val A long long value to set the attribute to
  892. * @return On success, 0 is returned
  893. * @return On error, a negative errno code is returned */
  894. __api __check_ret int iio_device_buffer_attr_write_longlong(const struct iio_device *dev,
  895. const char *attr, long long val);
  896. /** @brief Set the value of the given buffer-specific attribute
  897. * @param dev A pointer to an iio_device structure
  898. * @param attr A NULL-terminated string corresponding to the name of the
  899. * attribute
  900. * @param val A double value to set the attribute to
  901. * @return On success, 0 is returned
  902. * @return On error, a negative errno code is returned */
  903. __api __check_ret int iio_device_buffer_attr_write_double(const struct iio_device *dev,
  904. const char *attr, double val);
  905. /** @brief Associate a pointer to an iio_device structure
  906. * @param dev A pointer to an iio_device structure
  907. * @param data The pointer to be associated */
  908. __api void iio_device_set_data(struct iio_device *dev, void *data);
  909. /** @brief Retrieve a previously associated pointer of an iio_device structure
  910. * @param dev A pointer to an iio_device structure
  911. * @return The pointer previously associated if present, or NULL */
  912. __api void * iio_device_get_data(const struct iio_device *dev);
  913. /** @brief Retrieve the trigger of a given device
  914. * @param dev A pointer to an iio_device structure
  915. * @param trigger a pointer to a pointer of an iio_device structure. The pointed
  916. * pointer will be set to the address of the iio_device structure corresponding
  917. * to the associated trigger device.
  918. * @return On success, 0 is returned
  919. * @return On error, a negative errno code is returned */
  920. __api __check_ret int iio_device_get_trigger(const struct iio_device *dev,
  921. const struct iio_device **trigger);
  922. /** @brief Associate a trigger to a given device
  923. * @param dev A pointer to an iio_device structure
  924. * @param trigger a pointer to the iio_device structure corresponding to the
  925. * trigger that should be associated.
  926. * @return On success, 0 is returned
  927. * @return On error, a negative errno code is returned */
  928. __api __check_ret int iio_device_set_trigger(const struct iio_device *dev,
  929. const struct iio_device *trigger);
  930. /** @brief Return True if the given device is a trigger
  931. * @param dev A pointer to an iio_device structure
  932. * @return True if the device is a trigger, False otherwise */
  933. __api __check_ret __pure bool iio_device_is_trigger(const struct iio_device *dev);
  934. /** @brief Configure the number of kernel buffers for a device
  935. *
  936. * This function allows to change the number of buffers on kernel side.
  937. * @param dev A pointer to an iio_device structure
  938. * @param nb_buffers The number of buffers
  939. * @return On success, 0 is returned
  940. * @return On error, a negative errno code is returned */
  941. __api __check_ret int iio_device_set_kernel_buffers_count(const struct iio_device *dev,
  942. unsigned int nb_buffers);
  943. /** @} *//* ------------------------------------------------------------------*/
  944. /* ------------------------- Channel functions -------------------------------*/
  945. /** @defgroup Channel Channel
  946. * @{
  947. * @struct iio_channel
  948. * @brief Represents an input or output channel of a device */
  949. /** @brief Retrieve a pointer to the iio_device structure
  950. * @param chn A pointer to an iio_channel structure
  951. * @return A pointer to an iio_device structure */
  952. __api __check_ret __pure const struct iio_device * iio_channel_get_device(
  953. const struct iio_channel *chn);
  954. /** @brief Retrieve the channel ID (e.g. <b><i>voltage0</i></b>)
  955. * @param chn A pointer to an iio_channel structure
  956. * @return A pointer to a static NULL-terminated string */
  957. __api __check_ret __pure const char * iio_channel_get_id(const struct iio_channel *chn);
  958. /** @brief Retrieve the channel name (e.g. <b><i>vccint</i></b>)
  959. * @param chn A pointer to an iio_channel structure
  960. * @return A pointer to a static NULL-terminated string
  961. *
  962. * <b>NOTE:</b> if the channel has no name, NULL is returned. */
  963. __api __check_ret __pure const char * iio_channel_get_name(const struct iio_channel *chn);
  964. /** @brief Return True if the given channel is an output channel
  965. * @param chn A pointer to an iio_channel structure
  966. * @return True if the channel is an output channel, False otherwise */
  967. __api __check_ret __pure bool iio_channel_is_output(const struct iio_channel *chn);
  968. /** @brief Return True if the given channel is a scan element
  969. * @param chn A pointer to an iio_channel structure
  970. * @return True if the channel is a scan element, False otherwise
  971. *
  972. * <b>NOTE:</b> a channel that is a scan element is a channel that can
  973. * generate samples (for an input channel) or receive samples (for an output
  974. * channel) after being enabled. */
  975. __api __check_ret __pure bool iio_channel_is_scan_element(const struct iio_channel *chn);
  976. /** @brief Enumerate the channel-specific attributes of the given channel
  977. * @param chn A pointer to an iio_channel structure
  978. * @return The number of channel-specific attributes found */
  979. __api __check_ret __pure unsigned int iio_channel_get_attrs_count(
  980. const struct iio_channel *chn);
  981. /** @brief Get the channel-specific attribute present at the given index
  982. * @param chn A pointer to an iio_channel structure
  983. * @param index The index corresponding to the attribute
  984. * @return On success, a pointer to a static NULL-terminated string
  985. * @return If the index is invalid, NULL is returned */
  986. __api __check_ret __pure const char * iio_channel_get_attr(
  987. const struct iio_channel *chn, unsigned int index);
  988. /** @brief Try to find a channel-specific attribute by its name
  989. * @param chn A pointer to an iio_channel structure
  990. * @param name A NULL-terminated string corresponding to the name of the
  991. * attribute
  992. * @return On success, a pointer to a static NULL-terminated string
  993. * @return If the name does not correspond to any known attribute of the given
  994. * channel, NULL is returned
  995. *
  996. * <b>NOTE:</b> This function is useful to detect the presence of an attribute.
  997. * It can also be used to retrieve the name of an attribute as a pointer to a
  998. * static string from a dynamically allocated string. */
  999. __api __check_ret __pure const char * iio_channel_find_attr(
  1000. const struct iio_channel *chn, const char *name);
  1001. /** @brief Retrieve the filename of an attribute
  1002. * @param chn A pointer to an iio_channel structure
  1003. * @param attr a NULL-terminated string corresponding to the name of the
  1004. * attribute
  1005. * @return On success, a pointer to a static NULL-terminated string
  1006. * @return If the attribute name is unknown, NULL is returned */
  1007. __api __check_ret __pure const char * iio_channel_attr_get_filename(
  1008. const struct iio_channel *chn, const char *attr);
  1009. /** @brief Read the content of the given channel-specific attribute
  1010. * @param chn A pointer to an iio_channel structure
  1011. * @param attr A NULL-terminated string corresponding to the name of the
  1012. * attribute
  1013. * @param dst A pointer to the memory area where the NULL-terminated string
  1014. * corresponding to the value read will be stored
  1015. * @param len The available length of the memory area, in bytes
  1016. * @return On success, the number of bytes written to the buffer
  1017. * @return On error, a negative errno code is returned
  1018. *
  1019. * <b>NOTE:</b>By passing NULL as the "attr" argument to iio_channel_attr_read,
  1020. * it is now possible to read all of the attributes of a channel.
  1021. *
  1022. * The buffer is filled with one block of data per attribute of the channel,
  1023. * by the order they appear in the iio_channel structure.
  1024. *
  1025. * The first four bytes of one block correspond to a 32-bit signed value in
  1026. * network order. If negative, it corresponds to the errno code that were
  1027. * returned when reading the attribute; if positive, it corresponds to the
  1028. * length of the data read. In that case, the rest of the block contains
  1029. * the data. */
  1030. __api __check_ret ssize_t iio_channel_attr_read(const struct iio_channel *chn,
  1031. const char *attr, char *dst, size_t len);
  1032. /** @brief Read the content of all channel-specific attributes
  1033. * @param chn A pointer to an iio_channel structure
  1034. * @param cb A pointer to a callback function
  1035. * @param data A pointer that will be passed to the callback function
  1036. * @return On success, 0 is returned
  1037. * @return On error, a negative errno code is returned
  1038. *
  1039. * <b>NOTE:</b> This function is especially useful when used with the network
  1040. * backend, as all the channel-specific attributes are read in one single
  1041. * command. */
  1042. __api __check_ret int iio_channel_attr_read_all(struct iio_channel *chn,
  1043. int (*cb)(struct iio_channel *chn,
  1044. const char *attr, const char *val, size_t len, void *d),
  1045. void *data);
  1046. /** @brief Read the content of the given channel-specific attribute
  1047. * @param chn A pointer to an iio_channel structure
  1048. * @param attr A NULL-terminated string corresponding to the name of the
  1049. * attribute
  1050. * @param val A pointer to a bool variable where the value should be stored
  1051. * @return On success, 0 is returned
  1052. * @return On error, a negative errno code is returned */
  1053. __api __check_ret int iio_channel_attr_read_bool(const struct iio_channel *chn,
  1054. const char *attr, bool *val);
  1055. /** @brief Read the content of the given channel-specific attribute
  1056. * @param chn A pointer to an iio_channel structure
  1057. * @param attr A NULL-terminated string corresponding to the name of the
  1058. * attribute
  1059. * @param val A pointer to a long long variable where the value should be stored
  1060. * @return On success, 0 is returned
  1061. * @return On error, a negative errno code is returned */
  1062. __api __check_ret int iio_channel_attr_read_longlong(const struct iio_channel *chn,
  1063. const char *attr, long long *val);
  1064. /** @brief Read the content of the given channel-specific attribute
  1065. * @param chn A pointer to an iio_channel structure
  1066. * @param attr A NULL-terminated string corresponding to the name of the
  1067. * attribute
  1068. * @param val A pointer to a double variable where the value should be stored
  1069. * @return On success, 0 is returned
  1070. * @return On error, a negative errno code is returned */
  1071. __api __check_ret int iio_channel_attr_read_double(const struct iio_channel *chn,
  1072. const char *attr, double *val);
  1073. /** @brief Set the value of the given channel-specific attribute
  1074. * @param chn A pointer to an iio_channel structure
  1075. * @param attr A NULL-terminated string corresponding to the name of the
  1076. * attribute
  1077. * @param src A NULL-terminated string to set the attribute to
  1078. * @return On success, the number of bytes written
  1079. * @return On error, a negative errno code is returned
  1080. *
  1081. * <b>NOTE:</b>By passing NULL as the "attr" argument to iio_channel_attr_write,
  1082. * it is now possible to write all of the attributes of a channel.
  1083. *
  1084. * The buffer must contain one block of data per attribute of the channel,
  1085. * by the order they appear in the iio_channel structure.
  1086. *
  1087. * The first four bytes of one block correspond to a 32-bit signed value in
  1088. * network order. If negative, the attribute is not written; if positive,
  1089. * it corresponds to the length of the data to write. In that case, the rest
  1090. * of the block must contain the data. */
  1091. __api __check_ret ssize_t iio_channel_attr_write(const struct iio_channel *chn,
  1092. const char *attr, const char *src);
  1093. /** @brief Set the value of the given channel-specific attribute
  1094. * @param chn A pointer to an iio_channel structure
  1095. * @param attr A NULL-terminated string corresponding to the name of the
  1096. * attribute
  1097. * @param src A pointer to the data to be written
  1098. * @param len The number of bytes that should be written
  1099. * @return On success, the number of bytes written
  1100. * @return On error, a negative errno code is returned */
  1101. __api __check_ret ssize_t iio_channel_attr_write_raw(const struct iio_channel *chn,
  1102. const char *attr, const void *src, size_t len);
  1103. /** @brief Set the values of all channel-specific attributes
  1104. * @param chn A pointer to an iio_channel structure
  1105. * @param cb A pointer to a callback function
  1106. * @param data A pointer that will be passed to the callback function
  1107. * @return On success, 0 is returned
  1108. * @return On error, a negative errno code is returned
  1109. *
  1110. * <b>NOTE:</b> This function is especially useful when used with the network
  1111. * backend, as all the channel-specific attributes are written in one single
  1112. * command. */
  1113. __api __check_ret int iio_channel_attr_write_all(struct iio_channel *chn,
  1114. ssize_t (*cb)(struct iio_channel *chn,
  1115. const char *attr, void *buf, size_t len, void *d),
  1116. void *data);
  1117. /** @brief Set the value of the given channel-specific attribute
  1118. * @param chn A pointer to an iio_channel structure
  1119. * @param attr A NULL-terminated string corresponding to the name of the
  1120. * attribute
  1121. * @param val A bool value to set the attribute to
  1122. * @return On success, 0 is returned
  1123. * @return On error, a negative errno code is returned */
  1124. __api __check_ret int iio_channel_attr_write_bool(const struct iio_channel *chn,
  1125. const char *attr, bool val);
  1126. /** @brief Set the value of the given channel-specific attribute
  1127. * @param chn A pointer to an iio_channel structure
  1128. * @param attr A NULL-terminated string corresponding to the name of the
  1129. * attribute
  1130. * @param val A long long value to set the attribute to
  1131. * @return On success, 0 is returned
  1132. * @return On error, a negative errno code is returned */
  1133. __api __check_ret int iio_channel_attr_write_longlong(const struct iio_channel *chn,
  1134. const char *attr, long long val);
  1135. /** @brief Set the value of the given channel-specific attribute
  1136. * @param chn A pointer to an iio_channel structure
  1137. * @param attr A NULL-terminated string corresponding to the name of the
  1138. * attribute
  1139. * @param val A double value to set the attribute to
  1140. * @return On success, 0 is returned
  1141. * @return On error, a negative errno code is returned */
  1142. __api __check_ret int iio_channel_attr_write_double(const struct iio_channel *chn,
  1143. const char *attr, double val);
  1144. /** @brief Enable the given channel
  1145. * @param chn A pointer to an iio_channel structure
  1146. *
  1147. * <b>NOTE:</b>Before creating an iio_buffer structure with
  1148. * iio_device_create_buffer, it is required to enable at least one channel of
  1149. * the device to read from. */
  1150. __api void iio_channel_enable(struct iio_channel *chn);
  1151. /** @brief Disable the given channel
  1152. * @param chn A pointer to an iio_channel structure */
  1153. __api void iio_channel_disable(struct iio_channel *chn);
  1154. /** @brief Returns True if the channel is enabled
  1155. * @param chn A pointer to an iio_channel structure
  1156. * @return True if the channel is enabled, False otherwise */
  1157. __api __check_ret bool iio_channel_is_enabled(const struct iio_channel *chn);
  1158. /** @brief Demultiplex the samples of a given channel
  1159. * @param chn A pointer to an iio_channel structure
  1160. * @param buffer A pointer to an iio_buffer structure
  1161. * @param dst A pointer to the memory area where the demultiplexed data will be
  1162. * stored
  1163. * @param len The available length of the memory area, in bytes
  1164. * @return The size of the demultiplexed data, in bytes */
  1165. __api __check_ret size_t iio_channel_read_raw(const struct iio_channel *chn,
  1166. struct iio_buffer *buffer, void *dst, size_t len);
  1167. /** @brief Demultiplex and convert the samples of a given channel
  1168. * @param chn A pointer to an iio_channel structure
  1169. * @param buffer A pointer to an iio_buffer structure
  1170. * @param dst A pointer to the memory area where the converted data will be
  1171. * stored
  1172. * @param len The available length of the memory area, in bytes
  1173. * @return The size of the converted data, in bytes */
  1174. __api __check_ret size_t iio_channel_read(const struct iio_channel *chn,
  1175. struct iio_buffer *buffer, void *dst, size_t len);
  1176. /** @brief Multiplex the samples of a given channel
  1177. * @param chn A pointer to an iio_channel structure
  1178. * @param buffer A pointer to an iio_buffer structure
  1179. * @param src A pointer to the memory area where the sequential data will
  1180. * be read from
  1181. * @param len The length of the memory area, in bytes
  1182. * @return The number of bytes actually multiplexed */
  1183. __api __check_ret size_t iio_channel_write_raw(const struct iio_channel *chn,
  1184. struct iio_buffer *buffer, const void *src, size_t len);
  1185. /** @brief Convert and multiplex the samples of a given channel
  1186. * @param chn A pointer to an iio_channel structure
  1187. * @param buffer A pointer to an iio_buffer structure
  1188. * @param src A pointer to the memory area where the sequential data will
  1189. * be read from
  1190. * @param len The length of the memory area, in bytes
  1191. * @return The number of bytes actually converted and multiplexed */
  1192. __api __check_ret size_t iio_channel_write(const struct iio_channel *chn,
  1193. struct iio_buffer *buffer, const void *src, size_t len);
  1194. /** @brief Associate a pointer to an iio_channel structure
  1195. * @param chn A pointer to an iio_channel structure
  1196. * @param data The pointer to be associated */
  1197. __api void iio_channel_set_data(struct iio_channel *chn, void *data);
  1198. /** @brief Retrieve a previously associated pointer of an iio_channel structure
  1199. * @param chn A pointer to an iio_channel structure
  1200. * @return The pointer previously associated if present, or NULL */
  1201. __api void * iio_channel_get_data(const struct iio_channel *chn);
  1202. /** @brief Get the type of the given channel
  1203. * @param chn A pointer to an iio_channel structure
  1204. * @return The type of the channel */
  1205. __api __check_ret __pure enum iio_chan_type iio_channel_get_type(
  1206. const struct iio_channel *chn);
  1207. /** @brief Get the modifier type of the given channel
  1208. * @param chn A pointer to an iio_channel structure
  1209. * @return The modifier type of the channel */
  1210. __api __check_ret __pure enum iio_modifier iio_channel_get_modifier(
  1211. const struct iio_channel *chn);
  1212. /** @} *//* ------------------------------------------------------------------*/
  1213. /* ------------------------- Buffer functions --------------------------------*/
  1214. /** @defgroup Buffer Buffer
  1215. * @{
  1216. * @struct iio_buffer
  1217. * @brief An input or output buffer, used to read or write samples */
  1218. /** @brief Retrieve a pointer to the iio_device structure
  1219. * @param buf A pointer to an iio_buffer structure
  1220. * @return A pointer to an iio_device structure */
  1221. __api __check_ret __pure const struct iio_device * iio_buffer_get_device(
  1222. const struct iio_buffer *buf);
  1223. /** @brief Create an input or output buffer associated to the given device
  1224. * @param dev A pointer to an iio_device structure
  1225. * @param samples_count The number of samples that the buffer should contain
  1226. * @param cyclic If True, enable cyclic mode
  1227. * @return On success, a pointer to an iio_buffer structure
  1228. * @return On error, NULL is returned, and errno is set to the error code
  1229. *
  1230. * <b>NOTE:</b> Channels that have to be written to / read from must be enabled
  1231. * before creating the buffer. */
  1232. __api __check_ret struct iio_buffer * iio_device_create_buffer(const struct iio_device *dev,
  1233. size_t samples_count, bool cyclic);
  1234. /** @brief Destroy the given buffer
  1235. * @param buf A pointer to an iio_buffer structure
  1236. *
  1237. * <b>NOTE:</b> After that function, the iio_buffer pointer shall be invalid. */
  1238. __api void iio_buffer_destroy(struct iio_buffer *buf);
  1239. /** @brief Get a pollable file descriptor
  1240. *
  1241. * Can be used to know when iio_buffer_refill() or iio_buffer_push() can be
  1242. * called
  1243. * @param buf A pointer to an iio_buffer structure
  1244. * @return On success, valid file descriptor
  1245. * @return On error, a negative errno code is returned
  1246. */
  1247. __api __check_ret int iio_buffer_get_poll_fd(struct iio_buffer *buf);
  1248. /** @brief Make iio_buffer_refill() and iio_buffer_push() blocking or not
  1249. *
  1250. * After this function has been called with blocking == false,
  1251. * iio_buffer_refill() and iio_buffer_push() will return -EAGAIN if no data is
  1252. * ready.
  1253. * A device is blocking by default.
  1254. * @param buf A pointer to an iio_buffer structure
  1255. * @param blocking true if the buffer API should be blocking, else false
  1256. * @return On success, 0
  1257. * @return On error, a negative errno code is returned
  1258. */
  1259. __api __check_ret int iio_buffer_set_blocking_mode(struct iio_buffer *buf, bool blocking);
  1260. /** @brief Fetch more samples from the hardware
  1261. * @param buf A pointer to an iio_buffer structure
  1262. * @return On success, the number of bytes read is returned
  1263. * @return On error, a negative errno code is returned
  1264. *
  1265. * <b>NOTE:</b> Only valid for input buffers */
  1266. __api __check_ret ssize_t iio_buffer_refill(struct iio_buffer *buf);
  1267. /** @brief Send the samples to the hardware
  1268. * @param buf A pointer to an iio_buffer structure
  1269. * @return On success, the number of bytes written is returned
  1270. * @return On error, a negative errno code is returned
  1271. *
  1272. * <b>NOTE:</b> Only valid for output buffers */
  1273. __api __check_ret ssize_t iio_buffer_push(struct iio_buffer *buf);
  1274. /** @brief Send a given number of samples to the hardware
  1275. * @param buf A pointer to an iio_buffer structure
  1276. * @param samples_count The number of samples to submit
  1277. * @return On success, the number of bytes written is returned
  1278. * @return On error, a negative errno code is returned
  1279. *
  1280. * <b>NOTE:</b> Only valid for output buffers */
  1281. __api __check_ret ssize_t iio_buffer_push_partial(struct iio_buffer *buf,
  1282. size_t samples_count);
  1283. /** @brief Cancel all buffer operations
  1284. * @param buf The buffer for which operations should be canceled
  1285. *
  1286. * This function cancels all outstanding buffer operations previously scheduled.
  1287. * This means any pending iio_buffer_push() or iio_buffer_refill() operation
  1288. * will abort and return immediately, any further invocations of these functions
  1289. * on the same buffer will return immediately with an error.
  1290. *
  1291. * Usually iio_buffer_push() and iio_buffer_refill() will block until either all
  1292. * data has been transferred or a timeout occurs. This can depending on the
  1293. * configuration take a significant amount of time. iio_buffer_cancel() is
  1294. * useful to bypass these conditions if the buffer operation is supposed to be
  1295. * stopped in response to an external event (e.g. user input).
  1296. *
  1297. * To be able to capture additional data after calling this function the buffer
  1298. * should be destroyed and then re-created.
  1299. *
  1300. * This function can be called multiple times for the same buffer, but all but
  1301. * the first invocation will be without additional effect.
  1302. *
  1303. * This function is thread-safe, but not signal-safe, i.e. it must not be called
  1304. * from a signal handler.
  1305. */
  1306. __api void iio_buffer_cancel(struct iio_buffer *buf);
  1307. /** @brief Get the start address of the buffer
  1308. * @param buf A pointer to an iio_buffer structure
  1309. * @return A pointer corresponding to the start address of the buffer */
  1310. __api void * iio_buffer_start(const struct iio_buffer *buf);
  1311. /** @brief Find the first sample of a channel in a buffer
  1312. * @param buf A pointer to an iio_buffer structure
  1313. * @param chn A pointer to an iio_channel structure
  1314. * @return A pointer to the first sample found, or to the end of the buffer if
  1315. * no sample for the given channel is present in the buffer
  1316. *
  1317. * <b>NOTE:</b> This function, coupled with iio_buffer_step and iio_buffer_end,
  1318. * can be used to iterate on all the samples of a given channel present in the
  1319. * buffer, doing the following:
  1320. *
  1321. * @verbatim
  1322. for (void *ptr = iio_buffer_first(buffer, chn); ptr < iio_buffer_end(buffer); ptr += iio_buffer_step(buffer)) {
  1323. ....
  1324. }
  1325. @endverbatim */
  1326. __api void * iio_buffer_first(const struct iio_buffer *buf,
  1327. const struct iio_channel *chn);
  1328. /** @brief Get the step size between two samples of one channel
  1329. * @param buf A pointer to an iio_buffer structure
  1330. * @return the difference between the addresses of two consecutive samples of
  1331. * one same channel */
  1332. __api __check_ret ptrdiff_t iio_buffer_step(const struct iio_buffer *buf);
  1333. /** @brief Get the address that follows the last sample in a buffer
  1334. * @param buf A pointer to an iio_buffer structure
  1335. * @return A pointer corresponding to the address that follows the last sample
  1336. * present in the buffer */
  1337. __api void * iio_buffer_end(const struct iio_buffer *buf);
  1338. /** @brief Call the supplied callback for each sample found in a buffer
  1339. * @param buf A pointer to an iio_buffer structure
  1340. * @param callback A pointer to a function to call for each sample found
  1341. * @param data A user-specified pointer that will be passed to the callback
  1342. * @return number of bytes processed.
  1343. *
  1344. * <b>NOTE:</b> The callback receives four arguments:
  1345. * * A pointer to the iio_channel structure corresponding to the sample,
  1346. * * A pointer to the sample itself,
  1347. * * The length of the sample in bytes,
  1348. * * The user-specified pointer passed to iio_buffer_foreach_sample. */
  1349. __api __check_ret ssize_t iio_buffer_foreach_sample(struct iio_buffer *buf,
  1350. ssize_t (*callback)(const struct iio_channel *chn,
  1351. void *src, size_t bytes, void *d), void *data);
  1352. /** @brief Associate a pointer to an iio_buffer structure
  1353. * @param buf A pointer to an iio_buffer structure
  1354. * @param data The pointer to be associated */
  1355. __api void iio_buffer_set_data(struct iio_buffer *buf, void *data);
  1356. /** @brief Retrieve a previously associated pointer of an iio_buffer structure
  1357. * @param buf A pointer to an iio_buffer structure
  1358. * @return The pointer previously associated if present, or NULL */
  1359. __api void * iio_buffer_get_data(const struct iio_buffer *buf);
  1360. /** @} *//* ------------------------------------------------------------------*/
  1361. /* ---------------------------- HWMON support --------------------------------*/
  1362. /** @defgroup Hwmon Compatibility with hardware monitoring (hwmon) devices
  1363. * @{
  1364. * @enum hwmon_chan_type
  1365. * @brief Hwmon channel type
  1366. *
  1367. * Libiio support hardware-monitoring (hwmon) devices as well. This enum
  1368. * specifies the type of data associated with the hwmon channel.
  1369. *
  1370. * NOTE: as of 2021 only the current hwmon API is supported. The old
  1371. * and deprecated APIs are not supported, and won't be supported unless we
  1372. * have a case where updating a hwmon driver is not possible.
  1373. */
  1374. enum hwmon_chan_type {
  1375. HWMON_VOLTAGE,
  1376. HWMON_FAN,
  1377. HWMON_PWM,
  1378. HWMON_TEMP,
  1379. HWMON_CURRENT,
  1380. HWMON_POWER,
  1381. HWMON_ENERGY,
  1382. HWMON_HUMIDITY,
  1383. HWMON_INTRUSION,
  1384. HWMON_CHAN_TYPE_UNKNOWN = IIO_CHAN_TYPE_UNKNOWN,
  1385. };
  1386. /**
  1387. * @brief Get the type of the given hwmon channel
  1388. * @param chn A pointer to an iio_channel structure
  1389. * @return The type of the hwmon channel */
  1390. static inline enum hwmon_chan_type
  1391. hwmon_channel_get_type(const struct iio_channel *chn)
  1392. {
  1393. return (enum hwmon_chan_type) iio_channel_get_type(chn);
  1394. }
  1395. /**
  1396. * @brief Get whether or not the device is a hardware monitoring device
  1397. * @param dev A pointer to an iio_device structure
  1398. * @return True if the device is a hardware monitoring device,
  1399. * false if it is a IIO device */
  1400. static inline bool iio_device_is_hwmon(const struct iio_device *dev)
  1401. {
  1402. const char *id = iio_device_get_id(dev);
  1403. return id[0] == 'h';
  1404. }
  1405. /** @} *//* ------------------------------------------------------------------*/
  1406. /* ------------------------- Low-level functions -----------------------------*/
  1407. /** @defgroup Debug Debug and low-level functions
  1408. * @{
  1409. * @struct iio_data_format
  1410. * @brief Contains the format of a data sample.
  1411. *
  1412. * The different fields inform about the correct way to convert one sample from
  1413. * its raw format (as read from / generated by the hardware) to its real-world
  1414. * value.
  1415. */
  1416. struct iio_data_format {
  1417. /** @brief Total length of the sample, in bits */
  1418. unsigned int length;
  1419. /** @brief Length of valuable data in the sample, in bits */
  1420. unsigned int bits;
  1421. /** @brief Right-shift to apply when converting sample */
  1422. unsigned int shift;
  1423. /** @brief Contains True if the sample is signed */
  1424. bool is_signed;
  1425. /** @brief Contains True if the sample is fully defined, sign extended, etc. */
  1426. bool is_fully_defined;
  1427. /** @brief Contains True if the sample is in big-endian format */
  1428. bool is_be;
  1429. /** @brief Contains True if the sample should be scaled when converted */
  1430. bool with_scale;
  1431. /** @brief Contains the scale to apply if with_scale is set */
  1432. double scale;
  1433. /** @brief Number of times length repeats (added in v0.8) */
  1434. unsigned int repeat;
  1435. };
  1436. /** @brief Get the current sample size
  1437. * @param dev A pointer to an iio_device structure
  1438. * @return On success, the sample size in bytes
  1439. * @return On error, a negative errno code is returned
  1440. *
  1441. * <b>NOTE:</b> The sample size is not constant and will change when channels
  1442. * get enabled or disabled. */
  1443. __api __check_ret ssize_t iio_device_get_sample_size(const struct iio_device *dev);
  1444. /** @brief Get the index of the given channel
  1445. * @param chn A pointer to an iio_channel structure
  1446. * @return On success, the index of the specified channel
  1447. * @return On error, a negative errno code is returned */
  1448. __api __check_ret __pure long iio_channel_get_index(const struct iio_channel *chn);
  1449. /** @brief Get a pointer to a channel's data format structure
  1450. * @param chn A pointer to an iio_channel structure
  1451. * @return A pointer to the channel's iio_data_format structure */
  1452. __api __check_ret __cnst const struct iio_data_format * iio_channel_get_data_format(
  1453. const struct iio_channel *chn);
  1454. /** @brief Convert the sample from hardware format to host format
  1455. * @param chn A pointer to an iio_channel structure
  1456. * @param dst A pointer to the destination buffer where the converted sample
  1457. * should be written
  1458. * @param src A pointer to the source buffer containing the sample */
  1459. __api void iio_channel_convert(const struct iio_channel *chn,
  1460. void *dst, const void *src);
  1461. /** @brief Convert the sample from host format to hardware format
  1462. * @param chn A pointer to an iio_channel structure
  1463. * @param dst A pointer to the destination buffer where the converted sample
  1464. * should be written
  1465. * @param src A pointer to the source buffer containing the sample */
  1466. __api void iio_channel_convert_inverse(const struct iio_channel *chn,
  1467. void *dst, const void *src);
  1468. /** @brief Enumerate the debug attributes of the given device
  1469. * @param dev A pointer to an iio_device structure
  1470. * @return The number of debug attributes found */
  1471. __api __check_ret __pure unsigned int iio_device_get_debug_attrs_count(
  1472. const struct iio_device *dev);
  1473. /** @brief Get the debug attribute present at the given index
  1474. * @param dev A pointer to an iio_device structure
  1475. * @param index The index corresponding to the debug attribute
  1476. * @return On success, a pointer to a static NULL-terminated string
  1477. * @return If the index is invalid, NULL is returned */
  1478. __api __check_ret __pure const char * iio_device_get_debug_attr(
  1479. const struct iio_device *dev, unsigned int index);
  1480. /** @brief Try to find a debug attribute by its name
  1481. * @param dev A pointer to an iio_device structure
  1482. * @param name A NULL-terminated string corresponding to the name of the
  1483. * debug attribute
  1484. * @return On success, a pointer to a static NULL-terminated string
  1485. * @return If the name does not correspond to any known debug attribute of the
  1486. * given device, NULL is returned
  1487. *
  1488. * <b>NOTE:</b> This function is useful to detect the presence of a debug
  1489. * attribute.
  1490. * It can also be used to retrieve the name of a debug attribute as a pointer
  1491. * to a static string from a dynamically allocated string. */
  1492. __api __check_ret __pure const char * iio_device_find_debug_attr(
  1493. const struct iio_device *dev, const char *name);
  1494. /** @brief Read the content of the given debug attribute
  1495. * @param dev A pointer to an iio_device structure
  1496. * @param attr A NULL-terminated string corresponding to the name of the
  1497. * debug attribute
  1498. * @param dst A pointer to the memory area where the NULL-terminated string
  1499. * corresponding to the value read will be stored
  1500. * @param len The available length of the memory area, in bytes
  1501. * @return On success, the number of bytes written to the buffer
  1502. * @return On error, a negative errno code is returned
  1503. *
  1504. * <b>NOTE:</b>By passing NULL as the "attr" argument to
  1505. * iio_device_debug_attr_read, it is now possible to read all of the debug
  1506. * attributes of a device.
  1507. *
  1508. * The buffer is filled with one block of data per debug attribute of the
  1509. * device, by the order they appear in the iio_device structure.
  1510. *
  1511. * The first four bytes of one block correspond to a 32-bit signed value in
  1512. * network order. If negative, it corresponds to the errno code that were
  1513. * returned when reading the debug attribute; if positive, it corresponds
  1514. * to the length of the data read. In that case, the rest of the block contains
  1515. * the data. */
  1516. __api __check_ret ssize_t iio_device_debug_attr_read(const struct iio_device *dev,
  1517. const char *attr, char *dst, size_t len);
  1518. /** @brief Read the content of all debug attributes
  1519. * @param dev A pointer to an iio_device structure
  1520. * @param cb A pointer to a callback function
  1521. * @param data A pointer that will be passed to the callback function
  1522. * @return On success, 0 is returned
  1523. * @return On error, a negative errno code is returned
  1524. *
  1525. * <b>NOTE:</b> This function is especially useful when used with the network
  1526. * backend, as all the debug attributes are read in one single command. */
  1527. __api __check_ret int iio_device_debug_attr_read_all(struct iio_device *dev,
  1528. int (*cb)(struct iio_device *dev, const char *attr,
  1529. const char *value, size_t len, void *d),
  1530. void *data);
  1531. /** @brief Set the value of the given debug attribute
  1532. * @param dev A pointer to an iio_device structure
  1533. * @param attr A NULL-terminated string corresponding to the name of the
  1534. * debug attribute
  1535. * @param src A NULL-terminated string to set the debug attribute to
  1536. * @return On success, the number of bytes written
  1537. * @return On error, a negative errno code is returned
  1538. *
  1539. * <b>NOTE:</b>By passing NULL as the "attr" argument to
  1540. * iio_device_debug_attr_write, it is now possible to write all of the
  1541. * debug attributes of a device.
  1542. *
  1543. * The buffer must contain one block of data per debug attribute of the device,
  1544. * by the order they appear in the iio_device structure.
  1545. *
  1546. * The first four bytes of one block correspond to a 32-bit signed value in
  1547. * network order. If negative, the debug attribute is not written; if positive,
  1548. * it corresponds to the length of the data to write. In that case, the rest
  1549. * of the block must contain the data. */
  1550. __api __check_ret ssize_t iio_device_debug_attr_write(const struct iio_device *dev,
  1551. const char *attr, const char *src);
  1552. /** @brief Set the value of the given debug attribute
  1553. * @param dev A pointer to an iio_device structure
  1554. * @param attr A NULL-terminated string corresponding to the name of the
  1555. * debug attribute
  1556. * @param src A pointer to the data to be written
  1557. * @param len The number of bytes that should be written
  1558. * @return On success, the number of bytes written
  1559. * @return On error, a negative errno code is returned */
  1560. __api __check_ret ssize_t iio_device_debug_attr_write_raw(const struct iio_device *dev,
  1561. const char *attr, const void *src, size_t len);
  1562. /** @brief Set the values of all debug attributes
  1563. * @param dev A pointer to an iio_device structure
  1564. * @param cb A pointer to a callback function
  1565. * @param data A pointer that will be passed to the callback function
  1566. * @return On success, 0 is returned
  1567. * @return On error, a negative errno code is returned
  1568. *
  1569. * <b>NOTE:</b> This function is especially useful when used with the network
  1570. * backend, as all the debug attributes are written in one single command. */
  1571. __api __check_ret int iio_device_debug_attr_write_all(struct iio_device *dev,
  1572. ssize_t (*cb)(struct iio_device *dev,
  1573. const char *attr, void *buf, size_t len, void *d),
  1574. void *data);
  1575. /** @brief Read the content of the given debug attribute
  1576. * @param dev A pointer to an iio_device structure
  1577. * @param attr A NULL-terminated string corresponding to the name of the
  1578. * debug attribute
  1579. * @param val A pointer to a bool variable where the value should be stored
  1580. * @return On success, 0 is returned
  1581. * @return On error, a negative errno code is returned */
  1582. __api __check_ret int iio_device_debug_attr_read_bool(const struct iio_device *dev,
  1583. const char *attr, bool *val);
  1584. /** @brief Read the content of the given debug attribute
  1585. * @param dev A pointer to an iio_device structure
  1586. * @param attr A NULL-terminated string corresponding to the name of the
  1587. * debug attribute
  1588. * @param val A pointer to a long long variable where the value should be stored
  1589. * @return On success, 0 is returned
  1590. * @return On error, a negative errno code is returned */
  1591. __api __check_ret int iio_device_debug_attr_read_longlong(const struct iio_device *dev,
  1592. const char *attr, long long *val);
  1593. /** @brief Read the content of the given debug attribute
  1594. * @param dev A pointer to an iio_device structure
  1595. * @param attr A NULL-terminated string corresponding to the name of the
  1596. * debug attribute
  1597. * @param val A pointer to a double variable where the value should be stored
  1598. * @return On success, 0 is returned
  1599. * @return On error, a negative errno code is returned */
  1600. __api __check_ret int iio_device_debug_attr_read_double(const struct iio_device *dev,
  1601. const char *attr, double *val);
  1602. /** @brief Set the value of the given debug attribute
  1603. * @param dev A pointer to an iio_device structure
  1604. * @param attr A NULL-terminated string corresponding to the name of the
  1605. * debug attribute
  1606. * @param val A bool value to set the debug attribute to
  1607. * @return On success, 0 is returned
  1608. * @return On error, a negative errno code is returned */
  1609. __api __check_ret int iio_device_debug_attr_write_bool(const struct iio_device *dev,
  1610. const char *attr, bool val);
  1611. /** @brief Set the value of the given debug attribute
  1612. * @param dev A pointer to an iio_device structure
  1613. * @param attr A NULL-terminated string corresponding to the name of the
  1614. * debug attribute
  1615. * @param val A long long value to set the debug attribute to
  1616. * @return On success, 0 is returned
  1617. * @return On error, a negative errno code is returned */
  1618. __api __check_ret int iio_device_debug_attr_write_longlong(const struct iio_device *dev,
  1619. const char *attr, long long val);
  1620. /** @brief Set the value of the given debug attribute
  1621. * @param dev A pointer to an iio_device structure
  1622. * @param attr A NULL-terminated string corresponding to the name of the
  1623. * debug attribute
  1624. * @param val A double value to set the debug attribute to
  1625. * @return On success, 0 is returned
  1626. * @return On error, a negative errno code is returned */
  1627. __api __check_ret int iio_device_debug_attr_write_double(const struct iio_device *dev,
  1628. const char *attr, double val);
  1629. /** @brief Identify the channel or debug attribute corresponding to a filename
  1630. * @param dev A pointer to an iio_device structure
  1631. * @param filename A NULL-terminated string corresponding to the filename
  1632. * @param chn A pointer to a pointer of an iio_channel structure. The pointed
  1633. * pointer will be set to the address of the iio_channel structure if the
  1634. * filename correspond to the attribute of a channel, or NULL otherwise.
  1635. * @param attr A pointer to a NULL-terminated string. The pointer
  1636. * pointer will be set to point to the name of the attribute corresponding to
  1637. * the filename.
  1638. * @return On success, 0 is returned, and *chn and *attr are modified.
  1639. * @return On error, a negative errno code is returned. *chn and *attr are not
  1640. * modified. */
  1641. __api __check_ret int iio_device_identify_filename(const struct iio_device *dev,
  1642. const char *filename, struct iio_channel **chn,
  1643. const char **attr);
  1644. /** @brief Set the value of a hardware register
  1645. * @param dev A pointer to an iio_device structure
  1646. * @param address The address of the register
  1647. * @param value The value to set the register to
  1648. * @return On success, 0 is returned
  1649. * @return On error, a negative errno code is returned */
  1650. __api __check_ret int iio_device_reg_write(struct iio_device *dev,
  1651. uint32_t address, uint32_t value);
  1652. /** @brief Get the value of a hardware register
  1653. * @param dev A pointer to an iio_device structure
  1654. * @param address The address of the register
  1655. * @param value A pointer to the variable where the value will be written
  1656. * @return On success, 0 is returned
  1657. * @return On error, a negative errno code is returned */
  1658. __api __check_ret int iio_device_reg_read(struct iio_device *dev,
  1659. uint32_t address, uint32_t *value);
  1660. /** @} */
  1661. #ifdef __cplusplus
  1662. }
  1663. #endif
  1664. #undef __api
  1665. #endif /* __IIO_H__ */