Skip to content

Commit

Permalink
feat(ports): flash scripts into vfs
Browse files Browse the repository at this point in the history
  • Loading branch information
Lzw655 committed Nov 12, 2024
1 parent b6f8df9 commit 188ce42
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 39 deletions.
3 changes: 2 additions & 1 deletion ports/esp32/boards/ESP32_S3_BOX_3/mpconfigboard.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
3 changes: 1 addition & 2 deletions ports/esp32/boards/ESP32_S3_BOX_3/sdkconfig.board
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 2 additions & 0 deletions ports/esp32/main_esp32s3_box3/esp32_common.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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})

Expand Down
73 changes: 40 additions & 33 deletions ports/esp32/main_esp32s3_box3/lvgl_port.c
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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;
Expand All @@ -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};
Expand Down Expand Up @@ -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));
}
}

Expand Down Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions ports/esp32/main_esp32s3_box3/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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");
Expand All @@ -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);
Expand Down
Binary file not shown.

0 comments on commit 188ce42

Please sign in to comment.