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

时间: 2024-08-28 07:51:04

asm335x系列adc和触摸屏驱动(转)的相关文章

NUC970平台触摸屏驱动移植

原理概述 1.首先要区分lcd和触摸屏,lcd是一个屏幕,触摸屏是贴在lcd上的两层膜. 2.四线电阻触摸屏的原理:触摸屏就是上下两层膜,比如上层代表x轴(XM:负端,XP:正端),下层代表y轴(YM:负端,YP:正端).当读取x轴坐标时,XP接3.3v,XM接地,从YM读取按下点的电压值作为模拟输入信号,再经过AD转换后就得到了x轴坐标.同理,当读取y轴坐标时,YP接3.3v,YM接地,从XM读取按下点的电压值作为模拟输入,再经过AD转换后就得到了y轴坐标. 触摸屏驱动程序采用中断方式对触摸笔

转载: linux2.6.37.4内核在XC2440开发板上移植(六)之触摸屏驱动移植

来自:http://blog.chinaunix.net/uid-22030783-id-3023527.html 内核自带s3c2440的触摸屏控制器驱动,属于input子系统的驱动,触摸屏驱动需要ADC驱动的支持,触摸屏驱动文件为:drivers/input/touchscreen/s3c2410_ts.c 在mach-xc2440.c文件中加入对触摸屏驱动的支持, 创建s3c2410_ts_mach_info平台数据 加入必要的头文件: #include <plat/ts.h> xc24

触摸屏驱动三部曲之功能实现及优化

小伙伴们准备好了吗?又到了看手册写代码的时候了.既懂硬件又懂软件的驱动工程师们.Come On..... 一.总体框图 二.驱动代码 #include <linux/errno.h> #include <linux/kernel.h> #include <linux/module.h> #include <linux/slab.h> #include <linux/input.h> #include <linux/init.h> #i

触摸屏驱动三部曲之输入子系统

一.触摸屏系统框架 1.框架代码(具体细节处理,见下节代码) #include <linux/errno.h> #include <linux/kernel.h> #include <linux/module.h> #include <linux/slab.h> #include <linux/input.h> #include <linux/init.h> #include <linux/serio.h> #includ

[国嵌攻略][140][触摸屏驱动分析]

触摸屏驱动分析 初始化 1.使能ADC时钟 2.将物理地址转化为虚拟地址 3.让触摸屏进入等待中断模式 4.分配输入设备结构 5.设置可能上报的事件类型和按键类型 6.为TC和ADC中断注册处理函数 7.注册输入型设备 按下处理 1.判断按下或弹起 2.如果是按下情况,那么启动XY坐标的AD转换 3.进行4次ADC转换,获取4次XY坐标值 4.计算4次采集的平均值,并上报给内核

S3C2440触摸屏驱动实例开发讲解

出处:http://www.embeddedlinux.org.cn/html/yingjianqudong/ 一.开发环境 主  机:VMWare--Fedora 9 开发板:Mini2440--64MB Nand, Kernel:2.6.30.4 编译器:arm-linux-gcc-4.3.2 二.前提知识 1.Linux输入子系统(Input Subsystem): 在Linux中,输入子系统是由输入子系统设备驱动层.输入子系统核心层(Input Core)和输入子系统事件处理层(Even

ARM-Linux驱动-触摸屏驱动分析

出处:http://blog.csdn.net/geekcome/article/details/6580981 硬件平台:FL2440 内核版本:2.6.28 主机平台:Ubuntu 11.04 内核版本:2.6.39 原创作品,转载请标明出处http://blog.csdn.net/yming0221/article/details/6580981 1.下面是ADC和触摸屏接口的模块图 当触摸屏接口使用时,XM或YM接触摸屏接口的地 当触摸屏接口不使用时,XM或YM接模拟信号,做普通ADC使

触摸屏驱动三部曲之硬件原理

零.触摸屏驱动三部曲概述 触摸屏已经在我们的生活中无处不在,所以说写好触摸屏的驱动是很重要的.接下来我会通过三篇文章详细讲解触摸屏的驱动. 1.触摸屏驱动三部曲之硬件原理 写好一个驱动,一定要对硬件有所了解,这节我会讲解触摸屏的基础知识和电阻触摸屏的原理. 2.触摸屏驱动三部曲之输入子系统 输入子系统在驱动中占着举足轻重的位置,按键,触摸屏,鼠标等输入型设备都可以利用input接口函数来实现设备驱动.想知道具体怎么实现的就来看这节吧. 3.触摸屏驱动三部曲之功能实现及优化 这节主要是分析框架,写

触摸屏驱动

触摸屏驱动 input子系统框架: 输入子系统的核心文件input.c,其中的file_operations中的.open会找到input_handler得到具体的fops, 在linux内核中是evdev.c来提供handler,它里面有一个evdev_handler,这个evdev_handler中提供了更为详细的fops(evdev_fops),所以应用程序通过标准的接口(open,read,write等)来访问/dev/input/eventn(n=0,1,2,3...) 最终会访问到e