我们基于Framebuffer对板载的小屏幕进行显示测试,
代码如下
#include <unistd.h>
#include <stdio.h>
#include <fcntl.h>
#include <linux/fb.h>
#include <sys/mman.h>
#include <stdlib.h>
#include <string.h>
#define RED 0xF800
#define YELLOW 0xFFE0
#define BLUE 0x001F
#define WHITE 0xFFFF
#define BLACK 0x0000
void fill_color16(short *fb_addr, short bit_map, int psize)
{
int i;
for(i=0; i<psize; i++) {
*fb_addr = bit_map;
fb_addr++;
}
}
int main ()
{
int fp=0;
struct fb_var_screeninfo vinfo;
struct fb_fix_screeninfo finfo;
long screensize=0;
char *fbp = NULL, *test_fbp=NULL;
int x = 0, y = 0;
long location = 0;
int i;
int num = 5;
int pix_size=0;
fp = open("/dev/fb1", O_RDWR);
if(fp < 0) {
printf("Error : Can not open framebuffer device/n");
exit(1);
}
if(ioctl(fp, FBIOGET_FSCREENINFO, &finfo)){
printf("Error reading fixed information/n");
exit(2);
}
if(ioctl(fp, FBIOGET_VSCREENINFO, &vinfo)){
printf("Error reading variable information/n");
exit(3);
}
screensize = vinfo.xres * vinfo.yres * vinfo.bits_per_pixel / 8;
printf("The phy mem = 0x%x, total size = %d(byte)\n", finfo.smem_start, finfo.smem_len);
printf("xres = %d, yres = %d, bits_per_pixel = %d\n", vinfo.xres, vinfo.yres, vinfo.bits_per_pixel);
printf("So the screensize = %d(byte), using %d frame\n", screensize, finfo.smem_len/screensize);
printf("vinfo.xoffset = %d, vinfo.yoffset = %d\n", vinfo.xoffset, vinfo.yoffset);
printf("vinfo.vmode is :%d\n", vinfo.vmode);
printf("finfo.ypanstep is :%d\n", finfo.ypanstep);
printf("vinfo.red.offset=0x%x\n", vinfo.red.offset);
printf("vinfo.red.length=0x%x\n", vinfo.red.length);
printf("vinfo.green.offset=0x%x\n", vinfo.green.offset);
printf("vinfo.green.length=0x%x\n", vinfo.green.length);
printf("vinfo.blue.offset=0x%x\n", vinfo.blue.offset);
printf("vinfo.blue.length=0x%x\n", vinfo.blue.length);
printf("vinfo.transp.offset=0x%x\n", vinfo.transp.offset);
printf("vinfo.transp.length=0x%x\n", vinfo.transp.length);
fbp =(char *)mmap(0, screensize, PROT_READ | PROT_WRITE, MAP_SHARED, fp,0);
if ((int)fbp == -1)
{
printf ("Error: failed to map framebuffer device to memory./n");
exit (4);
}
printf("Get virt mem = %p\n", fbp);
pix_size = vinfo.xres * vinfo.yres;
/* using first frame, for FBIOPAN_DISPLAY
* 当刷新需要调用FBIOPAN_DISPLAY, 要告知驱动刷哪块帧, 用到下面两个参数
* 如果使用第二帧buffer -> vinfo.xoffset = 0; vinfo.yoffset = vinfo.yres;
*/
vinfo.xoffset = 0;
vinfo.yoffset = 0;
/* show color loop */
while(num--) {
printf("\ndrawing YELLOW......\n");
fill_color16((short *)fbp, YELLOW, pix_size);
//ioctl(fp, FBIOPAN_DISPLAY, &vinfo);
sleep(3);
printf("\ndrawing BLUE......\n");
fill_color16((short *)fbp, BLUE, pix_size);
//ioctl(fp, FBIOPAN_DISPLAY, &vinfo);
sleep(3);
printf("\ndrawing RED......\n");
fill_color16((short *)fbp, RED, pix_size);
//ioctl(fp, FBIOPAN_DISPLAY, &vinfo);
sleep(3);
}
#if 1
/*这是你想画的点的位置坐标,(0,0)点在屏幕左上角*/
x = 10;
y = 10;
location = x * (vinfo.bits_per_pixel / 8) + y * finfo.line_length;
test_fbp = fbp + location;
printf("draw line.......\n");
for(i = 0; i < (vinfo.xres - x); i++)
*test_fbp++ = i+30;
//ioctl(fp, FBIOPAN_DISPLAY, &vinfo);
#endif
munmap(fbp, screensize); /*解除映射*/
close (fp);
return 0;
}
编译
gcc fb.c -o fb
运行
./fb
测试效果见视频
TFT已经坏了,等买快新的再试一下
测试效果见视频
TFT已经坏了,等买快新的再试一下
这么容易就挂吗?