add raspi4 lcd driver

This commit is contained in:
bigmagic 2020-11-27 14:30:25 +08:00
parent f8c8bc1c41
commit 5bcf84edcb
15 changed files with 3133 additions and 20 deletions

View File

@ -142,7 +142,9 @@ CONFIG_RT_USING_DFS_DEVFS=y
#
CONFIG_RT_USING_DEVICE_IPC=y
CONFIG_RT_PIPE_BUFSZ=512
# CONFIG_RT_USING_SYSTEM_WORKQUEUE is not set
CONFIG_RT_USING_SYSTEM_WORKQUEUE=y
CONFIG_RT_SYSTEM_WORKQUEUE_STACKSIZE=2048
CONFIG_RT_SYSTEM_WORKQUEUE_PRIORITY=23
CONFIG_RT_USING_SERIAL=y
CONFIG_RT_SERIAL_USING_DMA=y
CONFIG_RT_SERIAL_RB_BUFSZ=64
@ -175,7 +177,7 @@ CONFIG_RT_USING_SPI=y
CONFIG_RT_USING_WDT=y
# CONFIG_RT_USING_AUDIO is not set
# CONFIG_RT_USING_SENSOR is not set
# CONFIG_RT_USING_TOUCH is not set
CONFIG_RT_USING_TOUCH=y
# CONFIG_RT_USING_HWCRYPTO is not set
# CONFIG_RT_USING_PULSE_ENCODER is not set
# CONFIG_RT_USING_INPUT_CAPTURE is not set
@ -206,7 +208,13 @@ CONFIG_RT_USING_POSIX=y
#
# Socket abstraction layer
#
# CONFIG_RT_USING_SAL is not set
CONFIG_RT_USING_SAL=y
#
# protocol stack implement
#
CONFIG_SAL_USING_LWIP=y
CONFIG_SAL_USING_POSIX=y
#
# Network interface device
@ -616,8 +624,8 @@ CONFIG_BSP_USING_UART=y
CONFIG_RT_USING_UART0=y
# CONFIG_RT_USING_UART1 is not set
CONFIG_RT_USING_UART3=y
CONFIG_RT_USING_UART4=y
# CONFIG_RT_USING_UART5 is not set
# CONFIG_RT_USING_UART4 is not set
CONFIG_RT_USING_UART5=y
CONFIG_BSP_USING_GIC=y
CONFIG_BSP_USING_GIC400=y
# CONFIG_BSP_USING_GIC500 is not set
@ -625,10 +633,11 @@ CONFIG_BSP_USING_PIN=y
CONFIG_BSP_USING_SPI=y
CONFIG_BSP_USING_SPI0_BUS=y
CONFIG_BSP_USING_SPI0_DEVICE0=y
# CONFIG_BSP_USING_SPI0_DEVICE1 is not set
CONFIG_BSP_USING_SPI0_DEVICE1=y
CONFIG_BSP_USING_CORETIMER=y
# CONFIG_BSP_USING_SYSTIMER is not set
CONFIG_BSP_USING_WDT=y
CONFIG_BSP_USING_ETH=y
# CONFIG_BSP_USING_RTC is not set
CONFIG_BSP_USING_SDIO=y
CONFIG_BSP_USING_SDIO0=y
@ -636,5 +645,11 @@ CONFIG_BSP_USING_SDIO0=y
#
# Board Peripheral Drivers
#
CONFIG_BSP_USING_HDMI=y
CONFIG_BSP_USING_HDMI_DISPLAY=y
CONFIG_BSP_USING_LCD=y
# CONFIG_BSP_USING_HDMI_DISPLAY is not set
CONFIG_BSP_USING_DSI_DISPLAY=y
# CONFIG_BSP_USING_ILI9486 is not set
CONFIG_BSP_USING_TOUCH=y
CONFIG_BSP_USING_DSI_TOUCH_DEV=y
# CONFIG_BSP_USING_XPT_TOUCH_DEV is not set
# CONFIG_USING_LCD_CONSOLE is not set

View File

@ -93,6 +93,10 @@ menu "Hardware Drivers Config"
select RT_USING_WDT
default n
config BSP_USING_ETH
bool "Enable ETH"
default n
menuconfig BSP_USING_RTC
bool "Enable RTC"
select RT_USING_RTC
@ -119,14 +123,37 @@ menu "Hardware Drivers Config"
endmenu
menu "Board Peripheral Drivers"
menuconfig BSP_USING_HDMI
bool "Enable HDMI"
menuconfig BSP_USING_LCD
bool "Enable LCD"
default n
if BSP_USING_HDMI
if BSP_USING_LCD
config BSP_USING_HDMI_DISPLAY
bool "HDMI DISPLAY"
default n
config BSP_USING_DSI_DISPLAY
bool "DSI DISPLAY"
default n
config BSP_USING_ILI9486
bool "ILI9486 DISPLAY"
default n
endif
menuconfig BSP_USING_TOUCH
bool "Enable Touch"
default n
if BSP_USING_TOUCH
config BSP_USING_DSI_TOUCH_DEV
bool "DSI TOUCH"
default n
config BSP_USING_XPT_TOUCH_DEV
bool "XPT TOUCH"
default n
endif
config USING_LCD_CONSOLE
bool "LCD CONSOLE"
default n
endmenu
endmenu

View File

@ -1,9 +1,17 @@
# RT-Thread building script for component
from building import *
cwd = GetCurrentDir()
src = Glob('*.c') + Glob('*.cpp')
CPPPATH = [cwd, str(Dir('#'))]
if not GetDepend('BSP_USING_ETH'):
SrcRemove(src, ['drv_eth.c'])
if not GetDepend('BSP_USING_SPI'):
SrcRemove(src, ['drv_spi.c'])
if not GetDepend('BSP_USING_WDT'):
SrcRemove(src, ['drv_wdt.c'])
group = DefineGroup('driver', src, depend = [''], CPPPATH = CPPPATH)
# build for sub-directory

View File

@ -21,7 +21,8 @@
struct mem_desc platform_mem_desc[] = {
{0x0, 0x6400000, 0x0, NORMAL_MEM},
{0x8000000, 0x8800000, 0x8000000, DEVICE_MEM}, //mbox msg
{0x0EA00000, 0x0EE00000, 0x0EA00000, DEVICE_MEM}, //framebuffer
{0x0E000000, 0x0EE00000, 0x0E000000, DEVICE_MEM}, //framebuffer
{0x0F400000, 0x0FA00000, 0x0F400000, DEVICE_MEM}, //dsi_touch
{0xFD500000, 0xFDA00000, 0xFD500000, DEVICE_MEM}, //gmac
{0xFE000000, 0xFE400000, 0xFE000000, DEVICE_MEM}, //peripheral
{0xFF800000, 0xFFA00000, 0xFF800000, DEVICE_MEM} //gic

View File

@ -75,7 +75,6 @@ static rt_err_t raspi_spi_configure(struct rt_spi_device *device, struct rt_spi_
{
RT_ASSERT(cfg != RT_NULL);
RT_ASSERT(device != RT_NULL);
rt_uint16_t divider;
struct raspi_spi_device* hw_config = (struct raspi_spi_device *)(device->parent.user_data);
struct raspi_spi_hw_config *hwcfg = (struct raspi_spi_hw_config *)hw_config->spi_hw_config;
// spi clear fifo

View File

@ -0,0 +1,18 @@
# RT-Thread building script for component
from building import *
cwd = GetCurrentDir()
src = Glob('*.c') + Glob('*.cpp')
CPPPATH = [cwd]
if not (GetDepend('BSP_USING_HDMI_DISPLAY') or GetDepend('BSP_USING_DSI_DISPLAY')):
SrcRemove(src, ['drv_hdmi.c'])
if not GetDepend('BSP_USING_ILI9486'):
SrcRemove(src, ['drv_ili9486.c'])
if not GetDepend('USING_LCD_CONSOLE'):
SrcRemove(src, ['lcd_console.c'])
group = DefineGroup('drv_lcd', src, depend = ['BSP_USING_LCD'], CPPPATH = CPPPATH)
Return('group')

View File

@ -13,10 +13,14 @@
#include "mbox.h"
#include "drv_hdmi.h"
#ifdef BSP_USING_HDMI
#ifdef USING_LCD_CONSOLE
#include "lcd_console.h"
#endif
#if defined(BSP_USING_HDMI_DISPLAY) || defined(BSP_USING_DSI_DISPLAY)
#define LCD_WIDTH (800)
#define LCD_HEIGHT (480)
#define LCD_DEPTH (32)
#define LCD_DEPTH (4)
#define LCD_BPP (32)
#define TAG_ALLOCATE_BUFFER 0x00040001
@ -84,6 +88,9 @@ rt_size_t hdmi_fb_read(rt_device_t dev, rt_off_t pos, void *buf, rt_size_t size)
rt_size_t hdmi_fb_write(rt_device_t dev, rt_off_t pos, const void *buffer, rt_size_t size)
{
#ifdef USING_LCD_CONSOLE
fb_print((char*)buffer);
#endif
return size;
}
@ -105,7 +112,7 @@ rt_err_t hdmi_fb_control(rt_device_t dev, int cmd, void *args)
RT_ASSERT(info != RT_NULL);
info->pixel_format = RTGRAPHIC_PIXEL_FORMAT_RGB888;
info->bits_per_pixel= LCD_DEPTH;
info->bits_per_pixel= 32;
info->width = lcd->width;
info->height = lcd->height;
info->framebuffer = lcd->fb;
@ -285,12 +292,18 @@ void *bcm271x_mbox_fb_alloc(int width, int height, int bpp, int nrender)
mbox[34] = TAG_END;
mbox_call(8, MMU_DISABLE);
return (void *)((rt_uint32_t)(mbox[5] & 0x3fffffff));
}
int hdmi_fb_init(void)
{
_hdmi.fb = (rt_uint8_t *)bcm271x_mbox_fb_alloc(LCD_WIDTH, LCD_HEIGHT, LCD_BPP, 1);
if(_hdmi.fb == RT_NULL)
{
rt_kprintf("init dsi or hdmi err!\n");
return 0;
}
bcm271x_mbox_fb_setoffset(0, 0);
bcm271x_mbox_fb_set_porder(0);
_hdmi.width = LCD_WIDTH;
@ -299,8 +312,9 @@ int hdmi_fb_init(void)
_hdmi.pitch = 0;
_hdmi.pixel_format = RTGRAPHIC_PIXEL_FORMAT_RGB888;
rt_memset(_hdmi.fb, 0, LCD_WIDTH*LCD_HEIGHT*(LCD_BPP/8));
//rt_kprintf("_hdmi.fb is %p\n", _hdmi.fb);
rt_hdmi_fb_device_init(&_hdmi, "lcd");
rt_hdmi_fb_device_init(&_hdmi, "hdmi");
return 0;
}

View File

@ -0,0 +1,381 @@
/*
* Copyright (c) 2006-2020, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2020-11-08 bigmagic first version
*/
#include <rtthread.h>
#include <rtdevice.h>
#include <raspi4.h>
#include <drv_spi.h>
#include "drv_ili9486.h"
#ifdef USING_LCD_CONSOLE
#include "lcd_console.h"
#endif
//http://www.lcdwiki.com/MHS-3.5inch_RPi_Display
#define LCD_DEVICE_NAME ("spi0.0")
#define LCD_SPI_SEND_FAST
//waveshare
#define LCD_SCREEN_WIDTH (320)
#define LCD_SCREEN_HEIGHT (480)
#define LCD_RESET_PIN (25)
#define LCD_RS_PIN (24)
#define LCD_SPI_FREQ_MAX (125*1000*1000)
uint16_t LCD_HEIGHT = LCD_SCREEN_HEIGHT;
uint16_t LCD_WIDTH = LCD_SCREEN_WIDTH;
#define SCREEN_VERTICAL_1 (0)
#define SCREEN_HORIZONTAL_1 (1)
#define SCREEN_VERTICAL_2 (2)
#define SCREEN_HORIZONTAL_2 (3)
struct rt_semaphore lcd_spi_lock;
struct rt_semaphore lcd_lock;
//rgb565 lcd buffer
uint16_t _lcd_buffer[LCD_SCREEN_WIDTH * LCD_SCREEN_HEIGHT];
uint16_t send_buffer[LCD_SCREEN_WIDTH * LCD_SCREEN_HEIGHT];
static struct rt_spi_device *lcd_dev;
static inline void send_cmd(void)
{
rt_pin_write(LCD_RS_PIN, PIN_LOW);
}
static inline void send_data(void)
{
rt_pin_write(LCD_RS_PIN, PIN_HIGH);
}
void writeData16(rt_uint16_t data)
{
rt_uint8_t send_data[2];
send_data[1] = data & 0x00FF;
send_data[0] = ((data >> 8) & 0x00FF);
rt_spi_transfer(lcd_dev, &send_data[0], RT_NULL, 2);
}
void writeData(void* dev,rt_uint8_t data)
{
writeData16((rt_uint16_t)(data));
}
void writeCommand(void* dev, rt_uint8_t cmd)
{
send_cmd();
writeData16((rt_uint16_t)(cmd));
send_data();
}
void lcd_write_commmand(rt_uint8_t cmd)
{
writeCommand(lcd_dev, cmd);
}
void lcd_write_data(rt_uint8_t data)
{
writeData(lcd_dev, data);
}
/*Ser rotation of the screen - changes x0 and y0*/
static inline void lcd_set_rotation(uint8_t rotation)
{
writeCommand(lcd_dev, 0x36);
rt_thread_mdelay(100);
switch(rotation) {
case SCREEN_VERTICAL_1:
writeData(lcd_dev, 0x48);
LCD_WIDTH = 320;
LCD_HEIGHT = 480;
break;
case SCREEN_HORIZONTAL_1:
writeData(lcd_dev, 0x28);
LCD_WIDTH = 480;
LCD_HEIGHT = 320;
break;
case SCREEN_VERTICAL_2:
writeData(lcd_dev, 0x98);
LCD_WIDTH = 320;
LCD_HEIGHT = 480;
break;
case SCREEN_HORIZONTAL_2:
writeData(lcd_dev, 0xF8);
LCD_WIDTH = 480;
LCD_HEIGHT = 320;
break;
default:
//EXIT IF SCREEN ROTATION NOT VALID!
break;
}
if((rotation == SCREEN_VERTICAL_1) || (rotation == SCREEN_VERTICAL_2))
{
lcd_write_commmand(0x2A);
lcd_write_data(0x00);
lcd_write_data(0x00);
lcd_write_data(0x01);
lcd_write_data(0x3F);
lcd_write_commmand(0x2B);
lcd_write_data(0x00);
lcd_write_data(0x00);
lcd_write_data(0x01);
lcd_write_data(0xE0);
}
if((rotation == SCREEN_HORIZONTAL_1) || (rotation == SCREEN_HORIZONTAL_2))
{
lcd_write_commmand(0x2B);
lcd_write_data(0x00);
lcd_write_data(0x00);
lcd_write_data(0x01);
lcd_write_data(0x3F);
lcd_write_commmand(0x2A);
lcd_write_data(0x00);
lcd_write_data(0x00);
lcd_write_data(0x01);
lcd_write_data(0xE0);
}
}
static inline void fast_send_data(void)
{
rt_uint32_t ii = 0;
rt_uint32_t tx_index = 0;
char *tx_data = (char *)send_buffer;
rt_sem_take(&lcd_spi_lock, RT_WAITING_FOREVER);
SPI_REG_CS(SPI_0_BASE) &= (~(3 << 0));
SPI_REG_CLK(SPI_0_BASE) = 4;
SPI_REG_CS(SPI_0_BASE) |= SPI_CS_TA;
for(tx_index=0;tx_index<(LCD_SCREEN_WIDTH * LCD_SCREEN_HEIGHT) * 2;tx_index++)
{
for(ii = 0; ii < 32; ii = ii + 2)
{
SPI_REG_FIFO(SPI_0_BASE) = tx_data[tx_index + ii + 1];
SPI_REG_FIFO(SPI_0_BASE) = tx_data[tx_index + ii];
}
while (!(SPI_REG_CS(SPI_0_BASE) & SPI_CS_DONE));
SPI_REG_CS(SPI_0_BASE) |= (SPI_CS_CLEAR_TX) | (SPI_CS_CLEAR_RX);
tx_index = tx_index + 31;
}
SPI_REG_CS(SPI_0_BASE) |= (SPI_CS_CLEAR_TX) | (SPI_CS_CLEAR_RX);
SPI_REG_CS(SPI_0_BASE) &= (~SPI_CS_TA);
rt_sem_release(&lcd_spi_lock);
}
static inline void lcd_show(void)
{
lcd_write_commmand(0x2C); // Memory write?
//rt_thread_mdelay(150);
#ifdef LCD_SPI_SEND_FAST
fast_send_data();
#else
int i, j;
for (i = 0 ; i < 30 ; i ++)
{
uint16_t *tx_data = (uint16_t*)&send_buffer[5120* i];
int32_t data_sz = 5120;
for( j=0; j<data_sz; j++)
{
writeData16(tx_data[j]);
}
}
#endif
}
static void lcd_init(void)
{
writeCommand(lcd_dev, 0x28);
rt_thread_mdelay(150);
writeCommand(lcd_dev, 0x3A); // Interface Pixel Format
writeData(lcd_dev, 0x55); // 16 bit/pixe
writeCommand(lcd_dev, 0xC2); // Interface Pixel Format
writeData(lcd_dev, 0x44);
writeCommand(lcd_dev, 0xC5); // VCOM Control
writeData(lcd_dev, 0x00);
writeData(lcd_dev, 0x00);
writeData(lcd_dev, 0x00);
writeData(lcd_dev, 0x00);
writeCommand(lcd_dev, 0xE0); // PGAMCTRL(Positive Gamma Control)
writeData(lcd_dev, 0x0F);
writeData(lcd_dev, 0x1F);
writeData(lcd_dev, 0x1C);
writeData(lcd_dev, 0x0C);
writeData(lcd_dev, 0x0F);
writeData(lcd_dev, 0x08);
writeData(lcd_dev, 0x48);
writeData(lcd_dev, 0x98);
writeData(lcd_dev, 0x37);
writeData(lcd_dev, 0x0A);
writeData(lcd_dev, 0x13);
writeData(lcd_dev, 0x04);
writeData(lcd_dev, 0x11);
writeData(lcd_dev, 0x0D);
writeData(lcd_dev, 0x00);
writeCommand(lcd_dev, 0xE1); // NGAMCTRL (Negative Gamma Correction)
writeData(lcd_dev, 0x0F);
writeData(lcd_dev, 0x32);
writeData(lcd_dev, 0x2E);
writeData(lcd_dev, 0x0B);
writeData(lcd_dev, 0x0D);
writeData(lcd_dev, 0x05);
writeData(lcd_dev, 0x47);
writeData(lcd_dev, 0x75);
writeData(lcd_dev, 0x37);
writeData(lcd_dev, 0x06);
writeData(lcd_dev, 0x10);
writeData(lcd_dev, 0x03);
writeData(lcd_dev, 0x24);
writeData(lcd_dev, 0x20);
writeData(lcd_dev, 0x00);
writeCommand(lcd_dev, 0x11); // Sleep out, also SW reset
rt_thread_mdelay(150);
writeCommand(lcd_dev, 0x20); // Display Inversion OFF RPi LCD (A)
//writeCommand(lcd_dev, 0x21); // Display Inversion ON RPi LCD (B)
lcd_set_rotation(SCREEN_VERTICAL_2);
writeCommand(lcd_dev, 0x29); // Display ON
rt_thread_mdelay(150);
}
static inline void lcd_reset(void)
{
//Reset signal, low reset (pin22)
rt_pin_mode(LCD_RESET_PIN,PIN_MODE_OUTPUT);
rt_pin_write(LCD_RESET_PIN, PIN_HIGH);
rt_thread_mdelay(100);
rt_pin_write(LCD_RESET_PIN, PIN_LOW);
rt_thread_mdelay(100);
rt_pin_write(LCD_RESET_PIN, PIN_HIGH);
}
rt_err_t ili9486_open(rt_device_t dev, rt_uint16_t oflag)
{
return RT_EOK;
}
rt_err_t ili9486_close(rt_device_t dev)
{
return RT_EOK;
}
rt_size_t ili9486_read(rt_device_t dev, rt_off_t pos, void *buf, rt_size_t size)
{
return 0;
}
rt_size_t ili9486_write(rt_device_t dev, rt_off_t pos, const void *buffer, rt_size_t size)
{
#ifdef USING_LCD_CONSOLE
fb_print((char*)buffer);
#endif
return size;
}
rt_err_t ili9486_control(rt_device_t dev, int cmd, void *args)
{
rt_sem_take(&lcd_lock, RT_WAITING_FOREVER);
switch (cmd)
{
case RTGRAPHIC_CTRL_RECT_UPDATE:
{
struct rt_device_rect_info *info = (struct rt_device_rect_info*)args;
info = info;
rt_memcpy(send_buffer, _lcd_buffer, LCD_SCREEN_WIDTH * LCD_SCREEN_HEIGHT * 2);
lcd_show();
}
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_RGB565;
info->bits_per_pixel= 16;
info->width = LCD_WIDTH;
info->height = LCD_HEIGHT;
info->framebuffer = (void *)_lcd_buffer;//lcd->fb;
}
break;
}
rt_sem_release(&lcd_lock);
return RT_EOK;
}
#ifdef RT_USING_DEVICE_OPS
const static struct rt_device_ops ili9486_ops =
{
RT_NULL,
ili9486_open,
ili9486_close,
ili9486_read,
ili9486_write,
ili9486_control,
};
#endif
static int hw_ili9486_lcd_init(void)
{
struct rt_device *device;
device = rt_malloc(sizeof(struct rt_device));
rt_memset(device, 0, sizeof(struct rt_device));
lcd_reset();
rt_pin_mode(LCD_RS_PIN, PIN_MODE_OUTPUT);
lcd_dev = (struct rt_spi_device *)rt_device_find(LCD_DEVICE_NAME);
if (!lcd_dev)
{
rt_kprintf("no %s!\n", LCD_DEVICE_NAME);
}
lcd_dev->config.max_hz = LCD_SPI_FREQ_MAX;//125M
lcd_init();
rt_sem_init(&lcd_spi_lock, "lcd_spi_lock", 1, RT_IPC_FLAG_FIFO);
rt_sem_init(&lcd_lock, "lcd_spi_lock", 1, RT_IPC_FLAG_FIFO);
/* set device type */
device->type = RT_Device_Class_Graphic;
/* initialize device interface */
#ifdef RT_USING_DEVICE_OPS
device->ops = &ili9486_ops;
#else
device->init = RT_NULL;
device->open = ili9486_open;
device->close = ili9486_close;
device->read = ili9486_read;
device->write = ili9486_write;
device->control = ili9486_control;
#endif
/* register to device manager */
rt_device_register(device, "lcd", RT_DEVICE_FLAG_RDWR);
return RT_EOK;
}
INIT_DEVICE_EXPORT(hw_ili9486_lcd_init);

View File

@ -0,0 +1,13 @@
/*
* Copyright (c) 2006-2020, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2020-11-08 bigmagic first version
*/
#ifndef __DRV_ILI9486_H__
#define __DRV_ILI9486_H__
#endif//ILI9486

View File

@ -0,0 +1,258 @@
/*
* Copyright (c) 2006-2020, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2020-11-09 bigmagic first version
*/
#include "lcd_console.h"
#include "lcd_font_20.h"
#define LCD_CONSOLE_FLUSH_NOW 1
#define CONSOLE_NAME "hdmi"
#define COLOR_DELTA 0.05
#ifndef LCD_CONSOLE_FLUSH_NOW
static rt_thread_t console_flush_thread_tid = RT_NULL;
#define CONSOLE_FLUSH_THREAD_STACK_SIZE (1024)
#define CONSOLE_FLUSH_THREAD_PRIORITY (20)
#define CONSOLE_FLUSH_THREAD_TIMESLICE (10)
#define LCD_CONSOLE_DELAY (100) //100ms
#endif
static rt_device_t console_dev = RT_NULL;
static fb_t console_fb;
static rt_uint8_t* virt_buffer;
static rt_uint32_t CHAR_W = 8;
static rt_uint32_t CHAR_H = 20;
static int prev_x_offset = 0;
static void newline(fb_t* fb)
{
uint8_t* to;
uint8_t* from;
int i;
fb->y++;
fb->x = 5 * fb->depth;
if (fb->y == (fb->height / CHAR_H))
{
to = (uint8_t*) fb->vaddr;
from = to + (CHAR_H * fb->pitch);
for (i = 0; i < ((fb->height - CHAR_H) * fb->pitch); i++)
{
*to++ = *from++;
}
if(fb->depth >= 3)
{
uint32_t *addr_32bit = (uint32_t*) (fb->vaddr) + (fb->height - CHAR_H) * fb->width;
for (i = 0; i < (CHAR_H * fb->width); i++)
{
*addr_32bit++ = fb->back;
}
}
else
{
uint16_t *addr_16bit = (uint16_t*) (fb->vaddr) + (fb->height - CHAR_H) * fb->width;
for (i = 0; i < (CHAR_H * fb->width); i++)
{
*addr_16bit++ = fb->back;
}
}
fb->y = fb->y - 1;
}
}
static void fb_draw_char(fb_t *fb, char s)
{
unsigned char* addr = (unsigned char*) fb->vaddr;
unsigned char *glyph = (unsigned char *)lcd_console_font_dejavu_20_glyph_bitmap + lcd_console_font_dejavu_20_glyph_dsc[s - 32].glyph_index;
CHAR_W = lcd_console_font_dejavu_20_glyph_dsc[s - 32].w_px;
fb->x = fb->x + prev_x_offset * fb->depth;
int i, j, line, mask, bytesperline = (CHAR_W + 7) / 8;
int kk = (bytesperline) * 8;
prev_x_offset = CHAR_W + 2;
// calculate the offset on screen
int offs = (fb->y * CHAR_H * fb->pitch) + fb->x;
// display a character
for (j = 0; j < CHAR_H; j++)
{
// display one row
line = offs;
mask = 1;
mask = 0x80;
for (i = 0; i < kk; i++)
{
if(fb->depth >= 3)
{
*((unsigned int*) (addr + line)) = ((int) *(glyph + ((i)/8)) * 1) & mask ? fb->fore : fb->back;
}
else
{
*((unsigned short*) (addr + line)) = ((int) *(glyph + ((i)/8)) * 1) & mask ? fb->fore : fb->back;
}
mask >>= 1;
if(mask == 0)
{
mask = 0x80;
}
line += fb->depth;
}
// adjust to next line
glyph += bytesperline;
offs += fb->pitch;
}
}
void fb_print(char *s)
{
fb_t *fb = &console_fb;
// draw next character if it's not zero
while (*s)
{
// handle carrige return
if (*s == '\r')
{
fb->x = 5 * fb->depth;
}
else if (*s == '\n')
{
newline(fb);
}
else if (*s == '\t')
{
//tab is 8 spaces
if((fb->x + 8 * fb->depth) < (fb->width) * fb->depth)
{
fb->x = fb->x + 8 * fb->depth;
}
}
else if (*s == '\b')
{
if (fb->x > 5 * fb->depth)
{
fb->x = fb->x - prev_x_offset * fb->depth;
fb_draw_char(fb, ' ');
}
}
else if((fb->x + prev_x_offset * fb->depth + 5 * fb->depth) >= (fb->width * fb->depth))
{
newline(fb);
fb_draw_char(fb, *s);
}
else
{
fb_draw_char(fb, *s);
}
s++;
}
#ifdef LCD_CONSOLE_FLUSH_NOW
rt_memcpy((void *)fb->paddr, (void *)fb->vaddr, fb->size);
if(console_dev != RT_NULL)
{
rt_device_control(console_dev,RTGRAPHIC_CTRL_RECT_UPDATE, RT_NULL);
}
#endif
}
#ifndef LCD_CONSOLE_FLUSH_NOW
void lcd_console_task_entry(void *param)
{
fb_t *fb = (fb_t *)param;
while (1)
{
rt_memcpy((void *)fb->paddr, (void *)fb->vaddr, fb->size);
if(console_dev != RT_NULL)
{
rt_device_control(console_dev,RTGRAPHIC_CTRL_RECT_UPDATE, RT_NULL);
}
rt_thread_mdelay(LCD_CONSOLE_DELAY);
}
}
#endif
int lcd_console_init(void)
{
struct rt_device_graphic_info info;
console_dev = rt_device_find(CONSOLE_NAME);
if(console_dev == RT_NULL)
{
rt_kprintf("no console dev!\n");
return 0;
}
if(console_dev->ref_count >= 1)
{
rt_kprintf("lcd console has open!\n");
return 0;
}
rt_device_open(console_dev,RT_DEVICE_OFLAG_RDWR);
rt_device_control(console_dev, RTGRAPHIC_CTRL_GET_INFO, &info);
virt_buffer = (rt_uint8_t* )rt_malloc(info.width * info.height * (info.bits_per_pixel/8));
rt_memset(virt_buffer, 0 , info.width * info.height * (info.bits_per_pixel/8));
console_fb.width = info.width;
console_fb.height = info.height;
console_fb.pitch = info.width * (info.bits_per_pixel/8);
console_fb.vaddr = (rt_uint32_t)virt_buffer;
console_fb.paddr = (rt_uint32_t)info.framebuffer;
console_fb.size = info.width * info.height * (info.bits_per_pixel/8);
console_fb.depth = info.bits_per_pixel/8;
console_fb.x = 0;
console_fb.y = 0;
if(console_fb.depth >= 3)
{
console_fb.fore = CONSOLE_WHITE_32;
console_fb.back = CONSOLE_BLACK_32;
}
else
{
console_fb.fore = CONSOLE_WHITE_16;
console_fb.back = CONSOLE_BLACK_16;
}
#ifndef LCD_CONSOLE_FLUSH_NOW
console_flush_thread_tid = rt_thread_create("lcd_console", lcd_console_task_entry, (void *)&console_fb,
CONSOLE_FLUSH_THREAD_STACK_SIZE,
CONSOLE_FLUSH_THREAD_PRIORITY, CONSOLE_FLUSH_THREAD_TIMESLICE);
if (console_flush_thread_tid != RT_NULL)
rt_thread_startup(console_flush_thread_tid);
#endif
/*
* note:
* if serial console and lcd console together
* you can add /src/kservice.c:rt_kprintf
* #ifdef USING_LCD_CONSOLE
* fb_print((char*)rt_log_buf);
* #endif
*
* remove rt_console_set_device(CONSOLE_NAME);
*/
rt_console_set_device(CONSOLE_NAME);
rt_show_version();//show rt-thread logo
return 0;
}
INIT_APP_EXPORT(lcd_console_init);

View File

@ -0,0 +1,59 @@
/*
* Copyright (c) 2006-2020, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2020-11-09 bigmagic first version
*/
#ifndef __LCD_CONSOLE_H__
#define __LCD_CONSOLE_H__
#include <rtthread.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_32 COLOR_WHITE
#define CONSOLE_BLACK_32 COLOR_BLACK
#define CONSOLE_GREEN_32 COLOR_GREEN
#define CONSOLE_CYAN_32 COLOR_CYAN
#define CONSOLE_RED_32 COLOR_RED
#define RGB16(r, g, b) ((((r))<<11) | (((g))<<5) | ((b)))
#define CONSOLE_YELLOW_16 RGB16(0x1f,0x3f,0)
#define CONSOLE_WHITE_16 RGB16(0x1f,0x3f,0x1f)
#define CONSOLE_BLACK_16 RGB16(0,0,0)
#define CONSOLE_GREEN_16 RGB16(0,0x3f,0)
#define CONSOLE_CYAN_16 RGB16(0,0x3f,0x1f)
#define CONSOLE_RED_16 RGB16(0x1f,0,0)
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 vaddr;
rt_uint32_t paddr;
rt_uint32_t size;
} fb_t;
void fb_print(char *s);
int lcd_console_init(void);
#endif//CONSOLE

File diff suppressed because it is too large Load Diff

View File

@ -52,6 +52,13 @@ static void dsi_touch_thread_entry(void *param)
{
static volatile uint32_t touchbuf;
touchbuf = bcm271x_mbox_get_touch(); //0x0f436000
if(touchbuf == RT_NULL)
{
rt_kprintf("init dsi touch err!\n");
return;
}
while (1)
{
struct touch_regs *regs = (struct touch_regs *)touchbuf;

View File

@ -94,6 +94,9 @@
#define RT_USING_DEVICE_IPC
#define RT_PIPE_BUFSZ 512
#define RT_USING_SYSTEM_WORKQUEUE
#define RT_SYSTEM_WORKQUEUE_STACKSIZE 2048
#define RT_SYSTEM_WORKQUEUE_PRIORITY 23
#define RT_USING_SERIAL
#define RT_SERIAL_USING_DMA
#define RT_SERIAL_RB_BUFSZ 64
@ -106,6 +109,7 @@
#define RT_MMCSD_MAX_PARTITION 16
#define RT_USING_SPI
#define RT_USING_WDT
#define RT_USING_TOUCH
/* Using USB */
@ -119,6 +123,12 @@
/* Socket abstraction layer */
#define RT_USING_SAL
/* protocol stack implement */
#define SAL_USING_LWIP
#define SAL_USING_POSIX
/* Network interface device */
@ -240,21 +250,25 @@
#define BSP_USING_UART
#define RT_USING_UART0
#define RT_USING_UART3
#define RT_USING_UART4
#define RT_USING_UART5
#define BSP_USING_GIC
#define BSP_USING_GIC400
#define BSP_USING_PIN
#define BSP_USING_SPI
#define BSP_USING_SPI0_BUS
#define BSP_USING_SPI0_DEVICE0
#define BSP_USING_SPI0_DEVICE1
#define BSP_USING_CORETIMER
#define BSP_USING_WDT
#define BSP_USING_ETH
#define BSP_USING_SDIO
#define BSP_USING_SDIO0
/* Board Peripheral Drivers */
#define BSP_USING_HDMI
#define BSP_USING_HDMI_DISPLAY
#define BSP_USING_LCD
#define BSP_USING_DSI_DISPLAY
#define BSP_USING_TOUCH
#define BSP_USING_DSI_TOUCH_DEV
#endif