diff --git a/components/esp_lcd/src/esp_lcd_panel_ssd1306.c b/components/esp_lcd/src/esp_lcd_panel_ssd1306.c index 323c1faac9..06d14a1131 100644 --- a/components/esp_lcd/src/esp_lcd_panel_ssd1306.c +++ b/components/esp_lcd/src/esp_lcd_panel_ssd1306.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2021 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -52,6 +52,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) @@ -137,6 +138,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); esp_lcd_panel_io_tx_param(io, SSD1306_CMD_DISP_ON, NULL, 0); // SEG/COM will be ON after 100ms after sending DISP_ON command vTaskDelay(pdMS_TO_TICKS(100)); @@ -148,11 +151,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; @@ -201,7 +215,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; @@ -209,7 +223,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)