基于beagleboard-xm的触摸屏移栽和Qt4.6.2移植

基于beagleboard-xm的触摸屏移植和Qt4.6.2移植

本文均属自己阅读源码的点滴总结,转账请注明出处谢谢。

欢迎和大家交流。qq:1037701636 email: gzzaigcn2009@163.comgzzaigcn2012@gmail.com

 

 

过去的一周,大概不到5天由于项目的部分需求暂时需要使用到触摸屏,所以暂时停下来做了一下bb-xm的触摸屏移植和Qt的支持。

学是必须的,写代码是必须的,看代码是必须的,整理文档也是必须的。

下面就简单和大家分享过去一周的成果。

1.先是简单介绍Qt4.6.2的移植部分,其实移植早做好了,只是现在想增加触摸屏对qt的支持,所以给出如下qt的编译配置:

./configure -prefix /home/Qt/lib_arm -opensource -confirm-license -release -shared -embedded arm -xplatform qws/linux-arm-g++ -depths 8,16,24,32 -fast -optimized-qmake -pch -qt-sql-sqlite -qt-libjpeg -qt-zlib -qt-libpng -qt-freetype -little-endian -host-little-endian -no-qt3support -no-libtiff -no-libmng -no-opengl -no-mmx -no-sse -no-sse2 -no-3dnow -no-openssl -no-webkit -no-phonon -no-nis -no-opengl -no-cups -no-glib -no-xcursor -no-xfixes -no-xrandr -no-xrender -no-separate-debug-info -nomake examples -nomake tools -nomake docs -qt-mouse-tslib -I /home/Qt/tslib/include -L /home/Qt/tslib/lib -verbose

-qt-mouse-tslib -I /home/Qt/tslib/include -L /home/Qt/tslib/lib这部分是Qt支持触摸屏的关键,-I和-L分别制定了tslib所在的库和头文件,说道这里tslib的编译简单如下:

步骤:
./autogen.sh
export CC=/opt/CodeSourcery/Sourcery_G++_Lite/bin/arm-none-linux-gnueabi-gcc
export PATH=/opt/CodeSourcery/Sourcery_G++_Lite/bin/:$PATH
./configure --prefix=/home/Qt/tslib --host=arm-linux --cache-file=arm-linux.cache
make
make install
 
出现错误:
Can't exec "libtoolize": No such file or directory at /usr/bin/autoreconf line 196.
Use of uninitialized value in pattern match (m//) at /usr/bin/autoreconf line 196.
configure.ac:25: error: possibly undefined macro: AC_DISABLE_STATIC
      If this token and others are legitimate, please use m4_pattern_allow.
      See the Autoconf documentation.
configure.ac:26: error: possibly undefined macro: AC_ENABLE_SHARED
configure.ac:27: error: possibly undefined macro: AC_LIBTOOL_DLOPEN
configure.ac:28: error: possibly undefined macro: AC_PROG_LIBTOOL
autoreconf: /usr/bin/autoconf failed with exit status: 1
 
执行apt-get install libtool即可解决;
 
接上面的内容:其实Qt的配置蕴含了很多关键点,通过以上配置完成Qt库的交叉编译,生成库文件,在编译qt程序时只需要将qmake路径指定就可以,qmake生成makefile等会将原先配置的编译器以及额外需要的链接库加入进去。现在对整个Linux世界的编译有了很深入的了解,基本到达了汇编级别。嘿嘿。
 
完成了以上内容哦就是库拷贝到系统的文件系统中去,至于放在哪里,取决于你自己的环境变量设置。当然,如果对Linux系统整个启动过程有很好的了解的话,可以很好的来实现程序的启动。
对于触摸屏的Qt,由于程序默认编译好后就链接了libtslib....的库,所以在运行时肯定会去找这个库,需要设置Qt的环境变量,这里不再多说。
注意点:
No raw modules loaded.
Couldnt load module input
No raw modules loaded.
QWSTslibMouseHandlerPrivate: ts_config() failed with error: 'No such file or directory'
Please check your tslib installation!:
需要有环境变量export TSLIB_PLUGINDIR=$TSLIB_ROOT/lib/ts,需要修改ts,conf的文件选择module_raw,不能有空格否则会出现sgualment 错误。
如果需要Qt永久不出现鼠标的图像:配置时添加-no-feature-CURSOR;
 
 
 
下面把beagleboard-xm部分移植触摸屏介绍一下,这方面好像很多只能在国外的论坛上见到,我这里也是简单的移植,毕竟和内核打交道我知道难度的所在,如果要完全弄懂一个月都够我消化的。
TSC2046和ADS7846两个处理器完全一样,包括引脚和工作原理,考虑到DM3730不具备现成的触摸屏控制器,所以才会外接触摸屏驱动控制器;控制触摸屏ADS7846采用MCSPI多通道串口来完成对采样到的数据的读取。MCSPI3工作在模式0的状态。
 
 
基于beagleboard-xm的触摸屏移栽和Qt4.6.2移植
 
在beagleboard中涉及到ads7846核心驱动部分的代码主要位于:
/arch/arm/mach_omap2.c下面,这里要做的其实就是在系统在未Init_module的时候,先在内核注册相关的设备,整对bb-xm是通过mcspi与ads7846进行交互的,所以需要在噶源码初添加对ads7846的支持,代码如下:
//by gzz 
#ifdef CONFIG_TOUCHSCREEN_ADS7846

#define OMAP3_BEAGLE_TS_GPIO       162 /* gpio_133 for v1.0 */

#include <plat/mcspi.h>
#include <linux/spi/spi.h>
#include <linux/spi/ads7846.h>     //for ads7864 touchscreen  

static struct omap2_mcspi_device_config ads7846_mcspi_config = {
        .turbo_mode     = 0,
        .single_channel = 1,    /* 0: slave, 1: master */
};

static int ads7846_get_pendown_state(void)
{
        return !gpio_get_value(OMAP3_BEAGLE_TS_GPIO);
}

struct ads7846_platform_data ads7846_config = {
        .x_max                  = 0x0fff,
        .y_max                  = 0x0fff,
        .x_plate_ohms           = 180,
        .pressure_max           = 255,
        .debounce_max           = 10,
        .debounce_tol           = 3,
        .debounce_rep           = 1,
        .get_pendown_state      = ads7846_get_pendown_state,
        .keep_vref_on           = 1,
        .settle_delay_usecs     = 150,
        .wakeup					= true,
};

struct spi_board_info omap3beagle_spi_board_info[] = {
        [0] = {
                .modalias               = "ads7846",
                .bus_num                = 3,
                .chip_select            = 0,
                .max_speed_hz           = 1500000,
                .controller_data        = &ads7846_mcspi_config,
                .irq                    = OMAP_GPIO_IRQ(OMAP3_BEAGLE_TS_GPIO),
                .platform_data          = &ads7846_config,
        },
};


static void ads7846_dev_init(void)
{
    printk("Initialize ads7846 touch screen controller\n");

        if (gpio_request(OMAP3_BEAGLE_TS_GPIO, "ADS7846 pendown") < 0)
                printk(KERN_ERR "can't get ads7846 pen down GPIO\n");

        gpio_direction_input(OMAP3_BEAGLE_TS_GPIO);

        omap_set_gpio_debounce(OMAP3_BEAGLE_TS_GPIO, 1);
        omap_set_gpio_debounce_time(OMAP3_BEAGLE_TS_GPIO, 0xa);
}

#else
static inline void __init ads7846_dev_init(void) { return; }
#endif
加入该部分代码后再在该模块初始化函数omap3_beagle_init中
 +:spi_register_board_info(omap3beagle_spi_board_info, ARRAY_SIZE(omap3beagle_spi_board_info));//by gzz
 +:ads7846_dev_init();//bg gzz
对以上两部分代码昨晚添加工作后,其实整个核心的移植已经完成,因为内核很好的完成了mcspi和ads7846的架构和代码(开源的世界就是博大),无论是spi数据的收发,都安装合理的架构完成,
核心的是spi_transfer和spi_message,前者表示一个命令字和数据,通常一次对ads的操作,包括2个spi_transfer,一个spi_message,将spi_message写如对于 spi_master完成数据的发送以及接受。
 
在完成代码的modify后,就需要配置内核的.config文件,通过图形或者收到添加对触摸屏的驱动支持,这里不再多说。。
 
以上部分的整个流程下去,系统就可以正常使用触摸屏了。自己再配置一下触摸屏矫正程序,整个简单的触摸屏以及qt的移植就完成了,继续努力,感觉自己压力很大很大,加油吧,你不是一个人在奋斗。加油、、、