void Gui_Task(void *arg)
{
static lv_disp_draw_buf_t disp_buf;
static lv_disp_drv_t disp_drv;
ESP_LOGI(TAG, "Create semaphores");
sem_vsync_end = xSemaphoreCreateBinary();
assert(sem_vsync_end);
sem_gui_ready = xSemaphoreCreateBinary();
assert(sem_gui_ready);
init_backlight_pwm();
ESP_LOGI(TAG, "Install RGB LCD panel driver");
esp_lcd_panel_handle_t panel_handle = NULL;
esp_lcd_rgb_panel_config_t panel_config = {
.data_width = 16, // RGB565 in parallel mode, thus 16bit in width
.psram_trans_align = 64,
.clk_src = LCD_CLK_SRC_DEFAULT,
.disp_gpio_num = PIN_NUM_DISP_EN,
.pclk_gpio_num = PIN_NUM_PCLK,
.vsync_gpio_num = PIN_NUM_VSYNC,
.hsync_gpio_num = PIN_NUM_HSYNC,
.de_gpio_num = PIN_NUM_DE,
.data_gpio_nums = {
PIN_NUM_DATA0,PIN_NUM_DATA1,PIN_NUM_DATA2,PIN_NUM_DATA3,PIN_NUM_DATA4,
PIN_NUM_DATA5,PIN_NUM_DATA6,PIN_NUM_DATA7,PIN_NUM_DATA8,PIN_NUM_DATA9,
PIN_NUM_DATA10,PIN_NUM_DATA11,PIN_NUM_DATA12,PIN_NUM_DATA13,PIN_NUM_DATA14,PIN_NUM_DATA15,
},
.timings = {
.pclk_hz = LCD_PIXEL_CLOCK_HZ,
.h_res = LCD_H_RES,
.v_res = LCD_V_RES,
.hsync_back_porch = HSYNC_BACK_PORCH,
.hsync_front_porch = HSYNC_FRONT_PORCH,
.hsync_pulse_width = HSYNC_PULSE_WIDTH,
.vsync_back_porch = VSYNC_BACK_PORCH,
.vsync_front_porch = VSYNC_FRONT_PORCH,
.vsync_pulse_width = VSYNC_PULSE_WIDTH,
.flags.pclk_active_neg = true,
},
.flags.fb_in_psram = true,
};
ESP_ERROR_CHECK(esp_lcd_new_rgb_panel(&panel_config, &panel_handle));
ESP_LOGI(TAG, "Register event callbacks");
esp_lcd_rgb_panel_event_callbacks_t cbs = {
.on_vsync = on_vsync_event,
};
ESP_ERROR_CHECK(esp_lcd_rgb_panel_register_event_callbacks(panel_handle, &cbs, &disp_drv));
ESP_LOGI(TAG, "Initialize RGB LCD panel");
ESP_ERROR_CHECK(esp_lcd_panel_reset(panel_handle));
ESP_ERROR_CHECK(esp_lcd_panel_init(panel_handle));
i2c_master_init();
esp_lcd_touch_config_t tp_cfg = {
.x_max =LCD_H_RES,
.y_max = LCD_V_RES,
.rst_gpio_num = TOUCH_GT911_RST,
.int_gpio_num = -1,
.flags = {
.swap_xy = 0,
.mirror_x = 0,
.mirror_y = 0,
},
};
esp_lcd_panel_io_handle_t tp_io_handle = NULL;
esp_lcd_panel_io_i2c_config_t io_config = ESP_LCD_TOUCH_IO_I2C_GT911_CONFIG();
ESP_ERROR_CHECK(esp_lcd_new_panel_io_i2c((esp_lcd_i2c_bus_handle_t)I2C_NUM_0, &io_config, &tp_io_handle));
ESP_LOGI(TAG, "Initialize touch controller GT911");
ESP_ERROR_CHECK(esp_lcd_touch_new_i2c_gt911(tp_io_handle, &tp_cfg, &tp));
ESP_LOGI(TAG, "Initialize LVGL library");
lv_init();
void *buf1 = NULL;
void *buf2 = NULL;
buf1 = heap_caps_malloc(LCD_H_RES * 100 * sizeof(lv_color_t), MALLOC_CAP_SPIRAM);
assert(buf1);
buf2 = heap_caps_malloc(LCD_H_RES * 100 * sizeof(lv_color_t), MALLOC_CAP_SPIRAM);
assert(buf2);
lv_disp_draw_buf_init(&disp_buf, buf1, buf2, LCD_H_RES * 100);
ESP_LOGI(TAG, "Register display driver to LVGL");
lv_disp_drv_init(&disp_drv);
disp_drv.hor_res = LCD_H_RES;
disp_drv.ver_res = LCD_V_RES;
disp_drv.flush_cb = 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);
/**** Init Touchpad GT911 **********/
static lv_indev_drv_t indev_drv;
lv_indev_drv_init(&indev_drv);
indev_drv.type = LV_INDEV_TYPE_POINTER;
indev_drv.disp = disp;
indev_drv.read_cb = lvgl_touch_cb;
indev_drv.user_data = tp;
lv_indev_drv_register(&indev_drv);
ui_init();
xTaskCreatePinnedToCore(Tick_Task, "Tick_Task", 4096, NULL,1, &tickTaskHandle, TICK_TASK_CORE);
while(1){
lv_timer_handler();
vTaskDelay(GUI_PERIOD);
}
}