esp32c3-usb_serial/main/GUI/lvgl_task.c

71 lines
2.5 KiB
C

#include "public.h"
#include "esp_lcd_st7735.h"
#include "driver/gpio.h"
#include "driver/spi_master.h"
#include "esp_timer.h"
#include "esp_lcd_panel_io.h"
#include "esp_lcd_panel_vendor.h"
#include "esp_lcd_panel_ops.h"
static const char *TAG = "lcd";
esp_lcd_panel_handle_t panel_handle = NULL;
void Gui_Task(void *pvParameter)
{
//esp_lcd_panel_handle_t panel_handle = NULL;
(void)pvParameter;
ESP_LOGI(TAG, "Initialize SPI bus");
spi_bus_config_t buscfg = st7735_PANEL_BUS_SPI_CONFIG(GPIO_NUM_36,GPIO_NUM_35,128*160*2);
ESP_ERROR_CHECK(spi_bus_initialize(SPI2_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 = st7735_PANEL_IO_SPI_CONFIG(GPIO_NUM_34,GPIO_NUM_38,NULL,NULL);
// {
// .dc_gpio_num = PIN_NUM_LCD_DC,
// .cs_gpio_num = PIN_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,
// .on_color_trans_done = notify_lvgl_flush_ready,
// //.user_ctx = &disp_drv,
// };
// 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));
ESP_LOGI(TAG, "Install st7735 panel driver");
esp_lcd_panel_dev_config_t panel_config = {
.reset_gpio_num = GPIO_NUM_37,
.rgb_endian = LCD_RGB_ENDIAN_RGB,
.bits_per_pixel = 16,
.color_space = ESP_LCD_COLOR_SPACE_BGR,
};
ESP_ERROR_CHECK(esp_lcd_new_panel_st7735(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, true, true));
esp_lcd_panel_swap_xy(panel_handle, true);
esp_lcd_panel_mirror(panel_handle, false, true);
ESP_LOGI(TAG, "Turn on LCD backlight");
// gpio_set_level(PIN_NUM_BK_LIGHT, LCD_BK_LIGHT_ON_LEVEL);
esp_lcd_panel_swap_xy(panel_handle, false);
esp_lcd_panel_mirror(panel_handle, true, true);
uint8_t* lcd_data;
lcd_data = malloc(128*160*2);
memset(&lcd_data[0],0xff,128*240*2);
esp_lcd_panel_draw_bitmap(panel_handle, 0, 0, 128, 160, &lcd_data[0]);
memset(&lcd_data[0],0x00,320*240*2);
esp_lcd_panel_draw_bitmap(panel_handle, 60, 180, 220, 220, &lcd_data[0]);
vTaskDelete(NULL);
}