久久久久久久999_99精品久久精品一区二区爱城_成人欧美一区二区三区在线播放_国产精品日本一区二区不卡视频_国产午夜视频_欧美精品在线观看免费

 找回密碼
 立即注冊(cè)

QQ登錄

只需一步,快速開(kāi)始

搜索
查看: 6412|回復(fù): 0
打印 上一主題 下一主題
收起左側(cè)

零知開(kāi)源分享-移植 LittleVGL.GUI庫(kù)demo演示

[復(fù)制鏈接]
跳轉(zhuǎn)到指定樓層
樓主
本帖最后由 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)板


(2)TFT液晶顯示屏
(3)開(kāi)發(fā)工具
零知開(kāi)發(fā)工具與零知開(kāi)發(fā)板配合使用,實(shí)現(xiàn)程序一鍵下載。


2、硬件連接
使用2.4寸、ILI9341驅(qū)動(dòng)、帶觸摸屏XPT2046的TFT液晶顯示屏作為顯示工具,與零知增強(qiáng)板配合使用,硬件連接按下表進(jìn)行連線:



3、編寫(xiě)代碼
因?yàn)槭褂昧薚FT液晶顯示屏作為顯示工具,所以需要用到FSMC_TFT庫(kù),同時(shí)也用到觸摸屏功能,也需要XPT2046的軟件庫(kù),相關(guān)的庫(kù)文件可到零知實(shí)驗(yàn)室官網(wǎng)免費(fèi)獲取。
(1)顯示設(shè)備
初始化:
  1. /**
  2. * Initialize your display here
  3. */
  4. void tft_init(void)
  5. {
  6.         lv_disp_drv_t disp_drv;
  7.         lv_disp_drv_init(&disp_drv);
  8.          
  9.         disp_drv.disp_fill = tft_fill;
  10.         disp_drv.disp_map = tft_map;
  11.         disp_drv.disp_flush = tft_flush;
  12.          
  13.         lv_disp_drv_register(&disp_drv);
  14. }
復(fù)制代碼
液晶屏與LittleVGL庫(kù)相關(guān)聯(lián),進(jìn)行顯示的操作:
  1. /**
  2. * Flush a color buffer
  3. * @param x1 left coordinate of the rectangle
  4. * @param x2 right coordinate of the rectangle
  5. * @param y1 top coordinate of the rectangle
  6. * @param y2 bottom coordinate of the rectangle
  7. * @param color_p pointer to an array of colors
  8. */
  9. void tft_flush(int32_t x1, int32_t y1, int32_t x2, int32_t y2, const lv_color_t * color_p)
  10. {
  11.         //        LCD_Color_Fill(x1,y1,x2,y2,color_p);
  12.         u16 height,width;
  13.         u16 i,j;
  14.         width=x2-x1+1;                         //得到填充的寬度
  15.         height=y2-y1+1;                        //高度
  16.         for(i=0;i<height;i++)
  17.         {
  18.                 LCD_SetCursor(x1,y1+i);           //設(shè)置光標(biāo)位置
  19.                 LCD_WriteRAM_Prepare();     //開(kāi)始寫(xiě)入GRAM
  20.                 for(j=0;j<width;j++)
  21.                 {
  22.                         LCD_TYPE->LCD_RAM=color_p->full;//寫(xiě)入數(shù)據(jù)
  23.                         color_p++;
  24.                 }
  25.         }
  26.         lv_flush_ready();
  27. }


  28. /**
  29. * Put a color map to a rectangular area
  30. * @param x1 left coordinate of the rectangle
  31. * @param x2 right coordinate of the rectangle
  32. * @param y1 top coordinate of the rectangle
  33. * @param y2 bottom coordinate of the rectangle
  34. * @param color_p pointer to an array of colors
  35. */
  36. void tft_map(int32_t x1, int32_t y1, int32_t x2, int32_t y2, const lv_color_t * color_p)
  37. {
  38.         u16 height,width;
  39.         u16 i,j;
  40.         width=x2-x1+1;                         //得到填充的寬度
  41.         height=y2-y1+1;                        //高度
  42.         for(i=0;i<height;i++)
  43.         {
  44.                 LCD_SetCursor(x1,y1+i);           //設(shè)置光標(biāo)位置
  45.                 LCD_WriteRAM_Prepare();     //開(kāi)始寫(xiě)入GRAM
  46.                 for(j=0;j<width;j++)
  47.                 {
  48.                         LCD_TYPE->LCD_RAM=color_p->full;//寫(xiě)入數(shù)據(jù)
  49.                         color_p++;
  50.                 }
  51.         }
  52. }

  53. /**
  54. * Fill a rectangular area with a color
  55. * @param x1 left coordinate of the rectangle
  56. * @param x2 right coordinate of the rectangle
  57. * @param y1 top coordinate of the rectangle
  58. * @param y2 bottom coordinate of the rectangle
  59. * @param color fill color
  60. */
  61. void tft_fill(int32_t x1, int32_t y1, int32_t x2, int32_t y2, lv_color_t color)
  62. {
  63.         LCD_Fill(x1,y1,x2,y2,color.full);
  64. }
復(fù)制代碼
(2)輸入設(shè)備,即用觸摸屏作為輸入設(shè)備
初始化:
  1. /**
  2. * init touchpad here
  3. */
  4. /*************************
  5. * Input device interface
  6. *************************/
  7. void touchpad_init(void)
  8. {
  9.          
  10.         lv_indev_drv_t indev_drv;                       /*Descriptor of an input device driver*/
  11.         lv_indev_drv_init(&indev_drv);                  /*Basic initialization*/
  12.         indev_drv.type = LV_INDEV_TYPE_POINTER;         /*The touchpad is pointer type device*/
  13.         indev_drv.read = ex_tp_read;                 /*Library ready your touchpad via this function*/
  14.         lv_indev_drv_register(&indev_drv);              /*Finally register the driver*/
  15. }
復(fù)制代碼
觸摸位置的讀取:
  1. /*
  2. * touch read position
  3. */
  4. bool ex_tp_read(lv_indev_data_t *data)
  5. {
  6.         bool tp_is_pressed = ts.touched(); /*TODO read here the state of toush pad*/
  7.         int16_t last_x = 0;
  8.         int16_t last_y = 0;
  9.          
  10.         if(tp_is_pressed) {
  11.                 /*Touch pad is being pressed now*/
  12.                 TS_Point p = ts.getPoint();
  13.                  
  14.                 //convert to lcd position
  15.                 last_y = 320-(p.x *320)/4095;       /*TODO save the current X coordinate*/
  16.                 last_x = 240-(p.y *240)/4095;       /*TODO save the current Y coordinate*/
  17.                  
  18.                 Serial.print("touched:");
  19.                 Serial.print(last_x);Serial.print(",");Serial.println(last_y);
  20.         }
  21.          
  22.         data->point.x = last_x;
  23.         data->point.y = last_y;
  24.         data->state = tp_is_pressed ? LV_INDEV_STATE_PR : LV_INDEV_STATE_REL;
  25.          
  26.         return false;       /*Return false because no moare to be read*/
  27. }
復(fù)制代碼
注:觸摸屏最好先進(jìn)行校準(zhǔn),這樣讀取位置就比較精確,這里簡(jiǎn)單的進(jìn)行了一下轉(zhuǎn)換,對(duì)于尺寸較大的控件影響不大,如果是尺寸很小的控件不做校準(zhǔn),讀取位置就會(huì)有很大的偏差。
(3)LVGL system tick
使用一個(gè)1ms定時(shí)器中斷進(jìn)行提供:

  1. void timer_handler(stimer_t *timer)
  2. {        
  3.         lv_tick_inc(1);
  4. }

  5. void lvgl_timer_init()
  6. {
  7.         static stimer_t m_timer;
  8.         m_timer.timer = TIM3;
  9.         TimerHandleInit(&m_timer, 10-1, 8400-1);//1ms timer
  10.         attachIntHandle(&m_timer, timer_handler);
  11. }
復(fù)制代碼

(4)創(chuàng)建lvgl的一個(gè)demo
這里直接調(diào)用了官方示例的demo進(jìn)行演示。

4、運(yùn)行效果:













還可以使用PC端模擬器輔助開(kāi)發(fā)調(diào)試UI,以下是windows上Qt運(yùn)行效果:


相關(guān)的庫(kù)文件和完整工程代碼可到零知實(shí)驗(yàn)室官網(wǎng)免費(fèi)獲取。






分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏 分享淘帖 頂 踩
回復(fù)

使用道具 舉報(bào)

本版積分規(guī)則

手機(jī)版|小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術(shù)交流QQ群281945664

Powered by 單片機(jī)教程網(wǎng)

快速回復(fù) 返回頂部 返回列表
主站蜘蛛池模板: h片免费看| 日本不卡在线观看 | 成年人视频在线免费观看 | 超碰在线亚洲 | 亚洲在线| 国产一区2区 | 久久com | 激情欧美日韩一区二区 | h视频免费在线观看 | 国产免费一区二区三区 | 欧美一区免费在线观看 | 日本不卡视频在线播放 | 亚洲风情在线观看 | 成人国产精品色哟哟 | 欧美日韩在线视频一区二区 | 毛片a区 | 天天躁日日躁狠狠躁白人 | 国产精品视频在线观看 | 91久久精品一区二区二区 | 精品视频导航 | 国产精品91视频 | 精品久久久久久18免费网站 | 蜜桃视频一区二区三区 | 国产综合视频 | 成人片网址 | 国内精品久久久久 | 亚洲欧美中文日韩在线v日本 | 麻豆精品一区二区三区在线观看 | 久久精品国产亚洲a | 亚洲国产一区在线 | 日韩快播电影网 | 99精品一区二区三区 | 国产黄色小视频在线观看 | 中文字幕欧美一区二区 | a国产视频 | 精品国产99 | 久久www免费人成看片高清 | 狠狠入ady亚洲精品经典电影 | 北条麻妃99精品青青久久主播 | 亚洲一区 | 久久国产精品视频 |