qmk_firmware

QMK firmware for my keyboards (Corne, Sweep Ferris) and trackball (Ploopy Adept)
Log | Files | Refs | Submodules | LICENSE

ws2812_i2c.c (907B)


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