基於iio的ADC驅動(android)


rk3288開發板上的AD接口分為:高速ADC流(High-speed ADC Stream Interface)、溫度傳感器(Temperature Sensor)、逐次逼近ADC(Successive Approximation Register);
ADC擴展知識:
1、獲取 AD 通道
        struct iio_channel *chan; //定義 IIO 通道結構體
        chan = iio_channel_get(&pdev->dev, NULL); //獲取 IIO 通道結構體
2、讀取 AD 采集到的原始數據
        int value,Vresult;
        ret = iio_read_channel_raw(chan, &value);
        調用 iio_read_channel_raw 函數讀取 AD 采集的原始數據並存入value變量中。
3、計算采集到的電壓
        使用標准電壓將 AD 轉換的值轉換為用戶所需要的電壓值。其計算公式如下:
        Vresult = (Vref * value) / (2^n-1) ========> 用戶需要的電壓 = (rk3288標准電壓 * 采集的原始數據) / (2^AD位數-1)
        例如,rk3288的AD標准電壓為 1.8V,AD 采集位數為10位精度,AD采集到的原始數據為1234,則:
                            Vresult = (1800mv * 1234) / 1023;
4、ADC 常用函數接口
        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:存放讀取結果的指針;

rk3288-android5.1添加ADC驅動,以下以酒精傳感器為例:
1、在rk3288 linux設備數(DTS)上添加AD設備
        路徑:android\kernel\arch\arm\boot\dts\xxx-rk3288.dts
        

(轉載自:https://blog.csdn.net/soar999999/article/details/100715619)


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM