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@0:cffa136e7f8f, 2020-09-08 (annotated)
- Committer:
- elelthvd
- Date:
- Tue Sep 08 05:23:58 2020 +0000
- Revision:
- 0:cffa136e7f8f
- Child:
- 1:a23fffad1321
Initial commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
elelthvd | 0:cffa136e7f8f | 1 | /** |
elelthvd | 0:cffa136e7f8f | 2 | * @file lvgl_f746ng.cpp |
elelthvd | 0:cffa136e7f8f | 3 | * |
elelthvd | 0:cffa136e7f8f | 4 | */ |
elelthvd | 0:cffa136e7f8f | 5 | |
elelthvd | 0:cffa136e7f8f | 6 | /********************* |
elelthvd | 0:cffa136e7f8f | 7 | * INCLUDES |
elelthvd | 0:cffa136e7f8f | 8 | *********************/ |
elelthvd | 0:cffa136e7f8f | 9 | #include "mbed.h" |
elelthvd | 0:cffa136e7f8f | 10 | #include "lvgl_f746ng.h" |
elelthvd | 0:cffa136e7f8f | 11 | #include <cstdio> |
elelthvd | 0:cffa136e7f8f | 12 | #include "../lvgl/lvgl.h" |
elelthvd | 0:cffa136e7f8f | 13 | #include "lv_port_disp.h" |
elelthvd | 0:cffa136e7f8f | 14 | #include "lv_port_indev.h" |
elelthvd | 0:cffa136e7f8f | 15 | |
elelthvd | 0:cffa136e7f8f | 16 | /********************* |
elelthvd | 0:cffa136e7f8f | 17 | * DEFINES |
elelthvd | 0:cffa136e7f8f | 18 | *********************/ |
elelthvd | 0:cffa136e7f8f | 19 | |
elelthvd | 0:cffa136e7f8f | 20 | /********************** |
elelthvd | 0:cffa136e7f8f | 21 | * TYPEDEFS |
elelthvd | 0:cffa136e7f8f | 22 | **********************/ |
elelthvd | 0:cffa136e7f8f | 23 | |
elelthvd | 0:cffa136e7f8f | 24 | /********************** |
elelthvd | 0:cffa136e7f8f | 25 | * STATIC PROTOTYPES |
elelthvd | 0:cffa136e7f8f | 26 | **********************/ |
elelthvd | 0:cffa136e7f8f | 27 | void lv_ticker_func(void); |
elelthvd | 0:cffa136e7f8f | 28 | |
elelthvd | 0:cffa136e7f8f | 29 | /********************** |
elelthvd | 0:cffa136e7f8f | 30 | * STATIC VARIABLES |
elelthvd | 0:cffa136e7f8f | 31 | **********************/ |
elelthvd | 0:cffa136e7f8f | 32 | Ticker lvgl_ticker; // mbed Ticker for lvgl |
elelthvd | 0:cffa136e7f8f | 33 | |
elelthvd | 0:cffa136e7f8f | 34 | /********************** |
elelthvd | 0:cffa136e7f8f | 35 | * MACROS |
elelthvd | 0:cffa136e7f8f | 36 | **********************/ |
elelthvd | 0:cffa136e7f8f | 37 | |
elelthvd | 0:cffa136e7f8f | 38 | /********************** |
elelthvd | 0:cffa136e7f8f | 39 | * GLOBAL FUNCTIONS |
elelthvd | 0:cffa136e7f8f | 40 | **********************/ |
elelthvd | 0:cffa136e7f8f | 41 | |
elelthvd | 0:cffa136e7f8f | 42 | /* Initialize lvgl + target port specifics + mbed ticker. */ |
elelthvd | 0:cffa136e7f8f | 43 | void lvgl_f746ng_init() |
elelthvd | 0:cffa136e7f8f | 44 | { |
elelthvd | 0:cffa136e7f8f | 45 | debug("lvgl_f746ng_init\r\n"); |
elelthvd | 0:cffa136e7f8f | 46 | lv_init(); //Initialize the LittlevGL |
elelthvd | 0:cffa136e7f8f | 47 | lv_port_disp_init(); //Initialize diplay |
elelthvd | 0:cffa136e7f8f | 48 | lv_port_indev_init(); //Initialize touchpad |
elelthvd | 0:cffa136e7f8f | 49 | lvgl_ticker.attach(callback(&lv_ticker_func), 10ms); //Attach callback to ticker |
elelthvd | 0:cffa136e7f8f | 50 | } |
elelthvd | 0:cffa136e7f8f | 51 | |
elelthvd | 0:cffa136e7f8f | 52 | /********************** |
elelthvd | 0:cffa136e7f8f | 53 | * STATIC FUNCTIONS |
elelthvd | 0:cffa136e7f8f | 54 | **********************/ |
elelthvd | 0:cffa136e7f8f | 55 | /* Callback function for lvgl timing. */ |
elelthvd | 0:cffa136e7f8f | 56 | void lv_ticker_func() |
elelthvd | 0:cffa136e7f8f | 57 | { |
elelthvd | 0:cffa136e7f8f | 58 | //Call lv_tick_inc(x) every x milliseconds in a Timer or Task (x should be between 1 and 10). |
elelthvd | 0:cffa136e7f8f | 59 | //It is required for the internal timing of LittlevGL. |
elelthvd | 0:cffa136e7f8f | 60 | lv_tick_inc(10); |
elelthvd | 0:cffa136e7f8f | 61 | //Call lv_task_handler() periodically every few milliseconds. |
elelthvd | 0:cffa136e7f8f | 62 | //It will redraw the screen if required, handle input devices etc. |
elelthvd | 0:cffa136e7f8f | 63 | lv_task_handler(); |
elelthvd | 0:cffa136e7f8f | 64 | } |