Add main loop with framebuffer color change
This commit is contained in:
parent
d0b2e6376f
commit
1d4759d8c0
38
src/main.c
38
src/main.c
|
@ -1,7 +1,43 @@
|
||||||
#include<stdio.h>
|
#include<stdio.h>
|
||||||
|
#include<stdlib.h>
|
||||||
|
#include<stdint.h>
|
||||||
|
#include<stdbool.h>
|
||||||
|
#include<fcntl.h>
|
||||||
|
#include<linux/fb.h>
|
||||||
|
#include<sys/ioctl.h>
|
||||||
|
#include<sys/mman.h>
|
||||||
|
|
||||||
int
|
int
|
||||||
main(void) {
|
main(void) {
|
||||||
printf("hello world\n");
|
// Open frambuffer and get the size.
|
||||||
|
int fb = open("/dev/fb0", O_RDWR);
|
||||||
|
if (fb <= 0) {
|
||||||
|
fprintf(stderr, "couldn't open the framebuffer\n");
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
struct fb_var_screeninfo info;
|
||||||
|
if (ioctl(fb, FBIOGET_VSCREENINFO, &info) != 0) {
|
||||||
|
fprintf(stderr, "couldn't get the framebuffer size\n");
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Mmap the framebuffer to a buffer object.
|
||||||
|
size_t width = info.xres;
|
||||||
|
size_t height = info.yres;
|
||||||
|
size_t len = 4 * width * height;
|
||||||
|
uint32_t *buf = mmap(NULL, len, PROT_READ | PROT_WRITE, MAP_SHARED, fb, 0);
|
||||||
|
if (buf == MAP_FAILED) {
|
||||||
|
fprintf(stderr, "couldn't mmap the framebuffer\n");
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
uint8_t shade = 0;
|
||||||
|
while (true) {
|
||||||
|
for (size_t j = 0; j < height; j++) {
|
||||||
|
for (size_t i = 0; i < width; i++) {
|
||||||
|
buf[j * width + i] = shade;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
shade++;
|
||||||
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue