summaryrefslogtreecommitdiff
path: root/drivers/avr
diff options
context:
space:
mode:
authorFlorian Didron <fdidron@users.noreply.github.com>2019-12-06 09:25:39 +0900
committerGitHub <noreply@github.com>2019-12-06 09:25:39 +0900
commit13e1dd3d53a75840cce9c7fa52fd6d8d26a36a9a (patch)
treea51a6bd431d848279d8c03357ac05ecfb25312ce /drivers/avr
parent1d600f09a8b813f77d8b6ff4cc55484b7154ae25 (diff)
parent038cef3054a816021a797c217d147057c8edd926 (diff)
Merge pull request #222 from zsa/staging
Firmware 15
Diffstat (limited to 'drivers/avr')
-rw-r--r--drivers/avr/ws2812.c33
-rw-r--r--drivers/avr/ws2812.h35
-rw-r--r--drivers/avr/ws2812_i2c.c31
3 files changed, 42 insertions, 57 deletions
diff --git a/drivers/avr/ws2812.c b/drivers/avr/ws2812.c
index 0a02c6f7fd..5c733c4ab0 100644
--- a/drivers/avr/ws2812.c
+++ b/drivers/avr/ws2812.c
@@ -25,13 +25,17 @@
#include <avr/interrupt.h>
#include <avr/io.h>
#include <util/delay.h>
-#include "debug.h"
-#if !defined(LED_ARRAY) && defined(RGB_MATRIX_ENABLE)
-// LED color buffer
-LED_TYPE led[DRIVER_LED_TOTAL];
-# define LED_ARRAY led
-#endif
+/*
+ * Forward declare internal functions
+ *
+ * The functions take a byte-array and send to the data output as WS2812 bitstream.
+ * The length is the number of bytes to send - three per LED.
+ */
+
+void ws2812_sendarray(uint8_t *array, uint16_t length);
+void ws2812_sendarray_mask(uint8_t *array, uint16_t length, uint8_t pinmask);
+
#ifdef RGBW_BB_TWI
@@ -135,23 +139,6 @@ unsigned char I2C_Write(unsigned char c) {
#endif
-#ifdef RGB_MATRIX_ENABLE
-// Set an led in the buffer to a color
-void inline ws2812_setled(int i, uint8_t r, uint8_t g, uint8_t b) {
- led[i].r = r;
- led[i].g = g;
- led[i].b = b;
-}
-
-void ws2812_setled_all(uint8_t r, uint8_t g, uint8_t b) {
- for (int i = 0; i < sizeof(led) / sizeof(led[0]); i++) {
- led[i].r = r;
- led[i].g = g;
- led[i].b = b;
- }
-}
-#endif
-
// Setleds for standard RGB
void inline ws2812_setleds(LED_TYPE *ledarray, uint16_t leds) {
// ws2812_setleds_pin(ledarray,leds, _BV(ws2812_pin));
diff --git a/drivers/avr/ws2812.h b/drivers/avr/ws2812.h
index a9dd897185..9652b94bbe 100644
--- a/drivers/avr/ws2812.h
+++ b/drivers/avr/ws2812.h
@@ -20,13 +20,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#ifndef LIGHT_WS2812_H_
-#define LIGHT_WS2812_H_
-
-#include <avr/io.h>
-#include <avr/interrupt.h>
-//#include "ws2812_config.h"
-//#include "i2cmaster.h"
+#pragma once
#include "quantum/color.h"
@@ -42,33 +36,6 @@
* - Send out the LED data
* - Wait 50�s to reset the LEDs
*/
-#ifdef RGB_MATRIX_ENABLE
-void ws2812_setled(int index, uint8_t r, uint8_t g, uint8_t b);
-void ws2812_setled_all(uint8_t r, uint8_t g, uint8_t b);
-#endif
-
void ws2812_setleds(LED_TYPE *ledarray, uint16_t number_of_leds);
void ws2812_setleds_pin(LED_TYPE *ledarray, uint16_t number_of_leds, uint8_t pinmask);
void ws2812_setleds_rgbw(LED_TYPE *ledarray, uint16_t number_of_leds);
-
-/*
- * Old interface / Internal functions
- *
- * The functions take a byte-array and send to the data output as WS2812 bitstream.
- * The length is the number of bytes to send - three per LED.
- */
-
-void ws2812_sendarray(uint8_t *array, uint16_t length);
-void ws2812_sendarray_mask(uint8_t *array, uint16_t length, uint8_t pinmask);
-
-/*
- * Internal defines
- */
-#ifndef CONCAT
-# define CONCAT(a, b) a##b
-#endif
-#ifndef CONCAT_EXP
-# define CONCAT_EXP(a, b) CONCAT(a, b)
-#endif
-
-#endif /* LIGHT_WS2812_H_ */
diff --git a/drivers/avr/ws2812_i2c.c b/drivers/avr/ws2812_i2c.c
new file mode 100644
index 0000000000..8525a026c7
--- /dev/null
+++ b/drivers/avr/ws2812_i2c.c
@@ -0,0 +1,31 @@
+#include "ws2812.h"
+#include "i2c_master.h"
+
+#ifndef WS2812_ADDRESS
+# define WS2812_ADDRESS 0xb0
+#endif
+
+#ifndef WS2812_TIMEOUT
+# define WS2812_TIMEOUT 100
+#endif
+
+void ws2812_init(void) { i2c_init(); }
+
+// Setleds for standard RGB
+void ws2812_setleds(LED_TYPE *ledarray, uint16_t leds) {
+ static bool s_init = false;
+ if (!s_init) {
+ ws2812_init();
+ s_init = true;
+ }
+
+ i2c_transmit(WS2812_ADDRESS, (uint8_t *)ledarray, sizeof(LED_TYPE) * leds, WS2812_TIMEOUT);
+}
+
+// Setleds for SK6812RGBW
+void ws2812_setleds_rgbw(LED_TYPE *ledarray, uint16_t leds) {
+// not supported - for now error out if its enabled
+#ifdef RGBW
+# error "RGBW not supported"
+#endif
+}