04、IIO相关API
IIO相关接口位于linux/iio/consumer.h
一、API 原型
c
/**
* struct iio_channel - everything needed for a consumer to use a channel
* @indio_dev: Device on which the channel exists.
* @channel: Full description of the channel.
* @data: Data about the channel used by consumer.
*/
struct iio_channel {
struct iio_dev *indio_dev;
const struct iio_chan_spec *channel;
void *data;
};
/**
* iio_channel_get() - get description of all that is needed to access channel.
* @dev: Pointer to consumer device. Device name must match
* the name of the device as provided in the iio_map
* with which the desired provider to consumer mapping
* was registered.
* @consumer_channel: Unique name to identify the channel on the consumer
* side. This typically describes the channels use within
* the consumer. E.g. 'battery_voltage'
*/
struct iio_channel *iio_channel_get(struct device *dev,
const char *consumer_channel);
/**
* iio_channel_release() - release channels obtained via iio_channel_get
* @chan: The channel to be released.
*/
void iio_channel_release(struct iio_channel *chan);
/**
* devm_iio_channel_get() - Resource managed version of iio_channel_get().
* @dev: Pointer to consumer device. Device name must match
* the name of the device as provided in the iio_map
* with which the desired provider to consumer mapping
* was registered.
* @consumer_channel: Unique name to identify the channel on the consumer
* side. This typically describes the channels use within
* the consumer. E.g. 'battery_voltage'
*
* Returns a pointer to negative errno if it is not able to get the iio channel
* otherwise returns valid pointer for iio channel.
*
* The allocated iio channel is automatically released when the device is
* unbound.
*/
struct iio_channel *devm_iio_channel_get(struct device *dev,
const char *consumer_channel);
/**
* iio_channel_get_all() - get all channels associated with a client
* @dev: Pointer to consumer device.
*
* Returns an array of iio_channel structures terminated with one with
* null iio_dev pointer.
* This function is used by fairly generic consumers to get all the
* channels registered as having this consumer.
*/
struct iio_channel *iio_channel_get_all(struct device *dev);
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
二、常用API
2.1、功能:获取 iio 通道描述
参数:
- dev: 使用该通道的设备描述指针
- consumer_channel: 该设备所使用的 IIO 通道描述指针
c
struct iio_channel *iio_channel_get(struct device *dev, const char *consumer_channel);
1
2.2、功能:释放 iio_channel_get 函数获取到的通道
参数:
- chan:要被释放的通道描述指针
c
void iio_channel_release(struct iio_channel *chan);
1
2.3、功能:读取 chan 通道 AD 采集的原始数据。
参数:
- chan:要读取的采集通道指针
- val:存放读取结果的指针
c
int iio_read_channel_raw(struct iio_channel *chan, int *val);
1