From: Jan "Yenya" Kasprzak Date: Mon, 3 Jun 2013 15:56:06 +0000 (+0200) Subject: main.c: on-demand sleep modes X-Git-Url: https://www.fi.muni.cz/~kas/git//home/kas/public_html/git/?a=commitdiff_plain;h=64f1e5840b7b8839885a76812e6be97cdd39c6cd;p=bike-lights.git main.c: on-demand sleep modes --- diff --git a/firmware/main.c b/firmware/main.c index 0e33957..a83884b 100644 --- a/firmware/main.c +++ b/firmware/main.c @@ -71,7 +71,20 @@ int main(void) sei(); #if 1 while (1) { - sleep_mode(); + cli(); + if (TIMER1_IS_ON()) { + set_sleep_mode(SLEEP_MODE_IDLE); + } else if (adc_is_on) { + set_sleep_mode(SLEEP_MODE_ADC); + } else { + set_sleep_mode(SLEEP_MODE_PWR_DOWN); + } + + sleep_enable(); + // keep BOD active, no sleep_bod_disable(); + sei(); + sleep_cpu(); + sleep_disable(); } #endif