@@ -194,6 +194,11 @@ void smartdisplay_init()
194
194
// Setup TFT display
195
195
display = lvgl_lcd_init ();
196
196
197
+ #ifndef DISPLAY_SOFTWARE_ROTATION
198
+ // Register callback for hardware rotation
199
+ lv_display_add_event_cb (display , lvgl_display_resolution_changed_callback , LV_EVENT_RESOLUTION_CHANGED , NULL );
200
+ #endif
201
+
197
202
// Clear screen
198
203
lv_obj_clean (lv_scr_act ());
199
204
// Turn backlight on (50%)
@@ -210,3 +215,34 @@ void smartdisplay_init()
210
215
lv_indev_enable (indev , true);
211
216
#endif
212
217
}
218
+
219
+ #ifndef DISPLAY_SOFTWARE_ROTATION
220
+ // Called when driver resolution is updated (including rotation)
221
+ // Top of the display is top left when connector is at the bottom
222
+ // The rotation values are relative to how you would rotate the physical display in the clockwise direction.
223
+ // So, LV_DISPLAY_ROTATION_90 means you rotate the hardware 90 degrees clockwise, and the display rotates 90 degrees counterclockwise to compensate.
224
+ void lvgl_display_resolution_changed_callback (lv_event_t * event )
225
+ {
226
+ const esp_lcd_panel_handle_t panel_handle = display -> user_data ;
227
+ switch (display -> rotation )
228
+ {
229
+ case LV_DISPLAY_ROTATION_0 :
230
+ ESP_ERROR_CHECK (esp_lcd_panel_swap_xy (panel_handle , DISPLAY_SWAP_XY ));
231
+ ESP_ERROR_CHECK (esp_lcd_panel_mirror (panel_handle , DISPLAY_MIRROR_X , DISPLAY_MIRROR_Y ));
232
+ break ;
233
+ case LV_DISPLAY_ROTATION_90 :
234
+ ESP_ERROR_CHECK (esp_lcd_panel_swap_xy (panel_handle , !DISPLAY_SWAP_XY ));
235
+ ESP_ERROR_CHECK (esp_lcd_panel_mirror (panel_handle , DISPLAY_MIRROR_X , !DISPLAY_MIRROR_Y ));
236
+ break ;
237
+ case LV_DISPLAY_ROTATION_180 :
238
+ ESP_ERROR_CHECK (esp_lcd_panel_swap_xy (panel_handle , DISPLAY_SWAP_XY ));
239
+ ESP_ERROR_CHECK (esp_lcd_panel_mirror (panel_handle , !DISPLAY_MIRROR_X , !DISPLAY_MIRROR_Y ));
240
+ break ;
241
+ case LV_DISPLAY_ROTATION_270 :
242
+ ESP_ERROR_CHECK (esp_lcd_panel_swap_xy (panel_handle , !DISPLAY_SWAP_XY ));
243
+ ESP_ERROR_CHECK (esp_lcd_panel_mirror (panel_handle , !DISPLAY_MIRROR_X , DISPLAY_MIRROR_Y ));
244
+ break ;
245
+ }
246
+ }
247
+
248
+ #endif
0 commit comments