diff --git a/boards b/boards index ae8d611..4b2c054 160000 --- a/boards +++ b/boards @@ -1 +1 @@ -Subproject commit ae8d611a0ed8dacc744246bcaabd6711ccf793e9 +Subproject commit 4b2c0540acea25c71a67ec1605c8111ecc6367e3 diff --git a/src/esp32_smartdisplay.c b/src/esp32_smartdisplay.c index aa8e6ee..b7f46ea 100644 --- a/src/esp32_smartdisplay.c +++ b/src/esp32_smartdisplay.c @@ -194,6 +194,11 @@ void smartdisplay_init() // Setup TFT display display = lvgl_lcd_init(); +#ifndef DISPLAY_SOFTWARE_ROTATION + // Register callback for hardware rotation + lv_display_add_event_cb(display, lvgl_display_resolution_changed_callback, LV_EVENT_RESOLUTION_CHANGED, NULL); +#endif + // Clear screen lv_obj_clean(lv_scr_act()); // Turn backlight on (50%) @@ -210,3 +215,34 @@ void smartdisplay_init() lv_indev_enable(indev, true); #endif } + +#ifndef DISPLAY_SOFTWARE_ROTATION +// Called when driver resolution is updated (including rotation) +// Top of the display is top left when connector is at the bottom +// The rotation values are relative to how you would rotate the physical display in the clockwise direction. +// So, LV_DISPLAY_ROTATION_90 means you rotate the hardware 90 degrees clockwise, and the display rotates 90 degrees counterclockwise to compensate. +void lvgl_display_resolution_changed_callback(lv_event_t *event) +{ + const esp_lcd_panel_handle_t panel_handle = display->user_data; + switch (display->rotation) + { + case LV_DISPLAY_ROTATION_0: + ESP_ERROR_CHECK(esp_lcd_panel_swap_xy(panel_handle, DISPLAY_SWAP_XY)); + ESP_ERROR_CHECK(esp_lcd_panel_mirror(panel_handle, DISPLAY_MIRROR_X, DISPLAY_MIRROR_Y)); + break; + case LV_DISPLAY_ROTATION_90: + ESP_ERROR_CHECK(esp_lcd_panel_swap_xy(panel_handle, !DISPLAY_SWAP_XY)); + ESP_ERROR_CHECK(esp_lcd_panel_mirror(panel_handle, DISPLAY_MIRROR_X, !DISPLAY_MIRROR_Y)); + break; + case LV_DISPLAY_ROTATION_180: + ESP_ERROR_CHECK(esp_lcd_panel_swap_xy(panel_handle, DISPLAY_SWAP_XY)); + ESP_ERROR_CHECK(esp_lcd_panel_mirror(panel_handle, !DISPLAY_MIRROR_X, !DISPLAY_MIRROR_Y)); + break; + case LV_DISPLAY_ROTATION_270: + ESP_ERROR_CHECK(esp_lcd_panel_swap_xy(panel_handle, !DISPLAY_SWAP_XY)); + ESP_ERROR_CHECK(esp_lcd_panel_mirror(panel_handle, !DISPLAY_MIRROR_X, DISPLAY_MIRROR_Y)); + break; + } +} + +#endif \ No newline at end of file