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)
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/>.
27 #if defined(USE_BUTTONS)
29 #include "drivers/io.h"
31 #include "drivers/buttons.h"
34 static IO_t buttonAPin
= IO_NONE
;
38 static IO_t buttonBPin
= IO_NONE
;
41 #ifdef BUTTON_A_PIN_INVERTED
42 #define BUTTON_A_PIN_GPIO_MODE IOCFG_IPD
44 #define BUTTON_A_PIN_GPIO_MODE IOCFG_IPU
47 #ifdef BUTTON_B_PIN_INVERTED
48 #define BUTTON_B_PIN_GPIO_MODE IOCFG_IPD
50 #define BUTTON_B_PIN_GPIO_MODE IOCFG_IPU
53 void buttonsInit(void)
56 buttonAPin
= IOGetByTag(IO_TAG(BUTTON_A_PIN
));
57 IOInit(buttonAPin
, OWNER_SYSTEM
, 0);
58 IOConfigGPIO(buttonAPin
, BUTTON_A_PIN_GPIO_MODE
);
62 buttonBPin
= IOGetByTag(IO_TAG(BUTTON_B_PIN
));
63 IOInit(buttonBPin
, OWNER_SYSTEM
, 0);
64 IOConfigGPIO(buttonBPin
, BUTTON_B_PIN_GPIO_MODE
);
69 bool buttonAPressed(void)
71 #ifdef BUTTON_A_PIN_INVERTED
72 return IORead(buttonAPin
);
74 return !IORead(buttonAPin
);
80 bool buttonBPressed(void)
82 #ifdef BUTTON_B_PIN_INVERTED
83 return IORead(buttonBPin
);
85 return !IORead(buttonBPin
);