/** * @file main * */ /********************* * INCLUDES *********************/ #include #include #include #include #include "lvgl/lvgl.h" #include "lv_drivers/display/monitor.h" #include "lv_drivers/indev/mouse.h" #include "lv_drivers/indev/keyboard.h" #include "lv_examples/lv_examples.h" // #include "../../../lv_examples.h" /********************* * DEFINES *********************/ /********************** * TYPEDEFS **********************/ /********************** * STATIC PROTOTYPES **********************/ static void hal_init(void); static int tick_thread(void *data); /********************** * STATIC VARIABLES **********************/ static lv_indev_t * kb_indev; #define MCU_PGMR_SIMM 1 /********************** * MACROS **********************/ /********************** * GLOBAL FUNCTIONS **********************/ #if MCU_PGMR_SIMM lv_obj_t* bar; lv_obj_t* child; lv_obj_t* pgm_step; lv_obj_t* parents; lv_obj_t* label_device; lv_obj_t* label_hexfile_name; //lv_obj_t* label_ok; //lv_obj_t* label_ng; lv_obj_t* cont_led_red; lv_obj_t* cont_led_green; lv_obj_t* led_red; lv_obj_t* led_green; static child_window_clear(void); static void child_window_create(lv_obj_t* p); bool child_created; #endif extern const LV_ATTRIBUTE_MEM_ALIGN LV_ATTRIBUTE_LARGE_CONST uint8_t bmp_logo_map[]; const lv_img_dsc_t bmp_logo = { .header.always_zero = 0, .header.w = 240, .header.h = 50, .data_size = 12000 * LV_COLOR_SIZE / 8, .header.cf = LV_IMG_CF_TRUE_COLOR, .data = bmp_logo_map, }; lv_obj_t* logo_image; int main(int argc, char** argv) { /*Initialize LittlevGL*/ lv_init(); /*Initialize the HAL for LittlevGL*/ hal_init(); /* * Demos, benchmarks, and tests. * * Uncomment any one (and only one) of the functions below to run that * item. */ // lv_demo_widgets(); //lv_demo_benchmark(); // lv_demo_keypad_encoder(); //lv_demo_printer(); //lv_demo_stress(); //lv_ex_get_started_1(); //lv_ex_get_started_2(); // lv_ex_get_started_3(); // lv_ex_style_1(); // lv_ex_style_2(); // lv_ex_style_3(); // lv_ex_style_4(); // lv_ex_style_5(); // Pattern // lv_ex_style_6(); // lv_ex_style_7(); // ÅؽºÆ® ½ºÅ¸ÀÏ // lv_ex_style_8(); // ¶óÀÎ ½ºÅ¸ÀÏ // lv_ex_style_9(); // À̹ÌÁö ½ºÅ¸ÀÏ // lv_ex_style_10(); // º¯È¯ ½Ã°£, µô·¹ÀÌ ±âŸ ½ºÅ¸ÀÏ // lv_ex_style_11(); // °ÔÀÌÁö ½ºÅ¸ÀÏ // lv_ex_arc_1(); // lv_ex_arc_2(); // lv_ex_bar_1(); // lv_ex_btn_1(); // lv_ex_btn_2(); // ½ºÅ¸ÀÏ ¹öÆ° // lv_ex_btnmatrix_1(); // lv_ex_calendar_1(); // lv_ex_canvas_1(); // lv_ex_canvas_2(); // lv_ex_checkbox_1(); // lv_ex_chart_1(); // lv_ex_chart_2(); // lv_ex_cont_1(); // lv_ex_cpicker_1(); // lv_ex_cpicker_2(); // lv_ex_dropdown_1(); // lv_ex_dropdown_2(); // lv_ex_gauge_1(); // lv_ex_img_1(); // lv_ex_img_2(); // lv_ex_img_3(); // lv_ex_imgbtn_1(); // lv_ex_keyboard_1(); // lv_ex_label_1(); // lv_ex_label_2(); // lv_ex_label_3(); // lv_ex_led_1(); // lv_ex_line_1(); // lv_ex_list_1(); // lv_ex_linemeter_1(); // lv_ex_msgbox_1(); // lv_ex_msgbox_2(); // lv_ex_obj_1(); // lv_ex_page_1(); // lv_ex_spinner_1(); // lv_ex_roller_1(); // lv_ex_slider_1(); // lv_ex_slider_2(); // lv_ex_spinbox_1(); // lv_ex_switch_1(); // lv_ex_textarea_1(); // lv_ex_textarea_2(); // lv_ex_textarea_3(); // lv_ex_objmask_1(); // lv_ex_objmask_2(); // lv_ex_table_1(); // lv_ex_tabview_1(); // lv_ex_tileview_1(); // lv_ex_win_1(); /* * There are many examples of individual widgets found under the * lv_examples/src/lv_ex_widgets directory. Here are a few sample test * functions. Look in that directory to find all the rest. */ // lv_ex_arc_1(); // lv_ex_cpicker_1(); // lv_ex_gauge_1(); // lv_ex_img_1(); // lv_ex_tileview_1(); uint32_t img_display_time = 80; uint32_t progress = 0; bool dir = false; char char_buff[32]; char char_buff2[32]; static uint32_t rep_cnt = 0; static uint32_t restart_cnt = 0; static uint32_t led_cnt = 0; static uint32_t ok_cnt = 99900; static uint32_t ng_cnt = 8888; child_created = true; logo_image = lv_img_create(lv_scr_act(), NULL); lv_img_set_src(logo_image, &bmp_logo); lv_obj_align(logo_image, lv_scr_act(), LV_ALIGN_CENTER, 0, 0); while (1) { lv_task_handler(); Sleep(15); if (--img_display_time == 0) break; } lv_obj_clean(lv_scr_act()); #if MCU_PGMR_SIMM LV_THEME_DEFAULT_INIT(lv_theme_get_color_primary(), lv_theme_get_color_secondary(), LV_THEME_MATERIAL_FLAG_DARK, lv_theme_get_font_small(), lv_theme_get_font_small(), lv_theme_get_font_normal(), lv_theme_get_font_normal()); parents = lv_obj_create(lv_scr_act(), NULL); lv_obj_set_size(parents, LV_HOR_RES_MAX-6, LV_VER_RES_MAX-6); lv_obj_align(parents, lv_scr_act(), LV_ALIGN_CENTER, 0, 0); label_device = lv_label_create(parents, NULL); label_hexfile_name = lv_label_create(parents, NULL); cont_led_red = lv_cont_create(parents, NULL); lv_obj_set_size(cont_led_red, 100, 32); cont_led_green = lv_cont_create(parents, NULL); lv_obj_set_size(cont_led_green, 100, 32); lv_obj_align(cont_led_green, parents, LV_ALIGN_CENTER, -58, +38); lv_obj_align(cont_led_red, parents, LV_ALIGN_CENTER, +58, +38); led_red = lv_led_create(cont_led_red, NULL); lv_obj_set_style_local_bg_color(led_red, LV_LED_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_RED); lv_obj_set_style_local_border_color(led_red, LV_LED_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_WHITE); lv_obj_set_style_local_shadow_color(led_red, LV_LED_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_RED); lv_obj_set_style_local_bg_grad_color(led_red, LV_LED_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_RED); lv_obj_set_style_local_value_font(led_red, LV_LED_PART_MAIN, LV_STATE_DEFAULT, lv_theme_get_font_small()); lv_obj_set_style_local_value_align(led_red, LV_LED_PART_MAIN, LV_STATE_DEFAULT, LV_ALIGN_OUT_RIGHT_MID); lv_obj_set_style_local_value_ofs_x(led_red, LV_LED_PART_MAIN, LV_STATE_DEFAULT, 8 /*LV_DPI / 20*/); lv_obj_set_style_local_value_color(led_red, LV_LED_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_WHITE); lv_obj_set_size(led_red, 12, 12); lv_obj_align(led_red, cont_led_red, LV_ALIGN_IN_BOTTOM_LEFT, +10, -10); lv_led_set_bright(led_red, 50); sprintf(char_buff, "NG : %d", 0); lv_obj_set_style_local_value_str(led_red, LV_LED_PART_MAIN, LV_STATE_DEFAULT, char_buff); led_green = lv_led_create(cont_led_green, NULL); lv_obj_set_style_local_bg_color(led_green, LV_LED_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_CYAN); lv_obj_set_style_local_border_color(led_green, LV_LED_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_WHITE); lv_obj_set_style_local_shadow_color(led_green, LV_LED_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_CYAN); lv_obj_set_style_local_bg_grad_color(led_green, LV_LED_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_CYAN); lv_obj_set_style_local_value_font(led_green, LV_LED_PART_MAIN, LV_STATE_DEFAULT, lv_theme_get_font_small()); lv_obj_set_style_local_value_align(led_green, LV_LED_PART_MAIN, LV_STATE_DEFAULT, LV_ALIGN_OUT_RIGHT_MID); lv_obj_set_style_local_value_ofs_x(led_green, LV_LED_PART_MAIN, LV_STATE_DEFAULT, 8 /*LV_DPI / 20*/); lv_obj_set_style_local_value_color(led_green, LV_LED_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_WHITE); lv_obj_set_size(led_green, 12, 12); lv_obj_align(led_green, cont_led_green, LV_ALIGN_IN_BOTTOM_LEFT, +10, -10); lv_led_set_bright(led_green, 50); sprintf(char_buff, "OK : %d", 0); lv_obj_set_style_local_value_str(led_green, LV_LED_PART_MAIN, LV_STATE_DEFAULT, char_buff); lv_label_set_text(label_device, "STM32F103RBT6"); lv_obj_set_width(label_device, 200); lv_obj_align(label_device, parents, LV_ALIGN_IN_TOP_MID, 0, +10); lv_label_set_text(label_hexfile_name, "test_pgm_very_long_file_name_122345.hex"); lv_label_set_long_mode(label_hexfile_name, LV_LABEL_LONG_SROLL_CIRC); /*Circular scroll*/ lv_obj_set_width(label_hexfile_name, 200); lv_obj_align(label_hexfile_name, parents, LV_ALIGN_CENTER, 0, -32); lv_obj_set_width(label_hexfile_name, 200); #if 0 lv_label_set_text_fmt(label_ok, "OK : %d", 0); lv_obj_align(label_ok, cont_led_green, LV_ALIGN_IN_BOTTOM_RIGHT, -10, -8); lv_label_set_text_fmt(label_ng, "NG : %d", 0); lv_obj_align(label_ng, cont_led_red, LV_ALIGN_IN_BOTTOM_RIGHT, -10, -8); #elif 0 lv_label_set_text_fmt(label_ok, "OK : %d", 0); lv_obj_align(label_ok, cont_led_green, LV_ALIGN_IN_RIGHT_MID, -10, 0); lv_label_set_text_fmt(label_ng, "NG : %d", 0); lv_obj_align(label_ng, cont_led_red, LV_ALIGN_IN_RIGHT_MID, -10, 0); #endif child_window_create(parents); #endif while (1) { /* Periodically call the lv_task handler. * It could be done in a timer interrupt or an OS task too. */ lv_task_handler(); Sleep(15); /*Just to let the system breathe */ #if MCU_PGMR_SIMM if (rep_cnt < 3) { // lv_label_set_text_fmt(progress_text, "%d", progress); memset(char_buff, 0, 32); sprintf(char_buff, "%d/100", progress); lv_obj_set_style_local_value_str(bar, LV_BAR_PART_BG, LV_STATE_DEFAULT, char_buff); lv_bar_set_value(bar, progress, LV_ANIM_OFF); if (progress < 100) progress++; else { progress = 0; if (rep_cnt == 0) { lv_label_set_text(pgm_step, "EEPROM programming"); lv_obj_align(pgm_step, child, LV_ALIGN_CENTER, 0, -22); } else if (rep_cnt == 1) { lv_label_set_text(pgm_step, "OPTION programming"); lv_obj_align(pgm_step, child, LV_ALIGN_CENTER, 0, -22); } else if (rep_cnt == 2) { child_created = true; if (++led_cnt & 1) { ok_cnt++; ok_cnt = ok_cnt % 100000; lv_led_set_bright(led_red, 50); lv_led_set_bright(led_green, 255); memset(char_buff, 0, 32); sprintf(char_buff, "OK : %d", ok_cnt); lv_obj_set_style_local_value_str(led_green, LV_LED_PART_MAIN, LV_STATE_DEFAULT, char_buff); // lv_label_set_text_fmt(label_ok, "OK : %d", ok_cnt); // lv_obj_align(label_ok, cont_led_green, LV_ALIGN_IN_BOTTOM_RIGHT, -10, -8); } else { ng_cnt++; lv_led_set_bright(led_red, 255); lv_led_set_bright(led_green, 50); memset(char_buff, 0, 32); sprintf(char_buff, "NG : %d", ng_cnt); lv_obj_set_style_local_value_str(led_red, LV_LED_PART_MAIN, LV_STATE_DEFAULT, char_buff); // lv_label_set_text_fmt(label_ng, "NG : %d", ng_cnt); // lv_obj_align(label_ng, cont_led_red, LV_ALIGN_IN_BOTTOM_RIGHT, -10, -8); } } ++rep_cnt; } } else { if (child_created == true) { if (restart_cnt == 0) { child_window_clear(); } if (++restart_cnt > 200) { child_window_create(parents); rep_cnt = 0; restart_cnt = 0; child_created = false; } else { } } } } #endif return 0; } #if MCU_PGMR_SIMM static child_window_clear(void) { lv_obj_clean(child); lv_obj_del(child); } static void child_window_create(lv_obj_t* p) { /** child window create */ child = lv_obj_create(p, NULL); lv_obj_set_size(child, 206, LV_VER_RES_MAX / 2 + 10); lv_obj_align(child, p, LV_ALIGN_CENTER, 0, 0); /** bar create */ bar = lv_bar_create(child, NULL); /** bar_h ÄÁÅ×À̳ʰ¡ ºÎ¸ð°´Ã¼·Î bar»ý¼º */ lv_obj_set_style_local_value_font(bar, LV_BAR_PART_BG, LV_STATE_DEFAULT, lv_theme_get_font_small()); lv_obj_set_style_local_value_align(bar, LV_BAR_PART_BG, LV_STATE_DEFAULT, LV_ALIGN_OUT_BOTTOM_MID); lv_obj_set_style_local_value_ofs_y(bar, LV_BAR_PART_BG, LV_STATE_DEFAULT, 4 /*LV_DPI / 20*/); // 130/20 = 6 lv_obj_set_style_local_margin_bottom(bar, LV_BAR_PART_BG, LV_STATE_DEFAULT, LV_DPI / 7); // 130/7 = 18 // lv_obj_set_style_local_bg_color(bar, LV_BAR_PART_BG, LV_STATE_DEFAULT, LV_COLOR_BLACK); lv_obj_set_style_local_shadow_color(bar, LV_BAR_PART_INDIC, LV_STATE_DEFAULT, LV_COLOR_CYAN); lv_obj_set_style_local_bg_grad_color(bar, LV_BAR_PART_INDIC, LV_STATE_DEFAULT, LV_COLOR_CYAN); // lv_obj_set_style_local_border_color(bar, LV_BAR_PART_INDIC, LV_STATE_DEFAULT, LV_COLOR_RED); lv_bar_set_range(bar, 0, 100); lv_obj_set_size(bar, 180, 15); // x_size, y_size lv_obj_align(bar, child, LV_ALIGN_CENTER, 0, 0); /** label create */ pgm_step = lv_label_create(child, NULL); lv_label_set_text(pgm_step, "Flash programming"); lv_obj_align(pgm_step, child, LV_ALIGN_CENTER, 0, -22); } #endif /********************** * STATIC FUNCTIONS **********************/ /** * Initialize the Hardware Abstraction Layer (HAL) for the Littlev graphics library */ static void hal_init(void) { /* Add a display * Use the 'monitor' driver which creates window on PC's monitor to simulate a display*/ monitor_init(); static lv_disp_buf_t disp_buf1; static lv_color_t buf1_1[LV_HOR_RES_MAX * 120]; lv_disp_buf_init(&disp_buf1, buf1_1, NULL, LV_HOR_RES_MAX * 120); lv_disp_drv_t disp_drv; lv_disp_drv_init(&disp_drv); /*Basic initialization*/ disp_drv.buffer = &disp_buf1; disp_drv.flush_cb = monitor_flush; lv_disp_drv_register(&disp_drv); /* Add the mouse (or touchpad) as input device * Use the 'mouse' driver which reads the PC's mouse*/ mouse_init(); lv_indev_drv_t indev_drv; lv_indev_drv_init(&indev_drv); /*Basic initialization*/ indev_drv.type = LV_INDEV_TYPE_POINTER; indev_drv.read_cb = mouse_read; /*This function will be called periodically (by the library) to get the mouse position and state*/ lv_indev_drv_register(&indev_drv); /* If the PC keyboard driver is enabled in`lv_drv_conf.h` * add this as an input device. It might be used in some examples. */ #if USE_KEYBOARD lv_indev_drv_t kb_drv; lv_indev_drv_init(&kb_drv); kb_drv.type = LV_INDEV_TYPE_KEYPAD; kb_drv.read_cb = keyboard_read; kb_indev = lv_indev_drv_register(&kb_drv); #endif /* Tick init. * You have to call 'lv_tick_inc()' in every milliseconds * Create an SDL thread to do this */ SDL_CreateThread(tick_thread, "tick", NULL); } /** * A task to measure the elapsed time for LittlevGL * @param data unused * @return never return */ static int tick_thread(void *data) { while (1) { lv_tick_inc(5); SDL_Delay(5); /*Sleep for 1 millisecond*/ } return 0; }