]> oss.titaniummirror.com Git - rgblamp.git/blobdiff - rgb.h
Merge new functionality
[rgblamp.git] / rgb.h
diff --git a/rgb.h b/rgb.h
index d24b41bf34cd3a389cb62b6865551911009608d5..b2149edfaffd1786bf89066bfeb0bce5084495e3 100644 (file)
--- a/rgb.h
+++ b/rgb.h
 
 #include "isr.h"
 
+/* Optional brightness compensation.  Pick zero or one */
+#define CEIL256
+#undef CEIL32
+
 /* Initialize the RGB LED assembly.  Outputs are zero, PWM is off. */
 void rgb_init();
 
 /* Turn on the rgb.  Outputs are zero, or last values set by rgb_set(). */
-#define rgb_on() do { TMR2ON = 1; } while (0)
+#define rgb_on() (TMR2ON = 1)
 
 /* Turn off the rgb, first setting outputs to zero. */
 void rgb_off();
 
 /* Set a PWM value for each color LED.  0=off, 255=full on. */
+#ifdef CEIL256
+extern const unsigned char pwm_table[];
+#define rgb_set(red, grn, blu, wht) do { \
+    ndi(); /* FIXME: doesn't seem to fix flicker */ \
+    CCPR3L = pwm_table[(red)]; \
+    CCPR2L = pwm_table[(grn)]; \
+    CCPR4L = pwm_table[(blu)]; \
+    CCPR1L = pwm_table[(wht)]; \
+    nei(); \
+} while (0)
+#else
+#ifdef CEIL32
+extern const unsigned char pwm_table[];
 #define rgb_set(red, grn, blu, wht) do { \
     ndi(); /* FIXME: doesn't seem to fix flicker */ \
-    CCPR1L = (red); \
+    CCPR3L = pwm_table[(red) >> 3]; \
+    CCPR2L = pwm_table[(grn) >> 3]; \
+    CCPR4L = pwm_table[(blu) >> 3]; \
+    CCPR1L = pwm_table[(wht) >> 3]; \
+    nei(); \
+} while (0)
+#else
+#define rgb_set(red, grn, blu, wht) do { \
+    ndi(); /* FIXME: doesn't seem to fix flicker */ \
+    CCPR3L = (red); \
     CCPR2L = (grn); \
-    CCPR3L = (blu); \
-    CCPR4L = (wht); \
+    CCPR4L = (blu); \
+    CCPR1L = (wht); \
     nei(); \
 } while (0)
+#endif
+#endif
 
 #endif