2 #include <util/delay.h>
4 #include <avr/interrupt.h>
10 static void hw_setup()
24 set_sleep_mode(SLEEP_MODE_IDLE);
27 static void inline hw_suspend()
37 void power_down(unsigned char err)
46 set_sleep_mode(SLEEP_MODE_PWR_DOWN);
56 // allow wakeup by long button-press only
57 } while (!buttons_wait_for_release());
59 // ok, so I will wake up
63 static void inline first_boot()
65 unsigned char mcusr_save;
67 // disable the WDT if running
73 if (mcusr_save & _BV(WDRF)) // was watchdog reset?
78 power_usi_disable(); // Once for lifetime
79 ACSRA |= _BV(ACD); // disable analog comparator
84 power_down(mcusr_save & _BV(WDRF));
89 static void inline main_loop_iteration()
93 set_sleep_mode(SLEEP_MODE_IDLE);
94 } else if (adc_is_on) {
95 set_sleep_mode(SLEEP_MODE_ADC);
97 set_sleep_mode(SLEEP_MODE_PWR_DOWN);
101 // keep BOD active, no sleep_bod_disable();
112 main_loop_iteration();
119 PORTB &=~ _BV( PB2 );