/*Used to copy the buffer's content to the display*/
disp_drv.flush_cb = disp_flush;
/*Set a display buffer*/
disp_drv.buffer = &disp_buf_1;
#if LV_USE_GPU
/*Optionally add functions to access the GPU. (Only in buffered mode, LV_VDB_SIZE != 0)*/
/*Blend two color array using opacity*/
disp_drv.gpu_blend = gpu_blend;
/*Fill a memory array with a color*/
disp_drv.gpu_fill = gpu_fill;
#endif
/*Finally register the driver*/
lv_disp_drv_register(&disp_drv);
}
/**********************
* STATIC FUNCTIONS
**********************/
/* Initialize your display and the required peripherals. */
static void disp_init(void)
{
/*You code here*/
}
/* Flush the content of the internal buffer the specific area on the display
* You can use DMA or any hardware acceleration to do this operation in the background but
* 'lv_disp_flush_ready()' has to be called when finished. */
static void disp_flush(lv_disp_drv_t * disp_drv, const lv_area_t * area, lv_color_t * color_p)
{
LCD_Color_Fill(area->x1,area->y1,area->x2,area->y2,(u16*)color_p);
/* IMPORTANT!!!
* Inform the graphics library that you are ready with the flushing*/
lv_disp_flush_ready(disp_drv);
}
/*OPTIONAL: GPU INTERFACE*/
#if LV_USE_GPU
/* If your MCU has hardware accelerator (GPU) then you can use it to blend to memories using opacity
* It can be used only in buffered mode (LV_VDB_SIZE != 0 in lv_conf.h)*/
static void gpu_blend(lv_disp_drv_t * disp_drv, lv_color_t * dest, const lv_color_t * src, uint32_t length, lv_opa_t opa)
{
/*It's an example code which should be done by your GPU*/
uint32_t i;
for(i = 0; i < length; i++) {
dest[i] = lv_color_mix(dest[i], src[i], opa);
}
}
/* If your MCU has hardware accelerator (GPU) then you can use it to fill a memory with a color
* It can be used only in buffered mode (LV_VDB_SIZE != 0 in lv_conf.h)*/
static void gpu_fill_cb(lv_disp_drv_t * disp_drv, lv_color_t * dest_buf, lv_coord_t dest_width,
const lv_area_t * fill_area, lv_color_t color);
{
/*It's an example code which should be done by your GPU*/
uint32_t x, y;
dest_buf += dest_width * fill_area->y1; /*Go to the first line*/
for(y = fill_area->y1; y < fill_area->y2; y++) {
for(x = fill_area->x1; x < fill_area->x2; x++) {
dest_buf[x] = color;
}
dest_buf+=dest_width; /*Go to the next line*/
}
}
#endif /*LV_USE_GPU*/
#else /* Enable this file at the top */
/* This dummy typedef exists purely to silence -Wpedantic. */
typedef int keep_pedantic_happy;
#endif
lv_port_indev.c
/**
* @file lv_port_indev.c
*
*/
/*Copy this file as 'lv_port_indev.c' and set this value to '1' to enable content*/
#if 1
/*********************
* INCLUDES
*********************/
#include 'lv_port_indev.h'
#include 'touch.h'
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
/**********************
* STATIC PROTOTYPES
**********************/
static bool touchpad_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data);
/**********************
* STATIC VARIABLES
**********************/
/**********************
* MACROS
**********************/
/**********************
* GLOBAL FUNCTIONS
**********************/
void lv_port_indev_init(void)
{
lv_indev_drv_t indev_drv;
/*------------------
* Touchpad
* -----------------*/
/*Register a touchpad input device*/
lv_indev_drv_init(&indev_drv);
indev_drv.type = LV_INDEV_TYPE_POINTER;
indev_drv.read_cb = touchpad_read;
lv_indev_drv_register(&indev_drv);
}
/**********************
* STATIC FUNCTIONS
**********************/
/* Will be called by the library to read the touchpad */
static bool touchpad_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data)
{
static uint16_t last_x = 0;
static uint16_t last_y = 0;
if(tp_dev.sta&TP_PRES_DOWN)//触摸按下了
{
last_x = tp_dev.x[0];
last_y = tp_dev.y[0];
data->point.x = last_x;
data->point.y = last_y;
data->state = LV_INDEV_STATE_PR;
}else{
data->point.x = last_x;
data->point.y = last_y;
data->state = LV_INDEV_STATE_REL;
}
/*Return `false` because we are not buffering and no more data to read*/
return false;
}
#else /* Enable this file at the top */
/* This dummy typedef exists purely to silence -Wpedantic. */
typedef int keep_pedantic_happy;
#endif
在新建一个GUI_APP文件夹,把里面我们要展示的例子,添加进去~
在main函数里面调用:
TIM1_Int_Init(999,119);//定时器初始化(1ms 中断),用于给 lvgl 提供 1ms 的心跳节拍
LCD_Init();
tp_dev.init();//触摸初始化
lv_init(); //lvgl系统初始化
lv_port_disp_init(); //lvgl显示接口初始化,放在lv_init()的后面
lv_port_indev_init(); //lvgl输入接口初始化,放在lv_init()的后面
//通过TEST_NUM的值来选择运行不同的例程
#if(TEST_NUM==1)
demo_create();
#elif(TEST_NUM==2)
lv_test_theme_1(lv_theme_night_init(210, NULL));
#else
lv_test_theme_2();
#endif
while(1)
{
tp_dev.scan(0);
lv_task_handler();
}
编译,查看效果。如前图。好了LVGL的移植就到这了
上一篇:GD32开发实战指南(基础篇) 第10章 串口通信
下一篇:最后一页
推荐阅读最新更新时间:2024-11-08 09:54
设计资源 培训 开发板 精华推荐
- 使用 ROHM Semiconductor 的 BD4737 的参考设计
- 【ART-Pi】电压电流表
- FMC-ADC01-2-1-0,用于 ADS6443、14 位、4 通道、80 MSPS 模数转换器的 FPGA 夹层卡
- 使用采用陶瓷电容器的 LTC3612IFE 通用降压稳压器的典型应用,2.25MHz
- RT8072 5A、2MHz、高效同步降压转换器的典型应用
- 使用 Semtech 的 SC4509 的参考设计
- 用于开/关控制应用的 AM2G-1224DZ ±24V 2 瓦 DC-DC 转换器的典型应用
- LT1084CT-3.3、3.3V/5A 调节输出电压低压差稳压器的典型应用电路
- ARG81800 EVB,用于 ARG81800 超低 IQ 同步降压稳压器的评估板,具有 SYNCIN、CLKOUT 和 PGOOD 3.5 至 36 Vin、3.3 Vout、1A、2.15 MHz
- NCV7691RCLV1GEVB:八路后组合灯评估板