• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2020 Nanjing Xiaoxiongpai Intelligent Technology Co., Ltd.
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  * limitations under the License.
14  */
15 
16 #include <stdio.h>
17 #include <unistd.h>
18 
19 #include "cmsis_os2.h"
20 #include "iot_gpio.h"
21 #include "iot_gpio_ex.h"
22 #include "ohos_init.h"
23 
24 #define LED_GPIO 2
25 #define BUTTON_F1_GPIO 11
26 #define BUTTON_F2_GPIO 12
27 
28 /**
29  * @brief Callback for F1 key
30  *
31  */
F1Pressed(char * arg)32 static void F1Pressed(char *arg)
33 {
34     (void)arg;
35     IoTGpioSetOutputVal(LED_GPIO, 1);
36 }
37 
38 /**
39  * @brief Callback for F2 key
40  *
41  */
F2Pressed(char * arg)42 static void F2Pressed(char *arg)
43 {
44     (void)arg;
45     IoTGpioSetOutputVal(LED_GPIO, 0);
46 }
47 
48 /**
49  * @brief Main Entry of the Button Example
50  *
51  */
ButtonExampleEntry(void)52 static void ButtonExampleEntry(void)
53 {
54     // init gpio of LED
55     IoTGpioInit(LED_GPIO);
56     IoTGpioSetDir(LED_GPIO, IOT_GPIO_DIR_OUT);
57 
58     // init gpio of F1 key and set it as the falling edge to trigger interrupt
59     IoTGpioInit(BUTTON_F1_GPIO);
60     IoTGpioSetFunc(BUTTON_F1_GPIO, IOT_GPIO_FUNC_GPIO_11_GPIO);
61     IoTGpioSetDir(BUTTON_F1_GPIO, IOT_GPIO_DIR_IN);
62     IoTGpioSetPull(BUTTON_F1_GPIO, IOT_GPIO_PULL_UP);
63     IoTGpioRegisterIsrFunc(BUTTON_F1_GPIO, IOT_INT_TYPE_EDGE, IOT_GPIO_EDGE_FALL_LEVEL_LOW, F1Pressed, NULL);
64 
65     // init gpio of F2 key and set it as the falling edge to trigger interrupt
66     IoTGpioInit(BUTTON_F2_GPIO);
67     IoTGpioSetFunc(BUTTON_F2_GPIO, IOT_GPIO_FUNC_GPIO_12_GPIO);
68     IoTGpioSetDir(BUTTON_F2_GPIO, IOT_GPIO_DIR_IN);
69     IoTGpioSetPull(BUTTON_F2_GPIO, IOT_GPIO_PULL_UP);
70     IoTGpioRegisterIsrFunc(BUTTON_F2_GPIO, IOT_INT_TYPE_EDGE, IOT_GPIO_EDGE_FALL_LEVEL_LOW, F2Pressed, NULL);
71 }
72 
73 APP_FEATURE_INIT(ButtonExampleEntry);