- add eepromdata.h
[moodlight.git] / ledpwm.c
index dfc26d6801c06b9ed0970b56402a0359b34f764c..b9ef73cb8dcc15e83c03ad71da83034a2d703ba6 100644 (file)
--- a/ledpwm.c
+++ b/ledpwm.c
@@ -1,4 +1,4 @@
-/* $Id: ledpwm.c,v 1.1 2010/06/26 19:08:18 simimeie Exp $
+/* $Id: ledpwm.c,v 1.3 2010/07/10 07:34:51 simimeie Exp $
  * Functions for led brightness control via PWM (pulse width modulation).
  */
 
@@ -8,16 +8,21 @@
 /* Select between Phase correct PWM and Fast PWM mode.
  * setting this to 1 selects phase correct mode, everything else is Fast PWM. */
 #define PHASECORRECTPWM 1
+
 /*
  * Our hardware connections are as follows:
  *  Red -> PD6 / OC0A
  *  Green -> PD5 / OC0B
  *  Blue -> PD3 / OC2B
  */
+
+uint8_t ledpwm_re = 0xff, ledpwm_gr = 0xff, ledpwm_bl = 0xff;
+uint8_t ledpwm_bri = 128;
+
 void ledpwm_init(void)
 {
   /* Set OC2B, OC0A and OC0B to output */
-  DDRD |= _BV(PD3) | _BV(PD5) | _BV(PD6);
+  DDRD |= _BV(3) | _BV(5) | _BV(6);
   /* Set compare output mode for OC2B in timer counter control register: */
 #if (PHASECORRECTPWM == 1)
   /* select phase correct PWM mode (1). WGM2 bit is 0 so we don't need to touch TCCR2B. */
@@ -68,11 +73,11 @@ void ledpwm_setled(uint8_t led, uint8_t val)
 #else /* not PHASECORRECTPWM */
   if (val == 0) {
     switch (led) {
-    case LEDPWM_REDLED:   DDRD &= (uint8_t)~_BV(PD6);
+    case LEDPWM_REDLED:   DDRD &= (uint8_t)~_BV(6);
                           break;
-    case LEDPWM_GREENLED: DDRD &= (uint8_t)~_BV(PD5);
+    case LEDPWM_GREENLED: DDRD &= (uint8_t)~_BV(5);
                           break;
-    case LEDPWM_BLUELED:  DDRD &= (uint8_t)~_BV(PD3);
+    case LEDPWM_BLUELED:  DDRD &= (uint8_t)~_BV(3);
                           break;
     };
   } else {
@@ -81,16 +86,22 @@ void ledpwm_setled(uint8_t led, uint8_t val)
       val = 255;
     }
     switch (led) {
-    case LEDPWM_REDLED:   DDRD |= _BV(PD6);
+    case LEDPWM_REDLED:   DDRD |= _BV(6);
                           OCR0A = val;
                           break;
-    case LEDPWM_GREENLED: DDRD |= _BV(PD5);
+    case LEDPWM_GREENLED: DDRD |= _BV(5);
                           OCR0B = val;
                           break;
-    case LEDPWM_BLUELED:  DDRD |= _BV(PD3);
+    case LEDPWM_BLUELED:  DDRD |= _BV(3);
                           OCR2B = val;
                           break;
     };
   }
 #endif /* PHASECORRECTPWM */
 }
+
+void ledpwm_set(uint8_t red, uint8_t green, uint8_t blue, uint8_t br) {
+  ledpwm_setled(LEDPWM_REDLED,  (((uint16_t)red   * br) / 255));
+  ledpwm_setled(LEDPWM_GREENLED,(((uint16_t)green * br) / 255));
+  ledpwm_setled(LEDPWM_BLUELED, (((uint16_t)blue  * br) / 255));
+}
This page took 0.054835 seconds and 4 git commands to generate.