- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
- 73
- 74
- 75
- 76
- 77
- 78
- 79
- 80
- 81
- 82
- 83
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <linux/fb.h>
#include <stropts.h>
#include <sys/mman.h>
#include <unistd.h>
typedef unsigned char uint8_t;
typedef unsigned short uint16_t;
typedef unsigned int uint32_t;
typedef unsigned long int uint64_t;
inline uint32_t pixel_color(uint8_t r, uint8_t g, uint8_t b, struct fb_var_screeninfo *vinfo)
{
return (r<<vinfo->red.offset) | (g<<vinfo->green.offset) | (b<<vinfo->blue.offset);
}
int main()
{
int fb_fd = open("/dev/fb0", O_RDWR);
if(fb_fd == -1) {
perror("open");
return 1;
}
struct fb_fix_screeninfo finfo;
struct fb_var_screeninfo vinfo;
//Get variable screen information
if(ioctl(fb_fd, FBIOGET_VSCREENINFO, &vinfo) == -1) {
perror("ioctl");
return 1;
}
//Get fixed screen information
if(ioctl(fb_fd, FBIOGET_FSCREENINFO, &finfo) == -1) {
perror("ioctl");
return 1;
}
vinfo.grayscale=0;
vinfo.bits_per_pixel=32;
if(ioctl(fb_fd, FBIOPUT_VSCREENINFO, &vinfo) == -1) {
perror("ioctl");
return 1;
}
if(ioctl(fb_fd, FBIOGET_VSCREENINFO, &vinfo) == -1) {
perror("ioctl");
return 1;
}
if(vinfo.grayscale != 0) {
printf("Error set grayscale!\n");
return 1;
}
if(vinfo.bits_per_pixel != 32) {
printf("Error set bits_per_pixel!\n");
return 1;
}
long screensize = vinfo.yres_virtual * finfo.line_length;
uint8_t *fbp = mmap(0, screensize, PROT_READ | PROT_WRITE, MAP_SHARED, fb_fd, (off_t)0);
if(fbp == MAP_FAILED) {
perror("mmap");
return 1;
}
uint32_t pixel = pixel_color(46, 255, 46, &vinfo);
//Убедитесь, что вы правильно установили x, y и пиксель
long line = 0;
while(1)
{
if(line > vinfo.xres) break;
long location;
for (long x = 0; x < line; x++)
for (long y=0; y<vinfo.yres; y++)
{
location = (x+vinfo.xoffset) * (vinfo.bits_per_pixel/8) + (y+vinfo.yoffset) * finfo.line_length;
*((uint32_t*)(fbp + location)) = pixel;
}
line++;
usleep(100000);
}
return 0;
}
угадайте до запуска по какой оси прога будет рисовать и понос пролетит мимо вас!