X-Git-Url: https://oss.titaniummirror.com/gitweb?a=blobdiff_plain;f=rgb.c;h=cdee44902a93950e680989a21e1c5d7d6ced02e0;hb=HEAD;hp=d2d6a805b629a054f73808a497054bf7480e0112;hpb=1eee76670bd725ca44d1574f96ff3a0d773f2995;p=rgblamp.git diff --git a/rgb.c b/rgb.c index d2d6a80..cdee449 100644 --- a/rgb.c +++ b/rgb.c @@ -1,3 +1,32 @@ +/* + * Copyright © 2011, 2012, Titanium Mirror, Inc.. + * All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * - Neither the name of Titanium Mirror, Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED + * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, + * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE + * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + /* * File: rgb.c * @@ -5,10 +34,65 @@ */ #include +#include "rgb.h" #define PINS_PORTB 0b00101001 #define PINS_PORTC 0b00000100 +/* To get a perceived linear output, the PWM value must be adjusted according + * to CIE Lightness. The human eye perceives changes at lower intensities + * more readily that at higher intensities. + * + * L* = 116(Y/Yn)^1/3 - 16 , Y/Yn > 0.008856 + * L* = 903.3(Y/Yn), Y/Yn <= 0.008856 +*/ + +#ifdef CEIL256 +const unsigned char pwm_table[] = { + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 2, 2, 2, 2, 2, + 2, 2, 2, 3, 3, 3, 3, 3, + 3, 3, 4, 4, 4, 4, 4, 5, + 5, 5, 5, 5, 6, 6, 6, 6, + 6, 7, 7, 7, 7, 8, 8, 8, + 8, 9, 9, 9, 10, 10, 10, 11, + 11, 11, 12, 12, 12, 13, 13, 13, + 14, 14, 14, 15, 15, 16, 16, 17, + 17, 17, 18, 18, 19, 19, 20, 20, + 21, 21, 22, 22, 23, 23, 24, 24, + 25, 25, 26, 27, 27, 28, 28, 29, + 30, 30, 31, 31, 32, 33, 33, 34, + 35, 35, 36, 37, 38, 38, 39, 40, + 41, 41, 42, 43, 44, 45, 45, 46, + 47, 48, 49, 50, 51, 51, 52, 53, + 54, 55, 56, 57, 58, 59, 60, 61, + 62, 63, 64, 65, 66, 67, 68, 69, + 70, 71, 73, 74, 75, 76, 77, 78, + 80, 81, 82, 83, 84, 86, 87, 88, + 90, 91, 92, 93, 95, 96, 98, 99, + 100, 102, 103, 105, 106, 107, 109, 110, + 112, 113, 115, 116, 118, 120, 121, 123, + 124, 126, 128, 129, 131, 133, 134, 136, + 138, 139, 141, 143, 145, 146, 148, 150, + 152, 154, 156, 157, 159, 161, 163, 165, + 167, 169, 171, 173, 175, 177, 179, 181, + 183, 185, 187, 189, 192, 194, 196, 198, + 200, 203, 205, 207, 209, 212, 214, 216, + 218, 221, 223, 226, 228, 230, 233, 235, + 238, 240, 243, 245, 248, 250, 253, 255 +}; +#else +#ifdef CEIL32 +const unsigned char pwm_table[] = { + 0, 1, 2, 3, 4, 5, 7, 9, + 12, 15, 18, 22, 27, 32, 38, 44, + 51, 58, 67, 76, 86, 96, 108, 120, + 134, 148, 163, 180, 197, 216, 235, 255 +}; +#endif +#endif + void rgb_init() { /* Initialize rgb