阶段1: 将 dzbj 项目的 LVGL 8.3.11 LCD 显示集成到 AI小智 主项目, 开机显示 ScreenHome 界面,同时优化配网模式下的内存使用, 确保 WiFi+BLE+LVGL 三者共存运行。 ## 新增功能 ### dzbj 显示模块集成 - 新增 main/dzbj/ 目录,移植 LCD 驱动(ST77916 QSPI)、触摸驱动(CST816S)、 LVGL 初始化和 SquareLine Studio UI 界面 - I2C 总线共享:dzbj 触摸控制器复用主项目的 I2C_NUM_1 总线 - GPIO 冲突解决:LED(GPIO21)、Touch1(GPIO1)、Touch4(GPIO7) 改为 NC, 电池 ADC 从 GPIO6 改为 GPIO3 - 添加 LVGL、esp_lcd_st77916、esp_lcd_touch_cst816s 等组件依赖 - managed_components 纳入版本管理 ### 配网模式轻量化启动 - BoxAudioCodec: 新增 output_only 模式,仅创建 I2S TX 通道(省 ~13KB DMA) 跳过 ES7210 ADC 初始化(省 ~2-4KB) - AudioCodec: 新增 StartOutputOnly() 方法,仅启用扬声器输出 - Application: 配网模式跳过 Opus 编码器、输入重采样器、协议初始化、 天气位置检测等网络业务 - 板级构造函数: 配网模式跳过电池检测、IMU传感器、PowerSaveTimer ### WifiBoard 配网流程修复 - NeedsProvisioning() 静态方法: 读取 NVS force_ap 和 SSID 列表, 用于提前判断配网模式 - force_ap 竞态修复: 构造函数不再清零 force_ap,改在 StartNetwork() 清零, 确保 NeedsProvisioning() 能正确读到 force_ap=1 - Application 缓存 provisioning_mode_ 成员变量,避免重复读 NVS ### BLE 配网重启修复 - 配网成功后用 esp_timer 延迟重启替代 xTaskCreate, 避免内存紧张时任务创建失败导致设备不重启 - 注释掉 WiFi 连接成功后的 MAC 地址发送步骤 ### sdkconfig 内存优化 - BT_ALLOCATION_FROM_SPIRAM_FIRST=y (BLE 动态分配优先 PSRAM) - SPIRAM_MALLOC_RESERVE_INTERNAL=32768 - NVS_ALLOCATE_CACHE_IN_SPIRAM=y - WiFi 静态缓冲区数量优化 (RX=10, TX=8) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
3.6 KiB
Timers
LVGL has a built-in timer system. You can register a function to have it be called periodically. The timers are handled and called in lv_timer_handler(), which needs to be called every few milliseconds.
See Porting for more information.
Timers are non-preemptive, which means a timer cannot interrupt another timer. Therefore, you can call any LVGL related function in a timer.
Create a timer
To create a new timer, use lv_timer_create(timer_cb, period_ms, user_data). It will create an lv_timer_t * variable, which can be used later to modify the parameters of the timer.
lv_timer_create_basic() can also be used. This allows you to create a new timer without specifying any parameters.
A timer callback should have a void (*lv_timer_cb_t)(lv_timer_t *); prototype.
For example:
void my_timer(lv_timer_t * timer)
{
/*Use the user_data*/
uint32_t * user_data = timer->user_data;
printf("my_timer called with user data: %d\n", *user_data);
/*Do something with LVGL*/
if(something_happened) {
something_happened = false;
lv_btn_create(lv_scr_act(), NULL);
}
}
...
static uint32_t user_data = 10;
lv_timer_t * timer = lv_timer_create(my_timer, 500, &user_data);
Ready and Reset
lv_timer_ready(timer) makes a timer run on the next call of lv_timer_handler().
lv_timer_reset(timer) resets the period of a timer. It will be called again after the defined period of milliseconds has elapsed.
Set parameters
You can modify some timer parameters later:
lv_timer_set_cb(timer, new_cb)lv_timer_set_period(timer, new_period)
Repeat count
You can make a timer repeat only a given number of times with lv_timer_set_repeat_count(timer, count). The timer will automatically be deleted after it's called the defined number of times. Set the count to -1 to repeat indefinitely.
Measure idle time
You can get the idle percentage time of lv_timer_handler with lv_timer_get_idle(). Note that, it doesn't measure the idle time of the overall system, only lv_timer_handler.
It can be misleading if you use an operating system and call lv_timer_handler in a timer, as it won't actually measure the time the OS spends in an idle thread.
Asynchronous calls
In some cases, you can't perform an action immediately. For example, you can't delete an object because something else is still using it, or you don't want to block the execution now.
For these cases, lv_async_call(my_function, data_p) can be used to call my_function on the next invocation of lv_timer_handler. data_p will be passed to the function when it's called.
Note that only the data pointer is saved, so you need to ensure that the variable will be "alive" while the function is called. It can be static, global or dynamically allocated data.
If you want to cancel an asynchronous call, call lv_async_call_cancel(my_function, data_p), which will clear all asynchronous calls matching my_function and data_p.
For example:
void my_screen_clean_up(void * scr)
{
/*Free some resources related to `scr`*/
/*Finally delete the screen*/
lv_obj_del(scr);
}
...
/*Do something with the object on the current screen*/
/*Delete screen on next call of `lv_timer_handler`, not right now.*/
lv_async_call(my_screen_clean_up, lv_scr_act());
/*The screen is still valid so you can do other things with it*/
If you just want to delete an object and don't need to clean anything up in my_screen_cleanup you could just use lv_obj_del_async which will delete the object on the next call to lv_timer_handler.
API
.. doxygenfile:: lv_timer.h
:project: lvgl
.. doxygenfile:: lv_async.h
:project: lvgl