aboutsummaryrefslogtreecommitdiff
path: root/spaghetti-monster/fsm-standby.c
diff options
context:
space:
mode:
authorSelene ToyKeeper2019-11-19 00:44:14 -0700
committerSelene ToyKeeper2019-11-19 00:44:14 -0700
commitd6d40c54707bd840bff3e919e99f7a8bf03ee526 (patch)
tree90086acbcabd0ce5a34fef5298f780cf8e8b13b4 /spaghetti-monster/fsm-standby.c
parentadded SOS mode to the BLF LT1 Lantern build, because people wanted it (diff)
parentMateminco MF01S can fit muggle mode again, barely (diff)
downloadanduril-d6d40c54707bd840bff3e919e99f7a8bf03ee526.tar.gz
anduril-d6d40c54707bd840bff3e919e99f7a8bf03ee526.tar.bz2
anduril-d6d40c54707bd840bff3e919e99f7a8bf03ee526.zip
merged irq-refactor branch, which fixes some small but long-standing issues:
- fixed occasional short/aborted frames in aux LED sleep animation - fixed rare case of bogus voltage and/or temperature values - fixed issue where nice_delay_ms() didn't work in setup() - fixed theoretical possibility of extra-noisy buttons causing a hang - fixed reboot loop which happened after any crashes - fixed issue where button press in sleep mode could occasionally crash (but the issue may have been created by this branch before being fixed by it) - reduced occasional missed button events while asleep (still seems to happen but not nearly as much) Also does some other things: - cleans up the ADC code significantly - cleans up the WDT code - adds a voltage stabilizer/lowpass option (enabled on t1634 builds) - greatly reduces time spent per interrupt, which might make a future PWM-DSM technique possible - moves most interrupt-handling logic to a non-critical code path, deferring that code until timing doesn't matter as much - sped up button state measurements - very slightly reduces power used in sleep mode
Diffstat (limited to 'spaghetti-monster/fsm-standby.c')
-rw-r--r--spaghetti-monster/fsm-standby.c29
1 files changed, 22 insertions, 7 deletions
diff --git a/spaghetti-monster/fsm-standby.c b/spaghetti-monster/fsm-standby.c
index 44b047a..e4ef92c 100644
--- a/spaghetti-monster/fsm-standby.c
+++ b/spaghetti-monster/fsm-standby.c
@@ -42,16 +42,19 @@ void sleep_until_eswitch_pressed()
// make sure switch isn't currently pressed
while (button_is_pressed()) {}
empty_event_sequence(); // cancel pending input on suspend
- //PCINT_since_WDT = 0; // ensure PCINT won't ignore itself
-
- PCINT_on(); // wake on e-switch event
#ifdef TICK_DURING_STANDBY
+ // detect which type of event caused a wake-up
+ irq_adc = 0;
+ irq_wdt = 0;
+ irq_pcint = 0;
while (go_to_standby) {
- f_wdt = 0; // detect if WDT was what caused a wake-up
#else
go_to_standby = 0;
#endif
+
+ PCINT_on(); // wake on e-switch event
+
// configure sleep mode
set_sleep_mode(SLEEP_MODE_PWR_DOWN);
@@ -65,10 +68,19 @@ void sleep_until_eswitch_pressed()
sleep_disable();
#ifdef TICK_DURING_STANDBY
- // determine what woke us up... WDT or PCINT
- if (! f_wdt) { // PCINT went off; wake up
+ // determine what woke us up...
+ if (irq_pcint) { // button pressed; wake up
go_to_standby = 0;
}
+ if (irq_adc) { // ADC done measuring
+ adcint_enable = 1;
+ ADC_inner();
+ //ADC_off(); // takes care of itself
+ //irq_adc = 0; // takes care of itself
+ }
+ if (irq_wdt) { // generate a sleep tick
+ WDT_inner();
+ }
}
#endif
@@ -78,7 +90,10 @@ void sleep_until_eswitch_pressed()
#endif
// go back to normal running mode
- //PCINT_on(); // should be on already
+ // PCINT not needed any more, and can cause problems if on
+ // (occasional reboots on wakeup-by-button-press)
+ PCINT_off();
+ // restore normal awake-mode interrupts
ADC_on();
WDT_on();
}