logo

qmk_firmware

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

ws2812_custom.c (1137B)


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