I think the API of
lv_task_handler can be improved to reduce CPU usage when nothing is happening.
Currently, we recommend that users call it every 10 milliseconds or so. If there is no work to be done, it will return almost immediately, and the system can go back to sleep for another 10 milliseconds.
These constant wakeups do affect power consumption, though, and we have enough information stored within the task structure to be able to handle things much more efficiently.
My proposal consists of a few different improvements which should enable us to reach 0% CPU usage when idle. All of these can be done in a minor release as they won’t break existing functionality.
I’m happy and eager to implement these myself; this post is mainly to confirm that others (particularly @kisvegabor) agree with the general strategy.
lv_task_handlerreturn the time in milliseconds after which another task will be ready to run. This will enable the OS to sleep for exactly the required amount of time (instead of picking an interval like 10ms). If nothing needs to be done then a special value should be returned that indicates LittlevGL is waiting for some event to occur (i.e. input or a widget state change).
- In order to achieve 0% CPU usage, we must ensure that no LittlevGL task is “ready-to-run” (in OS terminology) if no work needs to be done. We should make use of
LV_TASK_PRIO_OFFfor built-in tasks.
lv_disp_refr_taskshould be modified to change its priority to
LV_TASK_PRIO_OFFonce it finishes refreshing all invalidated areas. Any function which invalidates areas should then resume the refresh task. This ensures that the refresh task only runs if something actually needs to be drawn.
- We need to add a mode whereby the input task can be suspended at initialization time and triggered to run when necessary (e.g. by a touch interrupt). Currently, like the refresh task, the input task runs on a set frequency even if no input is available.
With these changes, it should be possible to completely suspend the processor if nothing has changed within LittlevGL.