|
本帖最后由 roc2 于 2019-5-30 15:00 編輯
Little VGL作為一個優(yōu)秀、源碼開源的GUI庫,內(nèi)存占用少但界面炫酷,目前得到越來越多的支持。零知開源平臺已移植了該庫,下面在零知開發(fā)板-增強板上進行實驗演示。
特性:- 16, 32 or 64 bit microcontroller or processor
- 16 MHz clock speed
- 8 kB RAM for static data and >2 KB RAM for dynamic data (graphical objects)
- 64 kB program memory (flash)
- 支持GPU
1、硬件準備
(1)零知開發(fā)板-增強板
好看增強板.png (743.77 KB, 下載次數(shù): 71)
下載附件
2019-5-30 14:57 上傳
(2)TFT液晶顯示屏
(3)開發(fā)工具
零知開發(fā)工具與零知開發(fā)板配合使用,實現(xiàn)程序一鍵下載。
零知界面.png (73.3 KB, 下載次數(shù): 73)
下載附件
2019-5-30 14:59 上傳
2、硬件連接
使用2.4寸、ILI9341驅(qū)動、帶觸摸屏XPT2046的TFT液晶顯示屏作為顯示工具,與零知增強板配合使用,硬件連接按下表進行連線:
硬件連接.jpg (108.34 KB, 下載次數(shù): 85)
下載附件
2019-5-30 14:18 上傳
3、編寫代碼
因為使用了TFT液晶顯示屏作為顯示工具,所以需要用到FSMC_TFT庫,同時也用到觸摸屏功能,也需要XPT2046的軟件庫,相關(guān)的庫文件可到零知實驗室官網(wǎng)免費獲取。
(1)顯示設(shè)備
初始化:
- /**
- * Initialize your display here
- */
- void tft_init(void)
- {
- lv_disp_drv_t disp_drv;
- lv_disp_drv_init(&disp_drv);
-
- disp_drv.disp_fill = tft_fill;
- disp_drv.disp_map = tft_map;
- disp_drv.disp_flush = tft_flush;
-
- lv_disp_drv_register(&disp_drv);
- }
復(fù)制代碼 液晶屏與LittleVGL庫相關(guān)聯(lián),進行顯示的操作:
- /**
- * Flush a color buffer
- * @param x1 left coordinate of the rectangle
- * @param x2 right coordinate of the rectangle
- * @param y1 top coordinate of the rectangle
- * @param y2 bottom coordinate of the rectangle
- * @param color_p pointer to an array of colors
- */
- void tft_flush(int32_t x1, int32_t y1, int32_t x2, int32_t y2, const lv_color_t * color_p)
- {
- // LCD_Color_Fill(x1,y1,x2,y2,color_p);
- u16 height,width;
- u16 i,j;
- width=x2-x1+1; //得到填充的寬度
- height=y2-y1+1; //高度
- for(i=0;i<height;i++)
- {
- LCD_SetCursor(x1,y1+i); //設(shè)置光標位置
- LCD_WriteRAM_Prepare(); //開始寫入GRAM
- for(j=0;j<width;j++)
- {
- LCD_TYPE->LCD_RAM=color_p->full;//寫入數(shù)據(jù)
- color_p++;
- }
- }
- lv_flush_ready();
- }
- /**
- * Put a color map to a rectangular area
- * @param x1 left coordinate of the rectangle
- * @param x2 right coordinate of the rectangle
- * @param y1 top coordinate of the rectangle
- * @param y2 bottom coordinate of the rectangle
- * @param color_p pointer to an array of colors
- */
- void tft_map(int32_t x1, int32_t y1, int32_t x2, int32_t y2, const lv_color_t * color_p)
- {
- u16 height,width;
- u16 i,j;
- width=x2-x1+1; //得到填充的寬度
- height=y2-y1+1; //高度
- for(i=0;i<height;i++)
- {
- LCD_SetCursor(x1,y1+i); //設(shè)置光標位置
- LCD_WriteRAM_Prepare(); //開始寫入GRAM
- for(j=0;j<width;j++)
- {
- LCD_TYPE->LCD_RAM=color_p->full;//寫入數(shù)據(jù)
- color_p++;
- }
- }
- }
- /**
- * Fill a rectangular area with a color
- * @param x1 left coordinate of the rectangle
- * @param x2 right coordinate of the rectangle
- * @param y1 top coordinate of the rectangle
- * @param y2 bottom coordinate of the rectangle
- * @param color fill color
- */
- void tft_fill(int32_t x1, int32_t y1, int32_t x2, int32_t y2, lv_color_t color)
- {
- LCD_Fill(x1,y1,x2,y2,color.full);
- }
復(fù)制代碼 (2)輸入設(shè)備,即用觸摸屏作為輸入設(shè)備
初始化:
- /**
- * init touchpad here
- */
- /*************************
- * Input device interface
- *************************/
- void touchpad_init(void)
- {
-
- 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 = ex_tp_read; /*Library ready your touchpad via this function*/
- lv_indev_drv_register(&indev_drv); /*Finally register the driver*/
- }
復(fù)制代碼 觸摸位置的讀。
- /*
- * touch read position
- */
- bool ex_tp_read(lv_indev_data_t *data)
- {
- bool tp_is_pressed = ts.touched(); /*TODO read here the state of toush pad*/
- int16_t last_x = 0;
- int16_t last_y = 0;
-
- if(tp_is_pressed) {
- /*Touch pad is being pressed now*/
- TS_Point p = ts.getPoint();
-
- //convert to lcd position
- last_y = 320-(p.x *320)/4095; /*TODO save the current X coordinate*/
- last_x = 240-(p.y *240)/4095; /*TODO save the current Y coordinate*/
-
- Serial.print("touched:");
- Serial.print(last_x);Serial.print(",");Serial.println(last_y);
- }
-
- data->point.x = last_x;
- data->point.y = last_y;
- data->state = tp_is_pressed ? LV_INDEV_STATE_PR : LV_INDEV_STATE_REL;
-
- return false; /*Return false because no moare to be read*/
- }
復(fù)制代碼 注:觸摸屏最好先進行校準,這樣讀取位置就比較精確,這里簡單的進行了一下轉(zhuǎn)換,對于尺寸較大的控件影響不大,如果是尺寸很小的控件不做校準,讀取位置就會有很大的偏差。
(3)LVGL system tick
使用一個1ms定時器中斷進行提供:
- void timer_handler(stimer_t *timer)
- {
- lv_tick_inc(1);
- }
-
- void lvgl_timer_init()
- {
- static stimer_t m_timer;
- m_timer.timer = TIM3;
- TimerHandleInit(&m_timer, 10-1, 8400-1);//1ms timer
- attachIntHandle(&m_timer, timer_handler);
- }
復(fù)制代碼
(4)創(chuàng)建lvgl的一個demo
這里直接調(diào)用了官方示例的demo進行演示。
4、運行效果:
1.jpg (232.75 KB, 下載次數(shù): 72)
下載附件
2019-5-30 14:38 上傳
2.jpg (233.49 KB, 下載次數(shù): 85)
下載附件
2019-5-30 14:38 上傳
3.jpg (215.49 KB, 下載次數(shù): 85)
下載附件
2019-5-30 14:39 上傳
4.jpg (232.49 KB, 下載次數(shù): 73)
下載附件
2019-5-30 14:39 上傳
還可以使用PC端模擬器輔助開發(fā)調(diào)試UI,以下是windows上Qt運行效果:
windows.jpg (449.77 KB, 下載次數(shù): 100)
下載附件
2019-5-30 14:42 上傳
相關(guān)的庫文件和完整工程代碼可到零知實驗室官網(wǎng)免費獲取。
|
|