ART-Pi Smart開發(fā)板為RT-Thread聯(lián)合百問(wèn)科技出品,使用的是 NXP 公司的 i.MX6ULL 處理器,具備單核 ARM Cortex-A7,最高運(yùn)行頻率可以達(dá)到 800MHz。擁有 1 路 LCD 顯示、1 路數(shù)字?jǐn)z像頭、8 路 UART、2 路 USB OTG、2 路 CAN、2 路以太網(wǎng)等資源,便于客戶靈活定制。
概述
我申請(qǐng)測(cè)試是想實(shí)現(xiàn)3D打印機(jī)的高級(jí)功能的,由于測(cè)試時(shí)間有限(本來(lái)規(guī)定測(cè)試時(shí)間為一個(gè)月,但是板子到手只有不到半個(gè)月)。要在這么短的時(shí)間內(nèi)移植全部程序是遠(yuǎn)遠(yuǎn)不夠的,特別是RT-Thread Smart系統(tǒng)還需要時(shí)間學(xué)習(xí),所以決定移植基于LVGL的圖形UI。查看了RT-Thread官方網(wǎng)站,還沒(méi)有基于LVGL的移植報(bào)告,這樣就更有意義。
RT-Thread Smart簡(jiǎn)介
RT-Thread Smart(簡(jiǎn)稱 rt-smart)是基于 RT-Thread 操作系統(tǒng)衍生的新分支,面向帶 MMU,中高端應(yīng)用的芯片,例如 ARM Cortex-A 系列芯片,MIPS 芯片,帶 MMU 的 RISC-V 芯片等。rt-smart 在 RT-Thread 操作系統(tǒng)的基礎(chǔ)上啟用獨(dú)立、完整的進(jìn)程方式,同時(shí)以混合微內(nèi)核模式執(zhí)行。rt-smart 是一款高性能混合微內(nèi)核操作系統(tǒng),主要包含內(nèi)核模塊和用戶態(tài)運(yùn)行時(shí)環(huán)境。內(nèi)核模塊包括虛擬地址空間管理、進(jìn)程管理、線程管理、進(jìn)程間通信、虛擬文件系統(tǒng)框架、網(wǎng)絡(luò)接口層框架、設(shè)備驅(qū)動(dòng)框架、msh 控制臺(tái)、日志系統(tǒng)、異常中斷管理和系統(tǒng)調(diào)用接口,設(shè)備驅(qū)動(dòng)框架包含串口驅(qū)動(dòng)框架和看門狗驅(qū)動(dòng)框架。用戶態(tài)運(yùn)行時(shí)環(huán)境包括用戶態(tài) C 庫(kù)。
LVGL簡(jiǎn)介
LVGL(輕量級(jí)和通用圖形庫(kù))是一個(gè)免費(fèi)和開源的圖形庫(kù),它提供了創(chuàng)建嵌入式GUI所需的一切,具有易于使用的圖形元素,美麗的視覺效果和低內(nèi)存占用。LVGL的項(xiàng)目作者是來(lái)自匈牙利首都布達(dá)佩斯的 Gábor Kiss-Vámosi 。Kiss 在2016年將其并發(fā)布在 GitHub 上。當(dāng)時(shí)叫 LittlevGL而不是LVGL,后來(lái)作者統(tǒng)一修改為 LVGL。 像一般的開源項(xiàng)目的那樣,它是作為一個(gè)人的項(xiàng)目開始的。 從那時(shí)起,陸續(xù)有近 100 名貢獻(xiàn)者參與了項(xiàng)目開發(fā),使得 LVGL 逐漸成為最受歡迎的嵌入式圖形庫(kù)之一。
開發(fā)環(huán)境
硬件
硬件環(huán)境搭建
電源輸入:5V,500 mA,通過(guò)開發(fā)板 USB-TypeC(下面)供電。如下圖所示,通過(guò)測(cè)試電腦的 USB 直接對(duì)開發(fā)板供電
串口連接:下方的 USB-TypeC 接口,既是用作電源供電,同時(shí)也是 USB 轉(zhuǎn) UART 接口,主要用于打印系統(tǒng)的控制臺(tái)輸入和輸出
| 波特率 |數(shù)據(jù)位|停止位|校驗(yàn)位|流控|
|—————-|———|———|———|——|
|115200 | 8 |1 |無(wú) |無(wú)|
網(wǎng)絡(luò)接口:通過(guò)路由器和網(wǎng)線,將開發(fā)板和測(cè)試電腦連接在同一個(gè)局域網(wǎng)內(nèi)
Micro SD卡:32GB 或 32GB 以下??墒褂米x卡器將編譯生成的用戶 APP 固件文件(.elf)復(fù)制到 SD 卡
顯示接口:開發(fā)板未上電之前,先將 4.3 寸 LCD 顯示器的 40 Pin FPC 排線連接到 ART-Pi Smart 開發(fā)板背面的 LCD 硬件插槽
ART-Pi Smart 硬件連接圖
軟件
SDK下載
ART-Pi Smart SDK 軟件包
ART-Pi-Smart SDK 倉(cāng)庫(kù)是 RT-Thread 團(tuán)隊(duì)對(duì) ART-Pi Smart 開發(fā)板所作的支持包,用于學(xué)習(xí)和評(píng)估 RT-Thread Smart 微內(nèi)核操作系統(tǒng),讓用戶可以更簡(jiǎn)單方便地開發(fā)自己的應(yīng)用程序。
ART-Pi smart 開發(fā)板的 SDK 倉(cāng)庫(kù),主要包括 RT-Thread Smart 的源碼,BSP 驅(qū)動(dòng),應(yīng)用程序 demo 等。
SDK 下載方法:通過(guò) Git 下載 ART-Pi Smart SDK 包:
git clone https://gitee.com/rtthread/ART-Pi-smart.git
下載工具鏈
rt-smart 采用的工具鏈為:arm-linux-musleabi 工具鏈,ART-Pi smart sdk本身并不攜帶工具鏈,所以在下載了sdk后需要自行安裝工具鏈,不過(guò)安裝工具鏈非常簡(jiǎn)單,只需要在sdk的tools目錄下執(zhí)行下python腳本即可:
python get_toolchain.py
將下載下來(lái)的工具鏈,解壓到指定的路徑 /rt-smart/tools/gnu_gcc/ 下面
軟件環(huán)境
安裝Visual Studio Code并安裝插件
安裝Visual Studio Code后要安裝RT-Thread Smart插件,目前VS Code RT-Thread Smart插件已經(jīng)上傳到VS Code市場(chǎng),所以安裝非常方便,可以直接在VS Code 的擴(kuò)展市場(chǎng)中搜索 RT-Thread Smart,點(diǎn)擊安裝即可:(推薦安裝Path interestise)
可選安裝Visual Studio
根據(jù)LVGL for VS項(xiàng)目,設(shè)計(jì)LVGL的界面,并編譯成基于Windows平臺(tái)的仿真軟件,確保UI部分沒(méi)有bug。
效果
創(chuàng)建 LVGL Demo
設(shè)置SDK工具鏈路徑
編譯文件路徑
編譯
下載
關(guān)鍵代碼
用戶態(tài)應(yīng)用是一份 elf(Executable Linkable Format)文件,由 GNU GCC 編譯鏈接而產(chǎn)生。在 RT-Thread Smart 中,它被固定加載到虛擬地址 0x100000 處執(zhí)行。當(dāng)需要系統(tǒng)服務(wù)時(shí)通過(guò)系統(tǒng)調(diào)用的方式通過(guò) MMU陷入到內(nèi)核中。用戶態(tài)應(yīng)用環(huán)境中,外設(shè)的使用需要先調(diào)用rt_device_find()函數(shù)查找設(shè)備,然后通過(guò)rt_device_open()打開,使用rt_device_control()函數(shù)通過(guò)命令字實(shí)現(xiàn)相應(yīng)的功能。至于設(shè)備的初始化和功能的實(shí)現(xiàn)交到內(nèi)核完成,這樣就極大的降低用戶態(tài)應(yīng)用開發(fā)難度,這種思想應(yīng)該大贊一個(gè)。
LVGL初始化
#if LV_USE_LOG
static void lv_rt_log(const char buf)
{
LOG_I(buf);
}
#endif / LV_USE_LOG */
static void lvgl_thread_entry(void parameter)
{
rt_kprintf("Startup lvgl thread.n");
#if LV_USE_LOG
lv_log_register_print_cb(lv_rt_log);
#endif / LV_USE_LOG /
lv_init();
lv_port_disp_init();
lv_port_indev_init();
lv_user_gui_init();
/ handle the tasks of LVGL */
while(1)
{
lv_task_handler();
rt_thread_mdelay(10);
}
}
int lvgl_thread_init(void)
{
rt_thread_t rtt;
rtt = rt_thread_create("lvgl", lvgl_thread_entry, NULL, 4096, PKG_LVGL_THREAD_PRIO, 100);
if(rtt == RT_NULL)
{
LOG_D("Failed to create LVGL thread");
return -1;
}
rt_thread_startup(rtt);
return 0;
}
LCD設(shè)備接口與lvgl對(duì)接
void lv_port_disp_init(void)
{
rt_err_t result;
lcd_device = rt_device_find("lcd");
if (lcd_device == 0)
{
LOG_D("lcd_device error!");
return;
}
result = rt_device_open(lcd_device, 0);
if (result != RT_EOK)
{
LOG_D("device_open error!");
return;
}
result = rt_device_control(lcd_device, FBIOGET_FSCREENINFO, &f_info);
if (result != RT_EOK)
{
LOG_D("device_control error!");
/* get device information failed */
return;
}
rt_kprintf("Display Device: %s - 0x%08x, size %dn", f_info.id, (unsigned int)f_info.smem_start, f_info.smem_len);
rt_device_control(lcd_device, FBIOGET_VSCREENINFO, &v_info);
rt_kprintf("tScreen: %dx%d, %dbppn", v_info.xres, v_info.yres, v_info.bits_per_pixel);
/ Initialize disp_buf
with the buffer(s). /
lv_disp_draw_buf_init(&disp_buf, lv_disp_buf1, RT_NULL, DISP_BUF_SIZE);
lv_disp_drv_init(&disp_drv); / Basic initialization /
/ Set the resolution of the display /
disp_drv.hor_res = v_info.xres;
disp_drv.ver_res = v_info.yres;
/ Set a display buffer /
disp_drv.draw_buf = &disp_buf;
/ Used to copy the buffer's content to the display /
disp_drv.flush_cb = lcd_fb_flush;
/ Finally register the driver /
lv_disp_t * disp = lv_disp_drv_register(&disp_drv);
g_disp_drv = disp_drv;
lv_disp_set_default(disp);
lv_theme_t * th = lv_theme_default_init(disp, lv_palette_main(LV_PALETTE_BLUE), lv_palette_main(LV_PALETTE_RED), LV_THEME_DEFAULT_DARK, LV_FONT_DEFAULT);
lv_disp_set_theme(disp, th);
lv_group_t * gr = lv_group_create();
lv_group_set_default(gr);
}
觸摸采用的芯片是GT911,通過(guò)I2C接口獲得
void lv_port_indev_init(void)
{
touch_dev = rt_device_find(TOUCH_DEV_NAME);
if (touch_dev == RT_NULL)
{
rt_kprintf("Can't find device:%sn", TOUCH_DEV_NAME);
return;
}
if (rt_device_open(touch_dev, RT_DEVICE_FLAG_INT_RX) != RT_EOK)
{
rt_kprintf("open device failed!n");
return;
}
void id;
rt_uint16_t x = g_disp_drv.hor_res;
rt_uint16_t y = g_disp_drv.ver_res;
id = rt_malloc(sizeof(rt_uint8_t) * 8);
rt_device_control(touch_dev, RT_TOUCH_CTRL_GET_ID, id);
rt_uint8_t * read_id = (rt_uint8_t )id;
rt_kprintf("Touch device: id = GT%d%d%d n", read_id[0] - '0', read_id[1] - '0', read_id[2] - '0');
rt_device_control(touch_dev, RT_TOUCH_CTRL_SET_X_RANGE, &x); / if possible you can set your x y coordinate /
rt_device_control(touch_dev, RT_TOUCH_CTRL_SET_Y_RANGE, &y);
rt_device_control(touch_dev, RT_TOUCH_CTRL_GET_INFO, id);
rt_kprintf("trange_x = %4d, range_y = %4d, point_num = %4dn",
( (struct rt_touch_info )id).range_x, ( (struct rt_touch_info )id).range_y, ( (struct rt_touch_info )id).point_num);
signal(SIGINT, Stop);
static lv_indev_drv_t indev_drv;
lv_indev_drv_init(&indev_drv); / Basic initialization /
indev_drv.type = LV_INDEV_TYPE_POINTER;
indev_drv.read_cb = input_read;
/ Register the driver in LVGL and save the created input device object /
g_touch_dev = lv_indev_drv_register(&indev_drv);
}
運(yùn)行
按復(fù)位鍵啟動(dòng)到msh環(huán)境
運(yùn)行測(cè)試程序
總結(jié)
通過(guò)測(cè)試,我對(duì)RT-Thread smart的印象深刻。以前也開發(fā)過(guò)RT-Thread的項(xiàng)目,但對(duì)rt-smart這種將內(nèi)核與用戶態(tài)分隔開,以前只在大型桌面操作系統(tǒng)里見到的特征,能在嵌入式系統(tǒng)里運(yùn)用感到震撼。這樣使開發(fā)板的設(shè)計(jì)只需要提供內(nèi)核和驅(qū)動(dòng)代碼,應(yīng)用開發(fā)只需要掛載使用,極大地降低應(yīng)用開發(fā)難度,提高代碼重用度。而且提高應(yīng)用代碼隔離時(shí)系統(tǒng)更加健壯。
在測(cè)試過(guò)程中,遇到了問(wèn)題,RT-Thread掌門人——熊譜翔先生很快親自回答。在這里表示感謝。
由于時(shí)間太短,其它外設(shè)還沒(méi)有來(lái)得及測(cè)試,頗為遺憾。
同時(shí),希望RT-Thread能夠提供統(tǒng)一的開發(fā)環(huán)境,特別是基于Windows平臺(tái),畢竟用戶多一些。能否像LVGL提供一個(gè)模擬器(基于Visual Studio),畢竟Visual Studio調(diào)試功能很強(qiáng),且有VisualGDB加持。這樣就可在模擬器上消滅與平臺(tái)無(wú)關(guān)的bug,減少仿真調(diào)試,下載時(shí)間。
-
處理器
+關(guān)注
關(guān)注
68文章
19899瀏覽量
235429 -
以太網(wǎng)
+關(guān)注
關(guān)注
41文章
5642瀏覽量
176058 -
LCD顯示
+關(guān)注
關(guān)注
0文章
132瀏覽量
18977 -
RT-Thread
+關(guān)注
關(guān)注
32文章
1412瀏覽量
41995 -
ART-Pi
+關(guān)注
關(guān)注
0文章
23瀏覽量
1536
發(fā)布評(píng)論請(qǐng)先 登錄
RT-Thread NUC97x 移植 LVGL
基于ART-Pi Smart平臺(tái)的設(shè)計(jì)方案推薦
基于RT-Thread操作系統(tǒng)衍生rt-smart實(shí)時(shí)操作系統(tǒng)簡(jiǎn)介
ART Pi Smart基于RT-Thread Smart系統(tǒng)的LVGL移植簡(jiǎn)介
在RT-Thread Smart下怎樣去使用NimBLE軟件包呢
RT-Thread Smart快速上手
RT-Thread Smart已正式上線,源代碼可下載,采用Apache License 2.0
RT-Thread Smart已正式上線
RT-Thread聯(lián)合百問(wèn)科技出品ART-Pi Smart開發(fā)板
RT-Thread Smart 上手指南

ART-PI Smart開發(fā)板介紹與開發(fā)環(huán)境的建立
RT-Thread全球技術(shù)大會(huì):RT-Thread Smart更好的兼容Linux生態(tài)

基于xmake的RT-Thread Smart用戶態(tài)開發(fā)教程

基于xmake的RT-Thread Smart用戶態(tài)開發(fā)教程

評(píng)論