This does not compile yet, to be fixed.
/* adc.c */
#define PWMLED_ADC_SHIFT 1 /* 1<<1 measurements per single callback */
extern volatile unsigned char need_battery_adc;
+extern volatile unsigned char adc_running;
void init_adc();
void susp_adc();
/* pwm.c */
#define PWM_MAX 0xFF
+extern volatile unsigned char pwm_running;
void init_pwm();
void susp_pwm();
void pwm_off();
sei();
#if 1
while (1) {
- sleep_mode();
+ cli();
+ if (pwm_running) {
+ set_sleep_mode(SLEEP_MODE_IDLE);
+ } else if (adc_running) {
+ set_sleep_mode(SLEEP_MODE_ADC);
+ } else {
+ set_sleep_mode(SLEEP_MODE_PWR_DOWN);
+ }
+ // keep BOD active, no sleep_bod_disable();
+ sei();
+ sleep_cpu();
+ sleep_disable();
}
#endif