Skip to content

Commit

Permalink
lcd: Support rotation SSD1306 and fix mirror y.
Browse files Browse the repository at this point in the history
  • Loading branch information
espzav committed Dec 6, 2022
1 parent 795a70f commit 5f6eac2
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions components/esp_lcd/src/esp_lcd_panel_ssd1306.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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;
}

Expand All @@ -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;
Expand Down Expand Up @@ -204,15 +218,18 @@ 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;
}

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)
Expand Down

0 comments on commit 5f6eac2

Please sign in to comment.