觸摸屏驅(qū)動(dòng)程序(輸入子系統(tǒng))
#include "linux/kernel.h"
#include "linux/module.h"
#include "linux/slab.h"
#include "linux/input.h"
#include "linux/init.h"
#include "linux/serio.h"
#include "linux/delay.h"
#include "linux/platform_device.h"
#include "linux/clk.h"
#include "asm/io.h"
#include "asm/irq.h"
#include "asm/plat-s3c24xx/ts.h"
#include "asm/arch/regs-adc.h"
#include "asm/arch/regs-gpio.h"
struct s3c_ts_regs {
};
static struct input_dev *s3c_ts_dev;
static volatile struct s3c_ts_regs *s3c_ts_regs;
static struct timer_list ts_timer;
//等到觸控筆按下模式
static void enter_wait_pen_down_mode(void)
{
}
//等到觸控筆松開模式
static void enter_wait_pen_up_mode(void)
{
}
//進(jìn)入X/Y方向ADC同時(shí)轉(zhuǎn)換模式
static void enter_measure_xy_mode(void)
{
}
//啟動(dòng)ADC轉(zhuǎn)換
static void start_adc(void)
{
}
static int s3c_filter_ts(int x[], int y[])
{
#define ERR_LIMIT 10
}
static void s3c_ts_timer_function(unsigned long data)
{
}
//觸控筆按下、抬起中斷服務(wù)函數(shù)
static irqreturn_t pen_down_up_irq(int irq, void *dev_id)
{
}
static irqreturn_t adc_irq(int irq, void *dev_id)
{
}
static int s3c_ts_init(void)
{
}
static void s3c_ts_exit(void)
{
}
module_init(s3c_ts_init);
module_exit(s3c_ts_exit);
MODULE_LICENSE("GPL");
================================================================
解析:
加載驅(qū)動(dòng)以后運(yùn)行s3c_ts_init函數(shù),程序進(jìn)入等待觸控筆按下模式enter_wait_pen_down_mode(),當(dāng)有觸控筆按下時(shí)進(jìn)入按下中斷服務(wù)函數(shù)中運(yùn)行,即pen_down_up_irq中,進(jìn)入中斷服務(wù)函數(shù)后立即判斷觸控筆是否依然按下,如果這個(gè)時(shí)候觸控筆已經(jīng)松開則上報(bào)事件;若此時(shí)觸控筆依然按下則進(jìn)入X/Y雙方向同時(shí)進(jìn)行ADC轉(zhuǎn)換模式,并啟動(dòng)ADC轉(zhuǎn)換。當(dāng)ADC轉(zhuǎn)換完成以后進(jìn)入ADC中斷服務(wù)程序,從adcdat0、adcdat1獲取到x方向、y方向的ADC數(shù)據(jù),再判斷觸控筆是否離開,如果已經(jīng)離開則進(jìn)行上報(bào)數(shù)據(jù);否則保存此次ADC轉(zhuǎn)換數(shù)據(jù)再判斷ADC采集到的數(shù)據(jù)有沒有到4次,如果累計(jì)到4次則進(jìn)行軟件濾波后上報(bào)事件,進(jìn)入等待觸控筆離開模式enter_wait_pen_up_mode,同時(shí)啟動(dòng)定時(shí)器開始計(jì)時(shí)處理連續(xù)按壓事件;如果不夠4次則再次進(jìn)入X/Y雙方向同時(shí)進(jìn)行ADC轉(zhuǎn)換模式,并啟動(dòng)ADC轉(zhuǎn)換。當(dāng)定時(shí)時(shí)間到了以后進(jìn)入定時(shí)中斷服務(wù)函數(shù)里,判斷觸控筆是否離開,如果觸控筆松開則上報(bào)事件,進(jìn)入等待觸控筆按下模式,否則再次進(jìn)入X/Y雙方向同時(shí)進(jìn)行ADC轉(zhuǎn)換模式,并啟動(dòng)ADC轉(zhuǎn)換。依次!
測(cè)試2th~7th:
1. make menuconfig 去掉原來的觸摸屏驅(qū)動(dòng)程序
-> Device Drivers
make uImage
使用新內(nèi)核啟動(dòng)
2. insmod s3c_ts.ko
按下/松開觸摸筆
測(cè)試2th~7th:
1. ls /dev/event*
2. insmod s3c_ts.ko
3. ls /dev/event*
4. hexdump /dev/event0
0000000 29a4 0000 8625 0008 0003 0000 0172 0000
0000010 29a4 0000 8631 0008 0003 0001 027c 0000
0000020 29a4 0000 8634 0008 0003 0018 0001 0000
0000030 29a4 0000 8638 0008 0001 014a 0001 0000
0000040 29a4 0000 863c 0008 0000 0000 0000 0000
0000050 29a4 0000 c85e 0008 0003 0000 0171 0000
0000060 29a4 0000 c874 0008 0003 0001 027d 0000
0000070 29a4 0000 c87b 0008 0000 0000 0000 0000
0000080 29a4 0000 ed37 0008 0003 0018 0000 0000
0000090 29a4 0000 ed48 0008 0001 014a 0000 0000
00000a0 29a4 0000 ed4a 0008 0000 0000 0000 0000
lcd和觸摸屏聯(lián)合使用參考”tslib編譯使用方法“
//暫時(shí)忽略下面三行命令
//sudo apt-get install autoconf
//sudo apt-get install automake
//sudo apt-get install libtool
編譯:
tar xzf tslib-1.4.tar.gz
cd tslib
./autogen.sh
mkdir tmp
echo "ac_cv_func_malloc_0_nonnull=yes" >arm-linux.cache
./configure --host=arm-linux --cache-file=arm-linux.cache --prefix=$(pwd)/tmp
make
make install //安裝到tmp目錄
安裝:
cd tmp
再把tmp目錄下的4個(gè)文件全都拷貝到開發(fā)板的根目錄下
cp * /home/book/workspace/JZ2440_TestFile/system/first_fs -rfd
(采用網(wǎng)絡(luò)文件系統(tǒng)啟動(dòng)時(shí)開發(fā)板的根目錄,但是此時(shí)并沒有拷貝到開發(fā)板的flash上面,如果要拷貝到開發(fā)板的flash上面可以不用網(wǎng)絡(luò)文件系統(tǒng)啟動(dòng),采用手動(dòng)掛載的方式把文件系統(tǒng)掛載到開發(fā)板的mnt目錄下,在從mnt目錄下把tmp里的文件拷貝到開發(fā)板的根目錄下面,這樣就算真正的在開發(fā)板的flash上面了。)
使用:
先安裝s3c_ts.ko, lcd.ko
1.
修改 /etc/ts.conf第1行(去掉#號(hào)和第一個(gè)空格):
# module_raw input
改為:
module_raw input
2.設(shè)置環(huán)境變量
export TSLIB_TSDEVICE=/dev/event0
export TSLIB_CALIBFILE=/etc/pointercal
export TSLIB_CONFFILE=/etc/ts.conf
export TSLIB_PLUGINDIR=/lib/ts
export TSLIB_CONSOLEDEVICE=none
export TSLIB_FBDEVICE=/dev/fb0
使用以下兩個(gè)命令進(jìn)行測(cè)試:

評(píng)論