1. 程式人生 > >asm335x系列adc和觸控式螢幕驅動

asm335x系列adc和觸控式螢幕驅動

An analog-to-digital converter (abbreviated ADC) is a device that uses sampling to convert a continuous quantity to a discrete time representation in digital form.

The TSC_ADC_SS (Touchscreen_ADC_subsystem) is an 8 channel general purpose ADC, with optional support for interleaving Touch Screen conversions. The TSC_ADC_SS can be used and configured in one of the following application options:

  • 8 general purpose ADC channels
  • 4 wire TS, with 4 general purpose ADC channels
  • 5 wire TS, with 3 general purpose ADC channels
  • 8 wire TS

ADC used is 12 bit SAR ADC with a sample rate of 200 KSPS (Kilo Samples Per Second). The ADC samples the analog signal when "start of conversion" signal is high and continues sampling 1 clock cycle after the falling edge. It captures the signal at the end of sampling period and starts conversion. It uses 12 clock cycles to digitize the sampled input; then an "end of conversion" signal is enabled high indicating that the digital data ADCOUT<11:0> is ready for SW to consume. A new conversion cycle can be initiated after the previous data is read. Please note that the ADC output is positive binary weighted data.

Driver Configuration

You can enable ADC driver in the kernel as follows.

Device Drivers  --->
         [*]  Staging drivers  --->
                  [*]  Industrial I/O support  --->  
                  [*]  Enable buffer support within IIO
                  <*>     Industrial I/O lock free software ring                                                               
                  < >     Industrial I/O buffering based on kfifo
                  -*-  Enable triggered sampling support                                                                      
                  (2)     Maximum number of consumers per trigger
                       Analog to digital converters  --->
                                <*>   TI's ADC driver

Building as Loadable Kernel Module

  • In-case if you want to build the driver as module, use <M> instead of <*> during menuconfig while selecting the drivers (as shown below). For more information on loadable modules refer Loadable Module HOWTO
Device Drivers  --->
         [*]  Staging drivers  --->
                  [*]  Industrial I/O support  --->
                  [*]  Enable buffer support within IIO
                  <*>     Industrial I/O lock free software ring                                                               
                  < >     Industrial I/O buffering based on kfifo
                  -*-  Enable triggered sampling support                                                                      
                  (2)     Maximum number of consumers per trigger
                       Analog to digital converters  --->
                                <M>   TI's ADC driver
  • This step applies if the driver is built as module
  1. Do "make modules" to build the ADC driver as module. The module should be present in "drivers/staging/iio/adc/ti_adc.ko".
  2. Load the driver using "ti_adc.ko".

Platform data

ADC platform data is added in board file(arch/arm/mach-omap2/board-am335xevm.c) as shown below.

#include <linux/platform_data/ti_adc.h>
static struct adc_data am335x_adc_data = {
        .adc_channels = 4,
};
static struct mfd_tscadc_board tscadc = {
        .tsc_init = &am335x_touchscreen_data,
        .adc_init = &am335x_adc_data,
};

The parameter "adc_channels" needs to hold data related to how many channels you want to use for ADC.

  • If ADC and touchscreen are used together, add platform data as shown above.
  • If ADC alone is being used, you will need to remove platform data for touch screen.

Example below. Notice adc_channels is increased to 8 in the adc initialization.

static struct adc_data am335x_adc_data = { 
        .adc_channels = 8,
};
/*
static struct tsc_data am335x_touchscreen_data  = {
        .wires  = 4,
        .x_plate_resistance = 200,
        .steps_to_configure = 5,
}; */
static struct mfd_tscadc_board tscadc = {
   /*   .tsc_init = &am335x_touchscreen_data, */
        .adc_init = &am335x_adc_data,
};

You can find the source code for ADC here

Usage

To test ADC, Connect a DC voltage supply to each of the AIN0 through AIN7 pins (based on your channel configuration), and vary voltage between 0 and 1.8v reference voltage.

CAUTION

Make sure that the voltage supplied does not cross 1.8v

On loading the module you would see the IIO device created

[email protected]:~# ls -al /sys/bus/iio/devices/iio\:device0/
drwxr-xr-x    5 root     root            0 Jan  1 00:00 .
drwxr-xr-x    4 root     root            0 Jan  1 00:00 ..
drwxr-xr-x    2 root     root            0 Jan  1 00:00 buffer
-r--r--r--    1 root     root         4096 Jan  1 00:00 dev
-r--r--r--    1 root     root         4096 Jan  1 00:00 in_voltage0_raw
-r--r--r--    1 root     root         4096 Jan  1 00:00 in_voltage1_raw
-r--r--r--    1 root     root         4096 Jan  1 00:00 in_voltage2_raw
-r--r--r--    1 root     root         4096 Jan  1 00:00 in_voltage3_raw
-r--r--r--    1 root     root         4096 Jan  1 00:00 in_voltage4_raw
-r--r--r--    1 root     root         4096 Jan  1 00:00 in_voltage5_raw
-r--r--r--    1 root     root         4096 Jan  1 00:00 in_voltage6_raw
-r--r--r--    1 root     root         4096 Jan  1 00:00 in_voltage7_raw
-rw-r--r--    1 root     root         4096 Jan  1 00:00 mode
-r--r--r--    1 root     root         4096 Jan  1 00:00 name
drwxr-xr-x    2 root     root            0 Jan  1 00:00 power
drwxr-xr-x    2 root     root            0 Jan  1 00:00 scan_elements
lrwxrwxrwx    1 root     root            0 Jan  1 00:00 subsystem -> ../../../../../../bus/iio
-rw-r--r--    1 root     root         4096 Jan  1 00:00 uevent
[email protected]:~#

Modes of operation

When the ADC sequencer finishes cycling through all the enabled channels, the user can decide if the sequencer should stop (one-shot mode), or loop back and schedule again (continuous mode). If one-shot mode is enabled, then the sequencer will only be scheduled one time (the sequencer HW will automatically disable the StepEnable bit after it is scheduled which will guarantee only one sample is taken per channel). When the user wants to continuously take samples, continuous mode needs to be enabled. One cannot read ADC data from one channel operating in One-shot mode and and other in continuous mode at the same time.

One-shot Mode

To read a single ADC output from a particular channel this interface can be used.

[email protected]:~# cat /sys/bus/iio/devices/iio\:device0/in_voltage0_raw
4095

This feature is exposed by IIO through the following files:

  • in_voltageX_raw: raw value of the channel X of the ADC
NOTE

Check ADC mode.
[email protected]:~# cat /sys/bus/iio/devices/iio\:device0/mode
oneshot

To read a single ADC value, ADC has to be configured in one-shot mode. If not in one-shot mode, This can be set by:

[email protected]:~# echo oneshot > /sys/bus/iio/devices/iio\:device0/mode

Continuous Mode

CAUTION

Please note that continuous mode is only supported with the v3.2_AM335xPSP_04.06.00.10-rc1 release or later

Important folders in the iio:deviceX directory are:

  • Buffer
    • bytes_per_datum:
    • enabled: get and set the state of the buffer
    • length: get and set the length of the buffer.

The buffer directory contains 3 files:

[email protected]:~# ls -al /sys/bus/iio/devices/iio\:device0/buffer/
drwxr-xr-x    2 root     root            0 Jan  1 00:00 .
drwxr-xr-x    5 root     root            0 Jan  1 00:00 ..
-rw-r--r--    1 root     root         4096 Jan  1 00:01 bytes_per_datum
-rw-r--r--    1 root     root         4096 Jan  1 00:01 enable
-rw-r--r--    1 root     root         4096 Jan  1 00:01 length
  • Scan_elements directory contains interfaces for elements that will be captured for a single sample set in the buffer.
[email protected]:~# ls -al /sys/bus/iio/devices/iio\:device0/scan_elements/
drwxr-xr-x    2 root     root            0 Jan  1 00:00 .
drwxr-xr-x    5 root     root            0 Jan  1 00:00 ..
-rw-r--r--    1 root     root         4096 Jan  1 00:02 in_voltage0_en
-r--r--r--    1 root     root         4096 Jan  1 00:02 in_voltage0_index
-r--r--r--    1 root     root         4096 Jan  1 00:02 in_voltage0_type
-rw-r--r--    1 root     root         4096 Jan  1 00:02 in_voltage1_en
-r--r--r--    1 root     root         4096 Jan  1 00:02 in_voltage1_index
-r--r--r--    1 root     root         4096 Jan  1 00:02 in_voltage1_type
-rw-r--r--    1 root     root         4096 Jan  1 00:02 in_voltage2_en
-r--r--r--    1 root     root         4096 Jan  1 00:02 in_voltage2_index
-r--r--r--    1 root     root         4096 Jan  1 00:02 in_voltage2_type
-rw-r--r--    1 root     root         4096 Jan  1 00:02 in_voltage3_en
-r--r--r--    1 root     root         4096 Jan  1 00:02 in_voltage3_index
-r--r--r--    1 root     root         4096 Jan  1 00:02 in_voltage3_type
-rw-r--r--    1 root     root         4096 Jan  1 00:02 in_voltage4_en
-r--r--r--    1 root     root         4096 Jan  1 00:02 in_voltage4_index
-r--r--r--    1 root     root         4096 Jan  1 00:02 in_voltage4_type
-rw-r--r--    1 root     root         4096 Jan  1 00:02 in_voltage5_en
-r--r--r--    1 root     root         4096 Jan  1 00:02 in_voltage5_index
-r--r--r--    1 root     root         4096 Jan  1 00:02 in_voltage5_type
-rw-r--r--    1 root     root         4096 Jan  1 00:02 in_voltage6_en
-r--r--r--    1 root     root         4096 Jan  1 00:02 in_voltage6_index
-r--r--r--    1 root     root         4096 Jan  1 00:02 in_voltage6_type
-rw-r--r--    1 root     root         4096 Jan  1 00:02 in_voltage7_en
-r--r--r--    1 root     root         4096 Jan  1 00:02 in_voltage7_index
-r--r--r--    1 root     root         4096 Jan  1 00:02 in_voltage7_type
[email protected]:~#

Scan_elements exposes 3 files per channel:

  • in_voltageX_en: is this channel enabled?
  • in_voltageX_index: index of this channel in the buffer's chunks
  • in_voltageX_type : How the ADC stores its data. Reading this file should return you a string something like below:
[email protected]:~# cat /sys/bus/iio/devices/iio\:device0/scan_elements/in_voltage1_type
le:u12/32>>0

Where:

  • le represents the endianness, here little endian
  • u is the sign of the value returned. It could be either u (for unsigned) or s (for signed)
  • 12 is the number of relevant bits of information
  • 32 is the actual number of bits used to store the datum
  • 0 is the number of right shifts needed.
How to set it up

To read ADC data continuously we need to enable buffer and channels to be used.

NOTE

Check ADC mode.
[email protected]:~# cat /sys/bus/iio/devices/iio\:device0/mode
oneshot

To read data continuously, ADC has to be configured in continuous mode. This can be done by:

[email protected]:~# echo continuous > /sys/bus/iio/devices/iio\:device0/mode

Set up the channels in use (you can enable any combination of the channels you want)

[email protected]:~# echo 1 > /sys/bus/iio/devices/iio\:device0/scan_elements/in_voltage0_en
[email protected]:~# echo 1 > /sys/bus/iio/devices/iio\:device0/scan_elements/in_voltage5_en
[email protected]:~# echo 1 > /sys/bus/iio/devices/iio\:device0/scan_elements/in_voltage7_en

Set up the buffer length

[email protected]:~# echo 100 > /sys/bus/iio/devices/iio\:device0/buffer/length

Enable the capture

[email protected]:~# echo 1 > /sys/bus/iio/devices/iio\:device0/buffer/enable

Now, all the captures are exposed in the character device /dev/iio:device0 

To stop the capture, just disable the buffer

[email protected]:~# echo 0 > /sys/bus/iio/devices/iio\:device0/buffer/enable

ADC Driver Limitations

This driver is based on the IIO (Industrial I/O subsystem), however this is the first release of this driver and it has limited functionality:

  1. No HW trigger Support. Currently only supporting software trigger.
  2. Limited number of samples in continuous capture mode. (Only 1528 samples per capture)
  3. Limited maximum sample rate in continuous mode: 8K samples / second.
  4. Simultaneous capture on multiple ADC channels is not supported. Currently only supports continuous capture on a single ADC input channel at a time.
  5. "Out of Range" not supported by ADC driver.

Formula Used for Calculation

To cross verify the digital values read use,

D = Vin * (2^n - 1) / Vref
Where:
D = Digital value
Vin = Input voltage
n = No of bits
Vref = reference voltage

Ex: Read value on channel AIN4 for input voltage supplied 1.01:

Formula:

Vin = 1.01 * (2^12 -1 )/ 1.8
Vin = 2297.75

Value read from sysfs:

[email protected]:~# cat /sys/bus/iio/devices/iio\:device0/in_voltage4_raw
2298

Board setup

To test ADC on AM335x EVM

On top of EVM, on LCD daughter board, J8 connector can be used, where ADC channel input AIN0-AN7 pins are brought out. For further information of J8 connector layout please refer to EVM schematics here

To test ADC on Beaglebone:

On BeagleBone platform, P9 expansion header can be used. For further information on expansion header layout please refer to the Beaglebone schematics here

Sample Application

The source code is located under kernel sources "drivers/staging/iio/Documentation/generic_buffer.c". Since our driver is not trigger based we need to modify this application to bypass the trigger detection. Please apply patchMedia:Generic_buffer.patch on top of the application generic_buffer.c in order to bypass the trigger conditions.

How to compile:

arm-arago-linux-gnueabi-gcc --static generic_buffer.c -o generic_buffer

or

<path_to_cross-compiler/cross-compiler-prefix->-gcc --static generic_buffer.c -o generic_buffer

Then copy the generic_buffer program on your target board and follow below sequence -

Enable the channels:

[email protected]:~# echo 1 > /sys/bus/iio/devices/iio\:device0/scan_elements/in_voltage4_en

Check the mode:

[email protected]:~# cat /sys/bus/iio/devices/iio\:device0/mode
oneshot
[email protected]:~# echo continuous > /sys/bus/iio/devices/iio\:device0/mode

Finally, the generic_buffer application does all the "enable" and "disable" actions for you. You will only need to specify the IIO driver. Application takes two arguments, buffer length to use (256 in this example) the default value is 128 and the number of iterations you want to run (3 in this example).

[email protected]:~# ./generic_buffer -n tiadc -l 256 -c 3

The output of this application is directly printed on console

來源:http://processors.wiki.ti.com/index.php/AM335x_ADC_Driver's_Guide

相關推薦

asm335x系列adc觸控式螢幕驅動

An analog-to-digital converter (abbreviated ADC) is a device that uses sampling to convert a continuous quantity to a discrete time repr

修改LCD觸控式螢幕驅動的一些經驗

硬體平臺:遠峰開發板 + 3.5寸三星液晶屏軟體平臺:winCE PB5.0 + SMDK BSP====LCD部分====解析度修改1、s2410.h (D:/WINCE500/PLATFORM/SMDK2410/INC/)#define LCD_XSIZE_TFT (64

ADC模數轉換器與觸控式螢幕驅動

             關於ADC與觸控式螢幕驅動(再續) ADC及時模數轉換 1模擬訊號指得是:一種時間上連續設定上也連續的物理量,具有無窮多個值,從自然界的大部分物理量都是 模擬的 2數字訊號主要是指時間上和數值上都是離散的,然而離散型的數值只有真和假,因此可以用二進

python之路系列-生成器叠代器-景麗洋老師

之前 什麽 arc alex 試題 hid hash lose code 返回頂部 楔子 假如我現在有一個列表l=[‘a‘,‘b‘,‘c‘,‘d‘,‘e‘],我想取列表中的內容,有幾種方式? 首先,我可以通過索引取值l[0],其次我們是不是還可以用for循環來取值呀? 你有

archlinux系統安裝博通B43XX系列無線網卡驅動

使用手冊 archlinux 如果 war log 命令工具 ces lib 博通 我的無線網卡是博通的B43xx系列,大家都知道博通對於其Wifi卡在 GNU/Linux 上的支持不好可謂是臭名昭著。 用 lspci -vnn -d 14e4: 或者 lspci

MySQL inner join判斷驅動驅動表的一個例子

span tab blog limit es2017 技術 spa employees rst 下述SQL中,驅動表是S表,因為S表有過濾條件 s.emp_no in (10001,10002)。 select s.emp_no ,count(distinc

第14章 ADC觸摸屏接口

ctsc lsb tar 詳解 spa 很多 發生 aps 數據位 本章目標: 了解S3C2410/S3C2440和觸摸屏的結構; 了解電阻觸摸屏的工作原理和等效電路圖; 了解S3C2410/S3C2440觸摸屏控制器的多種工作模式;

android黑科技系列——WiresharkFiddler分析Android中的TLS協議包數據(附帶案例樣本)

以管理員身份運行 inter pca lar stop 解析失敗 dash 獲取 程序 一、前言 在之前一篇文章已經介紹了一款網絡訪問軟件的破解教程,當時采用的突破口是應用程序本身的一個漏洞,就是沒有關閉日誌信息,我們通過抓取日誌獲取到關鍵信息來找到突破口進行破解的。那篇

屬性驅動模型驅動的簡單了解

一個 getpara java col bsp set get 宋體 定義 1)屬性驅動:就是jsp表單中的name都和action當中的一一屬性對應,這樣在action當中就不用像servlet一樣去通過String username=request.getParamet

溝通技巧系列 - 積極移情傾聽

width 技巧 gin 試用 發現 ont 消息 智力 關於 image.png 積極傾聽 - Active Listening 傾聽是你可以擁有的最重要的技能之一。你聽得多好對你的工作效率,以及你與他人關系的質量有重大影響。 例如: 我們傾聽以獲

溝通技巧系列 - 給予接受反饋的正確姿勢

準備 你會 在哪裏 美的 剛才 方式 辦公室 出現 了解 給予反饋 “績效評估” - 往往是不論普通員工還是管理者都不願意做的事情。 世界各地的員工和管理人員都對這種儀式感到恐懼,其中存在的主要問題是:我們已經將反饋的給予和接受程序化了。我們暗中觀察員工的日常

python內置函數中的 IO文件系列 openos

python io文件 open os 內置函數 本篇介紹 IO 中的 open 和 os基礎用法。本次用一個遊戲登陸 基礎界面做引子,來介紹。實現存儲的話,方式是很多的。 比如 存到字典 和列表了,可是字典、列表是臨時的,玩網頁遊戲一次還是可以,如果要是一個反復要用到的一個軟件的話,顯

【重磅來襲:系列二】史上最全NB-IoT技術方面的系列問題聯盟答案

zdb 史上最全 post lnl gyb nb-iot技術 dsd cxx target 1p賀新艙jp蔔裝鏈5f杖家醞http://bgjxld.wikidot.com/nv涯匱巴zt凹舷感9a溫悠舊http://zmzjsz.wikidot.com/lx猶鍁匭3d拭謨

進程管理終端驅動基本概念

大型機 工程師 tin 每次 pad 設備 完成 wid first 一、前言 對於任何一種OS,終端部分的內容總是令人非常的痛苦和沮喪,GNU/linux也是如此。究其原因主要有兩個,一是終端驅動和終端相關的系統軟件承載了太多的內容:各種虛擬終端、 偽終端、串口通信、mo

OC開發系列-@property@synthesize

AS ret per get方法 蘋果 return 結構 urn AC property和synthesize關鍵字 創建一個Person類。 #import <Foundation/Foundation.h> @interface Person : NSO

(九)模型驅動屬性驅動

tag rda add struts put username strong get exists 出於結構清晰的考慮,應該采用單獨的Model實例來封裝請求參數和處理結果,這就是所謂的模型驅動, 所謂模型驅動,就是使用單獨的JavaBean來貫穿整個MVC流程。 所謂屬性

SRM32學習筆記(8)——ADCDAC

補充 一次 說明 否則 onf 允許 包括 特性 而不是 1、ADC簡介 STM32 擁有 1~3 個 ADC(STM32F101/102 系列只有 1 個 ADC)STM32F103至少擁有2個ADC,STM32F103ZE包含3個ADC,這些 ADC

Java多線程系列-start()run方法的區別

java多線 情況下 pub -s name println get system runt start()和run是Thread類裏面的兩個方法。 學過的都知道,我們創建了一個線程類,通過調用start()方法來啟動線程,並且該線程會執行內部的run()方法,那麽我們可

GSMA公佈移動360系列–中東北非地區大會的首批演講嘉賓名單

年度移動盛會將業界專家、政府和監管官員齊聚一堂,共同就地區重大問題展開探討   倫敦--(美國商業資訊)--GSMA今日公佈了移動360系列–中東和北非(Mobile 360 Series – MENA)大會的首批演講嘉賓名單,此次大會將於2018年11月26至27日在迪拜舉行

Llinux-觸控式螢幕驅動(詳解)

https://www.cnblogs.com/lifexy/p/7628889.html https://forum.qt.io/topic/57756/solved-proper-configuration-of-capacitive-touchscreen-with-qt5-and-egl