aboutsummaryrefslogtreecommitdiff
path: root/spaghetti-monster
diff options
context:
space:
mode:
authorSelene ToyKeeper2017-10-01 18:19:34 -0600
committerSelene ToyKeeper2017-10-01 18:19:34 -0600
commit4a640e385f63e747adfafafa450335d9eb0526ab (patch)
tree977dcdc2bcd7b4bbfcd5b1b495409e7a6a7ca7f1 /spaghetti-monster
parentMade dual-switch startup optionally go to moon if e-switch is held. (diff)
downloadanduril-4a640e385f63e747adfafafa450335d9eb0526ab.tar.gz
anduril-4a640e385f63e747adfafafa450335d9eb0526ab.tar.bz2
anduril-4a640e385f63e747adfafafa450335d9eb0526ab.zip
Use either full or quarter speed in nice delays, based on output level.
This fixes issues with some blinky modes being audible (particularly biking and lightning modes), without sacrificing the power savings for other blinkies (like beacon and battcheck).
Diffstat (limited to 'spaghetti-monster')
-rw-r--r--spaghetti-monster/fsm-events.c20
1 files changed, 19 insertions, 1 deletions
diff --git a/spaghetti-monster/fsm-events.c b/spaghetti-monster/fsm-events.c
index e965224..b8e9018 100644
--- a/spaghetti-monster/fsm-events.c
+++ b/spaghetti-monster/fsm-events.c
@@ -125,16 +125,34 @@ uint8_t nice_delay_ms(uint16_t ms) {
*/
while(ms-- > 0) {
#ifdef USE_DYNAMIC_UNDERCLOCKING
+ #ifdef USE_RAMPING
+ uint8_t level = actual_level; // volatile, avoid repeat access
+ if (level < QUARTERSPEED_LEVEL) {
+ CLKPR = 1<<CLKPCE; CLKPR = 2;
+ _delay_loop_2(BOGOMIPS*98/100/4);
+ }
+ //else if (level < HALFSPEED_LEVEL) {
+ // CLKPR = 1<<CLKPCE; CLKPR = 1;
+ // _delay_loop_2(BOGOMIPS*98/100/2);
+ //}
+ else {
+ CLKPR = 1<<CLKPCE; CLKPR = 0;
+ _delay_loop_2(BOGOMIPS*98/100);
+ }
+ // restore regular clock speed
+ CLKPR = 1<<CLKPCE; CLKPR = 0;
+ #else
// underclock MCU to save power
CLKPR = 1<<CLKPCE; CLKPR = 2;
// wait
_delay_loop_2(BOGOMIPS*98/100/4);
// restore regular clock speed
CLKPR = 1<<CLKPCE; CLKPR = 0;
+ #endif // ifdef USE_RAMPING
#else
// wait
_delay_loop_2(BOGOMIPS*98/100);
- #endif
+ #endif // ifdef USE_DYNAMIC_UNDERCLOCKING
process_emissions();
if ((nice_delay_interrupt) || (old_state != current_state)) {
If you find this content useful please consider a small donation via bitcoin: bitcoin:1mxKyQsHHugqRxPKgwaA7wUwJEGCNthn2?amount=0.001&message=Donation Scraping git contents via cgit is very resource intensive. The continued hosting of these git repositories is entirely financed by your bitcoin contributions. For donations of a least 1 mBTC you include your IP address in the message of your bitcoin donation. This will remove this message in the future for requests from your IP, which will significantly reduce token usage. In any case, any contributions to bitcoin address 1mxKyQsHHugqRxPKgwaA7wUwJEGCNthn2 are very welcome. Thanks in advance for you contribution to a self-sustaining ecosystem.