diff options
Diffstat (limited to 'drivers/avr/is31fl3731.c')
-rw-r--r-- | drivers/avr/is31fl3731.c | 36 |
1 files changed, 11 insertions, 25 deletions
diff --git a/drivers/avr/is31fl3731.c b/drivers/avr/is31fl3731.c index e5941cf41..c7a99e3a3 100644 --- a/drivers/avr/is31fl3731.c +++ b/drivers/avr/is31fl3731.c @@ -20,7 +20,7 @@ #include <avr/io.h> #include <util/delay.h> #include <string.h> -#include "TWIlib.h" +#include "i2c_master.h" #include "progmem.h" // This is a 7-bit address, that gets left-shifted and bit 0 @@ -50,7 +50,7 @@ #define ISSI_BANK_FUNCTIONREG 0x0B // helpfully called 'page nine' // Transfer buffer for TWITransmitData() -uint8_t g_twi_transfer_buffer[TXMAXBUFLEN]; +uint8_t g_twi_transfer_buffer[20]; // These buffers match the IS31FL3731 PWM registers 0x24-0xB3. // Storing them like this is optimal for I2C transfers to the registers. @@ -80,17 +80,11 @@ bool g_led_control_registers_update_required = false; void IS31FL3731_write_register( uint8_t addr, uint8_t reg, uint8_t data ) { - g_twi_transfer_buffer[0] = (addr << 1) | 0x00; - g_twi_transfer_buffer[1] = reg; - g_twi_transfer_buffer[2] = data; - - // Set the error code to have no relevant information - TWIInfo.errorCode = TWI_NO_RELEVANT_INFO; - // Continuously attempt to transmit data until a successful transmission occurs - //while ( TWIInfo.errorCode != 0xFF ) - //{ - TWITransmitData( g_twi_transfer_buffer, 3, 0 ); - //} + g_twi_transfer_buffer[0] = reg; + g_twi_transfer_buffer[1] = data; + + //Transmit data until succesful + while(i2c_transmit(addr << 1, g_twi_transfer_buffer,2) != 0); } void IS31FL3731_write_pwm_buffer( uint8_t addr, uint8_t *pwm_buffer ) @@ -100,29 +94,21 @@ void IS31FL3731_write_pwm_buffer( uint8_t addr, uint8_t *pwm_buffer ) // transmit PWM registers in 9 transfers of 16 bytes // g_twi_transfer_buffer[] is 20 bytes - // set the I2C address - g_twi_transfer_buffer[0] = (addr << 1) | 0x00; - // iterate over the pwm_buffer contents at 16 byte intervals for ( int i = 0; i < 144; i += 16 ) { // set the first register, e.g. 0x24, 0x34, 0x44, etc. - g_twi_transfer_buffer[1] = 0x24 + i; + g_twi_transfer_buffer[0] = 0x24 + i; // copy the data from i to i+15 // device will auto-increment register for data after the first byte // thus this sets registers 0x24-0x33, 0x34-0x43, etc. in one transfer for ( int j = 0; j < 16; j++ ) { - g_twi_transfer_buffer[2 + j] = pwm_buffer[i + j]; + g_twi_transfer_buffer[1 + j] = pwm_buffer[i + j]; } - // Set the error code to have no relevant information - TWIInfo.errorCode = TWI_NO_RELEVANT_INFO; - // Continuously attempt to transmit data until a successful transmission occurs - while ( TWIInfo.errorCode != 0xFF ) - { - TWITransmitData( g_twi_transfer_buffer, 16 + 2, 0 ); - } + //Transmit buffer until succesful + while(i2c_transmit(addr << 1, g_twi_transfer_buffer,17) != 0); } } |