From 45c0432949485129c3ec000f3fb75439af2e472b Mon Sep 17 00:00:00 2001 From: Rene Zeldenthuis Date: Sun, 10 Dec 2023 20:29:34 +0100 Subject: [PATCH] Software Rotation --- src/esp32_smartdisplay.c | 10 ++++++++-- src/smartdisplay_gc9a01.c | 4 ++++ src/smartdisplay_ili9341.c | 4 ++++ src/smartdisplay_rgb.c | 4 ++++ src/smartdisplay_st7789.c | 4 ++++ src/smartdisplay_st7796.c | 4 ++++ 6 files changed, 28 insertions(+), 2 deletions(-) diff --git a/src/esp32_smartdisplay.c b/src/esp32_smartdisplay.c index ae1bfc2..087df15 100644 --- a/src/esp32_smartdisplay.c +++ b/src/esp32_smartdisplay.c @@ -24,12 +24,13 @@ static void lvgl_update_callback(lv_disp_drv_t *drv) { esp_lcd_panel_handle_t panel_handle = disp_drv.user_data; esp_lcd_touch_handle_t touch_handle = indev_drv.user_data; -#ifdef PANEL_SWAP_XY switch (drv->rotated) { case LV_DISP_ROT_NONE: +#if defined(PANEL_SWAP_XY) && defined(PANEL_MIRROR_X) && defined(PANEL_MIRROR_Y) ESP_ERROR_CHECK(esp_lcd_panel_swap_xy(panel_handle, PANEL_SWAP_XY)); ESP_ERROR_CHECK(esp_lcd_panel_mirror(panel_handle, PANEL_MIRROR_X, PANEL_MIRROR_Y)); +#endif #if defined(PANEL_GAP_X) || defined(PANEL_GAP_Y) ESP_ERROR_CHECK(esp_lcd_panel_set_gap(panel_handle, PANEL_GAP_X, PANEL_GAP_Y)); #endif @@ -39,8 +40,10 @@ static void lvgl_update_callback(lv_disp_drv_t *drv) #endif break; case LV_DISP_ROT_90: +#if defined(PANEL_SWAP_XY) && defined(PANEL_MIRROR_X) && defined(PANEL_MIRROR_Y) ESP_ERROR_CHECK(esp_lcd_panel_swap_xy(panel_handle, !PANEL_SWAP_XY)); ESP_ERROR_CHECK(esp_lcd_panel_mirror(panel_handle, !PANEL_MIRROR_X, PANEL_MIRROR_Y)); +#endif #if defined(PANEL_GAP_X) || defined(PANEL_GAP_Y) ESP_ERROR_CHECK(esp_lcd_panel_set_gap(panel_handle, PANEL_GAP_Y, PANEL_GAP_X)); #endif @@ -50,8 +53,10 @@ static void lvgl_update_callback(lv_disp_drv_t *drv) #endif break; case LV_DISP_ROT_180: +#if defined(PANEL_SWAP_XY) && defined(PANEL_MIRROR_X) && defined(PANEL_MIRROR_Y) ESP_ERROR_CHECK(esp_lcd_panel_swap_xy(panel_handle, PANEL_SWAP_XY)); ESP_ERROR_CHECK(esp_lcd_panel_mirror(panel_handle, !PANEL_MIRROR_X, !PANEL_MIRROR_Y)); +#endif #if defined(PANEL_GAP_X) || defined(PANEL_GAP_Y) ESP_ERROR_CHECK(esp_lcd_panel_set_gap(panel_handle, PANEL_GAP_X, PANEL_GAP_Y)); #endif @@ -61,8 +66,10 @@ static void lvgl_update_callback(lv_disp_drv_t *drv) #endif break; case LV_DISP_ROT_270: +#if defined(PANEL_SWAP_XY) && defined(PANEL_MIRROR_X) && defined(PANEL_MIRROR_Y) ESP_ERROR_CHECK(esp_lcd_panel_swap_xy(panel_handle, !PANEL_SWAP_XY)); ESP_ERROR_CHECK(esp_lcd_panel_mirror(panel_handle, PANEL_MIRROR_X, !PANEL_MIRROR_Y)); +#endif #if defined(PANEL_GAP_X) || defined(PANEL_GAP_Y) ESP_ERROR_CHECK(esp_lcd_panel_set_gap(panel_handle, PANEL_GAP_Y, PANEL_GAP_X)); #endif @@ -72,7 +79,6 @@ static void lvgl_update_callback(lv_disp_drv_t *drv) #endif break; } -#endif } void smartdisplay_init() diff --git a/src/smartdisplay_gc9a01.c b/src/smartdisplay_gc9a01.c index c405cfb..8adfabe 100644 --- a/src/smartdisplay_gc9a01.c +++ b/src/smartdisplay_gc9a01.c @@ -31,6 +31,10 @@ void gc9a01_lv_flush(lv_disp_drv_t *drv, const lv_area_t *area, lv_color16_t *co void lvgl_tft_init(lv_disp_drv_t *drv) { + // Hardware rotation is supported + drv->sw_rotate = 0; + drv->rotated = LV_DISP_ROT_NONE; + // Create SPI bus const spi_bus_config_t spi_bus_config = GC9A01_SPI_BUS_CONFIG; ESP_ERROR_CHECK_WITHOUT_ABORT(spi_bus_initialize(GC9A01_SPI_HOST, &spi_bus_config, SPI_DMA_CH_AUTO)); diff --git a/src/smartdisplay_ili9341.c b/src/smartdisplay_ili9341.c index 64d623f..2a3fe49 100644 --- a/src/smartdisplay_ili9341.c +++ b/src/smartdisplay_ili9341.c @@ -31,6 +31,10 @@ static void ili9341_lv_flush(lv_disp_drv_t *drv, const lv_area_t *area, lv_color void lvgl_tft_init(lv_disp_drv_t *drv) { + // Hardware rotation is supported + drv->sw_rotate = 0; + drv->rotated = LV_DISP_ROT_NONE; + // Create SPI bus const spi_bus_config_t spi_bus_config = ILI9341_SPI_BUS_CONFIG; ESP_ERROR_CHECK_WITHOUT_ABORT(spi_bus_initialize(ILI9341_SPI_HOST, &spi_bus_config, SPI_DMA_CH_AUTO)); diff --git a/src/smartdisplay_rgb.c b/src/smartdisplay_rgb.c index c91eba6..dff822d 100644 --- a/src/smartdisplay_rgb.c +++ b/src/smartdisplay_rgb.c @@ -21,6 +21,10 @@ static void direct_io_lv_flush(lv_disp_drv_t *drv, const lv_area_t *area, lv_col void lvgl_tft_init(lv_disp_drv_t *drv) { + // Hardware rotation is NOT supported + drv->sw_rotate = 1; + drv->rotated = LV_DISP_ROT_NONE; + // Create direct_io panel handle esp_lcd_rgb_panel_config_t tft_panel_config = RBG_PANEL_CONFIG; tft_panel_config.on_frame_trans_done = direct_io_frame_trans_done; diff --git a/src/smartdisplay_st7789.c b/src/smartdisplay_st7789.c index 343c929..f15b53b 100644 --- a/src/smartdisplay_st7789.c +++ b/src/smartdisplay_st7789.c @@ -29,6 +29,10 @@ static void st7789_lv_flush(lv_disp_drv_t *drv, const lv_area_t *area, lv_color1 void lvgl_tft_init(lv_disp_drv_t *drv) { + // Hardware rotation is supported + drv->sw_rotate = 0; + drv->rotated = LV_DISP_ROT_NONE; + // Create SPI bus const spi_bus_config_t spi_bus_config = ST7789_SPI_BUS_CONFIG; ESP_ERROR_CHECK_WITHOUT_ABORT(spi_bus_initialize(ST7789_SPI_HOST, &spi_bus_config, SPI_DMA_CH_AUTO)); diff --git a/src/smartdisplay_st7796.c b/src/smartdisplay_st7796.c index cb030d0..2322779 100644 --- a/src/smartdisplay_st7796.c +++ b/src/smartdisplay_st7796.c @@ -31,6 +31,10 @@ static void st7796_lv_flush(lv_disp_drv_t *drv, const lv_area_t *area, lv_color1 void lvgl_tft_init(lv_disp_drv_t *drv) { + // Hardware rotation is supported + drv->sw_rotate = 0; + drv->rotated = LV_DISP_ROT_NONE; + // Create SPI bus const spi_bus_config_t spi_bus_config = ST7796_SPI_BUS_CONFIG; ESP_ERROR_CHECK_WITHOUT_ABORT(spi_bus_initialize(ST7796_SPI_HOST, &spi_bus_config, SPI_DMA_CH_AUTO));