Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gd32470z-lckfb新增官方配套800x480 RGB LCD屏幕的显示驱动与触摸驱动 #9842

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions bsp/gd32/arm/gd32470z-lckfb/SConstruct
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,8 @@ objs.extend(SConscript(os.path.join(libraries_path_prefix, gd32_library, 'SConsc
# include drivers
objs.extend(SConscript(os.path.join(libraries_path_prefix, 'gd32_drivers', 'SConscript')))

# include lcd and drivers
objs.extend(SConscript(os.path.join(RTT_ROOT, 'bsp', 'gd32', 'arm', 'gd32470z-lckfb', 'board', 'ports', 'SConscript')))

# make a building
DoBuilding(TARGET, objs)
31 changes: 31 additions & 0 deletions bsp/gd32/arm/gd32470z-lckfb/board/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,37 @@ endmenu

menu "Board extended module Drivers"

menuconfig BSP_USING_LCD
bool "Enable LCD"
select RT_USING_LCD
default n
if BSP_USING_LCD

config BSP_USING_TLI
bool "Enable TLI"
default y

config BSP_USING_SDRAM
bool "Enable SDRAM"
select RT_USING_SDRAM
default y

config BSP_USING_TOUCH
bool "Enable TOUCH"
select RT_USING_TOUCH
default n

config BSP_USING_GPU
bool "Enable GPU"
select RT_USING_GPU
default y

config BSP_USING_DRAW_PANEL_EXAMPLE
bool "Enable DRAW PANEL EXAMPLE"
select RT_USING_DRAW_PANEL_EXAMPLE
default n
endif

endmenu

endmenu
23 changes: 23 additions & 0 deletions bsp/gd32/arm/gd32470z-lckfb/board/ports/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#### 1.简介

用于GD32F470立创开发板配套RGB LCD屏幕的驱动,支持触摸。
#### 2.在 ENV 中的开启
ps:建议全部开启
```
Hardware Drivers Config --->
Board extended module Drivers --->
Enable LCD --->
- [*]Enable TLI
- [*]Enable SDRAM
- [*]Enable TOUCH
- [*]Enable GPU
- [*]Enable DRAW PANEL EXAMPLE
```
#### 3.注意事项
1.如果屏幕出现刷新抖动,触摸屏出现连点的情况,可以尝试在 `libraries\GD32F4xx_Firmware_Library\CMSIS\GD\GD32F4xx\Source\system_gd32f4xx.c`将时钟值修改为
`#define __SYSTEM_CLOCK_240M_PLL_25M_HXTAL (uint32_t)(240000000)`

#### 4.联系方式

- 维护:godmial
- 主页:<https://github.com/godmial>
25 changes: 25 additions & 0 deletions bsp/gd32/arm/gd32470z-lckfb/board/ports/SConscript
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
Import('RTT_ROOT')
Import('rtconfig')
from building import *

cwd = GetCurrentDir()

# add the general drivers.
src = Split("""
""")

# add lcd drivers.
if GetDepend('BSP_USING_LCD'):
src += ['drv_lcd.c']

if GetDepend('BSP_USING_TOUCH'):
src += ['drv_touch.c']

if GetDepend('BSP_USING_DRAW_PANEL_EXAMPLE'):
src += ['draw_panel.c']

path = [cwd]

group = DefineGroup('Applications', src, depend = [''], CPPPATH = path)

Return('group')
215 changes: 215 additions & 0 deletions bsp/gd32/arm/gd32470z-lckfb/board/ports/draw_panel.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,215 @@
#include <board.h>
#include <rthw.h>
#include <rtthread.h>
#include "drv_lcd.h"
#include "drv_touch.h"

#define COLOR_MAX 14

//像素最大放大倍数
#define PIXEL_SIZE_MAX 20

typedef struct button_struct
{
uint16_t x;
uint16_t y;
uint16_t w;
uint16_t h;
uint16_t color;
uint16_t value;
} _widget_object_struct;

uint16_t color_buf[COLOR_MAX] = {GRAYBLUE, BLACK, BLUE, BRED, GRED, GBLUE, RED, MAGENTA, GREEN, YELLOW, CYAN, BROWN, BRRED, GRAY};
_widget_object_struct button_clear, button_color, button_pixel, button_eraser;


/**********************************************************
* 函 数 名 称:widget_object_init
* 函 数 功 能:控件对象初始化
* 传 入 参 数:obj:要初始化的控件
* xywh:控件的(x,y)起点坐标 w宽h高
* color:控件颜色
* value:控件值
* 函 数 返 回:无
* 作 者:LCKFB
* 备 注:无
**********************************************************/
void widget_object_init(_widget_object_struct *obj, uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint16_t color, uint16_t value)
{
obj->x = x;
obj->y = y;
obj->h = h;
obj->w = w;
obj->color = color;
obj->value = value;
}


/**********************************************************
* 函 数 名 称:ui_init
* 函 数 功 能:UI界面初始化
* 传 入 参 数:无
* 函 数 返 回:无
* 作 者:LCKFB
* 备 注:无
**********************************************************/
void ui_init(void)
{
char temp_buf[20] = {0};

//绘制[清除]按钮
//绘制一个圆角按钮
tli_show_button(button_clear.x, button_clear.y, button_clear.w, button_clear.h, 12, button_clear.color);
//绘制圆角按钮的文本
tli_show_string(button_clear.x + 20, button_clear.y + 20, WHITE, button_clear.color, 2, "clear", 0);

//绘制[颜色]按钮
//绘制一个圆角按钮
tli_show_button(button_color.x, button_color.y, button_color.w, button_color.h, 12, button_color.color);
//绘制圆角按钮的文本
tli_show_string(button_color.x + 20, button_color.y + 20, WHITE, button_color.color, 2, "color", 0);

//绘制[像素]按钮
//绘制一个圆角按钮
tli_show_button(button_pixel.x, button_pixel.y, button_pixel.w, button_pixel.h, 12, button_pixel.color);
if (button_pixel.value == 0)
{
//绘制圆角按钮的文本
tli_show_string(button_pixel.x + 20, button_pixel.y + 20, WHITE, button_pixel.color, 2, "pixel", 0);
button_pixel.value = 1;
}
else
{
//绘制居中显示的字符串
sprintf(temp_buf, "%d", button_pixel.value);
tli_show_string(button_pixel.x + (button_pixel.w / 2) - (strlen(temp_buf) / 2 * 16), button_pixel.y + 20, WHITE, button_pixel.color, 2, (uint8_t *)temp_buf, 0);
}

//绘制[擦除]按钮
//绘制一个圆角按钮
tli_show_button(button_eraser.x, button_eraser.y, button_eraser.w, button_eraser.h, 12, button_eraser.color);
//绘制圆角按钮的文本
tli_show_string(button_eraser.x + (button_eraser.w / 2) - (strlen("eraser") / 2 * 16), button_eraser.y + 20, WHITE, button_eraser.color, 2, "eraser", 0);
}

int draw_panel_test(void)
{
int touch_state = 0;
char color_num = 0;
char pixel_size = 0;

// 屏幕初始化
lcd_disp_config();
// 触摸初始化
FT5206_Init();
//全屏清屏
tli_draw_Rectangle(0, 0, 800, 480, WHITE, 1);


//初始化[清除]按钮的xywh
widget_object_init(&button_clear, 800 - 130, 480 - 80, 120, 70, BLUE, 0);
//初始化[颜色]按钮的xywh
widget_object_init(&button_color, 10, 480 - 80, 120, 70, BLUE, 0);
//初始化[像素]按钮的xywh
widget_object_init(&button_pixel, 400 - 60, 480 - 80, 120, 70, BLUE, pixel_size);
//初始化[橡皮擦]按钮的xywh
widget_object_init(&button_eraser, 800 - 130 - 130, 480 - 80, 120, 70, BLUE, 0);

//UI显示
ui_init();

while (1)
{
//触摸扫描
touch_state = FT5206_Scan(0);
//如果屏幕被触摸
if (touch_state == 1)
{
//[颜色]按钮被按下
if (tp_dev.x[0] >= button_color.x && tp_dev.x[0] <= (button_color.x + button_color.w))
{
if (tp_dev.y[0] >= button_color.y && tp_dev.y[0] <= (button_color.y + button_color.h))
{
//判断是否松手
letgo_scan(0, button_color.x, button_color.y, (button_color.x + button_color.w), (button_color.y + button_color.h));
//改变颜色
color_num = (color_num + 1) % COLOR_MAX;
//重新设置[颜色]按钮的背景色
widget_object_init(&button_color, button_color.x, button_color.y, button_color.w, button_color.h, color_buf[color_num], 0);
//UI重新显示
ui_init();
}
}
//[清除]按钮被按下
if (tp_dev.x[0] >= button_clear.x && tp_dev.x[0] <= (button_clear.x + button_clear.w))
{
if (tp_dev.y[0] >= button_clear.y && tp_dev.y[0] <= (button_clear.y + button_clear.h))
{
//判断是否松手
letgo_scan(0, button_clear.x, button_clear.y, (button_clear.x + button_clear.w), (button_clear.y + button_clear.h));
//清屏为背景色
tli_draw_Rectangle(0, 0, 800, 480, WHITE, 1);
//UI重新显示
ui_init();
}
}
//[像素]按钮被按下
if (tp_dev.x[0] >= button_pixel.x && tp_dev.x[0] <= (button_pixel.x + button_pixel.w))
{
if (tp_dev.y[0] >= button_pixel.y && tp_dev.y[0] <= (button_pixel.y + button_pixel.h))
{
//判断是否松手
letgo_scan(0, button_pixel.x, button_pixel.y, (button_pixel.x + button_pixel.w), (button_pixel.y + button_pixel.h));
//像素放大倍数自增
pixel_size++;
//如果像素放大倍数大于最大倍数
if (pixel_size > PIXEL_SIZE_MAX) pixel_size = 1;
//重新设置[颜色]按钮的背景色
widget_object_init(&button_pixel, button_pixel.x, button_pixel.y, button_pixel.w, button_pixel.h, button_pixel.color, pixel_size);
//UI重新显示
ui_init();
}
}

//[擦除]按钮被按下
if (tp_dev.x[0] >= button_eraser.x && tp_dev.x[0] <= (button_eraser.x + button_eraser.w))
{
if (tp_dev.y[0] >= button_eraser.y && tp_dev.y[0] <= (button_eraser.y + button_eraser.h))
{
//判断是否松手
letgo_scan(0, button_eraser.x, button_eraser.y, (button_eraser.x + button_eraser.w), (button_eraser.y + button_eraser.h));
//修改擦除按钮的状态
button_eraser.value = !button_eraser.value;
//如果是擦除状态
if (button_eraser.value)
{
//初始化[橡皮擦]按钮的xywh颜色修改为黑色
widget_object_init(&button_eraser, 800 - 130 - 130, 480 - 80, 120, 70, BLACK, button_eraser.value);
}
else
{
//初始化[橡皮擦]按钮的xywh颜色修改为蓝色
widget_object_init(&button_eraser, 800 - 130 - 130, 480 - 80, 120, 70, BLUE, button_eraser.value);
}
//UI重新显示
ui_init();
}
}

//如果不是擦除状态
if (!button_eraser.value)
{
//绘制触摸点
//根据[颜色]按钮的背景色设置触摸点的颜色
point_enlargement(tp_dev.x[0], tp_dev.y[0], color_buf[color_num], button_pixel.value);
}
else
{
//擦除
point_enlargement(tp_dev.x[0], tp_dev.y[0], WHITE, button_pixel.value);
}
}
}
}
// MSH_CMD_EXPORT(draw_panel_test, draw panel test)
INIT_COMPONENT_EXPORT(draw_panel_test);
Loading
Loading