Add ScopedLock for LVGL.
This commit is contained in:
		
							parent
							
								
									dd5335815c
								
							
						
					
					
						commit
						58a83590ca
					
				@ -32,6 +32,14 @@ static const char *TAG = "lcd-panel";
 | 
				
			|||||||
#define PIN_SCL                GPIO_NUM_22
 | 
					#define PIN_SCL                GPIO_NUM_22
 | 
				
			||||||
#define PIN_RST                -1
 | 
					#define PIN_RST                -1
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					struct ScopedLock {
 | 
				
			||||||
 | 
					  explicit ScopedLock(_lock_t& lock) : lock_(&lock) { _lock_acquire(lock_); }
 | 
				
			||||||
 | 
					  ~ScopedLock() { _lock_release(lock_); }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					private:
 | 
				
			||||||
 | 
					  _lock_t* lock_;
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class Display {
 | 
					class Display {
 | 
				
			||||||
public:
 | 
					public:
 | 
				
			||||||
  Display();
 | 
					  Display();
 | 
				
			||||||
 | 
				
			|||||||
@ -7,12 +7,12 @@ void setup()
 | 
				
			|||||||
{
 | 
					{
 | 
				
			||||||
  Display d;
 | 
					  Display d;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  ESP_LOGI(TAG, "Display LVGL Scroll Text");
 | 
					 | 
				
			||||||
  // Lock the mutex due to the LVGL APIs are not thread-safe
 | 
					 | 
				
			||||||
  _lock_acquire(&Display::lvgl_api_lock_);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  // UI function
 | 
					  // UI function
 | 
				
			||||||
  {
 | 
					  {
 | 
				
			||||||
 | 
					    // Lock the mutex due to the LVGL APIs are not thread-safe
 | 
				
			||||||
 | 
					    ScopedLock lock(Display::lvgl_api_lock_);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    ESP_LOGI(TAG, "Display LVGL Scroll Text");
 | 
				
			||||||
    lv_obj_t *scr = lv_display_get_screen_active(d.get_display());
 | 
					    lv_obj_t *scr = lv_display_get_screen_active(d.get_display());
 | 
				
			||||||
    lv_obj_t *label = lv_label_create(scr);
 | 
					    lv_obj_t *label = lv_label_create(scr);
 | 
				
			||||||
    // Circular scroll
 | 
					    // Circular scroll
 | 
				
			||||||
@ -26,8 +26,6 @@ void setup()
 | 
				
			|||||||
                     lv_display_get_horizontal_resolution(d.get_display()));
 | 
					                     lv_display_get_horizontal_resolution(d.get_display()));
 | 
				
			||||||
    lv_obj_align(label, LV_ALIGN_TOP_MID, 0, 0);
 | 
					    lv_obj_align(label, LV_ALIGN_TOP_MID, 0, 0);
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					 | 
				
			||||||
  _lock_release(&Display::lvgl_api_lock_);
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void loop() { }
 | 
					void loop() { }
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user