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 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
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));
91 set_sleep_mode(SLEEP_MODE_IDLE);
92 } else if (adc_is_on) {
93 set_sleep_mode(SLEEP_MODE_ADC);
95 set_sleep_mode(SLEEP_MODE_PWR_DOWN);
99 // keep BOD active, no sleep_bod_disable();
111 PORTB &=~ _BV( PB2 );