Merge pull request #11297 from SteveCEvans/baro_state
[betaflight.git] / src / main / drivers / buttons.c
bloba83ed83ef970336626b816e6a5b9b8b852da7936
1 /*
2 * This file is part of Cleanflight and Betaflight.
4 * Cleanflight and Betaflight are free software. You can redistribute
5 * this software and/or modify this software under the terms of the
6 * GNU General Public License as published by the Free Software
7 * Foundation, either version 3 of the License, or (at your option)
8 * any later version.
10 * Cleanflight and Betaflight are distributed in the hope that they
11 * will be useful, but WITHOUT ANY WARRANTY; without even the implied
12 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 * See the GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this software.
18 * If not, see <http://www.gnu.org/licenses/>.
21 #include <stdbool.h>
22 #include <stdint.h>
23 #include <string.h>
25 #include "platform.h"
27 #if defined(USE_BUTTONS)
29 #include "drivers/io.h"
31 #include "drivers/buttons.h"
33 #ifdef BUTTON_A_PIN
34 static IO_t buttonAPin = IO_NONE;
35 #endif
37 #ifdef BUTTON_B_PIN
38 static IO_t buttonBPin = IO_NONE;
39 #endif
41 #ifdef BUTTON_A_PIN_INVERTED
42 #define BUTTON_A_PIN_GPIO_MODE IOCFG_IPD
43 #else
44 #define BUTTON_A_PIN_GPIO_MODE IOCFG_IPU
45 #endif
47 #ifdef BUTTON_B_PIN_INVERTED
48 #define BUTTON_B_PIN_GPIO_MODE IOCFG_IPD
49 #else
50 #define BUTTON_B_PIN_GPIO_MODE IOCFG_IPU
51 #endif
53 void buttonsInit(void)
55 #ifdef BUTTON_A_PIN
56 buttonAPin = IOGetByTag(IO_TAG(BUTTON_A_PIN));
57 IOInit(buttonAPin, OWNER_SYSTEM, 0);
58 IOConfigGPIO(buttonAPin, BUTTON_A_PIN_GPIO_MODE);
59 #endif
61 #ifdef BUTTON_B_PIN
62 buttonBPin = IOGetByTag(IO_TAG(BUTTON_B_PIN));
63 IOInit(buttonBPin, OWNER_SYSTEM, 0);
64 IOConfigGPIO(buttonBPin, BUTTON_B_PIN_GPIO_MODE);
65 #endif
68 #ifdef BUTTON_A_PIN
69 bool buttonAPressed(void)
71 #ifdef BUTTON_A_PIN_INVERTED
72 return IORead(buttonAPin);
73 #else
74 return !IORead(buttonAPin);
75 #endif
77 #endif
79 #ifdef BUTTON_B_PIN
80 bool buttonBPressed(void)
82 #ifdef BUTTON_B_PIN_INVERTED
83 return IORead(buttonBPin);
84 #else
85 return !IORead(buttonBPin);
86 #endif
88 #endif
90 #endif