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
35 GpioInit();
36 IoSetFunc(WIFI_IOT_IO_NAME_GPIO_9, WIFI_IOT_IO_FUNC_GPIO_9_GPIO);
37 GpioSetDir(WIFI_IOT_IO_NAME_GPIO_9, WIFI_IOT_GPIO_DIR_OUT);
38
39 while (NUM) {
40 printf("LED_SPARK! \n");
41 GpioSetOutputVal(WIFI_IOT_IO_NAME_GPIO_9, WIFI_IOT_GPIO_VALUE0);
42 osDelay(OS_DELAY);
43 GpioSetOutputVal(WIFI_IOT_IO_NAME_GPIO_9, WIFI_IOT_GPIO_VALUE1);
44 osDelay(OS_DELAY);
45 }
46 return NULL;
47 }
48
GpioExampleEntry(void)49 static void GpioExampleEntry(void)
50 {
51 osThreadAttr_t attr;
52
53 attr.name = "GpioTask";
54 attr.attr_bits = 0U;
55 attr.cb_mem = NULL;
56 attr.cb_size = 0U;
57 attr.stack_mem = NULL;
58 attr.stack_size = LED_TASK_STACK_SIZE;
59 attr.priority = LED_TASK_PRIO;
60
61 if (osThreadNew((osThreadFunc_t)GpioTask, NULL, &attr) == NULL) {
62 printf("[GpioExample] Failed to create GpioTask!\n");
63 }
64 }
65
66 SYS_RUN(GpioExampleEntry); // if test add it
67