67 lines
2.1 KiB
C
67 lines
2.1 KiB
C
#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) == 0 && 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;
|
|
}
|