summaryrefslogtreecommitdiff
path: root/drivers/avr
diff options
context:
space:
mode:
authorDrashna Jaelre <drashna@live.com>2020-01-05 19:04:55 -0800
committerFlorian Didron <fdidron@users.noreply.github.com>2020-01-09 08:57:11 +0900
commitdf91396be99ea4bd916c8671d233d75d3d67aa18 (patch)
tree33325a06ad2caf8c5b0e9206733719d9c4b938d8 /drivers/avr
parent81126b6673313dc5e40ed92cc67f85b430003894 (diff)
WS2812 Overhaul (#210)
* ARM - ws2812 bitbang (#7173) * Initial ARM bitbang ws2812 driver * Unify chibios platform to run rgblight_task * Remove 'avr only' comments from ws2812 docs * Remove 'avr only' comments from ws2812 docs * Unify chibios platform to run rgblight_task - review comments * Remove debug flags from keymap * Add comments from review * Add defines for STM32L0XX * Attempt to get arm ws2812 working on multiple gcc versions * Support RGBLIGHT_SLEEP when ChibiOS boards suspend (#7280) Copypasta from the AVR suspend implementation with a Teensy-specific hack removed * Unify RGB and RGBW commands (#7297) * Fix unicode in comments Co-Authored-By: fauxpark <fauxpark@gmail.com> * Remove separate RGBW implementation for a unified function * Set White to 0 in RGBW LEDs This is just to get this working, later, proper brightness can be handled elsewhere. * Use us instead of nanoseconds(?) since it renders correctly on web * Remove RGBW function from arm/ws2812.h * Remove RGBW function from arm/ws2812.c * Formatting changes * Add doc info * Remove force of debug on within rgblight - causes lockups waiting for hid_listen (#7330) * Move Ergodox EZ RGB Light code to custom driver (#7309) * Move Ergodox EZ RGB code to custom driver Also implements full addressing of Ergodox EZ's LED Strip, as written by seebs Co-authored-by: Seebs <seebs@seebs.net> * Make Clipping range accessible for custom drivers * Remove RGBW_BB_TWI from driver and docs * Revert changes to clipping range support * Use just rgblight_set instead of full custom driver * Convert to i2c_master commands * Rename rgblight driver and clean up includes * Use White channel on RGBW LEDs * SPI DMA based RGB Underglow for STM32 (#7674) * Initial stash of ws2812 spi driver * Update comment, add sync backup plan * Add testing notes to spi ws2812 driver * Align RGBW error messages Co-authored-by: Joel Challis <git@zvecr.com> Co-authored-by: Jonathan Rascher <jon@bcat.name> Co-authored-by: Florian Didron <fdidron@users.noreply.github.com>
Diffstat (limited to 'drivers/avr')
-rw-r--r--drivers/avr/ws2812.c141
-rw-r--r--drivers/avr/ws2812.h3
-rw-r--r--drivers/avr/ws2812_i2c.c12
3 files changed, 9 insertions, 147 deletions
diff --git a/drivers/avr/ws2812.c b/drivers/avr/ws2812.c
index 5c733c4ab0..82d985c20a 100644
--- a/drivers/avr/ws2812.c
+++ b/drivers/avr/ws2812.c
@@ -36,109 +36,6 @@
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
-
-// Port for the I2C
-# define I2C_DDR DDRD
-# define I2C_PIN PIND
-# define I2C_PORT PORTD
-
-// Pins to be used in the bit banging
-# define I2C_CLK 0
-# define I2C_DAT 1
-
-# define I2C_DATA_HI() \
- I2C_DDR &= ~(1 << I2C_DAT); \
- I2C_PORT |= (1 << I2C_DAT);
-# define I2C_DATA_LO() \
- I2C_DDR |= (1 << I2C_DAT); \
- I2C_PORT &= ~(1 << I2C_DAT);
-
-# define I2C_CLOCK_HI() \
- I2C_DDR &= ~(1 << I2C_CLK); \
- I2C_PORT |= (1 << I2C_CLK);
-# define I2C_CLOCK_LO() \
- I2C_DDR |= (1 << I2C_CLK); \
- I2C_PORT &= ~(1 << I2C_CLK);
-
-# define I2C_DELAY 1
-
-void I2C_WriteBit(unsigned char c) {
- if (c > 0) {
- I2C_DATA_HI();
- } else {
- I2C_DATA_LO();
- }
-
- I2C_CLOCK_HI();
- _delay_us(I2C_DELAY);
-
- I2C_CLOCK_LO();
- _delay_us(I2C_DELAY);
-
- if (c > 0) {
- I2C_DATA_LO();
- }
-
- _delay_us(I2C_DELAY);
-}
-
-// Inits bitbanging port, must be called before using the functions below
-//
-void I2C_Init(void) {
- I2C_PORT &= ~((1 << I2C_DAT) | (1 << I2C_CLK));
-
- I2C_CLOCK_HI();
- I2C_DATA_HI();
-
- _delay_us(I2C_DELAY);
-}
-
-// Send a START Condition
-//
-void I2C_Start(void) {
- // set both to high at the same time
- I2C_DDR &= ~((1 << I2C_DAT) | (1 << I2C_CLK));
- _delay_us(I2C_DELAY);
-
- I2C_DATA_LO();
- _delay_us(I2C_DELAY);
-
- I2C_CLOCK_LO();
- _delay_us(I2C_DELAY);
-}
-
-// Send a STOP Condition
-//
-void I2C_Stop(void) {
- I2C_CLOCK_HI();
- _delay_us(I2C_DELAY);
-
- I2C_DATA_HI();
- _delay_us(I2C_DELAY);
-}
-
-// write a byte to the I2C slave device
-//
-unsigned char I2C_Write(unsigned char c) {
- for (char i = 0; i < 8; i++) {
- I2C_WriteBit(c & 128);
-
- c <<= 1;
- }
-
- I2C_WriteBit(0);
- _delay_us(I2C_DELAY);
- _delay_us(I2C_DELAY);
-
- // _delay_us(I2C_DELAY);
- // return I2C_ReadBit();
- return 0;
-}
-
-#endif
-
// Setleds for standard RGB
void inline ws2812_setleds(LED_TYPE *ledarray, uint16_t leds) {
// ws2812_setleds_pin(ledarray,leds, _BV(ws2812_pin));
@@ -146,45 +43,15 @@ void inline ws2812_setleds(LED_TYPE *ledarray, uint16_t leds) {
}
void inline ws2812_setleds_pin(LED_TYPE *ledarray, uint16_t leds, uint8_t pinmask) {
- // ws2812_DDRREG |= pinmask; // Enable DDR
// new universal format (DDR)
_SFR_IO8((RGB_DI_PIN >> 4) + 1) |= pinmask;
- ws2812_sendarray_mask((uint8_t *)ledarray, leds + leds + leds, pinmask);
- _delay_us(50);
-}
-
-// Setleds for SK6812RGBW
-void inline ws2812_setleds_rgbw(LED_TYPE *ledarray, uint16_t leds) {
-#ifdef RGBW_BB_TWI
- uint8_t sreg_prev, twcr_prev;
- sreg_prev = SREG;
- twcr_prev = TWCR;
- cli();
- TWCR &= ~(1 << TWEN);
- I2C_Init();
- I2C_Start();
- I2C_Write(0x84);
- uint16_t datlen = leds << 2;
- uint8_t curbyte;
- uint8_t *data = (uint8_t *)ledarray;
- while (datlen--) {
- curbyte = *data++;
- I2C_Write(curbyte);
- }
- I2C_Stop();
- SREG = sreg_prev;
- TWCR = twcr_prev;
-#endif
-
- // ws2812_DDRREG |= _BV(ws2812_pin); // Enable DDR
- // new universal format (DDR)
- _SFR_IO8((RGB_DI_PIN >> 4) + 1) |= _BV(RGB_DI_PIN & 0xF);
-
- ws2812_sendarray_mask((uint8_t *)ledarray, leds << 2, _BV(RGB_DI_PIN & 0xF));
+ ws2812_sendarray_mask((uint8_t *)ledarray, leds * sizeof(LED_TYPE), pinmask);
-#ifndef RGBW_BB_TWI
+#ifdef RGBW
_delay_us(80);
+#else
+ _delay_us(50);
#endif
}
diff --git a/drivers/avr/ws2812.h b/drivers/avr/ws2812.h
index 9652b94bbe..b869fb28c8 100644
--- a/drivers/avr/ws2812.h
+++ b/drivers/avr/ws2812.h
@@ -34,8 +34,7 @@
* The functions will perform the following actions:
* - Set the data-out pin as output
* - Send out the LED data
- * - Wait 50�s to reset the LEDs
+ * - Wait 50us to reset the LEDs
*/
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);
diff --git a/drivers/avr/ws2812_i2c.c b/drivers/avr/ws2812_i2c.c
index 8525a026c7..1c332e24b6 100644
--- a/drivers/avr/ws2812_i2c.c
+++ b/drivers/avr/ws2812_i2c.c
@@ -1,6 +1,10 @@
#include "ws2812.h"
#include "i2c_master.h"
+#ifdef RGBW
+# error "RGBW not supported"
+#endif
+
#ifndef WS2812_ADDRESS
# define WS2812_ADDRESS 0xb0
#endif
@@ -21,11 +25,3 @@ void ws2812_setleds(LED_TYPE *ledarray, uint16_t leds) {
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
-}