参考资料
徐宏的博客:移植最新的 LVGL 到安信可ESP32\C3模组,显示一个二维码。
一、新建一个工程模板
二、克隆lvgl所需要的库
找到刚才创建的工程blink,在里面创建一个 components 文件夹 克隆所需的最新的 LVGL依赖库,(2021.11.16) V8.1 为例:
git clone -b release/v8.1 https://github.com/lvgl/lvgl
克隆所需的最新的针对ESP32芯片系列的LVGL驱动库
git clone https://github.com/lvgl/lvgl_esp32_drivers
三、你可能会遇到下面这个问题(示例):
四、开始移植
代码如下(示例):
lvgl_init.h
#include "freertos/FreeRTOS.h"
#include "freertos/event_groups.h"
#include "lvgl.h"
#include "freertos/semphr.h"
#include "esp_system.h"
#ifdef LV_LVGL_H_INCLUDE_SIMPLE
#include "lvgl.h"
#else
#include "lvgl/lvgl.h"
#endif
#include "lvgl_helpers.h"
#include "lvgl/src/hal/lv_hal_disp.h"
#define LV_TICK_PERIOD_MS 1
#define BUF_W 20
#define BUF_H 10
void lv_tick_task(void *arg);
void guiTask1(void *pvParameter);
void Show_State();
lvgl_init.c
#include "lvgl_init.h"
void lv_tick_task(void *arg)
{
lv_tick_inc(LV_TICK_PERIOD_MS);
}
SemaphoreHandle_t xGuiSemaphore;
lv_obj_t *label_1;
lv_obj_t *label_2;
void Show_State()
{
lv_obj_t *scr = lv_scr_act();
lv_obj_set_pos(scr, 0, 0);
lv_scr_load(scr);
label_1 = lv_label_create(scr);
lv_label_set_recolor(label_1, 1);
lv_label_set_long_mode(label_1, LV_LABEL_LONG_DOT);
lv_obj_set_pos(label_1, 10, 10);
lv_obj_set_size(label_1, 160, 30);
lv_label_set_text(label_1, "This is a GUI thread yes");
label_2 = lv_label_create(scr);
lv_label_set_recolor(label_2, 1);
lv_label_set_long_mode(label_2, LV_LABEL_LONG_SCROLL);
lv_obj_set_pos(label_2, 10, 40);
lv_obj_set_size(label_2, 160, 40);
lv_label_set_text(label_2, "This is the Intetnet thread");
}
void guiTask1(void *pvParameter)
{
(void)pvParameter;
xGuiSemaphore = xSemaphoreCreateMutex();
lv_init();
lvgl_driver_init();
lv_color_t *buf1 = heap_caps_malloc(DISP_BUF_SIZE * sizeof(lv_color_t), MALLOC_CAP_DMA);
assert(buf1 != NULL);
#ifndef CONFIG_LV_TFT_DISPLAY_MONOCHROME
lv_color_t *buf2 = heap_caps_malloc(DISP_BUF_SIZE * sizeof(lv_color_t), MALLOC_CAP_DMA);
assert(buf2 != NULL);
#else
static lv_color_t *buf2 = NULL;
#endif
static lv_disp_draw_buf_t disp_buf;
uint32_t size_in_px = DISP_BUF_SIZE;
#if defined CONFIG_LV_TFT_DISPLAY_CONTROLLER_IL3820 || defined CONFIG_LV_TFT_DISPLAY_CONTROLLER_JD79653A || defined CONFIG_LV_TFT_DISPLAY_CONTROLLER_UC8151D || defined CONFIG_LV_TFT_DISPLAY_CONTROLLER_SSD1306
size_in_px *= 8;
#endif
lv_disp_draw_buf_init(&disp_buf, buf1, buf2, size_in_px);
lv_disp_drv_t disp_drv;
lv_disp_drv_init(&disp_drv);
disp_drv.hor_res = LV_HOR_RES_MAX;
disp_drv.ver_res = LV_VER_RES_MAX;
disp_drv.flush_cb = disp_driver_flush;
disp_drv.draw_buf = &disp_buf;
lv_disp_drv_register(&disp_drv);
#if CONFIG_LV_TOUCH_CONTROLLER != TOUCH_CONTROLLER_NONE
lv_indev_drv_t indev_drv;
lv_indev_drv_init(&indev_drv);
indev_drv.read_cb = touch_driver_read;
indev_drv.type = LV_INDEV_TYPE_POINTER;
lv_indev_drv_register(&indev_drv);
#endif
const esp_timer_create_args_t periodic_timer_args = {
.callback = &lv_tick_task,
.name = "periodic_gui"};
esp_timer_handle_t periodic_timer;
ESP_ERROR_CHECK(esp_timer_create(&periodic_timer_args, &periodic_timer));
ESP_ERROR_CHECK(esp_timer_start_periodic(periodic_timer, LV_TICK_PERIOD_MS * 1000));
Show_State();
while (1)
{
vTaskDelay(pdMS_TO_TICKS(10));
if (pdTRUE == xSemaphoreTake(xGuiSemaphore, portMAX_DELAY))
{
lv_task_handler();
xSemaphoreGive(xGuiSemaphore);
}
}
free(buf1);
#ifndef CONFIG_LV_TFT_DISPLAY_MONOCHROME
free(buf2);
#endif
vTaskDelete(NULL);
}
blink.c
#include <stdio.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "driver/gpio.h"
#include "sdkconfig.h"
#include "lvgl_init.h"
#define BLINK_GPIO CONFIG_BLINK_GPIO
extern void guiTask1(void *pvParameter);
void app_main(void)
{
xTaskCreatePinnedToCore(guiTask1, "gui", 4096 * 2, NULL, 1, NULL, 1);
gpio_reset_pin(BLINK_GPIO);
gpio_set_direction(BLINK_GPIO, GPIO_MODE_OUTPUT);
while (1)
{
printf("Turning off the LED\n");
gpio_set_level(BLINK_GPIO, 0);
vTaskDelay(1000 / portTICK_PERIOD_MS);
printf("Turning on the LED\n");
gpio_set_level(BLINK_GPIO, 1);
vTaskDelay(1000 / portTICK_PERIOD_MS);
}
}
编译烧录,看看结果 出现了乱码,花屏!!!
五、乱码,花屏,颜色不对解决方法
如果出现乱码,花屏,颜色不对,不要慌, 乱码,花屏:一般是屏幕的驱动问题 颜色不对:一般是颜色反转问题,在IDF设置中可以进行设置,前面有说到
说回来我这个花屏的问题: 我使用的是AT7735S-1.44寸的显示屏 这时候就正常了输出了
下一篇说一下怎么移植效果例程!
|