forked from notro/fbtft
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtest_fbcpp.cpp
59 lines (51 loc) · 1.3 KB
/
test_fbcpp.cpp
1
2
3
4
5
6
7
8
9
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
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/errno.h>
#include <sys/fcntl.h>
#include <sys/ioctl.h>
#include <sys/mman.h>
#include <linux/fb.h>
#include <linux/omapfb.h>
void drawColor(int width, int height, int color)
{
uint16_t *canvas = new uint16_t[width * height];
for(int y = 0; y < height; y++) {
for(int x = 0; x < width; x++) {
if (((x > 200) && (x <= 300) ) && ((y > 20) && (y <= 40) ) ) {
canvas[x + y * width] = 0x00FF;
}
else {
canvas[x + y * width] = color;
}
}
}
int fd;
fd = open("/dev/fb1", O_WRONLY);
write(fd, canvas, width * height * 2);
close(fd);
delete[] canvas;
}
void drawColor2(int width, int height, int color)
{
int fd;
fd = open("/dev/fb1", O_RDWR);
uint16_t *frameBuffer = (uint16_t *)mmap(NULL, width * height * 2, PROT_WRITE, MAP_SHARED, fd, 0);
for(int y = 0; y < height; y++) {
for(int x = 0; x < width; x++) {
frameBuffer[x + y * width] = color;
}
}
msync(frameBuffer, width * height * 2, 0);
munmap(frameBuffer, width * height * 2);
close(fd);
}
int main()
{
int width = 640;
int height = 48;
/* Fill solid color */
drawColor(width, height, 0xFFFF);
}