led_i2c.c 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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. #ifdef RGBLIGHT_ENABLE
  18. # include "ergodox_ez.h"
  19. void rgblight_call_driver(LED_TYPE *led, uint8_t led_num) {
  20. i2c_init();
  21. i2c_start(0x84, ERGODOX_EZ_I2C_TIMEOUT);
  22. int i = 0;
  23. # if defined(ERGODOX_LED_30)
  24. // prevent right-half code from trying to bitbang all 30
  25. // so with 30 LEDs, we count from 29 to 15 here, and the
  26. // other half does 0 to 14.
  27. uint8_t half_led_num = RGBLED_NUM / 2;
  28. for (i = half_led_num + half_led_num - 1; i >= half_led_num; --i)
  29. # elif defined(ERGODOX_LED_15_MIRROR)
  30. for (i = 0; i < led_num; ++i)
  31. # else // ERGDOX_LED_15 non-mirrored
  32. for (i = led_num - 1; i >= 0; --i)
  33. # endif
  34. {
  35. uint8_t *data = (uint8_t *)(led + i);
  36. i2c_write(*data++, ERGODOX_EZ_I2C_TIMEOUT);
  37. i2c_write(*data++, ERGODOX_EZ_I2C_TIMEOUT);
  38. i2c_write(*data++, ERGODOX_EZ_I2C_TIMEOUT);
  39. #ifdef RGBW
  40. i2c_write(*data++, ERGODOX_EZ_I2C_TIMEOUT);
  41. #endif
  42. }
  43. i2c_stop();
  44. ws2812_setleds(led, led_num);
  45. }
  46. #endif // RGBLIGHT_ENABLE