Repository navigation
Expand file tree
/
Copy pathframebuffer.c
More file actions
83 lines (62 loc) · 1.87 KB
/
Copy pathframebuffer.c
File metadata and controls
83 lines (62 loc) · 1.87 KB
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
/* framebuffer.c
*
* Description: Module for interfacing with Pi 2's framebuffer.
*/
#include "framebuffer.h"
#include "mbox.h"
/* Whether this module is initialized */
static bool_t is_initialized;
/* Frame buffer info structure */
static fb_info_t fb_info;
/* Frame buffer address */
static unsigned int fb_addr;
/* Initializes the frame buffer module. *
* Must be called before all other methods. *
* Returns whether initialization succeeded. */
bool_t fb_init(void)
{
unsigned int fb_info_addr;
// Get the address of the fb info struct
fb_info_addr = (unsigned int) &fb_info;
// Fill the info structure with data
fb_info.width = FB_WIDTH;
fb_info.height = FB_HEIGHT;
fb_info.virtual_width = FB_WIDTH;
fb_info.virtual_height = FB_HEIGHT;
fb_info.pitch = 0;
fb_info.depth = 32;
fb_info.x_offset = 0;
fb_info.y_offset = 0;
fb_info.fb_addr = 0;
fb_info.size = 0;
// Write info structure address to framebuffer channel
// (Need to add VC_START_ADDR for video core address)
mbox_write(MBOX_FB_CHANNEL, fb_info_addr + VC_START_ADDR);
// Wait for GPU to modify the structure
mbox_read(MBOX_FB_CHANNEL);
// Read the frame buffer location
// (Need to subtract VC_START_ADDR since it came from video core)
fb_addr = fb_info.fb_addr - VC_START_ADDR;
// If frame buffer address was modified, initialization successful
is_initialized = (fb_addr != 0);
return is_initialized;
}
/* Returns whether the module is initialized */
bool_t fb_is_initialized(void)
{
return is_initialized;
}
/* Returns the modified frame buffer info structure */
fb_info_t *fb_get_info(void)
{
if (!is_initialized)
return NULL;
return &fb_info;
}
/* Returns the address of the requested frame buffer */
unsigned int fb_get_addr(void)
{
if (!is_initialized)
return -1;
return fb_addr;
}