Skip to content

Commit 070458a

Browse files
authored
Remove sw_rotate (#210)
* Remove sw_rotate * Removed unused code * LVGL version to 9.2.2 * Enable all devices * Updated markdown
1 parent 48487b1 commit 070458a

11 files changed

+52
-63
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -595,6 +595,8 @@ The following libraries are used from the [Espressif component registry](https:/
595595

596596
## Version history
597597

598+
- October 2024
599+
- Fix for LVGL 9.2.2 that removed the sw_rotate flag
598600
- August 2024
599601
- LVGL 9.2
600602
- New boards

library.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,6 @@
3535
"frameworks": "arduino",
3636
"platforms": "espressif32",
3737
"dependencies": {
38-
"lvgl/lvgl": "9.2.0"
38+
"lvgl/lvgl": "^9.2.2"
3939
}
4040
}

platformio.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ build_flags =
5959
'-D ESP_LCD_PANEL_IO_ADDITIONS_VER_PATCH=1'
6060

6161
lib_deps =
62-
62+
lvgl/lvgl@^9.2.2
6363
# The platformio.test_dir contains the test_main.cpp just to have an setup() and loop() function
6464
# so it will compile
6565
${platformio.test_dir}

src/esp32_smartdisplay.c

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -193,9 +193,6 @@ void smartdisplay_init()
193193
#endif
194194
// Setup TFT display
195195
display = lvgl_lcd_init();
196-
// Register callback for hardware rotation
197-
if (!display->sw_rotate)
198-
lv_display_add_event_cb(display, lvgl_display_resolution_changed_callback, LV_EVENT_RESOLUTION_CHANGED, NULL);
199196

200197
// Clear screen
201198
lv_obj_clean(lv_scr_act());
@@ -213,31 +210,3 @@ void smartdisplay_init()
213210
lv_indev_enable(indev, true);
214211
#endif
215212
}
216-
217-
// Called when driver resolution is updated (including rotation)
218-
// Top of the display is top left when connector is at the bottom
219-
// The rotation values are relative to how you would rotate the physical display in the clockwise direction.
220-
// Thus, LV_DISPLAY_ROTATION_90 means you rotate the hardware 90 degrees clockwise, and the display rotates 90 degrees counterclockwise to compensate.
221-
void lvgl_display_resolution_changed_callback(lv_event_t *event)
222-
{
223-
const esp_lcd_panel_handle_t panel_handle = display->user_data;
224-
switch (display->rotation)
225-
{
226-
case LV_DISPLAY_ROTATION_0:
227-
ESP_ERROR_CHECK(esp_lcd_panel_swap_xy(panel_handle, DISPLAY_SWAP_XY));
228-
ESP_ERROR_CHECK(esp_lcd_panel_mirror(panel_handle, DISPLAY_MIRROR_X, DISPLAY_MIRROR_Y));
229-
break;
230-
case LV_DISPLAY_ROTATION_90:
231-
ESP_ERROR_CHECK(esp_lcd_panel_swap_xy(panel_handle, !DISPLAY_SWAP_XY));
232-
ESP_ERROR_CHECK(esp_lcd_panel_mirror(panel_handle, DISPLAY_MIRROR_X, !DISPLAY_MIRROR_Y));
233-
break;
234-
case LV_DISPLAY_ROTATION_180:
235-
ESP_ERROR_CHECK(esp_lcd_panel_swap_xy(panel_handle, DISPLAY_SWAP_XY));
236-
ESP_ERROR_CHECK(esp_lcd_panel_mirror(panel_handle, !DISPLAY_MIRROR_X, !DISPLAY_MIRROR_Y));
237-
break;
238-
case LV_DISPLAY_ROTATION_270:
239-
ESP_ERROR_CHECK(esp_lcd_panel_swap_xy(panel_handle, !DISPLAY_SWAP_XY));
240-
ESP_ERROR_CHECK(esp_lcd_panel_mirror(panel_handle, !DISPLAY_MIRROR_X, DISPLAY_MIRROR_Y));
241-
break;
242-
}
243-
}

src/lvgl_panel_gc9a01_spi.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ bool gc9a01_color_trans_done(esp_lcd_panel_io_handle_t panel_io_handle, esp_lcd_
1717

1818
void gc9a01_lv_flush(lv_display_t *display, const lv_area_t *area, uint8_t *px_map)
1919
{
20+
// Hardware rotation is supported
2021
log_v("display:0x%08x, area:%0x%08x, color_map:0x%08x", display, area, px_map);
2122

2223
esp_lcd_panel_handle_t panel_handle = display->user_data;
@@ -40,10 +41,6 @@ lv_display_t *lvgl_lcd_init()
4041
void *drawBuffer = heap_caps_malloc(drawBufferSize, LVGL_BUFFER_MALLOC_FLAGS);
4142
lv_display_set_buffers(display, drawBuffer, NULL, drawBufferSize, LV_DISPLAY_RENDER_MODE_PARTIAL);
4243

43-
// Hardware rotation is supported
44-
display->sw_rotate = 0;
45-
display->rotation = LV_DISPLAY_ROTATION_0;
46-
4744
// Create SPI bus
4845
const spi_bus_config_t spi_bus_config = {
4946
.mosi_io_num = GC9A01_SPI_BUS_MOSI_IO_NUM,

src/lvgl_panel_ili9341_spi.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ bool ili9341_color_trans_done(esp_lcd_panel_io_handle_t panel_io, esp_lcd_panel_
1515

1616
void ili9341_lv_flush(lv_display_t *display, const lv_area_t *area, uint8_t *px_map)
1717
{
18+
// Hardware rotation is supported
1819
esp_lcd_panel_handle_t panel_handle = display->user_data;
1920
uint32_t pixels = lv_area_get_size(area);
2021
uint16_t *p = (uint16_t *)px_map;
@@ -36,10 +37,6 @@ lv_display_t *lvgl_lcd_init()
3637
void *drawBuffer = heap_caps_malloc(drawBufferSize, LVGL_BUFFER_MALLOC_FLAGS);
3738
lv_display_set_buffers(display, drawBuffer, NULL, drawBufferSize, LV_DISPLAY_RENDER_MODE_PARTIAL);
3839

39-
// Hardware rotation is supported
40-
display->sw_rotate = 0;
41-
display->rotation = LV_DISPLAY_ROTATION_0;
42-
4340
// Create SPI bus
4441
const spi_bus_config_t spi_bus_config = {
4542
.mosi_io_num = ILI9341_SPI_BUS_MOSI_IO_NUM,

src/lvgl_panel_st7262_par.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ bool direct_io_frame_trans_done(esp_lcd_panel_handle_t panel, esp_lcd_rgb_panel_
1313

1414
void direct_io_lv_flush(lv_display_t *display, const lv_area_t *area, uint8_t *px_map)
1515
{
16+
// Hardware rotation is not supported
1617
const esp_lcd_panel_handle_t panel_handle = display->user_data;
1718

1819
lv_display_rotation_t rotation = lv_display_get_rotation(display);
@@ -68,10 +69,6 @@ lv_display_t *lvgl_lcd_init()
6869
void *drawBuffer = heap_caps_malloc(drawBufferSize, LVGL_BUFFER_MALLOC_FLAGS);
6970
lv_display_set_buffers(display, drawBuffer, NULL, drawBufferSize, LV_DISPLAY_RENDER_MODE_PARTIAL);
7071

71-
// Hardware rotation is not supported
72-
display->sw_rotate = 1;
73-
display->rotation = LV_DISPLAY_ROTATION_0;
74-
7572
// Create direct_io panel handle
7673
const esp_lcd_rgb_panel_config_t rgb_panel_config = {
7774
.clk_src = ST7262_PANEL_CONFIG_CLK_SRC,

src/lvgl_panel_st7701_par.c

Lines changed: 42 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,49 @@ bool direct_io_frame_trans_done(esp_lcd_panel_handle_t panel, esp_lcd_rgb_panel_
1515

1616
void direct_io_lv_flush(lv_display_t *display, const lv_area_t *area, uint8_t *px_map)
1717
{
18+
// Hardware rotation is not supported
1819
const esp_lcd_panel_handle_t panel_handle = display->user_data;
19-
// LV_COLOR_16_SWAP is handled by mapping of the data
20-
ESP_ERROR_CHECK(esp_lcd_panel_draw_bitmap(panel_handle, area->x1, area->y1, area->x2 + 1, area->y2 + 1, px_map));
20+
21+
lv_display_rotation_t rotation = lv_display_get_rotation(display);
22+
if (rotation == LV_DISPLAY_ROTATION_0)
23+
{
24+
ESP_ERROR_CHECK(esp_lcd_panel_draw_bitmap(panel_handle, area->x1, area->y1, area->x2 + 1, area->y2 + 1, px_map));
25+
return;
26+
}
27+
28+
// Rotated
29+
int32_t w = lv_area_get_width(area);
30+
int32_t h = lv_area_get_height(area);
31+
lv_color_format_t cf = lv_display_get_color_format(display);
32+
uint32_t px_size = lv_color_format_get_size(cf);
33+
size_t buf_size = w * h * px_size;
34+
log_v("alloc rotation buffer to: %u bytes", buf_size);
35+
void *rotation_buffer = heap_caps_malloc(buf_size, LVGL_BUFFER_MALLOC_FLAGS);
36+
assert(rotation_buffer != NULL);
37+
38+
uint32_t w_stride = lv_draw_buf_width_to_stride(w, cf);
39+
uint32_t h_stride = lv_draw_buf_width_to_stride(h, cf);
40+
41+
switch (rotation)
42+
{
43+
case LV_DISPLAY_ROTATION_90:
44+
lv_draw_sw_rotate(px_map, rotation_buffer, w, h, w_stride, h_stride, rotation, cf);
45+
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));
46+
break;
47+
case LV_DISPLAY_ROTATION_180:
48+
lv_draw_sw_rotate(px_map, rotation_buffer, w, h, w_stride, w_stride, rotation, cf);
49+
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));
50+
break;
51+
case LV_DISPLAY_ROTATION_270:
52+
lv_draw_sw_rotate(px_map, rotation_buffer, w, h, w_stride, h_stride, rotation, cf);
53+
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));
54+
break;
55+
default:
56+
assert(false);
57+
break;
58+
}
59+
60+
free(rotation_buffer);
2161
};
2262

2363
lv_display_t *lvgl_lcd_init()
@@ -29,10 +69,6 @@ lv_display_t *lvgl_lcd_init()
2969
void *drawBuffer = heap_caps_malloc(drawBufferSize, LVGL_BUFFER_MALLOC_FLAGS);
3070
lv_display_set_buffers(display, drawBuffer, NULL, drawBufferSize, LV_DISPLAY_RENDER_MODE_PARTIAL);
3171

32-
// Hardware rotation is not supported
33-
display->sw_rotate = 1;
34-
display->rotation = LV_DISPLAY_ROTATION_0;
35-
3672
// Install 3-wire SPI panel IO
3773
esp_lcd_panel_io_3wire_spi_config_t io_3wire_spi_config = {
3874
.line_config = {

src/lvgl_panel_st7789_i80.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ bool st7789_color_trans_done(esp_lcd_panel_io_handle_t panel_io, esp_lcd_panel_i
1414

1515
void st7789_lv_flush(lv_display_t *drv, const lv_area_t *area, uint8_t *px_map)
1616
{
17+
// Hardware rotation is supported
1718
const esp_lcd_panel_handle_t panel_handle = drv->user_data;
1819
uint32_t pixels = lv_area_get_size(area);
1920
uint16_t *p = (uint16_t *)px_map;
@@ -35,10 +36,6 @@ lv_display_t *lvgl_lcd_init(uint32_t hor_res, uint32_t ver_res)
3536
void *drawBuffer = heap_caps_malloc(drawBufferSize, LVGL_BUFFER_MALLOC_FLAGS);
3637
lv_display_set_buffers(display, drawBuffer, NULL, drawBufferSize, LV_DISPLAY_RENDER_MODE_PARTIAL);
3738

38-
// Hardware rotation is supported
39-
display->sw_rotate = 0;
40-
display->rotation = LV_DISPLAY_ROTATION_0;
41-
4239
pinMode(ST7789_RD_GPIO, OUTPUT);
4340
digitalWrite(ST7789_RD_GPIO, HIGH);
4441

src/lvgl_panel_st7789_spi.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ bool st7789_color_trans_done(esp_lcd_panel_io_handle_t panel_io, esp_lcd_panel_i
1515

1616
void st7789_lv_flush(lv_display_t *display, const lv_area_t *area, uint8_t *px_map)
1717
{
18+
// Hardware rotation is supported
1819
esp_lcd_panel_handle_t panel_handle = display->user_data;
1920
uint32_t pixels = lv_area_get_size(area);
2021
uint16_t *p = (uint16_t *)px_map;
@@ -36,10 +37,6 @@ lv_display_t *lvgl_lcd_init(uint32_t hor_res, uint32_t ver_res)
3637
void *drawBuffer = heap_caps_malloc(drawBufferSize, LVGL_BUFFER_MALLOC_FLAGS);
3738
lv_display_set_buffers(display, drawBuffer, NULL, drawBufferSize, LV_DISPLAY_RENDER_MODE_PARTIAL);
3839

39-
// Hardware rotation is supported
40-
display->sw_rotate = 0;
41-
display->rotation = LV_DISPLAY_ROTATION_0;
42-
4340
// Create SPI bus
4441
const spi_bus_config_t spi_bus_config = {
4542
.mosi_io_num = ST7789_SPI_BUS_MOSI_IO_NUM,

src/lvgl_panel_st7796_spi.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ bool st7796_color_trans_done(esp_lcd_panel_io_handle_t panel_io, esp_lcd_panel_i
1616

1717
void st7796_lv_flush(lv_display_t *display, const lv_area_t *area, uint8_t *px_map)
1818
{
19+
// Hardware rotation is supported
1920
esp_lcd_panel_handle_t panel_handle = display->user_data;
2021
uint32_t pixels = lv_area_get_size(area);
2122
uint16_t *p = (uint16_t *)px_map;
@@ -37,10 +38,6 @@ lv_display_t *lvgl_lcd_init(uint32_t hor_res, uint32_t ver_res)
3738
void *drawBuffer = heap_caps_malloc(drawBufferSize, LVGL_BUFFER_MALLOC_FLAGS);
3839
lv_display_set_buffers(display, drawBuffer, NULL, drawBufferSize, LV_DISPLAY_RENDER_MODE_PARTIAL);
3940

40-
// Hardware rotation is supported
41-
display->sw_rotate = 0;
42-
display->rotation = LV_DISPLAY_ROTATION_0;
43-
4441
// Create SPI bus
4542
const spi_bus_config_t spi_bus_config = {
4643
.mosi_io_num = ST7796_SPI_BUS_MOSI_IO_NUM,

0 commit comments

Comments
 (0)