Example of using the LVGL (8.3.4) with the MbedOS (6.16 - bare metal) on the Disco-F746NG board

Dependencies:   BSP_DISCO_F746NG

Committer:
JohnnyK
Date:
Mon Dec 02 19:28:26 2019 +0000
Revision:
0:10c4b83c458d
Child:
1:627f26953c53
First

Who changed what in which revision?

UserRevisionLine numberNew contents of line
JohnnyK 0:10c4b83c458d 1 //#pragma -O0
JohnnyK 0:10c4b83c458d 2 #include "mbed.h"
JohnnyK 0:10c4b83c458d 3 #include "lvgl/lvgl.h"
JohnnyK 0:10c4b83c458d 4 #include "lv_port_disp.h"
JohnnyK 0:10c4b83c458d 5 #include "lv_port_indev.h"
JohnnyK 0:10c4b83c458d 6 #include "demo.h" //Comment/uncomment will switch between LittlevGL demo and Hello word example
JohnnyK 0:10c4b83c458d 7
JohnnyK 0:10c4b83c458d 8 #define LVGL_TICK 5 //Time tick value for lvgl in ms (1-10msa)
JohnnyK 0:10c4b83c458d 9 #define TICKER_TIME 0.001 * LVGL_TICK //modified to miliseconds
JohnnyK 0:10c4b83c458d 10 #define WAIT_TIME 1000 * LVGL_TICK //modified to microseconds
JohnnyK 0:10c4b83c458d 11
JohnnyK 0:10c4b83c458d 12 Ticker ticker; //Ticker for lvgl
JohnnyK 0:10c4b83c458d 13
JohnnyK 0:10c4b83c458d 14 //Callback function for lvgl timing.
JohnnyK 0:10c4b83c458d 15 void lv_ticker_func(){
JohnnyK 0:10c4b83c458d 16
JohnnyK 0:10c4b83c458d 17 lv_tick_inc(LVGL_TICK);
JohnnyK 0:10c4b83c458d 18 //Call lv_tick_inc(x) every x milliseconds in a Timer or Task (x should be between 1 and 10).
JohnnyK 0:10c4b83c458d 19 //It is required for the internal timing of LittlevGL.
JohnnyK 0:10c4b83c458d 20 lv_task_handler();
JohnnyK 0:10c4b83c458d 21 //Call lv_task_handler() periodically every few milliseconds.
JohnnyK 0:10c4b83c458d 22 //It will redraw the screen if required, handle input devices etc.
JohnnyK 0:10c4b83c458d 23 }
JohnnyK 0:10c4b83c458d 24
JohnnyK 0:10c4b83c458d 25 //lvgl button object event handler
JohnnyK 0:10c4b83c458d 26 void event_handler(lv_obj_t * obj, lv_event_t event){
JohnnyK 0:10c4b83c458d 27 if(event == LV_EVENT_CLICKED) {
JohnnyK 0:10c4b83c458d 28 printf("Clicked\n");
JohnnyK 0:10c4b83c458d 29 }
JohnnyK 0:10c4b83c458d 30 else if(event == LV_EVENT_VALUE_CHANGED) {
JohnnyK 0:10c4b83c458d 31 printf("Toggled\n");
JohnnyK 0:10c4b83c458d 32 }
JohnnyK 0:10c4b83c458d 33 }
JohnnyK 0:10c4b83c458d 34
JohnnyK 0:10c4b83c458d 35 int main()
JohnnyK 0:10c4b83c458d 36 {
JohnnyK 0:10c4b83c458d 37 printf("LittlevGL GUI-");
JohnnyK 0:10c4b83c458d 38 lv_init(); //Initialize the LittlevGL
JohnnyK 0:10c4b83c458d 39 lv_port_disp_init(); //Initialize diplay
JohnnyK 0:10c4b83c458d 40 lv_port_indev_init(); //Initialize touchpad
JohnnyK 0:10c4b83c458d 41 ticker.attach(callback(&lv_ticker_func),TICKER_TIME); //Attach callback to ticker
JohnnyK 0:10c4b83c458d 42
JohnnyK 0:10c4b83c458d 43 #ifndef DEMO_H
JohnnyK 0:10c4b83c458d 44 printf("Hello word\n");
JohnnyK 0:10c4b83c458d 45 lv_obj_t * label_h = lv_label_create(lv_scr_act(), NULL);
JohnnyK 0:10c4b83c458d 46 static lv_style_t st;
JohnnyK 0:10c4b83c458d 47 lv_style_copy( &st, &lv_style_plain );
JohnnyK 0:10c4b83c458d 48 st.text.font = &lv_font_roboto_28;
JohnnyK 0:10c4b83c458d 49 lv_obj_set_style( label_h, &st );
JohnnyK 0:10c4b83c458d 50 lv_obj_set_size(label_h, 50, 30);
JohnnyK 0:10c4b83c458d 51 lv_label_set_recolor(label_h, true);
JohnnyK 0:10c4b83c458d 52 lv_label_set_text(label_h, "#ff0000 Hello word#");
JohnnyK 0:10c4b83c458d 53 lv_obj_align(label_h, NULL, LV_ALIGN_IN_TOP_MID, 0, 0);
JohnnyK 0:10c4b83c458d 54
JohnnyK 0:10c4b83c458d 55 lv_obj_t * label;
JohnnyK 0:10c4b83c458d 56 lv_obj_t * btn1 = lv_btn_create(lv_scr_act(), NULL);
JohnnyK 0:10c4b83c458d 57 lv_obj_set_event_cb(btn1, event_handler);
JohnnyK 0:10c4b83c458d 58 lv_obj_align(btn1, NULL, LV_ALIGN_CENTER, 0, -40);
JohnnyK 0:10c4b83c458d 59 label = lv_label_create(btn1, NULL);
JohnnyK 0:10c4b83c458d 60 lv_label_set_text(label, "Button");
JohnnyK 0:10c4b83c458d 61 lv_obj_t *btn2 = lv_btn_create(lv_scr_act(), NULL);
JohnnyK 0:10c4b83c458d 62 lv_obj_set_event_cb(btn2, event_handler);
JohnnyK 0:10c4b83c458d 63 lv_obj_align(btn2, NULL, LV_ALIGN_CENTER, 0, 40);
JohnnyK 0:10c4b83c458d 64 lv_btn_set_toggle(btn2, true);
JohnnyK 0:10c4b83c458d 65 lv_btn_toggle(btn2);
JohnnyK 0:10c4b83c458d 66 lv_btn_set_fit2(btn2, LV_FIT_NONE, LV_FIT_TIGHT);
JohnnyK 0:10c4b83c458d 67 label = lv_label_create(btn2, NULL);
JohnnyK 0:10c4b83c458d 68 lv_label_set_text(label, "Toggled");
JohnnyK 0:10c4b83c458d 69 #else
JohnnyK 0:10c4b83c458d 70 printf("Demo\n");
JohnnyK 0:10c4b83c458d 71 demo_create(); // Demo from lv_examples
JohnnyK 0:10c4b83c458d 72 #endif
JohnnyK 0:10c4b83c458d 73
JohnnyK 0:10c4b83c458d 74 while(1) {
JohnnyK 0:10c4b83c458d 75 //something
JohnnyK 0:10c4b83c458d 76 //wait_us(WAIT_TIME);
JohnnyK 0:10c4b83c458d 77 }
JohnnyK 0:10c4b83c458d 78 }