|
本帖最后由 roc2 于 2019-5-30 15:00 編輯
Little VGL作為一個(gè)優(yōu)秀、源碼開(kāi)源的GUI庫(kù),內(nèi)存占用少但界面炫酷,目前得到越來(lái)越多的支持。零知開(kāi)源平臺(tái)已移植了該庫(kù),下面在零知開(kāi)發(fā)板-增強(qiáng)板上進(jìn)行實(shí)驗(yàn)演示。
特性:- 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、硬件準(zhǔn)備
(1)零知開(kāi)發(fā)板-增強(qiáng)板
好看增強(qiáng)板.png (743.77 KB, 下載次數(shù): 71)
下載附件
2019-5-30 14:57 上傳
(2)TFT液晶顯示屏
(3)開(kāi)發(fā)工具
零知開(kāi)發(fā)工具與零知開(kāi)發(fā)板配合使用,實(shí)現(xiàn)程序一鍵下載。
零知界面.png (73.3 KB, 下載次數(shù): 73)
下載附件
2019-5-30 14:59 上傳
2、硬件連接
使用2.4寸、ILI9341驅(qū)動(dòng)、帶觸摸屏XPT2046的TFT液晶顯示屏作為顯示工具,與零知增強(qiáng)板配合使用,硬件連接按下表進(jìn)行連線:
硬件連接.jpg (108.34 KB, 下載次數(shù): 85)
下載附件
2019-5-30 14:18 上傳
3、編寫(xiě)代碼
因?yàn)槭褂昧薚FT液晶顯示屏作為顯示工具,所以需要用到FSMC_TFT庫(kù),同時(shí)也用到觸摸屏功能,也需要XPT2046的軟件庫(kù),相關(guān)的庫(kù)文件可到零知實(shí)驗(yàn)室官網(wǎng)免費(fèi)獲取。
(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庫(kù)相關(guān)聯(lián),進(jì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è)置光標(biāo)位置
- LCD_WriteRAM_Prepare(); //開(kāi)始寫(xiě)入GRAM
- for(j=0;j<width;j++)
- {
- LCD_TYPE->LCD_RAM=color_p->full;//寫(xiě)入數(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è)置光標(biāo)位置
- LCD_WriteRAM_Prepare(); //開(kāi)始寫(xiě)入GRAM
- for(j=0;j<width;j++)
- {
- LCD_TYPE->LCD_RAM=color_p->full;//寫(xiě)入數(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ù)制代碼 注:觸摸屏最好先進(jìn)行校準(zhǔn),這樣讀取位置就比較精確,這里簡(jiǎn)單的進(jìn)行了一下轉(zhuǎn)換,對(duì)于尺寸較大的控件影響不大,如果是尺寸很小的控件不做校準(zhǔn),讀取位置就會(huì)有很大的偏差。
(3)LVGL system tick
使用一個(gè)1ms定時(shí)器中斷進(jìn)行提供:
- 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的一個(gè)demo
這里直接調(diào)用了官方示例的demo進(jìn)行演示。
4、運(yùn)行效果:
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端模擬器輔助開(kāi)發(fā)調(diào)試UI,以下是windows上Qt運(yùn)行效果:
windows.jpg (449.77 KB, 下載次數(shù): 100)
下載附件
2019-5-30 14:42 上傳
相關(guān)的庫(kù)文件和完整工程代碼可到零知實(shí)驗(yàn)室官網(wǎng)免費(fèi)獲取。
|
|