logo

qmk_firmware

custom branch of QMK firmware git clone https://anongit.hacktivis.me/git/qmk_firmware.git

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