CSDN仅用于增加百度收录权重,排版未优化,日常不维护。请访问:www.hceng.cn 查看、评论。
本博文对应地址: https://hceng.cn/2017/05/26/移植MiniGUI到JZ2440/#more
尝试将MiniGUI到JZ2440上。
移植所需文件:
文件包名 | 作用 |
---|---|
libminigui-1.6.10.tar.gz | MiniGUI开发库 |
minigui-res-1.6.10.tar.gz | MiniGUI资源文件 |
mg-samples-1.6.10.tar.gz | MiniGUI示例程序 |
tslib-1.4.tar.gz | 触摸屏功能 |
1.移植MiniGUI
1.1 解压、编译MiniGUI开发库
{% codeblock lang:shell%}
tar xzf libminigui-1.6.10.tar.gz
cd libminigui-1.6.10/
mkdir tmp
./configure CC=arm-linux-gcc --prefix=${PWD}/tmp --build=i386-linux --host=arm-linux --target=arm-linux
make
make install
{% endcodeblock %}
完成上面操作,即可在tmp目录下生成以下文件:
将生成的/lib下所有文件(和共享库相关)拷贝到开发板/lib目录下,将生成的/etc下的MiniGUI.cfg也拷贝到开发板/etc目录下:
{% codeblock lang:shell%}
cp –rfd ./lib/* /work/hceng/nfs_rootfs/lib
cp ./etc/* /work/hceng/nfs_rootfs/etc
{% endcodeblock %}
1.2 解压MiniGUI资源文件
{% codeblock lang:shell%}
tar xzf minigui-res-1.6.10.tar.gz
cd minigui-res-1.6.10/
{% endcodeblock %}
修改config.linux,指定生成文件路径:
编译生成:
{% codeblock lang:shell%}
make install
{% endcodeblock %}
此时会在指定的/tmp目录下生成以下文件:
这些文件包含了MiniGUI会使用到的资源,包括基本字体、图标、位图和鼠标光标等,
将这些文件全部复制到开发板的/usr/local/lib/minigui/res/路径下,这个路径是前面MiniGUI.cfg指定的。
1.3 编译MiniGUI示例程序
解压、配置、编译:
{% codeblock lang:shell%}
tar xzf mg-samples-1.6.10.tar.gz
cd mg-samples-1.6.10.tar.gz/
./configure CC=arm-linux-gcc --build=i386-linux --host=arm-linux -target=arm-linux CFLAGS=-I/work/minigui/libminigui-1.6.10/tmp/include LDFLAGS=-L/work/minigui/libminigui-1.6.10/tmp/lib
make
make install
{% endcodeblock %}
此时会在/src目录下生成示例程序:
复制示例程序到开发板里面去,注意有些程序需要本目录下的图片文件,需要一同拷贝过去。这里以helloworld为例:
{% codeblock lang:shell%}
cp helloworld /work/hceng/nfs_rootfs/
{% endcodeblock %}
1.4 其他修改
- 修改前面复制到开发板/etc目录下的MiniGUI.cfg以适应JZ2440。
- 在开发板的/etc目录下建立ld.so.conf文件,并添加如下内容:
{% codeblock lang:shell%}
/usr/local/lib
/usr/lib
/lib
{% endcodeblock %} - 在/etc/init.d/rcS脚本文件里添加如下内容(非必需):
{% codeblock lang:shell%}
/bin/ln –s /dev/vc/0 /dev/tty0
{% endcodeblock %}
移植MiniGUI完成,运行应用程序:
2.移植tslib
2.1 安装一些工具
{% codeblock lang:shell%}
sudo apt-get install autoconf
sudo apt-get install automake
sudo apt-get install libtool
{% endcodeblock %}
2.2 解压、编译
{% codeblock lang:shell%}
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
{% endcodeblock %}
2.3 安装
{% codeblock lang:shell%}
cd tmp
cp * -rfd /work/hceng/nfs_rootfs
{% endcodeblock %}
2.4 修改/etc/ts.conf第1行(去掉#号和第一个空格)
{% codeblock lang:shell%}
module_raw input
{% endcodeblock %}
改为:
{% codeblock lang:shell%}
module_raw input
{% endcodeblock %}
2.5 在开发板设置环境变量
{% codeblock lang:shell%}
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
{% endcodeblock %}
2.6 运行校准示例程序
{% codeblock lang:shell%}
ts_calibrate
{% endcodeblock %}
如果在运行程序的时候,出现提示:
{% codeblock lang:shell%}
selected device is not a touchscreen I understand
{% endcodeblock %}
有显示,但无法触屏,可能是编译器版本和内核版本不一致,解决方法如下:
修改编译器的input.h:
{% codeblock lang:shell%}
cd /usr/local/arm/4.3.2/arm-none-linux-gnueabi/libc/usr/include/linux
sudo vim input.h
{% endcodeblock %}
将
{% codeblock lang:c%}
#define EV_VERSION 0x010000
{% endcodeblock %}
改为:
{% codeblock lang:c%}
#define EV_VERSION 0x010001
{% endcodeblock %}
重新进行前面的编译即可,编译后,记得改回编译器的版本。
3.MiniGUI和tslib链接
此时虽然分别移植好了MiniGUI和tslib,但触屏并不能正常的控制GUI,需要进行将
MiniGUI和tslib进行链接。
- 使用MiniGUI 的 IAL 引擎,修改/libminigui-1.6.10/src/ial/下的dummy.c成如下:
{% codeblock lang:c%}
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include “common.h”
#include “tslib.h”
#ifdef _DUMMY_IAL
#include <sys/ioctl.h>
#include <sys/poll.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <linux/kd.h>
#include “ial.h”
#include “dummy.h”
#ifndef _DEBUG
#define _DEBUG // for debugging
#endif
/* for storing data reading from /dev/touchScreen/0raw */
typedef struct {
unsigned short pressure;
unsigned short x;
unsigned short y;
unsigned short pad;
} TS_EVENT;
static unsigned char state [NR_KEYS];
static int mousex = 0;
static int mousey = 0;
static TS_EVENT ts_event;
static struct tsdev *ts;
/************************ Low Level Input Operations *********************/
/
- Mouse operations – Event
*/
static int mouse_update(void)
{
return 1;
}
static void mouse_getxy(int x, int y)
{
if (mousex < 0) mousex = 0;
if (mousey < 0) mousey = 0;
if (mousex > 639) mousex = 639;
if (mousey > 479) mousey = 479;
#ifdef _DEBUG
// printf (“mousex = %d, mousey = %d/n”, mousex, mousey);
#endif
*x = mousex;
*y = mousey;
}
static int mouse_getbutton(void)
{
return ts_event.pressure;
}
#ifdef _LITE_VERSION
static int wait_event (int which, int maxfd, fd_set *in, fd_set *out, fd_set *except,
struct timeval *timeout)
#else
static int wait_event (int which, fd_set *in, fd_set *out, fd_set *except,
struct timeval *timeout)
#endif
{
struct ts_sample sample;
int ret = 0;
int fd;
fd_set rfds;
int e;
if (!in) {
in = &rfds;
FD_ZERO (in);
}
fd = ts_fd(ts);
if ((which & IAL_MOUSEEVENT) && fd >= 0) {
FD_SET (fd, in);
#ifdef _LITE_VERSION
if (fd > maxfd) maxfd = fd;
#endif
}
#ifdef _LITE_VERSION
e = select (maxfd + 1, in, out, except, timeout) ;
#else
e = select (FD_SETSIZE, in, out, except, timeout) ;
#endif
if (e > 0) {
// input events is coming
if (fd > 0 && FD_ISSET (fd, in)) {
FD_CLR (fd, in);
ts_event.x=0;
ts_event.y=0;
ret = ts_read(ts, &sample, 1);
if (ret < 0) {
perror("ts_read()");
exit(-1);
}
ts_event.x = sample.x;
ts_event.y = sample.y;
ts_event.pressure = (sample.pressure > 0 ? 4:0);
// if (ts_event.pressure > 0 &&
if((ts_event.x >= 0 && ts_event.x <= 639) &&
(ts_event.y >= 0 && ts_event.y <= 479)) {
mousex = ts_event.x;
mousey = ts_event.y;
// printf("ts_event.x is %d, ts_event.y is %d------------------------------------->/n",ts_event.x ,ts_event.y);
}
//#ifdef _DEBUG
// if (ts_event.pressure > 0) {
// printf (“mouse down: ts_event.x = %d, ts_event.y = %d,ts_event.pressure = %d/n”,ts_event.x,ts_event.y,ts_event.pressure);
// }
//#endif
ret |= IAL_MOUSEEVENT;
return (ret);
}
}
else if (e < 0) {
return -1;
}
return (ret);
}BOOL InitDummyInput(INPUT* input, const char* mdev, const char* mtype)
{
char *ts_device = NULL;
if ((ts_device = getenv("TSLIB_TSDEVICE")) != NULL) {
// open touch screen event device in blocking mode
ts = ts_open(ts_device, 0);
} else {
#ifdef USE_INPUT_API
ts = ts_open("/dev/input/0raw", 0);
#else
ts = ts_open("/dev/touchscreen/ucb1x00", 0);
#endif
}
#ifdef _DEBUG
printf (“TSLIB_TSDEVICE is open!!!/n”);
#endif
if (!ts) {
perror(“ts_open()”);
exit(-1);
}
if (ts_config(ts)) {
perror("ts_config()");
exit(-1);
}
input->update_mouse = mouse_update;
input->get_mouse_xy = mouse_getxy;
input->set_mouse_xy = NULL;
input->get_mouse_button = mouse_getbutton;
input->set_mouse_range = NULL;
input->wait_event = wait_event;
mousex = 0;
mousey = 0;
ts_event.x = ts_event.y = ts_event.pressure = 0;
return TRUE;
}
void TermDummyInput(void)
{
if (ts)
ts_close(ts);
}
#endif /* _DUMMY_IAL */
{% endcodeblock %}
-
指定tslib 相关的头文件和共享库文件重新编译libminigui:
{% codeblock lang:shell%}
cd /work/minigui/libminigui-1.6.10/
./configure CC=arm-linux-gcc --prefix=${PWD}/tmp --build=i386-linux --host=arm-linux --target=arm-linux CFLAGS="-I/work/minigui/tslib/tmp/include -L/work/minigui/tslib/tmp/lib -lts"
{% endcodeblock %}
将新生成的/tmp/lib下的文件覆盖掉开发板原来的文件:
{% codeblock lang:shell%}
cp –rfd ./lib/* /work/hceng/nfs_rootfs/lib
{% endcodeblock %} -
因为共享文件变了,这里重新编译示例程序libminigui:
{% codeblock lang:shell%}
./configure CC=arm-linux-gcc --build=i386-linux --host=arm-linux -target=arm-linux CFLAGS=-I/work/minigui/libminigui-1.6.10/tmp/include LDFLAGS=-L/work/minigui/libminigui-1.6.10/tmp/lib
{% endcodeblock %}
再将生成的应用程序复制到开发板重新运行:
{% codeblock lang:shell%}
cp painter /work/hceng/nfs_rootfs/
{% endcodeblock %}
在开发板运行:
{% codeblock lang:shell%}
./ painter
{% endcodeblock %}