lcd: Support rotation SSD1306 and fix mirror y.

This commit is contained in:
Vilem Zavodny 2022-12-06 15:24:19 +01:00
parent 795a70f8b3
commit 5f6eac2283

View File

@ -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)