?? 觸摸屏移植(成功)for2.6.rtf
字號:
在 linux2.6.14 中沒有提供 s3c2410 的驅動,所以我們要新建驅動文件,我們在 linux2.6.14/drivers/input/touchscreen 目錄下建立新的文件 hfrk_s3c2410_ts.c 文件,驅動文件我們可以參考類似的觸摸屏驅動,具體的內容參看網站或者光盤提供的源代碼。
首先:我們需要修改 linux2.6.14/drivers/input/touchscreen 目錄下的 makefile 文件,在文件的最后 添加 :
obj-$(CONFIG_TOUCHSCREEN_S3C2410) += hfrk_s3c2410_ts.o
第二:我們需要修改 linux2.6.14/ drivers/input/touchscreen/Kconfig 中添加:
config TOUCHSCREEN_S
tristate "Samsung S3C2410 touchscreen input driver"
depends on ARCH_SMDK2410 && INPUT && INPUT_TOUCHSCREEN
select SERIO
help
Say Y here if you have the s3c2410 touchscreen.
If unsure, say N.
To compile this driver as a module, choose M here: the
module will be called s3c2410_ts.
config TOUCHSCREEN_S3C2410_DEBUG
boolean "Samsung S3C2410 touchscreen debug messages"
depends on TOUCHSCREEN_S3C2410
help
Select this if you want debug messages
修改完成以后,在我們配置內核的時候,就會增加關系s3c2410的觸摸屏配置,我們選擇上這些配置就可以把驅動增加進去了
Device drivers - à
Input device support à
Touchscreens à
<*>Samsung S3C2410 touchscreen input driver
[]Samsung s3c2410 touchscreen debug message
第三:在 /linux-2.6.14/arch/arm/mach-s3c2410/mach-smdk2410.c, 中增加如下內容:
static struct s3c2410_ts_mach_info sbc2410_ts_cfg __initdata = {
.delay = 10000,
.presc = 49,
.oversampling_shift = 2,
};
在smdk2410_devices結構中,添加:
&s3c_device_ts,
在smdk2410_map_io函數中添加:
set_s3c2410ts_info(&sbc2410_ts_cfg);
第四:在 /linux-2.6.14/ arch/arm/mach-s3c2410/devs.h 文件中添加:
extern struct platform_device s3c_device_ts;
第五:在arch/arm/mach-s3c2410/devs.c文件中添加如下幾行:
/* Touchscreen */
static struct s3c2410_ts_mach_info s3c2410ts_info;
void __init set_s3c2410ts_info(struct s3c2410_ts_mach_info *hard_s3c2410ts_info)
{
memcpy(&s3c2410ts_info,hard_s3c2410ts_info,sizeof(struct s3c2410_ts_mach_info));
}
EXPORT_SYMBOL(set_s3c2410ts_info);
struct platform_device s3c_device_ts = {
.name = "s3c2410-ts",
.id = -1,
.dev = {
.platform_data = &s3c2410ts_info,
}
};
EXPORT_SYMBOL(s3c_device_ts);
經過這些修改,我們的觸摸屏驅動已經完成 , 我們編譯就可以了。我們的 這個觸摸屏驅動在內核注冊為 /dev/input/mouse0 十.創建設備文件 根據你的配置情況創建相應的設備文件例如: mknod -m 666 ts -c 13 128 等首先需要有調試好的2.6觸摸屏驅動,該驅動在網上可以找到,它將觸摸屏注冊為input設備,將坐標信息傳輸到input層。tslib可以直接從input層獲取坐標信息,因此,下面將要介紹如何讓qte3.3.5支持tslib。這樣qte3.3.5的程序就可以用觸摸屏控制了。 qte2,qtopia都直接支持tslib,而qte3不能直接支持tslib,需要加patch。具體方法如下:1.編譯qte3.3.5 * cd qte-3.3.5 * export QTDIR=$PWD * cp uic bin/(拷貝x-11的bin/uic工具到bin下) * (關鍵步驟,否則編譯時會報錯說libts不兼容) $ echo yes |./configure -embedded arm -thread $ cd src/moc $ make * 從網上尋找tslib-patch。該patch針對qte3.3.4,此處根據patch內容手動patch:增加兩個文件到 src/embedded/下(src/embedded/qmousetslib_qws.h, src/embedded/qmousetslib_qws.cpp),修改相應文件 (src/embedded/qmousedriverfactory_qws.cpp, src/embedded/qt_embedded.pri,configure) * 編譯tslib,拷貝tslib.h到include,libts.so等庫到lib下。 * $ echo yes |./configure -embedded arm –thread –qt-mouse-tslib –I$QTDIR/include –L$QTDIR/lib –lts * make * make install2.拷貝文件到目標板 拷貝qte3.3.5/lib到目標板,拷貝tslib的build目錄到目標板(記住,要拷貝和編譯qte時使用的相同的tslib版本)3.設置環境變量export QTDIR=/hjcaiexport LD_LIBRARY_PATH=/hjcai/libexport QWS_MOUSE_PROTO=tslib:/dev/input/tsraw0export TSLIB_TSDEVICE=/dev/input/tsraw0export TSLIB_CONSOLEDEVICE=noneexport TSLIB_FBDEVICE=/dev/fb0export TSLIB_CONFFILE=/hjcai/build/etc/ts.confexport TSLIB_PLUGINDIR=/hjcai/build/share/ts/pluginsexport TSLIB_TSEVENTTYPE="H3600"export TSLIB_CALIBFILE=/etc/pointercal4 觸摸屏校正先進行觸摸屏校正,注釋掉build/etc/ts.conf中的dejitter模塊,執行build/bin下的ts_calibrate程序,此時會在/etc下生成pointercal文件。5 測試拷貝qte3.3.5下examples/hello/hello文件到目標板,修改權限,然后執行./hello –qws發現程序可以用觸摸屏控制。關于硬件。 從LCD的型號來來看,與s3c2410兼容得比較好的LCD是Sumsung自己產的LTS系列,如LTS350Q1PD1,LTS350Q1PE1。但是這類型號現在已停產,基本上無法買到。代替的型號是LTV系列,如LTV350QVF04,LTV350QVF05。 我使用的是LTV350QVF05。這是一款3.5寸,由TFT LCD,背光電路,觸摸屏,內置驅動四部分組成的LCD模塊。由于內置了驅動電路,因此它可以和s3c2410之間可以直接相連,硬件設計簡單。少量購買的價格在300左右。 LTV350QVF05通過一個60pin的軟平線接口和外面相連,其中除了和s3c2410相連接的信號外,最重要的是它的幾個電源信號,包括背光部分的電源。調試硬件,首先要保證它的幾個電源信號滿足要求。Max1779芯片提供三路電源輸出,能很好地滿足需求。另外需要提供一個Vcom信號。該信號用于LCD的行翻轉,是一個低電平0V,高電平3.3V左右的方波信號。LCD模塊內部提供一個M信號,只需要將該信號取反就可以得到Vcom信號。通常會搭一個可調的運放電路來實現,調整放大倍數和偏移可以改變屏的亮度和對比度。 在調試好幾個電源信號后,上電,應該可以把屏點亮。起初應該是白屏。 下面介紹驅動的移植。 關于驅動移植。 網上可以找到代碼s3c2410fb.c,基本上可以直接使用。移植的基本步驟是:1. 添加s3c2410fb.c到drivers/video目錄下。2. 在s3c2410fb.c中添加適當的LCD初始化代碼。LTV350QV接口中有一個spi接口用來啟動LCD,設計中可以采用gpio口來模擬spi口輸出控制信號。編寫一個初始化函數,然后在s3c2410fb_init函數中調用即可。3. 修改video目錄的Kconfig和Makefile,保證s3c2410fb.c被編譯進內核。4. 在arch/arm/mach-s3c2410/mach-smdk2410.c中添加static struct s3c2410fb_mach_info smdk2410_lcd_platdata結構。該結構的參數用于設置s3c2410的LCD控制寄存器,需要認真根據自己的LCD參數來設置。包括分辨率、幀頻、圖像格式等參數。5. 在arch/arm/mach-s3c2410/mach-smdk2410.c函數smdk2410_map_io中添加代碼:set_s3c2410fb_info(&smdk2410_lcd_platdata)6. 在arch/arm/mach-s3c2410/devs.c中添加以下代碼:static struct s3c2410fb_mach_info s3c2410fb_info;void __init set_s3c2410fb_info(struct s3c2410fb_mach_info *hard_s3c2410fb_info){ memcpy(&s3c2410fb_info,hard_s3c2410fb_info,sizeof(struct s3c2410fb_mach_info)); s3c_device_lcd.dev.platform_data = &s3c2410fb_info;}EXPORT_SYMBOL(set_s3c2410fb_info);7. 配置內核,添加對LCD的支持,包括啟動logo(小企鵝)的支持。 如果啟動后可以看見小企鵝,說明LCD驅動移植成功。 可能的問題:1. smdk2410_lcd_platdata結構中幀頻(Vsync的頻率)的設置不能高于LCD的最高幀頻,可以增大lcdcon1中clkval的值Vclk,進而降低Vsync。2. 圖像深度最好設為16bpp,我用過24bpp,結果無法顯示企鵝,可能是內核驅動本身不支持。3. 如果過幾分鐘后,圖像沒了。注釋掉drivers/char/vt.c中的blank_screen_t()函數內容。調試過程:按照以上步驟做好后,在終端輸入命令:make bzImage確保linux-2.6.14/include/asm/arch-s3c2410/s3c2410_ts.h有該文件出現以下錯誤:
CC arch/arm/mach-s3c2410/mach-smdk2410.oarch/arm/mach-s3c2410/mach-smdk2410.c:131: error: variable `sbc2410_ts_cfg' has initializer but incomplete typearch/arm/mach-s3c2410/mach-smdk2410.c:132: error: unknown field `delay' specified in initializerarch/arm/mach-s3c2410/mach-smdk2410.c:132: warning: excess elements in struct initializerarch/arm/mach-s3c2410/mach-smdk2410.c:132: warning: (near initialization for `sbc2410_ts_cfg')arch/arm/mach-s3c2410/mach-smdk2410.c:133: error: unknown field `presc' specified in initializerarch/arm/mach-s3c2410/mach-smdk2410.c:133: warning: excess elements in struct initializerarch/arm/mach-s3c2410/mach-smdk2410.c:133: warning: (near initialization for `sbc2410_ts_cfg')arch/arm/mach-s3c2410/mach-smdk2410.c:134: error: unknown field `oversampling_shift' specified in initializerarch/arm/mach-s3c2410/mach-smdk2410.c:134: warning: excess elements in struct initializerarch/arm/mach-s3c2410/mach-smdk2410.c:134: warning: (near initialization for `sbc2410_ts_cfg')arch/arm/mach-s3c2410/mach-smdk2410.c: In function `smdk2410_map_io':arch/arm/mach-s3c2410/mach-smdk2410.c:143: warning: implicit declaration of function `set_s3c2410ts_info'arch/arm/mach-s3c2410/mach-smdk2410.c: At top level:arch/arm/mach-s3c2410/mach-smdk2410.c:131: error: storage size of `sbc2410_ts_cfg' isn't knownmake[1]: *** [arch/arm/mach-s3c2410/mach-smdk2410.o] 錯誤 1make: *** [arch/arm/mach-s3c2410] 錯誤 2在arch/arm/mach-s3c2410/devs.c文件中添加如下幾行:
#include <asm/arch/s3c2440_ts.h> 在 /linux-2.6.14/arch/arm/mach-s3c2410/mach-smdk2410.c, 中增加如下內容:
#include <asm/arch/s3c2440_ts.h> 重新編譯,有下面的錯誤:CC drivers/input/touchscreen/s3c2410_ts.odrivers/input/touchscreen/s3c2410_ts.c: In function `touch_timer_fire':drivers/input/touchscreen/s3c2410_ts.c:145: error: called object is not a functiondrivers/input/touchscreen/s3c2410_ts.c:154: error: called object is not a functiondrivers/input/touchscreen/s3c2410_ts.c: In function `stylus_action':drivers/input/touchscreen/s3c2410_ts.c:196: error: called object is not a functiondrivers/input/touchscreen/s3c2410_ts.c:200: error: called object is not a functiondrivers/input/touchscreen/s3c2410_ts.c: In function `s3c2410ts_probe':drivers/input/touchscreen/s3c2410_ts.c:261: error: called object is not a functiondrivers/input/touchscreen/s3c2410_ts.c: In function `touch_timer_fire':drivers/input/touchscreen/s3c2410_ts.c:145: warning: statement with no effectdrivers/input/touchscreen/s3c2410_ts.c:154: warning: statement with no effectdrivers/input/touchscreen/s3c2410_ts.c: In function `stylus_action':drivers/input/touchscreen/s3c2410_ts.c:196: warning: statement with no effectdrivers/input/touchscreen/s3c2410_ts.c:200: warning: statement with no effectdrivers/input/touchscreen/s3c2410_ts.c: In function `s3c2410ts_probe':drivers/input/touchscreen/s3c2410_ts.c:261: warning: statement with no effectmake[3]: *** [drivers/input/touchscreen/s3c2410_ts.o] 錯誤 1make[2]: *** [drivers/input/touchscreen] 錯誤 2make[1]: *** [drivers/input] 錯誤 2make: *** [drivers] 錯誤 2在文件位置在 include/asm-arm/arch-s3c2410/regs-adc.h, 并在其添加如下內容#define S3C2410_ADCTSC_XY_PST_N (0x0<<0)#define S3C2410_ADCTSC_XY_PST_X (0x1<<0)#define S3C2410_ADCTSC_XY_PST_Y (0x2<<0)#define S3C2410_ADCTSC_XY_PST_W (0x3<<0)但好象沒效果。下面是使用胡軍國給的tsFrom軍國的s3c2410_ts.c和s3c2410_ts.h(需復制到linux-2.6.14/include/asm/arch)文件,$make bzImage出現以下錯誤:CC drivers/input/touchscreen/s3c2410_ts.odrivers/input/touchscreen/s3c2410_ts.c:107:1: warning: "IRQ_HANDLED" redefinedIn file included from include/linux/rcuref.h:36,
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -