打印
[Beagle Bone]

AM335X 触摸屏的硬件连接及Linux驱动

[复制链接]
7481|18
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
zhangmangui|  楼主 | 2014-12-31 12:35 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
本帖最后由 zhangmangui 于 2015-1-1 21:34 编辑

许多客户问到触摸屏的连接及驱动问题,另外还有同时使用触摸屏和通用ADC,特此分享如下:
1. overview
AM335x TS controller支持如下四种:
• 8 general-purpose ADC channels 即8路通用的ADC
• 4-wire TSC with 4 general-purpose ADC channels 即4路作为4线触摸屏连接,4路作为通用ADC
• 5-wire TSC with 3 general-purpose ADC channels 即5路作为5线触摸屏连接,3路作为通用ADC
• 8-wire TSC 即8路作为8线触摸屏连接
2. HW connection
AM335X TS controller与各种类型触摸屏连接如下:
关于4线触摸屏的连接方式如下:

5线触摸屏连接如下:

8线触摸品连接如下:
3. Linux driver
关于触摸屏的驱动说明,可以参考http://processors.wiki.ti.com/index.php/AM335x_ADC_Driver%27s_Guide
需要说明的是SDK-5.07.00.00开始,驱动中同时支持TS和通用ADC,即可以支持4线触摸屏+4路通用ADC、5线触摸品+3路通用ADC、8线触摸屏。
对于触摸屏的原理,可以参考**《Using resistive touch screens for human/machine interface》
关于Touch-screen acquisition flowchart,见下图


RE: AM335X 触摸屏的硬件连接及Linux驱动<技术分享> by Gary Wu
需要补充说明的是TS的驱动在linux/drivers/mfd/ti_tscadc.c
关于platform data在linux/arch/arm/mach-omap2/board-am335xevm.c中有如下结构体,默认是支持4线屏的。如果支持其他,需要修改下述结构体中的参数。
/* TSc controller */
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,
};


来自deyisupport

相关帖子

沙发
lcofjp| | 2014-12-31 15:02 | 只看该作者
谢谢楼主分享!

使用特权

评论回复
板凳
andylianggq| | 2015-1-1 19:55 | 只看该作者

使用特权

评论回复
地板
andylianggq| | 2015-1-1 19:55 | 只看该作者
硬件平台基于beaglebone black板,应用程序在SDK7.0上实现。
10.4寸LCD控制加载正常,触摸屏校准只在一个很小区域有响应,触摸屏工作不正常,通过修改驱动可以完成触摸控制鼠标,但是有偏移;
在7寸屏上测试,完全正常;测量阻抗 7寸 x:258 Y:670; 10.4寸屏 x:400,Y:685
目标:实现10.4寸电阻屏的校准。

使用特权

评论回复
5
zhangmangui|  楼主 | 2015-1-1 21:34 | 只看该作者
andylianggq 发表于 2015-1-1 19:55
http://processors.wiki.ti.com/index.php/AM335x_ADC_Driver's_Guide
这个链接无效啊

你看看这个链接  
http://processors.wiki.ti.com/index.php/AM335x_ADC_Driver%27s_Guide

使用特权

评论回复
6
zhangmangui|  楼主 | 2015-1-1 21:37 | 只看该作者
andylianggq 发表于 2015-1-1 19:55
硬件平台基于beaglebone black板,应用程序在SDK7.0上实现。
10.4寸LCD控制加载正常,触摸屏校准只在一个很 ...

这个屏的大小导致的坐标错差吧    调制校准吧  
具体没搞过   还望你能指导

使用特权

评论回复
7
zhangmangui|  楼主 | 2015-1-1 21:38 | 只看该作者
本帖最后由 zhangmangui 于 2015-1-1 21:40 编辑

Introduction
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 driverBuilding 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

  • Do "make modules" to build the ADC driver as module. The module should be present in "drivers/staging/iio/adc/ti_adc.ko".
  • Load the driver using "ti_adc.ko".
Platform dataADC 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
UsageTo 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
root@arago-armv7:~# 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 namedrwxr-xr-x    2 root     root            0 Jan  1 00:00 powerdrwxr-xr-x    2 root     root            0 Jan  1 00:00 scan_elementslrwxrwxrwx    1 root     root            0 Jan  1 00:00 subsystem -> ../../../../../../bus/iio-rw-r--r--    1 root     root         4096 Jan  1 00:00 ueventroot@arago-armv7:~#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.
root@arago-armv7:~# cat /sys/bus/iio/devices/iio\:device0/in_voltage0_raw4095This 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. root@arago-armv7:~# cat /sys/bus/iio/devices/iio\:device0/modeoneshotTo 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:
root@arago-armv7:~# echo oneshot > /sys/bus/iio/devices/iio\:device0/mode

Continuous ModeCAUTION
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:
root@arago-armv7:~# 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.
root@arago-armv7:~# 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_typeroot@arago-armv7:~#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:
root@arago-armv7:~# cat /sys/bus/iio/devices/iio\:device0/scan_elements/in_voltage1_typele:u12/32>>0Where:

  • 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 upTo read ADC data continuously we need to enable buffer and channels to be used.
NOTE

Check ADC mode. root@arago-armv7:~# cat /sys/bus/iio/devices/iio\:device0/modeoneshotTo read data continuously, ADC has to be configured in continuous mode. This can be done by:
root@arago-armv7:~# 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)
root@arago-armv7:~# echo 1 > /sys/bus/iio/devices/iio\:device0/scan_elements/in_voltage0_enroot@arago-armv7:~# echo 1 > /sys/bus/iio/devices/iio\:device0/scan_elements/in_voltage5_enroot@arago-armv7:~# echo 1 > /sys/bus/iio/devices/iio\:device0/scan_elements/in_voltage7_enSet up the buffer length
root@arago-armv7:~# echo 100 > /sys/bus/iio/devices/iio\:device0/buffer/lengthEnable the capture
root@arago-armv7:~# echo 1 > /sys/bus/iio/devices/iio\:device0/buffer/enableNow, all the captures are exposed in the character device /dev/iio:device0

To stop the capture, just disable the buffer
root@arago-armv7:~# echo 0 > /sys/bus/iio/devices/iio\:device0/buffer/enableADC 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:

  • No HW trigger Support. Currently only supporting software trigger.
  • Limited number of samples in continuous capture mode. (Only 1528 samples per capture)
  • Limited maximum sample rate in continuous mode: 8K samples / second.
  • Simultaneous capture on multiple ADC channels is not supported. Currently only supports continuous capture on a single ADC input channel at a time.
  • "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) / VrefWhere:D = Digital valueVin = Input voltagen = No of bitsVref = reference voltageEx: Read value on channel AIN4 for input voltage supplied 1.01:
Formula:
Vin = 1.01 * (2^12 -1 )/ 1.8Vin = 2297.75Value read from sysfs:
root@arago-armv7:~# cat /sys/bus/iio/devices/iio\:device0/in_voltage4_raw2298Board setupTo test ADC on AM335x EVMOn 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 patch Media: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_bufferor
<path_to_cross-compiler/cross-compiler-prefix->-gcc --static generic_buffer.c -o generic_bufferThen copy the generic_buffer program on your target board and follow below sequence -
Enable the channels:
root@arago-armv7:~# echo 1 > /sys/bus/iio/devices/iio\:device0/scan_elements/in_voltage4_enCheck the mode:
root@arago-armv7:~# cat /sys/bus/iio/devices/iio\:device0/modeoneshotroot@arago-armv7:~# echo continuous > /sys/bus/iio/devices/iio\:device0/modeFinally, 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).
root@arago-armv7:~# ./generic_buffer -n tiadc -l 256 -c 3

使用特权

评论回复
8
天师猫神| | 2015-1-2 16:46 | 只看该作者
谢谢楼主分享!

使用特权

评论回复
9
zhangmangui|  楼主 | 2015-1-3 20:26 | 只看该作者
有些乱   谢谢楼上支持

使用特权

评论回复
10
通用账户| | 2015-1-27 22:08 | 只看该作者
zhangmangui 发表于 2015-1-3 20:26
有些乱   谢谢楼上支持

老版啊,有没有用手机屏dsi接口和ctp i2c的方案啊,或者现成的?
我看那个ssd2828貌似好像能搞但是网上没什么资料,手机屏也不知道选哪个好

使用特权

评论回复
11
zhangmangui|  楼主 | 2015-1-27 22:26 | 只看该作者
通用账户 发表于 2015-1-27 22:08
老版啊,有没有用手机屏dsi接口和ctp i2c的方案啊,或者现成的?
我看那个ssd2828貌似好像能搞但是网上没 ...

不好意思啊   没有

使用特权

评论回复
12
mini1986| | 2015-4-16 12:43 | 只看该作者
使用串口红外触摸屏也是可以滴......

使用特权

评论回复
13
mini1986| | 2015-4-22 08:45 | 只看该作者
sdk6.0上实现了10寸屏,效果还不错......

使用特权

评论回复
14
zhangmangui|  楼主 | 2015-4-25 22:58 | 只看该作者
mini1986 发表于 2015-4-22 08:45
sdk6.0上实现了10寸屏,效果还不错......

求分享 啊  

使用特权

评论回复
15
mini1986| | 2015-4-27 12:40 | 只看该作者
跟7寸屏一样,除了分辨率参数外,没啥改的......

使用特权

评论回复
16
lanzai| | 2016-3-8 10:40 | 只看该作者
我用的是BBB,触摸屏的4根线连到AIN0~AIN3上,移植的TSLIB,但是运行校正程序,提示我selected device is not touchscreen(must support BTN_TOUCH or BIN_LEFT events)
我用的是TI SDK8.0
这是为什么啊?我遗漏了哪些步骤?

使用特权

评论回复
17
zhangmangui|  楼主 | 2016-3-8 21:35 | 只看该作者
lanzai 发表于 2016-3-8 10:40
我用的是BBB,触摸屏的4根线连到AIN0~AIN3上,移植的TSLIB,但是运行校正程序,提示我selected device is n ...

不好意思    没升入研究过

使用特权

评论回复
18
cnb12345| | 2016-4-26 15:01 | 只看该作者

使用特权

评论回复
19
tomgreen7654321| | 2022-1-7 08:44 | 只看该作者

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

个人签名:欢迎进入【TI DSP 论坛】 & 【DSP 技术】           TI忠诚粉丝!

935

主题

26376

帖子

588

粉丝