1 /*
2 * Copyright (C) 2022 HiHope Open Source Organization .
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http:// www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 *
14 * limitations under the License.
15 */
16
17 #include <stdio.h>
18
19 #include <unistd.h>
20
21 #include "cmsis_os2.h"
22 #include "ohos_init.h"
23 #include "wifiiot_gpio.h"
24 #include "wifiiot_gpio_ex.h"
25
26 #define LED_TASK_STACK_SIZE 1024
27 #define LED_TASK_PRIO 25
28 #define NUM 1
29 #define OS_DELAY 50
30
GpioTask(const char * arg)31 static int* GpioTask(const char* arg)
32 {
33 (void)arg;
34 // GPIO模块初始化
35 GpioInit();
36 // 设置引脚功能,id参数用于指定引脚,val用于指定引脚功能
37 IoSetFunc(WIFI_IOT_IO_NAME_GPIO_9, WIFI_IOT_IO_FUNC_GPIO_9_GPIO);
38 // 设置GPIO引脚方向,id参数用于指定引脚,dir参数用于指定输入或输出
39 GpioSetDir(WIFI_IOT_IO_NAME_GPIO_9, WIFI_IOT_GPIO_DIR_OUT);
40
41 while (NUM) {
42 printf("LED_SPARK! \n");
43 // 设置GPIO引脚的输出状态,id参数用于指定引脚,val参数用于指定高电平或低电平
44 GpioSetOutputVal(WIFI_IOT_IO_NAME_GPIO_9, WIFI_IOT_GPIO_VALUE0);
45 osDelay(OS_DELAY);
46 GpioSetOutputVal(WIFI_IOT_IO_NAME_GPIO_9, WIFI_IOT_GPIO_VALUE1);
47 osDelay(OS_DELAY);
48 }
49 return NULL;
50 }
51
GpioExampleEntry(void)52 static void GpioExampleEntry(void)
53 {
54 osThreadAttr_t attr;
55
56 attr.name = "GpioTask";
57 attr.attr_bits = 0U;
58 attr.cb_mem = NULL;
59 attr.cb_size = 0U;
60 attr.stack_mem = NULL;
61 attr.stack_size = LED_TASK_STACK_SIZE;
62 attr.priority = LED_TASK_PRIO;
63
64 if (osThreadNew((osThreadFunc_t)GpioTask, NULL, &attr) == NULL) {
65 printf("[GpioExample] Failed to create GpioTask!\n");
66 }
67 }
68
69 SYS_RUN(GpioExampleEntry); // if test add it
70