@@ -80,12 +80,6 @@ template <typename Pixel> class Display : public BaseComponent {
8080 nullptr }; /* *< Optional function used to configure display with new rotation setting. */
8181 DisplayRotation rotation{
8282 DisplayRotation::LANDSCAPE}; /* *< Default / Initial rotation of the display. */
83- Task::BaseConfig task_config{.name = " Display" ,
84- .stack_size_bytes = 4096 ,
85- .priority = 20 ,
86- .core_id = 0 }; /* *< Task configuration. */
87- std::chrono::duration<float > update_period{
88- 0.01 }; /* *< How frequently to run the update function. */
8983 };
9084
9185 /* *
@@ -148,11 +142,9 @@ template <typename Pixel> class Display : public BaseComponent {
148142 , height_(lvgl_conf.height)
149143 , display_buffer_px_size_(mem_conf.pixel_buffer_size)
150144 , vram_0_(mem_conf.vram0)
151- , vram_1_(mem_conf.vram1)
152- , update_period_(lvgl_conf.update_period) {
145+ , vram_1_(mem_conf.vram1) {
153146 init_backlight (lcd_config.backlight_pin , lcd_config.backlight_on_value );
154- init_gfx (lvgl_conf.flush_callback , lvgl_conf.rotation_callback , lvgl_conf.rotation ,
155- lvgl_conf.task_config );
147+ init_gfx (lvgl_conf.flush_callback , lvgl_conf.rotation_callback , lvgl_conf.rotation );
156148 set_brightness (1.0 );
157149 }
158150
@@ -170,12 +162,10 @@ template <typename Pixel> class Display : public BaseComponent {
170162 : BaseComponent(" Display" , log_level)
171163 , width_(lvgl_conf.width)
172164 , height_(lvgl_conf.height)
173- , display_buffer_px_size_(mem_conf.pixel_buffer_size)
174- , update_period_(lvgl_conf.update_period) {
165+ , display_buffer_px_size_(mem_conf.pixel_buffer_size) {
175166 init_memory (mem_conf.double_buffered , mem_conf.allocation_flags );
176167 init_backlight (lcd_config.backlight_pin , lcd_config.backlight_on_value );
177- init_gfx (lvgl_conf.flush_callback , lvgl_conf.rotation_callback , lvgl_conf.rotation ,
178- lvgl_conf.task_config );
168+ init_gfx (lvgl_conf.flush_callback , lvgl_conf.rotation_callback , lvgl_conf.rotation );
179169 set_brightness (1.0 );
180170 }
181171
@@ -196,11 +186,9 @@ template <typename Pixel> class Display : public BaseComponent {
196186 , display_buffer_px_size_(mem_conf.pixel_buffer_size)
197187 , vram_0_(mem_conf.vram0)
198188 , vram_1_(mem_conf.vram1)
199- , update_period_(lvgl_conf.update_period)
200189 , set_brightness_(oled_config.set_brightness_callback)
201190 , get_brightness_(oled_config.get_brightness_callback) {
202- init_gfx (lvgl_conf.flush_callback , lvgl_conf.rotation_callback , lvgl_conf.rotation ,
203- lvgl_conf.task_config );
191+ init_gfx (lvgl_conf.flush_callback , lvgl_conf.rotation_callback , lvgl_conf.rotation );
204192 set_brightness (1.0 );
205193 }
206194
@@ -219,20 +207,17 @@ template <typename Pixel> class Display : public BaseComponent {
219207 , width_(lvgl_conf.width)
220208 , height_(lvgl_conf.height)
221209 , display_buffer_px_size_(mem_conf.pixel_buffer_size)
222- , update_period_(lvgl_conf.update_period)
223210 , set_brightness_(oled_config.set_brightness_callback)
224211 , get_brightness_(oled_config.get_brightness_callback) {
225212 init_memory (mem_conf.double_buffered , mem_conf.allocation_flags );
226- init_gfx (lvgl_conf.flush_callback , lvgl_conf.rotation_callback , lvgl_conf.rotation ,
227- lvgl_conf.task_config );
213+ init_gfx (lvgl_conf.flush_callback , lvgl_conf.rotation_callback , lvgl_conf.rotation );
228214 set_brightness (1.0 );
229215 }
230216
231217 /* *
232218 * @brief Stops the upate task and frees the display buffer memory.
233219 */
234220 ~Display () {
235- task_->stop ();
236221 if (created_vram_) {
237222 free (vram_0_);
238223 free (vram_1_);
@@ -282,18 +267,6 @@ template <typename Pixel> class Display : public BaseComponent {
282267 return 0 .0f ;
283268 }
284269
285- /* *
286- * @brief Pause the display update task, to prevent LVGL from writing to the
287- * display.
288- */
289- void pause () { paused_ = true ; }
290-
291- /* *
292- * @brief Resume the display update task, to allow LVGL to write to the
293- * display.
294- */
295- void resume () { paused_ = false ; }
296-
297270 /* *
298271 * @brief Force a redraw / refresh of the display.
299272 *
@@ -395,10 +368,9 @@ template <typename Pixel> class Display : public BaseComponent {
395368 * @param flush_callback Callback used to flush color data to the display.
396369 * @param rotation_callback function to call in the event handler on rotation change.
397370 * @param rotation Default / initial rotation of the display.
398- * @param task_config Configuration for the task that runs the lvgl tick
399371 */
400372 void init_gfx (const flush_fn flush_callback, const rotation_fn rotation_callback,
401- DisplayRotation rotation, const Task::BaseConfig &task_config ) {
373+ DisplayRotation rotation) {
402374 // save the callbacks
403375 if (flush_callback == nullptr ) {
404376 logger_.error (" No flush callback provided, cannot initialize display!" );
@@ -413,6 +385,10 @@ template <typename Pixel> class Display : public BaseComponent {
413385
414386 lv_init ();
415387
388+ lv_tick_set_cb (xTaskGetTickCount);
389+
390+ lv_delay_set_cb (vTaskDelay_wrapper);
391+
416392 display_ = lv_display_create (width_, height_);
417393 // store a pointer to this object in the display user data, so that we can
418394 // access it in the flush callback
@@ -429,14 +405,6 @@ template <typename Pixel> class Display : public BaseComponent {
429405
430406 // Setting as default display, allows the use of lv_disp_get_default()
431407 lv_display_set_default (display_);
432-
433- // Now start the task for the ui management
434- using namespace std ::placeholders;
435- task_ = Task::make_unique ({
436- .callback = std::bind (&Display::update, this , _1, _2, _3),
437- .task_config = task_config,
438- });
439- task_->start ();
440408 }
441409
442410 /* *
@@ -479,35 +447,12 @@ template <typename Pixel> class Display : public BaseComponent {
479447 }
480448
481449 /* *
482- * @brief Flush the data to the display, called within the task_.
483- *
484- * This task should always be high priority, so that it is higher than
485- * than the task running lv_task_handler(). For more info, see
486- * https://docs.lvgl.io/latest/en/html/porting/tick.html
450+ * @brief Wrapper around vTaskDelay, to pass to LVGL.
451+ * If not, LVGL will do random math as to delay the task instead.
452+ * @param ms The number of milliseconds to delay.
487453 */
488- bool update (std::mutex &m, std::condition_variable &cv, bool &task_notified) {
489- auto now = std::chrono::high_resolution_clock::now ();
490- static auto prev = now;
491- if (!paused_) {
492- int elapsed_ms = std::chrono::duration_cast<std::chrono::milliseconds>(now - prev).count ();
493- // we shouldn't stop, update the display
494- lv_tick_inc (elapsed_ms);
495- }
496- // update previous timestamp
497- prev = now;
498- // delay
499- {
500- using namespace std ::chrono_literals;
501- std::unique_lock<std::mutex> lk (m);
502- cv.wait_for (lk, update_period_, [&task_notified] { return task_notified; });
503- task_notified = false ;
504- }
505- // don't want to stop the task
506- return false ;
507- }
454+ static void vTaskDelay_wrapper (const uint32_t ms) { vTaskDelay (pdMS_TO_TICKS (ms)); }
508455
509- std::atomic<bool > paused_{false };
510- std::unique_ptr<Task> task_;
511456 size_t width_;
512457 size_t height_;
513458 flush_fn flush_callback_{nullptr };
@@ -518,7 +463,6 @@ template <typename Pixel> class Display : public BaseComponent {
518463 bool created_vram_{false };
519464 std::vector<Led::ChannelConfig> led_channel_configs_;
520465 std::unique_ptr<Led> backlight_{nullptr };
521- std::chrono::duration<float > update_period_;
522466 lv_display_t *display_;
523467 set_brightness_fn set_brightness_{nullptr };
524468 get_brightness_fn get_brightness_{nullptr };
0 commit comments