App:Library:LVGL:docs:Porting:Operating system and interrupts

提供: robot-jp wiki
2022年6月22日 (水) 14:45時点におけるTakashi (トーク | 投稿記録)による版
ナビゲーションに移動検索に移動

https://docs.lvgl.io/8.2/porting/os.html

英文 自動翻訳


Operating system and interrupts

英文 自動翻訳

LVGL is not thread-safe by default.

However, in the following conditions it's valid to call LVGL related functions:

  • In events. Learn more in Events.
  • In lv_timer. Learn more in Timers.
LVGLは、デフォルトではスレッドセーフではありません。

ただし、以下の条件では、LVGL関連の関数を呼び出すことが有効です。

  • LVGLは、デフォルトではスレッドセーフではありません。イベントで。詳細については、イベントをご覧ください。
  • lv_timer。詳細については、タイマーをご覧ください。
戻る : Previous


Tasks and threads

英文 自動翻訳

If you need to use real tasks or threads, you need a mutex which should be invoked before the call of lv_timer_handler and released after it. Also, you have to use the same mutex in other tasks and threads around every LVGL (lv_...) related function call and code. This way you can use LVGL in a real multitasking environment. Just make use of a mutex to avoid the concurrent calling of LVGL functions.

Here is some pseudocode to illustrate the concept:

 static mutex_t lvgl_mutex;

 void lvgl_thread(void)
 {
     while(1) {
         mutex_lock(&lvgl_mutex);
         lv_task_handler();
         mutex_unlock(&lvgl_mutex);
         thread_sleep(10); /* sleep for 10 ms */
     }
 }
 
 void other_thread(void)
 {
     /* You must always hold the mutex while using LVGL APIs */
     mutex_lock(&lvgl_mutex);
     lv_obj_t *img = lv_img_create(lv_scr_act());
     mutex_unlock(&lvgl_mutex);
     
     while(1) {
         mutex_lock(&lvgl_mutex);
         /* change to the next image */
         lv_img_set_src(img, next_image);
         mutex_unlock(&lvgl_mutex);
         thread_sleep(2000);
     }
 }


実際のタスクまたはスレッドを使用する必要がある場合は、呼び出しの前に呼び出して、呼び出しlv_timer_handler後に解放するミューテックスが必要です。また、すべてのLVGL(lv_...)関連の関数呼び出しとコードの周りの他のタスクとスレッドで同じミューテックスを使用する必要があります。このようにして、実際のマルチタスク環境でLVGLを使用できます。LVGL関数の同時呼び出しを回避するには、ミューテックスを使用するだけです。

概念を説明するためのいくつかの擬似コードを次に示します。

 static  mutex_t  lvgl_mutex ;

 void  lvgl_thread (void )
 { 
     while (1 ) { 
         mutex_lock (&lvgl_mutex ); 
         lv_task_handler (); 
         mutex_unlock (&lvgl_mutex ); 
         thread_sleep (10 );  /*10ミリ秒間スリープ*/ 
     } 
 }
 
 void  other_thread (void )
 { 
     / *LVGLAPIを使用している間は常にミューテックスを保持する必要があります*/ 
     mutex_lock (&lvgl_mutex ); 
     lv_obj_t  * img  =  lv_img_create (lv_scr_act ()); 
     mutex_unlock (&lvgl_mutex );
     
     while (1 ) { 
         mutex_lock (&lvgl_mutex ); 
         /*次の画像に変更します*/ 
         lv_img_set_src (img 、 next_image ); 
         mutex_unlock (&lvgl_mutex ); 
         thread_sleep (2000 ); 
     } 
 }
戻る : Previous


Interrupts

英文 自動翻訳

Try to avoid calling LVGL functions from interrupt handlers (except lv_tick_inc() and lv_disp_flush_ready()). But if you need to do this you have to disable the interrupt which uses LVGL functions while lv_timer_handler is running.

It's a better approach to simply set a flag or some value in the interrupt, and periodically check it in an LVGL timer (which is run by lv_timer_handler).

lv_tick_inc()割り込みハンドラー(およびを除く)からLVGL関数を呼び出さないようにしてくださいlv_disp_flush_ready()。ただし、これを行う必要がある場合は、lv_timer_handler実行中にLVGL関数を使用する割り込みを無効にする必要があります。

割り込みにフラグまたは何らかの値を設定し、LVGLタイマー(によって実行されるlv_timer_handler)で定期的にチェックすることをお勧めします。

戻る : Previous