当前位置:网站首页>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
边栏推荐
- qq机器人账号不能发送群消息,被风控
- C#/VB.NET:从PowerPoint文档中提取文本和图片
- Samsung's flagship discount is 1,800, Apple's discount is over 1,000, and the domestic flagship is only reduced by 500 to send beggars
- grafana对接本地ldap
- Mysql table structure change scheme comparison and analysis
- [免费专栏] Android安全之安卓APK浅析
- 【Unity3D】2D动画
- [免费专栏] Android安全之Android Studion 动态调试APK的两种方法
- Linux上给PHP安装redis扩展
- 2022.08.05_每日一题
猜你喜欢
随机推荐
PHP 变量注释/**@var*/
牛客网 Verilog 在线编程题库解答(VL1~VL10)
如何抑制告警风暴?
2021 RoboCom 世界机器人开发者大赛-本科组(决赛)
Go-Excelize API源码阅读(五)—— Close()
Swift -- 数组高阶函数
Swift--多条件排序
关于链表的操作
C#/VB.NET:从PowerPoint文档中提取文本和图片
Codesys结构变量编程应用(STRUCT类型)
Ng DevUI 周下载量突破1000啦!
Qt 5.12 LTS 部署
典型的数据仓库模型实施过程详解
数学建模——模拟退火
再次开始清理电子海图开发群中长期潜水人士
你应该试着独自做个游戏
How to stop the test after reaching a given number of errors during stress testing in JMeter
工大科雅深交所上市:市值45亿 齐承英家族是大股东
[] free column Android dynamic debugging GDB APP of safety
MYSQL物理存储文件的页和INNOBUF的页是否有大小区别?