[Renesas]Add tft-lcd lvgl support
|
@ -33,8 +33,12 @@ if GetDepend(['BSP_USING_I2C', 'BSP_USING_HW_I2C']):
|
|||
src += ['drv_i2c.c']
|
||||
|
||||
if GetDepend(['BSP_USING_SPI']):
|
||||
src += ['drv_spi.c']
|
||||
src += ['drv_sci_spi.c']
|
||||
if GetDepend('BSP_USING_SCI_SPI0') or GetDepend('BSP_USING_SCI_SPI1') \
|
||||
or GetDepend('BSP_USING_SCI_SPI2') or GetDepend('BSP_USING_SCI_SPI3') \
|
||||
or GetDepend('BSP_USING_SCI_SPI4') or GetDepend('BSP_USING_SCI_SPI9'): \
|
||||
src += ['drv_sci_spi.c']
|
||||
else:
|
||||
src += ['drv_spi.c']
|
||||
|
||||
if GetDepend(['BSP_USING_ADC']):
|
||||
src += ['drv_adc.c']
|
||||
|
|
|
@ -50,6 +50,20 @@ menu "Hardware Drivers Config"
|
|||
endif
|
||||
endif
|
||||
|
||||
menuconfig BSP_USING_SPI
|
||||
bool "Enable SPI BUS"
|
||||
default n
|
||||
select RT_USING_SPI
|
||||
if BSP_USING_SPI
|
||||
config BSP_USING_SPI0
|
||||
bool "Enable SPI0 BUS"
|
||||
default n
|
||||
|
||||
config BSP_USING_SPI1
|
||||
bool "Enable SPI1 BUS"
|
||||
default n
|
||||
endif
|
||||
|
||||
menuconfig BSP_USING_FS
|
||||
bool "Enable File System"
|
||||
select RT_USING_DFS
|
||||
|
@ -80,11 +94,27 @@ menu "Hardware Drivers Config"
|
|||
select BSP_USING_GPIO
|
||||
default n
|
||||
|
||||
config BSP_USING_LVGL
|
||||
config BSP_USING_SPI_LCD
|
||||
bool "Enable SPI LCD"
|
||||
select BSP_USING_GPIO
|
||||
select BSP_USING_SPI
|
||||
select BSP_USING_SPI0
|
||||
default n
|
||||
|
||||
menuconfig BSP_USING_LVGL
|
||||
bool "Enable LVGL for LCD"
|
||||
select BSP_USING_LCD
|
||||
select PKG_USING_LVGL
|
||||
default n
|
||||
if BSP_USING_LVGL
|
||||
config BSP_USING_LCD_ILI9431
|
||||
bool "Enable LVGL for LCD_ILI9431"
|
||||
select BSP_USING_SPI_LCD
|
||||
default n
|
||||
config BSP_USING_LCD_RGB
|
||||
bool "Enable LVGL for LCD_RGB565"
|
||||
select BSP_USING_LCD
|
||||
default n
|
||||
endif
|
||||
|
||||
if BSP_USING_LVGL
|
||||
config BSP_USING_LVGL_DEMO
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2006-2021, RT-Thread Development Team
|
||||
* Copyright (c) 2006-2023, RT-Thread Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2006-2021, RT-Thread Development Team
|
||||
* Copyright (c) 2006-2023, RT-Thread Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
|
|
|
@ -1,16 +1,18 @@
|
|||
/*
|
||||
* Copyright (c) 2006-2021, RT-Thread Development Team
|
||||
* Copyright (c) 2006-2023, RT-Thread Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2021-10-18 Meco Man First version
|
||||
* 2023-02-22 Rbb666 First version
|
||||
*/
|
||||
|
||||
#ifndef LV_CONF_H
|
||||
#define LV_CONF_H
|
||||
|
||||
#include <rtconfig.h>
|
||||
|
||||
/* Enable additional color format support */
|
||||
#define DLG_LVGL_CF 1
|
||||
|
||||
|
@ -20,10 +22,19 @@
|
|||
|
||||
#define LV_USE_PERF_MONITOR 1
|
||||
#define LV_COLOR_DEPTH 16
|
||||
#define LV_HOR_RES_MAX 480
|
||||
#define LV_VER_RES_MAX 272
|
||||
|
||||
#define DLG_LVGL_USE_GPU_RA6M3 0
|
||||
#ifdef BSP_USING_SPI_LCD
|
||||
#define LV_HOR_RES_MAX 240
|
||||
#define LV_VER_RES_MAX 320
|
||||
#define LV_COLOR_16_SWAP 1
|
||||
#define LV_DPI_DEF 99
|
||||
#else
|
||||
#define LV_HOR_RES_MAX 480
|
||||
#define LV_VER_RES_MAX 272
|
||||
#define LV_DPI_DEF 89
|
||||
#endif
|
||||
|
||||
#define DLG_LVGL_USE_GPU_RA6M3 0
|
||||
|
||||
#ifdef PKG_USING_LV_MUSIC_DEMO
|
||||
/* music player demo */
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2006-2022, RT-Thread Development Team
|
||||
* Copyright (c) 2006-2023, RT-Thread Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
|
@ -8,13 +8,18 @@
|
|||
* 2021-11-24 Rbb666 The first version
|
||||
*/
|
||||
#include <lvgl.h>
|
||||
#include "lcd_port.h"
|
||||
#include "hal_data.h"
|
||||
|
||||
#if DLG_LVGL_USE_GPU_RA6M3
|
||||
#include "lv_port_gpu.h"
|
||||
#endif
|
||||
|
||||
#ifdef BSP_USING_SPI_LCD
|
||||
#include "lcd_ili9341.h"
|
||||
#else
|
||||
#include "lcd_port.h"
|
||||
#endif
|
||||
|
||||
#define COLOR_BUFFER (LV_HOR_RES_MAX * LV_VER_RES_MAX / 4)
|
||||
|
||||
/*A static or global variable to store the buffers*/
|
||||
|
@ -22,42 +27,13 @@ static lv_disp_draw_buf_t disp_buf;
|
|||
|
||||
/*Descriptor of a display driver*/
|
||||
static lv_disp_drv_t disp_drv;
|
||||
static struct rt_device_graphic_info info;
|
||||
|
||||
/*Static or global buffer(s). The second buffer is optional*/
|
||||
// 0x1FFE0000 0x20040000
|
||||
__attribute__((section(".ARM.__at_0x1FFE0000"))) lv_color_t buf_1[COLOR_BUFFER];
|
||||
|
||||
static uint8_t lvgl_ready_done = RT_EBUSY;
|
||||
|
||||
static rt_device_t device;
|
||||
static struct rt_device_graphic_info info;
|
||||
static rt_sem_t trans_done_semphr = RT_NULL;
|
||||
|
||||
void _ra_port_display_callback(display_callback_args_t *p_args)
|
||||
{
|
||||
if (lvgl_ready_done != RT_EOK)
|
||||
return;
|
||||
|
||||
if (DISPLAY_EVENT_LINE_DETECTION == p_args->event)
|
||||
{
|
||||
/* enter interrupt */
|
||||
rt_interrupt_enter();
|
||||
|
||||
lv_disp_flush_ready((lv_disp_drv_t *)&disp_drv);
|
||||
|
||||
rt_sem_release(trans_done_semphr);
|
||||
|
||||
/* exit interrupt */
|
||||
rt_interrupt_leave();
|
||||
}
|
||||
}
|
||||
|
||||
// Wait until Vsync is triggered through callback function
|
||||
void vsync_wait(void)
|
||||
{
|
||||
rt_sem_take(trans_done_semphr, RT_WAITING_FOREVER);
|
||||
}
|
||||
|
||||
#if !DLG_LVGL_USE_GPU_RA6M3
|
||||
static void color_to16_maybe(lv_color16_t *dst, lv_color_t *src)
|
||||
{
|
||||
#if (LV_COLOR_DEPTH == 16)
|
||||
|
@ -68,9 +44,15 @@ static void color_to16_maybe(lv_color16_t *dst, lv_color_t *src)
|
|||
dst->ch.red = src->ch.red;
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
static void disp_flush(lv_disp_drv_t *disp_drv, const lv_area_t *area, lv_color_t *color_p)
|
||||
{
|
||||
#ifdef BSP_USING_SPI_LCD
|
||||
lcd_fill_array_spi(area->x1, area->y1, area->x2, area->y2, color_p);
|
||||
#elif DLG_LVGL_USE_GPU_RA6M3
|
||||
lv_port_gpu_flush();
|
||||
#else
|
||||
int x1, x2, y1, y2;
|
||||
|
||||
x1 = area->x1;
|
||||
|
@ -98,10 +80,6 @@ static void disp_flush(lv_disp_drv_t *disp_drv, const lv_area_t *area, lv_color_
|
|||
uint32_t y;
|
||||
long int location = 0;
|
||||
|
||||
#if DLG_LVGL_USE_GPU_RA6M3
|
||||
lv_port_gpu_flush();
|
||||
#endif
|
||||
|
||||
/* color_p is a buffer pointer; the buffer is provided by LVGL */
|
||||
lv_color16_t *fbp16 = (lv_color16_t *)info.framebuffer;
|
||||
|
||||
|
@ -116,12 +94,16 @@ static void disp_flush(lv_disp_drv_t *disp_drv, const lv_area_t *area, lv_color_
|
|||
|
||||
color_p += x2 - act_x2;
|
||||
}
|
||||
|
||||
vsync_wait();
|
||||
#endif
|
||||
lv_disp_flush_ready(disp_drv);
|
||||
}
|
||||
|
||||
void lv_port_disp_init(void)
|
||||
{
|
||||
#ifdef BSP_USING_SPI_LCD
|
||||
spi_lcd_init();
|
||||
#else
|
||||
static rt_device_t device;
|
||||
/* LCD Device Init */
|
||||
device = rt_device_find("lcd");
|
||||
RT_ASSERT(device != RT_NULL);
|
||||
|
@ -133,22 +115,15 @@ void lv_port_disp_init(void)
|
|||
|
||||
RT_ASSERT(info.bits_per_pixel == 8 || info.bits_per_pixel == 16 ||
|
||||
info.bits_per_pixel == 24 || info.bits_per_pixel == 32);
|
||||
|
||||
trans_done_semphr = rt_sem_create("lvgl_sem", 1, RT_IPC_FLAG_PRIO);
|
||||
if (trans_done_semphr == RT_NULL)
|
||||
{
|
||||
rt_kprintf("create transform done semphr failed.\n");
|
||||
return;
|
||||
}
|
||||
|
||||
#endif
|
||||
/*Initialize `disp_buf` with the buffer(s). With only one buffer use NULL instead buf_2 */
|
||||
lv_disp_draw_buf_init(&disp_buf, buf_1, NULL, COLOR_BUFFER);
|
||||
|
||||
lv_disp_drv_init(&disp_drv); /*Basic initialization*/
|
||||
|
||||
/*Set the resolution of the display*/
|
||||
disp_drv.hor_res = LCD_WIDTH;
|
||||
disp_drv.ver_res = LCD_HEIGHT;
|
||||
disp_drv.hor_res = LV_HOR_RES_MAX;
|
||||
disp_drv.ver_res = LV_VER_RES_MAX;
|
||||
|
||||
/*Set a display buffer*/
|
||||
disp_drv.draw_buf = &disp_buf;
|
||||
|
@ -163,6 +138,4 @@ void lv_port_disp_init(void)
|
|||
|
||||
/*Finally register the driver*/
|
||||
lv_disp_drv_register(&disp_drv);
|
||||
|
||||
lvgl_ready_done = RT_EOK;
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2006-2022, RT-Thread Development Team
|
||||
* Copyright (c) 2006-2023, RT-Thread Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
|
@ -12,5 +12,4 @@
|
|||
|
||||
void lv_port_indev_init(void)
|
||||
{
|
||||
static lv_indev_drv_t indev_drv;
|
||||
}
|
||||
|
|
|
@ -1,22 +1,12 @@
|
|||
|
||||
import os
|
||||
from building import *
|
||||
import rtconfig
|
||||
|
||||
cwd = GetCurrentDir()
|
||||
objs = []
|
||||
cwd = GetCurrentDir()
|
||||
|
||||
src = []
|
||||
list = os.listdir(cwd)
|
||||
for item in list:
|
||||
if os.path.isfile(os.path.join(cwd, item, 'SConscript')):
|
||||
objs = objs + SConscript(os.path.join(item, 'SConscript'))
|
||||
|
||||
if GetDepend(['BSP_USING_RW007']):
|
||||
src += Glob('drv_rw007.c')
|
||||
|
||||
CPPPATH = [cwd]
|
||||
LOCAL_CFLAGS = ''
|
||||
|
||||
if rtconfig.PLATFORM in ['gcc', 'armclang']:
|
||||
LOCAL_CFLAGS += ' -std=c99'
|
||||
elif rtconfig.PLATFORM in ['armcc']:
|
||||
LOCAL_CFLAGS += ' --c99'
|
||||
|
||||
group = DefineGroup('Drivers', src, depend = [], CPPPATH = CPPPATH, LOCAL_CFLAGS = LOCAL_CFLAGS)
|
||||
|
||||
Return('group')
|
||||
Return('objs')
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2006-2021, RT-Thread Development Team
|
||||
* Copyright (c) 2006-2023, RT-Thread Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
|
||||
from building import *
|
||||
import rtconfig
|
||||
|
||||
cwd = GetCurrentDir()
|
||||
|
||||
src = []
|
||||
|
||||
if GetDepend(['BSP_USING_SPI_LCD']):
|
||||
src += Glob('lcd_ili9341.c')
|
||||
|
||||
CPPPATH = [cwd]
|
||||
LOCAL_CFLAGS = ''
|
||||
|
||||
if rtconfig.PLATFORM in ['gcc', 'armclang']:
|
||||
LOCAL_CFLAGS += ' -std=c99'
|
||||
elif rtconfig.PLATFORM in ['armcc']:
|
||||
LOCAL_CFLAGS += ' --c99'
|
||||
|
||||
group = DefineGroup('ili9341', src, depend = [], CPPPATH = CPPPATH, LOCAL_CFLAGS = LOCAL_CFLAGS)
|
||||
|
||||
Return('group')
|
|
@ -0,0 +1,343 @@
|
|||
/*
|
||||
* Copyright (c) 2006-2023, RT-Thread Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2023-02-23 Rbb666 First version
|
||||
*/
|
||||
#include <rtdevice.h>
|
||||
|
||||
#ifdef BSP_USING_SPI_LCD
|
||||
#include "lcd_ili9341.h"
|
||||
#include "drivers/spi.h"
|
||||
|
||||
/* 2.8 inch LCD module */
|
||||
/* res pin -> P4_14 */
|
||||
/* d/c pin -> P4_13 */
|
||||
/* cs pin -> P4_05 */
|
||||
/* sda pin -> p4_11 */
|
||||
/* scl pin -> p4_12 */
|
||||
|
||||
_lcd_dev lcddev;
|
||||
static struct rt_spi_device *lcd_dev;
|
||||
|
||||
static void rt_hw_spi_device_attach(const char *bus_name, const char *device_name, void *cs_Pin)
|
||||
{
|
||||
struct rt_spi_device *spi_device;
|
||||
RT_ASSERT(device_name != NULL && bus_name != NULL);
|
||||
spi_device = (struct rt_spi_device *)rt_malloc(sizeof(struct rt_spi_device));
|
||||
RT_ASSERT(spi_device != RT_NULL);
|
||||
rt_err_t err = rt_spi_bus_attach_device(spi_device, device_name, bus_name, cs_Pin);
|
||||
if (RT_EOK != err)
|
||||
{
|
||||
rt_kprintf("%s attach failed.", bus_name);
|
||||
}
|
||||
}
|
||||
|
||||
rt_err_t spi_lcd_init(void)
|
||||
{
|
||||
rt_err_t res = RT_EOK;
|
||||
|
||||
rt_hw_spi_device_attach("spi0", "spi30", (void *)LCD_CS_PIN);
|
||||
lcd_dev = (struct rt_spi_device *)rt_device_find("spi30");
|
||||
if (lcd_dev != RT_NULL)
|
||||
{
|
||||
struct rt_spi_configuration spi_config;
|
||||
spi_config.data_width = 8;
|
||||
spi_config.max_hz = 20 * 1000 * 1000;
|
||||
spi_config.mode = RT_SPI_MASTER | RT_SPI_MODE_0 | RT_SPI_MSB;
|
||||
rt_spi_configure(lcd_dev, &spi_config);
|
||||
}
|
||||
else
|
||||
{
|
||||
res = RT_ERROR;
|
||||
}
|
||||
|
||||
LCD_Init();
|
||||
|
||||
return res;
|
||||
}
|
||||
MSH_CMD_EXPORT(spi_lcd_init, lcd_spi_init);
|
||||
|
||||
void LCD_RESET(void)
|
||||
{
|
||||
LCD_RES_CLR;
|
||||
DELAY(100);
|
||||
LCD_RES_SET;
|
||||
DELAY(100);
|
||||
}
|
||||
|
||||
void LCD_WR_REG(uint8_t reg)
|
||||
{
|
||||
LCD_DC_CLR;
|
||||
rt_spi_send(lcd_dev, ®, 1);
|
||||
LCD_DC_SET;
|
||||
}
|
||||
|
||||
void LCD_WR_DATA(uint8_t data)
|
||||
{
|
||||
LCD_DC_SET;
|
||||
rt_spi_send(lcd_dev, &data, 1);
|
||||
}
|
||||
|
||||
void LCD_ReadData(uint8_t *data, uint16_t length)
|
||||
{
|
||||
LCD_DC_SET;
|
||||
rt_spi_transfer(lcd_dev, RT_NULL, &data, length);
|
||||
}
|
||||
|
||||
void LCD_WriteReg(uint8_t reg, uint16_t regdata)
|
||||
{
|
||||
LCD_WR_REG(reg);
|
||||
LCD_WR_DATA(regdata);
|
||||
}
|
||||
|
||||
void LCD_WriteRAM_Prepare(void)
|
||||
{
|
||||
LCD_WR_REG(lcddev.wramcmd);
|
||||
}
|
||||
|
||||
void LCD_WriteData_16Bit(uint16_t Data)
|
||||
{
|
||||
uint8_t buf[2];
|
||||
LCD_DC_SET;
|
||||
buf[0] = Data >> 8;
|
||||
buf[1] = Data & 0xff;
|
||||
rt_spi_send(lcd_dev, buf, 2);
|
||||
}
|
||||
|
||||
void LCD_direction(uint8_t direction)
|
||||
{
|
||||
lcddev.setxcmd = 0x2A;
|
||||
lcddev.setycmd = 0x2B;
|
||||
lcddev.wramcmd = 0x2C;
|
||||
switch (direction)
|
||||
{
|
||||
case 0:
|
||||
lcddev.width = LCD_W;
|
||||
lcddev.height = LCD_H;
|
||||
LCD_WriteReg(0x36, (1 << 3) | (0 << 6) | (0 << 7)); /* BGR==1,MY==0,MX==0,MV==0 */
|
||||
break;
|
||||
case 1:
|
||||
lcddev.width = LCD_H;
|
||||
lcddev.height = LCD_W;
|
||||
LCD_WriteReg(0x36, (1 << 3) | (0 << 7) | (1 << 6) | (1 << 5)); /* BGR==1,MY==1,MX==0,MV==1 */
|
||||
break;
|
||||
case 2:
|
||||
lcddev.width = LCD_W;
|
||||
lcddev.height = LCD_H;
|
||||
LCD_WriteReg(0x36, (1 << 3) | (1 << 6) | (1 << 7)); /* BGR==1,MY==0,MX==0,MV==0 */
|
||||
break;
|
||||
case 3:
|
||||
lcddev.width = LCD_H;
|
||||
lcddev.height = LCD_W;
|
||||
LCD_WriteReg(0x36, (1 << 3) | (1 << 7) | (1 << 5)); /* BGR==1,MY==1,MX==0,MV==1 */
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void LCD_SetWindows(uint16_t xStar, uint16_t yStar, uint16_t xEnd, uint16_t yEnd)
|
||||
{
|
||||
LCD_WR_REG(lcddev.setxcmd);
|
||||
LCD_WR_DATA(xStar >> 8);
|
||||
LCD_WR_DATA(0x00FF & xStar);
|
||||
LCD_WR_DATA(xEnd >> 8);
|
||||
LCD_WR_DATA(0x00FF & xEnd);
|
||||
|
||||
LCD_WR_REG(lcddev.setycmd);
|
||||
LCD_WR_DATA(yStar >> 8);
|
||||
LCD_WR_DATA(0x00FF & yStar);
|
||||
LCD_WR_DATA(yEnd >> 8);
|
||||
LCD_WR_DATA(0x00FF & yEnd);
|
||||
|
||||
LCD_WriteRAM_Prepare();
|
||||
}
|
||||
|
||||
void LCD_SetCursor(uint16_t Xpos, uint16_t Ypos)
|
||||
{
|
||||
LCD_SetWindows(Xpos, Ypos, Xpos, Ypos);
|
||||
}
|
||||
|
||||
void LCD_Clear(uint16_t Color)
|
||||
{
|
||||
unsigned int i, m;
|
||||
uint8_t buf[80];
|
||||
|
||||
for (i = 0; i < 40; i++)
|
||||
{
|
||||
buf[2 * i] = Color >> 8;
|
||||
buf[2 * i + 1] = Color & 0xff;
|
||||
}
|
||||
|
||||
LCD_SetWindows(0, 0, lcddev.width - 1, lcddev.height - 1);
|
||||
|
||||
LCD_DC_SET;
|
||||
for (i = 0; i < lcddev.height; i++)
|
||||
{
|
||||
for (m = 0; m < lcddev.width;)
|
||||
{
|
||||
m += 40;
|
||||
rt_spi_send(lcd_dev, buf, 80);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void LCD_Fill(uint16_t xsta, uint16_t ysta, uint16_t xend, uint16_t yend, uint16_t color)
|
||||
{
|
||||
uint16_t i, j;
|
||||
LCD_SetWindows(xsta, ysta, xend - 1, yend - 1);
|
||||
for (i = ysta; i < yend; i++)
|
||||
{
|
||||
for (j = xsta; j < xend; j++)
|
||||
{
|
||||
LCD_WriteData_16Bit(color);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void lcd_fill_array_spi(uint16_t Xstart, uint16_t Ystart, uint16_t Xend, uint16_t Yend, void *Image)
|
||||
{
|
||||
rt_uint32_t size = 0;
|
||||
|
||||
size = (Xend - Xstart + 1) * (Yend - Ystart + 1) * 2;/*16bit*/
|
||||
LCD_SetWindows(Xstart, Ystart, Xend, Yend);
|
||||
LCD_DC_SET;
|
||||
|
||||
rt_spi_send(lcd_dev, Image, size);
|
||||
}
|
||||
|
||||
static void _ili9341_init(void)
|
||||
{
|
||||
LCD_WR_REG(0xCF);
|
||||
LCD_WR_DATA(0x00);
|
||||
LCD_WR_DATA(0X83);
|
||||
LCD_WR_DATA(0X30);
|
||||
|
||||
LCD_WR_REG(0xED);
|
||||
LCD_WR_DATA(0x64);
|
||||
LCD_WR_DATA(0x03);
|
||||
LCD_WR_DATA(0X12);
|
||||
LCD_WR_DATA(0X81);
|
||||
|
||||
LCD_WR_REG(0xE8);
|
||||
LCD_WR_DATA(0x85);
|
||||
LCD_WR_DATA(0x00);
|
||||
LCD_WR_DATA(0x79);
|
||||
|
||||
LCD_WR_REG(0xCB);
|
||||
LCD_WR_DATA(0x39);
|
||||
LCD_WR_DATA(0x2C);
|
||||
LCD_WR_DATA(0x00);
|
||||
LCD_WR_DATA(0x34);
|
||||
LCD_WR_DATA(0x02);
|
||||
|
||||
LCD_WR_REG(0xF7);
|
||||
LCD_WR_DATA(0x20);
|
||||
|
||||
LCD_WR_REG(0xEA);
|
||||
LCD_WR_DATA(0x00);
|
||||
LCD_WR_DATA(0x00);
|
||||
|
||||
LCD_WR_REG(0xC0); /* Power control */
|
||||
LCD_WR_DATA(0x26); /* VRH[5:0] */
|
||||
|
||||
LCD_WR_REG(0xC1); /* Power control */
|
||||
LCD_WR_DATA(0x11); /* SAP[2:0];BT[3:0] */
|
||||
|
||||
LCD_WR_REG(0xC5); /* VCM control */
|
||||
LCD_WR_DATA(0x35);
|
||||
LCD_WR_DATA(0x3E);
|
||||
|
||||
LCD_WR_REG(0xC7); /* VCM control2 */
|
||||
LCD_WR_DATA(0XBE);
|
||||
|
||||
LCD_WR_REG(0x36); /* Memory Access Control */
|
||||
LCD_WR_DATA(0x28);
|
||||
|
||||
LCD_WR_REG(0x3A);
|
||||
LCD_WR_DATA(0x55);
|
||||
|
||||
LCD_WR_REG(0xB1);
|
||||
LCD_WR_DATA(0x00);
|
||||
LCD_WR_DATA(0x1B);
|
||||
|
||||
LCD_WR_REG(0xB6); /* Display Function Control */
|
||||
LCD_WR_DATA(0x0A);
|
||||
LCD_WR_DATA(0xA2);
|
||||
|
||||
LCD_WR_REG(0xF2); /* 3Gamma Function Disable */
|
||||
LCD_WR_DATA(0x08);
|
||||
|
||||
LCD_WR_REG(0x26); /* Gamma curve selected */
|
||||
LCD_WR_DATA(0x01);
|
||||
|
||||
LCD_WR_REG(0xE0); /* set Gamma */
|
||||
LCD_WR_DATA(0X1F);
|
||||
LCD_WR_DATA(0X1A);
|
||||
LCD_WR_DATA(0X18);
|
||||
LCD_WR_DATA(0X0A);
|
||||
LCD_WR_DATA(0X0F);
|
||||
LCD_WR_DATA(0X06);
|
||||
LCD_WR_DATA(0X45);
|
||||
LCD_WR_DATA(0X87);
|
||||
LCD_WR_DATA(0X32);
|
||||
LCD_WR_DATA(0X0A);
|
||||
LCD_WR_DATA(0X07);
|
||||
LCD_WR_DATA(0X02);
|
||||
LCD_WR_DATA(0X07);
|
||||
LCD_WR_DATA(0X05);
|
||||
LCD_WR_DATA(0X00);
|
||||
|
||||
LCD_WR_REG(0xE1); /* set Gamma */
|
||||
LCD_WR_DATA(0X00);
|
||||
LCD_WR_DATA(0X25);
|
||||
LCD_WR_DATA(0X27);
|
||||
LCD_WR_DATA(0X05);
|
||||
LCD_WR_DATA(0X10);
|
||||
LCD_WR_DATA(0X09);
|
||||
LCD_WR_DATA(0X3A);
|
||||
LCD_WR_DATA(0X78);
|
||||
LCD_WR_DATA(0X4D);
|
||||
LCD_WR_DATA(0X05);
|
||||
LCD_WR_DATA(0X18);
|
||||
LCD_WR_DATA(0X0D);
|
||||
LCD_WR_DATA(0X38);
|
||||
LCD_WR_DATA(0X3A);
|
||||
LCD_WR_DATA(0X2F);
|
||||
|
||||
LCD_WR_REG(0x29);
|
||||
}
|
||||
|
||||
void LCD_Init(void)
|
||||
{
|
||||
LCD_RESET(); /* LCD Hardware Reset */
|
||||
LCD_WR_REG(0x11); /* Sleep out */
|
||||
DELAY(120); /* Delay 120ms */
|
||||
_ili9341_init();
|
||||
|
||||
LCD_direction(USE_HORIZONTAL);
|
||||
}
|
||||
|
||||
static uint16_t color_array[] =
|
||||
{
|
||||
WHITE, BLACK, BLUE, BRED,
|
||||
GRED, GBLUE, RED, YELLOW
|
||||
};
|
||||
|
||||
static rt_err_t lcd_spi_test()
|
||||
{
|
||||
uint8_t index = 0;
|
||||
for (index = 0; index < sizeof(color_array) / sizeof(color_array[0]); index++)
|
||||
{
|
||||
LCD_Clear(color_array[index]);
|
||||
DELAY(200);
|
||||
}
|
||||
|
||||
return RT_EOK;
|
||||
}
|
||||
MSH_CMD_EXPORT(lcd_spi_test, lcd_spi_test);
|
||||
#endif
|
|
@ -0,0 +1,85 @@
|
|||
/*
|
||||
* Copyright (c) 2006-2023, RT-Thread Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2023-02-23 Rbb666 First version
|
||||
*/
|
||||
#ifndef __LCD_ILI9341_H__
|
||||
#define __LCD_ILI9341_H__
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
#include "hal_data.h"
|
||||
#include <stdint.h>
|
||||
#include <rtthread.h>
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint16_t width; /* LCD width */
|
||||
uint16_t height; /* LCD high */
|
||||
uint32_t id; /* LCD ID */
|
||||
uint8_t dir; /* 0:Vertical | 1:Vertical */
|
||||
uint16_t wramcmd; /* gram cmd */
|
||||
uint16_t setxcmd; /* set x cmd */
|
||||
uint16_t setycmd; /* set y cmd */
|
||||
} _lcd_dev;
|
||||
|
||||
/* LCD param */
|
||||
extern _lcd_dev lcddev;
|
||||
|
||||
#define USE_HORIZONTAL 0 /* 0-0째|1-90째|2-180째|-270째 */
|
||||
|
||||
/* lcd size */
|
||||
#define LCD_W 240
|
||||
#define LCD_H 320
|
||||
|
||||
#define WHITE 0xFFFF
|
||||
#define BLACK 0x0000
|
||||
#define BLUE 0x001F
|
||||
#define BRED 0XF81F
|
||||
#define GRED 0XFFE0
|
||||
#define GBLUE 0X07FF
|
||||
#define RED 0xF800
|
||||
#define MAGENTA 0xF81F
|
||||
#define GREEN 0x07E0
|
||||
#define CYAN 0x7FFF
|
||||
#define YELLOW 0xFFE0
|
||||
#define BROWN 0XBC40
|
||||
#define BRRED 0XFC07
|
||||
#define GRAY 0X8430
|
||||
|
||||
#define LCD_DC_PIN BSP_IO_PORT_04_PIN_13
|
||||
#define LCD_RES_PIN BSP_IO_PORT_04_PIN_14
|
||||
#define LCD_CS_PIN BSP_IO_PORT_04_PIN_05
|
||||
|
||||
#define LCD_DC_CLR rt_pin_write(LCD_DC_PIN, PIN_LOW)
|
||||
#define LCD_DC_SET rt_pin_write(LCD_DC_PIN, PIN_HIGH)
|
||||
#define LCD_RES_CLR rt_pin_write(LCD_RES_PIN, PIN_LOW)
|
||||
#define LCD_RES_SET rt_pin_write(LCD_RES_PIN, PIN_HIGH)
|
||||
#define DELAY rt_thread_mdelay
|
||||
|
||||
void LCD_RESET(void);
|
||||
void LCD_WR_REG(uint8_t reg);
|
||||
void LCD_WR_DATA(uint8_t data);
|
||||
void LCD_WriteReg(uint8_t reg, uint16_t regdata);
|
||||
void LCD_WriteRAM_Prepare(void);
|
||||
void LCD_WriteData_16Bit(uint16_t Data);
|
||||
void LCD_direction(uint8_t direction);
|
||||
void LCD_SetWindows(uint16_t xStar, uint16_t yStar, uint16_t xEnd, uint16_t yEnd);
|
||||
void LCD_SetCursor(uint16_t Xpos, uint16_t Ypos);
|
||||
void LCD_Clear(uint16_t Color);
|
||||
void LCD_Fill(uint16_t xsta, uint16_t ysta, uint16_t xend, uint16_t yend, uint16_t color);
|
||||
void lcd_fill_array_spi(uint16_t x_start, uint16_t y_start, uint16_t x_end, uint16_t y_end, void *pcolor);
|
||||
|
||||
void LCD_Init(void);
|
||||
rt_err_t spi_lcd_init(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
|
@ -6,9 +6,11 @@
|
|||
|
||||
![](picture/lvgl/00.png)
|
||||
|
||||
在 `Hardware Drivers Config → On-chip Peripheral Drivers` 中使能 `Enable LVGL for LCD` 选项
|
||||
## RGB 屏使用配置
|
||||
|
||||
![](picture/lvgl/01.png)
|
||||
在 `Hardware Drivers Config → On-chip Peripheral Drivers → Enable LVGL for LCD` 中使能 `Enable LVGL for LCD_RGB565` 选项
|
||||
|
||||
![](picture/lvgl/12.png)
|
||||
|
||||
接下来退出菜单界面,输入 `pkgs --update` 命令手动联网获取 lvgl 的软件包到 `packages` 文件夹下
|
||||
|
||||
|
@ -18,7 +20,7 @@
|
|||
|
||||
![](picture/lvgl/03.png)
|
||||
|
||||
## fsp 中配置 lcd 外设
|
||||
### fsp 中配置 GLCDC 外设
|
||||
|
||||
点击 mdk 中的 `Tools->RA Smart Configurator` 进入 rasc 配置软件
|
||||
|
||||
|
@ -48,6 +50,50 @@
|
|||
|
||||
![](picture/lvgl/10.png)
|
||||
|
||||
退出 rasc 后,在 mdk 中进行编译,下载即可
|
||||
### 编译烧录
|
||||
|
||||
退出 rasc 后,在 mdk 中进行编译,仿真下载即可
|
||||
|
||||
![](picture/lvgl/11.png)
|
||||
|
||||
## SPI(ILI9431) 屏使用配置
|
||||
|
||||
在 `Hardware Drivers Config → On-chip Peripheral Drivers → Enable LVGL for LCD` 中使能 `Enable LVGL for LCD_ILI9431` 选项
|
||||
|
||||
![](picture/lvgl/01.png)
|
||||
|
||||
接下来退出菜单界面,输入 `pkgs --update` 命令手动联网获取 lvgl 的软件包到 `packages` 文件夹下
|
||||
|
||||
![](picture/lvgl/02.png)
|
||||
|
||||
接着在env 终端中输入 `scons --target=mdk5` 生成 mdk 工程
|
||||
|
||||
![](picture/lvgl/03.png)
|
||||
|
||||
### fsp 中配置 SPI 外设
|
||||
|
||||
点击 mdk 中的 `Tools->RA Smart Configurator` 进入 rasc 配置软件
|
||||
|
||||
![](picture/lvgl/04.png)
|
||||
|
||||
点击 New Stack,选择 `Connectivity->SPI(r_spi)`,使能 SPI 外设
|
||||
|
||||
![](picture/lvgl/13.png)
|
||||
|
||||
在 `Callback` 中,设置中断回调函数,(默认使用SPI0)输入 :`spi0_callback`
|
||||
|
||||
![](picture/lvgl/14.png)
|
||||
|
||||
接着我们配置 SPI 的引脚属性(默认使用SPI0),进入 Pins 界面按照下图进行配置:
|
||||
|
||||
![](picture/lvgl/15.png)
|
||||
|
||||
完成以上配置后,点击 `Generate Project Content` 生成配置相关代码
|
||||
|
||||
![](picture/lvgl/16.png)
|
||||
|
||||
### 编译烧录
|
||||
|
||||
退出 rasc 后,在 mdk 中进行编译,仿真下载即可
|
||||
|
||||
![](picture/lvgl/11.png)
|
Before Width: | Height: | Size: 22 KiB After Width: | Height: | Size: 17 KiB |
After Width: | Height: | Size: 18 KiB |
After Width: | Height: | Size: 11 KiB |
After Width: | Height: | Size: 12 KiB |
After Width: | Height: | Size: 18 KiB |
After Width: | Height: | Size: 4.7 KiB |