feat: 重构项目结构以支持新的用户界面和功能
- 更新 CMakeLists.txt,添加新的源文件和依赖项以支持应用程序结构 - 移除旧的 main.c 和 lvgl_demo_ui.c 文件,整合应用逻辑至 app_main.c - 新增 app/ui_handlers.c 和 app/ui_handlers.h,准备处理 UI 事件 - 引入 bsp/display.c 和 bsp/touch.c,配置显示和触摸功能 - 添加 services/wifi_manager.c,管理 Wi-Fi 连接 - 组织 UI 组件和资源,提升代码可维护性与可读性 - 更新相关头文件和配置,确保项目兼容性与功能完整性
This commit is contained in:
@@ -0,0 +1,98 @@
|
||||
#include "display.h"
|
||||
|
||||
#include "board_config.h"
|
||||
|
||||
#include "driver/gpio.h"
|
||||
#include "driver/ledc.h"
|
||||
#include "driver/spi_master.h"
|
||||
#include "esp_lcd_panel_ops.h"
|
||||
#include "esp_lcd_panel_st7789.h"
|
||||
#include "esp_lcd_panel_vendor.h"
|
||||
#include "esp_log.h"
|
||||
|
||||
static const char *TAG = "display";
|
||||
|
||||
void display_backlight_set_brightness(uint16_t brightness)
|
||||
{
|
||||
if (brightness > 1023) {
|
||||
brightness = 1023;
|
||||
}
|
||||
ESP_ERROR_CHECK(
|
||||
ledc_set_duty(LEDC_LOW_SPEED_MODE, BOARD_LCD_BK_LIGHT_CH, brightness));
|
||||
ESP_ERROR_CHECK(
|
||||
ledc_update_duty(LEDC_LOW_SPEED_MODE, BOARD_LCD_BK_LIGHT_CH));
|
||||
}
|
||||
|
||||
void display_backlight_on(void)
|
||||
{
|
||||
display_backlight_set_brightness(1023);
|
||||
}
|
||||
|
||||
esp_err_t display_init(esp_lcd_panel_io_handle_t *io_handle_out,
|
||||
esp_lcd_panel_handle_t *panel_handle_out)
|
||||
{
|
||||
ESP_LOGI(TAG, "Configure LCD backlight PWM");
|
||||
ledc_timer_config_t ledc_timer = {
|
||||
.speed_mode = LEDC_LOW_SPEED_MODE,
|
||||
.timer_num = BOARD_LCD_BK_LIGHT_TIMER,
|
||||
.duty_resolution = LEDC_TIMER_10_BIT,
|
||||
.freq_hz = BOARD_LCD_BK_LIGHT_FREQ,
|
||||
.clk_cfg = LEDC_AUTO_CLK,
|
||||
};
|
||||
ESP_ERROR_CHECK(ledc_timer_config(&ledc_timer));
|
||||
|
||||
ledc_channel_config_t ledc_channel = {
|
||||
.speed_mode = LEDC_LOW_SPEED_MODE,
|
||||
.channel = BOARD_LCD_BK_LIGHT_CH,
|
||||
.timer_sel = BOARD_LCD_BK_LIGHT_TIMER,
|
||||
.intr_type = LEDC_INTR_DISABLE,
|
||||
.gpio_num = BOARD_PIN_BK_LIGHT,
|
||||
.duty = 0,
|
||||
.hpoint = 0,
|
||||
};
|
||||
ESP_ERROR_CHECK(ledc_channel_config(&ledc_channel));
|
||||
|
||||
ESP_LOGI(TAG, "Initialize SPI bus");
|
||||
spi_bus_config_t buscfg = {
|
||||
.sclk_io_num = BOARD_PIN_LCD_SCLK,
|
||||
.mosi_io_num = BOARD_PIN_LCD_MOSI,
|
||||
.miso_io_num = BOARD_PIN_LCD_MISO,
|
||||
.quadwp_io_num = -1,
|
||||
.quadhd_io_num = -1,
|
||||
.max_transfer_sz = BOARD_LCD_H_RES * 80 * sizeof(uint16_t),
|
||||
};
|
||||
ESP_ERROR_CHECK(spi_bus_initialize(BOARD_LCD_HOST, &buscfg, SPI_DMA_CH_AUTO));
|
||||
|
||||
ESP_LOGI(TAG, "Install panel IO");
|
||||
esp_lcd_panel_io_handle_t io_handle = NULL;
|
||||
esp_lcd_panel_io_spi_config_t io_config = {
|
||||
.dc_gpio_num = BOARD_PIN_LCD_DC,
|
||||
.cs_gpio_num = BOARD_PIN_LCD_CS,
|
||||
.pclk_hz = BOARD_LCD_PIXEL_CLOCK_HZ,
|
||||
.lcd_cmd_bits = BOARD_LCD_CMD_BITS,
|
||||
.lcd_param_bits = BOARD_LCD_PARAM_BITS,
|
||||
.spi_mode = 0,
|
||||
.trans_queue_depth = 10,
|
||||
};
|
||||
ESP_ERROR_CHECK(esp_lcd_new_panel_io_spi(BOARD_LCD_HOST, &io_config, &io_handle));
|
||||
|
||||
esp_lcd_panel_handle_t panel_handle = NULL;
|
||||
esp_lcd_panel_dev_config_t panel_config = {
|
||||
.reset_gpio_num = BOARD_PIN_LCD_RST,
|
||||
.rgb_ele_order = LCD_RGB_ELEMENT_ORDER_BGR,
|
||||
.bits_per_pixel = 16,
|
||||
};
|
||||
ESP_LOGI(TAG, "Install ST7789 panel driver");
|
||||
ESP_ERROR_CHECK(esp_lcd_new_panel_st7789(io_handle, &panel_config, &panel_handle));
|
||||
ESP_ERROR_CHECK(esp_lcd_panel_reset(panel_handle));
|
||||
ESP_ERROR_CHECK(esp_lcd_panel_init(panel_handle));
|
||||
ESP_ERROR_CHECK(esp_lcd_panel_mirror(panel_handle, false, false));
|
||||
ESP_ERROR_CHECK(esp_lcd_panel_disp_on_off(panel_handle, true));
|
||||
|
||||
ESP_LOGI(TAG, "Turn on LCD backlight");
|
||||
gpio_set_level(BOARD_PIN_BK_LIGHT, BOARD_LCD_BK_LIGHT_ON_LEVEL);
|
||||
|
||||
*io_handle_out = io_handle;
|
||||
*panel_handle_out = panel_handle;
|
||||
return ESP_OK;
|
||||
}
|
||||
Reference in New Issue
Block a user