/*************************************************
*
* file name:color.c
* author :[email protected]
* date :2024/05/11
* brief :通过内存映射的方式向lcd屏幕输出几个圆
* note :None
*
* CopyRight (c) 2024 [email protected] All Right Reseverd
*
**************************************************/
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdio.h>
#include <sys/mman.h>
int main(void)
{
int lcd_fd = open("/dev/fb0", O_RDWR);
if (-1 == lcd_fd)
{
printf("open lcd faild\n");
return -1;
}
int *lcd_mmap = (int *)mmap(
NULL,
800 * 480 * 4,
PROT_READ | PROT_WRITE,
MAP_SHARED,
lcd_fd,
0);
int x = 350, y = 300, r = 50;
int x1 = 100, y1 = 100, r1 = 20;
int x2 = 600, y2 = 260, r2 = 70;
for (int i = 0; i < 800 * 480; i++)
{
if (((i / 800) - y) * ((i / 800) - y) + ((i % 800) - x) * ((i % 800) - x) <= r * r)
{
lcd_mmap[i] = 0x00CCFFFF;
}
else if (((i / 800) - y1) * ((i / 800) - y1) + ((i % 800) - x1) * ((i % 800) - x1) <= r1 * r1)
{
lcd_mmap[i] = 0x00FFCCE5;
}
else if (((i / 800) - y2) * ((i / 800) - y2) + ((i % 800) - x2) * ((i % 800) - x2) <= r2 * r2)
{
lcd_mmap[i] = 0x00CCCCFF;
}
else
lcd_mmap[i] = 0x00ffffff;
}
write(lcd_fd, lcd_mmap, 800 * 480 * 4);
return 0;
}
运行结果