diff --git a/ports/esp32/boards/ESP32_S3_BOX_3/mpconfigboard.h b/ports/esp32/boards/ESP32_S3_BOX_3/mpconfigboard.h index 5f6513ec0b17..39f66b747606 100644 --- a/ports/esp32/boards/ESP32_S3_BOX_3/mpconfigboard.h +++ b/ports/esp32/boards/ESP32_S3_BOX_3/mpconfigboard.h @@ -10,4 +10,5 @@ #define MICROPY_HW_I2C0_SCL (9) #define MICROPY_HW_I2C0_SDA (8) -#define MICROPY_LV_USE_LOG (1) +#define MICROPY_LV_USE_LOG (0) +#define MICROPY_TASK_STACK_SIZE (50 * 1024) diff --git a/ports/esp32/boards/ESP32_S3_BOX_3/sdkconfig.board b/ports/esp32/boards/ESP32_S3_BOX_3/sdkconfig.board index 1a5c838a77c1..6769444152e3 100644 --- a/ports/esp32/boards/ESP32_S3_BOX_3/sdkconfig.board +++ b/ports/esp32/boards/ESP32_S3_BOX_3/sdkconfig.board @@ -9,8 +9,7 @@ CONFIG_SPIRAM_FETCH_INSTRUCTIONS=y CONFIG_SPIRAM_RODATA=y CONFIG_SPIRAM_SPEED_80M=y CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ_240=y -CONFIG_ESP_CONSOLE_UART_CUSTOM=y -CONFIG_ESP_CONSOLE_UART_BAUDRATE=2000000 CONFIG_FREERTOS_HZ=1000 CONFIG_ESP_BROOKESIA_MEMORY_USE_CUSTOM=y CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG=y +CONFIG_FATFS_LFN_HEAP=y diff --git a/ports/esp32/main_esp32s3_box3/esp32_common.cmake b/ports/esp32/main_esp32s3_box3/esp32_common.cmake index 7c2902599d63..a5d308ba5d96 100644 --- a/ports/esp32/main_esp32s3_box3/esp32_common.cmake +++ b/ports/esp32/main_esp32s3_box3/esp32_common.cmake @@ -170,6 +170,8 @@ idf_component_register( ${IDF_COMPONENTS} ) +fatfs_create_rawflash_image(vfs ./scripts FLASH_IN_PROJECT) + # Set the MicroPython target as the current (main) IDF component target. set(MICROPY_TARGET ${COMPONENT_TARGET}) diff --git a/ports/esp32/main_esp32s3_box3/lvgl_port.c b/ports/esp32/main_esp32s3_box3/lvgl_port.c index 7a23ed27d3de..50594ddb34d8 100644 --- a/ports/esp32/main_esp32s3_box3/lvgl_port.c +++ b/ports/esp32/main_esp32s3_box3/lvgl_port.c @@ -11,12 +11,12 @@ #include "lvgl/lvgl.h" #include "lvgl_port.h" -#define LVGL_DRAW_BUF_LINES 20 // number of display lines in each draw buffer +#define LVGL_DRAW_BUF_LINES 50 // number of display lines in each draw buffer #define LVGL_TICK_PERIOD_MS 2 #define LVGL_TASK_MAX_DELAY_MS 500 #define LVGL_TASK_MIN_DELAY_MS 1 #define LVGL_TASK_STACK_SIZE (6 * 1024) -#define LVGL_TASK_PRIORITY 2 +#define LVGL_TASK_PRIORITY (4) static _lock_t lvgl_api_lock; static const char *TAG = "lvgl_port"; @@ -29,38 +29,38 @@ bool lvgl_port_notify_lvgl_flush_ready(esp_lcd_panel_io_handle_t panel_io, esp_l } /* Rotate display and touch, when rotated screen in LVGL. Called when driver parameters are updated. */ -static void lvgl_port_update_callback(lv_display_t *disp) -{ - esp_lcd_panel_handle_t panel_handle = lv_display_get_user_data(disp); - lv_display_rotation_t rotation = lv_display_get_rotation(disp); - - switch (rotation) { - case LV_DISPLAY_ROTATION_0: - // Rotate LCD display - esp_lcd_panel_swap_xy(panel_handle, false); - esp_lcd_panel_mirror(panel_handle, true, false); - break; - case LV_DISPLAY_ROTATION_90: - // Rotate LCD display - esp_lcd_panel_swap_xy(panel_handle, true); - esp_lcd_panel_mirror(panel_handle, true, true); - break; - case LV_DISPLAY_ROTATION_180: - // Rotate LCD display - esp_lcd_panel_swap_xy(panel_handle, false); - esp_lcd_panel_mirror(panel_handle, false, true); - break; - case LV_DISPLAY_ROTATION_270: - // Rotate LCD display - esp_lcd_panel_swap_xy(panel_handle, true); - esp_lcd_panel_mirror(panel_handle, false, false); - break; - } -} +// static void lvgl_port_update_callback(lv_display_t *disp) +// { +// esp_lcd_panel_handle_t panel_handle = lv_display_get_user_data(disp); +// lv_display_rotation_t rotation = lv_display_get_rotation(disp); + +// switch (rotation) { +// case LV_DISPLAY_ROTATION_0: +// // Rotate LCD display +// esp_lcd_panel_swap_xy(panel_handle, false); +// esp_lcd_panel_mirror(panel_handle, true, false); +// break; +// case LV_DISPLAY_ROTATION_90: +// // Rotate LCD display +// esp_lcd_panel_swap_xy(panel_handle, true); +// esp_lcd_panel_mirror(panel_handle, true, true); +// break; +// case LV_DISPLAY_ROTATION_180: +// // Rotate LCD display +// esp_lcd_panel_swap_xy(panel_handle, false); +// esp_lcd_panel_mirror(panel_handle, false, true); +// break; +// case LV_DISPLAY_ROTATION_270: +// // Rotate LCD display +// esp_lcd_panel_swap_xy(panel_handle, true); +// esp_lcd_panel_mirror(panel_handle, false, false); +// break; +// } +// } static void lvgl_flush_cb(lv_display_t *disp, const lv_area_t *area, uint8_t *px_map) { - lvgl_port_update_callback(disp); + // lvgl_port_update_callback(disp); esp_lcd_panel_handle_t panel_handle = lv_display_get_user_data(disp); int offsetx1 = area->x1; int offsetx2 = area->x2; @@ -72,6 +72,12 @@ static void lvgl_flush_cb(lv_display_t *disp, const lv_area_t *area, uint8_t *px esp_lcd_panel_draw_bitmap(panel_handle, offsetx1, offsety1, offsetx2 + 1, offsety2 + 1, px_map); } +static void lvgl_flush_wait_cb(lv_display_t * disp) +{ + // wait for the flush to be ready + vTaskDelay(pdMS_TO_TICKS(LVGL_TASK_MIN_DELAY_MS)); +} + static void lvgl_touch_cb(lv_indev_t * indev, lv_indev_data_t * data) { uint16_t touchpad_x[1] = {0}; @@ -108,13 +114,13 @@ static MP_DEFINE_CONST_FUN_OBJ_1(mp_lv_task_handler_obj, mp_lv_task_handler); static void lvgl_port_task(void *arg) { printf("Starting LVGL task\n"); - uint32_t time_till_next_ms = 5; + uint32_t time_till_next_ms = 10; // uint32_t time_threshold_ms = 1000 / CONFIG_FREERTOS_HZ; while (1) { mp_sched_schedule((mp_obj_t)&mp_lv_task_handler_obj, mp_const_none); // in case of triggering a task watch dog time out // time_till_next_ms = MAX(time_till_next_ms, time_threshold_ms); - usleep(1000 * time_till_next_ms); + vTaskDelay(pdMS_TO_TICKS(time_till_next_ms)); } } @@ -142,6 +148,7 @@ lv_display_t *lvgl_port_init(int h_res, int v_res, esp_lcd_panel_handle_t panel_ lv_display_set_color_format(display, LV_COLOR_FORMAT_RGB565); // set the callback which can copy the rendered image to an area of the display lv_display_set_flush_cb(display, lvgl_flush_cb); + lv_display_set_flush_wait_cb(display, lvgl_flush_wait_cb); printf("Install LVGL tick timer\n"); // Tick interface for LVGL (using esp_timer to generate 2ms periodic event) diff --git a/ports/esp32/main_esp32s3_box3/main.c b/ports/esp32/main_esp32s3_box3/main.c index 86f0be515173..1d8a345cbc8e 100644 --- a/ports/esp32/main_esp32s3_box3/main.c +++ b/ports/esp32/main_esp32s3_box3/main.c @@ -74,7 +74,7 @@ #include "lvgl_port.h" // MicroPython runs as a task under FreeRTOS -#define MP_TASK_PRIORITY (ESP_TASK_PRIO_MIN + 1) +#define MP_TASK_PRIORITY (ESP_TASK_PRIO_MIN + 5) // Set the margin for detecting stack overflow, depending on the CPU architecture. #if CONFIG_IDF_TARGET_ESP32C3 @@ -145,8 +145,6 @@ void mp_task(void *pvParameter) { machine_i2s_init0(); #endif - init_lvgl_port(); - // run boot-up scripts pyexec_frozen_module("_boot.py", false); int ret = pyexec_file_if_exists("boot.py"); @@ -160,6 +158,8 @@ void mp_task(void *pvParameter) { } } + init_lvgl_port(); + for (;;) { if (pyexec_mode_kind == PYEXEC_MODE_RAW_REPL) { vprintf_like_t vprintf_log = esp_log_set_vprintf(vprintf_null); diff --git a/ports/esp32/main_esp32s3_box3/scripts/lvgl_demo.mpy b/ports/esp32/main_esp32s3_box3/scripts/lvgl_demo.mpy new file mode 100644 index 000000000000..92084d3faaa1 Binary files /dev/null and b/ports/esp32/main_esp32s3_box3/scripts/lvgl_demo.mpy differ