diff --git a/boards b/boards index e864619..01c9ec4 160000 --- a/boards +++ b/boards @@ -1 +1 @@ -Subproject commit e864619f48bb75cfb7d1db3387ffa5897126aa5f +Subproject commit 01c9ec49dda86a9b4d8cca59d5cfa1786843c1b1 diff --git a/platformio.ini b/platformio.ini index b2e4a2d..3d6030f 100644 --- a/platformio.ini +++ b/platformio.ini @@ -24,7 +24,7 @@ #default_envs = esp32-2432S032C #default_envs = esp32-2432S032N #default_envs = esp32-2432S032R -#default_envs = esp32-3248S035C +default_envs = esp32-3248S035C #default_envs = esp32-3248S035R #default_envs = esp32-4827S043C #default_envs = esp32-4827S043N diff --git a/src/esp32_smartdisplay.c b/src/esp32_smartdisplay.c index a22dd2f..1dad249 100644 --- a/src/esp32_smartdisplay.c +++ b/src/esp32_smartdisplay.c @@ -1,4 +1,5 @@ #include +#include #ifdef BOARD_HAS_TOUCH #include @@ -136,17 +137,41 @@ touch_calibration_data_t smartdisplay_compute_touch_calibration(const lv_point_t }; #endif +// Called when driver parameters are updated (rotation) +// Top of the display is top left when connector is at the bottom +static void lvgl_update_callback(lv_disp_drv_t *drv) +{ + const esp_lcd_panel_handle_t panel_handle = disp_drv.user_data; + switch (drv->rotated) + { + case LV_DISP_ROT_NONE: + ESP_ERROR_CHECK(esp_lcd_panel_swap_xy(panel_handle, LCD_SWAP_XY)); + ESP_ERROR_CHECK(esp_lcd_panel_mirror(panel_handle, LCD_MIRROR_X, LCD_MIRROR_Y)); + break; + case LV_DISP_ROT_90: + ESP_ERROR_CHECK(esp_lcd_panel_swap_xy(panel_handle, !LCD_SWAP_XY)); + ESP_ERROR_CHECK(esp_lcd_panel_mirror(panel_handle, !LCD_MIRROR_X, LCD_MIRROR_Y)); + break; + case LV_DISP_ROT_180: + ESP_ERROR_CHECK(esp_lcd_panel_swap_xy(panel_handle, LCD_SWAP_XY)); + ESP_ERROR_CHECK(esp_lcd_panel_mirror(panel_handle, !LCD_MIRROR_X, !LCD_MIRROR_Y)); + break; + case LV_DISP_ROT_270: + ESP_ERROR_CHECK(esp_lcd_panel_swap_xy(panel_handle, !LCD_SWAP_XY)); + ESP_ERROR_CHECK(esp_lcd_panel_mirror(panel_handle, LCD_MIRROR_X, !LCD_MIRROR_Y)); + break; + } +} + void smartdisplay_init() { log_d("smartdisplay_init"); #ifdef BOARD_HAS_RGB_LED // Setup RGB LED. High is off pinMode(RGB_LED_R, OUTPUT); - digitalWrite(RGB_LED_R, true); pinMode(RGB_LED_G, OUTPUT); - digitalWrite(RGB_LED_G, true); pinMode(RGB_LED_B, OUTPUT); - digitalWrite(RGB_LED_B, true); + smartdisplay_led_set_rgb(false, false, false); #endif #ifdef BOARD_HAS_CDS @@ -183,6 +208,8 @@ void smartdisplay_init() disp_drv.draw_buf = (lv_disp_draw_buf_t *)malloc(sizeof(lv_disp_draw_buf_t)); void *drawBuffer = heap_caps_malloc(sizeof(lv_color_t) * LVGL_BUFFER_PIXELS, LVGL_BUFFER_MALLOC_FLAGS); lv_disp_draw_buf_init(disp_drv.draw_buf, drawBuffer, NULL, LVGL_BUFFER_PIXELS); + // Register callback for changes to the driver parameters (rotation!) + disp_drv.drv_update_cb = lvgl_update_callback; // Initialize specific driver lvgl_lcd_init(&disp_drv); __attribute__((unused)) lv_disp_t *display = lv_disp_drv_register(&disp_drv); diff --git a/src/lvgl_touch_cst816s_i2c.c b/src/lvgl_touch_cst816s_i2c.c index b91cd7f..5d615e0 100644 --- a/src/lvgl_touch_cst816s_i2c.c +++ b/src/lvgl_touch_cst816s_i2c.c @@ -69,7 +69,7 @@ void lvgl_touch_init(lv_indev_drv_t *drv) .levels = { .reset = CST816S_TOUCH_CONFIG_LEVELS_RESET, .interrupt = CST816S_TOUCH_CONFIG_LEVELS_INTERRUPT}, - .flags = {.swap_xy = TOUCH_MIRROR_XY, .mirror_x = TOUCH_MIRROR_X, .mirror_y = TOUCH_MIRROR_Y}, + .flags = {.swap_xy = TOUCH_SWAP_XY, .mirror_x = TOUCH_MIRROR_X, .mirror_y = TOUCH_MIRROR_Y}, .user_data = io_handle}; log_d("touch_config: x_max:%d, y_max:%d, rst_gpio_num:%d, int_gpio_num:%d, levels:{reset:%d, interrupt:%d}, flags:{swap_xy:%d, mirror_x:%d, mirror_y:%d}, user_data:0x%08x", touch_config.x_max, touch_config.y_max, touch_config.rst_gpio_num, touch_config.int_gpio_num, touch_config.levels.reset, touch_config.levels.interrupt, touch_config.flags.swap_xy, touch_config.flags.mirror_x, touch_config.flags.mirror_y, touch_config.user_data); esp_lcd_touch_handle_t touch_handle; diff --git a/src/lvgl_touch_gt911_i2c.c b/src/lvgl_touch_gt911_i2c.c index 38dc776..2b09a26 100644 --- a/src/lvgl_touch_gt911_i2c.c +++ b/src/lvgl_touch_gt911_i2c.c @@ -70,7 +70,7 @@ void lvgl_touch_init(lv_indev_drv_t *drv) .levels = { .reset = GT911_TOUCH_CONFIG_LEVELS_RESET, .interrupt = GT911_TOUCH_CONFIG_LEVELS_INTERRUPT}, - .flags = {.swap_xy = TOUCH_MIRROR_XY, .mirror_x = TOUCH_MIRROR_X, .mirror_y = TOUCH_MIRROR_Y}, + .flags = {.swap_xy = TOUCH_SWAP_XY, .mirror_x = TOUCH_MIRROR_X, .mirror_y = TOUCH_MIRROR_Y}, .user_data = io_handle}; log_d("touch_config: x_max:%d, y_max:%d, rst_gpio_num:%d, int_gpio_num:%d, levels:{reset:%d, interrupt:%d}, flags:{swap_xy:%d, mirror_x:%d, mirror_y:%d}, user_data:0x%08x", touch_config.x_max, touch_config.y_max, touch_config.rst_gpio_num, touch_config.int_gpio_num, touch_config.levels.reset, touch_config.levels.interrupt, touch_config.flags.swap_xy, touch_config.flags.mirror_x, touch_config.flags.mirror_y, touch_config.user_data); esp_lcd_touch_handle_t touch_handle; diff --git a/src/lvgl_touch_xpt2046_spi.c b/src/lvgl_touch_xpt2046_spi.c index 175e006..2147dc4 100644 --- a/src/lvgl_touch_xpt2046_spi.c +++ b/src/lvgl_touch_xpt2046_spi.c @@ -69,7 +69,7 @@ void lvgl_touch_init(lv_indev_drv_t *drv) .levels = { .reset = XPT2046_TOUCH_CONFIG_LEVELS_RESET, .interrupt = XPT2046_TOUCH_CONFIG_LEVELS_INTERRUPT}, - .flags = {.swap_xy = TOUCH_MIRROR_XY, .mirror_x = TOUCH_MIRROR_X, .mirror_y = TOUCH_MIRROR_Y}, + .flags = {.swap_xy = TOUCH_SWAP_XY, .mirror_x = TOUCH_MIRROR_X, .mirror_y = TOUCH_MIRROR_Y}, .user_data = io_handle}; log_d("touch_config: x_max:%d, y_max:%d, rst_gpio_num:%d, int_gpio_num:%d, levels:{reset:%d, interrupt:%d}, flags:{swap_xy:%d, mirror_x:%d, mirror_y:%d}, user_data:0x%08x", touch_config.x_max, touch_config.y_max, touch_config.rst_gpio_num, touch_config.int_gpio_num, touch_config.levels.reset, touch_config.levels.interrupt, touch_config.flags.swap_xy, touch_config.flags.mirror_x, touch_config.flags.mirror_y, touch_config.user_data); esp_lcd_touch_handle_t touch_handle;