#define LV_TICK_CUSTOM 1 #if LV_TICK_CUSTOM #define LV_TICK_CUSTOM_INCLUDE "Arduino.h"/*Header for the system time function*/ #define LV_TICK_CUSTOM_SYS_TIME_EXPR (millis()) /*Expression evaluating to current system time in ms*/ #endif/*LV_TICK_CUSTOM*/
stm32使用硬件timer
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
HardwareTimer *MyTim; /*Initialize the graphics library's tick*/ MyTim = new HardwareTimer(TIM2); MyTim->setMode(2, TIMER_OUTPUT_COMPARE); // In our case, channekFalling is configured but not really used. Nevertheless it would be possible to attach a callback to channel compare match. MyTim->setOverflow(1000/LVGL_TICK_PERIOD, HERTZ_FORMAT); // period in Hz MyTim->attachInterrupt(lv_tick_handler); MyTim->resume();
#if !LV_TICK_CUSTOM /** * You have to call this function periodically * @param tick_period the call period of this function in milliseconds */ LV_ATTRIBUTE_TICK_INC voidlv_tick_inc(uint32_t tick_period) { tick_irq_flag = 0; sys_time += tick_period; } #endif
/*Save the state and save the pressed coordinate*/ data->state = ts.touched() ? LV_INDEV_STATE_PR : LV_INDEV_STATE_REL; if(data->state == LV_INDEV_STATE_PR){ TS_Point p = ts.getPoint(); //convert to lcd position last_x = LV_HOR_RES-(p.x *LV_HOR_RES)/4095; /*TODO save the current X coordinate*/ last_y = LV_VER_RES-(p.y *LV_VER_RES)/4095; /*TODO save the current Y coordinate*/ Serial.print("touched:"); Serial.print(last_x);Serial.print(",");Serial.println(last_y); }
/*Set the coordinates (if released use the last pressed coordinates)*/ data->point.x = last_x; data->point.y = last_y;
returnfalse; /*Return `false` because we are not buffering and no more data to read*/ }
/* Add the mouse 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_t * mouse_indev = lv_indev_drv_register(&indev_drv);
3 初始化节拍
arduino 自动完成此步骤
模拟器
1 2 3 4
/* Tick init. * You have to call 'lv_tick_inc()' in periodically to inform LittelvGL about how much time were elapsed * Create an SDL thread to do this*/ SDL_CreateThread(tick_thread, "tick", NULL);
stm32
1 2 3 4 5 6
/*Initialize the graphics library's tick*/ MyTim = new HardwareTimer(TIM2); MyTim->setMode(2, TIMER_OUTPUT_COMPARE); // In our case, channekFalling is configured but not really used. Nevertheless it would be possible to attach a callback to channel compare match. MyTim->setOverflow(1000/LVGL_TICK_PERIOD, HERTZ_FORMAT); // period in Hz MyTim->attachInterrupt(lv_tick_handler); MyTim->resume();
lv_obj_t * btn = lv_btn_create(lv_scr_act()); /*Add a button the current screen*/ lv_obj_set_pos(btn, 50, 50); /*Set its position*/ lv_obj_set_size(btn, 120, 50); /*Set its size*/ lv_obj_add_event_cb(btn, btn_event_cb, LV_EVENT_ALL, NULL); /*Assign a callback to the button*/