GUI

Dependencies:   BSP_DISCO_F746NG

Committer:
inistol
Date:
Mon Jan 13 15:13:51 2020 +0000
Revision:
0:78fce1e0dede
Test GUI

Who changed what in which revision?

UserRevisionLine numberNew contents of line
inistol 0:78fce1e0dede 1 #include "mbed.h"
inistol 0:78fce1e0dede 2 #include "lvgl/lvgl.h"
inistol 0:78fce1e0dede 3 #include "stm32f7xx.h"
inistol 0:78fce1e0dede 4 #include "stm32746g_discovery.h"
inistol 0:78fce1e0dede 5 #include "stm32746g_discovery_lcd.h"
inistol 0:78fce1e0dede 6 #include "stm32746g_discovery_ts.h"
inistol 0:78fce1e0dede 7 #include "demo.h"
inistol 0:78fce1e0dede 8 #include "lv_tutorial_hello_world.h"
inistol 0:78fce1e0dede 9 #include "lv_tutorial_animations.h"
inistol 0:78fce1e0dede 10 #include "lv_tutorial_responsive.h"
inistol 0:78fce1e0dede 11 #include "lv_test_theme_1.h"
inistol 0:78fce1e0dede 12
inistol 0:78fce1e0dede 13 #define LVGL_TICK 5 //Time tick value for lvgl in ms (1-10msa)
inistol 0:78fce1e0dede 14 #define TICKER_TIME 0.001 * LVGL_TICK //modified to miliseconds
inistol 0:78fce1e0dede 15
inistol 0:78fce1e0dede 16 Ticker ticker; //Initialize your system tick
inistol 0:78fce1e0dede 17 TS_StateTypeDef TS_State;
inistol 0:78fce1e0dede 18
inistol 0:78fce1e0dede 19 void lv_ticker_func();
inistol 0:78fce1e0dede 20 void display_init(void);
inistol 0:78fce1e0dede 21 void touchpad_init(void);
inistol 0:78fce1e0dede 22 static void my_disp_flush_cb(lv_disp_drv_t* disp_drv, const lv_area_t* area, lv_color_t* color_p);
inistol 0:78fce1e0dede 23 static bool touchpad_read(lv_indev_drv_t *indev, lv_indev_data_t *data);
inistol 0:78fce1e0dede 24
inistol 0:78fce1e0dede 25 int main()
inistol 0:78fce1e0dede 26 {
inistol 0:78fce1e0dede 27 printf("LittlevGL DEMO");
inistol 0:78fce1e0dede 28 display_init();
inistol 0:78fce1e0dede 29 touchpad_init();
inistol 0:78fce1e0dede 30 ticker.attach(callback(&lv_ticker_func),TICKER_TIME);
inistol 0:78fce1e0dede 31
inistol 0:78fce1e0dede 32 //
inistol 0:78fce1e0dede 33
inistol 0:78fce1e0dede 34 //
inistol 0:78fce1e0dede 35
inistol 0:78fce1e0dede 36 while(1);
inistol 0:78fce1e0dede 37 }
inistol 0:78fce1e0dede 38
inistol 0:78fce1e0dede 39 void lv_ticker_func(){
inistol 0:78fce1e0dede 40 lv_tick_inc(LVGL_TICK);
inistol 0:78fce1e0dede 41 //Call lv_tick_inc(x) every x milliseconds in a Timer or Task (x should be between 1 and 10).
inistol 0:78fce1e0dede 42 //It is required for the internal timing of LittlevGL.
inistol 0:78fce1e0dede 43 lv_task_handler();
inistol 0:78fce1e0dede 44 //Call lv_task_handler() periodically every few milliseconds.
inistol 0:78fce1e0dede 45 //It will redraw the screen if required, handle input devices etc.
inistol 0:78fce1e0dede 46 }
inistol 0:78fce1e0dede 47
inistol 0:78fce1e0dede 48 void display_init(void){
inistol 0:78fce1e0dede 49 //Init the touch screen display via the BSP driver. Based on ST's example.
inistol 0:78fce1e0dede 50 BSP_LCD_Init();
inistol 0:78fce1e0dede 51 BSP_LCD_LayerDefaultInit(0, LCD_FB_START_ADDRESS);
inistol 0:78fce1e0dede 52 BSP_LCD_DisplayOn();
inistol 0:78fce1e0dede 53 BSP_LCD_SelectLayer(0);
inistol 0:78fce1e0dede 54 BSP_LCD_Clear(LCD_COLOR_TRANSPARENT );
inistol 0:78fce1e0dede 55 BSP_LCD_SetFont(&LCD_DEFAULT_FONT);
inistol 0:78fce1e0dede 56 BSP_LCD_SetBackColor(LCD_COLOR_WHITE);
inistol 0:78fce1e0dede 57 BSP_LCD_SetTextColor(LCD_COLOR_DARKBLUE);
inistol 0:78fce1e0dede 58
inistol 0:78fce1e0dede 59 lv_init(); //Initialize the LittlevGL
inistol 0:78fce1e0dede 60 static lv_disp_buf_t disp_buf;
inistol 0:78fce1e0dede 61 static lv_color_t buf[LV_HOR_RES_MAX * 10]; //Declare a buffer for 10 lines
inistol 0:78fce1e0dede 62 lv_disp_buf_init(&disp_buf, buf, NULL, LV_HOR_RES_MAX * 10); //Initialize the display buffer
inistol 0:78fce1e0dede 63
inistol 0:78fce1e0dede 64 //Implement and register a function which can copy a pixel array to an area of your display
inistol 0:78fce1e0dede 65 lv_disp_drv_t disp_drv; //Descriptor of a display driver
inistol 0:78fce1e0dede 66 lv_disp_drv_init(&disp_drv); //Basic initialization
inistol 0:78fce1e0dede 67 disp_drv.flush_cb = my_disp_flush_cb; //Set your driver function
inistol 0:78fce1e0dede 68 disp_drv.buffer = &disp_buf; //Assign the buffer to the display
inistol 0:78fce1e0dede 69 lv_disp_drv_register(&disp_drv); //Finally register the driver
inistol 0:78fce1e0dede 70 }
inistol 0:78fce1e0dede 71
inistol 0:78fce1e0dede 72 void my_disp_flush_cb(lv_disp_drv_t* disp_drv, const lv_area_t* area, lv_color_t* color_p)
inistol 0:78fce1e0dede 73 {
inistol 0:78fce1e0dede 74 //The most simple case (but also the slowest) to put all pixels to the screen one-by-one
inistol 0:78fce1e0dede 75 uint16_t x, y;
inistol 0:78fce1e0dede 76 for(y = area->y1; y <= area->y2; y++) {
inistol 0:78fce1e0dede 77 for(x = area->x1; x <= area->x2; x++) {
inistol 0:78fce1e0dede 78 //put_px(x, y, *color_p)
inistol 0:78fce1e0dede 79 BSP_LCD_DrawPixel( x, y, color_p->full);
inistol 0:78fce1e0dede 80 color_p++;
inistol 0:78fce1e0dede 81 }
inistol 0:78fce1e0dede 82 }
inistol 0:78fce1e0dede 83 //IMPORTANT!!!* Inform the graphics library that you are ready with the flushing
inistol 0:78fce1e0dede 84 lv_disp_flush_ready(disp_drv);
inistol 0:78fce1e0dede 85 }
inistol 0:78fce1e0dede 86
inistol 0:78fce1e0dede 87
inistol 0:78fce1e0dede 88 void touchpad_init(void){
inistol 0:78fce1e0dede 89 BSP_TS_Init(480, 272);
inistol 0:78fce1e0dede 90 lv_indev_drv_t indev_drv; //Descriptor of an input device driver
inistol 0:78fce1e0dede 91 lv_indev_drv_init(&indev_drv); //Basic initialization
inistol 0:78fce1e0dede 92 indev_drv.type = LV_INDEV_TYPE_POINTER; //The touchpad is pointer type device
inistol 0:78fce1e0dede 93 indev_drv.read_cb = touchpad_read; //Set the touchpad_read function
inistol 0:78fce1e0dede 94 lv_indev_drv_register(&indev_drv); //Register touch driver in LvGL
inistol 0:78fce1e0dede 95 }
inistol 0:78fce1e0dede 96
inistol 0:78fce1e0dede 97 static bool touchpad_read(lv_indev_drv_t *indev, lv_indev_data_t *data){
inistol 0:78fce1e0dede 98 // Read your touchpad
inistol 0:78fce1e0dede 99 static int16_t last_x = 0;
inistol 0:78fce1e0dede 100 static int16_t last_y = 0;
inistol 0:78fce1e0dede 101 BSP_TS_GetState(&TS_State);
inistol 0:78fce1e0dede 102 if(TS_State.touchDetected) {
inistol 0:78fce1e0dede 103 data->point.x = TS_State.touchX[0];
inistol 0:78fce1e0dede 104 data->point.y = TS_State.touchY[0];
inistol 0:78fce1e0dede 105 last_x = data->point.x;
inistol 0:78fce1e0dede 106 last_y = data->point.y;
inistol 0:78fce1e0dede 107 data->state = LV_INDEV_STATE_PR;
inistol 0:78fce1e0dede 108 } else {
inistol 0:78fce1e0dede 109 data->point.x = last_x;
inistol 0:78fce1e0dede 110 data->point.y = last_y;
inistol 0:78fce1e0dede 111 data->state = LV_INDEV_STATE_REL;
inistol 0:78fce1e0dede 112 }
inistol 0:78fce1e0dede 113 return false; //false: no more data to read because we are no buffering
inistol 0:78fce1e0dede 114 }