Skip to content

Commit

Permalink
Merge pull request #355 from espressif/feat/lvgl_port_sw_rotation
Browse files Browse the repository at this point in the history
Feat/lvgl port sw rotation
  • Loading branch information
espzav authored Aug 6, 2024
2 parents 5d33575 + 4ffc076 commit 97d9dd9
Show file tree
Hide file tree
Showing 10 changed files with 232 additions and 33 deletions.
6 changes: 3 additions & 3 deletions bsp/esp32_p4_function_ev_board/esp32_p4_function_ev_board.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ static lv_indev_t *disp_indev = NULL;
#endif // (BSP_CONFIG_NO_GRAPHIC_LIB == 0)

sdmmc_card_t *bsp_sdcard = NULL; // Global uSD card handler
static esp_lcd_touch_handle_t tp; // LCD touch handle
static bool i2c_initialized = false;
static TaskHandle_t usb_host_task; // USB Host Library task

Expand Down Expand Up @@ -357,15 +356,14 @@ static lv_display_t *bsp_display_lcd_init(const bsp_display_cfg_t *cfg)
.mirror_x = true,
.mirror_y = true,
},
.color_format = LV_COLOR_FORMAT_RGB565,
.flags = {
.buff_dma = cfg->flags.buff_dma,
.buff_spiram = cfg->flags.buff_spiram,
#if LVGL_VERSION_MAJOR >= 9
.swap_bytes = (BSP_LCD_BIGENDIAN ? true : false),
#endif
#if LVGL_VERSION_MAJOR == 8
.sw_rotate = cfg->flags.sw_rotate, /* Only SW rotation is supported for 90° and 270° */
#endif
}
};

Expand All @@ -374,6 +372,7 @@ static lv_display_t *bsp_display_lcd_init(const bsp_display_cfg_t *cfg)

static lv_indev_t *bsp_display_indev_init(lv_display_t *disp)
{
esp_lcd_touch_handle_t tp;
BSP_ERROR_CHECK_RETURN_NULL(bsp_touch_new(NULL, &tp));
assert(tp);

Expand All @@ -395,6 +394,7 @@ lv_display_t *bsp_display_start(void)
.flags = {
.buff_dma = true,
.buff_spiram = false,
.sw_rotate = true,
}
};
return bsp_display_start_with_config(&cfg);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ esp_err_t bsp_sdcard_unmount(void);

#if (BSP_CONFIG_NO_GRAPHIC_LIB == 0)

#define BSP_LCD_DRAW_BUFF_SIZE (BSP_LCD_H_RES * 100) // Frame buffer size in pixels
#define BSP_LCD_DRAW_BUFF_SIZE (BSP_LCD_H_RES * 50) // Frame buffer size in pixels
#define BSP_LCD_DRAW_BUFF_DOUBLE (0)

/**
Expand Down
7 changes: 7 additions & 0 deletions components/esp_lvgl_port/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Changelog

## 2.3.0
- Fixed LVGL port for using with LVGL9 OS FreeRTOS enabled
- Fixed bad handled touch due to synchronization timer task

### Features
- Added support for SW rotation in LVGL9

## 2.2.2

### Fixes
Expand Down
4 changes: 2 additions & 2 deletions components/esp_lvgl_port/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -265,8 +265,8 @@ Display rotation can be changed at runtime.
lv_disp_set_rotation(disp_handle, LV_DISP_ROT_90);
```

> [!WARNING]
> Software rotation is available only in LVGL 8.
> [!NOTE]
> This feature consume more RAM.
> [!NOTE]
> During the hardware rotating, the component call [`esp_lcd`](https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/peripherals/lcd.html) API. When using software rotation, you cannot use neither `direct_mode` nor `full_refresh` in the driver. See [LVGL documentation](https://docs.lvgl.io/8.3/porting/display.html?highlight=sw_rotate) for more info.
Expand Down
2 changes: 1 addition & 1 deletion components/esp_lvgl_port/idf_component.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version: "2.2.2"
version: "2.3.0"
description: ESP LVGL port
url: https://github.com/espressif/esp-bsp/tree/master/components/esp_lvgl_port
dependencies:
Expand Down
4 changes: 1 addition & 3 deletions components/esp_lvgl_port/include/esp_lvgl_port_disp.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,7 @@ typedef struct {
struct {
unsigned int buff_dma: 1; /*!< Allocated LVGL buffer will be DMA capable */
unsigned int buff_spiram: 1; /*!< Allocated LVGL buffer will be in PSRAM */
#if LVGL_VERSION_MAJOR == 8
unsigned int sw_rotate: 1; /*!< Use software rotation (slower) */
#endif
unsigned int sw_rotate: 1; /*!< Use software rotation (slower) or PPA if available */
#if LVGL_VERSION_MAJOR >= 9
unsigned int swap_bytes: 1; /*!< Swap bytes in RGB656 (16-bit) color format before send to LCD driver */
#endif
Expand Down
19 changes: 16 additions & 3 deletions components/esp_lvgl_port/src/lvgl9/esp_lvgl_port.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ static const char *TAG = "LVGL";
typedef struct lvgl_port_ctx_s {
TaskHandle_t lvgl_task;
SemaphoreHandle_t lvgl_mux;
SemaphoreHandle_t timer_mux;
QueueHandle_t lvgl_queue;
SemaphoreHandle_t task_init_mux;
esp_timer_handle_t tick_timer;
Expand Down Expand Up @@ -61,16 +62,16 @@ esp_err_t lvgl_port_init(const lvgl_port_cfg_t *cfg)

memset(&lvgl_port_ctx, 0, sizeof(lvgl_port_ctx));

/* LVGL init */
lv_init();
/* Tick init */
lvgl_port_ctx.timer_period_ms = cfg->timer_period_ms;
ESP_RETURN_ON_ERROR(lvgl_port_tick_init(), TAG, "");
/* Create task */
lvgl_port_ctx.task_max_sleep_ms = cfg->task_max_sleep_ms;
if (lvgl_port_ctx.task_max_sleep_ms == 0) {
lvgl_port_ctx.task_max_sleep_ms = 500;
}
/* Timer semaphore */
lvgl_port_ctx.timer_mux = xSemaphoreCreateMutex();
ESP_GOTO_ON_FALSE(lvgl_port_ctx.timer_mux, ESP_ERR_NO_MEM, err, TAG, "Create timer mutex fail!");
/* LVGL semaphore */
lvgl_port_ctx.lvgl_mux = xSemaphoreCreateRecursiveMutex();
ESP_GOTO_ON_FALSE(lvgl_port_ctx.lvgl_mux, ESP_ERR_NO_MEM, err, TAG, "Create LVGL mutex fail!");
Expand Down Expand Up @@ -216,6 +217,11 @@ static void lvgl_port_task(void *arg)
vTaskDelete( NULL );
}

/* LVGL init */
lv_init();
/* Tick init */
lvgl_port_tick_init();

ESP_LOGI(TAG, "Starting LVGL task");
lvgl_port_ctx.running = true;
while (lvgl_port_ctx.running) {
Expand All @@ -227,6 +233,7 @@ static void lvgl_port_task(void *arg)

/* Call read input devices */
if (event.type == LVGL_PORT_EVENT_TOUCH) {
xSemaphoreTake(lvgl_port_ctx.timer_mux, portMAX_DELAY);
if (event.param != NULL) {
lv_indev_read(event.param);
} else {
Expand All @@ -236,6 +243,7 @@ static void lvgl_port_task(void *arg)
indev = lv_indev_get_next(indev);
}
}
xSemaphoreGive(lvgl_port_ctx.timer_mux);
}

/* Handle LVGL */
Expand All @@ -262,6 +270,9 @@ static void lvgl_port_task(void *arg)

static void lvgl_port_task_deinit(void)
{
if (lvgl_port_ctx.timer_mux) {
vSemaphoreDelete(lvgl_port_ctx.timer_mux);
}
if (lvgl_port_ctx.lvgl_mux) {
vSemaphoreDelete(lvgl_port_ctx.lvgl_mux);
}
Expand All @@ -280,8 +291,10 @@ static void lvgl_port_task_deinit(void)

static void lvgl_port_tick_increment(void *arg)
{
xSemaphoreTake(lvgl_port_ctx.timer_mux, portMAX_DELAY);
/* Tell LVGL how many milliseconds have elapsed */
lv_tick_inc(lvgl_port_ctx.timer_period_ms);
xSemaphoreGive(lvgl_port_ctx.timer_mux);
}

static esp_err_t lvgl_port_tick_init(void)
Expand Down
Loading

0 comments on commit 97d9dd9

Please sign in to comment.