#include #include #include #include #include "led.h" #include "sleep_led.h" /* Software PWM * ______ ______ __ * | ON |___OFF___| ON |___OFF___| .... * |<-------------->|<-------------->|<- .... * PWM period PWM period * * 256 interrupts/period[resolution] * 64 periods/second[frequency] * 256*64 interrupts/second * F_CPU/(256*64) clocks/interrupt */ #define SLEEP_LED_TIMER_TOP F_CPU/(256*64) void sleep_led_init(void) { /* Timer1 setup */ /* CTC mode */ TCCR1B |= _BV(WGM12); /* Clock selelct: clk/1 */ TCCR1B |= _BV(CS10); /* Set TOP value */ uint8_t sreg = SREG; cli(); OCR1AH = (SLEEP_LED_TIMER_TOP>>8)&0xff; OCR1AL = SLEEP_LED_TIMER_TOP&0xff; SREG = sreg; } void sleep_led_enable(void) { /* Enable Compare Match Interrupt */ TIMSK1 |= _BV(OCIE1A); } void sleep_led_disable(void) { /* Disable Compare Match Interrupt */ TIMSK1 &= ~_BV(OCIE1A); } __attribute__ ((weak)) void sleep_led_on(void) { led_set(1<