logo

qmk_firmware

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

ws2812_i2c.c (907B)


  1. // Copyright 2024 QMK
  2. // SPDX-License-Identifier: GPL-2.0-or-later
  3. #include "ws2812.h"
  4. #include "i2c_master.h"
  5. #ifdef WS2812_RGBW
  6. # error "RGBW not supported"
  7. #endif
  8. #ifndef WS2812_I2C_ADDRESS
  9. # define WS2812_I2C_ADDRESS 0xB0
  10. #endif
  11. #ifndef WS2812_I2C_TIMEOUT
  12. # define WS2812_I2C_TIMEOUT 100
  13. #endif
  14. ws2812_led_t ws2812_leds[WS2812_LED_COUNT];
  15. void ws2812_init(void) {
  16. i2c_init();
  17. }
  18. void ws2812_set_color(int index, uint8_t red, uint8_t green, uint8_t blue) {
  19. ws2812_leds[index].r = red;
  20. ws2812_leds[index].g = green;
  21. ws2812_leds[index].b = blue;
  22. }
  23. void ws2812_set_color_all(uint8_t red, uint8_t green, uint8_t blue) {
  24. for (int i = 0; i < WS2812_LED_COUNT; i++) {
  25. ws2812_set_color(i, red, green, blue);
  26. }
  27. }
  28. void ws2812_flush(void) {
  29. i2c_transmit(WS2812_I2C_ADDRESS, (uint8_t *)ws2812_leds, WS2812_LED_COUNT * sizeof(ws2812_led_t), WS2812_I2C_TIMEOUT);
  30. }