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
lvgl_f746ng.cpp@1:a23fffad1321, 2020-09-10 (annotated)
- Committer:
- elelthvd
- Date:
- Thu Sep 10 09:24:23 2020 +0000
- Revision:
- 1:a23fffad1321
- Parent:
- 0:cffa136e7f8f
Add usage for Mbed Thread
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
elelthvd | 0:cffa136e7f8f | 1 | |
elelthvd | 0:cffa136e7f8f | 2 | #include "lvgl_f746ng.h" |
elelthvd | 0:cffa136e7f8f | 3 | |
elelthvd | 1:a23fffad1321 | 4 | static void lv_ticker_func() { |
elelthvd | 1:a23fffad1321 | 5 | // Call lv_tick_inc(x) every x milliseconds in a Timer or Task (x should be |
elelthvd | 1:a23fffad1321 | 6 | // between 1 and 10). It is required for the internal timing of LittlevGL. |
elelthvd | 1:a23fffad1321 | 7 | lv_tick_inc(LVGL_TICK_INC); |
elelthvd | 1:a23fffad1321 | 8 | // Call lv_task_handler() periodically every few milliseconds. |
elelthvd | 1:a23fffad1321 | 9 | // It will redraw the screen if required, handle input devices etc. |
elelthvd | 1:a23fffad1321 | 10 | lv_task_handler(); |
elelthvd | 0:cffa136e7f8f | 11 | } |
elelthvd | 0:cffa136e7f8f | 12 | |
elelthvd | 1:a23fffad1321 | 13 | #ifdef LVGL_USE_THREAD |
elelthvd | 1:a23fffad1321 | 14 | static Thread lvgl_thread; // mbed Thread for lvgl |
elelthvd | 1:a23fffad1321 | 15 | static void lv_thread_func() { |
elelthvd | 1:a23fffad1321 | 16 | printf("lv_thread_func from context %p\n", ThisThread::get_id()); |
elelthvd | 1:a23fffad1321 | 17 | while (1) { |
elelthvd | 1:a23fffad1321 | 18 | ThisThread::sleep_for(LVGL_TICK_INC * 1ms); |
elelthvd | 1:a23fffad1321 | 19 | lv_ticker_func(); |
elelthvd | 1:a23fffad1321 | 20 | } |
elelthvd | 0:cffa136e7f8f | 21 | } |
elelthvd | 1:a23fffad1321 | 22 | #else |
elelthvd | 1:a23fffad1321 | 23 | static Ticker lvgl_ticker; // mbed Ticker for lvgl |
elelthvd | 1:a23fffad1321 | 24 | #endif /* LVGL_USE_THREAD */ |
elelthvd | 1:a23fffad1321 | 25 | |
elelthvd | 1:a23fffad1321 | 26 | /* Initialize lvgl + target port specifics + mbed ticker or thread. */ |
elelthvd | 1:a23fffad1321 | 27 | void lvgl_f746ng_init() { |
elelthvd | 1:a23fffad1321 | 28 | printf("lvgl_f746ng_init from context %p\n", ThisThread::get_id()); |
elelthvd | 1:a23fffad1321 | 29 | lv_init(); // Initialize the LittlevGL |
elelthvd | 1:a23fffad1321 | 30 | lv_port_disp_init(); // Initialize diplay |
elelthvd | 1:a23fffad1321 | 31 | lv_port_indev_init(); // Initialize touchpad |
elelthvd | 1:a23fffad1321 | 32 | #ifdef LVGL_USE_THREAD |
elelthvd | 1:a23fffad1321 | 33 | // Approach using mbed Thread |
elelthvd | 1:a23fffad1321 | 34 | lvgl_thread.start(lv_thread_func); |
elelthvd | 1:a23fffad1321 | 35 | // lvgl_thread.join(); // it will never join |
elelthvd | 1:a23fffad1321 | 36 | #else |
elelthvd | 1:a23fffad1321 | 37 | // Approach using mbed Ticker |
elelthvd | 1:a23fffad1321 | 38 | lvgl_ticker.attach(callback(&lv_ticker_func), LVGL_TICK_INC * 1ms); |
elelthvd | 1:a23fffad1321 | 39 | #endif /* LVGL_USE_THREAD */ |
elelthvd | 1:a23fffad1321 | 40 | } |
elelthvd | 1:a23fffad1321 | 41 |