说明
以下用 SAR-ADC 为例子,介绍 ADC 的基本配置方法。
ADC常用接口说明
1、iio_channel_get
struct iio_channel *iio_channel_get(struct device *dev, const char *consumer_channel);
功能:获取 iio 通道描述
参数:
dev: 使用该通道的设备描述指针
consumer_channel: 该设备所使用的 IIO 通道描述指针
2、iio_channel_release
void iio_channel_release(struct iio_channel *chan);
功能:释放 iio_channel_get 函数获取到的通道
参数:
chan:要被释放的通道描述指针
3、iio_read_channel_raw
int iio_read_channel_raw(struct iio_channel *chan, int *val);
功能:读取 chan 通道 AD 采集的原始数据。
参数:
chan:要读取的采集通道指针
val:存放读取结果的指针
DTS配置
配置DTS节点
SAR-ADC 的 DTS 节点在 kernel/arch/arm64/boot/dts/rockchip/rk3568.dtsi 文件中定义,如下所示:
saradc: saradc@fe720000 {
compatible = "rockchip,rk3568-saradc", "rockchip,rk3399-saradc";
reg = <0x0 0xfe720000 0x0 0x100>;
interrupts = <GIC_SPI 93 IRQ_TYPE_LEVEL_HIGH>;