#include #include #include "led.h" #include "softpwm_led.h" #include "debug.h" #define SOFTPWM_LED_FREQ 64 #define SOFTPWM_LED_TIMER_TOP F_CPU / (256 * SOFTPWM_LED_FREQ) static uint8_t softpwm_led_state = 0; static uint8_t softpwm_led_ocr[LED_COUNT] = {0}; static uint8_t softpwm_led_ocr_buff[LED_COUNT] = {0}; void softpwm_led_init(void) { #ifdef SOFTPWM_LED_TIMER3 /* Timer3 setup */ /* CTC mode */ TCCR3B |= (1<> 8) & 0xff; OCR3AL = SOFTPWM_LED_TIMER_TOP & 0xff; SREG = sreg; #else /* Timer1 setup */ /* CTC mode */ TCCR1B |= (1<> 8) & 0xff; OCR1AL = SOFTPWM_LED_TIMER_TOP & 0xff; SREG = sreg; #endif } void softpwm_led_enable(void) { /* Enable Compare Match Interrupt */ #ifdef SOFTPWM_LED_TIMER3 TIMSK3 |= (1< SOFTPWM_LED_FREQ) { count = 0; for (uint8_t i = 0; i < LED_COUNT; i++) { if (breathing_led_state & LED_BIT(i)) { if (++step[i] > breathing_led_duration[i]) { step[i] = 0; softpwm_led_ocr_buff[i] = pgm_read_byte(&breathing_table[index[i]]); index[i]++; } } } } } #endif }