`弄了半天,VSCode中还是识别不了串口,只好放弃,采用Ubuntu中编译,Windows中使用HiBurn来烧写。
拿到
开发板通常第一件事儿都是写个helloWorld的程序,点个灯
我也不例外,搞了个跑马灯。
代码如下:
led_demo.c
- #include
- #include
- #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!
- ");
- }
- }
- 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,未完待续……
`