aboutsummaryrefslogtreecommitdiff
path: root/spaghetti-monster/fsm-main.c
diff options
context:
space:
mode:
authorSelene ToyKeeper2019-08-11 15:16:23 -0600
committerSelene ToyKeeper2019-08-11 15:16:23 -0600
commit89a86871aa6330218043586f0347c0c1e7c79dab (patch)
treee3a4cc2a4517e5563e91cdaaf86718170d4f0a37 /spaghetti-monster/fsm-main.c
parentAdded setup info for Fedora. (diff)
parentadded scripts to flash attiny1634, which were missing before (diff)
downloadanduril-89a86871aa6330218043586f0347c0c1e7c79dab.tar.gz
anduril-89a86871aa6330218043586f0347c0c1e7c79dab.tar.bz2
anduril-89a86871aa6330218043586f0347c0c1e7c79dab.zip
merged fsm to trunk... lots of updates:
+ attiny1634 support + Emisar D4v2 support + Mateminco MF01S / MT18 support + Fireflies E01 and E07v2 support + RGB aux LED support + added factory reset function + added manual / automatic memory toggle + added 2-level brightness during lockout + added Fireflies UI + made momentary mode also support strobe-group modes * thermal regulation rewritten, behaves mostly better now * strobe modes auto-reverse their ramp now * muggle mode fixes * UI diagram and manual updated * button timing adjusted, and compile-time options added for it * general refactoring
Diffstat (limited to 'spaghetti-monster/fsm-main.c')
-rw-r--r--spaghetti-monster/fsm-main.c51
1 files changed, 41 insertions, 10 deletions
diff --git a/spaghetti-monster/fsm-main.c b/spaghetti-monster/fsm-main.c
index 6f74e9b..e537a9e 100644
--- a/spaghetti-monster/fsm-main.c
+++ b/spaghetti-monster/fsm-main.c
@@ -36,16 +36,8 @@ ISR(TIMER1_COMPA_vect) {
}
#endif
-int main() {
- // Don't allow interrupts while booting
- cli();
-
- #ifdef HALFSPEED
- // run at half speed
- CLKPR = 1<<CLKPCE;
- CLKPR = 1;
- #endif
-
+#if (ATTINY == 25) || (ATTINY == 45) || (ATTINY == 85)
+inline void hw_setup() {
// configure PWM channels
#if PWM_CHANNELS >= 1
DDRB |= (1 << PWM1_PIN);
@@ -75,6 +67,45 @@ int main() {
// configure e-switch
PORTB = (1 << SWITCH_PIN); // e-switch is the only input
PCMSK = (1 << SWITCH_PIN); // pin change interrupt uses this pin
+}
+#elif (ATTINY == 1634)
+inline void hw_setup() {
+ // this gets tricky with so many pins...
+ // ... so punt it to the hwdef file
+ hwdef_setup();
+}
+#else
+ #error Unrecognized MCU type
+#endif
+
+
+#ifdef USE_REBOOT
+void prevent_reboot_loop() {
+ // prevent WDT from rebooting MCU again
+ MCUSR &= ~(1<<WDRF); // reset status flag
+ wdt_disable();
+}
+#endif
+
+
+int main() {
+ // Don't allow interrupts while booting
+ cli();
+
+ #ifdef USE_REBOOT
+ prevent_reboot_loop();
+ #endif
+
+ hw_setup();
+
+ #if 0
+ #ifdef HALFSPEED
+ // run at half speed
+ // FIXME: not portable (also not needed)
+ CLKPR = 1<<CLKPCE;
+ CLKPR = 1;
+ #endif
+ #endif
#ifdef USE_DEBUG_BLINK
//debug_blink(1);