当前位置:网站首页>Openharmony Lightweight System Experiment--GPIO Lighting
Openharmony Lightweight System Experiment--GPIO Lighting
2022-08-09 21:36:00 【At siu-tong siu-tong】
This article mainly records the steps, problems and solutions of openharmony's GPIO lighting experiment;
Mainly follow Lian Zhian's tutorial: (6 messages) OpenHarmony lightweight system development [5] Driven GPIO lighting_Lian Zhian's blog-CSDN blog
I. Experimental steps
1. Create a new folder led_demo in the openharmony/code/master/master0805/applications/sample/wifi-iot/app directory;
And create a new led_demo.c file and BUILD.gn file in the led_demo folder;
2. Write led_demo.c program
#include //unist.h is a built-in header file of the linux/unix system and contains many prototypes of unix system service functions#include "stdio.h"#include "ohos_init.h"#include "cmsis_os2.h" // Standard header file, connected to each CMSIS-RTOS2 compatible RTOS,// This file defines the interface to CMSIS-RTOS#include "iot_gpio.h" #define LED_TEST_GPIO 9 // for hispark_pegasus void *LedTask(const char *arg){//Initialize GPIOIoTGpioInit(LED_TEST_GPIO); // set as outputIoTGpioSetDir(LED_TEST_GPIO, IOT_GPIO_DIR_OUT); (void)arg;while (1){//output low levelIoTGpioSetDir(LED_TEST_GPIO, 0);//The first parameter is pin GPIO9, the second parameter is: 0 output, 1 inputusleep(300000);//output high levelIoTGpioSetDir(LED_TEST_GPIO, 1);usleep(300000);} } return NULL;} void led_demo(void){osThreadAttr_t attr; attr.name = "LedTask";//The current task nameattr.attr_bits = 0U;attr.cb_mem = NULL;attr.cb_size = 0U;attr.stack_mem = NULL;attr.stack_size = 512;//The size of a stack of the entire taskattr.priority = 26;//The current task priority,//osThreadsNew will create a thread that will execute the LedTask taskif (osThreadNew((osThreadFunc_t)LedTask, NULL, &attr) == NULL) {printf("[LedExample] Failed to create LedTask!\n");} } }SYS_RUN(led_demo);//Don't forget to add this line of code// The macro that comes with the SYS_RUN system is to tell the project that the entry function of the business code is led_demo
3. Write the BUILD.gn file in the led_demo folder
(note that the header file path on the third line is added later)
static_library("led_demo") {sources = ["led_demo.c"]include_dirs = ["//utils/native/lite/include","//kernel/liteos_m/components/cmsis/2.0","//base/iothardware/peripheral/interfaces/inner_api",]}
4. Modify the BUILD.gn file in the app directory
The first led_demo refers to the led_demo folder name;
The led_demo after the colon refers to the led_demo.c file, without the .c suffix (I personally understand it)
import("//build/lite/config/component/lite_component.gni")lite_component("app") {features = ["led_demo:led_demo",]}
5. Compile --> Burn
Second, problems encountered
1, error: error: iot_gpio.h: No such file or directory
Cannot find iot_gpio.h header file
Reason: The version of the source code has changed (that is to say, when writing the BUILD.gn file in the led_demo folder, the path to add the header file is not the path provided by the source code of the previous version)
Solution: Enter find . -name iot_gpio.h to find the path to iot_gpio.h
Copy the found path to BUILD.gn;
Finally execute: hb build -f to compile
边栏推荐
- Swift -- 数组高阶函数
- IDEA tools commonly used configuration
- Flume (五) --------- 自定义 Interceptor、自定义 Source 与 自定义 Sink
- leetcode 503.下一个更大元素II 单调栈
- 《痞子衡嵌入式半月刊》 第 60 期
- MYSQL物理存储文件的页和INNOBUF的页是否有大小区别?
- YOLO v3 source, rounding
- 国产抗新冠口服药每瓶不超300元/ 我国IPv6网络全面建成/ 谷歌入局折叠屏手机...今日更多新鲜事在此...
- [免费专栏] Android安全之GDB动态调试APP
- 2022了你还不会『低代码』?数据科学也能玩转Low-Code啦!
猜你喜欢
随机推荐
pat链表专题训练+搜索专题
基于CC2530 E18-MS1-PCB Zigbee DIY作品(三)
numpy中nan_to_num如何使用
From functional testing to automated testing, do you know their shortcomings?
对应运放 RC 滤波负反馈的波形
AWS CodePipeLine 跨账号部署ECS
An overview of Office 365 Groups and how to create them
国产抗新冠口服药每瓶不超300元/ 我国IPv6网络全面建成/ 谷歌入局折叠屏手机...今日更多新鲜事在此...
IS31FL3737B 通用12×12 LED驱动器 I2C 42mA 40QFN
MySQL备份与恢复
史上最全架构师知识图谱(纯干货)
shell脚本基础语句使用(一)
最新BEV感知基线 | 你确定需要激光雷达?(卡内基梅隆大学)
Mysql table structure change scheme comparison and analysis
单调栈
Intensive reading of the paper: VIT - AN IMAGE IS WORTH 16X16 WORDS: TRANSFORMERS FOR IMAGE RECOGNITION AT SCALE
三星旗舰优惠千八,苹果优惠过千,国产旗舰只降五百打发叫花子
论文分享:「FED BN」使用LOCAL BATCH NORMALIZATION方法解决Non-iid问题
基于CC2530 E18-MS1-PCB Zigbee DIY作品(二)
宝塔面板安装使用