AIO-3288C 開發板上的 AD 接口分為:高速 ADC 流接口 (High-speed ADC Stream Interface)、溫度傳感器 (Temperature Sensor)、逐次逼近ADC (Successive Approximation Register)。本文主要介紹 ADC 的基本配置方法。 內核采用工業 I/O 子系統來控制 ADC,該子系統主要為 AD 轉換或者 DA 轉換的傳感器設計。 其相關數據結構以及配置方法如下:
struct iio_channel { struct iio_dev *indio_dev;//工業 I/O設備 const struct iio_chan_spec *channel;//I/O通道 void *data; };
該結構體主要用于描述 IO 口所屬的設備,其具體定義如下:
struct iio_dev { int id; int modes; int currentmode; struct device dev; struct iio_event_interface *event_interface; struct iio_buffer *buffer; struct list_head buffer_list; int scan_bytes; struct mutex mlock; const unsigned long *available_scan_masks; unsigned masklength; const unsigned long *active_scan_mask; bool scan_timestamp; unsigned scan_index_timestamp; struct iio_trigger *trig; struct iio_poll_func *pollfunc; struct iio_chan_spec const *channels; int num_channels; struct list_head channel_attr_list; struct attribute_group chan_attr_group; const char *name; const struct iio_info *info; struct mutex info_exist_lock; const struct iio_buffer_setup_ops *setup_ops; struct cdev chrdev; #define IIO_MAX_GROUPS 6 const struct attribute_group *groups[IIO_MAX_GROUPS + 1]; int groupcounter; unsigned long flags; #if defined(CONFIG_DEBUG_FS) struct dentry *debugfs_dentry; unsigned cached_reg_addr; #endif };
該結構體主要用于描述單個通道的屬性,具體定義如下:
struct iio_chan_spec { enum iio_chan_type type; //描述通道類型 int channel; //通道號 int channel2; //通道號 unsigned long address; //通道地址 int scan_index; struct { char sign; u8 realbits; u8 storagebits; u8 shift; enum iio_endian endianness; } scan_type; long info_mask; long info_mask_separate; long info_mask_shared_by_type; long event_mask; const struct iio_chan_spec_ext_info *ext_info; const char *extend_name; const char *datasheet_name; unsigned modified:1; unsigned indexed:1; unsigned output:1; unsigned differential:1; };
AIO-3288C ADC的 DTS 節點在 kernel/arch/arm/boot/dts/rk3288.dtsi 文件中定義,如下所示:
用戶只需在 firefly-rk3288-aio-3288c.dts 文件中添加通道定義,并將其 status 改為 “okay” 即可:
&adc { status = "okay"; adc_test{ compatible = "rockchip,adc_test"; io-channels = ; }; };
在驅動文件中定義 of_device_id 結構體數組:
static const struct of_device_id of_XXX_match[] = { { .compatible = "rockchip,adc_test" }, { /* Sentinel */ } };
將該結構體數組填充到要使用 ADC 的 platform_driver 中。
static struct platform_driver XXX_driver = { .probe = ..., .remove = ..., .driver = { .name = "..", .owner = THIS_MODULE, #ifdef CONFIG_OF .of_match_table = of_XXX_match, #endif }, };
struct iio_channel *chan; //定義 IIO 通道結構體 chan = iio_channel_get(&pdev->dev, NULL); //獲取 IIO 通道結構體
注:iio_channel_get 通過 probe 函數傳進來的參數 pdev 獲取 IIO 通道結構體,probe 函數如下:
static int XXX_probe(struct platform_device *pdev);
int val,ret; ret = iio_read_channel_raw(chan, &val);
調用 iio_read_channel_raw 函數讀取 AD 采集的原始數據并存入 val 中。
使用標準電壓將 AD 轉換的值轉換為用戶所需要的電壓值。其計算公式如下:
Vref / (2^n-1) = Vresult / raw
注:
- Vref 為標準電壓
- n 為 AD 轉換的位數
- Vresult 為用戶所需要的采集電壓
- raw 為 AD 采集的原始數據
例如,標準電壓為 1.8V,AD 采集位數為 10 位,AD 采集到的原始數據為 568,則:
Vresult = (1800mv * 568) / 1023;
struct iio_channel *iio_channel_get(struct device *dev, const char *consumer_channel);
- 功能:獲取 iio 通道描述
-
參數:
- dev: 使用該通道的設備描述指針
- consumer_channel: 該設備所使用的 IIO 通道描述指針
void iio_channel_release(struct iio_channel *chan);
- 功能:釋放 iio_channel_get 函數獲取到的通道
-
參數:
- chan:要被釋放的通道描述指針
int iio_read_channel_raw(struct iio_channel *chan, int *val);
- 功能:讀取 chan 通道 AD 采集的原始數據。
-
參數:
- chan:要讀取的采集通道指針
- val:存放讀取結果的指針
-
嵌入式主板
+關注
關注
7文章
6086瀏覽量
35614 -
Firefly
+關注
關注
2文章
538瀏覽量
7130
發布評論請先 登錄
相關推薦
fireflyAIO-3399C主板ADC介紹
fireflyAIO-3288C PWM 輸出介紹
fireflyAIO-3288C主板MIPI CSI攝像頭接口簡介
![<b class='flag-5'>fireflyAIO-3288C</b><b class='flag-5'>主板</b>MIPI CSI攝像頭<b class='flag-5'>接口</b>簡介](https://file.elecfans.com/web1/M00/AB/A3/pIYBAF220a6AR6sEAADzm-IuzVk573.png)
fireflyAIO-3288C主板ADB調試工具介紹
![<b class='flag-5'>fireflyAIO-3288C</b><b class='flag-5'>主板</b>ADB調試工具<b class='flag-5'>介紹</b>](https://file.elecfans.com/web1/M00/AB/A3/pIYBAF220b6AXbN_AAGexBYVy8w126.png)
評論