aboutsummaryrefslogtreecommitdiff
path: root/spaghetti-monster/fsm-pcint.c
diff options
context:
space:
mode:
authorSelene ToyKeeper2019-11-24 16:21:40 -0700
committerSelene ToyKeeper2019-11-24 16:21:40 -0700
commit30510a7948815f3092b8a2eff3321ad85ed5c480 (patch)
tree4a1b68628c779bf4092a64ae027917529d03e158 /spaghetti-monster/fsm-pcint.c
parentmerged changes from fsm branch, including version check and stuck-button safety (diff)
parentadded -fwhole-program gcc flag, suggested by Agro. Signficantly reduces ROM ... (diff)
downloadanduril-30510a7948815f3092b8a2eff3321ad85ed5c480.tar.gz
anduril-30510a7948815f3092b8a2eff3321ad85ed5c480.tar.bz2
anduril-30510a7948815f3092b8a2eff3321ad85ed5c480.zip
merged from upstream fsm branch to get a whole bunch of kernel-level improvements
Diffstat (limited to 'spaghetti-monster/fsm-pcint.c')
-rw-r--r--spaghetti-monster/fsm-pcint.c24
1 files changed, 8 insertions, 16 deletions
diff --git a/spaghetti-monster/fsm-pcint.c b/spaghetti-monster/fsm-pcint.c
index 4928980..1ba1c15 100644
--- a/spaghetti-monster/fsm-pcint.c
+++ b/spaghetti-monster/fsm-pcint.c
@@ -24,19 +24,9 @@
#include <util/delay_basic.h>
uint8_t button_is_pressed() {
- // remember the past 32 measurements
- static uint32_t readings = 0;
- // take at least one new measurement,
- // and wait for measurements to settle to all zeroes or all ones
- do {
- // shift past readings and add current value
- readings = (readings << 1) | ((SWITCH_PORT & (1<<SWITCH_PIN)) == 0);
- // wait a moment
- _delay_loop_2(BOGOMIPS/16); // up to 2ms to stabilize
- }
- while ((readings != 0) && (readings != 0xFFFFFFFF));
- button_last_state = readings;
- return readings;
+ uint8_t value = ((SWITCH_PORT & (1<<SWITCH_PIN)) == 0);
+ button_last_state = value;
+ return value;
}
inline void PCINT_on() {
@@ -75,7 +65,10 @@ inline void PCINT_off() {
//void button_change_interrupt() {
#if (ATTINY == 25) || (ATTINY == 45) || (ATTINY == 85) || (ATTINY == 1634)
-EMPTY_INTERRUPT(PCINT0_vect);
+//EMPTY_INTERRUPT(PCINT0_vect);
+ISR(PCINT0_vect) {
+ irq_pcint = 1;
+}
#else
#error Unrecognized MCU type
#endif
@@ -104,8 +97,7 @@ void PCINT_inner(uint8_t pressed) {
pushed = push_event(B_RELEASE);
}
- // check if sequence matches any defined sequences
- // if so, send event to current state callback
+ // send event to the current state callback
if (pushed) {
button_last_state = pressed;
emit_current_event(0);