您尚未登录。

楼主 # 2023-03-16 20:31:24

mrcong
会员
注册时间: 2020-08-11
已发帖子: 10
积分: 5

歪朵拉R3 F1C1200s 利用/dev/fb0刷新屏幕感觉速度也不快是哪里做错了嘛

歪朵拉R3 F1C1200s 利用/dev/fb0刷新屏幕感觉速度也不快是哪里做错了嘛

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <pthread.h>

#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <unistd.h>


//bool define
#define TRUE 1
#define FALSE 0

/* lcd 操作相关 头文件 */
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <linux/fb.h>
#include <sys/ioctl.h>
#include <unistd.h>
#include <string.h>
#include <sys/mman.h>
#include <termios.h>

#include <fcntl.h>



#ifndef DWORD
typedef unsigned long  DWORD;
#endif /* !DWORD */

#ifndef WORD
typedef unsigned short WORD;
#endif /* !WORD */



static int fb_fd = -1;
static unsigned char *fb_mem;
static int px_width;
static int line_width;
static int screen_width;
static int lcd_width;
static int lcd_height;
static struct fb_var_screeninfo var;


static int lcd_fb_display_px(WORD color, int x, int y)
{
	WORD *pen16;
	unsigned char r, g, b;
	r = ((color >> 10) & 0x1f);
	g = ((color >> 5) & 0x3f);
	b = (color & 0x1f);

	color = r<<11|g<<6|b;
	pen16 = (WORD *)(fb_mem + y*line_width + x*px_width);
	*pen16 = color;
	return 0;
}


static int lcd_fb_init()
{
	//如果使用 mmap 打开方式 必须是 读写方式
	fb_fd = open("/dev/fb0", O_RDWR);
	if(-1 == fb_fd)
	{
		printf("cat't open /dev/fb0 \n");
		return -1;
	}
	//获取屏幕参数
	if(-1 == ioctl(fb_fd, FBIOGET_VSCREENINFO, &var))
	{
		close(fb_fd);
		printf("cat't ioctl /dev/fb0 \n");
		return -1;
	}
	
	//计算参数
	px_width     = var.bits_per_pixel /8;
	line_width   = var.xres * px_width;
	screen_width = var.yres * line_width;
	lcd_width    = var.xres;
	lcd_height   = var.yres;
	
	printf("fb width:%d height:%d pixel:%d \n", lcd_width, lcd_height,px_width*8);

	fb_mem = (unsigned char *)mmap(NULL, screen_width, PROT_READ | PROT_WRITE, MAP_SHARED, fb_fd, 0);
	if(fb_mem == (void *)-1)
	{
		close(fb_fd);
		printf("cat't mmap /dev/fb0 \n");
		return -1;
	}
	//清屏
	memset(fb_mem, 0 , screen_width);
	return 0;
}



int main( int argc, char **argv )
{
	lcd_fb_init();
	
	//主循环中处理输入事件 声音播放
	int x,y =0;
	int color = 100;
	while(1)
	{
		for(color=0;color<65535;color++){
			for(x=0;x<800;x++){
			for(y=0;y<480;y++){
				lcd_fb_display_px(color,x,y);
			}
		}
		color+=10;
		}
		
		
	}
	return(0);
}

离线

页脚

工信部备案:粤ICP备20025096号 Powered by FluxBB

感谢为中文互联网持续输出优质内容的各位老铁们。 QQ: 516333132, 微信(wechat): whycan_cn (哇酷网/挖坑网/填坑网) service@whycan.cn