日韩无码专区无码一级三级片|91人人爱网站中日韩无码电影|厨房大战丰满熟妇|AV高清无码在线免费观看|另类AV日韩少妇熟女|中文日本大黄一级黄色片|色情在线视频免费|亚洲成人特黄a片|黄片wwwav色图欧美|欧亚乱色一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時間:8:30-17:00
你可能遇到了下面的問題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
OHOS3.0標(biāo)準(zhǔn)系統(tǒng)編寫C程序控制LED

想了解更多內(nèi)容,請訪問:

創(chuàng)新互聯(lián)是專業(yè)的潘集網(wǎng)站建設(shè)公司,潘集接單;提供成都做網(wǎng)站、網(wǎng)站制作,網(wǎng)頁設(shè)計,網(wǎng)站設(shè)計,建網(wǎng)站,PHP網(wǎng)站建設(shè)等專業(yè)做網(wǎng)站服務(wù);采用PHP框架,可快速的進(jìn)行潘集網(wǎng)站開發(fā)網(wǎng)頁制作和功能擴(kuò)展;專業(yè)做搜索引擎喜愛的網(wǎng)站,專業(yè)的做網(wǎng)站團(tuán)隊,希望更多企業(yè)前來合作!

和華為官方合作共建的鴻蒙技術(shù)社區(qū)

https://harmonyos.

前言:

OpenHarmony分為輕量系統(tǒng)、小型系統(tǒng)、標(biāo)準(zhǔn)系統(tǒng),目前對應(yīng)LiteOS-M、LiteOS-A、Linux內(nèi)核。但好像并沒有說一定是按照使用內(nèi)核來劃分。我們這里姑且先這么區(qū)分。本文使用的是比較新的OpenHarmony 3.0 LTS版本,Linux內(nèi)核,編譯標(biāo)準(zhǔn)系統(tǒng)。官方文檔已經(jīng)說明了,如何使用DevEco Studio開發(fā)hap包,并運(yùn)行在開發(fā)板,但是ACE框架能力有限。設(shè)備硬件開發(fā)還是需要C,所以這篇文章,將在標(biāo)準(zhǔn)系統(tǒng)下編譯C控制Hi3516開發(fā)板的LED閃爍。

1.環(huán)境準(zhǔn)備

3.0源碼下載:

 
 
 
 
  1. repo init -u https://gitee.com/openharmony/manifest.git -b OpenHarmony-3.0-LTS --no-repo-verify 
  2. repo sync -c 
  3. repo forall -c 'git lfs pull' 

區(qū)別于2.0需要安裝ruby,其他基本都一樣。

 
 
 
 
  1. sudo apt-get install ruby-full 

編譯命令

 
 
 
 
  1. build/prebuilts_download.sh 
  2. ./build.sh --product-name Hi3516DV300 

2.編寫helloworld.c

在applications\standard目錄下新建一個app目錄來存放.c的業(yè)務(wù)代碼。比如applications\standard\app\helloworld.c內(nèi)容容下:

 
 
 
 
  1. #include  
  2. int main(){ 
  3.     printf("Hello world.\n"); 
  4.     return 0; 

然后在當(dāng)前目錄新建編譯腳本BUILD.gn內(nèi)容如下:

 
 
 
 
  1. import("http://build/ohos.gni") 
  2. import("http://drivers/adapter/uhdf2/uhdf.gni") 
  3.  
  4. ohos_executable("helloworld") { 
  5.   sources = [ 
  6.     "helloworld.c" 
  7.   ] 
  8.   subsystem_name = "applications" 
  9.   part_name = "prebuilt_hap" 

然后添加到編譯框架applications\standard\hap\ohos.build增加如下內(nèi)容。

 
 
 
 
  1. "http://applications/standard/app:helloworld" 

最后執(zhí)行編譯命令即可,開發(fā)板使用的是Hi3516,在不指定out目錄時,缺省生成在/system/lib64或/system/lib下。

3.點亮開發(fā)板LED

能打印helloworld說明環(huán)境是沒問題的,接下來嘗試點亮開發(fā)板的LED。查看Hi3516DV300原理圖,請?zhí)砑渔溄用枋?/p>

Hi3516DV300共有4層板,由原理圖可知:最上層板的紅外補(bǔ)光燈接在GPIO5_1,綠色LED指示燈在GPIO2_3,核心板的紅色LED在GPIO3_4。

接下來參考OpenHarmony GPIO驅(qū)動說明。

確定GPIO管腳號

不同SOC芯片由于其GPIO控制器型號、參數(shù)、以及控制器驅(qū)動的不同,GPIO管腳號的換算方式不一樣。

  • Hi3516DV300

控制器管理12組GPIO管腳,每組8個。

GPIO號 = GPIO組索引 (0~11) * 每組GPIO管腳數(shù)(8) + 組內(nèi)偏移

舉例:GPIO10_3的GPIO號 = 10 * 8 + 3 = 83

  • Hi3518EV300

控制器管理10組GPIO管腳,每組10個。

GPIO號 = GPIO組索引 (0~9) * 每組GPIO管腳數(shù)(10) + 組內(nèi)偏移

舉例:GPIO7_3的GPIO管腳號 = 7 * 10 + 3 = 73

由此可以得出:

 
 
 
 
  1. GPIO5_1 = 5 * 8 + 1; 
  2. GPIO2_3 = 2 * 8 + 3; 
  3. GPIO3_4 = 3 * 8 + 4; 

 然后新建applications\standard\app\ledtest.c內(nèi)容如下

 
 
 
 
  1. #include      // standard library 標(biāo)準(zhǔn)庫函數(shù)頭文件 
  2. #include       // standard input output 標(biāo)準(zhǔn)輸入輸出函數(shù) 
  3. #include      // 定義了擴(kuò)展的整數(shù)類型和宏 
  4.  
  5. #include      // POSIX 系統(tǒng) API 訪問功能的頭文件 
  6. #include       // unix標(biāo)準(zhǔn)中通用的頭文件 define O_WRONLY and O_RDONLY   
  7.  
  8. // #include  
  9. #define GPIO_DIR_IN "in" 
  10. #define GPIO_DIR_OUT "out" 
  11. #define GPIO_VAL_LOW 0 
  12. #define GPIO_VAL_HIGHT 1 
  13.  
  14. int32_t GpioSetDir(uint16_t gpio, char* dir){ 
  15.     char path[100] = {0}; 
  16.     sprintf(path,"echo %d > /sys/class/gpio/export",gpio); 
  17.     system(path); 
  18.     printf("info:%s\n",path); 
  19.  
  20.     char direction[100] = {0}; 
  21.     sprintf(direction,"echo %s > /sys/class/gpio/gpio%d/direction",dir,gpio); 
  22.     system(direction); 
  23.     printf("info:%s\n",direction); 
  24.     return 0; 
  25.  
  26. int32_t GpioWrite(uint16_t gpio, uint16_t val) 
  27.     char path[100] = {0}; 
  28.     sprintf(path,"echo %d > /sys/class/gpio/gpio%d/value",val,gpio); 
  29.     system(path); 
  30.     printf("info:%s\n",path); 
  31.     return 0; 
  32.  
  33. int main(){ 
  34.     uint16_t  GPIO5_1 = 5 * 8 + 1; 
  35.     uint16_t  GPIO2_3 = 2 * 8 + 3; 
  36.     uint16_t  GPIO3_4 = 3 * 8 + 4; 
  37.      
  38.     printf("LED test start\n"); 
  39.      
  40.     int32_t ret; 
  41.     // uint16_t val; 
  42.     ret = GpioSetDir(GPIO5_1,GPIO_DIR_OUT); 
  43.     if (ret != 0) { 
  44.         printf("GpioSerDir: failed, ret %d\n", ret); 
  45.         return 0; 
  46.     } 
  47.     ret = GpioSetDir(GPIO2_3,GPIO_DIR_OUT); 
  48.     if (ret != 0) { 
  49.         printf("GpioSerDir: failed, ret %d\n", ret); 
  50.         return 0; 
  51.     } 
  52.     ret = GpioSetDir(GPIO3_4,GPIO_DIR_OUT); 
  53.     if (ret != 0) { 
  54.         printf("GpioSerDir: failed, ret %d\n", ret); 
  55.         return 0; 
  56.     } 
  57.  
  58.     while(1) 
  59.     { 
  60.         GpioWrite(GPIO5_1, GPIO_VAL_HIGHT); 
  61.         usleep(1000000); 
  62.         GpioWrite(GPIO5_1, GPIO_VAL_LOW); 
  63.         usleep(1000000); 
  64.         GpioWrite(GPIO2_3, GPIO_VAL_HIGHT); 
  65.         usleep(1000000); 
  66.         GpioWrite(GPIO2_3, GPIO_VAL_LOW); 
  67.         usleep(1000000); 
  68.         GpioWrite(GPIO3_4, GPIO_VAL_HIGHT); 
  69.         usleep(1000000); 
  70.         GpioWrite(GPIO3_4, GPIO_VAL_LOW); 
  71.         usleep(1000000); 
  72.     } 
  73.     return 0; 

 將業(yè)務(wù)代碼添加到BUILD.gn

 
 
 
 
  1. import("http://build/ohos.gni") 
  2. import("http://drivers/adapter/uhdf2/uhdf.gni") 
  3.  
  4. ohos_executable("helloworld") { 
  5.   sources = [ 
  6.     "helloworld.c" 
  7.   ] 
  8.   subsystem_name = "applications" 
  9.   part_name = "prebuilt_hap" 
  10.  
  11. ohos_executable("ledtest") { 
  12.   sources = [ 
  13.     "ledtest.c" 
  14.   ] 
  15.   subsystem_name = "applications" 
  16.   part_name = "prebuilt_hap" 

 applications\standard\hap\ohos.build

 
 
 
 
  1. "http://applications/standard/app:ledtest" 

之后將程序燒錄到開發(fā)板,執(zhí)行./system/bin/ledtest

就可以看到LED閃爍起來了。

本來是打算使用鴻蒙的GPIO接口來實現(xiàn)這個功能的,不過調(diào)試了很久也沒調(diào)通,最后無奈還是用的system自己實現(xiàn)的GPIO函數(shù)。有沒使用OpenHarmony的GPIO成功的小伙伴可以留言一起交流啊。

文章相關(guān)附件可以點擊下面的原文鏈接前往下載

https://harmonyos./resource/1269

想了解更多內(nèi)容,請訪問:

和華為官方合作共建的鴻蒙技術(shù)社區(qū)

https://harmonyos.


本文標(biāo)題:OHOS3.0標(biāo)準(zhǔn)系統(tǒng)編寫C程序控制LED
文章地址:http://m.5511xx.com/article/cojgojp.html