Skip to content

Commit e3f09ea

Browse files
GuEe-GUI1078249029
authored andcommitted
[DM/FEATURE] Support IIO (Industrial I/O) (RT-Thread#9598)
[DM/FEATURE] Support IIO (Industrial I/O) Signed-off-by: GuEe-GUI <[email protected]>
1 parent 3d81e31 commit e3f09ea

File tree

4 files changed

+105
-0
lines changed

4 files changed

+105
-0
lines changed

Diff for: components/drivers/iio/SConscript

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
from building import *
2+
3+
group = []
4+
5+
if not GetDepend(['RT_USING_DM']):
6+
Return('group')
7+
8+
cwd = GetCurrentDir()
9+
CPPPATH = [cwd + '/../include']
10+
11+
src = ['iio.c',]
12+
13+
group = DefineGroup('DeviceDrivers', src, depend = [''], CPPPATH = CPPPATH)
14+
15+
Return('group')

Diff for: components/drivers/iio/iio.c

+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/*
2+
* Copyright (c) 2006-2022, RT-Thread Development Team
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*
6+
* Change Logs:
7+
* Date Author Notes
8+
* 2022-3-08 GuEe-GUI the first version
9+
*/
10+
11+
#include <rtthread.h>
12+
#include <rtdevice.h>
13+
14+
static void *ofw_iio_channel_get_by_index(struct rt_ofw_node *np, int index, int *out_channel)
15+
{
16+
void *iio = RT_NULL;
17+
#ifdef RT_USING_OFW
18+
struct rt_ofw_node *iio_np;
19+
struct rt_ofw_cell_args iio_args;
20+
21+
if (!rt_ofw_parse_phandle_cells(np, "io-channels", "#io-channel-cells", index, &iio_args))
22+
{
23+
iio_np = iio_args.data;
24+
25+
if (!rt_ofw_data(iio_np))
26+
{
27+
rt_platform_ofw_request(iio_np);
28+
}
29+
30+
iio = rt_ofw_data(iio_np);
31+
rt_ofw_node_put(iio_np);
32+
33+
if (out_channel)
34+
{
35+
*out_channel = iio_args.args[0];
36+
}
37+
}
38+
#endif /* RT_USING_OFW */
39+
return iio;
40+
}
41+
42+
void *rt_iio_channel_get_by_index(struct rt_device *dev, int index, int *out_channel)
43+
{
44+
void *iio = RT_NULL;
45+
46+
if (!dev || index < 0)
47+
{
48+
return RT_NULL;
49+
}
50+
51+
if (dev->ofw_node)
52+
{
53+
iio = ofw_iio_channel_get_by_index(dev->ofw_node, index, out_channel);
54+
}
55+
56+
return iio;
57+
}
58+
59+
void *rt_iio_channel_get_by_name(struct rt_device *dev, const char *name, int *out_channel)
60+
{
61+
int index;
62+
63+
if (!dev || !name)
64+
{
65+
return RT_NULL;
66+
}
67+
68+
index = rt_dm_dev_prop_index_of_string(dev, "io-channel-names", name);
69+
70+
return rt_iio_channel_get_by_index(dev, index, out_channel);
71+
}

Diff for: components/drivers/include/drivers/iio.h

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/*
2+
* Copyright (c) 2006-2022, RT-Thread Development Team
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*
6+
* Change Logs:
7+
* Date Author Notes
8+
* 2022-3-08 GuEe-GUI the first version
9+
*/
10+
11+
#ifndef __IIO_H__
12+
#define __IIO_H__
13+
14+
void *rt_iio_channel_get_by_index(struct rt_device *dev, int index, int *out_channel);
15+
void *rt_iio_channel_get_by_name(struct rt_device *dev, const char *name, int *out_channel);
16+
17+
#endif /* __IIO_H__ */

Diff for: components/drivers/include/rtdevice.h

+2
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ extern "C" {
4949
#include "drivers/blk.h"
5050
#endif
5151

52+
#include "drivers/iio.h"
53+
5254
#ifdef RT_USING_OFW
5355
#include "drivers/ofw.h"
5456
#include "drivers/ofw_fdt.h"

0 commit comments

Comments
 (0)