summaryrefslogtreecommitdiffstats
path: root/quantum/color.c
diff options
context:
space:
mode:
authorJack Humbert <jack.humb@gmail.com>2018-05-08 21:24:18 +0200
committerGitHub <noreply@github.com>2018-05-08 21:24:18 +0200
commit14b7602a65dedaf51db1c9288144765d43a83a15 (patch)
tree8e21e6b77db1581deaeecfa3373fe70470e64c1f /quantum/color.c
parent46dca121fd2f51c4f5b87e48af37f43340591433 (diff)
downloadqmk_firmware-14b7602a65dedaf51db1c9288144765d43a83a15.tar.gz
qmk_firmware-14b7602a65dedaf51db1c9288144765d43a83a15.tar.xz
Adds IS31FL3731 RGB Matrix Implementation (#2910)
* adds is31fl3731 rgb matrix implementation * fix build script for force pushes * allow bootloader size to be overwritten * adds planck light implementation * split led config into 2 arrays * idk * betterize register handling * update planck implementation * update planck * refine rgb interface * cleanup names, rgb matrix * start documentation * finish up docs * add effects list * clean-up merge * add RGB_MATRIX_SKIP_FRAMES * add support for at90usb1286 to bootloader options
Diffstat (limited to 'quantum/color.c')
-rw-r--r--quantum/color.c87
1 files changed, 87 insertions, 0 deletions
diff --git a/quantum/color.c b/quantum/color.c
new file mode 100644
index 000000000..8ede053e7
--- /dev/null
+++ b/quantum/color.c
@@ -0,0 +1,87 @@
+/* Copyright 2017 Jason Williams
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#include "color.h"
+#include "led_tables.h"
+#include "progmem.h"
+
+RGB hsv_to_rgb( HSV hsv )
+{
+ RGB rgb;
+ uint8_t region, p, q, t;
+ uint16_t h, s, v, remainder;
+
+ if ( hsv.s == 0 )
+ {
+ rgb.r = hsv.v;
+ rgb.g = hsv.v;
+ rgb.b = hsv.v;
+ return rgb;
+ }
+
+ h = hsv.h;
+ s = hsv.s;
+ v = hsv.v;
+
+ region = h / 43;
+ remainder = (h - (region * 43)) * 6;
+
+ p = (v * (255 - s)) >> 8;
+ q = (v * (255 - ((s * remainder) >> 8))) >> 8;
+ t = (v * (255 - ((s * (255 - remainder)) >> 8))) >> 8;
+
+ switch ( region )
+ {
+ case 0:
+ rgb.r = v;
+ rgb.g = t;
+ rgb.b = p;
+ break;
+ case 1:
+ rgb.r = q;
+ rgb.g = v;
+ rgb.b = p;
+ break;
+ case 2:
+ rgb.r = p;
+ rgb.g = v;
+ rgb.b = t;
+ break;
+ case 3:
+ rgb.r = p;
+ rgb.g = q;
+ rgb.b = v;
+ break;
+ case 4:
+ rgb.r = t;
+ rgb.g = p;
+ rgb.b = v;
+ break;
+ default:
+ rgb.r = v;
+ rgb.g = p;
+ rgb.b = q;
+ break;
+ }
+
+ rgb.r = pgm_read_byte( &CIE1931_CURVE[rgb.r] );
+ rgb.g = pgm_read_byte( &CIE1931_CURVE[rgb.g] );
+ rgb.b = pgm_read_byte( &CIE1931_CURVE[rgb.b] );
+
+ return rgb;
+}
+