ARM40-A5应用程序——液晶屏触摸屏测试程序
2018.02.03
版权声明:本文为博主原创文章,允许转载。
一、在 shell 中的简单测试
(1) cat /dev/urandom > /dev/fb0 // 显示雪花屏
(2) cat /dev/zero > /dev/fb0 // 显示黑屏
(3) ts_calibrate // 触摸屏校准
(4) ts_test // 触摸屏测试
硬件上需要确保液晶屏背光已打开;触摸屏也可能需要配置环境变量,例如:export TSLIB_TSDEVICE=/dev/input/event0。
二、液晶屏测试程序的C语言源码
如果液晶屏接线为rgb888 (ARM40-A5中即为rgb888),文件名为 test_lcd.c,代码见本文的最后附(1)。
如果液晶屏接线为rgb666 (例如imx6中,将lvds0配置为18bit),文件名为 test_lcd_rgb666.c,代码见本文的最后附(2)。
如果液晶屏接线为rgb565,文件名为 test_lcd_rgb565.c,代码见本文的最后附(3)。
三、交叉编译
arm-none-linux-gnueabi-gcc -o test_lcd test_lcd.c
四、执行程序
将交叉编译得到的 test_lcd 文件拷贝到ARM40-A5板中,执行程序:
./test_lcd
可以观察到液晶屏上红、绿、蓝的显示变换,且shell中会打印出(示例):
vinfo.xres=800,vinfo.yres=480,vinfo.bits_per_pixel=24,screensize=1152000
finfo.line_length=2400,vinfo.bits_per_pixel=24
如果是 ./test_lcd_rgb666,打印(示例):
vinfo.xres=800,vinfo.yres=600,vinfo.bits_per_pixel=16,screensize=960000
finfo.line_length=1600,vinfo.bits_per_pixel=16
接线为rgb888,test_lcd_rgb666 也可以运行,只是颜色不符。
参考文章:
http://blog.csdn.net/TECH_PRO/article/details/73320927?fps=1&locationNum=9
基于嵌入式Linux的LCD液晶点阵显示的基本实现
http://blog.csdn.net/luxiaoxun/article/details/7622988
Linux framebuffer显示bmp图片
http://blog.chinaunix.net/uid-22666248-id-284768.html
framebuffer小程序显示3个矩形 测试 (六)
https://gist.github.com/rafalrusin/1482697
Linux Frame Buffer Test
https://android.googlesource.com/platform/system/extras/+/donut-release/tests/framebuffer/fb_test.c
fb_test.c
荟聚计划:共商 共建 共享 Grant
附:
(1)test_lcd.c 的代码
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/mman.h>
#include <linux/fb.h>
char *fbp = NULL;
struct fb_var_screeninfo vinfo;
struct fb_fix_screeninfo finfo;
typedef struct color {
char blue;
char green;
char red;
} COLOR;
COLOR black = {0, 0, 0};
COLOR white = {255, 255, 255};
COLOR blue255 = {255, 0, 0};
COLOR green255 = {0, 255, 0};
COLOR red255 = {0, 0, 255};
void display(int x1, int y1, int x2, int y2, struct color rgb);
int main (void)
{
int fd;
unsigned long screensize = 0;
int x,y;
int ret;
fd = open("/dev/fb0", O_RDWR);
if (fd < 0){
fprintf(stderr, "error open fb0\n");
return -1;
}
ret= ioctl(fd, FBIOGET_FSCREENINFO, &finfo ) ;
if (ret < 0) {
fprintf(stderr, "get fixed screen info error\n");
return -1;
}
ret = ioctl(fd, FBIOGET_VSCREENINFO, &vinfo);
if (ret < 0) {
fprintf(stderr, "get variable screen info error\n");
return -1;
}
ret = ioctl(fd, FBIOPAN_DISPLAY,&vinfo);
if (ret < 0) {
fprintf(stderr, "pan display failed, %d\n", ret);
return -1;
}
screensize=vinfo.xres * vinfo.yres * vinfo.bits_per_pixel/8;
printf("vinfo.xres=%d,vinfo.yres=%d,vinfo.bits_per_pixel=%d,screensize=%ld\n",
vinfo.xres,vinfo.yres,vinfo.bits_per_pixel,screensize);
printf("finfo.line_length=%d,vinfo.bits_per_pixel=%d\n", finfo.line_length,vinfo.bits_per_pixel);
fbp = (char *)mmap(NULL, screensize, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);
if (fbp == MAP_FAILED) {
fprintf(stderr, "mapped error\n");
return -1;
}
while(1) {
display(0, 0, vinfo.xres, vinfo.yres, white);
sleep(1);
display(0, 0, vinfo.xres, vinfo.yres, black);
display(0, 0, 3, 3, red255);
display(vinfo.xres-3, 0, vinfo.xres, 3, red255);
display(vinfo.xres-3, vinfo.yres-3, vinfo.xres, vinfo.yres, blue255);
display(0, vinfo.yres-3, 3, vinfo.yres, blue255);
sleep(3);
display(0, 0, 30, 30, red255);
display(30, 30, vinfo.xres-30, vinfo.yres-30, blue255);
display(60, 60, vinfo.xres-60, vinfo.yres-60, green255);
display(90, 90, vinfo.xres-90, vinfo.yres-90, red255);
sleep(1);
display(0, 0, vinfo.xres, vinfo.yres/3, red255);
display(0, vinfo.yres/3, vinfo.xres, vinfo.yres*2/3, green255);
display(0, vinfo.yres*2/3, vinfo.xres, vinfo.yres, blue255);
sleep(1);
display(0, 0, vinfo.xres/3, vinfo.yres, red255);
display(vinfo.xres/3, 0, vinfo.xres*2/3, vinfo.yres, green255);
display(vinfo.xres*2/3, 0, vinfo.xres, vinfo.yres, blue255);
sleep(1);
display(0, 0, vinfo.xres, vinfo.yres, red255);
sleep(1);
display(0, 0, vinfo.xres, vinfo.yres, green255);
sleep(1);
display(0, 0, vinfo.xres, vinfo.yres, blue255);
sleep(1);
}
munmap(fbp,screensize);
close(fd);
return 0;
}
void display(int x1, int y1, int x2, int y2, struct color rgb)
{
int x=0,y=0;
for(y = y1; y < y2; y++){
for(x = x1; x < x2; x++) {
char *tmp_ptr = fbp +
(x+vinfo.xoffset) * (vinfo.bits_per_pixel >> 3) +
(y+vinfo.yoffset) * finfo.line_length;
* tmp_ptr++ = rgb.blue;
* tmp_ptr++ = rgb.green;
* tmp_ptr++ = rgb.red;
}
}
}
(2)test_lcd_rgb666.c 的代码(仅给出不同的部分)
void display(int x1, int y1, int x2, int y2, struct color rgb)
{
int x=0,y=0;
for(y = y1; y < y2; y++){
for(x = x1; x < x2; x++) {
char *tmp_ptr = fbp +
(x+vinfo.xoffset) * (vinfo.bits_per_pixel >> 3) +
(y+vinfo.yoffset) * finfo.line_length;
unsigned short int t = (rgb.red << 12) | (rgb.green << 6) | rgb.blue;
*((unsigned short int *)tmp_ptr) = t;
}
}
}
(3)test_lcd_rgb565.c 的代码(仅给出不同的部分)
void display(int x1, int y1, int x2, int y2, struct color rgb)
{
int x=0,y=0;
for(y = y1; y < y2; y++){
for(x = x1; x < x2; x++) {
char *tmp_ptr = fbp +
(x+vinfo.xoffset) * (vinfo.bits_per_pixel >> 3) +
(y+vinfo.yoffset) * finfo.line_length;
unsigned short int t = (rgb.red << 11) | (rgb.green << 5) | rgb.blue;
*((unsigned short int *)tmp_ptr) = t;
}
}
}