From 5f6eac2283d05ce7d33e18df863ba1d40ec74e17 Mon Sep 17 00:00:00 2001 From: Vilem Zavodny Date: Tue, 6 Dec 2022 15:24:19 +0100 Subject: [PATCH] lcd: Support rotation SSD1306 and fix mirror y. --- .../esp_lcd/src/esp_lcd_panel_ssd1306.c | 21 +++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/components/esp_lcd/src/esp_lcd_panel_ssd1306.c b/components/esp_lcd/src/esp_lcd_panel_ssd1306.c index 86d73bfde8..8d78eba72c 100644 --- a/components/esp_lcd/src/esp_lcd_panel_ssd1306.c +++ b/components/esp_lcd/src/esp_lcd_panel_ssd1306.c @@ -56,6 +56,7 @@ typedef struct { int x_gap; int y_gap; unsigned int bits_per_pixel; + bool swap_axes; } ssd1306_panel_t; esp_err_t esp_lcd_new_panel_ssd1306(const esp_lcd_panel_io_handle_t io, const esp_lcd_panel_dev_config_t *panel_dev_config, esp_lcd_panel_handle_t *ret_panel) @@ -143,6 +144,8 @@ static esp_err_t panel_ssd1306_init(esp_lcd_panel_t *panel) esp_lcd_panel_io_tx_param(io, SSD1306_CMD_SET_CHARGE_PUMP, (uint8_t[]) { 0x14 // enable charge pump }, 1); + esp_lcd_panel_io_tx_param(io, SSD1306_CMD_MIRROR_X_OFF, NULL, 0); + esp_lcd_panel_io_tx_param(io, SSD1306_CMD_MIRROR_Y_OFF, NULL, 0); return ESP_OK; } @@ -151,11 +154,22 @@ static esp_err_t panel_ssd1306_draw_bitmap(esp_lcd_panel_t *panel, int x_start, ssd1306_panel_t *ssd1306 = __containerof(panel, ssd1306_panel_t, base); assert((x_start < x_end) && (y_start < y_end) && "start position must be smaller than end position"); esp_lcd_panel_io_handle_t io = ssd1306->io; + // adding extra gap x_start += ssd1306->x_gap; x_end += ssd1306->x_gap; y_start += ssd1306->y_gap; y_end += ssd1306->y_gap; + + if (ssd1306->swap_axes) { + int x = x_start; + x_start = y_start; + y_start = x; + x = x_end; + x_end = y_end; + y_end = x; + } + // one page contains 8 rows (COMs) uint8_t page_start = y_start / 8; uint8_t page_end = (y_end - 1) / 8; @@ -204,7 +218,7 @@ static esp_err_t panel_ssd1306_mirror(esp_lcd_panel_t *panel, bool mirror_x, boo if (mirror_y) { command = SSD1306_CMD_MIRROR_Y_ON; } else { - command = SSD1306_CMD_MIRROR_X_OFF; + command = SSD1306_CMD_MIRROR_Y_OFF; } esp_lcd_panel_io_tx_param(io, command, NULL, 0); return ESP_OK; @@ -212,7 +226,10 @@ static esp_err_t panel_ssd1306_mirror(esp_lcd_panel_t *panel, bool mirror_x, boo static esp_err_t panel_ssd1306_swap_xy(esp_lcd_panel_t *panel, bool swap_axes) { - return ESP_ERR_NOT_SUPPORTED; + ssd1306_panel_t *ssd1306 = __containerof(panel, ssd1306_panel_t, base); + ssd1306->swap_axes = swap_axes; + + return ESP_OK; } static esp_err_t panel_ssd1306_set_gap(esp_lcd_panel_t *panel, int x_gap, int y_gap)