diff options
Diffstat (limited to 'quantum/rgblight.c')
-rw-r--r-- | quantum/rgblight.c | 61 |
1 files changed, 39 insertions, 22 deletions
diff --git a/quantum/rgblight.c b/quantum/rgblight.c index 801ca1d0d..221a16402 100644 --- a/quantum/rgblight.c +++ b/quantum/rgblight.c | |||
@@ -6,24 +6,37 @@ | |||
6 | #include "rgblight.h" | 6 | #include "rgblight.h" |
7 | #include "debug.h" | 7 | #include "debug.h" |
8 | 8 | ||
9 | // Lightness curve using the CIE 1931 lightness formula | ||
10 | //Generated by the python script provided in http://jared.geek.nz/2013/feb/linear-led-pwm | ||
9 | const uint8_t DIM_CURVE[] PROGMEM = { | 11 | const uint8_t DIM_CURVE[] PROGMEM = { |
10 | 0, 1, 1, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, | 12 | 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, |
11 | 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, | 13 | 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, |
12 | 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 6, 6, 6, | 14 | 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, |
13 | 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, | 15 | 3, 4, 4, 4, 4, 4, 4, 5, 5, 5, |
14 | 8, 8, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 11, 11, 11, | 16 | 5, 5, 6, 6, 6, 6, 6, 7, 7, 7, |
15 | 11, 11, 12, 12, 12, 12, 12, 13, 13, 13, 13, 14, 14, 14, 14, 15, | 17 | 7, 8, 8, 8, 8, 9, 9, 9, 10, 10, |
16 | 15, 15, 16, 16, 16, 16, 17, 17, 17, 18, 18, 18, 19, 19, 19, 20, | 18 | 10, 10, 11, 11, 11, 12, 12, 12, 13, 13, |
17 | 20, 20, 21, 21, 22, 22, 22, 23, 23, 24, 24, 25, 25, 25, 26, 26, | 19 | 13, 14, 14, 15, 15, 15, 16, 16, 17, 17, |
18 | 27, 27, 28, 28, 29, 29, 30, 30, 31, 32, 32, 33, 33, 34, 35, 35, | 20 | 17, 18, 18, 19, 19, 20, 20, 21, 21, 22, |
19 | 36, 36, 37, 38, 38, 39, 40, 40, 41, 42, 43, 43, 44, 45, 46, 47, | 21 | 22, 23, 23, 24, 24, 25, 25, 26, 26, 27, |
20 | 48, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, | 22 | 28, 28, 29, 29, 30, 31, 31, 32, 32, 33, |
21 | 63, 64, 65, 66, 68, 69, 70, 71, 73, 74, 75, 76, 78, 79, 81, 82, | 23 | 34, 34, 35, 36, 37, 37, 38, 39, 39, 40, |
22 | 83, 85, 86, 88, 90, 91, 93, 94, 96, 98, 99, 101, 103, 105, 107, 109, | 24 | 41, 42, 43, 43, 44, 45, 46, 47, 47, 48, |
23 | 110, 112, 114, 116, 118, 121, 123, 125, 127, 129, 132, 134, 136, 139, 141, 144, | 25 | 49, 50, 51, 52, 53, 54, 54, 55, 56, 57, |
24 | 146, 149, 151, 154, 157, 159, 162, 165, 168, 171, 174, 177, 180, 183, 186, 190, | 26 | 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, |
25 | 193, 196, 200, 203, 207, 211, 214, 218, 222, 226, 230, 234, 238, 242, 248, 255 | 27 | 68, 70, 71, 72, 73, 74, 75, 76, 77, 79, |
26 | }; | 28 | 80, 81, 82, 83, 85, 86, 87, 88, 90, 91, |
29 | 92, 94, 95, 96, 98, 99, 100, 102, 103, 105, | ||
30 | 106, 108, 109, 110, 112, 113, 115, 116, 118, 120, | ||
31 | 121, 123, 124, 126, 128, 129, 131, 132, 134, 136, | ||
32 | 138, 139, 141, 143, 145, 146, 148, 150, 152, 154, | ||
33 | 155, 157, 159, 161, 163, 165, 167, 169, 171, 173, | ||
34 | 175, 177, 179, 181, 183, 185, 187, 189, 191, 193, | ||
35 | 196, 198, 200, 202, 204, 207, 209, 211, 214, 216, | ||
36 | 218, 220, 223, 225, 228, 230, 232, 235, 237, 240, | ||
37 | 242, 245, 247, 250, 252, 255, | ||
38 | }; | ||
39 | |||
27 | const uint8_t RGBLED_BREATHING_TABLE[] PROGMEM = { | 40 | const uint8_t RGBLED_BREATHING_TABLE[] PROGMEM = { |
28 | 0, 0, 0, 0, 1, 1, 1, 2, 2, 3, 4, 5, 5, 6, 7, 9, | 41 | 0, 0, 0, 0, 1, 1, 1, 2, 2, 3, 4, 5, 5, 6, 7, 9, |
29 | 10, 11, 12, 14, 15, 17, 18, 20, 21, 23, 25, 27, 29, 31, 33, 35, | 42 | 10, 11, 12, 14, 15, 17, 18, 20, 21, 23, 25, 27, 29, 31, 33, 35, |
@@ -42,10 +55,16 @@ const uint8_t RGBLED_BREATHING_TABLE[] PROGMEM = { | |||
42 | 37, 35, 33, 31, 29, 27, 25, 23, 21, 20, 18, 17, 15, 14, 12, 11, | 55 | 37, 35, 33, 31, 29, 27, 25, 23, 21, 20, 18, 17, 15, 14, 12, 11, |
43 | 10, 9, 7, 6, 5, 5, 4, 3, 2, 2, 1, 1, 1, 0, 0, 0 | 56 | 10, 9, 7, 6, 5, 5, 4, 3, 2, 2, 1, 1, 1, 0, 0, 0 |
44 | }; | 57 | }; |
58 | |||
59 | __attribute__ ((weak)) | ||
45 | const uint8_t RGBLED_BREATHING_INTERVALS[] PROGMEM = {30, 20, 10, 5}; | 60 | const uint8_t RGBLED_BREATHING_INTERVALS[] PROGMEM = {30, 20, 10, 5}; |
61 | __attribute__ ((weak)) | ||
46 | const uint8_t RGBLED_RAINBOW_MOOD_INTERVALS[] PROGMEM = {120, 60, 30}; | 62 | const uint8_t RGBLED_RAINBOW_MOOD_INTERVALS[] PROGMEM = {120, 60, 30}; |
63 | __attribute__ ((weak)) | ||
47 | const uint8_t RGBLED_RAINBOW_SWIRL_INTERVALS[] PROGMEM = {100, 50, 20}; | 64 | const uint8_t RGBLED_RAINBOW_SWIRL_INTERVALS[] PROGMEM = {100, 50, 20}; |
65 | __attribute__ ((weak)) | ||
48 | const uint8_t RGBLED_SNAKE_INTERVALS[] PROGMEM = {100, 50, 20}; | 66 | const uint8_t RGBLED_SNAKE_INTERVALS[] PROGMEM = {100, 50, 20}; |
67 | __attribute__ ((weak)) | ||
49 | const uint8_t RGBLED_KNIGHT_INTERVALS[] PROGMEM = {100, 50, 20}; | 68 | const uint8_t RGBLED_KNIGHT_INTERVALS[] PROGMEM = {100, 50, 20}; |
50 | 69 | ||
51 | rgblight_config_t rgblight_config; | 70 | rgblight_config_t rgblight_config; |
@@ -59,13 +78,8 @@ uint8_t rgblight_inited = 0; | |||
59 | 78 | ||
60 | 79 | ||
61 | void sethsv(uint16_t hue, uint8_t sat, uint8_t val, struct cRGB *led1) { | 80 | void sethsv(uint16_t hue, uint8_t sat, uint8_t val, struct cRGB *led1) { |
62 | // Convert hue, saturation, and value (HSV/HSB) to RGB. DIM_CURVE is used only | ||
63 | // on value and saturation (inverted). This looks the most natural. | ||
64 | uint8_t r = 0, g = 0, b = 0, base, color; | 81 | uint8_t r = 0, g = 0, b = 0, base, color; |
65 | 82 | ||
66 | val = pgm_read_byte(&DIM_CURVE[val]); | ||
67 | sat = 255 - pgm_read_byte(&DIM_CURVE[255 - sat]); | ||
68 | |||
69 | if (sat == 0) { // Acromatic color (gray). Hue doesn't mind. | 83 | if (sat == 0) { // Acromatic color (gray). Hue doesn't mind. |
70 | r = val; | 84 | r = val; |
71 | g = val; | 85 | g = val; |
@@ -107,6 +121,9 @@ void sethsv(uint16_t hue, uint8_t sat, uint8_t val, struct cRGB *led1) { | |||
107 | break; | 121 | break; |
108 | } | 122 | } |
109 | } | 123 | } |
124 | r = pgm_read_byte(&DIM_CURVE[r]); | ||
125 | g = pgm_read_byte(&DIM_CURVE[g]); | ||
126 | b = pgm_read_byte(&DIM_CURVE[b]); | ||
110 | 127 | ||
111 | setrgb(r, g, b, led1); | 128 | setrgb(r, g, b, led1); |
112 | } | 129 | } |