From 1cf63a193be50b14ecd33ee1c6eb5e470640e084 Mon Sep 17 00:00:00 2001 From: Drashna Jaelre Date: Thu, 14 Nov 2019 12:00:51 -0800 Subject: 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 * 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 --- drivers/avr/ws2812.c | 129 +-------------------------------------------------- 1 file changed, 2 insertions(+), 127 deletions(-) (limited to 'drivers/avr') diff --git a/drivers/avr/ws2812.c b/drivers/avr/ws2812.c index dc7e8d48a8..82d985c20a 100644 --- a/drivers/avr/ws2812.c +++ b/drivers/avr/ws2812.c @@ -36,108 +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)); @@ -145,38 +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) { -#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 |= pinmask; // Enable DDR // new universal format (DDR) _SFR_IO8((RGB_DI_PIN >> 4) + 1) |= pinmask; ws2812_sendarray_mask((uint8_t *)ledarray, leds * sizeof(LED_TYPE), pinmask); -#ifndef RGBW_BB_TWI -# ifdef RGBW +#ifdef RGBW _delay_us(80); -# else +#else _delay_us(50); -# endif #endif } -- cgit v1.2.3