프로그램 사용/lvgl2026. 1. 26. 14:07

main() 에서 

xTaskCreate()를 통해 쓰레드를 여러개 생성하여 돌리는 컨셉

 

sleep() 으로 cpu를 차지하는게 아니라

vTaskDelay()를 이용하여 다른 태스크에게 넘겨줘서 처리한다.

[링크 : https://fishpoint.tistory.com/12257]

 

esp32 esp-idf에 포팅된 엔트리 포인트가 app_main() 인가?

그리고  xTaskCreate는 없고 xTaskCreatePinnedToCore()라는 함수를 쓰는데

특정 core 에서 돌리게 하는 일종의 affinity 제한 쓰레드 생성 함수라고 하면 되려나?

// 主函数
void app_main() {
printf("\r\nAPP %s is start!~\r\n", TAG);
vTaskDelay(1000 / portTICK_PERIOD_MS);
// 如果要使用任务创建图形,则需要创建固定核心任务,否则可能会出现诸如内存损坏等问题
// 创建一个固定到其中一个核心的FreeRTOS任务,选择核心1
xTaskCreatePinnedToCore(guiTask, "gui", 4096*2, NULL, 0, NULL, 1);
}

void guiTask(void *pvParameter) {
    
    (void) pvParameter;
    xGuiSemaphore = xSemaphoreCreateMutex();    // 创建GUI信号量
    lv_init();          // 初始化LittlevGL
    lvgl_driver_init(); // 初始化液晶SPI驱动 触摸芯片SPI/IIC驱动

    static lv_color_t buf1[DISP_BUF_SIZE];
#ifndef CONFIG_LVGL_TFT_DISPLAY_MONOCHROME
    static lv_color_t buf2[DISP_BUF_SIZE];
#endif
    static lv_disp_buf_t disp_buf;

    uint32_t size_in_px = DISP_BUF_SIZE;

#if defined CONFIG_LVGL_TFT_DISPLAY_CONTROLLER_IL3820 
    /* Actual size in pixel, not bytes and use single buffer */
    size_in_px *= 8;
    lv_disp_buf_init(&disp_buf, buf1, NULL, size_in_px);
#elif defined CONFIG_LVGL_TFT_DISPLAY_MONOCHROME
    lv_disp_buf_init(&disp_buf, buf1, NULL, size_in_px);
#else
    lv_disp_buf_init(&disp_buf, buf1, buf2, size_in_px);
#endif

    lv_disp_drv_t disp_drv;
    lv_disp_drv_init(&disp_drv);
    disp_drv.flush_cb = disp_driver_flush;

// 如果配置为 单色模式
#ifdef CONFIG_LVGL_TFT_DISPLAY_MONOCHROME
    disp_drv.rounder_cb = disp_driver_rounder;
    disp_drv.set_px_cb = disp_driver_set_px;
#endif

    disp_drv.buffer = &disp_buf;
    lv_disp_drv_register(&disp_drv);


// 如果有配置触摸芯片,配置触摸
#if CONFIG_LVGL_TOUCH_CONTROLLER != TOUCH_CONTROLLER_NONE
    lv_indev_drv_t indev_drv;
    lv_indev_drv_init(&indev_drv);
    indev_drv.read_cb = touch_driver_read;
    indev_drv.type = LV_INDEV_TYPE_POINTER;
    lv_indev_drv_register(&indev_drv);
#endif


    const esp_timer_create_args_t periodic_timer_args = {
        .callback = &lv_tick_task,
        .name = "periodic_gui"
    };
    esp_timer_handle_t periodic_timer;
    ESP_ERROR_CHECK(esp_timer_create(&periodic_timer_args, &periodic_timer));
    ESP_ERROR_CHECK(esp_timer_start_periodic(periodic_timer, LV_TICK_PERIOD_MS * 1000));

    // 一个标签演示
    //lv_obj_t * scr = lv_disp_get_scr_act(NULL);         // 获取当前屏幕
    //lv_obj_t * label1 =  lv_label_create(scr, NULL);    // 在当前活动的屏幕上创建标签
    //lv_label_set_text(label1, "Hello\nworld!");         // 修改标签的文字
    // 对象对齐函数,将标签中心对齐,NULL表示在父级上对齐,当前父级是屏幕,0,0表示对齐后的x,y偏移量
    //lv_obj_align(label1, NULL, LV_ALIGN_CENTER, 0, 0);
/*
lv_indev_t * mouse_indev = lv_indev_drv_register(&indev_drv);
lv_obj_t * cursor_obj =  lv_img_create(lv_scr_act(), NULL); //Create an image object for the cursor 
lv_img_set_src(cursor_obj, &mouse_cursor_icon);             //Set the image source
lv_indev_set_cursor(mouse_indev, cursor_obj);               //Connect the image  object to the driver
*/
lv_demo_widgets();

    while (1) {
vTaskDelay(1);
// 尝试锁定信号量,如果成功,请调用lvgl的东西
if (xSemaphoreTake(xGuiSemaphore, (TickType_t)10) == pdTRUE) {
            lv_task_handler();
            xSemaphoreGive(xGuiSemaphore);  // 释放信号量
        }
    }
    vTaskDelete(NULL);      // 删除任务
}

 

esp-idf 4.3 사용중인데, xTaskCreate가 없다?

BaseType_t xTaskCreatePinnedToCore( TaskFunction_t pvTaskCode,
const char * const pcName,
const uint32_t usStackDepth,
void * const pvParameters,
UBaseType_t uxPriority,
TaskHandle_t * const pvCreatedTask,
const BaseType_t xCoreID)

xTaskCreatePinnedToCore                           esp-idf/freertos/libfreertos.a(tasks.c.obj)
                                                  esp-idf/esp_ipc/libesp_ipc.a(ipc.c.obj)
                                                  esp-idf/main/libmain.a(main.c.obj)
                                                  esp-idf/freertos/libfreertos.a(port_common.c.obj)
                                                  esp-idf/esp_timer/libesp_timer.a(esp_timer.c.obj)
                                                  esp-idf/esp32/libesp32.a(dport_access.c.obj)
                                                  esp-idf/pthread/libpthread.a(pthread.c.obj)
xTaskCreateRestricted                             esp-idf/freertos/libfreertos.a(tasks.c.obj)
xTaskCreateRestrictedStatic                       esp-idf/freertos/libfreertos.a(tasks.c.obj)
xTaskCreateStaticPinnedToCore                     esp-idf/freertos/libfreertos.a(tasks.c.obj)

 

코드가 어느 코어에서 실행되고 있는가를 확인하려면 xPortGetCoreID() 함수를 사용하면 된다.


xTaskCreatePinnedToCore (
  Task1code,      // 태스크를 구현한 함수
  “Task1”,        // 태스크 이름
  10000,          // 스택 크기 (word단위)
  NULL,           // 태스크 파라미터
  0,              // 태스크 우선순위
  &Task1,         // 태스크 핸들
  0 );            // 태스크가 실행될 코어

[링크 : https://arsviator.blogspot.com/2019/04/esp32-use-multicore-on-esp32.html]

[링크 : https://www.reddit.com/r/esp32/comments/vk66d8/what_is_difference_between/?tl=ko]

'프로그램 사용 > lvgl' 카테고리의 다른 글

lvgl pro on win10 실패  (0) 2026.01.22
lvgl pro, square line studio  (0) 2026.01.09
esp32 lvgl  (0) 2025.11.15
LVGL (Light and Versatile Graphics Library)  (0) 2023.11.18
Posted by 구차니