Skip to content

Commit

Permalink
Remove sw_rotate
Browse files Browse the repository at this point in the history
  • Loading branch information
rzeldent committed Oct 30, 2024
1 parent 596e2ea commit f97f567
Show file tree
Hide file tree
Showing 10 changed files with 75 additions and 36 deletions.
2 changes: 1 addition & 1 deletion library.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,6 @@
"frameworks": "arduino",
"platforms": "espressif32",
"dependencies": {
"lvgl/lvgl": "9.2.0"
"lvgl/lvgl": "^9.2.1"
}
}
2 changes: 1 addition & 1 deletion platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ build_flags =
'-D ESP_LCD_PANEL_IO_ADDITIONS_VER_PATCH=1'

lib_deps =
lvgl/[email protected].0
lvgl/lvgl@^9.2.1
# The platformio.test_dir contains the test_main.cpp just to have an setup() and loop() function
# so it will compile
${platformio.test_dir}
Expand Down
50 changes: 25 additions & 25 deletions src/esp32_smartdisplay.c
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,8 @@ void smartdisplay_init()
// Setup TFT display
display = lvgl_lcd_init();
// Register callback for hardware rotation
if (!display->sw_rotate)
lv_display_add_event_cb(display, lvgl_display_resolution_changed_callback, LV_EVENT_RESOLUTION_CHANGED, NULL);
// if (!display->sw_rotate)
// lv_display_add_event_cb(display, lvgl_display_resolution_changed_callback, LV_EVENT_RESOLUTION_CHANGED, NULL);

// Clear screen
lv_obj_clean(lv_scr_act());
Expand All @@ -218,26 +218,26 @@ void smartdisplay_init()
// Top of the display is top left when connector is at the bottom
// The rotation values are relative to how you would rotate the physical display in the clockwise direction.
// Thus, LV_DISPLAY_ROTATION_90 means you rotate the hardware 90 degrees clockwise, and the display rotates 90 degrees counterclockwise to compensate.
void lvgl_display_resolution_changed_callback(lv_event_t *event)
{
const esp_lcd_panel_handle_t panel_handle = display->user_data;
switch (display->rotation)
{
case LV_DISPLAY_ROTATION_0:
ESP_ERROR_CHECK(esp_lcd_panel_swap_xy(panel_handle, DISPLAY_SWAP_XY));
ESP_ERROR_CHECK(esp_lcd_panel_mirror(panel_handle, DISPLAY_MIRROR_X, DISPLAY_MIRROR_Y));
break;
case LV_DISPLAY_ROTATION_90:
ESP_ERROR_CHECK(esp_lcd_panel_swap_xy(panel_handle, !DISPLAY_SWAP_XY));
ESP_ERROR_CHECK(esp_lcd_panel_mirror(panel_handle, DISPLAY_MIRROR_X, !DISPLAY_MIRROR_Y));
break;
case LV_DISPLAY_ROTATION_180:
ESP_ERROR_CHECK(esp_lcd_panel_swap_xy(panel_handle, DISPLAY_SWAP_XY));
ESP_ERROR_CHECK(esp_lcd_panel_mirror(panel_handle, !DISPLAY_MIRROR_X, !DISPLAY_MIRROR_Y));
break;
case LV_DISPLAY_ROTATION_270:
ESP_ERROR_CHECK(esp_lcd_panel_swap_xy(panel_handle, !DISPLAY_SWAP_XY));
ESP_ERROR_CHECK(esp_lcd_panel_mirror(panel_handle, !DISPLAY_MIRROR_X, DISPLAY_MIRROR_Y));
break;
}
}
// void lvgl_display_resolution_changed_callback(lv_event_t *event)
// {
// const esp_lcd_panel_handle_t panel_handle = display->user_data;
// switch (display->rotation)
// {
// case LV_DISPLAY_ROTATION_0:
// ESP_ERROR_CHECK(esp_lcd_panel_swap_xy(panel_handle, DISPLAY_SWAP_XY));
// ESP_ERROR_CHECK(esp_lcd_panel_mirror(panel_handle, DISPLAY_MIRROR_X, DISPLAY_MIRROR_Y));
// break;
// case LV_DISPLAY_ROTATION_90:
// ESP_ERROR_CHECK(esp_lcd_panel_swap_xy(panel_handle, !DISPLAY_SWAP_XY));
// ESP_ERROR_CHECK(esp_lcd_panel_mirror(panel_handle, DISPLAY_MIRROR_X, !DISPLAY_MIRROR_Y));
// break;
// case LV_DISPLAY_ROTATION_180:
// ESP_ERROR_CHECK(esp_lcd_panel_swap_xy(panel_handle, DISPLAY_SWAP_XY));
// ESP_ERROR_CHECK(esp_lcd_panel_mirror(panel_handle, !DISPLAY_MIRROR_X, !DISPLAY_MIRROR_Y));
// break;
// case LV_DISPLAY_ROTATION_270:
// ESP_ERROR_CHECK(esp_lcd_panel_swap_xy(panel_handle, !DISPLAY_SWAP_XY));
// ESP_ERROR_CHECK(esp_lcd_panel_mirror(panel_handle, !DISPLAY_MIRROR_X, DISPLAY_MIRROR_Y));
// break;
// }
// }
2 changes: 1 addition & 1 deletion src/lvgl_panel_gc9a01_spi.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ lv_display_t *lvgl_lcd_init()
lv_display_set_buffers(display, drawBuffer, NULL, drawBufferSize, LV_DISPLAY_RENDER_MODE_PARTIAL);

// Hardware rotation is supported
display->sw_rotate = 0;
// display->sw_rotate = 0;
display->rotation = LV_DISPLAY_ROTATION_0;

// Create SPI bus
Expand Down
2 changes: 1 addition & 1 deletion src/lvgl_panel_ili9341_spi.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ lv_display_t *lvgl_lcd_init()
lv_display_set_buffers(display, drawBuffer, NULL, drawBufferSize, LV_DISPLAY_RENDER_MODE_PARTIAL);

// Hardware rotation is supported
display->sw_rotate = 0;
// display->sw_rotate = 0;
display->rotation = LV_DISPLAY_ROTATION_0;

// Create SPI bus
Expand Down
2 changes: 1 addition & 1 deletion src/lvgl_panel_st7262_par.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ lv_display_t *lvgl_lcd_init()
lv_display_set_buffers(display, drawBuffer, NULL, drawBufferSize, LV_DISPLAY_RENDER_MODE_PARTIAL);

// Hardware rotation is not supported
display->sw_rotate = 1;
//display->sw_rotate = 1;
display->rotation = LV_DISPLAY_ROTATION_0;

// Create direct_io panel handle
Expand Down
45 changes: 42 additions & 3 deletions src/lvgl_panel_st7701_par.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,47 @@ bool direct_io_frame_trans_done(esp_lcd_panel_handle_t panel, esp_lcd_rgb_panel_
void direct_io_lv_flush(lv_display_t *display, const lv_area_t *area, uint8_t *px_map)
{
const esp_lcd_panel_handle_t panel_handle = display->user_data;
// LV_COLOR_16_SWAP is handled by mapping of the data
ESP_ERROR_CHECK(esp_lcd_panel_draw_bitmap(panel_handle, area->x1, area->y1, area->x2 + 1, area->y2 + 1, px_map));

lv_display_rotation_t rotation = lv_display_get_rotation(display);
if (rotation == LV_DISPLAY_ROTATION_0)
{
ESP_ERROR_CHECK(esp_lcd_panel_draw_bitmap(panel_handle, area->x1, area->y1, area->x2 + 1, area->y2 + 1, px_map));
return;
}

// Rotated
int32_t w = lv_area_get_width(area);
int32_t h = lv_area_get_height(area);
lv_color_format_t cf = lv_display_get_color_format(display);
uint32_t px_size = lv_color_format_get_size(cf);
size_t buf_size = w * h * px_size;
log_v("alloc rotation buffer to: %u bytes", buf_size);
void *rotation_buffer = heap_caps_malloc(buf_size, LVGL_BUFFER_MALLOC_FLAGS);
assert(rotation_buffer != NULL);

uint32_t w_stride = lv_draw_buf_width_to_stride(w, cf);
uint32_t h_stride = lv_draw_buf_width_to_stride(h, cf);

switch (rotation)
{
case LV_DISPLAY_ROTATION_90:
lv_draw_sw_rotate(px_map, rotation_buffer, w, h, w_stride, h_stride, rotation, cf);
ESP_ERROR_CHECK(esp_lcd_panel_draw_bitmap(panel_handle, area->y1, display->ver_res - area->x1 - w, area->y1 + h, display->ver_res - area->x1, rotation_buffer));
break;
case LV_DISPLAY_ROTATION_180:
lv_draw_sw_rotate(px_map, rotation_buffer, w, h, w_stride, w_stride, rotation, cf);
ESP_ERROR_CHECK(esp_lcd_panel_draw_bitmap(panel_handle, display->hor_res - area->x1 - w, display->ver_res - area->y1 - h, display->hor_res - area->x1, display->ver_res - area->y1, rotation_buffer));
break;
case LV_DISPLAY_ROTATION_270:
lv_draw_sw_rotate(px_map, rotation_buffer, w, h, w_stride, h_stride, rotation, cf);
ESP_ERROR_CHECK(esp_lcd_panel_draw_bitmap(panel_handle, display->hor_res - area->y2 - 1, area->x2 - w + 1, display->hor_res - area->y2 - 1 + h, area->x2 + 1, rotation_buffer));
break;
default:
assert(false);
break;
}

free(rotation_buffer);
};

lv_display_t *lvgl_lcd_init()
Expand All @@ -30,7 +69,7 @@ lv_display_t *lvgl_lcd_init()
lv_display_set_buffers(display, drawBuffer, NULL, drawBufferSize, LV_DISPLAY_RENDER_MODE_PARTIAL);

// Hardware rotation is not supported
display->sw_rotate = 1;
//display->sw_rotate = 1;
display->rotation = LV_DISPLAY_ROTATION_0;

// Install 3-wire SPI panel IO
Expand Down
2 changes: 1 addition & 1 deletion src/lvgl_panel_st7789_i80.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ lv_display_t *lvgl_lcd_init(uint32_t hor_res, uint32_t ver_res)
lv_display_set_buffers(display, drawBuffer, NULL, drawBufferSize, LV_DISPLAY_RENDER_MODE_PARTIAL);

// Hardware rotation is supported
display->sw_rotate = 0;
//display->sw_rotate = 0;
display->rotation = LV_DISPLAY_ROTATION_0;

pinMode(ST7789_RD_GPIO, OUTPUT);
Expand Down
2 changes: 1 addition & 1 deletion src/lvgl_panel_st7789_spi.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ lv_display_t *lvgl_lcd_init(uint32_t hor_res, uint32_t ver_res)
lv_display_set_buffers(display, drawBuffer, NULL, drawBufferSize, LV_DISPLAY_RENDER_MODE_PARTIAL);

// Hardware rotation is supported
display->sw_rotate = 0;
//display->sw_rotate = 0;
display->rotation = LV_DISPLAY_ROTATION_0;

// Create SPI bus
Expand Down
2 changes: 1 addition & 1 deletion src/lvgl_panel_st7796_spi.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ lv_display_t *lvgl_lcd_init(uint32_t hor_res, uint32_t ver_res)
lv_display_set_buffers(display, drawBuffer, NULL, drawBufferSize, LV_DISPLAY_RENDER_MODE_PARTIAL);

// Hardware rotation is supported
display->sw_rotate = 0;
//display->sw_rotate = 0;
display->rotation = LV_DISPLAY_ROTATION_0;

// Create SPI bus
Expand Down

0 comments on commit f97f567

Please sign in to comment.