rgblight_custom.c (2546B)
1 /* 2 Copyright 2012 Jun Wako <wakojun@gmail.com> 3 Copyright 2013 Oleg Kostyuk <cub.uanic@gmail.com> 4 Copyright 2015 ZSA Technology Labs Inc (@zsa) 5 Copyright 2020 Christopher Courtney <drashna@live.com> (@drashna) 6 7 This program is free software: you can redistribute it and/or modify 8 it under the terms of the GNU General Public License as published by 9 the Free Software Foundation, either version 2 of the License, or 10 (at your option) any later version. 11 12 This program is distributed in the hope that it will be useful, 13 but WITHOUT ANY WARRANTY; without even the implied warranty of 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 GNU General Public License for more details. 16 17 You should have received a copy of the GNU General Public License 18 along with this program. If not, see <http://www.gnu.org/licenses/>. 19 */ 20 21 #include "ergodox_ez.h" 22 #include "ws2812.h" 23 24 #define WS2812_I2C_ADDRESS_LEFT 0x84 25 26 #if defined(ERGODOX_LED_30) 27 # define WS2812_LED_COUNT_LEFT (RGBLIGHT_LED_COUNT / 2) 28 ws2812_led_t ws2812_leds_left[WS2812_LED_COUNT_LEFT]; 29 #else 30 # define WS2812_LED_COUNT_LEFT RGBLIGHT_LED_COUNT 31 ws2812_led_t ws2812_leds_left[WS2812_LED_COUNT_LEFT]; 32 #endif 33 34 void set_color_left(int index, uint8_t red, uint8_t green, uint8_t blue) { 35 ws2812_leds_left[index].r = red; 36 ws2812_leds_left[index].g = green; 37 ws2812_leds_left[index].b = blue; 38 #if defined(WS2812_RGBW) 39 ws2812_rgb_to_rgbw(&ws2812_leds_left[index]); 40 #endif 41 } 42 43 void set_color_custom(int index, uint8_t red, uint8_t green, uint8_t blue) { 44 #if defined(ERGODOX_LED_30) 45 if (index < WS2812_LED_COUNT_LEFT) { 46 ws2812_set_color(index, red, green, blue); 47 } else { 48 set_color_left(RGBLIGHT_LED_COUNT - index - 1, red, green, blue); 49 } 50 #elif defined(ERGODOX_LED_15_MIRROR) 51 ws2812_set_color(index, red, green, blue); 52 set_color_left(index, red, green, blue); 53 #else 54 ws2812_set_color(index, red, green, blue); 55 set_color_left(WS2812_LED_COUNT_LEFT - index - 1, red, green, blue); 56 #endif 57 } 58 59 void set_color_all_custom(uint8_t red, uint8_t green, uint8_t blue) { 60 for (int i = 0; i < RGBLIGHT_LED_COUNT; i++) { 61 set_color_custom(i, red, green, blue); 62 } 63 } 64 65 void flush_custom(void) { 66 i2c_transmit(WS2812_I2C_ADDRESS_LEFT, (uint8_t *)ws2812_leds_left, sizeof(ws2812_leds_left), ERGODOX_EZ_I2C_TIMEOUT); 67 ws2812_flush(); 68 } 69 70 const rgblight_driver_t rgblight_driver = { 71 .init = ws2812_init, 72 .set_color = set_color_custom, 73 .set_color_all = set_color_all_custom, 74 .flush = flush_custom, 75 };