Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: BSP_DISCO_F746NG
Revision 1:a23fffad1321, committed 2020-09-10
- Comitter:
- elelthvd
- Date:
- Thu Sep 10 09:24:23 2020 +0000
- Parent:
- 0:cffa136e7f8f
- Commit message:
- Add usage for Mbed Thread
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/example_main.cpp Thu Sep 10 09:24:23 2020 +0000
@@ -0,0 +1,15 @@
+/* example_main.cpp */
+//
+//#include "lvgl_f746ng.h"
+//#include "mbed.h"
+//
+//int main() {
+// printf("main from context %p\n", ThisThread::get_id());
+//
+// lvgl_f746ng_init(); // Initialize the LittlevGL
+//
+// while (1) {
+// thread_sleep_for(100);
+// }
+//}
+//
--- 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 */
+}
+
--- a/lvgl_f746ng.h Tue Sep 08 05:23:58 2020 +0000
+++ b/lvgl_f746ng.h Thu Sep 10 09:24:23 2020 +0000
@@ -1,39 +1,15 @@
-/**
- * @file lvgl_f746ng.h
- *
- */
-#ifndef LVGL_F746NG_H
-#define LVGL_F746NG_H
-
-// #ifdef __cplusplus
-// extern "C" {
-// #endif
-
-/*********************
- * INCLUDES
- *********************/
+#include "lv_port_disp.h"
+#include "lv_port_indev.h"
+#include "lvgl/lvgl.h"
#include "mbed.h"
+#include <cstdio>
-/*********************
- * DEFINES
- *********************/
-
-/**********************
- * TYPEDEFS
- **********************/
+/* Use Thread or not (comment or not) */
+#define LVGL_USE_THREAD
+/* LvGL tick increment value */
+#define LVGL_TICK_INC 5
-/**********************
- * GLOBAL PROTOTYPES
- **********************/
-void lvgl_f746ng_init(void);
+/* Initialize lvgl + target port specifics + mbed ticker or thread. */
+void lvgl_f746ng_init();
-/**********************
- * MACROS
- **********************/
-
-// #ifdef __cplusplus
-// } /* extern "C" */
-// #endif
-
-#endif /*LVGL_F746NG_H*/