~toykeeper/flashlight-firmware/trunk

« back to all changes in this revision

Viewing changes to ToyKeeper/spaghetti-monster/fsm-main.c

  • Committer: Selene Scriven
  • Date: 2020-07-06 20:24:28 UTC
  • mfrom: (188.1.294 fsm)
  • Revision ID: bzr@toykeeper.net-20200706202428-7pyen2ow9q2rtd9p
merged nearly a year of updates from the fsm branch, including the new product map

Show diffs side-by-side

added added

removed removed

Lines of Context:
37
37
#endif
38
38
 
39
39
#if (ATTINY == 25) || (ATTINY == 45) || (ATTINY == 85)
40
 
inline void hw_setup() {
 
40
static inline void hw_setup() {
41
41
    // configure PWM channels
42
42
    #if PWM_CHANNELS >= 1
43
43
    DDRB |= (1 << PWM1_PIN);
69
69
    PCMSK = (1 << SWITCH_PIN);  // pin change interrupt uses this pin
70
70
}
71
71
#elif (ATTINY == 1634)
72
 
inline void hw_setup() {
 
72
static inline void hw_setup() {
73
73
    // this gets tricky with so many pins...
74
74
    // ... so punt it to the hwdef file
75
75
    hwdef_setup();
79
79
#endif
80
80
 
81
81
 
82
 
#ifdef USE_REBOOT
83
 
void prevent_reboot_loop() {
 
82
//#ifdef USE_REBOOT
 
83
static inline void prevent_reboot_loop() {
84
84
    // prevent WDT from rebooting MCU again
85
85
    MCUSR &= ~(1<<WDRF);  // reset status flag
86
86
    wdt_disable();
87
87
}
88
 
#endif
 
88
//#endif
89
89
 
90
90
 
91
91
int main() {
92
92
    // Don't allow interrupts while booting
93
93
    cli();
94
94
 
95
 
    #ifdef USE_REBOOT
 
95
    //#ifdef USE_REBOOT
 
96
    // prevents cycling after a crash,
 
97
    // whether intentional (like factory reset) or not (bugs)
96
98
    prevent_reboot_loop();
97
 
    #endif
 
99
    //#endif
98
100
 
99
101
    hw_setup();
100
102
 
123
125
    #else
124
126
    delay_4ms(1);
125
127
    #endif
126
 
    empty_event_sequence();
127
128
 
128
129
    // fallback for handling a few things
129
130
    #ifndef DONT_USE_DEFAULT_STATE
160
161
            standby_mode();
161
162
        }
162
163
 
 
164
        // catch up on interrupts
 
165
        handle_deferred_interrupts();
 
166
 
163
167
        // give the recipe some time slices
164
168
        loop();
165
169
 
168
172
    }
169
173
}
170
174
 
 
175
 
 
176
void handle_deferred_interrupts() {
 
177
    /*
 
178
    if (irq_pcint) {  // button pressed or released
 
179
        // nothing to do here
 
180
        // (PCINT only matters during standby)
 
181
    }
 
182
    */
 
183
    if (irq_adc) {  // ADC done measuring
 
184
        adc_deferred();
 
185
        // irq_adc = 0;  // takes care of itself
 
186
    }
 
187
    if (irq_wdt) {  // the clock ticked
 
188
        WDT_inner();
 
189
        // irq_wdt = 0;  // takes care of itself
 
190
    }
 
191
}
 
192
 
171
193
#endif