libiio  0.9
Library for interfacing with IIO devices
/home/travis/build/analogdevicesinc/libiio/iio.h
Go to the documentation of this file.
00001 /*
00002  * libiio - Library for interfacing industrial I/O (IIO) devices
00003  *
00004  * Copyright (C) 2014 Analog Devices, Inc.
00005  * Author: Paul Cercueil <paul.cercueil@analog.com>
00006  *
00007  * This library is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU Lesser General Public
00009  * License as published by the Free Software Foundation; either
00010  * version 2.1 of the License, or (at your option) any later version.
00011  *
00012  * This library is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015  * Lesser General Public License for more details.
00016  *
00017  * */
00018 
00022 #ifndef __IIO_H__
00023 #define __IIO_H__
00024 
00025 #ifdef __cplusplus
00026 extern "C" {
00027 #endif
00028 
00029 #include <limits.h>
00030 #include <stdint.h>
00031 #include <stdlib.h>
00032 #include <stddef.h>
00033 
00034 #if (defined(_WIN32) || defined(__MBED__))
00035 #ifndef _SSIZE_T_DEFINED
00036 typedef ptrdiff_t ssize_t;
00037 #define _SSIZE_T_DEFINED
00038 #endif
00039 #else
00040 #include <sys/types.h>
00041 #endif
00042 
00043 #if defined(_MSC_VER) && (_MSC_VER < 1800) && !defined(__BOOL_DEFINED)
00044 #undef bool
00045 #undef false
00046 #undef true
00047 #define bool char
00048 #define false 0
00049 #define true 1
00050 #else
00051 #include <stdbool.h>
00052 #endif
00053 
00054 #if defined(__GNUC__) && !defined(MATLAB_MEX_FILE) && !defined(MATLAB_LOADLIBRARY)
00055 #ifndef __cnst
00056 #define __cnst __attribute__((const))
00057 #endif
00058 #ifndef __pure
00059 #define __pure __attribute__((pure))
00060 #endif
00061 #define __notused __attribute__((unused))
00062 #else
00063 #define __cnst
00064 #define __pure
00065 #define __notused
00066 #endif
00067 
00068 #ifdef _WIN32
00069 #   ifdef LIBIIO_EXPORTS
00070 #   define __api __declspec(dllexport)
00071 #   else
00072 #   define __api __declspec(dllimport)
00073 #   endif
00074 #elif __GNUC__ >= 4 && !defined(MATLAB_MEX_FILE) && !defined(MATLAB_LOADLIBRARY)
00075 #   define __api __attribute__((visibility ("default")))
00076 #else
00077 #   define __api
00078 #endif
00079 
00080 struct iio_context;
00081 struct iio_device;
00082 struct iio_channel;
00083 struct iio_buffer;
00084 
00085 struct iio_context_info;
00086 struct iio_scan_context;
00087 
00095 enum iio_chan_type {
00096     IIO_VOLTAGE,
00097     IIO_CURRENT,
00098     IIO_POWER,
00099     IIO_ACCEL,
00100     IIO_ANGL_VEL,
00101     IIO_MAGN,
00102     IIO_LIGHT,
00103     IIO_INTENSITY,
00104     IIO_PROXIMITY,
00105     IIO_TEMP,
00106     IIO_INCLI,
00107     IIO_ROT,
00108     IIO_ANGL,
00109     IIO_TIMESTAMP,
00110     IIO_CAPACITANCE,
00111     IIO_ALTVOLTAGE,
00112     IIO_CCT,
00113     IIO_PRESSURE,
00114     IIO_HUMIDITYRELATIVE,
00115     IIO_ACTIVITY,
00116     IIO_STEPS,
00117     IIO_ENERGY,
00118     IIO_DISTANCE,
00119     IIO_VELOCITY,
00120     IIO_CONCENTRATION,
00121     IIO_RESISTANCE,
00122     IIO_PH,
00123     IIO_CHAN_TYPE_UNKNOWN = INT_MAX
00124 };
00125 
00133 enum iio_modifier {
00134     IIO_NO_MOD,
00135     IIO_MOD_X,
00136     IIO_MOD_Y,
00137     IIO_MOD_Z,
00138     IIO_MOD_X_AND_Y,
00139     IIO_MOD_X_AND_Z,
00140     IIO_MOD_Y_AND_Z,
00141     IIO_MOD_X_AND_Y_AND_Z,
00142     IIO_MOD_X_OR_Y,
00143     IIO_MOD_X_OR_Z,
00144     IIO_MOD_Y_OR_Z,
00145     IIO_MOD_X_OR_Y_OR_Z,
00146     IIO_MOD_LIGHT_BOTH,
00147     IIO_MOD_LIGHT_IR,
00148     IIO_MOD_ROOT_SUM_SQUARED_X_Y,
00149     IIO_MOD_SUM_SQUARED_X_Y_Z,
00150     IIO_MOD_LIGHT_CLEAR,
00151     IIO_MOD_LIGHT_RED,
00152     IIO_MOD_LIGHT_GREEN,
00153     IIO_MOD_LIGHT_BLUE,
00154     IIO_MOD_QUATERNION,
00155     IIO_MOD_TEMP_AMBIENT,
00156     IIO_MOD_TEMP_OBJECT,
00157     IIO_MOD_NORTH_MAGN,
00158     IIO_MOD_NORTH_TRUE,
00159     IIO_MOD_NORTH_MAGN_TILT_COMP,
00160     IIO_MOD_NORTH_TRUE_TILT_COMP,
00161     IIO_MOD_RUNNING,
00162     IIO_MOD_JOGGING,
00163     IIO_MOD_WALKING,
00164     IIO_MOD_STILL,
00165     IIO_MOD_ROOT_SUM_SQUARED_X_Y_Z,
00166     IIO_MOD_I,
00167     IIO_MOD_Q,
00168     IIO_MOD_CO2,
00169     IIO_MOD_VOC,
00170 };
00171 
00172 /* ---------------------------------------------------------------------------*/
00173 /* ------------------------- Scan functions ----------------------------------*/
00190 __api struct iio_scan_context * iio_create_scan_context(
00191         const char *backend, unsigned int flags);
00192 
00193 
00198 __api void iio_scan_context_destroy(struct iio_scan_context *ctx);
00199 
00200 
00208 __api ssize_t iio_scan_context_get_info_list(struct iio_scan_context *ctx,
00209         struct iio_context_info ***info);
00210 
00211 
00215 __api void iio_context_info_list_free(struct iio_context_info **info);
00216 
00217 
00222 __api __pure const char * iio_context_info_get_description(
00223         const struct iio_context_info *info);
00224 
00225 
00230 __api __pure const char * iio_context_info_get_uri(
00231         const struct iio_context_info *info);
00232 
00233 /* ------------------------------------------------------------------*/
00235 /* ------------------------- Top-level functions -----------------------------*/
00244 __api void iio_library_get_version(unsigned int *major,
00245         unsigned int *minor, char git_tag[8]);
00246 
00247 
00253 __api void iio_strerror(int err, char *dst, size_t len);
00254 
00255 
00261 __api __cnst bool iio_has_backend(const char *backend);
00262 
00263 
00268 __api __cnst unsigned int iio_get_backends_count(void);
00269 
00270 
00277 __api __cnst const char * iio_get_backend(unsigned int index);
00278 
00279 /* ------------------------------------------------------------------*/
00281 /* ------------------------- Context functions -------------------------------*/
00297 __api struct iio_context * iio_create_default_context(void);
00298 
00299 
00303 __api struct iio_context * iio_create_local_context(void);
00304 
00305 
00313 __api struct iio_context * iio_create_xml_context(const char *xml_file);
00314 
00315 
00324 __api struct iio_context * iio_create_xml_context_mem(
00325         const char *xml, size_t len);
00326 
00327 
00332 __api struct iio_context * iio_create_network_context(const char *host);
00333 
00334 
00339 __api struct iio_context * iio_create_context_from_uri(const char *uri);
00340 
00341 
00346 __api struct iio_context * iio_context_clone(const struct iio_context *ctx);
00347 
00348 
00353 __api void iio_context_destroy(struct iio_context *ctx);
00354 
00355 
00363 __api int iio_context_get_version(const struct iio_context *ctx,
00364         unsigned int *major, unsigned int *minor, char git_tag[8]);
00365 
00366 
00370 __api __pure const char * iio_context_get_xml(const struct iio_context *ctx);
00371 
00372 
00380 __api __pure const char * iio_context_get_name(const struct iio_context *ctx);
00381 
00382 
00389 __api __pure const char * iio_context_get_description(
00390         const struct iio_context *ctx);
00391 
00392 
00398 __api __pure unsigned int iio_context_get_attrs_count(
00399         const struct iio_context *ctx);
00400 
00401 
00411 __api int iio_context_get_attr(
00412         const struct iio_context *ctx, unsigned int index,
00413         const char **name, const char **value);
00414 
00415 
00424 __api const char * iio_context_get_attr_value(
00425         const struct iio_context *ctx, const char *name);
00426 
00427 
00431 __api __pure unsigned int iio_context_get_devices_count(
00432         const struct iio_context *ctx);
00433 
00434 
00440 __api __pure struct iio_device * iio_context_get_device(
00441         const struct iio_context *ctx, unsigned int index);
00442 
00443 
00451 __api __pure struct iio_device * iio_context_find_device(
00452         const struct iio_context *ctx, const char *name);
00453 
00454 
00462 __api int iio_context_set_timeout(
00463         struct iio_context *ctx, unsigned int timeout_ms);
00464 
00465 /* ------------------------------------------------------------------*/
00467 /* ------------------------- Device functions --------------------------------*/
00477 __api __pure const struct iio_context * iio_device_get_context(
00478         const struct iio_device *dev);
00479 
00480 
00484 __api __pure const char * iio_device_get_id(const struct iio_device *dev);
00485 
00486 
00492 __api __pure const char * iio_device_get_name(const struct iio_device *dev);
00493 
00494 
00498 __api __pure unsigned int iio_device_get_channels_count(
00499         const struct iio_device *dev);
00500 
00501 
00505 __api __pure unsigned int iio_device_get_attrs_count(
00506         const struct iio_device *dev);
00507 
00508 
00514 __api __pure struct iio_channel * iio_device_get_channel(
00515         const struct iio_device *dev, unsigned int index);
00516 
00517 
00523 __api __pure const char * iio_device_get_attr(
00524         const struct iio_device *dev, unsigned int index);
00525 
00526 
00535 __api __pure struct iio_channel * iio_device_find_channel(
00536         const struct iio_device *dev, const char *name, bool output);
00537 
00538 
00550 __api __pure const char * iio_device_find_attr(
00551         const struct iio_device *dev, const char *name);
00552 
00553 
00575  __api ssize_t iio_device_attr_read(const struct iio_device *dev,
00576         const char *attr, char *dst, size_t len);
00577 
00578 
00589 __api int iio_device_attr_read_all(struct iio_device *dev,
00590         int (*cb)(struct iio_device *dev, const char *attr,
00591             const char *value, size_t len, void *d),
00592         void *data);
00593 
00594 
00602 __api int iio_device_attr_read_bool(const struct iio_device *dev,
00603         const char *attr, bool *val);
00604 
00605 
00613 __api int iio_device_attr_read_longlong(const struct iio_device *dev,
00614         const char *attr, long long *val);
00615 
00616 
00624 __api int iio_device_attr_read_double(const struct iio_device *dev,
00625         const char *attr, double *val);
00626 
00627 
00646 __api ssize_t iio_device_attr_write(const struct iio_device *dev,
00647         const char *attr, const char *src);
00648 
00649 
00658 __api ssize_t iio_device_attr_write_raw(const struct iio_device *dev,
00659         const char *attr, const void *src, size_t len);
00660 
00661 
00672 __api int iio_device_attr_write_all(struct iio_device *dev,
00673         ssize_t (*cb)(struct iio_device *dev,
00674             const char *attr, void *buf, size_t len, void *d),
00675         void *data);
00676 
00677 
00685 __api int iio_device_attr_write_bool(const struct iio_device *dev,
00686         const char *attr, bool val);
00687 
00688 
00696 __api int iio_device_attr_write_longlong(const struct iio_device *dev,
00697         const char *attr, long long val);
00698 
00699 
00707 __api int iio_device_attr_write_double(const struct iio_device *dev,
00708         const char *attr, double val);
00709 
00710 
00714 __api void iio_device_set_data(struct iio_device *dev, void *data);
00715 
00716 
00720 __api void * iio_device_get_data(const struct iio_device *dev);
00721 
00722 
00730 __api int iio_device_get_trigger(const struct iio_device *dev,
00731         const struct iio_device **trigger);
00732 
00733 
00740 __api int iio_device_set_trigger(const struct iio_device *dev,
00741         const struct iio_device *trigger);
00742 
00743 
00747 __api __pure bool iio_device_is_trigger(const struct iio_device *dev);
00748 
00757 __api int iio_device_set_kernel_buffers_count(const struct iio_device *dev,
00758         unsigned int nb_buffers);
00759 /* ------------------------------------------------------------------*/
00761 /* ------------------------- Channel functions -------------------------------*/
00771 __api __pure const struct iio_device * iio_channel_get_device(
00772         const struct iio_channel *chn);
00773 
00774 
00778 __api __pure const char * iio_channel_get_id(const struct iio_channel *chn);
00779 
00780 
00786 __api __pure const char * iio_channel_get_name(const struct iio_channel *chn);
00787 
00788 
00792 __api __pure bool iio_channel_is_output(const struct iio_channel *chn);
00793 
00794 
00802 __api __pure bool iio_channel_is_scan_element(const struct iio_channel *chn);
00803 
00804 
00808 __api __pure unsigned int iio_channel_get_attrs_count(
00809         const struct iio_channel *chn);
00810 
00811 
00817 __api __pure const char * iio_channel_get_attr(
00818         const struct iio_channel *chn, unsigned int index);
00819 
00820 
00832 __api __pure const char * iio_channel_find_attr(
00833         const struct iio_channel *chn, const char *name);
00834 
00835 
00842 __api __pure const char * iio_channel_attr_get_filename(
00843         const struct iio_channel *chn, const char *attr);
00844 
00845 
00867 __api ssize_t iio_channel_attr_read(const struct iio_channel *chn,
00868         const char *attr, char *dst, size_t len);
00869 
00870 
00881 __api int iio_channel_attr_read_all(struct iio_channel *chn,
00882         int (*cb)(struct iio_channel *chn,
00883             const char *attr, const char *val, size_t len, void *d),
00884         void *data);
00885 
00886 
00894 __api int iio_channel_attr_read_bool(const struct iio_channel *chn,
00895         const char *attr, bool *val);
00896 
00897 
00905 __api int iio_channel_attr_read_longlong(const struct iio_channel *chn,
00906         const char *attr, long long *val);
00907 
00908 
00916 __api int iio_channel_attr_read_double(const struct iio_channel *chn,
00917         const char *attr, double *val);
00918 
00919 
00938 __api ssize_t iio_channel_attr_write(const struct iio_channel *chn,
00939         const char *attr, const char *src);
00940 
00941 
00950 __api ssize_t iio_channel_attr_write_raw(const struct iio_channel *chn,
00951         const char *attr, const void *src, size_t len);
00952 
00953 
00964 __api int iio_channel_attr_write_all(struct iio_channel *chn,
00965         ssize_t (*cb)(struct iio_channel *chn,
00966             const char *attr, void *buf, size_t len, void *d),
00967         void *data);
00968 
00969 
00977 __api int iio_channel_attr_write_bool(const struct iio_channel *chn,
00978         const char *attr, bool val);
00979 
00980 
00988 __api int iio_channel_attr_write_longlong(const struct iio_channel *chn,
00989         const char *attr, long long val);
00990 
00991 
00999 __api int iio_channel_attr_write_double(const struct iio_channel *chn,
01000         const char *attr, double val);
01001 
01002 
01009 __api void iio_channel_enable(struct iio_channel *chn);
01010 
01011 
01014 __api void iio_channel_disable(struct iio_channel *chn);
01015 
01016 
01020 __api bool iio_channel_is_enabled(const struct iio_channel *chn);
01021 
01022 
01030 __api size_t iio_channel_read_raw(const struct iio_channel *chn,
01031         struct iio_buffer *buffer, void *dst, size_t len);
01032 
01033 
01041 __api size_t iio_channel_read(const struct iio_channel *chn,
01042         struct iio_buffer *buffer, void *dst, size_t len);
01043 
01044 
01052 __api size_t iio_channel_write_raw(const struct iio_channel *chn,
01053         struct iio_buffer *buffer, const void *src, size_t len);
01054 
01055 
01063 __api size_t iio_channel_write(const struct iio_channel *chn,
01064         struct iio_buffer *buffer, const void *src, size_t len);
01065 
01066 
01070 __api void iio_channel_set_data(struct iio_channel *chn, void *data);
01071 
01072 
01076 __api void * iio_channel_get_data(const struct iio_channel *chn);
01077 
01078 
01082 __api __pure enum iio_chan_type iio_channel_get_type(
01083         const struct iio_channel *chn);
01084 
01085 
01089 __api __pure enum iio_modifier iio_channel_get_modifier(
01090         const struct iio_channel *chn);
01091 
01092 /* ------------------------------------------------------------------*/
01094 /* ------------------------- Buffer functions --------------------------------*/
01104 __api __pure const struct iio_device * iio_buffer_get_device(
01105         const struct iio_buffer *buf);
01106 
01107 
01117 __api struct iio_buffer * iio_device_create_buffer(const struct iio_device *dev,
01118         size_t samples_count, bool cyclic);
01119 
01120 
01125 __api void iio_buffer_destroy(struct iio_buffer *buf);
01126 
01135 __api int iio_buffer_get_poll_fd(struct iio_buffer *buf);
01136 
01148 __api int iio_buffer_set_blocking_mode(struct iio_buffer *buf, bool blocking);
01149 
01150 
01157 __api ssize_t iio_buffer_refill(struct iio_buffer *buf);
01158 
01159 
01166 __api ssize_t iio_buffer_push(struct iio_buffer *buf);
01167 
01168 
01176 __api ssize_t iio_buffer_push_partial(struct iio_buffer *buf,
01177         size_t samples_count);
01178 
01202 __api void iio_buffer_cancel(struct iio_buffer *buf);
01203 
01204 
01208 __api void * iio_buffer_start(const struct iio_buffer *buf);
01209 
01210 
01226 __api void * iio_buffer_first(const struct iio_buffer *buf,
01227         const struct iio_channel *chn);
01228 
01229 
01234 __api ptrdiff_t iio_buffer_step(const struct iio_buffer *buf);
01235 
01236 
01241 __api void * iio_buffer_end(const struct iio_buffer *buf);
01242 
01243 
01255 __api ssize_t iio_buffer_foreach_sample(struct iio_buffer *buf,
01256         ssize_t (*callback)(const struct iio_channel *chn,
01257             void *src, size_t bytes, void *d), void *data);
01258 
01259 
01263 __api void iio_buffer_set_data(struct iio_buffer *buf, void *data);
01264 
01265 
01269 __api void * iio_buffer_get_data(const struct iio_buffer *buf);
01270 
01271 /* ------------------------------------------------------------------*/
01273 /* ------------------------- Low-level functions -----------------------------*/
01283 struct iio_data_format {
01285     unsigned int length;
01286 
01288     unsigned int bits;
01289 
01291     unsigned int shift;
01292 
01294     bool is_signed;
01295 
01297     bool is_fully_defined;
01298 
01300     bool is_be;
01301 
01303     bool with_scale;
01304 
01306     double scale;
01307 
01309     unsigned int repeat;
01310 };
01311 
01312 
01320 __api ssize_t iio_device_get_sample_size(const struct iio_device *dev);
01321 
01322 
01327 __api __pure long iio_channel_get_index(const struct iio_channel *chn);
01328 
01329 
01333 __api __cnst const struct iio_data_format * iio_channel_get_data_format(
01334         const struct iio_channel *chn);
01335 
01336 
01342 __api void iio_channel_convert(const struct iio_channel *chn,
01343         void *dst, const void *src);
01344 
01345 
01351 __api void iio_channel_convert_inverse(const struct iio_channel *chn,
01352         void *dst, const void *src);
01353 
01354 
01358 __api __pure unsigned int iio_device_get_debug_attrs_count(
01359         const struct iio_device *dev);
01360 
01361 
01367 __api __pure const char * iio_device_get_debug_attr(
01368         const struct iio_device *dev, unsigned int index);
01369 
01370 
01383 __api __pure const char * iio_device_find_debug_attr(
01384         const struct iio_device *dev, const char *name);
01385 
01386 
01409 __api ssize_t iio_device_debug_attr_read(const struct iio_device *dev,
01410         const char *attr, char *dst, size_t len);
01411 
01412 
01422 __api int iio_device_debug_attr_read_all(struct iio_device *dev,
01423         int (*cb)(struct iio_device *dev, const char *attr,
01424             const char *value, size_t len, void *d),
01425         void *data);
01426 
01427 
01447 __api ssize_t iio_device_debug_attr_write(const struct iio_device *dev,
01448         const char *attr, const char *src);
01449 
01450 
01459 __api ssize_t iio_device_debug_attr_write_raw(const struct iio_device *dev,
01460         const char *attr, const void *src, size_t len);
01461 
01462 
01472 __api int iio_device_debug_attr_write_all(struct iio_device *dev,
01473         ssize_t (*cb)(struct iio_device *dev,
01474             const char *attr, void *buf, size_t len, void *d),
01475         void *data);
01476 
01477 
01485 __api int iio_device_debug_attr_read_bool(const struct iio_device *dev,
01486         const char *attr, bool *val);
01487 
01488 
01496 __api int iio_device_debug_attr_read_longlong(const struct iio_device *dev,
01497         const char *attr, long long *val);
01498 
01499 
01507 __api int iio_device_debug_attr_read_double(const struct iio_device *dev,
01508         const char *attr, double *val);
01509 
01510 
01518 __api int iio_device_debug_attr_write_bool(const struct iio_device *dev,
01519         const char *attr, bool val);
01520 
01521 
01529 __api int iio_device_debug_attr_write_longlong(const struct iio_device *dev,
01530         const char *attr, long long val);
01531 
01532 
01540 __api int iio_device_debug_attr_write_double(const struct iio_device *dev,
01541         const char *attr, double val);
01542 
01543 
01556 __api int iio_device_identify_filename(const struct iio_device *dev,
01557         const char *filename, struct iio_channel **chn,
01558         const char **attr);
01559 
01560 
01567 __api int iio_device_reg_write(struct iio_device *dev,
01568         uint32_t address, uint32_t value);
01569 
01570 
01577 __api int iio_device_reg_read(struct iio_device *dev,
01578         uint32_t address, uint32_t *value);
01579 
01580 
01583 #ifdef __cplusplus
01584 }
01585 #endif
01586 
01587 #undef __api
01588 
01589 #endif /* __IIO_H__ */
 All Data Structures Files Functions Variables Enumerations