diff --git a/README_zh.md b/README_zh.md index a9e5666e5bcee798e97c2350486ffa1ed6bd22bd..957e5a636b812888b563edc81a0e9fa24cf2a539 100755 --- a/README_zh.md +++ b/README_zh.md @@ -1,21 +1,23 @@ ## docs 资料包目录结构 -| 目录名 | 描述 | -| --------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | + +| 目录名 | 描述 | +| --------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | | board | [小凌派-RK2206开发板原理图](/vendor/lockzhiner/rk2206/docs/board/硬件原理图/小凌派开发板原理图/小凌派开发板底板原理图.pdf)、[硬件资料](/vendor/lockzhiner/rk2206/docs/board/硬件原理图/小凌派开发板原理图)、[视频课程配套PPT](/vendor/lockzhiner/rk2206/docs/board/课程配套PPT) 等等 | -| datasheet | [数据手册](/vendor/lockzhiner/rk2206/docs/datasheet) | -| figures | 资料图库 | +| datasheet | [数据手册](/vendor/lockzhiner/rk2206/docs/datasheet) | +| figures | 资料图库 | ## 资料导航 -| No | 类别 | 路径 | -| ---- | -------------- | ------------------------------------------------------------ | -| 1 | 开发板硬件资料 | [硬件原理图](/vendor/lockzhiner/rk2206/docs/board/硬件原理图) | -| 2 | 快速上手教程 | [教程](/vendor/lockzhiner/rk2206/README_zh.md) | -| 3 | 案例代码列表 | [案例](/vendor/lockzhiner/rk2206/samples/README_zh.md) | -| 4 | 视频学习地址 | [视频地址](https://space.bilibili.com/1360647720/channel/seriesdetail?sid=2088027)
注意:网页跳转后请重新刷新才生效 | -| 5 | 视频课程PPT | [课程配套课件](/vendor/lockzhiner/rk2206/docs/board/课程配套课件) | -| 6 | 常见问题 | 暂无 | + +| No | 类别 | 路径 | +| --- | -------------- | ------------------------------------------------------------------------------------------------------------------------ | +| 1 | 开发板硬件资料 | [硬件原理图](/vendor/lockzhiner/rk2206/docs/board/硬件原理图) | +| 2 | 快速上手教程 | [教程](/vendor/lockzhiner/rk2206/README_zh.md) | +| 3 | 案例代码列表 | [案例](/vendor/lockzhiner/rk2206/samples/README_zh.md) | +| 4 | 视频学习地址 | [视频地址](https://space.bilibili.com/1360647720/channel/seriesdetail?sid=2088027)
注意:网页跳转后请重新刷新才生效 | +| 5 | 视频课程PPT | [课程配套课件](/vendor/lockzhiner/rk2206/docs/board/课程配套课件) | +| 6 | 常见问题 | 暂无 | ## 一、小凌派-RK2206开发板介绍 @@ -55,55 +57,62 @@ 例程列表如下所示: -| 编号 | 类别 | 例程名 | 说明 | -| ---- | --------- | ----------------------- | ---------------------------------------------------------------------------------------------------------- | -| A0 | 内核 | Hello World | [Hello World](/vendor/lockzhiner/rk2206/samples/a0_hello_world/README_zh.md) | -| A1 | 内核 | thread | [任务](/vendor/lockzhiner/rk2206/samples/a1_kernal_task/README_zh.md) | -| A2 | 内核 | semaphore | [信号量](/vendor/lockzhiner/rk2206/samples/a2_kernel_semaphore/README_zh.md) | -| A3 | 内核 | timer | [定时器](/vendor/lockzhiner/rk2206/samples/a3_kernel_timer/README_zh.md) | -| A4 | 内核 | mutex | [互斥锁](/vendor/lockzhiner/rk2206/samples/a4_kernel_mutex/README_zh.md) | -| A5 | 内核 | queue | [消息队列](/vendor/lockzhiner/rk2206/samples/a5_kernel_queue/README_zh.md) | -| A6 | 内核 | event | [事件](/vendor/lockzhiner/rk2206/samples/a6_kernel_event/README_zh.md) | -| A7 | 内核 | hal_file | [标准文件读写](/vendor/lockzhiner/rk2206/samples/a7_hal_file/README_zh.md) | -| A8 | 内核 | hal_pwm | [标准PWM控制](/vendor/lockzhiner/rk2206/samples/a8_hal_pwm/README_zh.md) | -| A9 | 内核 | hal_dir | [标准目录操作](/vendor/lockzhiner/rk2206/samples/a9_hal_dir/README_zh.md) | -| A10 | 内核 | kv_store | [分布式数据管理](/vendor/lockzhiner/rk2206/samples/a10_kv_store/README_zh.md) | -| B1 | 基础 | adc | [ADC按键检测](/vendor/lockzhiner/rk2206/samples/b1_adc/README_zh.md) | -| B2 | 基础 | nfc | [NFC标签](/vendor/lockzhiner/rk2206/samples/b2_nfc/README_zh.md) | -| B3 | 基础 | eeprom | [EEPROM测试](/vendor/lockzhiner/rk2206/samples/b3_eeprom/README_zh.md) | -| B4 | 基础 | lcd | [LCD显示](/vendor/lockzhiner/rk2206/samples/b4_lcd/README_zh.md) | -| B5 | 基础 | oled | [OLED显示](/vendor/lockzhiner/rk2206/samples/b5_oled/README_zh.md) | -| B6 | 基础 | uart0 | [UART打印](/vendor/lockzhiner/rk2206/samples/b6_uart0/README_zh.md) | -| B6 | 基础 | uart2 | [UART2收发](/vendor/lockzhiner/rk2206/samples/b6_uart2/README_zh.md) | -| B7 | 基础 | wifi_tcp | [TCP通信](/vendor/lockzhiner/rk2206/samples/b7_wifi_tcp/README_zh.md) | -| B8 | 基础 | wifi_udp | [UDP通信](/vendor/lockzhiner/rk2206/samples/b8_wifi_udp/README_zh.md) | -| B9 | 基础 | gpio | [GPIO控制](/vendor/lockzhiner/rk2206/samples/b9_gpio/README_zh.md) | -| B10 | 基础 | gpio_interrupt | [GPIO中断控制](/vendor/lockzhiner/rk2206/samples/b10_gpio_interrupt/README_zh.md) | -| B11 | 基础 | i2c_scan | [i2c扫描从设备](/vendor/lockzhiner/rk2206/samples/b11_i2c_scan/README_zh.md) | -| B12 | 基础 | watchdog | [看门狗控制](/vendor/lockzhiner/rk2206/samples/b12_watchdog/README_zh.md) | -| B13 | 基础 | reboot | [重启控制](/vendor/lockzhiner/rk2206/samples/b13_reboot/README_zh.md) | -| B14 | 基础 | wifi_ap | [WiFi路由模式](/vendor/lockzhiner/rk2206/samples/b14_wifi_ap/README_zh.md) | -| B15 | 基础 | flash | [Flash读写](/vendor/lockzhiner/rk2206/samples/b15_flash/README_zh.md) | -| C1 | E53传感器 | e53_ia_example | [智慧农业](/vendor/lockzhiner/rk2206/samples/c1_e53_intelligent_agriculture/README_zh.md) | -| C2 | E53传感器 | e53_sc_example | [智慧井盖](/vendor/lockzhiner/rk2206/samples/c2_e53_smart_covers/README_zh.md) | -| C3 | E53传感器 | e53_isl_example | [智慧路灯](/vendor/lockzhiner/rk2206/samples/c3_e53_intelligent_street_lamp/README_zh.md) | -| C4 | E53传感器 | e53_iv01_example | [智慧车载](/vendor/lockzhiner/rk2206/samples/c4_e53_intelligent_vehicle_01/README_zh.md) | -| C5 | E53传感器 | e53_bi_example | [人体感应](/vendor/lockzhiner/rk2206/samples/c5_e53_body_induction/README_zh.md) | -| C6 | E53传感器 | e53_gs_example | [智能手势](/vendor/lockzhiner/rk2206/samples/c6_e53_gesture_sensor/README_zh.md) | -| C7 | E53传感器 | e53_intelligent_smoke_sensor | [智慧烟感](/vendor/lockzhiner/rk2206/samples/c7_e53_intelligent_smoke_sensor/README_zh.md) | -| C8 | E53传感器 | e53_temperature_measurement | [红外温控](/vendor/lockzhiner/rk2206/samples/c8_e53_temperature_measurement/README_zh.md) | -| D2 | 物联网 | iot_cloud_sc_example | [基于华为IoT平台的智慧井盖](/vendor/lockzhiner/rk2206/samples/d2_iot_cloud_smart_covers/README_zh.md) | -| D3 | 物联网 | iot_cloud_isl_example | [基于华为IoT平台的智慧路灯](/vendor/lockzhiner/rk2206/samples/d3_iot_cloud_intelligent_street_lamp/README_zh.md) | -| D4 | 物联网 | iot_cloud_iv_example | [基于华为IoT平台的智慧车载](/vendor/lockzhiner/rk2206/samples/d4_iot_cloud_intelligent_vehicle/README_zh.md) | -| D5 | 物联网 | iot_cloud_bi_example | [基于华为IoT平台的人体感应](/vendor/lockzhiner/rk2206/samples/d5_iot_cloud_body_induction/README_zh.md) | -| D6 | 物联网 | iot_cloud_gs_example | [基于华为IoT平台的智能手势](/vendor/lockzhiner/rk2206/samples/d6_iot_cloud_gesture_sensor/README_zh.md) | -| D7 | 物联网 | iot_cloud_ia_example | [基于华为IoT平台的智慧农业](/vendor/lockzhiner/rk2206/samples/d7_iot_cloud_intelligent_agriculture/README_zh.md) | -| D8 | 物联网 | iot_cloud_TH | [基于通鸿IoT平台的数据通信](/vendor/lockzhiner/rk2206/samples/d8_iot_cloud_TH/README_zh.md) | + +| 编号 | 类别 | 例程名 | 说明 | +| ---- | --------- | ---------------------------- | ---------------------------------------------------------------------------------------------------------------- | +| A0 | 内核 | Hello World | [Hello World](/vendor/lockzhiner/rk2206/samples/a0_hello_world/README_zh.md) | +| A1 | 内核 | thread | [任务](/vendor/lockzhiner/rk2206/samples/a1_kernal_task/README_zh.md) | +| A2 | 内核 | semaphore | [信号量](/vendor/lockzhiner/rk2206/samples/a2_kernel_semaphore/README_zh.md) | +| A3 | 内核 | timer | [定时器](/vendor/lockzhiner/rk2206/samples/a3_kernel_timer/README_zh.md) | +| A4 | 内核 | mutex | [互斥锁](/vendor/lockzhiner/rk2206/samples/a4_kernel_mutex/README_zh.md) | +| A5 | 内核 | queue | [消息队列](/vendor/lockzhiner/rk2206/samples/a5_kernel_queue/README_zh.md) | +| A6 | 内核 | event | [事件](/vendor/lockzhiner/rk2206/samples/a6_kernel_event/README_zh.md) | +| A7 | 内核 | hal_file | [标准文件读写](/vendor/lockzhiner/rk2206/samples/a7_hal_file/README_zh.md) | +| A8 | 内核 | hal_pwm | [标准PWM控制](/vendor/lockzhiner/rk2206/samples/a8_hal_pwm/README_zh.md) | +| A9 | 内核 | hal_dir | [标准目录操作](/vendor/lockzhiner/rk2206/samples/a9_hal_dir/README_zh.md) | +| A10 | 内核 | kv_store | [分布式数据管理](/vendor/lockzhiner/rk2206/samples/a10_kv_store/README_zh.md) | +| B1 | 基础 | adc | [ADC按键检测](/vendor/lockzhiner/rk2206/samples/b1_adc/README_zh.md) | +| B2 | 基础 | nfc | [NFC标签](/vendor/lockzhiner/rk2206/samples/b2_nfc/README_zh.md) | +| B3 | 基础 | eeprom | [EEPROM测试](/vendor/lockzhiner/rk2206/samples/b3_eeprom/README_zh.md) | +| B4 | 基础 | lcd | [LCD显示](/vendor/lockzhiner/rk2206/samples/b4_lcd/README_zh.md) | +| B5 | 基础 | oled | [OLED显示](/vendor/lockzhiner/rk2206/samples/b5_oled/README_zh.md) | +| B6 | 基础 | uart0 | [UART打印](/vendor/lockzhiner/rk2206/samples/b6_uart0/README_zh.md) | +| B6 | 基础 | uart2 | [UART2收发](/vendor/lockzhiner/rk2206/samples/b6_uart2/README_zh.md) | +| B7 | 基础 | wifi_tcp | [TCP通信](/vendor/lockzhiner/rk2206/samples/b7_wifi_tcp/README_zh.md) | +| B8 | 基础 | wifi_udp | [UDP通信](/vendor/lockzhiner/rk2206/samples/b8_wifi_udp/README_zh.md) | +| B9 | 基础 | gpio | [GPIO控制](/vendor/lockzhiner/rk2206/samples/b9_gpio/README_zh.md) | +| B10 | 基础 | gpio_interrupt | [GPIO中断控制](/vendor/lockzhiner/rk2206/samples/b10_gpio_interrupt/README_zh.md) | +| B11 | 基础 | i2c_scan | [i2c扫描从设备](/vendor/lockzhiner/rk2206/samples/b11_i2c_scan/README_zh.md) | +| B12 | 基础 | watchdog | [看门狗控制](/vendor/lockzhiner/rk2206/samples/b12_watchdog/README_zh.md) | +| B13 | 基础 | reboot | [重启控制](/vendor/lockzhiner/rk2206/samples/b13_reboot/README_zh.md) | +| B14 | 基础 | wifi_ap | [WiFi路由模式](/vendor/lockzhiner/rk2206/samples/b14_wifi_ap/README_zh.md) | +| B15 | 基础 | flash | [Flash读写](/vendor/lockzhiner/rk2206/samples/b15_flash/README_zh.md) | +| B16 | 基础 | iot_pwm | [IOT库PWM控制](/vendor/lockzhiner/rk2206/samples/b16_iot_pwm/README_zh.md) | +| B17 | 基础 | iot_adc | [IOT库ADC控制](/vendor/lockzhiner/rk2206/samples/b17_iot_adc/README_zh.md) | +| B18 | 基础 | iot_gpio | [IOT库GPIO控制](/vendor/lockzhiner/rk2206/samples/b18_iot_gpio/README_zh.md) | +| B19 | 基础 | iot_gpio_int | [IOT库GPIO中断控制](/vendor/lockzhiner/rk2206/samples/b19_iot_gpio_int/README_zh.md) | +| B20 | 基础 | iot_uart | [IOT库UART控制](/vendor/lockzhiner/rk2206/samples/b20_iot_uart/README_zh.md) | +| C1 | E53传感器 | e53_ia_example | [智慧农业](/vendor/lockzhiner/rk2206/samples/c1_e53_intelligent_agriculture/README_zh.md) | +| C2 | E53传感器 | e53_sc_example | [智慧井盖](/vendor/lockzhiner/rk2206/samples/c2_e53_smart_covers/README_zh.md) | +| C3 | E53传感器 | e53_isl_example | [智慧路灯](/vendor/lockzhiner/rk2206/samples/c3_e53_intelligent_street_lamp/README_zh.md) | +| C4 | E53传感器 | e53_iv01_example | [智慧车载](/vendor/lockzhiner/rk2206/samples/c4_e53_intelligent_vehicle_01/README_zh.md) | +| C5 | E53传感器 | e53_bi_example | [人体感应](/vendor/lockzhiner/rk2206/samples/c5_e53_body_induction/README_zh.md) | +| C6 | E53传感器 | e53_gs_example | [智能手势](/vendor/lockzhiner/rk2206/samples/c6_e53_gesture_sensor/README_zh.md) | +| C7 | E53传感器 | e53_intelligent_smoke_sensor | [智慧烟感](/vendor/lockzhiner/rk2206/samples/c7_e53_intelligent_smoke_sensor/README_zh.md) | +| C8 | E53传感器 | e53_temperature_measurement | [红外温控](/vendor/lockzhiner/rk2206/samples/c8_e53_temperature_measurement/README_zh.md) | +| D2 | 物联网 | iot_cloud_sc_example | [基于华为IoT平台的智慧井盖](/vendor/lockzhiner/rk2206/samples/d2_iot_cloud_smart_covers/README_zh.md) | +| D3 | 物联网 | iot_cloud_isl_example | [基于华为IoT平台的智慧路灯](/vendor/lockzhiner/rk2206/samples/d3_iot_cloud_intelligent_street_lamp/README_zh.md) | +| D4 | 物联网 | iot_cloud_iv_example | [基于华为IoT平台的智慧车载](/vendor/lockzhiner/rk2206/samples/d4_iot_cloud_intelligent_vehicle/README_zh.md) | +| D5 | 物联网 | iot_cloud_bi_example | [基于华为IoT平台的人体感应](/vendor/lockzhiner/rk2206/samples/d5_iot_cloud_body_induction/README_zh.md) | +| D6 | 物联网 | iot_cloud_gs_example | [基于华为IoT平台的智能手势](/vendor/lockzhiner/rk2206/samples/d6_iot_cloud_gesture_sensor/README_zh.md) | +| D7 | 物联网 | iot_cloud_ia_example | [基于华为IoT平台的智慧农业](/vendor/lockzhiner/rk2206/samples/d7_iot_cloud_intelligent_agriculture/README_zh.md) | +| D8 | 物联网 | iot_cloud_TH | [基于通鸿IoT平台的数据通信](/vendor/lockzhiner/rk2206/samples/d8_iot_cloud_TH/README_zh.md) | ## 五、源码目录简介 小凌派的源码目录延续OpenHarmony官方目录结构,以下是源码目录的说明: + | 目录名 | 描述 | | ------------ | ------------------------------------- | | applications | 应用程序样例 | diff --git a/device/rockchip/rk2206/adapter/hals/iot_hardware/wifiiot_lite/hal_iot_uart.c b/device/rockchip/rk2206/adapter/hals/iot_hardware/wifiiot_lite/hal_iot_uart.c index 3f2ff0611f4865ac529ec9bd4d548d9f9cc5469a..49ad9316de84133b6f6d331ead42f6f7cc4365d9 100755 --- a/device/rockchip/rk2206/adapter/hals/iot_hardware/wifiiot_lite/hal_iot_uart.c +++ b/device/rockchip/rk2206/adapter/hals/iot_hardware/wifiiot_lite/hal_iot_uart.c @@ -130,7 +130,7 @@ int IoTUartRead(unsigned int id, unsigned char *data, unsigned int dataLen) if (id >= EUARTDEV_MAX) { - PRINT_ERR("id(%d) >= EI2CDEV_MAX(%d)\n", id, EUARTDEV_MAX); + PRINT_ERR("id(%d) >= EUARTDEV_MAX(%d)\n", id, EUARTDEV_MAX); return IOT_FAILURE; } @@ -145,7 +145,7 @@ int IoTUartWrite(unsigned int id, const unsigned char *data, unsigned int dataLe if (id >= EUARTDEV_MAX) { - PRINT_ERR("id(%d) >= EI2CDEV_MAX(%d)\n", id, EUARTDEV_MAX); + PRINT_ERR("id(%d) >= EUARTDEV_MAX(%d)\n", id, EUARTDEV_MAX); return IOT_FAILURE; } @@ -164,7 +164,7 @@ unsigned int IoTUartDeinit(unsigned int id) if (id >= EUARTDEV_MAX) { - PRINT_ERR("id(%d) >= EI2CDEV_MAX(%d)\n", id, EUARTDEV_MAX); + PRINT_ERR("id(%d) >= EUARTDEV_MAX(%d)\n", id, EUARTDEV_MAX); return IOT_FAILURE; } @@ -183,7 +183,7 @@ unsigned int IoTUartSetFlowCtrl(unsigned int id, IotFlowCtrl flowCtrl) if (id >= EUARTDEV_MAX) { - PRINT_ERR("id(%d) >= EI2CDEV_MAX(%d)\n", id, EUARTDEV_MAX); + PRINT_ERR("id(%d) >= EUARTDEV_MAX(%d)\n", id, EUARTDEV_MAX); return IOT_FAILURE; } diff --git a/vendor/lockzhiner/rk2206/samples/BUILD.gn b/vendor/lockzhiner/rk2206/samples/BUILD.gn index 32defa4fb72bdf04155b40402b522cbda1f274e4..925cc2d934ca0df3e1c4c16a889ee4eea22fb94c 100755 --- a/vendor/lockzhiner/rk2206/samples/BUILD.gn +++ b/vendor/lockzhiner/rk2206/samples/BUILD.gn @@ -44,6 +44,11 @@ lite_component("app") { #"./b13_reboot:reboot_example", #"./b14_wifi_ap:wifi_ap_example", #"./b15_flash:flash_example", + # "./b16_iot_pwm:iot_pwm_example", + # "./b17_iot_adc:iot_adc_example", + # "./b18_iot_gpio:iot_gpio_example", + # "./b19_iot_gpio_int:iot_gpio_int_example", + # "./b20_iot_uart:iot_uart_example", # E53模块 #"./c1_e53_intelligent_agriculture:e53_ia_example", diff --git a/vendor/lockzhiner/rk2206/samples/b16_iot_pwm/BUILD.gn b/vendor/lockzhiner/rk2206/samples/b16_iot_pwm/BUILD.gn new file mode 100755 index 0000000000000000000000000000000000000000..994edbba0146f3b7142f085edf81452f8682d61d --- /dev/null +++ b/vendor/lockzhiner/rk2206/samples/b16_iot_pwm/BUILD.gn @@ -0,0 +1,24 @@ +# Copyright (c) 2022 FuZhou Lockzhiner Electronic Co., Ltd. All rights reserved. +# 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("iot_pwm_example") { + sources = [ "iot_pwm_example.c" ] + + include_dirs = [ + "//utils/native/lite/include", + "//utils/native/lite/hals/file", + "//base/iot_hardware/peripheral/interfaces/kits", + ] + + deps = [ "//device/rockchip/hardware:hardware" ] +} diff --git a/vendor/lockzhiner/rk2206/samples/b16_iot_pwm/README_zh.md b/vendor/lockzhiner/rk2206/samples/b16_iot_pwm/README_zh.md new file mode 100755 index 0000000000000000000000000000000000000000..2ad731060045d4e5ef6f0b1b344181e28c9fe764 --- /dev/null +++ b/vendor/lockzhiner/rk2206/samples/b16_iot_pwm/README_zh.md @@ -0,0 +1,409 @@ +# 小凌派-RK2206开发板基础外设开发-PWM控制 + +## 实验内容 + +本例程演示如何在小凌派-RK2206开发板上使用IOT库的PWM接口,进行PWM编程开发。例程将创建一个任务,每隔5秒将PWM0~10依次启用,输出1000Hz。 + +![小凌派-RK2206开发板](/vendor/lockzhiner/rk2206/docs/figures/lockzhiner-rk2206.jpg) + +## 程序设计 + +PWM在日常设备中非常常见,以下我们将演示IOT库的PWM接口如何进行PWM控制。 + +### API分析 + +#### 头文件 + +```c +base/iot_hardware/peripheral/interfaces/kits/iot_pwm.h +``` + +#### 初始化PWM设备:IoTPwmInit + +```c +unsigned int IoTPwmInit(unsigned int port); +``` + +**描述:** + +初始化PWM设备。 + +**参数:** + + +| 参数 | 类型 | 描述 | +| ---- | ------------ | --------- | +| port | unsigned int | PWM端口号 | + +其中,port对应于如下表所示: + + +| port | GPIO | +| ---- | -------- | +| 0 | GPIO_PB4 | +| 1 | GPIO_PB5 | +| 2 | GPIO_PB6 | +| 3 | GPIO_PC0 | +| 4 | GPIO_PC1 | +| 5 | GPIO_PC2 | +| 6 | GPIO_PC3 | +| 7 | GPIO_PC4 | +| 8 | GPIO_PC5 | +| 9 | GPIO_PC6 | +| 10 | GPIO_PC7 | + +**返回值:** + + +| 返回值 | 描述 | +| ----------- | ---- | +| IOT_SUCCESS | 成功 | +| IOT_FAILURE | 失败 | + +**实现:** + +`hal_iot_pwm.c`文件在`device/rockchip/rk2206/adapter/hals/iot_hardware/wifiiot_lite`目录下。 + +```c +unsigned int IoTPwmInit(unsigned int port) +{ + unsigned int ret = 0; + + if (port >= EPWMDEV_MAX) { + PRINT_ERR("port(%d) >= EPWMDEV_MAX(%d)\n", port, EPWMDEV_MAX); + return IOT_FAILURE; + } + + PinctrlSet(m_pwm_bus_info[port].pwm_bus.pwm.gpio, + m_pwm_bus_info[port].pwm_bus.pwm.func, + m_pwm_bus_info[port].pwm_bus.pwm.type, + m_pwm_bus_info[port].pwm_bus.pwm.drv); + PwmIoInit(m_pwm_bus_info[port].pwm_bus); + LzPwmInit(m_pwm_bus_info[port].port); + + return IOT_SUCCESS; +} +``` + +#### 取消初始化PWM设备:IoTPwmDeinit + +```c +unsigned int IoTPwmDeinit(unsigned int port); +``` + +**描述:** + +取消初始化PWM设备。 + +**参数:** + + +| 参数 | 类型 | 描述 | +| ---- | ------------ | --------- | +| port | unsigned int | PWM端口号 | + +其中,port对应于如下表所示: + + +| port | GPIO | +| ---- | -------- | +| 0 | GPIO_PB4 | +| 1 | GPIO_PB5 | +| 2 | GPIO_PB6 | +| 3 | GPIO_PC0 | +| 4 | GPIO_PC1 | +| 5 | GPIO_PC2 | +| 6 | GPIO_PC3 | +| 7 | GPIO_PC4 | +| 8 | GPIO_PC5 | +| 9 | GPIO_PC6 | +| 10 | GPIO_PC7 | + +**返回值:** + + +| 返回值 | 描述 | +| ----------- | ---- | +| IOT_SUCCESS | 成功 | +| IOT_FAILURE | 失败 | + +**实现:** + +`hal_iot_pwm.c`文件在`device/rockchip/rk2206/adapter/hals/iot_hardware/wifiiot_lite`目录下。 + +```c +unsigned int IoTPwmDeinit(unsigned int port) +{ + if (port >= EPWMDEV_MAX) { + PRINT_ERR("port(%d) >= EPWMDEV_MAX(%d)\n", port, EPWMDEV_MAX); + return IOT_FAILURE; + } + + LzGpioDeinit(m_pwm_bus_info[port].pwm_bus.pwm.gpio); + + LzPwmDeinit(m_pwm_bus_info[port].port); + + return IOT_SUCCESS; +} +``` + +#### 开始PWM信号输出:IoTPwmStart + +```c +unsigned int IoTPwmStart(unsigned int port, unsigned short duty, unsigned int freq); +``` + +**描述:** + +开始PWM信号输出。 + +**参数:** + + +| 参数 | 类型 | 描述 | +| ---- | -------------- | -------------------------- | +| port | unsigned int | PWM端口号 | +| duty | unsigned short | 高电平的占空比,范围为1~99 | +| freq | unsigned int | 频率 | + +其中,port对应于如下表所示: + + +| port | GPIO | +| ---- | -------- | +| 0 | GPIO_PB4 | +| 1 | GPIO_PB5 | +| 2 | GPIO_PB6 | +| 3 | GPIO_PC0 | +| 4 | GPIO_PC1 | +| 5 | GPIO_PC2 | +| 6 | GPIO_PC3 | +| 7 | GPIO_PC4 | +| 8 | GPIO_PC5 | +| 9 | GPIO_PC6 | +| 10 | GPIO_PC7 | + +**返回值:** + + +| 返回值 | 描述 | +| ----------- | ---- | +| IOT_SUCCESS | 成功 | +| IOT_FAILURE | 失败 | + +**实现:** + +`hal_iot_pwm.c`文件在`device/rockchip/rk2206/adapter/hals/iot_hardware/wifiiot_lite`目录下。 + +```c +unsigned int IoTPwmStart(unsigned int port, unsigned short duty, unsigned int freq) +{ +#define DUTY_MIN 1 +#define DUTY_MAX 99 +#define SEC_TO_NSEC (1000000000UL) + unsigned int duty_ns; + unsigned int cycle_ns; + + if (port >= EPWMDEV_MAX) { + PRINT_ERR("port(%d) >= EPWMDEV_MAX(%d)\n", port, EPWMDEV_MAX); + return IOT_FAILURE; + } + if ((duty < DUTY_MIN) || (DUTY_MAX < duty)) { + PRINT_ERR("duty(%d) out of the range(%d ~ %d)\n", duty, DUTY_MIN, DUTY_MAX); + return IOT_FAILURE; + } + if (freq == 0) { + PRINT_ERR("freq(%d) is invalid!\n", freq); + return IOT_FAILURE; + } + if (freq > SEC_TO_NSEC) { + PRINT_ERR("freq(%d) > SEC_TO_NSEC(%d)\n", freq, SEC_TO_NSEC); + return IOT_FAILURE; + } + + cycle_ns = SEC_TO_NSEC / freq; + duty_ns = cycle_ns * duty / 100; + + LzPwmStart(m_pwm_bus_info[port].port, duty_ns, cycle_ns); + + return IOT_SUCCESS; +} +``` + +#### 停止PWM信号输出:IoTPwmStop + +```c +unsigned int IoTPwmStop(unsigned int port); +``` + +**描述:** + +停止PWM信号输出。 + +**参数:** + + +| 参数 | 类型 | 描述 | +| ---- | ------------ | --------- | +| port | unsigned int | PWM端口号 | + +其中,port对应于如下表所示: + + +| port | GPIO | +| ---- | -------- | +| 0 | GPIO_PB4 | +| 1 | GPIO_PB5 | +| 2 | GPIO_PB6 | +| 3 | GPIO_PC0 | +| 4 | GPIO_PC1 | +| 5 | GPIO_PC2 | +| 6 | GPIO_PC3 | +| 7 | GPIO_PC4 | +| 8 | GPIO_PC5 | +| 9 | GPIO_PC6 | +| 10 | GPIO_PC7 | + +**返回值:** + + +| 返回值 | 描述 | +| ----------- | ---- | +| IOT_SUCCESS | 成功 | +| IOT_FAILURE | 失败 | + +**实现:** + +`hal_iot_pwm.c`文件在`device/rockchip/rk2206/adapter/hals/iot_hardware/wifiiot_lite`目录下。 + +```c +unsigned int IoTPwmStop(unsigned int port) +{ + if (port >= EPWMDEV_MAX) { + PRINT_ERR("port(%d) >= EPWMDEV_MAX(%d)\n", port, EPWMDEV_MAX); + return IOT_FAILURE; + } + + LzPwmStart(m_pwm_bus_info[port].port, 0, 0); + + return IOT_SUCCESS; +} +``` + +### 软件设计 + +**主要代码分析** + +在`pwm_example`函数中,创建一个任务。 + +```c +void pwm_example() +{ + unsigned int thread_id; + TSK_INIT_PARAM_S task = {0}; + unsigned int ret = LOS_OK; + + task.pfnTaskEntry = (TSK_ENTRY_FUNC)pwm_thread; + task.uwStackSize = 2048; + task.pcName = "pwm_thread"; + task.usTaskPrio = 20; + ret = LOS_TaskCreate(&thread_id, &task); + if (ret != LOS_OK) { + printf("Falied to create pwm_thread ret:0x%x\n", ret); + return; + } +} +``` + +`pwm_thread`任务中调用IOT库的PWM接口控制PWM。 + +```c +void pwm_thread() +{ + unsigned int ret; + /* PWM端口号对应于参考文件: + * device/rockchip/rk2206/adapter/hals/iot_hardware/wifiiot_lite/hal_iot_pwm.c + */ + unsigned int port = 0; + + while (1) { + printf("===========================\n"); + printf("PWM(%d) Init\n", port); + ret = IoTPwmInit(port); + if (ret != 0) { + printf("IoTPwmInit failed(%d)\n"); + continue; + } + + printf("PWM(%d) Start\n", port); + ret = IoTPwmStart(port, 50, 1000); + if (ret != 0) { + printf("IoTPwmStart failed(%d)\n"); + continue; + } + + LOS_Msleep(5000); + + printf("PWM(%d) end\n", port); + ret = IoTPwmStop(port); + if (ret != 0) { + printf("IoTPwmStop failed(%d)\n"); + continue; + } + + ret = IoTPwmDeinit(port); + if (ret != 0) { + printf("IoTPwmInit failed(%d)\n"); + continue; + } + + printf("\n"); + + port++; + if (port >= 11) { + port = 0; + } + } +} +``` + +## 编译调试 + +### 修改 BUILD.gn 文件 + +修改 `vendor/lockzhiner/rk2206/sample` 路径下 BUILD.gn 文件,指定 `iot_pwm_example` 参与编译。 + +```r +"./b16_iot_pwm:iot_pwm_example", +``` + +修改 `device/lockzhiner/rk2206/sdk_liteos` 路径下 Makefile 文件,添加 `-liot_pwm_example` 参与编译。 + +```r +hardware_LIBS = -lhal_iothardware -lhardware -lshellcmd -liot_pwm_example +``` + +### 运行结果 + +示例代码编译烧录代码后,按下开发板的RESET按键,通过串口助手查看日志,任务每隔5s控制不同PWM输出。 + +```r +entering kernel init... +hilog will init. +[MAIN:D]Main: LOS_Start ... +Entering scheduler +OHOS # hiview init success.=========================== +PWM(0) Init +[GPIO:D]LzGpioInit: id 12 is initialized successfully +PWM(0) Start +PWM(0) end +[GPIO:D]LzGpioDeinit: id 12 is released successfully + +=========================== +PWM(1) Init +[GPIO:D]LzGpioInit: id 13 is initialized successfully +PWM(1) Start +PWM(1) end +[GPIO:D]LzGpioDeinit: id 13 is released successfully +... +``` diff --git a/vendor/lockzhiner/rk2206/samples/b16_iot_pwm/iot_pwm_example.c b/vendor/lockzhiner/rk2206/samples/b16_iot_pwm/iot_pwm_example.c new file mode 100755 index 0000000000000000000000000000000000000000..fac2d386ad8eb7ba5eb47b68a6862ae3f4f4124b --- /dev/null +++ b/vendor/lockzhiner/rk2206/samples/b16_iot_pwm/iot_pwm_example.c @@ -0,0 +1,101 @@ +/* + * Copyright (c) 2025 FuZhou Lockzhiner Electronic Co., Ltd. All rights reserved. + * 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 "los_task.h" +#include "ohos_init.h" + +#include "iot_pwm.h" +#include "iot_errno.h" + +#include + +/*************************************************************** + * 函数名称: pwm_thread + * 说 明: 控制PWM线程函数 + * 参 数: 无 + * 返 回 值: 无 + ***************************************************************/ +void pwm_thread() +{ + unsigned int ret; + /* PWM端口号对应于参考文件: + * device/rockchip/rk2206/adapter/hals/iot_hardware/wifiiot_lite/hal_iot_pwm.c + */ + unsigned int port = 0; + + while (1) { + printf("===========================\n"); + printf("PWM(%d) Init\n", port); + ret = IoTPwmInit(port); + if (ret != 0) { + printf("IoTPwmInit failed(%d)\n"); + continue; + } + + printf("PWM(%d) Start\n", port); + ret = IoTPwmStart(port, 50, 1000); + if (ret != 0) { + printf("IoTPwmStart failed(%d)\n"); + continue; + } + + LOS_Msleep(5000); + + printf("PWM(%d) end\n", port); + ret = IoTPwmStop(port); + if (ret != 0) { + printf("IoTPwmStop failed(%d)\n"); + continue; + } + + ret = IoTPwmDeinit(port); + if (ret != 0) { + printf("IoTPwmInit failed(%d)\n"); + continue; + } + + printf("\n"); + + port++; + if (port >= 11) { + port = 0; + } + } +} + +/*************************************************************** + * 函数名称: pwm_example + * 说 明: pwm控制入口函数 + * 参 数: 无 + * 返 回 值: 无 + ***************************************************************/ +void pwm_example() +{ + unsigned int thread_id; + TSK_INIT_PARAM_S task = {0}; + unsigned int ret = LOS_OK; + + task.pfnTaskEntry = (TSK_ENTRY_FUNC)pwm_thread; + task.uwStackSize = 2048; + task.pcName = "pwm_thread"; + task.usTaskPrio = 20; + ret = LOS_TaskCreate(&thread_id, &task); + if (ret != LOS_OK) { + printf("Falied to create pwm_thread ret:0x%x\n", ret); + return; + } +} + +APP_FEATURE_INIT(pwm_example); diff --git a/vendor/lockzhiner/rk2206/samples/b17_iot_adc/BUILD.gn b/vendor/lockzhiner/rk2206/samples/b17_iot_adc/BUILD.gn new file mode 100755 index 0000000000000000000000000000000000000000..e6440540b815355d66ad30de8f68fd2b49dffe49 --- /dev/null +++ b/vendor/lockzhiner/rk2206/samples/b17_iot_adc/BUILD.gn @@ -0,0 +1,24 @@ +# Copyright (c) 2022 FuZhou Lockzhiner Electronic Co., Ltd. All rights reserved. +# 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("iot_adc_example") { + sources = [ "iot_adc_example.c" ] + + include_dirs = [ + "//utils/native/lite/include", + "//utils/native/lite/hals/file", + "//base/iot_hardware/peripheral/interfaces/kits", + ] + + deps = [ "//device/rockchip/hardware:hardware" ] +} diff --git a/vendor/lockzhiner/rk2206/samples/b17_iot_adc/README_zh.md b/vendor/lockzhiner/rk2206/samples/b17_iot_adc/README_zh.md new file mode 100755 index 0000000000000000000000000000000000000000..21b6e36dd9b86fede1d00401b5d7d6cd14b26905 --- /dev/null +++ b/vendor/lockzhiner/rk2206/samples/b17_iot_adc/README_zh.md @@ -0,0 +1,342 @@ +# 小凌派-RK2206开发板基础外设开发——ADC控制 + +## 实验内容 + +本示例将演示如何在小凌派-RK2206开发板上使用IOT库的ADC接口,进行ADC编程开发。例程将创建一个任务,读取按键的ADC值,并打印到串口。 + +![小凌派-RK2206](/vendor/lockzhiner/rk2206/docs/figures/lockzhiner-rk2206.jpg) + +## 程序设计 + +ADC在日常设备中非常常见,以下我们将演示IOT库的ADC接口如何进行读取按键的ADC值,并打印到串口。 + +### API分析 + +#### 头文件 + +```c +base/iot_hardware/peripheral/interfaces/kits/iot_adc.h +``` + +### 初始化ADC设备:IoTAdcInit + +```c +unsigned int IoTAdcInit(unsigned int id); +``` + +**描述:** + +初始化ADC设备。 + +**参数:** + + +| 参数 | 类型 | 描述 | +| ---- | ------------ | ------- | +| id | unsigned int | ADC通道 | + +ADC通道有7个,对应以下7个引脚: + + +| id | GPIO | +| -- | --------- | +| 0 | GPIO0_PC0 | +| 1 | GPIO0_PC1 | +| 2 | GPIO0_PC2 | +| 3 | GPIO0_PC3 | +| 4 | GPIO0_PC4 | +| 5 | GPIO0_PC5 | +| 6 | GPIO0_PC6 | +| 7 | GPIO0_PC7 | + +**返回值:** + + +| 返回值 | 描述 | +| ----------- | ---- | +| IOT_SUCCESS | 成功 | +| IOT_FAILURE | 失败 | + +**实现:** + +`hal_iot_adc.c`文件在`device/rockchip/rk2206/adapter/hals/iot_hardware/wifiiot_lite`目录下。 + +```c +unsigned int IoTAdcInit(unsigned int id) { + + unsigned int ret = 0; + uint32_t *pGrfSocCon29 = (uint32_t *)(0x41050000U + 0x274U); + uint32_t ulValue; + + if (id < 0 || id > 7) { + PRINT_ERR("id(%d) > 7 or id(%d) < 0\n", id, id); + return IOT_FAILURE; + } + + m_adcKey.ctrl1.gpio = GPIO0_PC0 + id; + + ret = DevIoInit(m_adcKey); + if (ret != LZ_HARDWARE_SUCCESS) { + PRINT_ERR("%s, %s, %d: ADC Key IO Init fail\n", __FILE__, __func__, + __LINE__); + return IOT_FAILURE; + } + + /* LzSaradcInit 接口只要初始化一次 */ + if(!init_adc_cnt) { + ret = LzSaradcInit(); + if (ret != LZ_HARDWARE_SUCCESS) { + PRINT_ERR("%s, %s, %d: ADC Init fail\n", __FILE__, __func__, __LINE__); + return IOT_FAILURE; + } + } + + /* 记录调用该接口次数 */ + init_adc_cnt++; + + /* 设置saradc的电压信号,选择AVDD */ + ulValue = *pGrfSocCon29; + ulValue &= ~(0x1 << 4); + ulValue |= ((0x1 << 4) << 16); + *pGrfSocCon29 = ulValue; + + return IOT_SUCCESS; +} +``` + +### 取消初始化ADC设备:IoTAdcDeinit + +```c +unsigned int IoTAdcDeinit(unsigned int id); +``` + +**描述:** + +取消初始化ADC设备。 + + +| 参数 | 类型 | 描述 | +| ---- | ------------ | ------- | +| id | unsigned int | ADC通道 | + +ADC通道有7个,对应以下7个引脚: + + +| id | GPIO | +| -- | --------- | +| 0 | GPIO0_PC0 | +| 1 | GPIO0_PC1 | +| 2 | GPIO0_PC2 | +| 3 | GPIO0_PC3 | +| 4 | GPIO0_PC4 | +| 5 | GPIO0_PC5 | +| 6 | GPIO0_PC6 | +| 7 | GPIO0_PC7 | + +**返回值:** + + +| 返回值 | 描述 | +| ----------- | ---- | +| IOT_SUCCESS | 成功 | +| IOT_FAILURE | 失败 | + +**实现:** + +`hal_iot_adc.c`文件在`device/rockchip/rk2206/adapter/hals/iot_hardware/wifiiot_lite`目录下。 + +```c +unsigned int IoTAdcDeinit(unsigned int id) { + + unsigned int ret = 0; + + if (id < 0 || id > 7) { + PRINT_ERR("id(%d) > 7 or id(%d) < 0\n", id, id); + return IOT_FAILURE; + } + + m_adcKey.ctrl1.gpio = GPIO0_PC0 + id; + + LzGpioDeinit(m_adcKey.ctrl1.gpio); + init_adc_cnt--; + + /* 当 init_adc_cnt 为 0 调用 LzSaradcDeinit 注销 */ + if(!init_adc_cnt) { + ret = LzSaradcDeinit(); + if (ret != LZ_HARDWARE_SUCCESS) { + PRINT_ERR("%s, %s, %d: ADC Deinit Fail\n", __FILE__, __func__, __LINE__); + return IOT_FAILURE; + } + } + + return IOT_SUCCESS; +} +``` + +### 获取ADC设备的值:IoTAdcGetVal + +```c +unsigned int IoTAdcGetVal(unsigned int id, unsigned int *val); +``` + +**描述:** + +获取ADC设备的值。 + +**参数:** + +| 参数 | 类型 | 描述 | +| ------------- | -------------- | -------- | +| id | unsigned int | ADC通道 | +| val | unsigned int * | 数据指针 | + +ADC通道有7个,对应以下7个引脚: + + +| id | GPIO | +| -- | --------- | +| 0 | GPIO0_PC0 | +| 1 | GPIO0_PC1 | +| 2 | GPIO0_PC2 | +| 3 | GPIO0_PC3 | +| 4 | GPIO0_PC4 | +| 5 | GPIO0_PC5 | +| 6 | GPIO0_PC6 | +| 7 | GPIO0_PC7 | + +**返回值:** + + +| 返回值 | 描述 | +| ----------- | ---- | +| IOT_SUCCESS | 成功 | +| IOT_FAILURE | 失败 | + +**实现:** + +`hal_iot_adc.c`文件在`device/rockchip/rk2206/adapter/hals/iot_hardware/wifiiot_lite`目录下。 + +```c +unsigned int IoTAdcGetVal(unsigned int id, unsigned int *val) { + + unsigned int ret = 0; + + if (id < 0 || id > 7) { + PRINT_ERR("id(%d) > 7 or id(%d) < 0\n", id, id); + return IOT_FAILURE; + } + + ret = LzSaradcReadValue(id, val); + + if (ret != LZ_HARDWARE_SUCCESS) { + PRINT_ERR("%s, %s, %d: ADC Read Fail\n", __FILE__, __func__, __LINE__); + return IOT_FAILURE; + } + + return IOT_SUCCESS; +} +``` + +### 软件设计 + +**主要代码分析** + +在`adc_example`函数中,创建一个任务。 + +```c +void adc_example() +{ + unsigned int thread_id; + TSK_INIT_PARAM_S task = {0}; + unsigned int ret = LOS_OK; + + task.pfnTaskEntry = (TSK_ENTRY_FUNC)adc_thread; + task.uwStackSize = 2048; + task.pcName = "adc_thread"; + task.usTaskPrio = 24; + ret = LOS_TaskCreate(&thread_id, &task); + if (ret != LOS_OK) { + printf("Falied to create adc_thread ret:0x%x\n", ret); + return; + } +} +``` + +`adc_thread`任务中调用IOT库的ADC接口控制ADC。 + +```c +void adc_thread() +{ + unsigned int data = 0; + float voltage = 0; + unsigned int ret = 0; + + /* 初始化adc设备 */ + ret = IoTAdcInit(ADC_CHANNEL); + if (ret == IOT_FAILURE) { + printf("%s, %s, %d: ADC Key IO Init fail\n", __FILE__, __func__, __LINE__); + } + + while (1) { + printf("***************Adc Example*************\r\n"); + /*获取电压值*/ + ret = IoTAdcGetVal(ADC_CHANNEL, &data); + if (ret == IOT_FAILURE) { + printf("%s, %s, %d: ADC Read Fail\n", __FILE__, __func__, __LINE__); + return 0.0; + } + voltage = (float)(data * 3.3 / 1024.0); + printf("vlt:%.3fV\n", voltage); + + /* 睡眠1秒 */ + LOS_Msleep(1000); + } +} +``` + +ADC模块采用10位的ADC采集寄存器,可测试电压范围为0~3.3V,所以ADC采集数值换算为实际电压计算公司为: + +```r +实际电压 = (ADC采集数值 / 1024) * 3.3V +``` + +注意:实际电压是 `float`类型,源代码计算要规范。具体源代码如下所示: + +```c +return (float)(data * 3.3 / 1024.0) +``` + +## 编译调试 + +### 修改 BUILD.gn 文件 + +修改 `vendor/lockzhiner/rk2206/sample` 路径下 BUILD.gn 文件,指定 `iot_adc_example` 参与编译。 + +```r +"./b17_iot_adc:iot_adc_example", +``` + +修改 `device/lockzhiner/rk2206/sdk_liteos` 路径下 Makefile 文件,添加 `-liot_adc_example` 参与编译。 + +```r +hardware_LIBS = -lhal_iothardware -lhardware -lshellcmd -liot_adc_example +``` + +### 运行结果 + +示例代码编译烧录代码后,按下开发板的RESET按键,通过串口助手查看日志,显示如下: + +```r +***************Adc Example************* +vlt:3.297V +***************Adc Example************* +vlt:3.297V +***************Adc Example************* +vlt:3.297V +***************Adc Example************* +vlt:3.297V +***************Adc Example************* +vlt:3.297V +***************Adc Example************* +vlt:3.297V +``` diff --git a/vendor/lockzhiner/rk2206/samples/b17_iot_adc/iot_adc_example.c b/vendor/lockzhiner/rk2206/samples/b17_iot_adc/iot_adc_example.c new file mode 100644 index 0000000000000000000000000000000000000000..c414c3f18ba653d447979dfb2be3ff7bac8188f7 --- /dev/null +++ b/vendor/lockzhiner/rk2206/samples/b17_iot_adc/iot_adc_example.c @@ -0,0 +1,84 @@ +/* + * Copyright (c) 2025 FuZhou Lockzhiner Electronic Co., Ltd. All rights reserved. + * 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 "los_task.h" +#include "ohos_init.h" + +#include "iot_adc.h" +#include "iot_errno.h" + +#include + +/* 定义ADC的通道号 */ +#define ADC_CHANNEL 5 + +/*************************************************************** + * 函数名称: adc_thread + * 说 明: ADC采集循环任务 + * 参 数: 无 + * 返 回 值: 无 + ***************************************************************/ +void adc_thread() +{ + unsigned int data = 0; + float voltage = 0; + unsigned int ret = 0; + + /* 初始化adc设备 */ + ret = IoTAdcInit(ADC_CHANNEL); + if (ret == IOT_FAILURE) { + printf("%s, %s, %d: ADC Key IO Init fail\n", __FILE__, __func__, __LINE__); + } + + while (1) { + printf("***************Adc Example*************\r\n"); + /*获取电压值*/ + ret = IoTAdcGetVal(ADC_CHANNEL, &data); + if (ret == IOT_FAILURE) { + printf("%s, %s, %d: ADC Read Fail\n", __FILE__, __func__, __LINE__); + return 0.0; + } + voltage = (float)(data * 3.3 / 1024.0); + printf("vlt:%.3fV\n", voltage); + + /* 睡眠1秒 */ + LOS_Msleep(1000); + } +} + +/*************************************************************** + * 函数名称: adc_example + * 说 明: 开机自启动调用函数 + * 参 数: 无 + * 返 回 值: 无 + ***************************************************************/ +void adc_example() +{ + unsigned int thread_id; + TSK_INIT_PARAM_S task = {0}; + unsigned int ret = LOS_OK; + + task.pfnTaskEntry = (TSK_ENTRY_FUNC)adc_thread; + task.uwStackSize = 2048; + task.pcName = "adc_thread"; + task.usTaskPrio = 24; + ret = LOS_TaskCreate(&thread_id, &task); + if (ret != LOS_OK) { + printf("Falied to create adc_thread ret:0x%x\n", ret); + return; + } +} + +APP_FEATURE_INIT(adc_example); \ No newline at end of file diff --git a/vendor/lockzhiner/rk2206/samples/b18_iot_gpio/BUILD.gn b/vendor/lockzhiner/rk2206/samples/b18_iot_gpio/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..44057f1141bf4189c6470a50236e992a2328577b --- /dev/null +++ b/vendor/lockzhiner/rk2206/samples/b18_iot_gpio/BUILD.gn @@ -0,0 +1,24 @@ +# Copyright (c) 2022 FuZhou Lockzhiner Electronic Co., Ltd. All rights reserved. +# 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("iot_gpio_example") { + sources = [ "iot_gpio_example.c" ] + + include_dirs = [ + "//utils/native/lite/include", + "//utils/native/lite/hals/file", + "//base/iot_hardware/peripheral/interfaces/kits", + ] + + deps = [ "//device/rockchip/hardware:hardware" ] +} diff --git a/vendor/lockzhiner/rk2206/samples/b18_iot_gpio/README_zh.md b/vendor/lockzhiner/rk2206/samples/b18_iot_gpio/README_zh.md new file mode 100644 index 0000000000000000000000000000000000000000..0970a2c5be01d13d9a2fd6132913440a33d1207f --- /dev/null +++ b/vendor/lockzhiner/rk2206/samples/b18_iot_gpio/README_zh.md @@ -0,0 +1,472 @@ +# 小凌派-RK2206开发板基础外设开发——GPIO控制 + +## 实验内容 + +本示例将演示如何在小凌派-RK2206开发板上使用IOT库的GPIO接口,进行GPIO编程开发。例程将创建一个任务,通过配置GPIO引脚,实现GPIO读写操作。 + +![小凌派-RK2206开发板](/vendor/lockzhiner/rk2206/docs/figures/lockzhiner-rk2206.jpg) + +## 程序设计 + +GPIO在日常设备中非常常见,以下我们将演示IOT库的GPIO接口如何进行GPIO口配置,以及GPIO口读写操作。 + +### API分析 + +#### 头文件 + +```c +base/iot_hardware/peripheral/interfaces/kits/iot_gpio.h +``` + +#### 初始化GPIO设备:IoTGpioInit + +```c +unsigned int IoTGpioInit(unsigned int id); +``` + +**描述:** + +初始化GPIO设备。 + +**参数:** + +| 参数 | 类型 | 描述 | +| ---- | ------------ | ---------- | +| id | unsigned int | GPIOID编号 | + +**返回值:** + + +| 返回值 | 描述 | +| ----------- | ---- | +| IOT_SUCCESS | 成功 | +| IOT_FAILURE | 失败 | + +**实现:** + +`hal_iot_gpio.c`文件在`device/rockchip/rk2206/adapter/hals/iot_hardware/wifiiot_lite`目录下。 + +```c +unsigned int IoTGpioInit(unsigned int id) +{ + unsigned int ret = 0; + + if (id > GPIO0_PC7 && id != GPIO1_PD0) { + PRINT_ERR("id(%d) > %d || id(%d) != %d\n", id, GPIO0_PC7, GPIO1_PD0); + return IOT_FAILURE; + } + + ret = LzGpioInit(id); + if (ret != LZ_HARDWARE_SUCCESS) { + return IOT_FAILURE; + } + + ret = PinctrlSet(id, MUX_FUNC0, PULL_KEEP, DRIVE_LEVEL0); + if (ret != LZ_HARDWARE_SUCCESS) { + return IOT_FAILURE; + } + + return IOT_SUCCESS; +} +``` + +#### 取消初始化GPIO设备:IoTGpioDeinit + +```c +unsigned int IoTGpioDeinit(unsigned int id); +``` + +**描述:** + +取消初始化GPIO设备。 + +**参数:** + +| 参数 | 类型 | 描述 | +| ---- | ------------ | ---------- | +| id | unsigned int | GPIOID编号 | + +**返回值:** + + +| 返回值 | 描述 | +| ----------- | ---- | +| IOT_SUCCESS | 成功 | +| IOT_FAILURE | 失败 | + +**实现:** + +`hal_iot_gpio.c`文件在`device/rockchip/rk2206/adapter/hals/iot_hardware/wifiiot_lite`目录下。 + +```c +unsigned int IoTGpioDeinit(unsigned int id) +{ + unsigned int ret = 0; + + if (id > GPIO0_PC7 && id != GPIO1_PD0) { + PRINT_ERR("id(%d) > %d || id(%d) != %d\n", id, GPIO0_PC7, GPIO1_PD0); + return IOT_FAILURE; + } + + ret = LzGpioDeinit(id); + if (ret != LZ_HARDWARE_SUCCESS) { + return IOT_FAILURE; + } + + return IOT_SUCCESS; +} +``` + +#### 设置GPIO引脚的方向:IoTGpioSetDir + +```c +unsigned int IoTGpioSetDir(unsigned int id, IotGpioDir dir); +``` + +**描述:** + +设置GPIO引脚的方向。 + +**参数:** + +| 参数 | 类型 | 描述 | +| ---- | ------------ | ---------- | +| id | unsigned int | GPIOID编号 | +| dir | IotGpioDir | GPIO方向 | + +其中,dir对应于如下表所示: + +| IotGpioDir | 描述 | +| ---------------- | ---- | +| IOT_GPIO_DIR_IN | 输入 | +| IOT_GPIO_DIR_OUT | 输出 | + + +**返回值:** + + +| 返回值 | 描述 | +| ----------- | ---- | +| IOT_SUCCESS | 成功 | +| IOT_FAILURE | 失败 | + +**实现:** + +`hal_iot_gpio.c`文件在`device/rockchip/rk2206/adapter/hals/iot_hardware/wifiiot_lite`目录下。 + +```c +unsigned int IoTGpioSetDir(unsigned int id, IotGpioDir dir) +{ + unsigned int ret = 0; + + if (id > GPIO0_PC7 && id != GPIO1_PD0) { + PRINT_ERR("id(%d) > %d || id(%d) != %d\n", id, GPIO0_PC7, GPIO1_PD0); + return IOT_FAILURE; + } + + ret = LzGpioSetDir(id, (LzGpioDir)dir); + if (ret != LZ_HARDWARE_SUCCESS) { + return IOT_FAILURE; + } + + return IOT_SUCCESS; +} +``` + +#### 获取GPIO引脚的方向:IoTGpioGetDir + +```c +unsigned int IoTGpioGetDir(unsigned int id, IotGpioDir *dir); +``` + +**描述:** + +获取GPIO引脚的方向。 + +**参数:** + +| 参数 | 类型 | 描述 | +| ---- | ------------ | ------------ | +| id | unsigned int | GPIOID编号 | +| dir | IotGpioDir * | GPIO方向指针 | + +**返回值:** + + +| 返回值 | 描述 | +| ----------- | ---- | +| IOT_SUCCESS | 成功 | +| IOT_FAILURE | 失败 | + +**实现:** + +`hal_iot_gpio.c`文件在`device/rockchip/rk2206/adapter/hals/iot_hardware/wifiiot_lite`目录下。 + +```c +unsigned int IoTGpioGetDir(unsigned int id, IotGpioDir *dir) +{ + unsigned int ret = 0; + + if (id > GPIO0_PC7 && id != GPIO1_PD0) { + PRINT_ERR("id(%d) > %d || id(%d) != %d\n", id, GPIO0_PC7, GPIO1_PD0); + return IOT_FAILURE; + } + + ret = LzGpioGetDir(id, (LzGpioDir *)dir); + if (ret != LZ_HARDWARE_SUCCESS) { + return IOT_FAILURE; + } + + return IOT_SUCCESS; +} +``` + +#### 设置GPIO引脚的输出电平值:IoTGpioSetOutputVal + +```c +unsigned int IoTGpioSetOutputVal(unsigned int id, IotGpioValue val); +``` + +**描述:** + +设置GPIO引脚的输出电平值。 + +**参数:** + +| 参数 | 类型 | 描述 | +| ---- | ------------ | ---------- | +| id | unsigned int | GPIOID编号 | +| val | IotGpioValue | 电平 | + +其中,val对应于如下表所示: + +| IotGpioValue | 描述 | +| --------------- | ------ | +| IOT_GPIO_VALUE0 | 低电平 | +| IOT_GPIO_VALUE1 | 高电平 | + +**返回值:** + + +| 返回值 | 描述 | +| ----------- | ---- | +| IOT_SUCCESS | 成功 | +| IOT_FAILURE | 失败 | + +**实现:** + +`hal_iot_gpio.c`文件在`device/rockchip/rk2206/adapter/hals/iot_hardware/wifiiot_lite`目录下。 + +```c +unsigned int IoTGpioSetOutputVal(unsigned int id, IotGpioValue val) +{ + unsigned int ret = 0; + + if (id > GPIO0_PC7 && id != GPIO1_PD0) { + PRINT_ERR("id(%d) > %d || id(%d) != %d\n", id, GPIO0_PC7, GPIO1_PD0); + return IOT_FAILURE; + } + + ret = LzGpioSetVal(id, (LzGpioValue)val); + if (ret != LZ_HARDWARE_SUCCESS) { + return IOT_FAILURE; + } + + return IOT_SUCCESS; +} +``` + +#### 获取GPIO引脚的输出电平值:IoTGpioGetOutputVal + +```c +unsigned int IoTGpioGetOutputVal(unsigned int id, IotGpioValue *val); +``` + +**描述:** + +获取GPIO引脚的输出电平值。 + +**参数:** + +| 参数 | 类型 | 描述 | +| ---- | -------------- | ---------- | +| id | unsigned int | GPIOID编号 | +| val | IotGpioValue * | 电平指针 | + +**返回值:** + + +| 返回值 | 描述 | +| ----------- | ---- | +| IOT_SUCCESS | 成功 | +| IOT_FAILURE | 失败 | + +**实现:** + +`hal_iot_gpio.c`文件在`device/rockchip/rk2206/adapter/hals/iot_hardware/wifiiot_lite`目录下。 + +```c +unsigned int IoTGpioGetOutputVal(unsigned int id, IotGpioValue *val) +{ + unsigned int ret = 0; + + if (id > GPIO0_PC7 && id != GPIO1_PD0) { + PRINT_ERR("id(%d) > %d || id(%d) != %d\n", id, GPIO0_PC7, GPIO1_PD0); + return IOT_FAILURE; + } + + ret = LzGpioGetVal(id, (LzGpioValue *)val); + if (ret != LZ_HARDWARE_SUCCESS) { + return IOT_FAILURE; + } + + return IOT_SUCCESS; +} +``` + +#### 获取GPIO引脚的输入电平值:IoTGpioGetInputVal + +```c +unsigned int IoTGpioGetInputVal(unsigned int id, IotGpioValue *val); +``` + +**描述:** + +获取GPIO引脚的输入电平值。 + +**参数:** + +| 参数 | 类型 | 描述 | +| ---- | -------------- | ---------- | +| id | unsigned int | GPIOID编号 | +| val | IotGpioValue * | 电平指针 | + +**返回值:** + + +| 返回值 | 描述 | +| ----------- | ---- | +| IOT_SUCCESS | 成功 | +| IOT_FAILURE | 失败 | + +**实现:** + +`hal_iot_gpio.c`文件在`device/rockchip/rk2206/adapter/hals/iot_hardware/wifiiot_lite`目录下。 + +```c +unsigned int IoTGpioGetInputVal(unsigned int id, IotGpioValue *val) +{ + unsigned int ret = 0; + + if (id > GPIO0_PC7 && id != GPIO1_PD0) { + PRINT_ERR("id(%d) > %d || id(%d) != %d\n", id, GPIO0_PC7, GPIO1_PD0); + return IOT_FAILURE; + } + + ret = LzGpioGetVal(id, (LzGpioValue *)val); + if (ret != LZ_HARDWARE_SUCCESS) { + return IOT_FAILURE; + } + + return IOT_SUCCESS; +} +``` + +### 软件设计 + +**主要代码分析** + +`gpio_example`函数中,创建一个任务。 + +```c +void gpio_example() +{ + unsigned int thread_id; + TSK_INIT_PARAM_S task = {0}; + unsigned int ret = LOS_OK; + + task.pfnTaskEntry = (TSK_ENTRY_FUNC)gpio_thread; + task.uwStackSize = 2048; + task.pcName = "gpio_thread"; + task.usTaskPrio = 24; + ret = LOS_TaskCreate(&thread_id, &task); + if (ret != LOS_OK) { + printf("Falied to create gpio_thread ret:0x%x\n", ret); + return; + } +} +``` + +`gpio_thread`任务中调用IOT库的GPIO接口初始化、配置、读写GPIO。 + +```c +void gpio_thread() +{ + unsigned int cur = 0; + IotGpioValue value = IOT_GPIO_VALUE0; + + IoTGpioInit(GPIO_TEST); + + while (1) { + printf("***************GPIO Example*************\r\n"); + printf("Write GPIO\n"); + IoTGpioSetDir(GPIO_TEST, IOT_GPIO_DIR_OUT); + if (cur == 0) { + IoTGpioSetOutputVal(GPIO_TEST, cur); + IoTGpioGetOutputVal(GPIO_TEST, &value); + printf("\tgpio set %d => gpio get %d\n", cur, value); + cur = 1; + } else { + IoTGpioSetOutputVal(GPIO_TEST, cur); + IoTGpioGetOutputVal(GPIO_TEST, &value); + printf("\tgpio set %d => gpio get %d\n", cur, value); + cur = 0; + } + /* 睡眠1秒 */ + LOS_Msleep(1000); + + printf("Read GPIO\n"); + IoTGpioSetDir(GPIO_TEST, IOT_GPIO_DIR_IN); + IoTGpioGetInputVal(GPIO_TEST, &value); + printf("\tgpio get %d\n", value); + /* 睡眠1秒 */ + LOS_Msleep(1000); + + printf("\n"); + } +} +``` + +## 编译调试 + +### 修改 BUILD.gn 文件 + +修改 `vendor/lockzhiner/rk2206/sample` 路径下 BUILD.gn 文件,指定 `iot_gpio_example` 参与编译。 + +```r +"./b18_iot_gpio:iot_gpio_example", +``` + +修改 `device/lockzhiner/rk2206/sdk_liteos` 路径下 Makefile 文件,添加 `-liot_gpio_example` 参与编译。 + +```r +hardware_LIBS = -lhal_iothardware -lhardware -lshellcmd -liot_gpio_example +``` + +### 运行结果 + +示例代码编译烧录代码后,按下开发板的RESET按键,通过串口助手查看日志,显示如下: + +```r +***************GPIO Example************* +Write GPIO + gpio set 0 => gpio get 0 +Read GPIO + gpio get 0 + +***************GPIO Example************* +Write GPIO + gpio set 1 => gpio get 1 +Read GPIO + gpio get 1 +``` \ No newline at end of file diff --git a/vendor/lockzhiner/rk2206/samples/b18_iot_gpio/iot_gpio_example.c b/vendor/lockzhiner/rk2206/samples/b18_iot_gpio/iot_gpio_example.c new file mode 100644 index 0000000000000000000000000000000000000000..7c1518052045dac4752df5c002270bfd3aacf41f --- /dev/null +++ b/vendor/lockzhiner/rk2206/samples/b18_iot_gpio/iot_gpio_example.c @@ -0,0 +1,91 @@ +/* + * Copyright (c) 2025 FuZhou Lockzhiner Electronic Co., Ltd. All rights reserved. + * 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 "los_task.h" +#include "ohos_init.h" + +#include "iot_gpio.h" +#include "iot_errno.h" + +#include + +#define GPIO_TEST GPIO0_PA0 + +/*************************************************************** + * 函数名称: gpio_thread + * 说 明: gpio任务 + * 参 数: 无 + * 返 回 值: 无 + ***************************************************************/ +void gpio_thread() +{ + unsigned int cur = 0; + IotGpioValue value = IOT_GPIO_VALUE0; + + IoTGpioInit(GPIO_TEST); + + while (1) { + printf("***************GPIO Example*************\r\n"); + printf("Write GPIO\n"); + IoTGpioSetDir(GPIO_TEST, IOT_GPIO_DIR_OUT); + if (cur == 0) { + IoTGpioSetOutputVal(GPIO_TEST, cur); + IoTGpioGetOutputVal(GPIO_TEST, &value); + printf("\tgpio set %d => gpio get %d\n", cur, value); + cur = 1; + } else { + IoTGpioSetOutputVal(GPIO_TEST, cur); + IoTGpioGetOutputVal(GPIO_TEST, &value); + printf("\tgpio set %d => gpio get %d\n", cur, value); + cur = 0; + } + /* 睡眠1秒 */ + LOS_Msleep(1000); + + printf("Read GPIO\n"); + IoTGpioSetDir(GPIO_TEST, IOT_GPIO_DIR_IN); + IoTGpioGetInputVal(GPIO_TEST, &value); + printf("\tgpio get %d\n", value); + /* 睡眠1秒 */ + LOS_Msleep(1000); + + printf("\n"); + } +} + +/*************************************************************** + * 函数名称: gpio_example + * 说 明: 开机自启动调用函数 + * 参 数: 无 + * 返 回 值: 无 + ***************************************************************/ +void gpio_example() +{ + unsigned int thread_id; + TSK_INIT_PARAM_S task = {0}; + unsigned int ret = LOS_OK; + + task.pfnTaskEntry = (TSK_ENTRY_FUNC)gpio_thread; + task.uwStackSize = 2048; + task.pcName = "gpio_thread"; + task.usTaskPrio = 24; + ret = LOS_TaskCreate(&thread_id, &task); + if (ret != LOS_OK) { + printf("Falied to create gpio_thread ret:0x%x\n", ret); + return; + } +} + +APP_FEATURE_INIT(gpio_example); diff --git a/vendor/lockzhiner/rk2206/samples/b19_iot_gpio_int/BUILD.gn b/vendor/lockzhiner/rk2206/samples/b19_iot_gpio_int/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..44b547625a7e6d97fef761e586b0b917a60c8963 --- /dev/null +++ b/vendor/lockzhiner/rk2206/samples/b19_iot_gpio_int/BUILD.gn @@ -0,0 +1,24 @@ +# Copyright (c) 2022 FuZhou Lockzhiner Electronic Co., Ltd. All rights reserved. +# 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("iot_gpio_int_example") { + sources = [ "iot_gpio_int_example.c" ] + + include_dirs = [ + "//utils/native/lite/include", + "//utils/native/lite/hals/file", + "//base/iot_hardware/peripheral/interfaces/kits", + ] + + deps = [ "//device/rockchip/hardware:hardware" ] +} diff --git a/vendor/lockzhiner/rk2206/samples/b19_iot_gpio_int/README_zh.md b/vendor/lockzhiner/rk2206/samples/b19_iot_gpio_int/README_zh.md new file mode 100644 index 0000000000000000000000000000000000000000..c99017db85e0a1ecdcd909d29e2956eede84a3b3 --- /dev/null +++ b/vendor/lockzhiner/rk2206/samples/b19_iot_gpio_int/README_zh.md @@ -0,0 +1,287 @@ +# 小凌派-RK2206开发板基础外设开发——GPIO中断控制 + +## 实验内容 + +本示例将演示如何在小凌派-RK2206开发板上使用IOT库的GPIO接口,进行GPIO编程开发。例程将创建一个任务,通过配置GPIO引脚为中断模式,实现GPIO中断操作。 + +![小凌派-RK2206开发板](/vendor/lockzhiner/rk2206/docs/figures/lockzhiner-rk2206.jpg) + +## 程序设计 + +GPIO在日常设备中非常常见,以下我们将演示IOT库的GPIO接口如何进行GPIO配置。 + +### API分析 + +#### 头文件 + +```c +base/iot_hardware/peripheral/interfaces/kits/iot_gpio.h +``` + +#### 启用GPIO引脚的中断功能:IoTGpioRegisterIsrFunc + +```c +unsigned int IoTGpioRegisterIsrFunc(unsigned int id, IotGpioIntType intType, IotGpioIntPolarity intPolarity, GpioIsrCallbackFunc func, char *arg); +``` + +**描述:** + +启用GPIO引脚的中断功能。 + +**参数:** + +| 参数 | 类型 | 描述 | +| ----------- | ------------------- | ---------------- | +| id | unsigned int | GPIOID编号 | +| intType | IotGpioIntType | 中断模式 | +| intPolarity | IotGpioIntPolarity | 中断极性 | +| func | GpioIsrCallbackFunc | 中断回调函数 | +| arg | char * | 中断回调函数参数 | + +**返回值:** + + +| 返回值 | 描述 | +| ----------- | ---- | +| IOT_SUCCESS | 成功 | +| IOT_FAILURE | 失败 | + +**实现:** + +`hal_iot_gpio.c`文件在`device/rockchip/rk2206/adapter/hals/iot_hardware/wifiiot_lite`目录下。 + +```c +unsigned int IoTGpioRegisterIsrFunc(unsigned int id, IotGpioIntType intType, IotGpioIntPolarity intPolarity, GpioIsrCallbackFunc func, char *arg) +{ + unsigned int ret = 0; + LzGpioIntType type; + + if (id > GPIO0_PC7 && id != GPIO1_PD0) { + PRINT_ERR("id(%d) > %d || id(%d) != %d\n", id, GPIO0_PC7, GPIO1_PD0); + return IOT_FAILURE; + } + + if (intType == IOT_INT_TYPE_LEVEL && intPolarity == IOT_GPIO_EDGE_FALL_LEVEL_LOW) + type = LZGPIO_INT_LEVEL_LOW; + else if (intType == IOT_INT_TYPE_LEVEL && intPolarity == IOT_GPIO_EDGE_RISE_LEVEL_HIGH) + type = LZGPIO_INT_LEVEL_HIGH; + else if (intType == IOT_INT_TYPE_EDGE && intPolarity == IOT_GPIO_EDGE_FALL_LEVEL_LOW) + type = LZGPIO_INT_EDGE_FALLING; + else if (intType == IOT_INT_TYPE_EDGE && intPolarity == IOT_GPIO_EDGE_RISE_LEVEL_HIGH) + type = LZGPIO_INT_EDGE_RISING; + else if (intType == IOT_INT_TYPE_EDGE && intPolarity == IOT_GPIO_EDGE_BOTH_TYPE) + type = LZGPIO_INT_EDGE_BOTH; + else + return IOT_FAILURE; + + ret = LzGpioRegisterIsrFunc(id, type, (GpioIsrFunc)func, arg); + if (ret != LZ_HARDWARE_SUCCESS) { + return IOT_FAILURE; + } + + return IOT_SUCCESS; +} +``` + +#### 禁用GPIO引脚的中断功能:IoTGpioUnregisterIsrFunc + +```c +unsigned int IoTGpioUnregisterIsrFunc(unsigned int id); +``` + +**描述:** + +禁用GPIO引脚的中断功能。 + +**参数:** + +| 参数 | 类型 | 描述 | +| ---- | ------------ | ---------- | +| id | unsigned int | GPIOID编号 | + +**返回值:** + + +| 返回值 | 描述 | +| ----------- | ---- | +| IOT_SUCCESS | 成功 | +| IOT_FAILURE | 失败 | + +**实现:** + +`hal_iot_gpio.c`文件在`device/rockchip/rk2206/adapter/hals/iot_hardware/wifiiot_lite`目录下。 + +```c +unsigned int IoTGpioUnregisterIsrFunc(unsigned int id) +{ + unsigned int ret = 0; + + if (id > GPIO0_PC7 && id != GPIO1_PD0) { + PRINT_ERR("id(%d) > %d || id(%d) != %d\n", id, GPIO0_PC7, GPIO1_PD0); + return IOT_FAILURE; + } + + ret = LzGpioUnregisterIsrFunc(id); + if (ret != LZ_HARDWARE_SUCCESS) { + return IOT_FAILURE; + } + + return IOT_SUCCESS; +} +``` + +#### 屏蔽GPIO引脚的中断功能:IoTGpioSetIsrMask + +```c +unsigned int IoTGpioSetIsrMask(unsigned int id, unsigned char mask); +``` + +**描述:** + +屏蔽GPIO引脚的中断功能。 + +**参数:** + +| 参数 | 类型 | 描述 | +| ---- | ------------- | -------------------------------- | +| id | unsigned int | GPIOID编号 | +| mask | unsigned char | 中断掩码 1:屏蔽开启 0:屏蔽关闭 | + +**返回值:** + + +| 返回值 | 描述 | +| ----------- | ---- | +| IOT_SUCCESS | 成功 | +| IOT_FAILURE | 失败 | + +**实现:** + +`hal_iot_gpio.c`文件在`device/rockchip/rk2206/adapter/hals/iot_hardware/wifiiot_lite`目录下。 + +```c +unsigned int IoTGpioSetIsrMask(unsigned int id, unsigned char mask) +{ + unsigned int ret = 0; + + if (id > GPIO0_PC7 && id != GPIO1_PD0) { + PRINT_ERR("id(%d) > %d || id(%d) != %d\n", id, GPIO0_PC7, GPIO1_PD0); + return IOT_FAILURE; + } + + if (!mask) + { + ret = LzGpioEnableIsr(id); + if (ret != LZ_HARDWARE_SUCCESS) { + return IOT_FAILURE; + } + } + else + { + ret = LzGpioDisableIsr(id); + if (ret != LZ_HARDWARE_SUCCESS) { + return IOT_FAILURE; + } + } + + return IOT_SUCCESS; +} +``` + +### 软件设计 + +**主要代码分析** + +`gpio_int_example`函数中,创建一个任务。 + +```c +void gpio_int_example() +{ + unsigned int thread_id; + TSK_INIT_PARAM_S task = {0}; + unsigned int ret = LOS_OK; + + task.pfnTaskEntry = (TSK_ENTRY_FUNC)gpio_int_thread; + task.uwStackSize = 2048; + task.pcName = "gpio_int_thread"; + task.usTaskPrio = 20; + ret = LOS_TaskCreate(&thread_id, &task); + if (ret != LOS_OK) { + printf("Falied to create gpio_int_thread ret:0x%x\n", ret); + return; + } +} +``` + +`gpio_int_thread`任务中调用IOT库的GPIO接口初始化、配置,并打印`m_gpio_interrupt_count`的值。 + +```c +void gpio_int_thread() +{ + unsigned int ret; + + /* 初始化引脚为GPIO */ + IoTGpioInit(GPIO_TEST); + /* 引脚配置为输入 */ + IoTGpioSetDir(GPIO_TEST, IOT_GPIO_DIR_IN); + /* 设置中断触发方式为下降沿和中断处理函数 */ + ret = IoTGpioRegisterIsrFunc(GPIO_TEST, IOT_INT_TYPE_EDGE, IOT_GPIO_EDGE_FALL_LEVEL_LOW, gpio_int_func, NULL); + if (ret != IOT_SUCCESS) { + printf("IoTGpioRegisterIsrFunc failed(%d)\n", ret); + return; + } + /* 关闭中断屏蔽 */ + IoTGpioSetIsrMask(GPIO_TEST, FALSE); + + while (1) { + printf("***************GPIO Interrupt Example*************\n"); + printf("gpio interrupt count = %d\n", m_gpio_interrupt_count); + printf("\n"); + /* 睡眠1秒 */ + LOS_Msleep(1000); + } +} +``` + +`gpio_int_func`回调函数中`m_gpio_interrupt_count`自增。 + +```c +void gpio_int_func() +{ + m_gpio_interrupt_count++; +} +``` + +## 编译调试 + +### 修改 BUILD.gn 文件 + +修改 `vendor/lockzhiner/rk2206/sample` 路径下 BUILD.gn 文件,指定 `iot_gpio_int_example` 参与编译。 + +```r +"./b19_iot_gpio_int:iot_gpio_int_example", +``` + +修改 `device/lockzhiner/rk2206/sdk_liteos` 路径下 Makefile 文件,添加 `-liot_gpio_int_example` 参与编译。 + +```r +hardware_LIBS = -lhal_iothardware -lhardware -lshellcmd -liot_gpio_int_example +``` + +### 运行结果 + +示例代码编译烧录代码后,按下开发板的RESET按键,按下按键,通过串口助手查看日志,显示如下: + +```r +***************GPIO Interrupt Example************* +gpio interrupt count = 0 + +***************GPIO Interrupt Example************* +gpio interrupt count = 1 + +***************GPIO Interrupt Example************* +gpio interrupt count = 2 + +***************GPIO Interrupt Example************* +gpio interrupt count = 3 +``` diff --git a/vendor/lockzhiner/rk2206/samples/b19_iot_gpio_int/iot_gpio_int_example.c b/vendor/lockzhiner/rk2206/samples/b19_iot_gpio_int/iot_gpio_int_example.c new file mode 100644 index 0000000000000000000000000000000000000000..3f2c4daed9f52bf8134b43ec434e562e4542e967 --- /dev/null +++ b/vendor/lockzhiner/rk2206/samples/b19_iot_gpio_int/iot_gpio_int_example.c @@ -0,0 +1,96 @@ +/* + * Copyright (c) 2025 FuZhou Lockzhiner Electronic Co., Ltd. All rights reserved. + * 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 "los_task.h" +#include "ohos_init.h" + +#include "iot_gpio.h" +#include "iot_errno.h" + +#include + +/* GPIO0_PC5与按键相连 按下K1引脚电压0.06V左右 可作为下降沿触发 */ +#define GPIO_TEST GPIO0_PC5 + +/* 按键按下次数 */ +static uint16_t m_gpio_interrupt_count; + +/*************************************************************** + * 函数名称: gpio_int_func + * 说 明: gpio中断响应处理函数 + * 参 数: 无 + * 返 回 值: 无 + ***************************************************************/ +void gpio_int_func() +{ + m_gpio_interrupt_count++; +} + +/*************************************************************** + * 函数名称: gpio_int_thread + * 说 明: gpio_int任务 + * 参 数: 无 + * 返 回 值: 无 + ***************************************************************/ +void gpio_int_thread() +{ + unsigned int ret; + + /* 初始化引脚为GPIO */ + IoTGpioInit(GPIO_TEST); + /* 引脚配置为输入 */ + IoTGpioSetDir(GPIO_TEST, IOT_GPIO_DIR_IN); + /* 设置中断触发方式为下降沿和中断处理函数 */ + ret = IoTGpioRegisterIsrFunc(GPIO_TEST, IOT_INT_TYPE_EDGE, IOT_GPIO_EDGE_FALL_LEVEL_LOW, gpio_int_func, NULL); + if (ret != IOT_SUCCESS) { + printf("IoTGpioRegisterIsrFunc failed(%d)\n", ret); + return; + } + /* 关闭中断屏蔽 */ + IoTGpioSetIsrMask(GPIO_TEST, FALSE); + + while (1) { + printf("***************GPIO Interrupt Example*************\n"); + printf("gpio interrupt count = %d\n", m_gpio_interrupt_count); + printf("\n"); + /* 睡眠1秒 */ + LOS_Msleep(1000); + } +} + +/*************************************************************** + * 函数名称: gpio_int_example + * 说 明: 开机自启动调用函数 + * 参 数: 无 + * 返 回 值: 无 + ***************************************************************/ +void gpio_int_example() +{ + unsigned int thread_id; + TSK_INIT_PARAM_S task = {0}; + unsigned int ret = LOS_OK; + + task.pfnTaskEntry = (TSK_ENTRY_FUNC)gpio_int_thread; + task.uwStackSize = 2048; + task.pcName = "gpio_int_thread"; + task.usTaskPrio = 20; + ret = LOS_TaskCreate(&thread_id, &task); + if (ret != LOS_OK) { + printf("Falied to create gpio_int_thread ret:0x%x\n", ret); + return; + } +} + +APP_FEATURE_INIT(gpio_int_example); \ No newline at end of file diff --git a/vendor/lockzhiner/rk2206/samples/b20_iot_uart/BUILD.gn b/vendor/lockzhiner/rk2206/samples/b20_iot_uart/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..4fc0c875ab33c4621872e36485bac5d75547aaff --- /dev/null +++ b/vendor/lockzhiner/rk2206/samples/b20_iot_uart/BUILD.gn @@ -0,0 +1,24 @@ +# Copyright (c) 2022 FuZhou Lockzhiner Electronic Co., Ltd. All rights reserved. +# 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("iot_uart_example") { + sources = [ "iot_uart_example.c" ] + + include_dirs = [ + "//utils/native/lite/include", + "//utils/native/lite/hals/file", + "//base/iot_hardware/peripheral/interfaces/kits", + ] + + deps = [ "//device/rockchip/hardware:hardware" ] +} diff --git a/vendor/lockzhiner/rk2206/samples/b20_iot_uart/README_zh.md b/vendor/lockzhiner/rk2206/samples/b20_iot_uart/README_zh.md new file mode 100644 index 0000000000000000000000000000000000000000..c6257d77c7b134f796063c37a487a84ef977a162 --- /dev/null +++ b/vendor/lockzhiner/rk2206/samples/b20_iot_uart/README_zh.md @@ -0,0 +1,391 @@ +# 小凌派-RK2206开发板基础外设开发——UART控制 + +## 实验内容 + +本示例将演示如何在小凌派-RK2206开发板上使用IOT库的UART接口,进行UART编程开发。例程将创建一个任务,通过配置UART引脚,实现UART读写操作。 + +![小凌派-RK2206开发板](/vendor/lockzhiner/rk2206/docs/figures/lockzhiner-rk2206.jpg) + +## 程序设计 + +UART在日常设备中非常常见,以下我们将演示IOT库的UART接口如何进行UART口配置,以及UART口读写操作。 + +### API分析 + +#### 头文件 + +```c +base/iot_hardware/peripheral/interfaces/kits/iot_uart.h +``` + +#### UART设备初始化:IoTUartInit + +```c +unsigned int IoTUartInit(unsigned int id, const IotUartAttribute *param); +``` + +**描述:** + +UART设备初始化。 + +**参数:** + +| 参数 | 类型 | 描述 | +| ----- | ------------------------ | ------------ | +| id | unsigned int | UART ID | +| param | const IotUartAttribute * | UART配置参数 | + +UART ID配置和IO复用如下表: + +| 串口 | id | TX | RX | +| ----- | --------- | --------- | --------- | +| UART0 | EUART0_M0 | GPIO0_PB7 | GPIO0_PB6 | +| UART0 | EUART0_M1 | GPIO0_PC7 | GPIO0_PC6 | +| UART1 | EUART1_M0 | GPIO0_PC3 | GPIO0_PC2 | +| UART1 | EUART1_M1 | GPIO0_PA7 | GPIO0_PA6 | +| UART2 | EUART2_M1 | GPIO0_PB3 | GPIO0_PB2 | + +**返回值:** + + +| 返回值 | 描述 | +| ----------- | ---- | +| IOT_SUCCESS | 成功 | +| IOT_FAILURE | 失败 | + +**实现:** + +`hal_iot_uart.c`文件在`device/rockchip/rk2206/adapter/hals/iot_hardware/wifiiot_lite`目录下。 + +```c +unsigned int IoTUartInit(unsigned int id, const IotUartAttribute *param) +{ + unsigned int ret = 0; + UartAttribute *temp_prt = (const UartAttribute *)param; + + if (id >= EUARTDEV_MAX) + { + PRINT_ERR("id(%d) >= EUARTDEV_MAX(%d)\n", id, EUARTDEV_MAX); + return IOT_FAILURE; + } + + PinctrlSet(m_uart_bus_info[id].uart_bus.rx.gpio, m_uart_bus_info[id].uart_bus.rx.func, m_uart_bus_info[id].uart_bus.rx.type, m_uart_bus_info[id].uart_bus.rx.drv); + PinctrlSet(m_uart_bus_info[id].uart_bus.tx.gpio, m_uart_bus_info[id].uart_bus.tx.func, m_uart_bus_info[id].uart_bus.tx.type, m_uart_bus_info[id].uart_bus.tx.drv); + + if (param->parity == IOT_UART_PARITY_NONE) + { + temp_prt->parity = UART_PARITY_NONE; + } + else if (param->parity == IOT_UART_PARITY_EVEN) + { + temp_prt->parity = UART_PARITY_EVEN; + } + else if (param->parity == IOT_UART_PARITY_ODD) + { + temp_prt->parity = UART_PARITY_ODD; + } + + if (m_uart_bus_info[id].id == 0) + { + LzUartDeinit(m_uart_bus_info[id].id); + uint32_t *pUart0 = (uint32_t *)(0x40070000U); + HAL_UART_DeInit(pUart0); + } + + ret = LzUartInit(m_uart_bus_info[id].id, temp_prt); + if (ret != LZ_HARDWARE_SUCCESS) + { + return IOT_FAILURE; + } + + return IOT_SUCCESS; +} +``` + +#### 取消初始化UART设备:IoTUartDeinit + +```c +unsigned int IoTUartDeinit(unsigned int id); +``` + +**描述:** + +取消初始化UART设备。 + +**参数:** + +| 参数 | 类型 | 描述 | +| ---- | ------------ | ------- | +| id | unsigned int | UART ID | + +UART ID配置和IO复用如下表: + +| 串口 | id | TX | RX | +| ----- | --------- | --------- | --------- | +| UART0 | EUART0_M0 | GPIO0_PB7 | GPIO0_PB6 | +| UART0 | EUART0_M1 | GPIO0_PC7 | GPIO0_PC6 | +| UART1 | EUART1_M0 | GPIO0_PC3 | GPIO0_PC2 | +| UART1 | EUART1_M1 | GPIO0_PA7 | GPIO0_PA6 | +| UART2 | EUART2_M1 | GPIO0_PB3 | GPIO0_PB2 | + +**返回值:** + + +| 返回值 | 描述 | +| ----------- | ---- | +| IOT_SUCCESS | 成功 | +| IOT_FAILURE | 失败 | + +**实现:** + +`hal_iot_uart.c`文件在`device/rockchip/rk2206/adapter/hals/iot_hardware/wifiiot_lite`目录下。 + +```c +unsigned int IoTUartDeinit(unsigned int id) +{ + unsigned int ret = 0; + + if (id >= EUARTDEV_MAX) + { + PRINT_ERR("id(%d) >= EUARTDEV_MAX(%d)\n", id, EUARTDEV_MAX); + return IOT_FAILURE; + } + + ret = LzUartDeinit(m_uart_bus_info[id].id); + if (ret != LZ_HARDWARE_SUCCESS) + { + return IOT_FAILURE; + } + + return IOT_SUCCESS; +} +``` + +#### UART设备读取指定长度的数据:IoTUartRead + +```c +int IoTUartRead(unsigned int id, unsigned char *data, unsigned int dataLen); +``` + +**描述:** + +UART设备读取指定长度的数据。 + +**参数:** + +| 参数 | 类型 | 描述 | +| ------- | --------------- | -------- | +| id | unsigned int | UART ID | +| data | unsigned char * | 数据指针 | +| dataLen | unsigned int | 数据长度 | + +UART ID配置和IO复用如下表: + +| 串口 | id | TX | RX | +| ----- | --------- | --------- | --------- | +| UART0 | EUART0_M0 | GPIO0_PB7 | GPIO0_PB6 | +| UART0 | EUART0_M1 | GPIO0_PC7 | GPIO0_PC6 | +| UART1 | EUART1_M0 | GPIO0_PC3 | GPIO0_PC2 | +| UART1 | EUART1_M1 | GPIO0_PA7 | GPIO0_PA6 | +| UART2 | EUART2_M1 | GPIO0_PB3 | GPIO0_PB2 | + +**返回值:** + + +| 返回值 | 描述 | +| ----------- | ---- | +| IOT_SUCCESS | 成功 | +| IOT_FAILURE | 失败 | + +**实现:** + +`hal_iot_uart.c`文件在`device/rockchip/rk2206/adapter/hals/iot_hardware/wifiiot_lite`目录下。 + +```c +int IoTUartRead(unsigned int id, unsigned char *data, unsigned int dataLen) +{ + unsigned int ret = 0; + + if (id >= EUARTDEV_MAX) + { + PRINT_ERR("id(%d) >= EUARTDEV_MAX(%d)\n", id, EUARTDEV_MAX); + return IOT_FAILURE; + } + + ret = LzUartRead(m_uart_bus_info[id].id, data, dataLen); + + return ret; +} +``` + +#### UART设备写指定长度的数据:IoTUartWrite + +```c +int IoTUartWrite(unsigned int id, const unsigned char *data, unsigned int dataLen); +``` + +**描述:** + +UART设备读取指定长度的数据。 + +**参数:** + +| 参数 | 类型 | 描述 | +| ------- | --------------------- | -------- | +| id | unsigned int | UART ID | +| data | const unsigned char * | 数据指针 | +| dataLen | unsigned int | 数据长度 | + +UART ID配置和IO复用如下表: + +| 串口 | id | TX | RX | +| ----- | --------- | --------- | --------- | +| UART0 | EUART0_M0 | GPIO0_PB7 | GPIO0_PB6 | +| UART0 | EUART0_M1 | GPIO0_PC7 | GPIO0_PC6 | +| UART1 | EUART1_M0 | GPIO0_PC3 | GPIO0_PC2 | +| UART1 | EUART1_M1 | GPIO0_PA7 | GPIO0_PA6 | +| UART2 | EUART2_M1 | GPIO0_PB3 | GPIO0_PB2 | + +**返回值:** + + +| 返回值 | 描述 | +| ----------- | ---- | +| IOT_SUCCESS | 成功 | +| IOT_FAILURE | 失败 | + +**实现:** + +`hal_iot_uart.c`文件在`device/rockchip/rk2206/adapter/hals/iot_hardware/wifiiot_lite`目录下。 + +```c +int IoTUartWrite(unsigned int id, const unsigned char *data, unsigned int dataLen) +{ + unsigned int ret = 0; + + if (id >= EUARTDEV_MAX) + { + PRINT_ERR("id(%d) >= EUARTDEV_MAX(%d)\n", id, EUARTDEV_MAX); + return IOT_FAILURE; + } + + ret = LzUartWrite(m_uart_bus_info[id].id, data, dataLen); + if (ret != LZ_HARDWARE_SUCCESS) + { + return IOT_FAILURE; + } + + return IOT_SUCCESS; +} +``` + +### 软件设计 + +**主要代码分析** + +在`uart_example`函数中,创建一个任务。 + +```c +void uart_example() +{ + unsigned int thread_id; + TSK_INIT_PARAM_S task = {0}; + unsigned int ret = LOS_OK; + + task.pfnTaskEntry = (TSK_ENTRY_FUNC)uart_thread; + task.uwStackSize = 2048; + task.pcName = "uart_thread"; + task.usTaskPrio = 24; + ret = LOS_TaskCreate(&thread_id, &task); + if (ret != LOS_OK) { + printf("Falied to create uart_thread ret:0x%x\n", ret); + return; + } +} +``` + +`uart_thread`任务中调用IOT库的UART接口配置、读写UART。 + +```c +void uart_thread() +{ + unsigned int ret; + IotUartAttribute attr; + unsigned char str[] = "HelloWorld!"; + unsigned char recv_buffer[STRING_MAXSIZE] = {0}; + unsigned int recv_length = 0; + + IoTUartDeinit(UART_ID); + + attr.baudRate = 115200; + attr.dataBits = IOT_UART_DATA_BIT_8; + attr.pad = IOT_FLOW_CTRL_NONE; + attr.parity = IOT_UART_PARITY_NONE; + attr.rxBlock = IOT_UART_BLOCK_STATE_NONE_BLOCK; + attr.stopBits = IOT_UART_STOP_BIT_1; + attr.txBlock = IOT_UART_BLOCK_STATE_NONE_BLOCK; + + /* 初始化串口 */ + ret = IoTUartInit(UART_ID, &attr); + if (ret != IOT_SUCCESS) { + printf("%s, %d: IoTUartInit(%d) failed!\n", __FILE__, __LINE__, ret); + return; + } + /* 休眠1秒 */ + LOS_Msleep(1000); + + while (1) { + printf("%s, %d: uart write and str(%s), len(%d)!\n", __FILE__, __LINE__, str, strlen(str)); + // IoTUartWrite是异步发送,非阻塞发送 + IoTUartWrite(UART_ID, str, strlen(str)); + // 等待发送完毕 + LOS_Msleep(1000); + + recv_length = 0; + memset(recv_buffer, 0, sizeof(recv_buffer)); + recv_length = IoTUartRead(UART_ID, recv_buffer, sizeof(recv_buffer)); + printf("%s, %d: uart recv and str(%s), len(%d)\n", __FILE__, __LINE__, recv_buffer, recv_length); + + /* 休眠1秒 */ + LOS_Msleep(1000); + } +} +``` + +## 编译调试 + +### 修改 BUILD.gn 文件 + +修改 `vendor/lockzhiner/rk2206/sample` 路径下 BUILD.gn 文件,指定 `iot_uart_example` 参与编译。 + +```r +"./b20_iot_uart:iot_uart_example", +``` + +修改 `device/lockzhiner/rk2206/sdk_liteos` 路径下 Makefile 文件,添加 `-liot_uart_example` 参与编译。 + +```r +hardware_LIBS = -lhal_iothardware -lhardware -lshellcmd -liot_uart_example +``` + +### 运行结果 + +示例代码编译烧录代码后,按下开发板的RESET按键,使用杜邦线连接TX和RX,通过串口助手查看日志,显示如下: + +```r +entering kernel init... +hilog will init. +[MAIN:D]Main: LOS_Start ... +Entering scheduler +OHOS # hiview init success.[UART:E]LzUartDeinit: id 0, controller has NOT been initialized +[UART:E]LzUartDeinit: id 0, controller has NOT been initialized +../../../vendor/lockzhiner/rk2206/samples/b20_iot_uart/iot_uart_example.c, 63: uart write and str(HelloWorld!), len(11)! +../../../vendor/lockzhiner/rk2206/samples/b20_iot_uart/iot_uart_example.c, 72: uart recv and str(HelloWorld!), len(11) +../../../vendor/lockzhiner/rk2206/samples/b20_iot_uart/iot_uart_example.c, 63: uart write and str(HelloWorld!), len(11)! +../../../vendor/lockzhiner/rk2206/samples/b20_iot_uart/iot_uart_example.c, 72: uart recv and str(HelloWorld!), len(11) +../../../vendor/lockzhiner/rk2206/samples/b20_iot_uart/iot_uart_example.c, 63: uart write and str(HelloWorld!), len(11)! +../../../vendor/lockzhiner/rk2206/samples/b20_iot_uart/iot_uart_example.c, 72: uart recv and str(HelloWorld!), len(11) +../../../vendor/lockzhiner/rk2206/samples/b20_iot_uart/iot_uart_example.c, 63: uart write and str(HelloWorld!), len(11)! +../../../vendor/lockzhiner/rk2206/samples/b20_iot_uart/iot_uart_example.c, 72: uart recv and str(HelloWorld!), len(11) + +``` \ No newline at end of file diff --git a/vendor/lockzhiner/rk2206/samples/b20_iot_uart/iot_uart_example.c b/vendor/lockzhiner/rk2206/samples/b20_iot_uart/iot_uart_example.c new file mode 100644 index 0000000000000000000000000000000000000000..d29aa075a7171dc219d6e812cf878080a3107f87 --- /dev/null +++ b/vendor/lockzhiner/rk2206/samples/b20_iot_uart/iot_uart_example.c @@ -0,0 +1,101 @@ +/* + * Copyright (c) 2025 FuZhou Lockzhiner Electronic Co., Ltd. All rights reserved. + * 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 "los_task.h" +#include "ohos_init.h" + +#include "iot_uart.h" +#include "iot_errno.h" + +#include + +/* 串口0 */ +#define UART_ID EUART0_M0 +#define STRING_MAXSIZE 128 + +/*************************************************************** + * 函数名称: uart_process + * 说 明: 串口0任务 + * 参 数: 无 + * 返 回 值: 无 + ***************************************************************/ +void uart_thread() +{ + unsigned int ret; + IotUartAttribute attr; + unsigned char str[] = "HelloWorld!"; + unsigned char recv_buffer[STRING_MAXSIZE] = {0}; + unsigned int recv_length = 0; + + IoTUartDeinit(UART_ID); + + attr.baudRate = 115200; + attr.dataBits = IOT_UART_DATA_BIT_8; + attr.pad = IOT_FLOW_CTRL_NONE; + attr.parity = IOT_UART_PARITY_NONE; + attr.rxBlock = IOT_UART_BLOCK_STATE_NONE_BLOCK; + attr.stopBits = IOT_UART_STOP_BIT_1; + attr.txBlock = IOT_UART_BLOCK_STATE_NONE_BLOCK; + + /* 初始化串口 */ + ret = IoTUartInit(UART_ID, &attr); + if (ret != IOT_SUCCESS) { + printf("%s, %d: IoTUartInit(%d) failed!\n", __FILE__, __LINE__, ret); + return; + } + /* 休眠1秒 */ + LOS_Msleep(1000); + + while (1) { + printf("%s, %d: uart write and str(%s), len(%d)!\n", __FILE__, __LINE__, str, strlen(str)); + // IoTUartWrite是异步发送,非阻塞发送 + IoTUartWrite(UART_ID, str, strlen(str)); + // 等待发送完毕 + LOS_Msleep(1000); + + recv_length = 0; + memset(recv_buffer, 0, sizeof(recv_buffer)); + recv_length = IoTUartRead(UART_ID, recv_buffer, sizeof(recv_buffer)); + printf("%s, %d: uart recv and str(%s), len(%d)\n", __FILE__, __LINE__, recv_buffer, recv_length); + + /* 休眠1秒 */ + LOS_Msleep(1000); + } +} + +/*************************************************************** + * 函数名称: uart_example + * 说 明: 开机自启动调用函数 + * 参 数: 无 + * 返 回 值: 无 + ***************************************************************/ +void uart_example() +{ + unsigned int thread_id; + TSK_INIT_PARAM_S task = {0}; + unsigned int ret = LOS_OK; + + task.pfnTaskEntry = (TSK_ENTRY_FUNC)uart_thread; + task.uwStackSize = 2048; + task.pcName = "uart_thread"; + task.usTaskPrio = 24; + ret = LOS_TaskCreate(&thread_id, &task); + if (ret != LOS_OK) { + printf("Falied to create uart_thread ret:0x%x\n", ret); + return; + } +} + +APP_FEATURE_INIT(uart_example); diff --git a/vendor/lockzhiner/rk2206/samples/b21_iot_flash/BUILD.gn b/vendor/lockzhiner/rk2206/samples/b21_iot_flash/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..3fb81c0cded0fdd80eeccb677a38127cc161efb8 --- /dev/null +++ b/vendor/lockzhiner/rk2206/samples/b21_iot_flash/BUILD.gn @@ -0,0 +1,24 @@ +# Copyright (c) 2022 FuZhou Lockzhiner Electronic Co., Ltd. All rights reserved. +# 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("iot_flash_example") { + sources = [ "iot_flash_example.c" ] + + include_dirs = [ + "//utils/native/lite/include", + "//utils/native/lite/hals/file", + "//base/iot_hardware/peripheral/interfaces/kits", + ] + + deps = [ "//device/rockchip/hardware:hardware" ] +} diff --git a/vendor/lockzhiner/rk2206/samples/b21_iot_flash/README_zh.md b/vendor/lockzhiner/rk2206/samples/b21_iot_flash/README_zh.md new file mode 100644 index 0000000000000000000000000000000000000000..164fdff4740156d0afffcf076e97dec9732fb190 --- /dev/null +++ b/vendor/lockzhiner/rk2206/samples/b21_iot_flash/README_zh.md @@ -0,0 +1,288 @@ +# 小凌派-RK2206开发板基础外设开发——FLASH读写 + +## 实验内容 + +本示例将演示如何在小凌派-RK2206开发板上使用IOT库的FLASH接口,进行FLASH编程开发。例程将创建一个任务,实现FLASH读写操作。 + +![小凌派-RK2206开发板](/vendor/lockzhiner/rk2206/docs/figures/lockzhiner-rk2206.jpg) + +## 程序设计 + +FLASH在日常设备中非常常见,以下我们将演示IOT库的FLASH接口如何进行UART口读写操作。 + +### API分析 + +#### 头文件 + +```c +base/iot_hardware/peripheral/interfaces/kits/iot_flash.h +``` + +#### FLASH设备初始化:IoTFlashInit + +```c +unsigned int IoTFlashInit(void); +``` + +**描述:** + +FLASH设备初始化。 + +**参数:** + +无 + +**返回值:** + + +| 返回值 | 描述 | +| ----------- | ---- | +| IOT_SUCCESS | 成功 | +| IOT_FAILURE | 失败 | + +**实现:** + +`hal_iot_flash.c`文件在`device/rockchip/rk2206/adapter/hals/iot_hardware/wifiiot_lite`目录下。 + +```c +unsigned int IoTFlashInit(void) +{ + return (FlashInit() == LZ_HARDWARE_SUCCESS) ? IOT_SUCCESS : IOT_FAILURE; +} +``` + +#### 取消初始化FLASH设备:IoTFlashDeinit + +```c +unsigned int IoTFlashDeinit(void); +``` + +**描述:** + +取消初始化FLASH设备。 + +**参数:** + +无 + +**返回值:** + + +| 返回值 | 描述 | +| ----------- | ---- | +| IOT_SUCCESS | 成功 | +| IOT_FAILURE | 失败 | + +**实现:** + +`hal_iot_flash.c`文件在`device/rockchip/rk2206/adapter/hals/iot_hardware/wifiiot_lite`目录下。 + +```c +unsigned int IoTFlashDeinit(void) +{ + return (FlashDeinit() == LZ_HARDWARE_SUCCESS) ? IOT_SUCCESS : IOT_FAILURE; +} +``` + +#### FLASH读操作:IoTFlashRead + +```c +unsigned int IoTFlashRead(unsigned int flashOffset, unsigned int size, unsigned char *ramData); +``` + +**描述:** + +FLASH读操作。 + +**参数:** + +| 参数 | 类型 | 描述 | +| ----------- | --------------- | --------- | +| flashOffset | unsigned int | flash地址 | +| size | unsigned int | 长度 | +| ramData | unsigned char * | 数据指针 | + +**返回值:** + + +| 返回值 | 描述 | +| ----------- | ---- | +| IOT_SUCCESS | 成功 | +| IOT_FAILURE | 失败 | + +**实现:** + +`hal_iot_flash.c`文件在`device/rockchip/rk2206/adapter/hals/iot_hardware/wifiiot_lite`目录下。 + +```c +unsigned int IoTFlashRead(unsigned int flashOffset, unsigned int size, unsigned char *ramData) +{ + return (FlashRead(flashOffset, size, ramData) == LZ_HARDWARE_SUCCESS) ? IOT_SUCCESS : IOT_FAILURE; +} +``` + +#### FLASH写操作:IoTFlashWrite + +```c +unsigned int IoTFlashWrite(unsigned int flashOffset, unsigned int size, const unsigned char *ramData, unsigned char doErase); +``` + +**描述:** + +FLASH写操作。 + +**参数:** + +| 参数 | 类型 | 描述 | +| ----------- | --------------- | --------- | +| flashOffset | unsigned int | flash地址 | +| size | unsigned int | 长度 | +| ramData | unsigned char * | 数据指针 | +| doErase | unsigned char | 无效位 | + +**返回值:** + + +| 返回值 | 描述 | +| ----------- | ---- | +| IOT_SUCCESS | 成功 | +| IOT_FAILURE | 失败 | + +**实现:** + +`hal_iot_flash.c`文件在`device/rockchip/rk2206/adapter/hals/iot_hardware/wifiiot_lite`目录下。 + +```c +unsigned int IoTFlashWrite(unsigned int flashOffset, unsigned int size, const unsigned char *ramData, unsigned char doErase) +{ + return (FlashWrite(flashOffset, size, ramData, doErase) == LZ_HARDWARE_SUCCESS) ? IOT_SUCCESS : IOT_FAILURE; +} +``` + +#### FLASH擦除操作:IoTFlashErase + +```c +unsigned int IoTFlashErase(unsigned int flashOffset, unsigned int size); +``` + +**描述:** + +FLASH擦除操作。 + +**参数:** + +| 参数 | 类型 | 描述 | +| ----------- | ------------ | --------- | +| flashOffset | unsigned int | flash地址 | +| size | unsigned int | 长度 | + +**返回值:** + + +| 返回值 | 描述 | +| ----------- | ---- | +| IOT_SUCCESS | 成功 | +| IOT_FAILURE | 失败 | + +**实现:** + +`hal_iot_flash.c`文件在`device/rockchip/rk2206/adapter/hals/iot_hardware/wifiiot_lite`目录下。 + +```c +unsigned int IoTFlashErase(unsigned int flashOffset, unsigned int size) +{ + return (FlashErase(flashOffset, size) == LZ_HARDWARE_SUCCESS) ? IOT_SUCCESS : IOT_FAILURE; +} +``` + +### 软件设计 + +**主要代码分析** + +在`flash_example`函数中,创建一个任务。 + +```c +void flash_example(void) +{ + unsigned int ret = LOS_OK; + unsigned int thread_id; + TSK_INIT_PARAM_S task = {0}; + + task.pfnTaskEntry = (TSK_ENTRY_FUNC)flash_thread; + task.uwStackSize = 1024 * 512; + task.pcName = "flash_thread"; + task.usTaskPrio = 24; + ret = LOS_TaskCreate(&thread_id, &task); + if (ret != LOS_OK) { + printf("Falied to create flash_thread ret:0x%x\n", ret); + return; + } +} +``` + +## 编译调试 + +### 修改 BUILD.gn 文件 + +修改 `vendor/lockzhiner/rk2206/sample` 路径下 BUILD.gn 文件,指定 `iot_flash_example` 参与编译。 + +```r +"./b21_iot_flash:iot_flash_example", +``` + +修改 `device/lockzhiner/rk2206/sdk_liteos` 路径下 Makefile 文件,添加 `-iot_flash_example` 参与编译。 + +```r +hardware_LIBS = -lhal_iothardware -lhardware -lshellcmd -liot_flash_example +``` + +### 运行结果 + +示例代码编译烧录代码后,按下开发板的RESET按键,通过串口助手查看日志,显示如下: + +```r +entering kernel init... +hilog will init. +[MAIN:D]Main: LOS_Start ... +Entering scheduler +OHOS # hiview init success.[FLASH:E]FlashDeinit: id 0, controller has NOT been initialized +[FLASH:I]FlashInit: blockSize 4096, blockStart 0, blockEnd 8388608 +Flash erase: address = 0x700000, length = 0x1000 +Flash write: address = 0x700000, length = 0x1000, ch = a +Flash read: address = 0x700000, length = 0x1000 + [0] = a + [1] = a + [2] = a + [3] = a + [4] = a + [5] = a + [6] = a + [7] = a + [8] = a + [9] = a + [10] = a + [11] = a + [12] = a + [13] = a + [14] = a + [15] = a +Flash erase: address = 0x700000, length = 0x1000 +Flash write: address = 0x700000, length = 0x1000, ch = b +Flash read: address = 0x700000, length = 0x1000 + [0] = b + [1] = b + [2] = b + [3] = b + [4] = b + [5] = b + [6] = b + [7] = b + [8] = b + [9] = b + [10] = b + [11] = b + [12] = b + [13] = b + [14] = b + [15] = b +``` \ No newline at end of file diff --git a/vendor/lockzhiner/rk2206/samples/b21_iot_flash/iot_flash_example.c b/vendor/lockzhiner/rk2206/samples/b21_iot_flash/iot_flash_example.c new file mode 100644 index 0000000000000000000000000000000000000000..ea612fac35189f851d3e14bd69f2fd260b1d01d6 --- /dev/null +++ b/vendor/lockzhiner/rk2206/samples/b21_iot_flash/iot_flash_example.c @@ -0,0 +1,111 @@ +/* + * Copyright (c) 2025 FuZhou Lockzhiner Electronic Co., Ltd. All rights reserved. + * 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 "los_task.h" +#include "ohos_init.h" + +#include "iot_flash.h" +#include "iot_errno.h" + +#include + +#define LOG_TAG "flash" // 模块名称 + +#define FLASH_ADDRESS_START (0x700000) // 起始地址 +#define FLASH_ADDRESS_LENGTH (0x100000) // 地址长度 +#define FLASH_BLOCK_SIZE (PART_BLOCK_SIZE) // 块大小 +#define FLASH_ERASE_BLOCK_SIZE (4096) // 擦除块大小 + +/*************************************************************** + * 函数名称: flash_thread + * 说 明: flash线程 + * 参 数: 无 + * 返 回 值: 无 + ***************************************************************/ +void flash_thread(void *args) +{ + uint32_t flash_base_address = FLASH_ADDRESS_START; + uint8_t flash_erase_buffer[FLASH_ERASE_BLOCK_SIZE]; + int ret; + uint8_t ch = 'a'; + + // 初始化flash + IoTFlashDeinit(); + IoTFlashInit(); + + while (1) { + for (uint32_t i = 0; i < 16; i += FLASH_ERASE_BLOCK_SIZE) { + uint32_t flash_address = flash_base_address + i; + uint32_t flash_length = FLASH_ERASE_BLOCK_SIZE; + + printf("Flash erase: address = 0x%x, length = 0x%x\n", flash_address, flash_length); + // 擦除 + ret = IoTFlashErase(flash_address, flash_length); + if (ret != IOT_SUCCESS) { + printf("Flash erase failed\n"); + goto flash_out; + } + + // 写入 + printf("Flash write: address = 0x%x, length = 0x%x, ch = %c\n", flash_address, flash_length, ch); + memset(flash_erase_buffer, ch, sizeof(flash_erase_buffer)); + ret = IoTFlashWrite(flash_address, sizeof(flash_erase_buffer), flash_erase_buffer, 0); + if (ret != IOT_SUCCESS) { + printf("Flash write failed\n"); + goto flash_out; + } + ch++; + + printf("Flash read: address = 0x%x, length = 0x%x\n", flash_address, flash_length); + memset(flash_erase_buffer, ch, sizeof(flash_erase_buffer)); + ret = IoTFlashRead(flash_address, sizeof(flash_erase_buffer), flash_erase_buffer); + if (ret != IOT_SUCCESS) { + printf("Flash read failed\n"); + goto flash_out; + } + for (uint32_t offset = 0; offset < 16; offset++) { + printf(" [%d] = %c\n", offset, flash_erase_buffer[offset]); + } + + flash_out: + LOS_Msleep(1000); + } + } +} + +/*************************************************************** + * 函数名称: flash_example + * 说 明: 开机自启动调用函数 + * 参 数: 无 + * 返 回 值: 无 + ***************************************************************/ +void flash_example(void) +{ + unsigned int ret = LOS_OK; + unsigned int thread_id; + TSK_INIT_PARAM_S task = {0}; + + task.pfnTaskEntry = (TSK_ENTRY_FUNC)flash_thread; + task.uwStackSize = 1024 * 512; + task.pcName = "flash_thread"; + task.usTaskPrio = 24; + ret = LOS_TaskCreate(&thread_id, &task); + if (ret != LOS_OK) { + printf("Falied to create flash_thread ret:0x%x\n", ret); + return; + } +} + +APP_FEATURE_INIT(flash_example);