描述
本文来源电子发烧友社区,作者:cszzlsw, 帖子地址:
https://bbs.elecfans.com/jishu_2006333_1_1.html继上一次开箱帖已经快过去两周了,不是楼主懒,实在是时间不足啊,事情太多了.看看这次咱们发现了些什么新的东西.1.编译环境搭建楼主所使用的环境是win10+wslwin10系统用来下载固件和编辑代码,wsl主要就是用做编译固件按照官网的文档:https://device.harmonyos.com/cn/ ... ld-0000001054781998一通安装,具体要安装什么东西官网说的很清楚了,这里就不浪费篇幅了,反正干嘛的先不知道,叫安那就安呗.前面都挺顺利,到最后下载的时候出问题,有个serialport怎么都安不上,直接折腾掉8小时以上真是叫人火大,后来实在搞不了了,论坛也找不到答案,微信群里也得不到答案耐着性子去看官方文档,结果就发现有一个步骤没有做,唉,真想给自己一耳光,具体见下:链接或贴图暂时没有,又找了一遍,没找到一通操作之后,就可以编译和下载固件了2.点灯眼尖的同学估计已经发现了,官方代码里面已经有点灯程序了.但是这个点灯程序会有点问题,后面再说首先还是祭出官方文档吧,官方文档第一篇叫你去联网,自己不走那套路直接看第二篇:https://device.harmonyos.com/cn/ ... rt-0000001050168544这个教程很重要,跟你讲怎么将自己的代码编译到最终的工程里去(心疼我那4个小时的瞎摸索,大家一定要仔细看文档).看懂了之后就在代码里面动刀子了,还好动的不大整完毕脚本之后,愉快的编译及下载,啊哦,怎么是蜂鸣器,不是灯啊说明io口错了.查看原理图(原理图下载链接:http://www.elecfans.com/soft/49/power/2020/202010221341380.html)到源码led_example.c里去.把所有的io_9改成11:
-
/*
-
* 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.
-
*/
-
-
#include
-
-
#include
-
-
#include "ohos_init.h"
-
#include "cmsis_os2.h"
-
#include "wifiiot_gpio.h"
-
#include "wifiiot_gpio_ex.h"
-
-
#define LED_INTERVAL_TIME_US 300000
-
#define LED_TASK_STACK_SIZE 512
-
#define LED_TASK_PRIO 25
-
-
enum LedState
-
{
-
LED_ON = 0,
-
LED_OFF,
-
LED_SPARK,
-
};
-
-
enum LedState g_ledState = LED_SPARK;
-
-
static void *LedTask(const char *arg)
-
{
-
(void)arg;
-
while (1)
-
{
-
switch (g_ledState)
-
{
-
case LED_ON:
-
GpioSetOutputVal(WIFI_IOT_IO_NAME_GPIO_11, 1);
-
usleep(LED_INTERVAL_TIME_US);
-
break;
-
case LED_OFF:
-
GpioSetOutputVal(WIFI_IOT_IO_NAME_GPIO_11, 0);
-
usleep(LED_INTERVAL_TIME_US);
-
break;
-
case LED_SPARK:
-
GpioSetOutputVal(WIFI_IOT_IO_NAME_GPIO_11, 0);
-
usleep(LED_INTERVAL_TIME_US);
-
GpioSetOutputVal(WIFI_IOT_IO_NAME_GPIO_11, 1);
-
usleep(LED_INTERVAL_TIME_US);
-
break;
-
default:
-
usleep(LED_INTERVAL_TIME_US);
-
break;
-
}
-
}
-
-
return NULL;
-
}
-
-
static void LedExampleEntry(void)
-
{
-
osThreadAttr_t attr;
-
printf("LedExampleEntry
-
");
-
GpioInit();
-
IoSetFunc(WIFI_IOT_IO_NAME_GPIO_11, WIFI_IOT_IO_FUNC_GPIO_11_GPIO);
-
GpioSetDir(WIFI_IOT_IO_NAME_GPIO_11, 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(LedExampleEntry);
复制代码
再来这次对了,一个绿油油的灯闪啊闪,成功,我们的wifiiot板子已经成功跟世界说出了"hello world"到此,第二篇帖子也水完了,小伙伴们,还犹豫什么,嗨起来.
打开APP阅读更多精彩内容