Skip to content

[DM/FEATURE] Support IIO (Industrial I/O) #9598

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions components/drivers/iio/SConscript
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from building import *

group = []

if not GetDepend(['RT_USING_DM']):
Return('group')

cwd = GetCurrentDir()
CPPPATH = [cwd + '/../include']

src = ['iio.c',]

group = DefineGroup('DeviceDrivers', src, depend = [''], CPPPATH = CPPPATH)

Return('group')
71 changes: 71 additions & 0 deletions components/drivers/iio/iio.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*
* Copyright (c) 2006-2022, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2022-3-08 GuEe-GUI the first version
*/

#include <rtthread.h>
#include <rtdevice.h>

static void *ofw_iio_channel_get_by_index(struct rt_ofw_node *np, int index, int *out_channel)
{
void *iio = RT_NULL;
#ifdef RT_USING_OFW
struct rt_ofw_node *iio_np;
struct rt_ofw_cell_args iio_args;

if (!rt_ofw_parse_phandle_cells(np, "io-channels", "#io-channel-cells", index, &iio_args))
{
iio_np = iio_args.data;

if (!rt_ofw_data(iio_np))
{
rt_platform_ofw_request(iio_np);
}

iio = rt_ofw_data(iio_np);
rt_ofw_node_put(iio_np);

if (out_channel)
{
*out_channel = iio_args.args[0];
}
}
#endif /* RT_USING_OFW */
return iio;
}

void *rt_iio_channel_get_by_index(struct rt_device *dev, int index, int *out_channel)
{
void *iio = RT_NULL;

if (!dev || index < 0)
{
return RT_NULL;
}

if (dev->ofw_node)
{
iio = ofw_iio_channel_get_by_index(dev->ofw_node, index, out_channel);
}

return iio;
}

void *rt_iio_channel_get_by_name(struct rt_device *dev, const char *name, int *out_channel)
{
int index;

if (!dev || !name)
{
return RT_NULL;
}

index = rt_dm_dev_prop_index_of_string(dev, "io-channel-names", name);

return rt_iio_channel_get_by_index(dev, index, out_channel);
}
17 changes: 17 additions & 0 deletions components/drivers/include/drivers/iio.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
* Copyright (c) 2006-2022, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2022-3-08 GuEe-GUI the first version
*/

#ifndef __IIO_H__
#define __IIO_H__

void *rt_iio_channel_get_by_index(struct rt_device *dev, int index, int *out_channel);
void *rt_iio_channel_get_by_name(struct rt_device *dev, const char *name, int *out_channel);

#endif /* __IIO_H__ */
2 changes: 2 additions & 0 deletions components/drivers/include/rtdevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ extern "C" {
#include "drivers/blk.h"
#endif

#include "drivers/iio.h"

#ifdef RT_USING_OFW
#include "drivers/ofw.h"
#include "drivers/ofw_fdt.h"
Expand Down
Loading