/* * Copyright (c) 2020 Nanjing Xiaoxiongpai Intelligent 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 #include #include "cmsis_os2.h" #include "iot_gpio.h" #include "iot_gpio_ex.h" #include "ohos_init.h" #define LED_GPIO 2 #define BUTTON_F1_GPIO 11 #define BUTTON_F2_GPIO 12 /** * @brief Callback for F1 key * */ static void F1Pressed(char *arg) { (void)arg; IoTGpioSetOutputVal(LED_GPIO, 1); } /** * @brief Callback for F2 key * */ static void F2Pressed(char *arg) { (void)arg; IoTGpioSetOutputVal(LED_GPIO, 0); } /** * @brief Main Entry of the Button Example * */ static void ButtonExampleEntry(void) { // init gpio of LED IoTGpioInit(LED_GPIO); IoTGpioSetDir(LED_GPIO, IOT_GPIO_DIR_OUT); // init gpio of F1 key and set it as the falling edge to trigger interrupt IoTGpioInit(BUTTON_F1_GPIO); IoTGpioSetFunc(BUTTON_F1_GPIO, IOT_GPIO_FUNC_GPIO_11_GPIO); IoTGpioSetDir(BUTTON_F1_GPIO, IOT_GPIO_DIR_IN); IoTGpioSetPull(BUTTON_F1_GPIO, IOT_GPIO_PULL_UP); IoTGpioRegisterIsrFunc(BUTTON_F1_GPIO, IOT_INT_TYPE_EDGE, IOT_GPIO_EDGE_FALL_LEVEL_LOW, F1Pressed, NULL); // init gpio of F2 key and set it as the falling edge to trigger interrupt IoTGpioInit(BUTTON_F2_GPIO); IoTGpioSetFunc(BUTTON_F2_GPIO, IOT_GPIO_FUNC_GPIO_12_GPIO); IoTGpioSetDir(BUTTON_F2_GPIO, IOT_GPIO_DIR_IN); IoTGpioSetPull(BUTTON_F2_GPIO, IOT_GPIO_PULL_UP); IoTGpioRegisterIsrFunc(BUTTON_F2_GPIO, IOT_INT_TYPE_EDGE, IOT_GPIO_EDGE_FALL_LEVEL_LOW, F2Pressed, NULL); } APP_FEATURE_INIT(ButtonExampleEntry);