You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

34 lines
830 B

  1. #include "ws2812.h"
  2. #include "i2c_master.h"
  3. #ifdef 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. void ws2812_init(void) {
  16. i2c_init();
  17. }
  18. // Setleds for standard RGB
  19. void ws2812_setleds(rgb_led_t *ledarray, uint16_t leds) {
  20. static bool s_init = false;
  21. if (!s_init) {
  22. ws2812_init();
  23. s_init = true;
  24. }
  25. i2c_transmit(WS2812_I2C_ADDRESS, (uint8_t *)ledarray, sizeof(rgb_led_t) * (leds >> 1), WS2812_I2C_TIMEOUT);
  26. i2c_transmit(WS2812_I2C_ADDRESS_RIGHT, (uint8_t *)ledarray+(sizeof(rgb_led_t) * (leds >> 1)), sizeof(rgb_led_t) * (leds - (leds >> 1)), WS2812_I2C_TIMEOUT);
  27. }