blob: e160edfe5f5e5e47ee846dec66cb164c324be251 [file] [log] [blame]
b.liud440f9f2025-04-18 10:44:31 +08001#include <stdio.h>
2#include <stdlib.h>
3#include <unistd.h>
4#include <fcntl.h>
5#include <errno.h>
6
7#include "mbtk_log.h"
8#include "mbtk_type.h"
9
10// RGB565
11#define COLOR_BLACK 0x0000
12#define COLOR_WRITE 0xFFFF
13#define DEV_FB_PATH "/dev/fb0"
14#define SCREEN_WIDTH 320
15#define SCREEN_HEIGTH 240
16
17typedef struct {
18 int left;
19 int top;
20 int width;
21 int heigth;
22} rect_t;
23
24static uint16 fb_buffer[SCREEN_WIDTH * SCREEN_HEIGTH];
25
26static int fb_refresh(int fd)
27{
28 rect_t rect;
29 rect.width = SCREEN_WIDTH / 2;
30 rect.heigth = SCREEN_HEIGTH / 2;
31 rect.left = (SCREEN_WIDTH - rect.width) / 2;
32 rect.top = (SCREEN_HEIGTH - rect.heigth) / 2;
33 // Fill in buffer.
34 int x,y;
35 for(y = 0; y < SCREEN_HEIGTH; y++) {
36 for(x = 0; x < SCREEN_WIDTH; x++) {
37 if(x >= rect.left && x <= rect.left + rect.width
38 && y >= rect.top && y <= rect.top + rect.heigth)
39 {
40 fb_buffer[x * SCREEN_HEIGTH + y] = COLOR_WRITE;
41 } else {
42 fb_buffer[x * SCREEN_HEIGTH + y] = COLOR_BLACK;
43 }
44 }
45 }
46
47 int len = write(fd, fb_buffer, sizeof(fb_buffer));
48 LOGD("Write : %d/%d", len, sizeof(fb_buffer));
49 // Write buffer to framebuffer.
50 if(sizeof(fb_buffer) != len) {
51 LOGE("Write fail:%d", errno);
52 return -1;
53 }
54
55 return 0;
56}
57
58int main(int argc, char *argv[]) {
59 if(access(DEV_FB_PATH, F_OK) != 0) {
60 LOGE("no %s, quit.", DEV_FB_PATH);
61 return -1;
62 }
63
64 int fb_fd = open(DEV_FB_PATH, O_RDWR);
65 if(fb_fd < 0) {
66 LOGE("open() fail:%d", errno);
67 return -1;
68 }
69
70 // Fresh framebuffer
71 while(1) {
72 if(fb_refresh(fb_fd)) {
73 break;
74 }
75
76 usleep(33); // 1000 / 30
77 }
78
79 LOGD("Exit");
80 return 0;
81}
82
83