forked from cs107e/cs107e.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfb.c
55 lines (47 loc) · 1.84 KB
/
fb.c
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
#include "mailbox.h"
#include "fb.h"
#include "printf.h"
// This prevents the GPU and CPU from caching mailbox messages
#define GPU_NOCACHE 0x40000000
typedef struct {
unsigned int width; // width of the display
unsigned int height; // height of the display
unsigned int virtual_width; // width of the virtual framebuffer
unsigned int virtual_height; // height of the virtual framebuffer
unsigned int pitch; // number of bytes per row
unsigned int depth; // number of bits per pixel
unsigned int x_offset; // x of the upper left corner of the virtual fb
unsigned int y_offset; // y of the upper left corner of the virtual fb
unsigned int framebuffer; // pointer to the start of the framebuffer
unsigned int size; // number of bytes in the framebuffer
} fb_config_t;
// Why is fb volatile?
// Why is it aligned to a multiple of 16?
volatile fb_config_t fb __attribute__ ((aligned(16)));
void fb_init(unsigned width, unsigned height, unsigned depth)
{
fb.width = width;
fb.virtual_width = width;
fb.height = height;
fb.virtual_height = height;
fb.depth = depth * 8; // convert number of bytes to number of bits
fb.x_offset = 0;
fb.y_offset = 0;
// the manual requires we to set these value to 0
// the GPU will return new values
fb.pitch = 0;
fb.framebuffer = 0;
fb.size = 0;
// Send the fb struct to the GPU
// Why do we add in GPU_NOCACHE?
mailbox_write(MAILBOX_FRAMEBUFFER, (unsigned)&fb + GPU_NOCACHE);
(void) mailbox_read(MAILBOX_FRAMEBUFFER);
printf("width = %d\n", fb.width );
printf("height = %d\n", fb.height );
printf("virtual width = %d\n", fb.virtual_width );
printf("virtual height = %d\n", fb.virtual_height );
printf("depth = %d\n", fb.depth );
printf("size = %d\n", fb.size );
printf("pitch = %d\n", fb.pitch );
printf("buffer = %08x\n", fb.framebuffer );
}