~toykeeper/flashlight-firmware/trunk

« back to all changes in this revision

Viewing changes to ToyKeeper/spaghetti-monster/fsm-standby.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:
42
42
    // make sure switch isn't currently pressed
43
43
    while (button_is_pressed()) {}
44
44
    empty_event_sequence();  // cancel pending input on suspend
45
 
    //PCINT_since_WDT = 0;  // ensure PCINT won't ignore itself
46
45
 
47
46
    PCINT_on();  // wake on e-switch event
48
47
 
49
48
    #ifdef TICK_DURING_STANDBY
 
49
    // detect which type of event caused a wake-up
 
50
    irq_adc = 0;
 
51
    irq_wdt = 0;
 
52
    irq_pcint = 0;
50
53
    while (go_to_standby) {
51
 
        f_wdt = 0;  // detect if WDT was what caused a wake-up
52
54
    #else
53
55
        go_to_standby = 0;
54
56
    #endif
 
57
 
55
58
        // configure sleep mode
56
59
        set_sleep_mode(SLEEP_MODE_PWR_DOWN);
57
60
 
65
68
        sleep_disable();
66
69
 
67
70
    #ifdef TICK_DURING_STANDBY
68
 
        // determine what woke us up... WDT or PCINT
69
 
        if (! f_wdt) {  // PCINT went off; wake up
 
71
        // determine what woke us up...
 
72
        if (irq_pcint) {  // button pressed; wake up
70
73
            go_to_standby = 0;
71
74
        }
 
75
        if (irq_adc) {  // ADC done measuring
 
76
            adc_deferred_enable = 1;
 
77
            adc_deferred();
 
78
            //ADC_off();  // takes care of itself
 
79
            //irq_adc = 0;  // takes care of itself
 
80
        }
 
81
        if (irq_wdt) {  // generate a sleep tick
 
82
            WDT_inner();
 
83
        }
72
84
    }
73
85
    #endif
74
86
 
78
90
    #endif
79
91
 
80
92
    // go back to normal running mode
81
 
    //PCINT_on();  // should be on already
 
93
    // PCINT not needed any more, and can cause problems if on
 
94
    // (occasional reboots on wakeup-by-button-press)
 
95
    PCINT_off();
 
96
    // restore normal awake-mode interrupts
82
97
    ADC_on();
83
98
    WDT_on();
84
99
}