From 80181901e13acc3fb073f77d18c4dcf3d8f8d082 Mon Sep 17 00:00:00 2001 From: ipason Date: Fri, 28 Nov 2025 07:53:56 +0000 Subject: [PATCH] =?UTF-8?q?=E7=A7=BB=E6=A4=8D=E6=98=BE=E7=A4=BA=E7=95=8C?= =?UTF-8?q?=E9=9D=A2=E7=BB=84=E4=BB=B6=E6=88=90=E5=8A=9F=EF=BC=8C=E5=B9=B6?= =?UTF-8?q?=E6=B5=8B=E8=AF=95=E9=80=9A=E8=BF=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .vscode/c_cpp_properties.json | 3 +- .vscode/settings.json | 6 +- components/user_i80_display/CMakeLists.txt | 23 + .../user_i80_display/user_i80_display.c | 445 ++++++++++++++++++ .../user_i80_display/user_i80_display.h | 113 +++++ main/CMakeLists.txt | 1 + main/main.c | 20 +- main/main.h | 2 +- 8 files changed, 609 insertions(+), 4 deletions(-) create mode 100644 components/user_i80_display/CMakeLists.txt create mode 100644 components/user_i80_display/user_i80_display.c create mode 100644 components/user_i80_display/user_i80_display.h diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json index e2c2816..d7b7a32 100644 --- a/.vscode/c_cpp_properties.json +++ b/.vscode/c_cpp_properties.json @@ -9,7 +9,8 @@ "includePath": [ "${config:idf.espIdfPath}/components/**", "${workspaceFolder}/**", - "${workspaceFolder}/components/user_common" + "${workspaceFolder}/components/user_common", + "${workspaceFolder}/components/user_i80_display" ], "browse": { "path": [ diff --git a/.vscode/settings.json b/.vscode/settings.json index 118631b..cc5d283 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -15,7 +15,11 @@ "sdkconfig.h": "c", "gpio.h": "c", "gpio_hal.h": "c", - "freertos.h": "c" + "freertos.h": "c", + "semphr.h": "c", + "user_i80_display.h": "c", + "i2c.h": "c", + "i2c_master.h": "c" } } \ No newline at end of file diff --git a/components/user_i80_display/CMakeLists.txt b/components/user_i80_display/CMakeLists.txt new file mode 100644 index 0000000..a6e1103 --- /dev/null +++ b/components/user_i80_display/CMakeLists.txt @@ -0,0 +1,23 @@ +# 定义源文件变量 +set(USER_I80_DISPLAY_SRCS "user_i80_display.c") + +# 定义依赖组件变量 +set(USER_I80_DISPLAY_REQUIRES + lvgl + freertos + esp_driver_ledc + esp_driver_gpio + esp_driver_i2c + + espressif__esp_lcd_touch_ft5x06 +) + +# 定义包含目录变量 +set(USER_I80_DISPLAY_INCLUDE_DIRS ".") + +# 注册组件 +idf_component_register( + SRCS ${USER_I80_DISPLAY_SRCS} + REQUIRES ${USER_I80_DISPLAY_REQUIRES} + INCLUDE_DIRS ${USER_I80_DISPLAY_INCLUDE_DIRS} +) diff --git a/components/user_i80_display/user_i80_display.c b/components/user_i80_display/user_i80_display.c new file mode 100644 index 0000000..403a8dc --- /dev/null +++ b/components/user_i80_display/user_i80_display.c @@ -0,0 +1,445 @@ +/** + * @file user_i80_display.c + * @brief LCD及触摸屏控制函数实现 + * + * 用于实现LCD控制IO及初始化函数 + * + * @author wang xiang en + * @date 2025-04-18 + * @version 版本号 + * @copyright 版权声明((C)2025, YUWELL MEDTECH Co.ltd) + */ +#include "user_i80_display.h" + + +/* 用于初始化配置的全局变量 */ +static esp_lcd_touch_handle_t tp = NULL; +static SemaphoreHandle_t lvgl_mux = NULL; +static const char *TAG = "LCD_Init"; + +/* 用于初始化配置的全局变量 */ +static lv_disp_draw_buf_t disp_buf; // Contains internal graphic buffer(s) called draw buffer(s) +static lv_disp_drv_t disp_drv; // Contains callback functions + +/** + * @brief 通知LVGL库,屏幕已经更新 + * + * 屏幕刷新时,LVGL库不会自动通知屏幕已经更新,需要手动调用此函数通知LVGL库,屏幕已经更新。 + * + * @param[in] panel_io lcd控制面板 + * @param[in] edata 事件码 + * @param[in] user_ctx 用户数据 + * + * @return 成功返回0,失败返回错误码 + */ +static bool example_notify_lvgl_flush_ready(esp_lcd_panel_io_handle_t panel_io, esp_lcd_panel_io_event_data_t *edata, void *user_ctx) +{ + lv_disp_drv_t *disp_driver = (lv_disp_drv_t *)user_ctx; + lv_disp_flush_ready(disp_driver); + return false; +} + + + +/** + * @brief 刷新屏幕 + * + * 使用lcd驱动进行屏幕内容刷新 + * + * @param[in] drv lcd控制驱动 + * @param[in] area 绘图区域 + * @param[in] color_map 色谱 + * + */ +static void example_lvgl_flush_cb(lv_disp_drv_t *drv, const lv_area_t *area, lv_color_t *color_map) +{ + esp_lcd_panel_handle_t panel_handle = (esp_lcd_panel_handle_t) drv->user_data; + int offsetx1 = area->x1; + int offsetx2 = area->x2; + int offsety1 = area->y1; + int offsety2 = area->y2; + // Copy a buffer's content to a specific area of the display + esp_lcd_panel_draw_bitmap(panel_handle, offsetx1, offsety1, offsetx2 + 1, offsety2 + 1, color_map); +} + + + + +/** + * @brief 触摸屏控制块 + * + * 通知LCD内核触摸屏的点击事件 + * + * @param[in] drv 控制驱动 + * @param[out] data 点击区域 + * + */ +static void example_lvgl_touch_cb(lv_indev_drv_t *drv, lv_indev_data_t *data) +{ + uint16_t touchpad_x[1] = {0}; + uint16_t touchpad_y[1] = {0}; + uint8_t touchpad_cnt = 0; + + /* Read touch controller data */ + esp_lcd_touch_read_data(drv->user_data); + + /* Get coordinates */ + bool touchpad_pressed = esp_lcd_touch_get_coordinates(drv->user_data, touchpad_x, touchpad_y, NULL, &touchpad_cnt, 1); + + if (touchpad_pressed && touchpad_cnt > 0) + { + data->point.x = touchpad_x[0]; + data->point.y = touchpad_y[0]; + data->state = LV_INDEV_STATE_PRESSED; + } + else + { + data->state = LV_INDEV_STATE_RELEASED; + } +} + + + + +/** + * @brief lvgl时钟加一 + * + * 时钟计数增加,驱动lvgl时钟 + * + * @param[in] arg not used + * + */ +static void example_increase_lvgl_tick(void *arg) +{ + /* Tell LVGL how many milliseconds have elapsed */ + lv_tick_inc(EXAMPLE_LVGL_TICK_PERIOD_MS); +} + + + + + + +/** + * @brief lvgl锁 + * + * 加锁以保护临界资源 + * + * @param[in] timeout_ms 锁住LVGL锁时间 + * @return true lvgl锁成功 + */ +bool example_lvgl_lock(int timeout_ms) +{ + // Convert timeout in milliseconds to FreeRTOS ticks + // If `timeout_ms` is set to -1, the program will block until the condition is met + const TickType_t timeout_ticks = (timeout_ms == -1) ? portMAX_DELAY : pdMS_TO_TICKS(timeout_ms); + return xSemaphoreTakeRecursive(lvgl_mux, timeout_ticks) == pdTRUE; +} + + + + + + +/** + * @brief lvgl解锁 + * + * 解锁更新界面内容 + */ +void example_lvgl_unlock(void) +{ + xSemaphoreGiveRecursive(lvgl_mux); +} + + + + + + +/** + * @brief lvgl主任务 + * + * 启动后开始进行lvgl线程运行 + * + * @param[in] arg not used + */ +static void example_lvgl_port_task(void *arg) +{ + ESP_LOGI(TAG, "Starting LVGL task"); + uint32_t task_delay_ms = EXAMPLE_LVGL_TASK_MAX_DELAY_MS; + while (1) { + // Lock the mutex due to the LVGL APIs are not thread-safe + if (example_lvgl_lock(-1)) { + task_delay_ms = lv_timer_handler(); + // Release the mutex + example_lvgl_unlock(); + } + if (task_delay_ms > EXAMPLE_LVGL_TASK_MAX_DELAY_MS) { + task_delay_ms = EXAMPLE_LVGL_TASK_MAX_DELAY_MS; + } else if (task_delay_ms < EXAMPLE_LVGL_TASK_MIN_DELAY_MS) { + task_delay_ms = EXAMPLE_LVGL_TASK_MIN_DELAY_MS; + } + vTaskDelay(pdMS_TO_TICKS(task_delay_ms)); + } +} + + + + + + +/** + * @brief i80总线初始化 + * + * 根据IO Num初始化总线 + * + * @param[in] io_handle 控制句柄 + * @param[in] user_ctx 用户数据 + */ +static void example_init_i80_bus(esp_lcd_panel_io_handle_t *io_handle, void *user_ctx) +{ + ESP_LOGI(TAG, "Initialize Intel 8080 bus"); + + /* 创建i80总线控制句柄 */ + esp_lcd_i80_bus_handle_t i80_bus = NULL; + esp_lcd_i80_bus_config_t bus_config = { + .clk_src = LCD_CLK_SRC_DEFAULT, + .dc_gpio_num = EXAMPLE_PIN_NUM_DC, + .wr_gpio_num = EXAMPLE_PIN_NUM_PCLK, + .data_gpio_nums = { + EXAMPLE_PIN_NUM_DATA0, + EXAMPLE_PIN_NUM_DATA1, + EXAMPLE_PIN_NUM_DATA2, + EXAMPLE_PIN_NUM_DATA3, + EXAMPLE_PIN_NUM_DATA4, + EXAMPLE_PIN_NUM_DATA5, + EXAMPLE_PIN_NUM_DATA6, + EXAMPLE_PIN_NUM_DATA7, + }, + .bus_width = CONFIG_EXAMPLE_LCD_I80_BUS_WIDTH, + .max_transfer_bytes = EXAMPLE_LCD_H_RES * 100 * sizeof(uint16_t), + .dma_burst_size = EXAMPLE_DMA_BURST_SIZE, + }; + /* 根据配置创建 i80总线控制句柄 */ + ESP_ERROR_CHECK(esp_lcd_new_i80_bus(&bus_config, &i80_bus)); + + /* 配置i80总线IO引脚 */ + esp_lcd_panel_io_i80_config_t io_config = { + .cs_gpio_num = EXAMPLE_PIN_NUM_CS, + .pclk_hz = EXAMPLE_LCD_PIXEL_CLOCK_HZ, + .trans_queue_depth = 10, + .dc_levels = { + .dc_idle_level = 0, + .dc_cmd_level = 0, + .dc_dummy_level = 0, + .dc_data_level = 1, + }, + .flags = { + .swap_color_bytes = !LV_COLOR_16_SWAP, // Swap can be done in LvGL (default) or DMA + }, + .on_color_trans_done = example_notify_lvgl_flush_ready, + .user_ctx = user_ctx, + .lcd_cmd_bits = EXAMPLE_LCD_CMD_BITS, + .lcd_param_bits = EXAMPLE_LCD_PARAM_BITS, + }; + ESP_ERROR_CHECK(esp_lcd_new_panel_io_i80(i80_bus, &io_config, io_handle)); +} + +/** + * @brief LCD控制句柄 + * + * 添加LCD控制句柄 + * + * @param[in] io_handle io句柄 + * @param[out] panel lcd句柄 + */ +static void example_init_lcd_panel(esp_lcd_panel_io_handle_t io_handle, esp_lcd_panel_handle_t *panel) +{ + esp_lcd_panel_handle_t panel_handle = NULL; + + ESP_LOGI(TAG, "Install LCD driver of st7789"); + esp_lcd_panel_dev_config_t panel_config = { + .reset_gpio_num = EXAMPLE_PIN_NUM_RST, + .rgb_ele_order = COLOR_RGB_ELEMENT_ORDER_BGR, + .bits_per_pixel = 16, + }; + ESP_ERROR_CHECK(esp_lcd_new_panel_st7789(io_handle, &panel_config, &panel_handle)); + + esp_lcd_panel_reset(panel_handle); + esp_lcd_panel_init(panel_handle); + // Set inversion, x/y coordinate order, x/y mirror according to your LCD module spec + // The gap is LCD panel specific, even panels with the same driver IC, can have different gap value + esp_lcd_panel_invert_color(panel_handle, false); + esp_lcd_panel_set_gap(panel_handle, 0, 0); + + esp_lcd_panel_mirror(panel_handle, true, false); + *panel = panel_handle; +} + +/** + * @brief 触摸屏驱动初始化 + * + */ +static void example_init_touch_panel(void) +{ + esp_lcd_panel_io_handle_t tp_io_handle = NULL; + i2c_master_bus_handle_t i2c_bus_handle = NULL; // 替换旧的esp_lcd_i2c_bus_handle_t + + ESP_LOGI(TAG, "Initialize I2C master bus"); + // 1. 初始化新版I2C主总线(替代旧的i2c_param_config+i2c_driver_install) + i2c_master_bus_config_t i2c_bus_config = { + .clk_source = I2C_CLK_SRC_DEFAULT, + .i2c_port = EXAMPLE_I2C_NUM, // I2C端口号(如I2C_NUM_0) + .scl_io_num = EXAMPLE_I2C_SCL, + .sda_io_num = EXAMPLE_I2C_SDA, + .glitch_ignore_cnt = 7, // 抗干扰配置(可选) + .flags.enable_internal_pullup = true, + }; + ESP_ERROR_CHECK(i2c_new_master_bus(&i2c_bus_config, &i2c_bus_handle)); + + // 2. 配置触摸面板的I2C IO参数 + esp_lcd_panel_io_i2c_config_t tp_io_config = { + .dev_addr = 0x38, // FT5x06默认地址 + .control_phase_bytes = 1, + .dc_bit_offset = 0, + .lcd_cmd_bits = 8, + .lcd_param_bits = 8, + .flags.disable_control_phase = true, + .scl_speed_hz = 400000, // 旧版本在此设置频率 + .on_color_trans_done = NULL, + .user_ctx = NULL, + }; + // 若FT5x06地址非默认(0x38),可在此修改:tp_io_config.dev_addr = 0x38; + + ESP_LOGI(TAG, "Initialize touch IO (I2C)"); + // 3. 创建LCD面板IO(传入新版I2C总线句柄) + ESP_ERROR_CHECK(esp_lcd_new_panel_io_i2c(i2c_bus_handle, &tp_io_config, &tp_io_handle)); + + // 4. 初始化触摸控制器 + esp_lcd_touch_config_t tp_cfg = { + .x_max = EXAMPLE_LCD_V_RES, + .y_max = EXAMPLE_LCD_H_RES, + .rst_gpio_num = -1, // 若无复位引脚则设为-1 + .int_gpio_num = -1, // 若无中断引脚则设为-1 + .flags = { + .swap_xy = 0, + .mirror_x = 0, + .mirror_y = 0, + }, + }; + + ESP_LOGI(TAG, "Initialize touch controller FT5X06"); + ESP_ERROR_CHECK(esp_lcd_touch_new_i2c_ft5x06(tp_io_handle, &tp_cfg, &tp)); +} + + + + + +/** + * @brief 最后总的触摸屏及LCD初始化函数 + * + */ +void initialize_display_and_touch(void) +{ + +/* 确定背光是否可用 */ +#if EXAMPLE_PIN_NUM_BK_LIGHT >= 0 + ESP_LOGI(TAG, "Turn off LCD backlight"); + gpio_config_t bk_gpio_config = { + .mode = GPIO_MODE_OUTPUT, + .pin_bit_mask = 1ULL << EXAMPLE_PIN_NUM_BK_LIGHT + }; + ESP_ERROR_CHECK(gpio_config(&bk_gpio_config)); + /* 关闭LCD背光 */ + gpio_set_level(EXAMPLE_PIN_NUM_BK_LIGHT, EXAMPLE_LCD_BK_LIGHT_OFF_LEVEL); +#endif // EXAMPLE_PIN_NUM_BK_LIGHT >= 0 + + /* 初始化i80总线 */ + esp_lcd_panel_io_handle_t io_handle = NULL; + example_init_i80_bus(&io_handle, &disp_drv); + + /* 初始化LCD控制panel */ + esp_lcd_panel_handle_t panel_handle = NULL; + example_init_lcd_panel(io_handle, &panel_handle); + + // Stub: User can flush pre-defined pattern to the screen before we turn on the screen or backlight + + /* Since everything is initialized, let's display some content */ + ESP_ERROR_CHECK(esp_lcd_panel_disp_on_off(panel_handle, true)); + + /* Turn on the backlight! */ +#if EXAMPLE_PIN_NUM_BK_LIGHT >= 0 + ESP_LOGI(TAG, "Turn on LCD backlight"); +#endif // EXAMPLE_PIN_NUM_BK_LIGHT >= 0 + + /* 初始化触摸屏 */ + example_init_touch_panel(); + + ESP_LOGI(TAG, "Initialize LVGL library"); + lv_init(); + + // Allocate draw buffers used by LVGL + uint32_t draw_buf_alloc_caps = 0; + +#if CONFIG_EXAMPLE_LCD_I80_COLOR_IN_PSRAM + draw_buf_alloc_caps |= MALLOC_CAP_SPIRAM; +#endif + lv_color_t *buf1 = esp_lcd_i80_alloc_draw_buffer(io_handle, EXAMPLE_LCD_H_RES * 100 * sizeof(lv_color_t), draw_buf_alloc_caps); + lv_color_t *buf2 = esp_lcd_i80_alloc_draw_buffer(io_handle, EXAMPLE_LCD_H_RES * 100 * sizeof(lv_color_t), draw_buf_alloc_caps); + assert(buf1); + assert(buf2); + ESP_LOGI(TAG, "buf1@%p, buf2@%p", buf1, buf2); + // Initialize LVGL draw buffers + lv_disp_draw_buf_init(&disp_buf, buf1, buf2, EXAMPLE_LCD_H_RES * 100); + + ESP_LOGI(TAG, "Register display driver to LVGL"); + lv_disp_drv_init(&disp_drv); + disp_drv.hor_res = EXAMPLE_LCD_H_RES; + disp_drv.ver_res = EXAMPLE_LCD_V_RES; + disp_drv.flush_cb = example_lvgl_flush_cb; + disp_drv.draw_buf = &disp_buf; + disp_drv.user_data = panel_handle; + lv_disp_t *disp = lv_disp_drv_register(&disp_drv); + + ESP_LOGI(TAG, "Install LVGL tick timer"); + // Tick interface for LVGL (using esp_timer to generate 2ms periodic event) + const esp_timer_create_args_t lvgl_tick_timer_args = { + .callback = &example_increase_lvgl_tick, + .name = "lvgl_tick" + }; + esp_timer_handle_t lvgl_tick_timer = NULL; + ESP_ERROR_CHECK(esp_timer_create(&lvgl_tick_timer_args, &lvgl_tick_timer)); + ESP_ERROR_CHECK(esp_timer_start_periodic(lvgl_tick_timer, EXAMPLE_LVGL_TICK_PERIOD_MS * 1000)); + + /* Install touch screen driver */ + static lv_indev_drv_t indev_drv; // Input device driver (Touch) + lv_indev_drv_init(&indev_drv); + indev_drv.type = LV_INDEV_TYPE_POINTER; + indev_drv.disp = disp; + indev_drv.read_cb = example_lvgl_touch_cb; + indev_drv.user_data = tp; + + lv_indev_drv_register(&indev_drv); + + lvgl_mux = xSemaphoreCreateRecursiveMutex(); + assert(lvgl_mux); + ESP_LOGI(TAG, "Create LVGL task"); + xTaskCreate(example_lvgl_port_task, "LVGL", EXAMPLE_LVGL_TASK_STACK_SIZE, NULL, EXAMPLE_LVGL_TASK_PRIORITY, NULL); + + ESP_LOGI(TAG, "Display LVGL animation"); + +} + + + + + + + + + + + + + diff --git a/components/user_i80_display/user_i80_display.h b/components/user_i80_display/user_i80_display.h new file mode 100644 index 0000000..875486c --- /dev/null +++ b/components/user_i80_display/user_i80_display.h @@ -0,0 +1,113 @@ +/** + * @file user_i80_display.h + * @brief LCD显示初始化 + * + * 用于声明LCD控制IO及初始化函数 + * + * @author wang xiang en + * @date 2025-04-18 + * @version 版本号 + * @copyright 版权声明((C)2025, YUWELL MEDTECH Co.ltd) + */ +#ifndef _USER_I80_DISPLAY_PORT_H +#define _USER_I80_DISPLAY_PORT_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include "freertos/FreeRTOS.h" +#include "freertos/task.h" +#include "freertos/semphr.h" +#include "esp_timer.h" +#include "esp_err.h" +#include "esp_log.h" +#include "esp_lcd_panel_io.h" +#include "esp_lcd_panel_vendor.h" +#include "esp_lcd_panel_ops.h" +#include "driver/gpio.h" +#include "lvgl.h" + +#include "driver/i2c_master.h" +#include "esp_lcd_touch_ft5x06.h" + +/* 定义总线IO Num */ +#define EXAMPLE_PIN_NUM_DATA0 GPIO_NUM_18 +#define EXAMPLE_PIN_NUM_DATA1 GPIO_NUM_17 +#define EXAMPLE_PIN_NUM_DATA2 GPIO_NUM_16 +#define EXAMPLE_PIN_NUM_DATA3 GPIO_NUM_15 +#define EXAMPLE_PIN_NUM_DATA4 GPIO_NUM_7 +#define EXAMPLE_PIN_NUM_DATA5 GPIO_NUM_6 +#define EXAMPLE_PIN_NUM_DATA6 GPIO_NUM_5 +#define EXAMPLE_PIN_NUM_DATA7 GPIO_NUM_4 + +/* 定义80总线控制IO NUM */ +#define EXAMPLE_PIN_NUM_PCLK GPIO_NUM_19 +#define EXAMPLE_PIN_NUM_CS GPIO_NUM_0 +#define EXAMPLE_PIN_NUM_DC GPIO_NUM_20 +#define EXAMPLE_PIN_NUM_RST GPIO_NUM_8 +#define EXAMPLE_PIN_NUM_BK_LIGHT GPIO_NUM_3 + +/* 定义背光开启/关闭GPIO电平值 */ +#define EXAMPLE_LCD_BK_LIGHT_ON_LEVEL (0) +#define EXAMPLE_LCD_BK_LIGHT_OFF_LEVEL !EXAMPLE_LCD_BK_LIGHT_ON_LEVEL + +/* 定义LCD参数 */ +#define EXAMPLE_LCD_H_RES 320 +#define EXAMPLE_LCD_V_RES 480 + +/* 定义80总线及RAM总线宽度 */ +#define EXAMPLE_LCD_CMD_BITS 8 +#define EXAMPLE_LCD_PARAM_BITS 8 + +/* 定义触摸屏控制IO */ +#define EXAMPLE_I2C_NUM 0 +#define EXAMPLE_I2C_SCL GPIO_NUM_39 +#define EXAMPLE_I2C_SDA GPIO_NUM_38 + +/* 定义LVGL任务参数 */ +#define EXAMPLE_LVGL_TICK_PERIOD_MS 2 +#define EXAMPLE_LVGL_TASK_MAX_DELAY_MS 500 +#define EXAMPLE_LVGL_TASK_MIN_DELAY_MS 1 +#define EXAMPLE_LVGL_TASK_STACK_SIZE (16 * 1024) +#define EXAMPLE_LVGL_TASK_PRIORITY 3 + +#define EXAMPLE_DMA_BURST_SIZE (64) + + +#define CONFIG_EXAMPLE_LCD_I80_BUS_WIDTH 8 +/* 定义LCD像素时钟频率 */ +#define EXAMPLE_LCD_PIXEL_CLOCK_HZ 20000000 + +/** + * @brief lvgl锁 + * + * 加锁以保护临界资源 + * + * @param[in] timeout_ms 锁住LVGL锁时间 + * @return true lvgl锁成功 + * + */ +bool example_lvgl_lock(int timeout_ms); + +/** + * @brief lvgl解锁 + * + * 解锁LVGL锁 + * + */ +void example_lvgl_unlock(void); + +/** + * @brief 最后总的触摸屏及LCD初始化函数 + * + */ +void initialize_display_and_touch(void); + + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /*_USER_I80_DISPLAY_PORT_H*/ \ No newline at end of file diff --git a/main/CMakeLists.txt b/main/CMakeLists.txt index 525c6ba..f862b79 100644 --- a/main/CMakeLists.txt +++ b/main/CMakeLists.txt @@ -8,6 +8,7 @@ set(MAIN_REQUIRES esp_driver_gpio user_power_task user_common + user_i80_display ) # 定义包含目录变量 diff --git a/main/main.c b/main/main.c index e685d54..7917bc8 100644 --- a/main/main.c +++ b/main/main.c @@ -2,7 +2,22 @@ #include "main.h" - +/* 创建LVGL界面(包含按钮) */ +static void lvgl_create_ui(void) +{ + // 创建按钮对象(居中显示) + lv_obj_t *btn = lv_btn_create(lv_scr_act()); // 在屏幕上创建按钮 + lv_obj_set_size(btn, 120, 60); // 设置按钮大小 + lv_obj_center(btn); // 按钮居中 + + // 为按钮添加点击事件 + // lv_obj_add_event_cb(btn, btn_click_event_cb, LV_EVENT_ALL, NULL); + + // 在按钮上创建文本标签 + lv_obj_t *label = lv_label_create(btn); // 在按钮内创建标签 + lv_label_set_text(label, "点击我"); // 设置标签文本 + lv_obj_center(label); // 标签在按钮内居中 +} void app_main(void) @@ -28,7 +43,10 @@ void app_main(void) NULL // 任务句柄 ); + initialize_display_and_touch(); //初始化显示界面和触摸屏 + + lvgl_create_ui(); while (1) diff --git a/main/main.h b/main/main.h index 9602768..01d3462 100644 --- a/main/main.h +++ b/main/main.h @@ -36,7 +36,7 @@ extern "C" { #include "user_power_task.h" #include "user_common.h" - +#include "user_i80_display.h"