|
/*********************************************************************************
|
* Copyright: (C) 2021 Guo Wenxue<Email:guowenxue@gmail.com QQ:281143292>
|
* All rights reserved.
|
*
|
* Filename: test_key.c
|
* Description: This file used to test GPIO button driver builtin Linux kernel on ARM board
|
*
|
* Version: 1.0.0(11/17/2021~)
|
* Author: Guo Wenxue <guowenxue@gmail.com>
|
* ChangeLog: 1, Release initial version on "11/17/2021 02:46:18 PM"
|
*
|
* Linux Clear LCD screen command :
|
*
|
* dd if=/dev/zero of=/dev/fb0 bs=320 count=720 [ 240*(24bpp/8)=720 ]
|
*
|
********************************************************************************/
|
|
#include <unistd.h>
|
#include <stdio.h>
|
#include <fcntl.h>
|
#include <linux/fb.h>
|
#include <sys/mman.h>
|
#include <stdlib.h>
|
#include <string.h>
|
#include <sys/ioctl.h>
|
|
|
#define CONFIG_RGB565
|
|
#ifdef CONFIG_RGB565 /* RRRR RGGG GGGB BBBB */
|
#define RED 0xF800
|
#define GREEN 0x07E0
|
#define BLUE 0x001F
|
#define YELLOW 0xFFE0
|
#define WHITE 0xFFFF
|
#endif
|
|
|
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/fb0", 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 red ...\n");
|
fill_color16((short *)fbp, RED, pix_size);
|
//ioctl(fp, FBIOPAN_DISPLAY, &vinfo);
|
sleep(3);
|
|
printf("\ndrawing green ...\n");
|
fill_color16((short *)fbp, GREEN, 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 yellow ...\n");
|
fill_color16((short *)fbp, YELLOW, 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;
|
}
|