编译helloworld测试,暂略。
如果有问题,查看嵌入式linux库版本strings /usr/lib/libstdc++.so.6 | grep GLIBCXX
查看/lib目录动态链接库加载器版本
用file检查比对编译的执行文件区别
在tslib-1.4源代码目录建立文件compilerconf.sh内容如下:
#!/bin/sh
./autogen.sh
make clean && make distclean
echo "ac_cv_func_malloc_0_nonnull=yes" >arm-linux.cache
./configure --host=arm-linux --prefix=/opt/tslib1.4 --cache-file=arm-linux.cache \
CC=/home/toolchain/v7-toolchain/bin/arm-linux-gnueabi-gcc
make && make install
–host=arm-linux,目标环境为arm版本linux
–prefix=/opt/tslib1.4,用于指定make install安装目录
CC=/home/toolchain/v7-toolchain/bin/arm-linux-gnueabi-gcc,用于指定嵌入式linux目标环境交叉编译工具,需要根据自己的开发版或目标环境确认。
在/etc/profile增加如下配置
export TSLIB_ROOT=/opt/tslib1.4
export TSLIB_TSDEVICE=/dev/input/event0
export TSLIB_FBDEVICE=/dev/fb0
export TSLIB_CONFFILE=$TSLIB_ROOT/etc/ts.conf
export TSLIB_PLUGINDIR=$TSLIB_ROOT/lib/ts
export TSLIB_CALIBFILE=$TSLIB_ROOT/etc/pointercal
export TSLIB_CONSOLEDEVICE=none
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$TSLIB_ROOT/lib
TSLIB_ROOT指定更目录,更具目标开发版自行决定。
TSLIB_TSDEVICE指定触控出入硬件,在/dev目录查找,可用cat /dev/input/event0测试,测试时点击触摸屏终端有数据显示说明测试通过。
TSLIB_FBDEVICE指定framebuff
TSLIB_CONFFILE指定配置文件
TSLIB_PLUGINDIR指定触摸屏插件所在路径
TSLIB_CALIBFILE指定标定文件
TSLIB_CONSOLEDEVICE设定控制台设备为none
LD_LIBRARY_PATH更新加载库路径
参考:tslib移植中环境变量编辑
执行如下代码更新环境变量,或重启
source /etc/profile
用export指令查看环境变量是否更新
export
用如下代码测试/dev/fb0是否正常工作
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <sys/mman.h>
#include <linux/fb.h>
#define COLOR24_RED 0x000000FF
#define COLOR24_GREEN 0x0000FF00
#define COLOR24_BLUE 0x00FF0000
#define COLOR32_RED 0xFF0000FF
#define COLOR32_GREEN 0xFF00FF00
#define COLOR32_BLUE 0xFFFF0000
int fdfb = -1;
struct fb_fix_screeninfo fbfix = { 0 };
struct fb_var_screeninfo fbvar = { 0 };
long screensize = 0;
int *fb32 = NULL;
int x = 0;
int y = 0;
long location = 0;
int main(int argc, char **argv)
{
unsigned long c_red=COLOR24_RED;
unsigned long c_green=COLOR24_GREEN;
unsigned long c_blue=COLOR24_BLUE;
// open framebuffer device
if(argc==1)
{
fdfb = open( "/dev/fb0", O_RDWR );
if( 0 > fdfb ) {
printf("Failure to open framebuffer device: /dev/fb0 !\n");
exit( -1 );
}
printf("Success to open framebuffer device: /dev/fb0 !\n");
}
else
{
fdfb = open( argv[1], O_RDWR );
if( 0 > fdfb ) {
printf("Failure to open framebuffer device: %s !\n",argv[1]);
exit( -1 );
}
printf("Success to open framebuffer device: %s !\n",argv[1]);
}
// get fixed screen information
if( ioctl( fdfb, FBIOGET_FSCREENINFO, &fbfix ) ) {
printf("Failure to get fixed screen information !\n");
exit( -2 );
}
printf("Success to get fixed screen information !\n");
// get varible screen information
if( ioctl( fdfb, FBIOGET_VSCREENINFO, &fbvar ) ) {
printf("Failure to get varible screen information !\n");
exit( -3 );
}
printf("Success to get varible screen information !\n");
// calculate the number of bytes for screen size
screensize = fbvar.xres * fbvar.yres * ( fbvar.bits_per_pixel / 8 );
printf("sceeninfo.xres = %d, screeninfo.yres = %d, screeninfo.bits_per_pixel = %dbpp, screensize = %d !\n", fbvar.xres, fbvar.yres, fbvar.bits_per_pixel, screensize);
// mmap framebuffer to process memory space
fb32 = (int *)mmap( 0, screensize, PROT_READ | PROT_WRITE, MAP_SHARED, fdfb, 0 );
if( NULL == fb32 ) {
printf("Failure to map framebuffer device memory to process's memory !\n");
exit( -4 );
}
printf("Success to map framebuffer device memory to process's memory !\n");
// draw pixel
if( 8 == fbvar.bits_per_pixel ) {
printf("Starting 8 bpp framebuffer test...\n");
}
else if( 16 == fbvar.bits_per_pixel ) {
printf("Starting 16 bpp framebuffer test...\n");
}
else if( 24 == fbvar.bits_per_pixel ) {
c_red=COLOR24_RED;
c_green=COLOR24_GREEN;
c_blue=COLOR24_BLUE;
printf("Starting 24 bpp framebuffer test...\n");
}
else{
c_red=COLOR32_RED;
c_green=COLOR32_GREEN;
c_blue=COLOR32_BLUE;
printf("Supporting 32 bpp !\n");
}
// draw red color area
printf("Starting to show RED area !\n");
for( y = 0; y < fbvar.yres / 3; y++ ) {
for( x = 0; x < fbvar.xres; x++ ) {
*( fb32 + y * fbvar.xres + x ) = c_red;
}
}
getchar();
// draw green color area
printf("Starting to show GREEN area !\n");
for( y = ( fbvar.yres / 3 ); y < ( fbvar.yres * 2 / 3); y++ ) {
for( x = 0; x < fbvar.xres; x++ ) {
*( fb32 + y * fbvar.xres + x ) = c_green;
}
}
getchar();
// draw blue color area
printf("Starting to show BLUE area !\n");
for( y = ( fbvar.yres * 2 / 3 ); y < fbvar.yres; y++ ) {
for( x = 0; x < fbvar.xres; x++ ) {
*( fb32 + y * fbvar.xres + x ) = c_blue;
}
}
getchar();
// unmap framebuffer memory
munmap( fb32, screensize );
printf("Finished to demo to operate framebuffer !\n");
// close device handle
close( fdfb );
return 0;
}
编译指令,根据自己交叉工具链更改
/home/toolchain/v7-toolchain/bin/arm-linux-gnueabi-gcc fb_test.c -o fb_test
目标板执行,注意添加可执行权限,chmod 777 ./fb_test
fb_test /dev/fb0
默认/dev/fb0可不用带参数,依次填充3蓝绿红三种颜色,按回车继续。
目标版执行结果如下:
Success to open framebuffer device: /dev/fb0 !
Success to get fixed screen information !
Success to get varible screen information !
sceeninfo.xres = 800, screeninfo.yres = 480, screeninfo.bits_per_pixel = 32bpp, screensize = 1536000 !
Success to map framebuffer device memory to process's memory !
Supporting 32 bpp !
Starting to show RED area !
Starting to show GREEN area !
Starting to show BLUE area !
Finished to demo to operate framebuffer !
Success to open framebuffer device: /dev/fb0 !
Success to get fixed screen information !
Success to get varible screen information !
sceeninfo.xres = 800, screeninfo.yres = 480, screeninfo.bits_per_pixel = 32bpp, screensize = 1536000 !
Success to map framebuffer device memory to process's memory !
Supporting 32 bpp !
Starting to show RED area !
Starting to show GREEN area !
Starting to show BLUE area !
Finished to demo to operate framebuffer
一开始目标板不正常工作,填充颜色都是黑色,查看screeninfo.bits_per_pixel = 32bpp, 目标版采用的32位颜色,更改测试代码如上,目标版工作正常。
tslib1.4也应当是只支持24位颜色,不支持32位颜色。开始调整tslib1.4代码。
注意32位颜色值一般这样分配:X8位,R8位,G8位,B8位或A8位,R8位,G8位,B8位。
参考:计算机颜色格式( 8位 16位 24位 32位色)
分析tslib代码,发现设置颜色函数为
static inline void __setpixel (union multiptr loc, unsigned xormode, unsigned color)
{
switch(bytes_per_pixel) {
case 1:
default:
if (xormode)
*loc.p8 ^= color;
else
*loc.p8 = color;
break;
case 2:
if (xormode)
*loc.p16 ^= color;
else
*loc.p16 = color;
break;
case 4:
if (xormode)
*loc.p32 ^= color;
else
*loc.p32 = color;
break;
}
}
修改为如下代码:
static inline void __setpixel (union multiptr loc, unsigned xormode, unsigned color)
{
switch(bytes_per_pixel) {
case 1:
default:
if (xormode)
*loc.p8 ^= color;
else
*loc.p8 = color;
break;
case 2:
if (xormode)
*loc.p16 ^= color;
else
*loc.p16 = color;
break;
case 4:
//if (xormode)
// *loc.p32 ^= color;
//else
// *loc.p32 = color;
//break;
if (xormode)
*loc.p32 =(*loc.p32^color)|0xff000000;
else
*loc.p32 = color|0xff000000;
break;
}
}
透明度置为0xff,24色直接赋值到32位色缺少了透明度数据,此时透明度数据是0,颜色或上0xff000000设置为不透明显示,重新编译,目标板测试,正常。
具体在ts_calibrate.c文件main函数
原代码:
if ((calfile = getenv("TSLIB_CALIBFILE")) != NULL) {
cal_fd = open (calfile, O_CREAT | O_RDWR);
} else {
cal_fd = open ("/etc/pointercal", O_CREAT | O_RDWR);
}
调整后代码:
if ((calfile = getenv("TSLIB_CALIBFILE")) != NULL) {
cal_fd = open (calfile, O_CREAT | O_RDWR,0777);
} else {
cal_fd = open ("/etc/pointercal", O_CREAT | O_RDWR,0777);
}
ssh和sftp访问工具推荐Remmina,使用简单方便。如果有更好的软件大家相互交流下。