Add framebuffer
This commit is contained in:
parent
4e6b23e57b
commit
c74d43e140
66
fb.c
Normal file
66
fb.c
Normal file
@ -0,0 +1,66 @@
|
||||
#include "fb.h"
|
||||
#include "mbox.h"
|
||||
#include "uart.h"
|
||||
#include "utils.h"
|
||||
#include <stdint.h>
|
||||
|
||||
#define MBOX_TAG_FBALLOC 0x40001
|
||||
#define MBOX_TAG_FBGETPITCH 0x40008
|
||||
#define MBOX_TAG_FBSETPHYS 0x48003
|
||||
#define MBOX_TAG_FBSETVIRT 0x48004
|
||||
#define MBOX_TAG_FBSETDEPTH 0x48005
|
||||
#define MBOX_TAG_FBSETPIXORD 0x48006
|
||||
#define MBOX_TAG_FBSETOFF 0x48009
|
||||
|
||||
unsigned char *init_fb(struct fbst *fb) {
|
||||
// sending many tags at once
|
||||
mbox[0] = 35 * 4;
|
||||
mbox[1] = MBOX_REQUEST;
|
||||
mbox[2] = MBOX_TAG_FBSETPHYS; // set phy wh
|
||||
mbox[3] = 8;
|
||||
mbox[4] = 0;
|
||||
mbox[5] = 1920; // FrameBufferInfo.width
|
||||
mbox[6] = 1080; // FrameBufferInfo.height
|
||||
mbox[7] = MBOX_TAG_FBSETVIRT; // set virt wh
|
||||
mbox[8] = 8;
|
||||
mbox[9] = 0;
|
||||
mbox[10] = 1920; // FrameBufferInfo.virtual_width
|
||||
mbox[11] = 1080; // FrameBufferInfo.virtual_height
|
||||
mbox[12] = MBOX_TAG_FBSETOFF; // set virt offset
|
||||
mbox[13] = 8;
|
||||
mbox[14] = 0;
|
||||
mbox[15] = 0; // FrameBufferInfo.x_offset
|
||||
mbox[16] = 0; // FrameBufferInfo.y.offset
|
||||
mbox[17] = MBOX_TAG_FBSETDEPTH; // set depth
|
||||
mbox[18] = 4;
|
||||
mbox[19] = 0;
|
||||
mbox[20] = 32; // FrameBufferInfo.depth
|
||||
mbox[21] = MBOX_TAG_FBSETPIXORD; // set pixel order
|
||||
mbox[22] = 4;
|
||||
mbox[23] = 0;
|
||||
mbox[24] = 1; // RGB, not BGR preferably
|
||||
mbox[25] = MBOX_TAG_FBALLOC; // get framebuffer, gets alignment on request
|
||||
mbox[26] = 8;
|
||||
mbox[27] = 0;
|
||||
mbox[28] = 4096; // FrameBufferInfo.pointer
|
||||
mbox[29] = 0; // FrameBufferInfo.size
|
||||
mbox[30] = MBOX_TAG_FBGETPITCH; // get pitch
|
||||
mbox[31] = 4;
|
||||
mbox[32] = 0;
|
||||
mbox[33] = 0; // FrameBufferInfo.pitch
|
||||
mbox[34] = MBOX_TAG_LAST;
|
||||
|
||||
if (mbox_call(MBOX_CH_PROP, mbox) && mbox[20] == 32 && mbox[28] != 0) {
|
||||
mbox[28] &= 0x3FFFFFFF; // convert GPU address to ARM address
|
||||
fb->width = mbox[5]; // get actual physical width
|
||||
fb->height = mbox[6]; // get actual physical height
|
||||
fb->pitch = mbox[33]; // get number of bytes per line
|
||||
fb->isrgb = mbox[24]; // get the actual channel order
|
||||
fb->fbp = (void *)((unsigned long)mbox[28]);
|
||||
} else {
|
||||
puts("Unable to set framebuffer!\r\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
return fb->fbp;
|
||||
}
|
11
fb.h
Normal file
11
fb.h
Normal file
@ -0,0 +1,11 @@
|
||||
#pragma once
|
||||
|
||||
struct fbst {
|
||||
unsigned char *fbp;
|
||||
unsigned int width;
|
||||
unsigned int height;
|
||||
unsigned int pitch;
|
||||
unsigned int isrgb;
|
||||
};
|
||||
|
||||
unsigned char *init_fb(struct fbst *fb);
|
27
hello.c
27
hello.c
@ -1,8 +1,15 @@
|
||||
#include "uart.h"
|
||||
#include "fb.h"
|
||||
#include "mbox.h"
|
||||
#include "uart.h"
|
||||
#include "utils.h"
|
||||
|
||||
int kernelmain(void) {
|
||||
struct fbst fb;
|
||||
int kernelmain(void)
|
||||
{
|
||||
init_uart();
|
||||
if (init_fb(&fb) == 0){
|
||||
puts("Fail to init framebuffer");
|
||||
}
|
||||
mbox[0] = 8 * 4;
|
||||
mbox[1] = MBOX_REQUEST;
|
||||
mbox[2] = MBOX_TAG_GETVCOREMEM;
|
||||
@ -23,6 +30,20 @@ int kernelmain(void) {
|
||||
puts("Error getting videocore mem\n");
|
||||
}
|
||||
|
||||
puts("Hello world\n");
|
||||
unsigned char *ptr=fb.fbp;
|
||||
|
||||
for(int y=0; y<fb.height; y++) {
|
||||
for(int x=0; x<fb.width; x++) {
|
||||
if(y%60==0)
|
||||
*((unsigned int*)ptr)=0x00FF0000;
|
||||
else if (y%40==0)
|
||||
*((unsigned int*)ptr)=0x0000FF00;
|
||||
else if (y%20==0)
|
||||
*((unsigned int*)ptr)=0x000000FF;
|
||||
else
|
||||
*((unsigned int*)ptr)=0x00000000;
|
||||
ptr+=4;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
2
mbox.c
2
mbox.c
@ -13,7 +13,7 @@
|
||||
// u32: firmware revision
|
||||
// mbox[0] = 4 * 6 // total length in byte
|
||||
// mbox[1] = MBOX_REQUEST
|
||||
// mbox[2] = 0x00000001
|
||||
// mbox[2] = 0x00000001 //TAG
|
||||
// mbox[3] = max(req_length, resp_length) -> 4
|
||||
// mbox[5] = 0 // 0 :request, 0x80000000: response
|
||||
// mbox[6] = MBOX_TAG_LAST
|
||||
|
Loading…
Reference in New Issue
Block a user