aboutsummaryrefslogtreecommitdiff
path: root/spaghetti-monster/fsm-main.c
diff options
context:
space:
mode:
authorSelene ToyKeeper2019-08-05 01:44:30 -0600
committerSelene ToyKeeper2019-08-05 01:44:30 -0600
commit24f290888e4132e8f67989de3fa42f492dc5bb8b (patch)
treef82fd0f22b3a979c1a63e1dcb21ee253cc67335b /spaghetti-monster/fsm-main.c
parentreplaced deprecated avr-size with avr-objdump in build.sh (diff)
parentmerged a sanitized copy of the Emisar D4v2 branch; history summarized below: (diff)
downloadanduril-24f290888e4132e8f67989de3fa42f492dc5bb8b.tar.gz
anduril-24f290888e4132e8f67989de3fa42f492dc5bb8b.tar.bz2
anduril-24f290888e4132e8f67989de3fa42f492dc5bb8b.zip
merged Emisar D4v2 branch, or at least a sanitized version of it
Diffstat (limited to 'spaghetti-monster/fsm-main.c')
-rw-r--r--spaghetti-monster/fsm-main.c56
1 files changed, 41 insertions, 15 deletions
diff --git a/spaghetti-monster/fsm-main.c b/spaghetti-monster/fsm-main.c
index 1c28f5f..e537a9e 100644
--- a/spaghetti-monster/fsm-main.c
+++ b/spaghetti-monster/fsm-main.c
@@ -36,21 +36,8 @@ ISR(TIMER1_COMPA_vect) {
}
#endif
-int main() {
- // Don't allow interrupts while booting
- cli();
-
- #ifdef USE_REBOOT // prevent reboot loops
- MCUSR &= ~(1<<WDRF); // reset status flag
- wdt_disable();
- #endif
-
- #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);
@@ -80,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);