From cef95e6926012cdcecdfa165c48ef2eff62e2e6c Mon Sep 17 00:00:00 2001 From: scgan Date: Thu, 2 Mar 2023 12:00:52 +0800 Subject: [PATCH] use APIs in esp_lcd(idfv5.0) for code_recognition example --- examples/code_recognition/main/app_main.c | 7 +- .../code_recognition/main/app_peripherals.c | 85 +++++++++---------- .../main/include/app_peripherals.h | 31 ++++--- 3 files changed, 66 insertions(+), 57 deletions(-) diff --git a/examples/code_recognition/main/app_main.c b/examples/code_recognition/main/app_main.c index fabed41..05c62d6 100644 --- a/examples/code_recognition/main/app_main.c +++ b/examples/code_recognition/main/app_main.c @@ -3,6 +3,7 @@ #include #include "esp_log.h" #include "esp_system.h" +#include "esp_timer.h" #include "freertos/FreeRTOS.h" #include "freertos/task.h" #include "app_peripherals.h" @@ -20,8 +21,8 @@ static void decode_task() #ifdef LCD_CONTROLLER int USE_LCD = 0; - scr_driver_t g_lcd; - if (ESP_OK == app_lcd_init(&g_lcd)) + esp_lcd_panel_handle_t panel_handle = NULL; + if (ESP_OK == app_lcd_init(&panel_handle)) USE_LCD = 1; #endif @@ -53,7 +54,7 @@ static void decode_task() #ifdef LCD_CONTROLLER if(USE_LCD){ - g_lcd.draw_bitmap(0, 0, fb->width, fb->height, (uint16_t *)fb->buf); + esp_lcd_panel_draw_bitmap(panel_handle, 0, 0, fb->width, fb->height, (uint16_t *)fb->buf); } #endif diff --git a/examples/code_recognition/main/app_peripherals.c b/examples/code_recognition/main/app_peripherals.c index 0224d40..7b59a89 100644 --- a/examples/code_recognition/main/app_peripherals.c +++ b/examples/code_recognition/main/app_peripherals.c @@ -1,7 +1,6 @@ #include "app_peripherals.h" #include "esp_log.h" #include "esp_system.h" -#include "st7789.h" static const char *TAG = "app_peripherals"; @@ -81,60 +80,60 @@ esp_err_t app_camera_init() #ifdef LCD_CONTROLLER -esp_err_t app_lcd_init(scr_driver_t *g_lcd){ - static scr_info_t g_lcd_info; +esp_err_t app_lcd_init(esp_lcd_panel_handle_t *panel_handle){ + gpio_config_t bk_gpio_config = { + .mode = GPIO_MODE_OUTPUT, + .pin_bit_mask = 1ULL << LCD_BCKL + }; + ESP_ERROR_CHECK(gpio_config(&bk_gpio_config)); + gpio_set_level(LCD_BCKL, LCD_BK_LIGHT_OFF_LEVEL); - spi_config_t bus_conf = { - .miso_io_num = LCD_MISO, - .mosi_io_num = LCD_MOSI, + spi_bus_config_t bus_conf = { .sclk_io_num = LCD_SCLK, - .max_transfer_sz = 2 * LCD_WIDTH * LCD_HEIGHT + 10, + .mosi_io_num = LCD_MOSI, + .miso_io_num = LCD_MISO, + .quadwp_io_num = -1, + .quadhd_io_num = -1, + .max_transfer_sz = LCD_H_RES * LCD_V_RES * sizeof(uint16_t), }; - spi_bus_handle_t spi_bus = spi_bus_create(SPI2_HOST, &bus_conf); + ESP_ERROR_CHECK(spi_bus_initialize(SPI2_HOST, &bus_conf, SPI_DMA_CH_AUTO)); - scr_interface_spi_config_t spi_lcd_cfg = { - .spi_bus = spi_bus, - .pin_num_cs = LCD_CS, - .pin_num_dc = LCD_DC, - .clk_freq = 40 * 1000000, - .swap_data = 0, + 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 = LCD_DC, + .cs_gpio_num = LCD_CS, + .pclk_hz = LCD_PIXEL_CLOCK_HZ, + .lcd_cmd_bits = LCD_CMD_BITS, + .lcd_param_bits = LCD_PARAM_BITS, + .spi_mode = 0, + .trans_queue_depth = 10, }; + // Attach the LCD to the SPI bus + ESP_ERROR_CHECK(esp_lcd_new_panel_io_spi((esp_lcd_spi_bus_handle_t)SPI2_HOST, &io_config, &io_handle)); - scr_interface_driver_t *iface_drv; - scr_interface_create(SCREEN_IFACE_SPI, &spi_lcd_cfg, &iface_drv); - esp_err_t ret = scr_find_driver(LCD_CONTROLLER, g_lcd); - if (ESP_OK != ret) - { - ESP_LOGE(TAG, "screen find failed"); - return ESP_FAIL; - } - - scr_controller_config_t lcd_cfg = { - .interface_drv = iface_drv, - .pin_num_rst = LCD_RST, - .pin_num_bckl = LCD_BCKL, - .rst_active_level = 0, - .bckl_active_level = 0, - .offset_hor = 0, - .offset_ver = 0, - .width = LCD_WIDTH, - .height = LCD_HEIGHT, - .rotate = LCD_ROTATE, + // ESP_LOGI(TAG, "Install ST7789 panel driver"); + esp_lcd_panel_dev_config_t panel_config = { + .reset_gpio_num = LCD_RST, + .rgb_endian = LCD_RGB_ENDIAN_RGB, + .bits_per_pixel = 16, }; - ret = g_lcd->init(&lcd_cfg); - if (ESP_OK != ret) - { - ESP_LOGE(TAG, "screen initialize failed"); - return ESP_FAIL; - } + 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)); #if CONFIG_CAMERA_MODULE_ESP_S2_KALUGA - lcd_st7789_set_invert(false); + esp_lcd_panel_invert_color(*panel_handle, false); + esp_lcd_panel_mirror(*panel_handle, 1, 0); //mirror_x + esp_lcd_panel_swap_xy(*panel_handle, 1);//swap_xy + #else + esp_lcd_panel_invert_color(*panel_handle, true);// Set inversion for esp32s3eye #endif - g_lcd->get_info(&g_lcd_info); - ESP_LOGI(TAG, "Screen name:%s | width:%d | height:%d", g_lcd_info.name, g_lcd_info.width, g_lcd_info.height); + // turn on display + esp_lcd_panel_disp_on_off(*panel_handle, true); + gpio_set_level(LCD_BCKL, LCD_BK_LIGHT_ON_LEVEL); return ESP_OK; } #endif \ No newline at end of file diff --git a/examples/code_recognition/main/include/app_peripherals.h b/examples/code_recognition/main/include/app_peripherals.h index 891e87a..6c959ee 100644 --- a/examples/code_recognition/main/include/app_peripherals.h +++ b/examples/code_recognition/main/include/app_peripherals.h @@ -6,7 +6,11 @@ #include "freertos/semphr.h" #include "esp_camera.h" -#include "screen_driver.h" +#include "driver/spi_master.h" +#include "driver/gpio.h" +#include "esp_lcd_panel_io.h" +#include "esp_lcd_panel_vendor.h" +#include "esp_lcd_panel_ops.h" // camera pins @@ -195,7 +199,7 @@ #define CAMERA_PIN_PCLK CONFIG_CAMERA_PIN_PCLK #endif -#define XCLK_FREQ_HZ 20000000 +#define XCLK_FREQ_HZ 15000000 #define CAMERA_PIXFORMAT PIXFORMAT_RGB565 #define CAMERA_FRAME_SIZE FRAMESIZE_240X240 #define CAMERA_FB_COUNT 2 @@ -213,10 +217,13 @@ #define LCD_DC 43 #define LCD_RST -1 #define LCD_BCKL 48 - -#define LCD_WIDTH 240 -#define LCD_HEIGHT 240 -#define LCD_ROTATE 0 +#define LCD_CMD_BITS 8 +#define LCD_PARAM_BITS 8 +#define LCD_PIXEL_CLOCK_HZ (40 * 1000 * 1000) +#define LCD_BK_LIGHT_ON_LEVEL 0 +#define LCD_BK_LIGHT_OFF_LEVEL !LCD_BK_LIGHT_ON_LEVEL +#define LCD_H_RES 240 +#define LCD_V_RES 240 #elif CONFIG_CAMERA_MODULE_ESP_S2_KALUGA #define LCD_CONTROLLER SCREEN_CONTROLLER_ST7789 @@ -227,11 +234,13 @@ #define LCD_DC 13 #define LCD_RST 16 #define LCD_BCKL 6 - -// LCD display width and height -#define LCD_WIDTH 240 -#define LCD_HEIGHT 320 -#define LCD_ROTATE SCR_SWAP_XY|SCR_MIRROR_X +#define LCD_CMD_BITS 8 +#define LCD_PARAM_BITS 8 +#define LCD_PIXEL_CLOCK_HZ (40 * 1000 * 1000) +#define LCD_BK_LIGHT_ON_LEVEL 0 +#define LCD_BK_LIGHT_OFF_LEVEL !LCD_BK_LIGHT_ON_LEVEL +#define LCD_H_RES 240 +#define LCD_V_RES 320 #endif