電子產(chǎn)業(yè)一站式賦能平臺(tái)

PCB聯(lián)盟網(wǎng)

搜索
查看: 650|回復(fù): 0
收起左側(cè)

【HarmonyOS HiSpark Wi-Fi IoT 套件試用連載】第三篇 跑馬燈

[復(fù)制鏈接]

2607

主題

2607

帖子

7472

積分

高級(jí)會(huì)員

Rank: 5Rank: 5

積分
7472
跳轉(zhuǎn)到指定樓層
樓主
發(fā)表于 2020-11-15 23:56:46 | 只看該作者 回帖獎(jiǎng)勵(lì) |倒序?yàn)g覽 |閱讀模式
【HarmonyOS HiSpark Wi-Fi IoT 套件試用連載】第三篇 跑馬燈, 弄了半天,VSCode中還是識(shí)別不了串口,只好放棄,采用Ubuntu中編譯,Windows中使用HiBurn來燒寫。



拿到開發(fā)板通常第一件事兒都是寫個(gè)helloWorld的程序,點(diǎn)個(gè)燈

我也不例外,搞了個(gè)跑馬燈。

代碼如下:

LED_demo.c





  • #include <stdio.h>
      
  • #include <unistd.h>
      
  • #include “ohos_init.h“
      
  • #include “cmsis_os2.h“
      
  • #include “wifiiot_gpio.h“
      
  • #include “wifiiot_gpio_ex.h“
      

  •   
  • #define LED_TASK_STACK_SIZE 512
      
  • #define LED_TASK_PRIO 25
      

  •   
  • enum LedState {
      
  •     LED_ON = 0,
      
  •     LED_OFF,
      
  •     LED_SPARK,
      
  • };
      
  • static void *LedTask(const char *arg)
      
  • {
      
  •     (void)arg;
      
  •     while (1) {
      
  •         GpioSetOutputVal(WIFI_IOT_IO_NAME_GPIO_10, 1);
      
  •         GpioSetOutputVal(WIFI_IOT_IO_NAME_GPIO_11, 0);
      
  •         GpioSetOutputVal(WIFI_IOT_IO_NAME_GPIO_12, 0);
      
  •         usleep(300000);
      
  •         GpioSetOutputVal(WIFI_IOT_IO_NAME_GPIO_10, 0);
      
  •         GpioSetOutputVal(WIFI_IOT_IO_NAME_GPIO_11, 0);
      
  •         GpioSetOutputVal(WIFI_IOT_IO_NAME_GPIO_12, 1);
      
  •         usleep(300000);
      
  •         GpioSetOutputVal(WIFI_IOT_IO_NAME_GPIO_10, 0);
      
  •         GpioSetOutputVal(WIFI_IOT_IO_NAME_GPIO_11, 1);
      
  •         GpioSetOutputVal(WIFI_IOT_IO_NAME_GPIO_12, 0);
      
  •         usleep(300000);
      
  •     }
      
  •     return NULL;
      
  • }
      

  •   
  • static void led_demo(void)
      
  • {
      
  •     osThreadAttr_t attr;
      
  •     GpioInit();
      
  •     IoSetFunc(WIFI_IOT_IO_NAME_GPIO_10, WIFI_IOT_IO_FUNC_GPIO_10_GPIO);
      
  •     IoSetFunc(WIFI_IOT_IO_NAME_GPIO_11, WIFI_IOT_IO_FUNC_GPIO_11_GPIO);
      
  •     IoSetFunc(WIFI_IOT_IO_NAME_GPIO_12, WIFI_IOT_IO_FUNC_GPIO_12_GPIO);
      
  •     GpioSetDir(WIFI_IOT_IO_NAME_GPIO_10, WIFI_IOT_GPIO_DIR_OUT);
      
  •     GpioSetDir(WIFI_IOT_IO_NAME_GPIO_11, WIFI_IOT_GPIO_DIR_OUT);
      
  •     GpioSetDir(WIFI_IOT_IO_NAME_GPIO_12, WIFI_IOT_GPIO_DIR_OUT);
      

  •   
  •     attr.name = “LedTask“;
      
  •     attr.attr_bits = 0U;
      
  •     attr.cb_mem = NULL;
      
  •     attr.cb_size = 0U;
      
  •     attr.stack_mem = NULL;
      
  •     attr.stack_size = LED_TASK_STACK_SIZE;
      
  •     attr.priority = LED_TASK_PRIO;
      

  •   
  •     if (osThreadNew((osThreadFunc_t)LedTask, NULL, &attr) == NULL) {
      
  •         printf(“[LedExample] Falied to create LedTask!\n“);
      
  •     }
      
  • }
      

  •   
  • SYS_RUN(led_demo);

復(fù)制代碼 led_demo文件夾中



BIULD.gn



  • # Copyright (c) 2020 Huawei Device Co., Ltd.
      
  • # Licensed under the Apache License, Version 2.0 (the “License“);
      
  • # you may not use this file except in compliance with the License.
      
  • # You may obtain a copy of the License at
      
  • #
      
  • #     http://www.apache.org/licenses/LICENSE-2.0
      
  • #
      
  • # Unless required by applicable law or agreed to in writing, software
      
  • # distributed under the License is distributed on an “AS IS“ BASIS,
      
  • # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
      
  • # See the License for the specific language governing permissions and
      
  • # limitations under the License.
      

  •   
  • static_library(“l(fā)ed_demo“) {
      
  •     sources = [
      
  •         “l(fā)ed_demo.c“
      
  •     ]
      

  •   
  •     include_dirs = [
      
  •         “//utils/native/lite/include“,
      
  •         “//kernel/liteos_m/components/cmsis/2.0“,
      
  •         “//base/iot_hardware/inteRFaces/kits/wifiiot_lite“,
      
  •     ]
      
  • }

復(fù)制代碼 同時(shí),也要將app文件夾中的編譯腳本文件BUILD.gn修改一下,在features中添加以下內(nèi)容:

“l(fā)ed_demo:led_demo“,



  • # Copyright (c) 2020 Huawei Device Co., Ltd.
      
  • # Licensed under the Apache License, Version 2.0 (the “License“);
      
  • # you may not use this file except in compliance with the License.
      
  • # You may obtain a copy of the License at
      
  • #
      
  • #     http://www.apache.org/licenses/LICENSE-2.0
      
  • #
      
  • # Unless required by applicable law or agreed to in writing, software
      
  • # distributed under the License is distributed on an “AS IS“ BASIS,
      
  • # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
      
  • # See the License for the specific language governing permissions and
      
  • # limitations under the License.
      

  •   
  • import(“//build/lite/config/component/lite_component.gni“)
      

  •   
  • lite_component(“app“) {
      
  •     features = [
      
  •         “startup“,
      
  •         “l(fā)ed_demo:led_demo“,
      
  •     ]
      
  • }

復(fù)制代碼 添加完之后,返回CODE-1.0目錄,在終端中輸入以下命令:python build.py wifiiot

編譯即可;

然后,返回Windows,用hiburn燒錄即可。

第三篇完結(jié),下一步,OLED,未完待續(xù)……

發(fā)表回復(fù)

本版積分規(guī)則


聯(lián)系客服 關(guān)注微信 下載APP 返回頂部 返回列表