1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-12-23 14:58:09 +00:00
trezor-firmware/legacy/buttons.c

71 lines
2.2 KiB
C
Raw Normal View History

2014-04-29 12:26:51 +00:00
/*
* This file is part of the Trezor project, https://trezor.io/
2014-04-29 12:26:51 +00:00
*
* Copyright (C) 2014 Pavol Rusnak <stick@satoshilabs.com>
*
* This library is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
#include "buttons.h"
struct buttonState button;
2017-12-13 18:38:51 +00:00
#if !EMULATOR
uint16_t buttonRead(void) { return gpio_port_read(BTN_PORT); }
2017-12-13 18:38:51 +00:00
#endif
void buttonUpdate(void) {
static uint16_t last_state = BTN_PIN_YES | BTN_PIN_NO;
2014-04-29 12:26:51 +00:00
uint16_t state = buttonRead();
2014-04-29 12:26:51 +00:00
if ((state & BTN_PIN_YES) == 0) { // Yes button is down
if ((last_state & BTN_PIN_YES) == 0) { // last Yes was down
if (button.YesDown < 2000000000) button.YesDown++;
button.YesUp = false;
} else { // last Yes was up
button.YesDown = 0;
button.YesUp = false;
}
} else { // Yes button is up
if ((last_state & BTN_PIN_YES) == 0) { // last Yes was down
button.YesDown = 0;
button.YesUp = true;
} else { // last Yes was up
button.YesDown = 0;
button.YesUp = false;
}
}
2014-04-29 12:26:51 +00:00
if ((state & BTN_PIN_NO) == 0) { // No button is down
if ((last_state & BTN_PIN_NO) == 0) { // last No was down
if (button.NoDown < 2000000000) button.NoDown++;
button.NoUp = false;
} else { // last No was up
button.NoDown = 0;
button.NoUp = false;
}
} else { // No button is up
if ((last_state & BTN_PIN_NO) == 0) { // last No was down
button.NoDown = 0;
button.NoUp = true;
} else { // last No was up
button.NoDown = 0;
button.NoUp = false;
}
}
2014-04-29 12:26:51 +00:00
last_state = state;
2014-04-29 12:26:51 +00:00
}