目标:用游戏手柄控制贪吃蛇
硬件平台:imax6q
版本信息: arm-none-linux-gnueabi-gcc-4.8.3、 qt5.7.1、linux3.0.1
一、交叉编译tslib1.4
由于 imax6q是 armv7-a 构架,所以以后的编译我们都应编译出 armv7 平台的文件
编译参数:
echo ‘ac_cv_func_malloc_0_nonnull=yes’ > arm-linux.cache
CFLAGS=-march=armv7-a ./configure -host=arm-linux -cache-file=arm-linux.cache -prefix=/usr/local/tslib_v7
编译成功后 我们验证下
二、编译qt4.7.1
安装依赖
apt-get install libxcb1 libxcb1-dev libx11-xcb1 libx11-xcb-dev libxcb-keysyms1 libxcb-keysyms1-dev libxcb-image0 libxcb-image0-dev libxcb-shm0 libxcb-shm0-dev libxcb-icccm4 libxcb-icccm4-dev libxcb-xfixes0-dev libxrender-dev libxcb-shape0-dev libxcb-randr0-dev libxcb-render-util0 libxcb-render-util0-dev libxcb-glx0-dev libxcb-xinerama0-dev xorg-dev zlib1g-dev
修改qtbase/mkspecs/linux-arm-gnueabi-g++/qmake.conf
#
# qmake configuration for building with arm-linux-gnueabi-g++
#MAKEFILE_GENERATOR = UNIX
CONFIG += incremental
QMAKE_INCREMENTAL_STYLE = sublibQT_QPA_DEFAULT_PLATFORM = linux #eglfs
QMAKE_CFLAGS_RELEASE += -O2 -march=armv7-a
QMAKE_CXXFLAGS_RELEASE += -O2 -march=armv7-ainclude(../common/linux.conf)
include(../common/gcc-base-unix.conf)
include(../common/g++-unix.conf)# modifications to g++.conf
QMAKE_CC = arm-none-linux-gnueabi-gcc
QMAKE_CXX = arm-none-linux-gnueabi-g++
QMAKE_LINK = arm-none-linux-gnueabi-g++
QMAKE_LINK_SHLIB = arm-none-linux-gnueabi-g++# modifications to linux.conf
QMAKE_AR = arm-none-linux-gnueabi-ar cqs
QMAKE_OBJCOPY = arm-none-linux-gnueabi-objcopy
QMAKE_NM = arm-none-linux-gnueabi-nm -P
QMAKE_STRIP = arm-none-linux-gnueabi-strip
load(qt_config)
下面是我的配置脚本
#!/bin/sh./configure \-v \
-prefix /opt/armv7_qt-5.7.0 \
-release \
-opensource \
-make libs \
-xplatform linux-arm-gnueabi-g++ \
-optimized-qmake \
-pch \
-qt-sql-sqlite \
-qt-libjpeg \
-qt-zlib \
-no-opengl \
-skip qt3d \
-skip qtcanvas3d \
-skip qtpurchasing \
-no-sse2 \
-no-openssl \
-no-nis \
-no-cups \
-no-glib \
-no-iconv \
-nomake examples \
-nomake tools \
-skip qtvirtualkeyboard \
-I/usr/local/tslib_v7/include \
-L/usr/local/tslib_v7/lib
exit
这是我的arm环境变量
export TSLIB_ROOT=/opt/tslib1.4
export QT_ROOT=/opt/qt-5.7.0
export TSLIB_TSDEVICE=/dev/input/event2
export TSLIB_TSEVENTTYPE=input
export TSLIB_CONFFILE=/opt/tslib1.4/etc/ts.conf
export TSLIB_PLUGINDIR=/opt/tslib1.4/lib/ts
export TSLIB_CONSOLEDEVICE=none
export TSLIB_FBDEVICE=/dev/fb0
export QWS_MOUSE_PROTO=tslib:/dev/input/event2
export LD_LIBRARY_PATH=/lib:/usr/lib:/usr/local/lib:$QT_ROOT/lib:$TSLIB_ROOT/lib:$TSLIB_ROOT/lib/
export QT_QPA_PLATFORM_PLUGIN_PATH=$QT_ROOT/plugins #很重要
export QT_QPA_PLATFORM=linuxfb:tty=/dev/fb0
export QT_QPA_FONTDIR=$QT_ROOT/lib/fonts
export QT_QPA_GENERIC_PLUGINS=tslib
export QWS_USB_KEYBOARD=/dev/input/event4 #键盘支持
具体编译过程我就不再细说,网上教程很多
http://blog.csdn.net/u012175418/article/details/52704734
完了后在主机配置QT
主要是要指定 交叉编译器的gcc、g++,和qt的qmake
- 驱动移植
对于驱动想法我是 用 内核的usbmouse.c 为模版,进行修改,由于前期在做游戏手柄驱动时遇到技术问题,我暂时改用 鼠标模拟键盘, 左键、右键、中键、pid 键 分别对应 A、D、W、S。用的典型的 usb + input 系统。
主要修改 中断函数
static void usb_mouse_irq(struct urb *urb)
{struct usb_mouse *mouse = urb->context;signed char *data = mouse->data;struct input_dev *dev = mouse->dev;int status;static unsigned char pre_val;char flag = 255;switch (urb->status) {case 0: /* success */break;case -ECONNRESET: /* unlink */case -ENOENT:case -ESHUTDOWN:return;/* -EPIPE: should clear the halt */default: /* error */goto resubmit;}if ((pre_val & (1<<0)) != (data[0] & (1<<0))){/* 左键发生了变化 */printk("L KEY \n");input_event(dev, EV_KEY, KEY_A, (data[0] & (1<<0)) ? 1 : 0);input_sync(dev);}if ((pre_val & (1<<1)) != (data[0] & (1<<1))){/* 右键发生了变化 */input_event(dev, EV_KEY, KEY_D, (data[0] & (1<<1)) ? 1 : 0);input_sync(dev);}if (data[2] == 0x15){/* 中键发生了变化 */input_event(dev, EV_KEY, KEY_W, 1);input_event(dev, EV_KEY, KEY_W, 0);input_sync(dev);}pre_val = data[0];if (data[2] == 0x1f ){//printk("orange down");//pre_val = 0x1f;flag = 's';input_event(dev, EV_KEY, KEY_S, 1);input_event(dev, EV_KEY, KEY_S, 0);input_sync(dev);}
input 的初始化也得改
input_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_REL);/*input_dev->keybit[BIT_WORD(KEY_W)] = BIT_MASK(KEY_A) |BIT_MASK(KEY_D) | BIT_MASK(KEY_S);input_dev->relbit[0] = BIT_MASK(REL_X) | BIT_MASK(REL_Y);input_dev->keybit[BIT_WORD(BTN_MOUSE)] |= BIT_MASK(BTN_SIDE) |BIT_MASK(BTN_EXTRA);input_dev->relbit[0] |= BIT_MASK(REL_WHEEL);*///set_bit(KEY_A, input_dev->keybit);for (i = 0; i < 255; i++)set_bit(usb_kbd_keycode[i], input_dev->keybit);
这里的usb_kbd_key_code 是借用usb键盘的代码。
附上测试视屏 (在文章底部,这是我的另一个博客)
欢迎大家留言提问交流