GUI
Dependencies: BSP_DISCO_F746NG
main.cpp
- Committer:
- inistol
- Date:
- 2020-01-13
- Revision:
- 0:78fce1e0dede
File content as of revision 0:78fce1e0dede:
#include "mbed.h" #include "lvgl/lvgl.h" #include "stm32f7xx.h" #include "stm32746g_discovery.h" #include "stm32746g_discovery_lcd.h" #include "stm32746g_discovery_ts.h" #include "demo.h" #include "lv_tutorial_hello_world.h" #include "lv_tutorial_animations.h" #include "lv_tutorial_responsive.h" #include "lv_test_theme_1.h" #define LVGL_TICK 5 //Time tick value for lvgl in ms (1-10msa) #define TICKER_TIME 0.001 * LVGL_TICK //modified to miliseconds Ticker ticker; //Initialize your system tick TS_StateTypeDef TS_State; void lv_ticker_func(); void display_init(void); void touchpad_init(void); static void my_disp_flush_cb(lv_disp_drv_t* disp_drv, const lv_area_t* area, lv_color_t* color_p); static bool touchpad_read(lv_indev_drv_t *indev, lv_indev_data_t *data); int main() { printf("LittlevGL DEMO"); display_init(); touchpad_init(); ticker.attach(callback(&lv_ticker_func),TICKER_TIME); // // while(1); } void lv_ticker_func(){ lv_tick_inc(LVGL_TICK); //Call lv_tick_inc(x) every x milliseconds in a Timer or Task (x should be between 1 and 10). //It is required for the internal timing of LittlevGL. lv_task_handler(); //Call lv_task_handler() periodically every few milliseconds. //It will redraw the screen if required, handle input devices etc. } void display_init(void){ //Init the touch screen display via the BSP driver. Based on ST's example. BSP_LCD_Init(); BSP_LCD_LayerDefaultInit(0, LCD_FB_START_ADDRESS); BSP_LCD_DisplayOn(); BSP_LCD_SelectLayer(0); BSP_LCD_Clear(LCD_COLOR_TRANSPARENT ); BSP_LCD_SetFont(&LCD_DEFAULT_FONT); BSP_LCD_SetBackColor(LCD_COLOR_WHITE); BSP_LCD_SetTextColor(LCD_COLOR_DARKBLUE); lv_init(); //Initialize the LittlevGL static lv_disp_buf_t disp_buf; static lv_color_t buf[LV_HOR_RES_MAX * 10]; //Declare a buffer for 10 lines lv_disp_buf_init(&disp_buf, buf, NULL, LV_HOR_RES_MAX * 10); //Initialize the display buffer //Implement and register a function which can copy a pixel array to an area of your display lv_disp_drv_t disp_drv; //Descriptor of a display driver lv_disp_drv_init(&disp_drv); //Basic initialization disp_drv.flush_cb = my_disp_flush_cb; //Set your driver function disp_drv.buffer = &disp_buf; //Assign the buffer to the display lv_disp_drv_register(&disp_drv); //Finally register the driver } void my_disp_flush_cb(lv_disp_drv_t* disp_drv, const lv_area_t* area, lv_color_t* color_p) { //The most simple case (but also the slowest) to put all pixels to the screen one-by-one uint16_t x, y; for(y = area->y1; y <= area->y2; y++) { for(x = area->x1; x <= area->x2; x++) { //put_px(x, y, *color_p) BSP_LCD_DrawPixel( x, y, color_p->full); color_p++; } } //IMPORTANT!!!* Inform the graphics library that you are ready with the flushing lv_disp_flush_ready(disp_drv); } void touchpad_init(void){ BSP_TS_Init(480, 272); lv_indev_drv_t indev_drv; //Descriptor of an input device driver lv_indev_drv_init(&indev_drv); //Basic initialization indev_drv.type = LV_INDEV_TYPE_POINTER; //The touchpad is pointer type device indev_drv.read_cb = touchpad_read; //Set the touchpad_read function lv_indev_drv_register(&indev_drv); //Register touch driver in LvGL } static bool touchpad_read(lv_indev_drv_t *indev, lv_indev_data_t *data){ // Read your touchpad static int16_t last_x = 0; static int16_t last_y = 0; BSP_TS_GetState(&TS_State); if(TS_State.touchDetected) { data->point.x = TS_State.touchX[0]; data->point.y = TS_State.touchY[0]; last_x = data->point.x; last_y = data->point.y; data->state = LV_INDEV_STATE_PR; } else { data->point.x = last_x; data->point.y = last_y; data->state = LV_INDEV_STATE_REL; } return false; //false: no more data to read because we are no buffering }