aboutsummaryrefslogtreecommitdiff
path: root/spaghetti-monster/fsm-adc.h
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-adc.h
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-adc.h')
-rw-r--r--spaghetti-monster/fsm-adc.h16
1 files changed, 13 insertions, 3 deletions
diff --git a/spaghetti-monster/fsm-adc.h b/spaghetti-monster/fsm-adc.h
index 274fb4d..6e39750 100644
--- a/spaghetti-monster/fsm-adc.h
+++ b/spaghetti-monster/fsm-adc.h
@@ -38,9 +38,18 @@
#define VOLTAGE_FUDGE_FACTOR 5
#endif
#endif
+
+volatile uint8_t irq_adc = 0; // ADC interrupt happened?
+volatile uint8_t irq_adc_stable = 0; // have we passed the 1st junk value yet?
+uint8_t adc_channel = 0; // 0=voltage, 1=temperature
+uint16_t adc_values[2]; // last ADC measurements (0=voltage, 1=temperature)
+uint8_t adcint_enable = 0; // is the current ADC result needed?
+void ADC_inner(); // do the actual ADC-related calculations
+
+static inline void ADC_voltage_handler();
volatile uint8_t voltage = 0;
-volatile uint8_t adcint_enable; // kludge, because adc auto-retrigger won't turn off
void low_voltage();
+
#ifdef USE_BATTCHECK
void battcheck();
#ifdef BATTCHECK_VpT
@@ -50,7 +59,7 @@ void battcheck();
#define USE_BLINK_DIGIT
#endif
#endif
-#endif
+#endif // ifdef USE_LVP
#ifdef USE_THERMAL_REGULATION
@@ -79,7 +88,8 @@ int8_t therm_cal_offset = 0;
//void low_temperature();
//void high_temperature();
volatile uint8_t reset_thermal_history = 1;
-#endif
+static inline void ADC_temperature_handler();
+#endif // ifdef USE_THERMAL_REGULATION
inline void ADC_on();