Boilerplate library to get started with LvGL on STM DISCO F746NG board. Adapted from https://os.mbed.com/users/JohnnyK/code/DISCO-F746NG_MbedOs_LvGL_example/

Dependencies:   BSP_DISCO_F746NG

Dependents:   LvGL_F746NG_test

Revision:
1:a23fffad1321
Parent:
0:cffa136e7f8f
--- a/lvgl_f746ng.cpp	Tue Sep 08 05:23:58 2020 +0000
+++ b/lvgl_f746ng.cpp	Thu Sep 10 09:24:23 2020 +0000
@@ -1,64 +1,41 @@
-/**
- * @file lvgl_f746ng.cpp
- *
- */
 
-/*********************
- *      INCLUDES
- *********************/
-#include "mbed.h"
 #include "lvgl_f746ng.h"
-#include <cstdio>
-#include "../lvgl/lvgl.h"
-#include "lv_port_disp.h"
-#include "lv_port_indev.h"
-
-/*********************
- *      DEFINES
- *********************/
-
-/**********************
- *      TYPEDEFS
- **********************/
 
-/**********************
- *  STATIC PROTOTYPES
- **********************/
-void lv_ticker_func(void);
-
-/**********************
- *  STATIC VARIABLES
- **********************/
-Ticker lvgl_ticker;  // mbed Ticker for lvgl
-
-/**********************
- *      MACROS
- **********************/
-
-/**********************
- *   GLOBAL FUNCTIONS
- **********************/
-
-/* Initialize lvgl + target port specifics + mbed ticker. */
-void lvgl_f746ng_init()
-{
-    debug("lvgl_f746ng_init\r\n"); 
-    lv_init();                                  //Initialize the LittlevGL
-    lv_port_disp_init();                        //Initialize diplay 
-    lv_port_indev_init();                       //Initialize touchpad
-    lvgl_ticker.attach(callback(&lv_ticker_func), 10ms); //Attach callback to ticker
+static void lv_ticker_func() {
+  // Call lv_tick_inc(x) every x milliseconds in a Timer or Task (x should be
+  // between 1 and 10). It is required for the internal timing of LittlevGL.
+  lv_tick_inc(LVGL_TICK_INC);
+  // Call lv_task_handler() periodically every few milliseconds.
+  // It will redraw the screen if required, handle input devices etc.
+  lv_task_handler();
 }
 
-/**********************
- *   STATIC FUNCTIONS
- **********************/
-/* Callback function for lvgl timing. */
-void lv_ticker_func()
-{
-    //Call lv_tick_inc(x) every x milliseconds in a Timer or Task (x should be between 1 and 10). 
-    //It is required for the internal timing of LittlevGL.
-    lv_tick_inc(10); 
-    //Call lv_task_handler() periodically every few milliseconds. 
-    //It will redraw the screen if required, handle input devices etc.
-    lv_task_handler(); 
+#ifdef LVGL_USE_THREAD
+static Thread lvgl_thread; // mbed Thread for lvgl
+static void lv_thread_func() {
+  printf("lv_thread_func from context %p\n", ThisThread::get_id());
+  while (1) {
+    ThisThread::sleep_for(LVGL_TICK_INC * 1ms);
+    lv_ticker_func();
+  }
 }
+#else
+static Ticker lvgl_ticker; // mbed Ticker for lvgl
+#endif /* LVGL_USE_THREAD */
+
+/* Initialize lvgl + target port specifics + mbed ticker or thread. */
+void lvgl_f746ng_init() {
+  printf("lvgl_f746ng_init from context %p\n", ThisThread::get_id());
+  lv_init();            // Initialize the LittlevGL
+  lv_port_disp_init();  // Initialize diplay
+  lv_port_indev_init(); // Initialize touchpad
+#ifdef LVGL_USE_THREAD
+  // Approach using mbed Thread
+  lvgl_thread.start(lv_thread_func);
+  // lvgl_thread.join();  // it will never join
+#else
+  // Approach using mbed Ticker
+  lvgl_ticker.attach(callback(&lv_ticker_func), LVGL_TICK_INC * 1ms);
+#endif /* LVGL_USE_THREAD */
+}
+