feat(nt35510): Implement sleep function

This commit is contained in:
morris
2023-10-09 14:19:31 +08:00
parent cbf2414226
commit b2972528c7

View File

@@ -37,6 +37,7 @@ static esp_err_t panel_nt35510_mirror(esp_lcd_panel_t *panel, bool mirror_x, boo
static esp_err_t panel_nt35510_swap_xy(esp_lcd_panel_t *panel, bool swap_axes); static esp_err_t panel_nt35510_swap_xy(esp_lcd_panel_t *panel, bool swap_axes);
static esp_err_t panel_nt35510_set_gap(esp_lcd_panel_t *panel, int x_gap, int y_gap); static esp_err_t panel_nt35510_set_gap(esp_lcd_panel_t *panel, int x_gap, int y_gap);
static esp_err_t panel_nt35510_disp_on_off(esp_lcd_panel_t *panel, bool off); static esp_err_t panel_nt35510_disp_on_off(esp_lcd_panel_t *panel, bool off);
static esp_err_t panel_nt35510_sleep(esp_lcd_panel_t *panel, bool sleep);
typedef struct { typedef struct {
esp_lcd_panel_t base; esp_lcd_panel_t base;
@@ -116,6 +117,7 @@ esp_lcd_new_panel_nt35510(const esp_lcd_panel_io_handle_t io, const esp_lcd_pane
nt35510->base.mirror = panel_nt35510_mirror; nt35510->base.mirror = panel_nt35510_mirror;
nt35510->base.swap_xy = panel_nt35510_swap_xy; nt35510->base.swap_xy = panel_nt35510_swap_xy;
nt35510->base.disp_on_off = panel_nt35510_disp_on_off; nt35510->base.disp_on_off = panel_nt35510_disp_on_off;
nt35510->base.disp_sleep = panel_nt35510_sleep;
*ret_panel = &(nt35510->base); *ret_panel = &(nt35510->base);
ESP_LOGD(TAG, "new nt35510 panel @%p", nt35510); ESP_LOGD(TAG, "new nt35510 panel @%p", nt35510);
@@ -157,7 +159,7 @@ static esp_err_t panel_nt35510_reset(esp_lcd_panel_t *panel)
} else { } else {
// perform software reset // perform software reset
ESP_RETURN_ON_ERROR(esp_lcd_panel_io_tx_param(io, LCD_CMD_SWRESET << 8, NULL, 0), TAG, ESP_RETURN_ON_ERROR(esp_lcd_panel_io_tx_param(io, LCD_CMD_SWRESET << 8, NULL, 0), TAG,
"io tx param LCD_CMD_SWRESET failed"); "io tx param failed");
vTaskDelay(pdMS_TO_TICKS(20)); // spec, wait at least 5m before sending new command vTaskDelay(pdMS_TO_TICKS(20)); // spec, wait at least 5m before sending new command
} }
@@ -170,14 +172,14 @@ static esp_err_t panel_nt35510_init(esp_lcd_panel_t *panel)
esp_lcd_panel_io_handle_t io = nt35510->io; esp_lcd_panel_io_handle_t io = nt35510->io;
// LCD goes into sleep mode and display will be turned off after power on reset, exit sleep mode first // LCD goes into sleep mode and display will be turned off after power on reset, exit sleep mode first
ESP_RETURN_ON_ERROR(esp_lcd_panel_io_tx_param(io, LCD_CMD_SLPOUT << 8, NULL, 0), TAG, ESP_RETURN_ON_ERROR(esp_lcd_panel_io_tx_param(io, LCD_CMD_SLPOUT << 8, NULL, 0), TAG,
"io tx param LCD_CMD_SLPOUT failed");; "io tx param failed");;
vTaskDelay(pdMS_TO_TICKS(100)); vTaskDelay(pdMS_TO_TICKS(100));
ESP_RETURN_ON_ERROR(esp_lcd_panel_io_tx_param(io, LCD_CMD_MADCTL << 8, (uint16_t[]) { ESP_RETURN_ON_ERROR(esp_lcd_panel_io_tx_param(io, LCD_CMD_MADCTL << 8, (uint16_t[]) {
nt35510->madctl_val, nt35510->madctl_val,
}, 2), TAG, "io tx param LCD_CMD_MADCTL failed"); }, 2), TAG, "io tx param failed");
ESP_RETURN_ON_ERROR(esp_lcd_panel_io_tx_param(io, LCD_CMD_COLMOD << 8, (uint16_t[]) { ESP_RETURN_ON_ERROR(esp_lcd_panel_io_tx_param(io, LCD_CMD_COLMOD << 8, (uint16_t[]) {
nt35510->colmod_val, nt35510->colmod_val,
}, 2), TAG, "io tx param LCD_CMD_COLMOD failed"); }, 2), TAG, "io tx param failed");
return ESP_OK; return ESP_OK;
} }
@@ -197,28 +199,28 @@ static esp_err_t panel_nt35510_draw_bitmap(esp_lcd_panel_t *panel, int x_start,
// define an area of frame memory where MCU can access // define an area of frame memory where MCU can access
ESP_RETURN_ON_ERROR(esp_lcd_panel_io_tx_param(io, (LCD_CMD_CASET << 8) + 0, (uint16_t[]) { ESP_RETURN_ON_ERROR(esp_lcd_panel_io_tx_param(io, (LCD_CMD_CASET << 8) + 0, (uint16_t[]) {
(x_start >> 8) & 0xFF, (x_start >> 8) & 0xFF,
}, 2), TAG, "io tx param LCD_CMD_CASET failed"); }, 2), TAG, "io tx param failed");
ESP_RETURN_ON_ERROR(esp_lcd_panel_io_tx_param(io, (LCD_CMD_CASET << 8) + 1, (uint16_t[]) { ESP_RETURN_ON_ERROR(esp_lcd_panel_io_tx_param(io, (LCD_CMD_CASET << 8) + 1, (uint16_t[]) {
x_start & 0xFF, x_start & 0xFF,
}, 2), TAG, "io tx param LCD_CMD_CASET failed"); }, 2), TAG, "io tx param failed");
ESP_RETURN_ON_ERROR(esp_lcd_panel_io_tx_param(io, (LCD_CMD_CASET << 8) + 2, (uint16_t[]) { ESP_RETURN_ON_ERROR(esp_lcd_panel_io_tx_param(io, (LCD_CMD_CASET << 8) + 2, (uint16_t[]) {
((x_end - 1) >> 8) & 0xFF, ((x_end - 1) >> 8) & 0xFF,
}, 2), TAG, "io tx param LCD_CMD_CASET failed"); }, 2), TAG, "io tx param failed");
ESP_RETURN_ON_ERROR(esp_lcd_panel_io_tx_param(io, (LCD_CMD_CASET << 8) + 3, (uint16_t[]) { ESP_RETURN_ON_ERROR(esp_lcd_panel_io_tx_param(io, (LCD_CMD_CASET << 8) + 3, (uint16_t[]) {
(x_end - 1) & 0xFF, (x_end - 1) & 0xFF,
}, 2), TAG, "io tx param LCD_CMD_CASET failed"); }, 2), TAG, "io tx param failed");
ESP_RETURN_ON_ERROR(esp_lcd_panel_io_tx_param(io, (LCD_CMD_RASET << 8) + 0, (uint16_t[]) { ESP_RETURN_ON_ERROR(esp_lcd_panel_io_tx_param(io, (LCD_CMD_RASET << 8) + 0, (uint16_t[]) {
(y_start >> 8) & 0xFF, (y_start >> 8) & 0xFF,
}, 2), TAG, "io tx param LCD_CMD_RASET failed"); }, 2), TAG, "io tx param failed");
ESP_RETURN_ON_ERROR(esp_lcd_panel_io_tx_param(io, (LCD_CMD_RASET << 8) + 1, (uint16_t[]) { ESP_RETURN_ON_ERROR(esp_lcd_panel_io_tx_param(io, (LCD_CMD_RASET << 8) + 1, (uint16_t[]) {
y_start & 0xFF, y_start & 0xFF,
}, 2), TAG, "io tx param LCD_CMD_RASET failed"); }, 2), TAG, "io tx param failed");
ESP_RETURN_ON_ERROR(esp_lcd_panel_io_tx_param(io, (LCD_CMD_RASET << 8) + 2, (uint16_t[]) { ESP_RETURN_ON_ERROR(esp_lcd_panel_io_tx_param(io, (LCD_CMD_RASET << 8) + 2, (uint16_t[]) {
((y_end - 1) >> 8) & 0xFF, ((y_end - 1) >> 8) & 0xFF,
}, 2), TAG, "io tx param LCD_CMD_RASET failed"); }, 2), TAG, "io tx param failed");
ESP_RETURN_ON_ERROR(esp_lcd_panel_io_tx_param(io, (LCD_CMD_RASET << 8) + 3, (uint16_t[]) { ESP_RETURN_ON_ERROR(esp_lcd_panel_io_tx_param(io, (LCD_CMD_RASET << 8) + 3, (uint16_t[]) {
(y_end - 1) & 0xFF, (y_end - 1) & 0xFF,
}, 2), TAG, "io tx param LCD_CMD_RASET failed"); }, 2), TAG, "io tx param failed");
// transfer frame buffer // transfer frame buffer
size_t len = (x_end - x_start) * (y_end - y_start) * nt35510->fb_bits_per_pixel / 8; size_t len = (x_end - x_start) * (y_end - y_start) * nt35510->fb_bits_per_pixel / 8;
ESP_RETURN_ON_ERROR(esp_lcd_panel_io_tx_color(io, LCD_CMD_RAMWR << 8, color_data, len), TAG, "io tx color failed"); ESP_RETURN_ON_ERROR(esp_lcd_panel_io_tx_color(io, LCD_CMD_RAMWR << 8, color_data, len), TAG, "io tx color failed");
@@ -237,7 +239,7 @@ static esp_err_t panel_nt35510_invert_color(esp_lcd_panel_t *panel, bool invert_
command = LCD_CMD_INVOFF; command = LCD_CMD_INVOFF;
} }
ESP_RETURN_ON_ERROR(esp_lcd_panel_io_tx_param(io, command << 8, NULL, 0), TAG, ESP_RETURN_ON_ERROR(esp_lcd_panel_io_tx_param(io, command << 8, NULL, 0), TAG,
"io tx param LCD_CMD_INVON/LCD_CMD_INVOFF failed"); "io tx param failed");
return ESP_OK; return ESP_OK;
} }
@@ -257,7 +259,7 @@ static esp_err_t panel_nt35510_mirror(esp_lcd_panel_t *panel, bool mirror_x, boo
} }
ESP_RETURN_ON_ERROR(esp_lcd_panel_io_tx_param(io, LCD_CMD_MADCTL << 8, (uint16_t[]) { ESP_RETURN_ON_ERROR(esp_lcd_panel_io_tx_param(io, LCD_CMD_MADCTL << 8, (uint16_t[]) {
nt35510->madctl_val nt35510->madctl_val
}, 2), TAG, "io tx param LCD_CMD_MADCTL failed"); }, 2), TAG, "io tx param failed");
return ESP_OK; return ESP_OK;
} }
@@ -272,7 +274,7 @@ static esp_err_t panel_nt35510_swap_xy(esp_lcd_panel_t *panel, bool swap_axes)
} }
ESP_RETURN_ON_ERROR(esp_lcd_panel_io_tx_param(io, LCD_CMD_MADCTL << 8, (uint16_t[]) { ESP_RETURN_ON_ERROR(esp_lcd_panel_io_tx_param(io, LCD_CMD_MADCTL << 8, (uint16_t[]) {
nt35510->madctl_val nt35510->madctl_val
}, 2), TAG, "io tx param LCD_CMD_MADCTL failed"); }, 2), TAG, "io tx param failed");
return ESP_OK; return ESP_OK;
} }
@@ -295,6 +297,23 @@ static esp_err_t panel_nt35510_disp_on_off(esp_lcd_panel_t *panel, bool on_off)
command = LCD_CMD_DISPOFF; command = LCD_CMD_DISPOFF;
} }
ESP_RETURN_ON_ERROR(esp_lcd_panel_io_tx_param(io, command << 8, NULL, 0), TAG, ESP_RETURN_ON_ERROR(esp_lcd_panel_io_tx_param(io, command << 8, NULL, 0), TAG,
"io tx param LCD_CMD_DISPON/LCD_CMD_DISPOFF failed"); "io tx param failed");
return ESP_OK;
}
static esp_err_t panel_nt35510_sleep(esp_lcd_panel_t *panel, bool sleep)
{
nt35510_panel_t *nt35510 = __containerof(panel, nt35510_panel_t, base);
esp_lcd_panel_io_handle_t io = nt35510->io;
int command = 0;
if (sleep) {
command = LCD_CMD_SLPIN;
} else {
command = LCD_CMD_SLPOUT;
}
ESP_RETURN_ON_ERROR(esp_lcd_panel_io_tx_param(io, command, NULL, 0), TAG,
"io tx param failed");
vTaskDelay(pdMS_TO_TICKS(100));
return ESP_OK; return ESP_OK;
} }