#include #include "lib/mystd.h" #include "lib/timer0.h" #include "lib/timer2.h" #define D5_R PD5 #define D5_G PD6 #define D5_B PD3 #define RGB_MASK (BV(D5_R) | BV(D5_G) | BV(D5_B)) void init_rgb(void) { t0_init_fpwm_3(PRESCALER_64); t2_init_fpwm_3(PRESCALER_64); t0_set_out_mode(TO_A | TO_B, TOM_00); t2_set_out_mode(TO_B, TOM_00); DDRD |= RGB_MASK; } void set_rgb(uint8_t r, uint8_t g, uint8_t b) { if (r == 0x00) { t0_set_out_mode(TO_B, TOM_00); PORTD = (PORTD & ~BV(D5_R)); } else { t0_set_out_mode(TO_B, TOM_10); t0_set_ocr(TO_B, r); } if (g == 0x00) { t0_set_out_mode(TO_A, TOM_00); PORTD = (PORTD & ~BV(D5_G)); } else { t0_set_out_mode(TO_A, TOM_10); t0_set_ocr(TO_A, g); } if (b == 0x00) { t2_set_out_mode(TO_B, TOM_00); PORTD = (PORTD & ~BV(D5_B)); } else { t2_set_out_mode(TO_B, TOM_10); t2_set_ocr(TO_B, b); } }