blob: 6be7eff7e4c1741ceee57fd732f5c8b17d33b3ab [file] [log] [blame]
Paul Cercueilbb4401d2014-02-28 16:10:49 +01001/*
2 * libiio - Library for interfacing industrial I/O (IIO) devices
3 *
4 * Copyright (C) 2014 Analog Devices, Inc.
5 * Author: Paul Cercueil <paul.cercueil@analog.com>
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * */
18
Paul Cercueil0b2ce712014-02-17 15:04:18 +010019#ifndef __IIO_PRIVATE_H__
20#define __IIO_PRIVATE_H__
21
Paul Cercueil00236242014-02-18 15:09:06 +010022/* Include public interface */
Paul Cercueil0b2ce712014-02-17 15:04:18 +010023#include "iio.h"
24
25#include <stdbool.h>
26
Paul Cercueil1fef1a52014-04-07 16:31:15 +020027#ifdef _MSC_BUILD
28#define snprintf sprintf_s
29#define strerror_r(err, buf, len) strerror_s(buf, len, err)
30#endif
31
Paul Cercueile1311222014-03-12 15:46:16 +010032#define BIT_MASK(bit) (1 << ((bit) % 32))
33#define BIT_WORD(bit) ((bit) / 32)
34#define TEST_BIT(addr, bit) (!!(*(((uint32_t *) addr) + BIT_WORD(bit)) \
35 & BIT_MASK(bit)))
36#define SET_BIT(addr, bit) \
37 *(((uint32_t *) addr) + BIT_WORD(bit)) |= BIT_MASK(bit)
38#define CLEAR_BIT(addr, bit) \
39 *(((uint32_t *) addr) + BIT_WORD(bit)) &= ~BIT_MASK(bit)
40
Paul Cercueil0b2ce712014-02-17 15:04:18 +010041enum iio_modifier {
42 IIO_NO_MOD,
43 IIO_MOD_X,
44 IIO_MOD_Y,
45 IIO_MOD_Z,
46 IIO_MOD_LIGHT_BOTH,
47 IIO_MOD_LIGHT_IR,
48 IIO_MOD_ROOT_SUM_SQUARED_X_Y,
49 IIO_MOD_SUM_SQUARED_X_Y_Z,
50 IIO_MOD_LIGHT_CLEAR,
51 IIO_MOD_LIGHT_RED,
52 IIO_MOD_LIGHT_GREEN,
53 IIO_MOD_LIGHT_BLUE,
54};
55
56struct iio_backend_ops {
Paul Cercueil45c575d2014-03-20 15:14:01 +010057 ssize_t (*read)(const struct iio_device *dev, void *dst, size_t len,
58 uint32_t *mask, size_t words);
Paul Cercueilec1760d2014-02-21 11:31:20 +010059 ssize_t (*write)(const struct iio_device *dev,
60 const void *src, size_t len);
Paul Cercueil93f17052014-04-02 13:56:27 +020061 int (*open)(const struct iio_device *dev,
62 size_t samples_count, uint32_t *mask, size_t words);
Paul Cercueilec1760d2014-02-21 11:31:20 +010063 int (*close)(const struct iio_device *dev);
Paul Cercueil0b2ce712014-02-17 15:04:18 +010064
Paul Cercueil93f7e1f2014-04-23 16:49:56 +020065 ssize_t (*get_buffer)(const struct iio_device *dev,
66 void **addr_ptr, uint32_t *mask, size_t words);
67
Paul Cercueil167d3112014-02-18 12:23:53 +010068 ssize_t (*read_device_attr)(const struct iio_device *dev,
Paul Cercueil50c762a2014-04-14 15:55:43 +020069 const char *attr, char *dst, size_t len, bool is_debug);
Paul Cercueil167d3112014-02-18 12:23:53 +010070 ssize_t (*write_device_attr)(const struct iio_device *dev,
Paul Cercueil50c762a2014-04-14 15:55:43 +020071 const char *attr, const char *src, bool is_debug);
Paul Cercueil167d3112014-02-18 12:23:53 +010072 ssize_t (*read_channel_attr)(const struct iio_channel *chn,
73 const char *attr, char *dst, size_t len);
74 ssize_t (*write_channel_attr)(const struct iio_channel *chn,
75 const char *attr, const char *src);
Paul Cercueil0b2ce712014-02-17 15:04:18 +010076
Paul Cercueil24ffa532014-03-10 12:39:58 +010077 int (*get_trigger)(const struct iio_device *dev,
78 const struct iio_device **trigger);
79 int (*set_trigger)(const struct iio_device *dev,
80 const struct iio_device *trigger);
81
Paul Cercueil0b2ce712014-02-17 15:04:18 +010082 void (*shutdown)(struct iio_context *ctx);
83};
84
Paul Cercueil82b3c1c2014-02-24 13:15:56 +010085struct iio_context_pdata;
Paul Cercueileaab6582014-02-21 09:35:59 +010086struct iio_device_pdata;
87struct iio_channel_pdata;
Paul Cercueil82b3c1c2014-02-24 13:15:56 +010088
Paul Cercueil0b2ce712014-02-17 15:04:18 +010089struct iio_context {
Paul Cercueil82b3c1c2014-02-24 13:15:56 +010090 struct iio_context_pdata *pdata;
Paul Cercueil0b2ce712014-02-17 15:04:18 +010091 const struct iio_backend_ops *ops;
Paul Cercueil0b2ce712014-02-17 15:04:18 +010092 const char *name;
93
94 struct iio_device **devices;
95 unsigned int nb_devices;
Paul Cercueil4c6729d2014-04-04 17:24:41 +020096
97 char *xml;
Paul Cercueil0b2ce712014-02-17 15:04:18 +010098};
99
Paul Cercueil0b2ce712014-02-17 15:04:18 +0100100struct iio_channel {
Paul Cercueileaab6582014-02-21 09:35:59 +0100101 struct iio_device *dev;
102 struct iio_channel_pdata *pdata;
Paul Cercueild96e61f2014-03-07 16:13:37 +0100103 void *userdata;
Paul Cercueileaab6582014-02-21 09:35:59 +0100104
Paul Cercueil35a01312014-02-20 10:56:57 +0100105 bool is_output;
Paul Cercueil85aaf482014-04-24 16:39:09 +0200106 bool is_scan_element;
Paul Cercueil0b2ce712014-02-17 15:04:18 +0100107 enum iio_modifier modifier;
Paul Cercueilcd6ce842014-03-14 13:21:06 +0100108 struct iio_data_format format;
Paul Cercueilbb618272014-02-20 11:35:52 +0100109 char *name, *id;
Paul Cercueilae88fde2014-03-12 11:47:10 +0100110 long index;
Paul Cercueil0b2ce712014-02-17 15:04:18 +0100111
Paul Cercueilbb618272014-02-20 11:35:52 +0100112 char **attrs;
Paul Cercueil0b2ce712014-02-17 15:04:18 +0100113 unsigned int nb_attrs;
114};
115
116struct iio_device {
117 const struct iio_context *ctx;
Paul Cercueileaab6582014-02-21 09:35:59 +0100118 struct iio_device_pdata *pdata;
Paul Cercueild96e61f2014-03-07 16:13:37 +0100119 void *userdata;
Paul Cercueileaab6582014-02-21 09:35:59 +0100120
Paul Cercueilbb618272014-02-20 11:35:52 +0100121 char *name, *id;
Paul Cercueil0b2ce712014-02-17 15:04:18 +0100122
Paul Cercueilbb618272014-02-20 11:35:52 +0100123 char **attrs;
Paul Cercueil0b2ce712014-02-17 15:04:18 +0100124 unsigned int nb_attrs;
125
Paul Cercueilddaa26a2014-04-14 17:32:18 +0200126 char **debug_attrs;
127 unsigned int nb_debug_attrs;
128
Paul Cercueil0b2ce712014-02-17 15:04:18 +0100129 struct iio_channel **channels;
130 unsigned int nb_channels;
Paul Cercueilff778232014-03-24 14:23:08 +0100131
132 uint32_t *mask;
133 size_t words;
Paul Cercueil0b2ce712014-02-17 15:04:18 +0100134};
135
Paul Cercueila689cd92014-03-20 16:37:25 +0100136struct iio_buffer {
137 const struct iio_device *dev;
138 void *buffer;
139 size_t length, data_length;
140
Paul Cercueil645ab972014-03-24 14:36:12 +0100141 uint32_t *mask;
Paul Cercueila689cd92014-03-20 16:37:25 +0100142 unsigned int sample_size;
Paul Cercueil66ba1712014-04-01 16:11:48 +0200143 bool is_output;
Paul Cercueila689cd92014-03-20 16:37:25 +0100144};
145
Paul Cercueil00236242014-02-18 15:09:06 +0100146void free_channel(struct iio_channel *chn);
147void free_device(struct iio_device *dev);
Paul Cercueil0b2ce712014-02-17 15:04:18 +0100148
Paul Cercueil42090d12014-02-24 12:32:23 +0100149char *iio_channel_get_xml(const struct iio_channel *chn, size_t *len);
150char *iio_device_get_xml(const struct iio_device *dev, size_t *len);
151
Paul Cercueil4c6729d2014-04-04 17:24:41 +0200152int iio_context_init(struct iio_context *ctx);
Paul Cercueilae88fde2014-03-12 11:47:10 +0100153
Paul Cercueile98500b2014-04-10 13:31:04 +0200154ssize_t iio_device_process_samples(const struct iio_device *dev,
Paul Cercueil46825942014-03-18 14:28:49 +0100155 uint32_t *mask, size_t words, void *buf, size_t len,
156 ssize_t (*cb)(const struct iio_channel *, void *, void *),
157 void *data);
Paul Cercueil645ab972014-03-24 14:36:12 +0100158
Paul Cercueile98500b2014-04-10 13:31:04 +0200159/* This function is not part of the API, but is used by the IIO daemon */
Paul Cercueil59f2aa32014-04-04 16:28:51 +0200160__api ssize_t iio_device_get_sample_size_mask(const struct iio_device *dev,
Paul Cercueil645ab972014-03-24 14:36:12 +0100161 uint32_t *mask, size_t words);
Paul Cercueil46825942014-03-18 14:28:49 +0100162
Paul Cercueil0b2ce712014-02-17 15:04:18 +0100163#endif /* __IIO_PRIVATE_H__ */