在 Linux 系统中通过 Framebuffer 驱动程序来控制 LCD。 Frame 是帧的意思, buffer 是缓冲的意思,这意味着 Framebuffer 就是一块内存,里面保存着一帧图像。 Framebuffer 中保存着一帧图像的每一个像素颜色值,假设 LCD 的分辨率是 1024x768,每一个像素的颜色用 32 位来表示,那么 Framebuffer 的大小就是:1024x768x32/8=3145728 字节。
LCD 的操作原理:
① 驱动程序设置好 LCD 控制器:
根据 LCD 的参数设置 LCD 控制器的时序、信号极性;
根据 LCD 分辨率、 BPP 分配 Framebuffer。
② APP 使用 ioctl 获得 LCD 分辨率、 BPP
③ APP 通过 mmap 映射 Framebuffer,在 Framebuffer 中写入数据
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <sys/mman.h>
#include <stdio.h>
#include <string.h>
#include <linux/fb.h>
#include <unistd.h>
unsigned int fd_fb;
unsigned int line_width, pixel_width, sc