Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
 into develop
  • Loading branch information
rzeldent committed Nov 1, 2024
2 parents 9d56cbf + 8755372 commit d056037
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions src/esp32_smartdisplay.c
Original file line number Diff line number Diff line change
Expand Up @@ -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%)
Expand All @@ -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

0 comments on commit d056037

Please sign in to comment.