~toykeeper/flashlight-firmware/fsm

« back to all changes in this revision

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

  • Committer: Selene ToyKeeper
  • Date: 2023-10-29 19:05:38 UTC
  • mto: (483.1.175 anduril2)
  • mto: This revision was merged to the branch mainline in revision 491.
  • Revision ID: bzr@toykeeper.net-20231029190538-8u28ea5apb4hkgi2
converted noctigon-dm11-boost to use PWM+DSM, and recalibrated timing for delays + smooth steps

Anduril has gradually gotten faster over the years, apparently, so it
needed longer delays to get accurate-ish timing for beacon and other modes.
Adding DSM also changes the timing perceptibly, so I made it possible to
calibrate the delay fudge factor on a per-build basis.

Show diffs side-by-side

added added

removed removed

Lines of Context:
127
127
        uint8_t level = actual_level;  // volatile, avoid repeat access
128
128
        if (level < QUARTERSPEED_LEVEL) {
129
129
            clock_prescale_set(clock_div_4);
130
 
            _delay_loop_2(BOGOMIPS*90/100/4);
 
130
            _delay_loop_2(BOGOMIPS*DELAY_FACTOR/100/4);
131
131
        }
132
132
        //else if (level < HALFSPEED_LEVEL) {
133
133
        //    clock_prescale_set(clock_div_2);
135
135
        //}
136
136
        else {
137
137
            clock_prescale_set(clock_div_1);
138
 
            _delay_loop_2(BOGOMIPS*90/100);
 
138
            _delay_loop_2(BOGOMIPS*DELAY_FACTOR/100);
139
139
        }
140
140
        // restore regular clock speed
141
141
        clock_prescale_set(clock_div_1);
143
143
        // underclock MCU to save power
144
144
        clock_prescale_set(clock_div_4);
145
145
        // wait
146
 
        _delay_loop_2(BOGOMIPS*90/100/4);
 
146
        _delay_loop_2(BOGOMIPS*DELAY_FACTOR/100/4);
147
147
        // restore regular clock speed
148
148
        clock_prescale_set(clock_div_1);
149
149
        #endif  // ifdef USE_RAMPING
150
150
        #else
151
151
        // wait
152
 
        _delay_loop_2(BOGOMIPS*90/100);
 
152
        _delay_loop_2(BOGOMIPS*DELAY_FACTOR/100);
153
153
        #endif  // ifdef USE_DYNAMIC_UNDERCLOCKING
154
154
 
155
155
        // run pending system processes while we wait