Example of using the LVGL (8.3.4) with the MbedOS (6.16 - bare metal) on the Disco-F746NG board
Dependencies: BSP_DISCO_F746NG
main.cpp
00001 /** 00002 * Notebook page https://os.mbed.com/users/JohnnyK/notebook/how-start-with-the-LVGL/ 00003 */ 00004 00005 #include "mbed.h" 00006 #include "lvgl.h" 00007 #include "demos/lv_demos.h" /*Comment/uncomment will switch between LVGL demos and Hello word example*/ 00008 #include "hal_stm_lvgl/tft/tft.h " 00009 #include "hal_stm_lvgl/touchpad/touchpad.h" 00010 00011 #define LVGL_TICK 10 //Time tick value for lvgl in ms (1-10msa) 00012 #define TICKER_TIME 10ms //modified to miliseconds 00013 00014 Ticker ticker; //Ticker for lvgl 00015 00016 /* 00017 * Callback function for lvgl timing. 00018 * Call lv_tick_inc(x) every x milliseconds in a Timer or Task (x should be between 1 and 10). 00019 * It is required for the internal timing of LittlevGL. 00020 */ 00021 void lv_ticker_func(){ 00022 lv_tick_inc(LVGL_TICK); 00023 } 00024 00025 #ifndef LV_DEMOS_H 00026 static void event_handler(lv_event_t* event) 00027 { 00028 lv_event_code_t code = lv_event_get_code(event); 00029 if(code == LV_EVENT_CLICKED) { 00030 printf("Clicked\n"); 00031 } 00032 else if(code == LV_EVENT_VALUE_CHANGED) { 00033 printf("Toggled\n"); 00034 } 00035 } 00036 #endif 00037 // main() runs in its own thread in the OS 00038 int main() 00039 { 00040 printf("LVGL-"); 00041 lv_init(); //Initialize the LVGL 00042 tft_init(); //Initialize diplay 00043 touchpad_init(); //Initialize touchpad 00044 ticker.attach(callback(&lv_ticker_func),TICKER_TIME); //Attach callback to ticker 00045 00046 #ifdef LV_DEMOS_H 00047 printf("Demo\n"); 00048 lv_demo_widgets(); 00049 #else 00050 printf("Hello world\n"); 00051 lv_obj_t * label1 = lv_label_create(lv_scr_act()); 00052 lv_label_set_long_mode(label1, LV_LABEL_LONG_WRAP); /*Break the long lines*/ 00053 lv_label_set_recolor(label1, true); /*Enable re-coloring by commands in the text*/ 00054 lv_label_set_text(label1, "#0000ff Hello# #ff00ff world# #ff0000 - the LVGL and MbedOS#"); 00055 lv_obj_set_width(label1, 150); 00056 lv_obj_align(label1, LV_ALIGN_TOP_MID, 0, 20); 00057 00058 lv_obj_t * label2 = lv_label_create(lv_scr_act()); 00059 lv_label_set_long_mode(label2, LV_LABEL_LONG_SCROLL_CIRCULAR); /*Circular scroll*/ 00060 lv_obj_set_width(label2, 150); 00061 lv_label_set_text(label2, "It is a circularly scrolling text. "); 00062 lv_obj_align(label2, LV_ALIGN_BOTTOM_MID, 0, 0); 00063 00064 lv_obj_t * label; 00065 lv_obj_t * btn1 = lv_btn_create(lv_scr_act()); 00066 lv_obj_add_event_cb(btn1, event_handler, LV_EVENT_ALL, NULL); 00067 lv_obj_align(btn1, LV_ALIGN_CENTER, 0, -25); 00068 label = lv_label_create(btn1); 00069 lv_label_set_text(label, "Button"); 00070 lv_obj_t * btn2 = lv_btn_create(lv_scr_act()); 00071 lv_obj_add_event_cb(btn2, event_handler,LV_EVENT_ALL, NULL); 00072 lv_obj_align(btn2, LV_ALIGN_CENTER, 0, 25); 00073 lv_obj_add_flag(btn2, LV_OBJ_FLAG_CHECKABLE); 00074 label = lv_label_create(btn2); 00075 lv_label_set_text(label, "Toggled"); 00076 #endif 00077 00078 while (true){ 00079 lv_task_handler(); 00080 //Call lv_task_handler() periodically every few milliseconds. 00081 //It will redraw the screen if required, handle input devices etc. 00082 thread_sleep_for(LVGL_TICK); 00083 } 00084 }
Generated on Sat Feb 4 2023 21:01:57 by 1.7.2