当前位置: 首页 > news >正文

Hi3861 OpenHarmony嵌入式应用入门--点灯

本篇实现对gpio的控制,通过控制输出进行gpio的点灯操作。

硬件

我们来操作IO2,控制绿色的灯。

软件

GPIO API

API名称

说明

hi_u32 hi_gpio_deinit(hi_void);

GPIO模块初始化

hi_u32 hi_io_set_pull(hi_io_name id, hi_io_pull val);

设置某个IO上下拉功能。

hi_u32 hi_gpio_set_dir(hi_gpio_idx id, hi_gpio_dir dir);

设置GPIO引脚方向,id参数用于指定引脚,dir参数用于指定输入或输出

hi_u32 hi_gpio_set_ouput_val(hi_gpio_idx id, hi_gpio_value val);

设置GPIO引脚的输出状态,id参数用于指定引脚,val参数用于指定高电平或低电平

hi_u32 hi_io_set_func(hi_io_name id, hi_u8 val);

设置引脚功能,id参数用于指定引脚,val用于指定引脚功能

hi_u32 hi_gpio_deinit(hi_void);

解除GPIO模块初始化

修改D:\DevEcoProjects\test\src\vendor\rtplay\rt_hi3861\demo\BUILD.gn文件,让工程编译led代码

# Copyright (c) 2023 Beijing HuaQing YuanJian Education Technology 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("demo") {features = ["base_01_led:base_led_example",]
}

创建D:\DevEcoProjects\test\src\vendor\rtplay\rt_hi3861\demo\base_01_led文件夹

文件夹中创建D:\DevEcoProjects\test\src\vendor\rtplay\rt_hi3861\demo\base_01_led\base_led_example.c文件D:\DevEcoProjects\test\src\vendor\rtplay\rt_hi3861\demo\base_01_led\BUILD.gn文件

# Copyright (c) 2023 Beijing HuaQing YuanJian Education Technology 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("base_led_example") {sources = ["base_led_example.c",]include_dirs = ["//utils/native/lite/include","//kernel/liteos_m/kal/cmsis","//base/iot_hardware/peripheral/interfaces/kits","//vendor/hqyj/fs_hi3861/common/bsp/include"]
}
/** Copyright (c) 2023 Beijing HuaQing YuanJian Education Technology 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 <stdio.h>
#include <unistd.h>#include "cmsis_os2.h"
#include "hi_gpio.h"
#include "hi_io.h"
#include "ohos_init.h"#define LED HI_IO_NAME_GPIO_2  // 开发板三色灯其中一个引脚osThreadId_t Task1_ID = 0;    //  任务1 ID
hi_gpio_value val, val_last;  // GPIO的状态值
#define TASK_STACK_SIZE 1024
#define TASK_DELAY_TIME (1000 * 1000)/*** @description: 任务1* @param {*}* @return {*}*/
void Task1(void)
{printf("enter Task 1.......\r\n");hi_gpio_init();                               // GPIO初始化hi_io_set_pull(LED, HI_IO_PULL_DOWN);         // 设置GPIO下拉,保证上电时为灭灯状态hi_io_set_func(LED, HI_IO_FUNC_GPIO_2_GPIO);  // 设置IO2为GPIO功能hi_gpio_set_dir(LED, HI_GPIO_DIR_OUT);        // 设置GPIO为输入模式while (1) {hi_gpio_set_ouput_val(LED, HI_GPIO_VALUE0);  // 设置GPIO引脚为低电平usleep(TASK_DELAY_TIME);                      // 1s sleephi_gpio_set_ouput_val(LED, HI_GPIO_VALUE1);  // 设置GPIO引脚为高电平usleep(TASK_DELAY_TIME);                      // 1s sleep}
}/*** @description: 初始化并创建任务* @param {*}* @return {*}*/
static void base_led_demo(void)
{printf("[demo] Enter base_led_demo()!\r\n");osThreadAttr_t taskOptions;taskOptions.name = "Task1";                // 任务的名字taskOptions.attr_bits = 0;                 // 属性位taskOptions.cb_mem = NULL;                 // 堆空间地址taskOptions.cb_size = 0;                   // 堆空间大小taskOptions.stack_mem = NULL;              // 栈空间地址taskOptions.stack_size = TASK_STACK_SIZE;  // 栈空间大小 单位:字节taskOptions.priority = osPriorityNormal;   // 任务的优先级:wqTask1_ID = osThreadNew((osThreadFunc_t)Task1, NULL, &taskOptions);  // 创建任务1if (Task1_ID != NULL) {printf("ID = %d, Create Task1_ID is OK!\r\n", Task1_ID);}
}
SYS_RUN(base_led_demo);

目录结构

│  config.json
│
├─common
│  └─bsp
│      ├─include
│      └─src
├─demo
│  │  BUILD.gn
│  │
│  ├─base_00_helloworld
│  │      base_helloworld_example.c
│  │      BUILD.gn
│  │
│  └─base_01_led
│          base_led_example.c
│          BUILD.gn
│
└─doc│  HarmonyOS开发板实验指导书 v2.1.pdf│  华清远见 FS_Hi3861开发指导.md│  华清远见 FS_Hi3861新手入门手册.md│├─board│      FS-Hi3861-V4.2.pdf│      FS-Hi3861QDB-V3.2.pdf│      hi-12f_kit_v1.1.0A7E6BCB9%A6-20211025.pdf│      hi-12f_v1.1.2-A7E6BCB9%A6-20211202.pdf│      nodemcu-hi-07s_12f-kit_v1.1-20210913.pdf│      RTplay2.01_2024-06-14.pdf│└─figures

使用build

效果就是LED间隔1秒闪烁。

http://www.lryc.cn/news/374882.html

相关文章:

  • SaaS案例分享:成功构建销售渠道的实战经验
  • 密钥管理简介
  • 2024中国应急(消防)品牌巡展成都站成功召开!
  • ansible-Role角色批量按照node_export节点,并追加信息到Prometheus文件中
  • 求最小公倍数 、小球走过路程计算 题目
  • 【Android面试八股文】你能说一说为什么IO是耗时操作?
  • 怎样增强 CLike 游戏的社交功能,促进玩家之间的互动和交流?
  • 12_YouOnlyLookOnce(YOLOv3)新一代实时目标检测技术
  • 安装 Nuxt.js 的步骤和注意事项
  • 【perl】环境搭建
  • 【车载音视频AI电脑】全国产海事船载视频监控系统解决方案
  • Centos SFTP搭建
  • 【中学教资科目二】01教育基础
  • 设计模式-享元模式Flyweight(结构型)
  • 【刷题】LeetCode刷题汇总
  • 树莓派pico入坑笔记,快捷键键盘制作
  • 华为鲲鹏应用开发基础:鲲鹏处理器及关键硬件特性介绍(二)
  • Vue.js结合ASP.NET Core构建用户登录与权限验证系统
  • 【html】如何利用id选择器实现主题切换
  • 服务器添加TLS域名证书核子之PKCS编解码
  • 使用 Selenium 自动化获取 CSDN 博客资源列表
  • 智能制造全闪解决方案,八大痛点,一网打尽
  • Python学习从0开始——Kaggle深度学习002
  • 比利时海外媒体宣发,发稿促进媒体通稿发布新形势-大舍传媒
  • 摄影构图:人像摄影和风景摄影的一些建议
  • 安卓实现输入快递单号生成二维码,摄像头扫描快递单号生成的二维码,可以得到快递信息
  • Mysql特殊用法分享
  • 一个开源的快速准确地将 PDF 转换为 markdown工具
  • 可通过小球进行旋转的十字光标(vtkResliceCursor)
  • python遍历文件夹并计算某类文件的数量,制图像文件到目标文件夹