mirror of
https://github.com/RT-Thread/rt-thread.git
synced 2025-01-31 17:50:29 +08:00
fix raspi3 hdmi driver
This commit is contained in:
parent
3024571acb
commit
7d23d713ed
@ -478,4 +478,5 @@ CONFIG_BSP_USING_SDIO0=y
|
||||
#
|
||||
# Board Peripheral Drivers
|
||||
#
|
||||
# CONFIG_BSP_USING_HDMI is not set
|
||||
CONFIG_BSP_USING_HDMI=y
|
||||
CONFIG_BSP_USING_HDMI_DISPLAY=y
|
||||
|
@ -105,7 +105,6 @@ menu "Hardware Drivers Config"
|
||||
menu "Board Peripheral Drivers"
|
||||
menuconfig BSP_USING_HDMI
|
||||
bool "Enable HDMI"
|
||||
select BSP_USING_SPI
|
||||
default n
|
||||
|
||||
if BSP_USING_HDMI
|
||||
|
@ -9,283 +9,30 @@
|
||||
*/
|
||||
|
||||
#include <rthw.h>
|
||||
#include <stdint.h>
|
||||
#include <rtthread.h>
|
||||
#include "mbox.h"
|
||||
#include "drv_fb.h"
|
||||
#include "mmu.h"
|
||||
|
||||
#define CHAR_W 8
|
||||
#define CHAR_H 12
|
||||
#define LCD_WIDTH (640)
|
||||
#define LCD_HEIGHT (480)
|
||||
#define LCD_DEPTH (32)
|
||||
|
||||
#define TAG_ALLOCATE_BUFFER 0x00040001
|
||||
#define TAG_SET_PHYS_WIDTH_HEIGHT 0x00048003
|
||||
#define TAG_SET_VIRT_WIDTH_HEIGHT 0x00048004
|
||||
#define TAG_SET_DEPTH 0x00048005
|
||||
#define TAG_SET_PIXEL_ORDER 0x00048006
|
||||
#define TAG_GET_PITCH 0x00040008
|
||||
#define TAG_SET_VIRT_OFFSET 0x00048009
|
||||
#define TAG_END 0x00000000
|
||||
|
||||
#define LCD_DEVICE(dev) (struct rt_hdmi_fb_device*)(dev)
|
||||
|
||||
#define COLOR_DELTA 0.05
|
||||
static struct rt_hdmi_fb_device _hdmi;
|
||||
|
||||
// https://github.com/xinu-os/xinu/blob/1789b7a50b5b73c2ea76ebd764c54a034097d04d/device/framebuffer_rpi/font.c
|
||||
unsigned char FONT[] = {
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /*' '*/
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /*' '*/
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /*' '*/
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /*' '*/
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /*' '*/
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /*' '*/
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /*' '*/
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /*' '*/
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /*' '*/
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /*' '*/
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /*' '*/
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /*' '*/
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /*' '*/
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /*' '*/
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /*' '*/
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /*' '*/
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /*' '*/
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /*' '*/
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /*' '*/
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /*' '*/
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /*' '*/
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /*' '*/
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /*' '*/
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /*' '*/
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /*' '*/
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /*' '*/
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /*' '*/
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /*' '*/
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /*' '*/
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /*' '*/
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /*' '*/
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /*' '*/
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /*' '*/
|
||||
0x00, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x00, 0x08, 0x00, 0x00, 0x00, /*'!'*/
|
||||
0x00, 0x14, 0x14, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /*'"'*/
|
||||
0x00, 0x00, 0x14, 0x14, 0x3e, 0x14, 0x3e, 0x14, 0x14, 0x00, 0x00, 0x00, /*'#'*/
|
||||
0x00, 0x00, 0x08, 0x3c, 0x0a, 0x1c, 0x28, 0x1e, 0x08, 0x00, 0x00, 0x00, /*'$'*/
|
||||
0x00, 0x00, 0x06, 0x26, 0x10, 0x08, 0x04, 0x32, 0x30, 0x00, 0x00, 0x00, /*'%'*/
|
||||
0x00, 0x00, 0x1c, 0x02, 0x02, 0x04, 0x2a, 0x12, 0x2c, 0x00, 0x00, 0x00, /*'&'*/
|
||||
0x00, 0x18, 0x08, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /*'''*/
|
||||
0x20, 0x10, 0x10, 0x08, 0x08, 0x08, 0x08, 0x08, 0x10, 0x10, 0x20, 0x00, /*'('*/
|
||||
0x02, 0x04, 0x04, 0x08, 0x08, 0x08, 0x08, 0x08, 0x04, 0x04, 0x02, 0x00, /*')'*/
|
||||
0x00, 0x00, 0x00, 0x08, 0x2a, 0x1c, 0x2a, 0x08, 0x00, 0x00, 0x00, 0x00, /*'*'*/
|
||||
0x00, 0x00, 0x00, 0x08, 0x08, 0x3e, 0x08, 0x08, 0x00, 0x00, 0x00, 0x00, /*'+'*/
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x08, 0x04, 0x00, /*','*/
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x3e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /*'-'*/
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x00, 0x00, 0x00, /*'.'*/
|
||||
0x20, 0x20, 0x10, 0x10, 0x08, 0x08, 0x04, 0x04, 0x02, 0x02, 0x00, 0x00, /*'/'*/
|
||||
0x00, 0x1c, 0x22, 0x32, 0x2a, 0x26, 0x22, 0x22, 0x1c, 0x00, 0x00, 0x00, /*'0'*/
|
||||
0x00, 0x08, 0x0c, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x00, 0x00, 0x00, /*'1'*/
|
||||
0x00, 0x1c, 0x22, 0x20, 0x10, 0x08, 0x04, 0x02, 0x3e, 0x00, 0x00, 0x00, /*'2'*/
|
||||
0x00, 0x1c, 0x22, 0x20, 0x18, 0x20, 0x20, 0x22, 0x1c, 0x00, 0x00, 0x00, /*'3'*/
|
||||
0x00, 0x10, 0x18, 0x18, 0x14, 0x14, 0x3e, 0x10, 0x38, 0x00, 0x00, 0x00, /*'4'*/
|
||||
0x00, 0x3e, 0x02, 0x02, 0x1e, 0x20, 0x20, 0x22, 0x1c, 0x00, 0x00, 0x00, /*'5'*/
|
||||
0x00, 0x18, 0x04, 0x02, 0x1e, 0x22, 0x22, 0x22, 0x1c, 0x00, 0x00, 0x00, /*'6'*/
|
||||
0x00, 0x3e, 0x22, 0x20, 0x20, 0x10, 0x10, 0x08, 0x08, 0x00, 0x00, 0x00, /*'7'*/
|
||||
0x00, 0x1c, 0x22, 0x22, 0x1c, 0x22, 0x22, 0x22, 0x1c, 0x00, 0x00, 0x00, /*'8'*/
|
||||
0x00, 0x1c, 0x22, 0x22, 0x22, 0x3c, 0x20, 0x10, 0x0c, 0x00, 0x00, 0x00, /*'9'*/
|
||||
0x00, 0x00, 0x00, 0x18, 0x18, 0x00, 0x00, 0x18, 0x18, 0x00, 0x00, 0x00, /*':'*/
|
||||
0x00, 0x00, 0x00, 0x18, 0x18, 0x00, 0x00, 0x18, 0x18, 0x08, 0x04, 0x00, /*';'*/
|
||||
0x00, 0x00, 0x00, 0x30, 0x0c, 0x03, 0x0c, 0x30, 0x00, 0x00, 0x00, 0x00, /*'<'*/
|
||||
0x00, 0x00, 0x00, 0x00, 0x3e, 0x00, 0x3e, 0x00, 0x00, 0x00, 0x00, 0x00, /*'='*/
|
||||
0x00, 0x00, 0x00, 0x03, 0x0c, 0x30, 0x0c, 0x03, 0x00, 0x00, 0x00, 0x00, /*'>'*/
|
||||
0x00, 0x1c, 0x22, 0x20, 0x10, 0x08, 0x08, 0x00, 0x08, 0x00, 0x00, 0x00, /*'?'*/
|
||||
0x00, 0x00, 0x1c, 0x22, 0x3a, 0x3a, 0x1a, 0x02, 0x1c, 0x00, 0x00, 0x00, /*'@'*/
|
||||
0x00, 0x00, 0x08, 0x14, 0x22, 0x22, 0x3e, 0x22, 0x22, 0x00, 0x00, 0x00, /*'A'*/
|
||||
0x00, 0x00, 0x1e, 0x22, 0x22, 0x1e, 0x22, 0x22, 0x1e, 0x00, 0x00, 0x00, /*'B'*/
|
||||
0x00, 0x00, 0x1c, 0x22, 0x02, 0x02, 0x02, 0x22, 0x1c, 0x00, 0x00, 0x00, /*'C'*/
|
||||
0x00, 0x00, 0x0e, 0x12, 0x22, 0x22, 0x22, 0x12, 0x0e, 0x00, 0x00, 0x00, /*'D'*/
|
||||
0x00, 0x00, 0x3e, 0x02, 0x02, 0x1e, 0x02, 0x02, 0x3e, 0x00, 0x00, 0x00, /*'E'*/
|
||||
0x00, 0x00, 0x3e, 0x02, 0x02, 0x1e, 0x02, 0x02, 0x02, 0x00, 0x00, 0x00, /*'F'*/
|
||||
0x00, 0x00, 0x1c, 0x22, 0x02, 0x32, 0x22, 0x22, 0x3c, 0x00, 0x00, 0x00, /*'G'*/
|
||||
0x00, 0x00, 0x22, 0x22, 0x22, 0x3e, 0x22, 0x22, 0x22, 0x00, 0x00, 0x00, /*'H'*/
|
||||
0x00, 0x00, 0x3e, 0x08, 0x08, 0x08, 0x08, 0x08, 0x3e, 0x00, 0x00, 0x00, /*'I'*/
|
||||
0x00, 0x00, 0x38, 0x20, 0x20, 0x20, 0x22, 0x22, 0x1c, 0x00, 0x00, 0x00, /*'J'*/
|
||||
0x00, 0x00, 0x22, 0x12, 0x0a, 0x06, 0x0a, 0x12, 0x22, 0x00, 0x00, 0x00, /*'K'*/
|
||||
0x00, 0x00, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x3e, 0x00, 0x00, 0x00, /*'L'*/
|
||||
0x00, 0x00, 0x22, 0x36, 0x2a, 0x2a, 0x22, 0x22, 0x22, 0x00, 0x00, 0x00, /*'M'*/
|
||||
0x00, 0x00, 0x22, 0x26, 0x26, 0x2a, 0x32, 0x32, 0x22, 0x00, 0x00, 0x00, /*'N'*/
|
||||
0x00, 0x00, 0x1c, 0x22, 0x22, 0x22, 0x22, 0x22, 0x1c, 0x00, 0x00, 0x00, /*'O'*/
|
||||
0x00, 0x00, 0x1e, 0x22, 0x22, 0x1e, 0x02, 0x02, 0x02, 0x00, 0x00, 0x00, /*'P'*/
|
||||
0x00, 0x00, 0x1c, 0x22, 0x22, 0x22, 0x22, 0x22, 0x1c, 0x30, 0x00, 0x00, /*'Q'*/
|
||||
0x00, 0x00, 0x1e, 0x22, 0x22, 0x1e, 0x0a, 0x12, 0x22, 0x00, 0x00, 0x00, /*'R'*/
|
||||
0x00, 0x00, 0x1c, 0x22, 0x02, 0x1c, 0x20, 0x22, 0x1c, 0x00, 0x00, 0x00, /*'S'*/
|
||||
0x00, 0x00, 0x3e, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x00, 0x00, 0x00, /*'T'*/
|
||||
0x00, 0x00, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x1c, 0x00, 0x00, 0x00, /*'U'*/
|
||||
0x00, 0x00, 0x22, 0x22, 0x22, 0x14, 0x14, 0x08, 0x08, 0x00, 0x00, 0x00, /*'V'*/
|
||||
0x00, 0x00, 0x22, 0x22, 0x22, 0x2a, 0x2a, 0x36, 0x22, 0x00, 0x00, 0x00, /*'W'*/
|
||||
0x00, 0x00, 0x22, 0x22, 0x14, 0x08, 0x14, 0x22, 0x22, 0x00, 0x00, 0x00, /*'X'*/
|
||||
0x00, 0x00, 0x22, 0x22, 0x14, 0x08, 0x08, 0x08, 0x08, 0x00, 0x00, 0x00, /*'Y'*/
|
||||
0x00, 0x00, 0x3e, 0x20, 0x10, 0x08, 0x04, 0x02, 0x3e, 0x00, 0x00, 0x00, /*'Z'*/
|
||||
0x38, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x38, 0x00, /*'['*/
|
||||
0x02, 0x02, 0x04, 0x04, 0x08, 0x08, 0x10, 0x10, 0x20, 0x20, 0x00, 0x00, /*'\'*/
|
||||
0x0e, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x0e, 0x00, /*']'*/
|
||||
0x00, 0x08, 0x14, 0x22, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /*'^'*/
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3f, 0x00, 0x00, /*'_'*/
|
||||
0x00, 0x0c, 0x08, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /*'`'*/
|
||||
0x00, 0x00, 0x00, 0x00, 0x3c, 0x22, 0x22, 0x32, 0x2c, 0x00, 0x00, 0x00, /*'a'*/
|
||||
0x00, 0x02, 0x02, 0x02, 0x1e, 0x22, 0x22, 0x22, 0x1e, 0x00, 0x00, 0x00, /*'b'*/
|
||||
0x00, 0x00, 0x00, 0x00, 0x3c, 0x02, 0x02, 0x02, 0x3c, 0x00, 0x00, 0x00, /*'c'*/
|
||||
0x00, 0x20, 0x20, 0x20, 0x3c, 0x22, 0x22, 0x22, 0x3c, 0x00, 0x00, 0x00, /*'d'*/
|
||||
0x00, 0x00, 0x00, 0x00, 0x1c, 0x22, 0x3e, 0x02, 0x1c, 0x00, 0x00, 0x00, /*'e'*/
|
||||
0x00, 0x38, 0x04, 0x04, 0x1e, 0x04, 0x04, 0x04, 0x04, 0x00, 0x00, 0x00, /*'f'*/
|
||||
0x00, 0x00, 0x00, 0x00, 0x3c, 0x22, 0x22, 0x22, 0x3c, 0x20, 0x20, 0x1c, /*'g'*/
|
||||
0x00, 0x02, 0x02, 0x02, 0x1e, 0x22, 0x22, 0x22, 0x22, 0x00, 0x00, 0x00, /*'h'*/
|
||||
0x00, 0x08, 0x08, 0x00, 0x0c, 0x08, 0x08, 0x08, 0x1c, 0x00, 0x00, 0x00, /*'i'*/
|
||||
0x00, 0x10, 0x10, 0x00, 0x1c, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x0e, /*'j'*/
|
||||
0x00, 0x02, 0x02, 0x02, 0x12, 0x0a, 0x06, 0x0a, 0x12, 0x00, 0x00, 0x00, /*'k'*/
|
||||
0x00, 0x0c, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x1c, 0x00, 0x00, 0x00, /*'l'*/
|
||||
0x00, 0x00, 0x00, 0x00, 0x16, 0x2a, 0x2a, 0x2a, 0x22, 0x00, 0x00, 0x00, /*'m'*/
|
||||
0x00, 0x00, 0x00, 0x00, 0x1a, 0x26, 0x22, 0x22, 0x22, 0x00, 0x00, 0x00, /*'n'*/
|
||||
0x00, 0x00, 0x00, 0x00, 0x1c, 0x22, 0x22, 0x22, 0x1c, 0x00, 0x00, 0x00, /*'o'*/
|
||||
0x00, 0x00, 0x00, 0x00, 0x1e, 0x22, 0x22, 0x22, 0x1e, 0x02, 0x02, 0x02, /*'p'*/
|
||||
0x00, 0x00, 0x00, 0x00, 0x3c, 0x22, 0x22, 0x22, 0x3c, 0x20, 0x20, 0x20, /*'q'*/
|
||||
0x00, 0x00, 0x00, 0x00, 0x1a, 0x06, 0x02, 0x02, 0x02, 0x00, 0x00, 0x00, /*'r'*/
|
||||
0x00, 0x00, 0x00, 0x00, 0x3c, 0x02, 0x1c, 0x20, 0x1e, 0x00, 0x00, 0x00, /*'s'*/
|
||||
0x00, 0x08, 0x08, 0x08, 0x3e, 0x08, 0x08, 0x08, 0x30, 0x00, 0x00, 0x00, /*'t'*/
|
||||
0x00, 0x00, 0x00, 0x00, 0x22, 0x22, 0x22, 0x32, 0x2c, 0x00, 0x00, 0x00, /*'u'*/
|
||||
0x00, 0x00, 0x00, 0x00, 0x36, 0x14, 0x14, 0x08, 0x08, 0x00, 0x00, 0x00, /*'v'*/
|
||||
0x00, 0x00, 0x00, 0x00, 0x22, 0x2a, 0x2a, 0x2a, 0x14, 0x00, 0x00, 0x00, /*'w'*/
|
||||
0x00, 0x00, 0x00, 0x00, 0x22, 0x14, 0x08, 0x14, 0x22, 0x00, 0x00, 0x00, /*'x'*/
|
||||
0x00, 0x00, 0x00, 0x00, 0x22, 0x22, 0x22, 0x22, 0x3c, 0x20, 0x20, 0x1c, /*'y'*/
|
||||
0x00, 0x00, 0x00, 0x00, 0x3e, 0x10, 0x08, 0x04, 0x3e, 0x00, 0x00, 0x00, /*'z'*/
|
||||
0x20, 0x10, 0x10, 0x10, 0x10, 0x08, 0x10, 0x10, 0x10, 0x10, 0x20, 0x00, /*'{'*/
|
||||
0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x00, /*'|'*/
|
||||
0x02, 0x04, 0x04, 0x04, 0x04, 0x08, 0x04, 0x04, 0x04, 0x04, 0x02, 0x00, /*'}'*/
|
||||
0x00, 0x04, 0x2a, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /*'~'*/
|
||||
0x00, 0x00, 0x00, 0x08, 0x08, 0x14, 0x14, 0x22, 0x3e, 0x00, 0x00, 0x00, /*DEL*/
|
||||
};
|
||||
|
||||
void newline(fb_t* fb)
|
||||
{
|
||||
uint8_t* to;
|
||||
uint8_t* from;
|
||||
int i;
|
||||
fb->y++;
|
||||
fb->x = 0;
|
||||
|
||||
if (fb->y == (fb->height / CHAR_H))
|
||||
{
|
||||
|
||||
to = (uint8_t*) fb->addr;
|
||||
from = to + (CHAR_H * fb->pitch);
|
||||
|
||||
for (i = 0; i < ((fb->height - CHAR_H) * fb->pitch); i++)
|
||||
{
|
||||
*to++ = *from++;
|
||||
}
|
||||
|
||||
uint32_t *addr = (uint32_t*) (fb->addr) + (fb->height - CHAR_H) * fb->width;
|
||||
|
||||
for (i = 0; i < (CHAR_H * fb->width); i++)
|
||||
{
|
||||
*addr++ = fb->back;
|
||||
}
|
||||
|
||||
fb->y--;
|
||||
}
|
||||
}
|
||||
|
||||
void clear_line(fb_t *fb, const int line)
|
||||
{
|
||||
int i;
|
||||
uint32_t* addr;
|
||||
if (line > fb->height / CHAR_H)
|
||||
{
|
||||
fb->y = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
fb->y = line;
|
||||
}
|
||||
|
||||
fb->x = 0;
|
||||
|
||||
addr = (uint32_t*) (fb->addr + (line * CHAR_H * fb->depth * fb->width));
|
||||
for (i = 0; i < (CHAR_H * fb->width); i++)
|
||||
{
|
||||
*addr++ = fb->back;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void clear(fb_t *fb, const uint32_t color)
|
||||
{
|
||||
|
||||
uint32_t *addr = (uint32_t*) fb->addr;
|
||||
uint32_t i;
|
||||
for (i = 0; i < (fb->height * fb->width); i++)
|
||||
{
|
||||
*addr++ = color;
|
||||
}
|
||||
fb->x = 0;
|
||||
fb->y = 0;
|
||||
|
||||
}
|
||||
|
||||
void fb_draw_char(fb_t *fb, char s)
|
||||
{
|
||||
unsigned char* addr = (unsigned char*) fb->addr;
|
||||
unsigned char *glyph = (unsigned char*) FONT + (s) * 12;
|
||||
// calculate the offset on screen
|
||||
int offs = (fb->y * CHAR_H * fb->pitch) + (fb->x * (CHAR_W + 1) * 4);
|
||||
// variables
|
||||
int i, j, line, mask, bytesperline = (CHAR_W + 7) / 8;
|
||||
// display a character
|
||||
for (j = 0; j < CHAR_H; j++)
|
||||
{
|
||||
// display one row
|
||||
line = offs;
|
||||
mask = 1;
|
||||
for (i = 0; i < CHAR_W; i++)
|
||||
{
|
||||
// if bit set, we use white color, otherwise black
|
||||
*((unsigned int*) (addr + line)) = ((int) *glyph) & mask ? fb->fore : fb->back;
|
||||
mask <<= 1;
|
||||
line += 4;
|
||||
}
|
||||
// adjust to next line
|
||||
glyph += bytesperline;
|
||||
offs += fb->pitch;
|
||||
}
|
||||
}
|
||||
|
||||
void fb_print(fb_t *fb, char *s)
|
||||
{
|
||||
|
||||
// draw next character if it's not zero
|
||||
while (*s)
|
||||
{
|
||||
// handle carrige return
|
||||
if (*s == '\r')
|
||||
{
|
||||
fb->x = 0;
|
||||
}
|
||||
else if (*s == '\n')
|
||||
{
|
||||
newline(fb);
|
||||
}
|
||||
else if (*s == '\t')
|
||||
{
|
||||
fb->x = ((fb->x + 4) >> 2) << 2;
|
||||
}
|
||||
else if (*s == '\b')
|
||||
{
|
||||
if (fb->x)
|
||||
{
|
||||
fb->x--;
|
||||
fb_draw_char(fb, ' ');
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
fb_draw_char(fb, *s);
|
||||
fb->x++;
|
||||
}
|
||||
// next character
|
||||
if (fb->x == fb->width / CHAR_W)
|
||||
{
|
||||
newline(fb);
|
||||
}
|
||||
s++;
|
||||
}
|
||||
}
|
||||
typedef rt_uint16_t color_t;
|
||||
|
||||
rt_err_t hdmi_fb_open(rt_device_t dev, rt_uint16_t oflag)
|
||||
{
|
||||
@ -299,46 +46,44 @@ rt_err_t hdmi_fb_close(rt_device_t dev)
|
||||
|
||||
rt_size_t hdmi_fb_read(rt_device_t dev, rt_off_t pos, void *buf, rt_size_t size)
|
||||
{
|
||||
#ifdef BSP_USING_USPI
|
||||
char* buffer = (char *) buf;
|
||||
if(keyboard_available())
|
||||
{
|
||||
int i = 0;
|
||||
int j = 0;
|
||||
while (i != size)
|
||||
{
|
||||
int ch = keyboard_getchar();
|
||||
if(ch != -1)
|
||||
buffer[j++] = ch;
|
||||
i++;
|
||||
}
|
||||
return j;
|
||||
|
||||
}
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
rt_size_t hdmi_fb_write(rt_device_t dev, rt_off_t pos, const void *buffer, rt_size_t size)
|
||||
{
|
||||
fb_print(&_hdmi.fb, (char *) buffer);
|
||||
#ifdef BSP_USING_HDMI_DISPLAY
|
||||
rt_device_t uart = rt_device_find("uart1");
|
||||
int old_flag = uart->open_flag;
|
||||
uart->open_flag |= RT_DEVICE_FLAG_STREAM;
|
||||
rt_device_write(uart, 0, buffer, size);
|
||||
uart->open_flag = old_flag;
|
||||
#endif
|
||||
return size;
|
||||
|
||||
}
|
||||
|
||||
rt_err_t hdmi_fb_control(rt_device_t dev, int cmd, void *args)
|
||||
{
|
||||
struct rt_hdmi_fb_device *lcd = LCD_DEVICE(dev);
|
||||
switch (cmd)
|
||||
{
|
||||
case RTGRAPHIC_CTRL_RECT_UPDATE:
|
||||
{
|
||||
struct rt_device_rect_info *info = (struct rt_device_rect_info*)args;
|
||||
info = info;
|
||||
}
|
||||
break;
|
||||
|
||||
case RTGRAPHIC_CTRL_GET_INFO:
|
||||
{
|
||||
struct rt_device_graphic_info* info = (struct rt_device_graphic_info*)args;
|
||||
|
||||
RT_ASSERT(info != RT_NULL);
|
||||
info->pixel_format = RTGRAPHIC_PIXEL_FORMAT_RGB888;
|
||||
info->bits_per_pixel= LCD_DEPTH;
|
||||
info->width = lcd->width;
|
||||
info->height = lcd->height;
|
||||
info->framebuffer = lcd->fb;//(rt_uint8_t *)lcd->fb;
|
||||
}
|
||||
break;
|
||||
}
|
||||
return RT_EOK;
|
||||
}
|
||||
|
||||
const static struct rt_device_ops hdmi_fb_ops = {
|
||||
const static struct rt_device_ops hdmi_fb_ops =
|
||||
{
|
||||
RT_NULL,
|
||||
hdmi_fb_open,
|
||||
hdmi_fb_close,
|
||||
@ -347,73 +92,12 @@ const static struct rt_device_ops hdmi_fb_ops = {
|
||||
hdmi_fb_control
|
||||
};
|
||||
|
||||
static struct rt_device_graphic_info _hdmi_info;
|
||||
|
||||
static void hdmi_draw_rect(const char* pixel, int x1, int y1, int x2, int y2)
|
||||
{
|
||||
int i, j;
|
||||
int line;
|
||||
for (j = y1; j <= y2; j++)
|
||||
{
|
||||
line = (j * _hdmi.fb.pitch) + (x1 * 4);
|
||||
for (i = x1; i <= x2; i++)
|
||||
{
|
||||
// if bit set, we use white color, otherwise black
|
||||
*((unsigned int*) (_hdmi_info.framebuffer + line)) = *(unsigned int*) pixel;
|
||||
line += 4;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static void hdmi_set_pixel(const char* pixel, int x, int y)
|
||||
{
|
||||
*(uint32_t*) (_hdmi.fb.addr + (y * _hdmi.fb.pitch + x * 4)) = *(uint32_t *) pixel;
|
||||
}
|
||||
|
||||
static void hdmi_get_pixel(char* pixel, int x, int y)
|
||||
{
|
||||
uint32_t ret = 0;
|
||||
ret = (*(uint32_t*) (_hdmi.fb.addr + (y * _hdmi.fb.pitch + x * 4)) & 0x00FFFFFF);
|
||||
*pixel = ret;
|
||||
}
|
||||
|
||||
static void hdmi_draw_hline(const char* pixel, int x1, int x2, int y)
|
||||
{
|
||||
hdmi_draw_rect(pixel, x1, y, x2, y);
|
||||
}
|
||||
|
||||
static void hdmi_draw_vline(const char* pixel, int x, int y1, int y2)
|
||||
{
|
||||
hdmi_draw_rect(pixel, x, y1, x, y2);
|
||||
}
|
||||
|
||||
static void hdmi_blit_line(const char* pixels, int x, int y, rt_size_t size)
|
||||
{
|
||||
int i = 0;
|
||||
uint32_t *pixel_base = (uint32_t*) (_hdmi.fb.addr + (y * _hdmi.fb.pitch + x * 4));
|
||||
uint32_t *colors = (uint32_t *) pixels;
|
||||
for (i = 0; i < size; i++)
|
||||
{
|
||||
pixel_base[i] = colors[i];
|
||||
}
|
||||
}
|
||||
|
||||
static struct rt_device_graphic_ops hdmi_ops = {
|
||||
hdmi_set_pixel,
|
||||
hdmi_get_pixel,
|
||||
hdmi_draw_hline,
|
||||
hdmi_draw_vline,
|
||||
hdmi_blit_line
|
||||
};
|
||||
|
||||
rt_err_t rt_hdmi_fb_device_init(struct rt_hdmi_fb_device *hdmi_fb, const char *name)
|
||||
{
|
||||
struct rt_device *device;
|
||||
RT_ASSERT(hdmi_fb != RT_NULL);
|
||||
|
||||
device = &hdmi_fb->parent;
|
||||
device->user_data = &hdmi_ops;
|
||||
|
||||
/* set device type */
|
||||
device->type = RT_Device_Class_Graphic;
|
||||
@ -435,89 +119,68 @@ rt_err_t rt_hdmi_fb_device_init(struct rt_hdmi_fb_device *hdmi_fb, const char *n
|
||||
return RT_EOK;
|
||||
}
|
||||
|
||||
/**
|
||||
* Show a picture
|
||||
*/
|
||||
void print_fb_info()
|
||||
int hdmi_fb_init(void)
|
||||
{
|
||||
rt_kprintf("FrameBuffer Info: \n \t width %x\t height %x\t depth %x\t addr %x\t size %x\t \n", fb_info.width,
|
||||
fb_info.height, fb_info.depth, fb_info.addr, fb_info.size);
|
||||
rt_kprintf("call mbox:%x,%x,%x,%x,%x\n", mbox[0], mbox[1], mbox[2], mbox[3], mbox[4]);
|
||||
}
|
||||
|
||||
void hdmi_fb_init()
|
||||
{
|
||||
unsigned int *mbox = (unsigned int*) MBOX_ADDR;
|
||||
mbox[0] = 35 * 4;
|
||||
mbox[0] = 4 * 35;
|
||||
mbox[1] = MBOX_REQUEST;
|
||||
|
||||
mbox[2] = 0x48003; //set phy wh
|
||||
mbox[2] = TAG_ALLOCATE_BUFFER;//get framebuffer, gets alignment on request
|
||||
mbox[3] = 8;
|
||||
mbox[4] = 8;
|
||||
mbox[5] = 640; //FrameBufferInfo.width
|
||||
mbox[6] = 480; //FrameBufferInfo.height
|
||||
mbox[4] = 0;
|
||||
mbox[5] = 4096; //FrameBufferInfo.pointer
|
||||
mbox[6] = 0; //FrameBufferInfo.size
|
||||
|
||||
mbox[7] = 0x48004; //set virt wh
|
||||
mbox[7] = TAG_SET_PHYS_WIDTH_HEIGHT;
|
||||
mbox[8] = 8;
|
||||
mbox[9] = 8;
|
||||
mbox[10] = 640; //FrameBufferInfo.virtual_width
|
||||
mbox[11] = 480; //FrameBufferInfo.virtual_height
|
||||
mbox[9] = 0;
|
||||
mbox[10] = LCD_WIDTH;
|
||||
mbox[11] = LCD_HEIGHT;
|
||||
|
||||
mbox[12] = 0x48009; //set virt offset
|
||||
mbox[12] = TAG_SET_VIRT_WIDTH_HEIGHT;
|
||||
mbox[13] = 8;
|
||||
mbox[14] = 8;
|
||||
mbox[15] = 0; //FrameBufferInfo.x_offset
|
||||
mbox[16] = 0; //FrameBufferInfo.y.offset
|
||||
mbox[14] = 0;
|
||||
mbox[15] = LCD_WIDTH;
|
||||
mbox[16] = LCD_HEIGHT;
|
||||
|
||||
mbox[17] = 0x48005; //set depth
|
||||
mbox[17] = TAG_SET_DEPTH;
|
||||
mbox[18] = 4;
|
||||
mbox[19] = 4;
|
||||
mbox[20] = 32; //FrameBufferInfo.depth
|
||||
mbox[19] = 0;
|
||||
mbox[20] = 16; //FrameBufferInfo.depth RGB 565
|
||||
|
||||
mbox[21] = 0x48006; //set pixel order
|
||||
mbox[21] = TAG_SET_PIXEL_ORDER;
|
||||
mbox[22] = 4;
|
||||
mbox[23] = 4;
|
||||
mbox[24] = 1; //RGB, not BGR preferably
|
||||
mbox[23] = 0;
|
||||
mbox[24] = 1; //RGB, not BGR preferably
|
||||
|
||||
mbox[25] = 0x40001; //get framebuffer, gets alignment on request
|
||||
mbox[26] = 8;
|
||||
mbox[27] = 8;
|
||||
mbox[28] = 4096; //FrameBufferInfo.pointer
|
||||
mbox[29] = 0; //FrameBufferInfo.size
|
||||
mbox[25] = TAG_GET_PITCH;
|
||||
mbox[26] = 4;
|
||||
mbox[27] = 0;
|
||||
mbox[28] = 0;
|
||||
|
||||
mbox[30] = 0x40008; //get pitch
|
||||
mbox[31] = 4;
|
||||
mbox[32] = 4;
|
||||
mbox[33] = 0; //FrameBufferInfo.pitch
|
||||
mbox[29] = TAG_SET_VIRT_OFFSET;
|
||||
mbox[30] = 8;
|
||||
mbox[31] = 8;
|
||||
mbox[32] = 0;
|
||||
mbox[33] = 0;
|
||||
|
||||
mbox[34] = MBOX_TAG_LAST;
|
||||
if (mbox_call(MBOX_CH_PROP, MMU_DISABLE) && mbox[20] == 32 && mbox[28] != 0)
|
||||
{
|
||||
mbox[28] &= 0x3FFFFFFF;
|
||||
_hdmi.fb.width = mbox[5];
|
||||
_hdmi.fb.height = mbox[6];
|
||||
_hdmi.fb.pitch = mbox[33];
|
||||
//_hdmi.fb.addr = (void*)((unsigned long)mbox[28]);
|
||||
_hdmi.fb.addr = (rt_uint32_t) mbox[28];
|
||||
_hdmi.fb.size = mbox[29];
|
||||
_hdmi.fb.depth = 32;
|
||||
_hdmi.fb.x = 0;
|
||||
_hdmi.fb.y = 0;
|
||||
_hdmi.fb.fore = CONSOLE_WHITE;
|
||||
_hdmi.fb.back = CONSOLE_BLACK;
|
||||
rt_hdmi_fb_device_init(&_hdmi, "hdmi");
|
||||
rt_hw_change_mmu_table(_hdmi.fb.addr, _hdmi.fb.size, _hdmi.fb.addr, DEVICE_MEM);
|
||||
fb_info.width = _hdmi.fb.width;
|
||||
fb_info.height = _hdmi.fb.height;
|
||||
fb_info.addr = _hdmi.fb.addr;
|
||||
fb_info.size = _hdmi.fb.size;
|
||||
fb_info.pitch = _hdmi.fb.pitch;
|
||||
fb_info.depth = _hdmi.fb.depth;
|
||||
_hdmi_info.pixel_format = RTGRAPHIC_PIXEL_FORMAT_RGB888;
|
||||
_hdmi_info.bits_per_pixel = _hdmi.fb.depth;
|
||||
_hdmi_info.width = _hdmi.fb.width;
|
||||
_hdmi_info.height = _hdmi.fb.height;
|
||||
_hdmi_info.framebuffer = (rt_uint8_t *) _hdmi.fb.addr;
|
||||
}
|
||||
mbox[34] = TAG_END;
|
||||
|
||||
mbox_call(MBOX_CH_PROP, MMU_DISABLE);
|
||||
|
||||
_hdmi.fb = (rt_uint8_t *)(uintptr_t)(mbox[5] & 0x3FFFFFFF);
|
||||
|
||||
_hdmi.width = LCD_WIDTH;
|
||||
_hdmi.height = LCD_HEIGHT;
|
||||
_hdmi.depth = LCD_DEPTH;
|
||||
_hdmi.pitch = 0;
|
||||
_hdmi.pixel_format = RTGRAPHIC_PIXEL_FORMAT_RGB888;
|
||||
|
||||
armv8_map((unsigned long)_hdmi.fb, (unsigned long)_hdmi.fb, 0x200000, MEM_ATTR_MEMORY);
|
||||
|
||||
rt_kprintf("_hdmi.fb is %p\n", _hdmi.fb);
|
||||
rt_hdmi_fb_device_init(&_hdmi, "lcd");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
INIT_DEVICE_EXPORT(hdmi_fb_init);
|
||||
|
@ -11,50 +11,16 @@
|
||||
#define __DRV_FB_H__
|
||||
|
||||
#define RGB(r, g, b) ((((r))<<16) | (((g))<<8) | ((b)))
|
||||
|
||||
#define COLOR_BLACK RGB(0, 0, 0)
|
||||
|
||||
#define COLOR_GREEN RGB(0, 255, 0)
|
||||
|
||||
#define COLOR_CYAN RGB(0, 255, 255)
|
||||
|
||||
#define COLOR_RED RGB(255, 0, 0)
|
||||
|
||||
#define COLOR_YELLOW RGB(255, 255, 0)
|
||||
|
||||
#define COLOR_WHITE RGB(255, 255, 255)
|
||||
|
||||
#define CONSOLE_WHITE COLOR_WHITE
|
||||
#define CONSOLE_BLACK COLOR_BLACK
|
||||
#define CONSOLE_GREEN COLOR_GREEN
|
||||
#define CONSOLE_CYAN COLOR_CYAN
|
||||
#define CONSOLE_RED COLOR_RED
|
||||
#define CONSOLE_YELLOW COLOR_YELLOW
|
||||
|
||||
typedef struct
|
||||
{
|
||||
rt_uint32_t width;
|
||||
rt_uint32_t height;
|
||||
rt_uint32_t vwidth;
|
||||
rt_uint32_t vheight;
|
||||
rt_uint32_t pitch;
|
||||
rt_uint32_t depth;
|
||||
rt_uint32_t fore;
|
||||
rt_uint32_t back;
|
||||
rt_uint32_t x;
|
||||
rt_uint32_t y;
|
||||
rt_uint32_t addr;
|
||||
rt_uint32_t size;
|
||||
}fb_t;
|
||||
|
||||
struct rt_hdmi_fb_device
|
||||
{
|
||||
struct rt_device parent;
|
||||
fb_t fb;
|
||||
|
||||
rt_uint32_t width;
|
||||
rt_uint32_t height;
|
||||
rt_uint32_t depth;
|
||||
rt_uint32_t pitch;
|
||||
rt_uint32_t pixel_format;
|
||||
|
||||
rt_uint8_t *fb;
|
||||
};
|
||||
|
||||
fb_t fb_info;
|
||||
void print_fb_info();
|
||||
void hdmi_fb_init();
|
||||
|
||||
#endif/* __DRV_FB_H__ */
|
||||
|
@ -39,6 +39,8 @@ SECTIONS
|
||||
*(.glue_7t)
|
||||
*(.gnu.linkonce.t*)
|
||||
|
||||
*(COMMON)
|
||||
|
||||
/* section information for finsh shell */
|
||||
. = ALIGN(16);
|
||||
__fsymtab_start = .;
|
||||
@ -108,7 +110,7 @@ SECTIONS
|
||||
*(.bss)
|
||||
*(.bss.*)
|
||||
*(.dynbss)
|
||||
*(COMMON)
|
||||
|
||||
PROVIDE(__bss_end = .);
|
||||
}
|
||||
_end = .;
|
||||
|
@ -204,5 +204,7 @@
|
||||
|
||||
/* Board Peripheral Drivers */
|
||||
|
||||
#define BSP_USING_HDMI
|
||||
#define BSP_USING_HDMI_DISPLAY
|
||||
|
||||
#endif
|
||||
|
Loading…
x
Reference in New Issue
Block a user