电子产业一站式赋能平台

PCB联盟网

搜索
查看: 672|回复: 0
收起左侧

【HarmonyOS HiSpark Wi-Fi IoT 套件试用连载】第三篇 跑马灯

[复制链接]

2607

主题

2607

帖子

7472

积分

高级会员

Rank: 5Rank: 5

积分
7472
发表于 2020-11-15 23:56:46 | 显示全部楼层 |阅读模式
【HarmonyOS HiSpark Wi-Fi IoT 套件试用连载】第三篇 跑马灯, 弄了半天,VSCode中还是识别不了串口,只好放弃,采用Ubuntu中编译,Windows中使用HiBurn来烧写。



拿到开发板通常第一件事儿都是写个helloWorld的程序,点个灯

我也不例外,搞了个跑马灯。

代码如下:

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);

复制代码 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(“led_demo“) {
      
  •     sources = [
      
  •         “led_demo.c“
      
  •     ]
      

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

复制代码 同时,也要将app文件夹中的编译脚本文件BUILD.gn修改一下,在features中添加以下内容:

“led_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“,
      
  •         “led_demo:led_demo“,
      
  •     ]
      
  • }

复制代码 添加完之后,返回CODE-1.0目录,在终端中输入以下命令:python build.py wifiiot

编译即可;

然后,返回Windows,用hiburn烧录即可。

第三篇完结,下一步,OLED,未完待续……
回复

使用道具 举报

发表回复

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则


联系客服 关注微信 下载APP 返回顶部 返回列表