Skip to content

Commit

Permalink
Move Ergodox EZ RGB Light code to custom driver (qmk#7309)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>

* 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
  • Loading branch information
drashna authored Nov 14, 2019
1 parent ab44245 commit 50937de
Showing 1 changed file with 2 additions and 127 deletions.
129 changes: 2 additions & 127 deletions drivers/avr/ws2812.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,147 +36,22 @@
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));
ws2812_setleds_pin(ledarray, leds, _BV(RGB_DI_PIN & 0xF));
}

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
}

Expand Down

0 comments on commit 50937de

Please sign in to comment.