LED drivers: change "TWI" to "I2C" (#22617)

This commit is contained in:
Ryan 2023-12-06 14:52:18 +11:00 committed by GitHub
parent 8b022cefc5
commit b6fbed3dc3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
16 changed files with 162 additions and 178 deletions

View File

@ -28,8 +28,7 @@
# define IS31FL3218_I2C_PERSISTENCE 0
#endif
// Reusable buffer for transfers
uint8_t g_twi_transfer_buffer[20];
uint8_t i2c_transfer_buffer[20];
// IS31FL3218 has 18 PWM outputs and a fixed I2C address, so no chaining.
uint8_t g_pwm_buffer[IS31FL3218_PWM_REGISTER_COUNT];
@ -39,27 +38,27 @@ uint8_t g_led_control_registers[IS31FL3218_LED_CONTROL_REGISTER_COUNT] = {0};
bool g_led_control_registers_update_required = false;
void is31fl3218_write_register(uint8_t reg, uint8_t data) {
g_twi_transfer_buffer[0] = reg;
g_twi_transfer_buffer[1] = data;
i2c_transfer_buffer[0] = reg;
i2c_transfer_buffer[1] = data;
#if IS31FL3218_I2C_PERSISTENCE > 0
for (uint8_t i = 0; i < IS31FL3218_I2C_PERSISTENCE; i++) {
if (i2c_transmit(IS31FL3218_I2C_ADDRESS << 1, g_twi_transfer_buffer, 2, IS31FL3218_I2C_TIMEOUT) == 0) break;
if (i2c_transmit(IS31FL3218_I2C_ADDRESS << 1, i2c_transfer_buffer, 2, IS31FL3218_I2C_TIMEOUT) == 0) break;
}
#else
i2c_transmit(IS31FL3218_I2C_ADDRESS << 1, g_twi_transfer_buffer, 2, IS31FL3218_I2C_TIMEOUT);
i2c_transmit(IS31FL3218_I2C_ADDRESS << 1, i2c_transfer_buffer, 2, IS31FL3218_I2C_TIMEOUT);
#endif
}
void is31fl3218_write_pwm_buffer(uint8_t *pwm_buffer) {
g_twi_transfer_buffer[0] = IS31FL3218_REG_PWM;
memcpy(g_twi_transfer_buffer + 1, pwm_buffer, 18);
i2c_transfer_buffer[0] = IS31FL3218_REG_PWM;
memcpy(i2c_transfer_buffer + 1, pwm_buffer, 18);
#if IS31FL3218_I2C_PERSISTENCE > 0
for (uint8_t i = 0; i < IS31FL3218_I2C_PERSISTENCE; i++) {
i2c_transmit(IS31FL3218_I2C_ADDRESS << 1, g_twi_transfer_buffer, 19, IS31FL3218_I2C_TIMEOUT);
i2c_transmit(IS31FL3218_I2C_ADDRESS << 1, i2c_transfer_buffer, 19, IS31FL3218_I2C_TIMEOUT);
}
#else
i2c_transmit(IS31FL3218_I2C_ADDRESS << 1, g_twi_transfer_buffer, 19, IS31FL3218_I2C_TIMEOUT);
i2c_transmit(IS31FL3218_I2C_ADDRESS << 1, i2c_transfer_buffer, 19, IS31FL3218_I2C_TIMEOUT);
#endif
}

View File

@ -28,8 +28,7 @@
# define IS31FL3218_I2C_PERSISTENCE 0
#endif
// Reusable buffer for transfers
uint8_t g_twi_transfer_buffer[20];
uint8_t i2c_transfer_buffer[20];
// IS31FL3218 has 18 PWM outputs and a fixed I2C address, so no chaining.
uint8_t g_pwm_buffer[IS31FL3218_PWM_REGISTER_COUNT];
@ -39,27 +38,27 @@ uint8_t g_led_control_registers[IS31FL3218_LED_CONTROL_REGISTER_COUNT] = {0};
bool g_led_control_registers_update_required = false;
void is31fl3218_write_register(uint8_t reg, uint8_t data) {
g_twi_transfer_buffer[0] = reg;
g_twi_transfer_buffer[1] = data;
i2c_transfer_buffer[0] = reg;
i2c_transfer_buffer[1] = data;
#if IS31FL3218_I2C_PERSISTENCE > 0
for (uint8_t i = 0; i < IS31FL3218_I2C_PERSISTENCE; i++) {
if (i2c_transmit(IS31FL3218_I2C_ADDRESS << 1, g_twi_transfer_buffer, 2, IS31FL3218_I2C_TIMEOUT) == 0) break;
if (i2c_transmit(IS31FL3218_I2C_ADDRESS << 1, i2c_transfer_buffer, 2, IS31FL3218_I2C_TIMEOUT) == 0) break;
}
#else
i2c_transmit(IS31FL3218_I2C_ADDRESS << 1, g_twi_transfer_buffer, 2, IS31FL3218_I2C_TIMEOUT);
i2c_transmit(IS31FL3218_I2C_ADDRESS << 1, i2c_transfer_buffer, 2, IS31FL3218_I2C_TIMEOUT);
#endif
}
void is31fl3218_write_pwm_buffer(uint8_t *pwm_buffer) {
g_twi_transfer_buffer[0] = IS31FL3218_REG_PWM;
memcpy(g_twi_transfer_buffer + 1, pwm_buffer, 18);
i2c_transfer_buffer[0] = IS31FL3218_REG_PWM;
memcpy(i2c_transfer_buffer + 1, pwm_buffer, 18);
#if IS31FL3218_I2C_PERSISTENCE > 0
for (uint8_t i = 0; i < IS31FL3218_I2C_PERSISTENCE; i++) {
i2c_transmit(IS31FL3218_I2C_ADDRESS << 1, g_twi_transfer_buffer, 19, IS31FL3218_I2C_TIMEOUT);
i2c_transmit(IS31FL3218_I2C_ADDRESS << 1, i2c_transfer_buffer, 19, IS31FL3218_I2C_TIMEOUT);
}
#else
i2c_transmit(IS31FL3218_I2C_ADDRESS << 1, g_twi_transfer_buffer, 19, IS31FL3218_I2C_TIMEOUT);
i2c_transmit(IS31FL3218_I2C_ADDRESS << 1, i2c_transfer_buffer, 19, IS31FL3218_I2C_TIMEOUT);
#endif
}

View File

@ -33,8 +33,7 @@
# define IS31FL3731_I2C_PERSISTENCE 0
#endif
// Transfer buffer for TWITransmitData()
uint8_t g_twi_transfer_buffer[20];
uint8_t i2c_transfer_buffer[20];
// These buffers match the IS31FL3731 PWM registers 0x24-0xB3.
// Storing them like this is optimal for I2C transfers to the registers.
@ -48,17 +47,17 @@ uint8_t g_led_control_registers[IS31FL3731_DRIVER_COUNT][IS31FL3731_LED_CONTROL_
bool g_led_control_registers_update_required[IS31FL3731_DRIVER_COUNT] = {false};
void is31fl3731_write_register(uint8_t addr, uint8_t reg, uint8_t data) {
g_twi_transfer_buffer[0] = reg;
g_twi_transfer_buffer[1] = data;
i2c_transfer_buffer[0] = reg;
i2c_transfer_buffer[1] = data;
#if IS31FL3731_I2C_PERSISTENCE > 0
for (uint8_t i = 0; i < IS31FL3731_I2C_PERSISTENCE; i++) {
if (i2c_transmit(addr << 1, g_twi_transfer_buffer, 2, IS31FL3731_I2C_TIMEOUT) == 0) {
if (i2c_transmit(addr << 1, i2c_transfer_buffer, 2, IS31FL3731_I2C_TIMEOUT) == 0) {
break;
}
}
#else
i2c_transmit(addr << 1, g_twi_transfer_buffer, 2, IS31FL3731_I2C_TIMEOUT);
i2c_transmit(addr << 1, i2c_transfer_buffer, 2, IS31FL3731_I2C_TIMEOUT);
#endif
}
@ -70,23 +69,23 @@ void is31fl3731_write_pwm_buffer(uint8_t addr, uint8_t *pwm_buffer) {
// assumes page 0 is already selected
// transmit PWM registers in 9 transfers of 16 bytes
// g_twi_transfer_buffer[] is 20 bytes
// i2c_transfer_buffer[] is 20 bytes
// iterate over the pwm_buffer contents at 16 byte intervals
for (int i = 0; i < IS31FL3731_PWM_REGISTER_COUNT; i += 16) {
// set the first register, e.g. 0x24, 0x34, 0x44, etc.
g_twi_transfer_buffer[0] = 0x24 + i;
i2c_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
memcpy(g_twi_transfer_buffer + 1, pwm_buffer + i, 16);
memcpy(i2c_transfer_buffer + 1, pwm_buffer + i, 16);
#if IS31FL3731_I2C_PERSISTENCE > 0
for (uint8_t i = 0; i < IS31FL3731_I2C_PERSISTENCE; i++) {
if (i2c_transmit(addr << 1, g_twi_transfer_buffer, 17, IS31FL3731_I2C_TIMEOUT) == 0) break;
if (i2c_transmit(addr << 1, i2c_transfer_buffer, 17, IS31FL3731_I2C_TIMEOUT) == 0) break;
}
#else
i2c_transmit(addr << 1, g_twi_transfer_buffer, 17, IS31FL3731_I2C_TIMEOUT);
i2c_transmit(addr << 1, i2c_transfer_buffer, 17, IS31FL3731_I2C_TIMEOUT);
#endif
}
}

View File

@ -32,8 +32,7 @@
# define IS31FL3731_I2C_PERSISTENCE 0
#endif
// Transfer buffer for TWITransmitData()
uint8_t g_twi_transfer_buffer[20];
uint8_t i2c_transfer_buffer[20];
// These buffers match the IS31FL3731 PWM registers 0x24-0xB3.
// Storing them like this is optimal for I2C transfers to the registers.
@ -47,15 +46,15 @@ uint8_t g_led_control_registers[IS31FL3731_DRIVER_COUNT][IS31FL3731_LED_CONTROL_
bool g_led_control_registers_update_required[IS31FL3731_DRIVER_COUNT] = {false};
void is31fl3731_write_register(uint8_t addr, uint8_t reg, uint8_t data) {
g_twi_transfer_buffer[0] = reg;
g_twi_transfer_buffer[1] = data;
i2c_transfer_buffer[0] = reg;
i2c_transfer_buffer[1] = data;
#if IS31FL3731_I2C_PERSISTENCE > 0
for (uint8_t i = 0; i < IS31FL3731_I2C_PERSISTENCE; i++) {
if (i2c_transmit(addr << 1, g_twi_transfer_buffer, 2, IS31FL3731_I2C_TIMEOUT) == 0) break;
if (i2c_transmit(addr << 1, i2c_transfer_buffer, 2, IS31FL3731_I2C_TIMEOUT) == 0) break;
}
#else
i2c_transmit(addr << 1, g_twi_transfer_buffer, 2, IS31FL3731_I2C_TIMEOUT);
i2c_transmit(addr << 1, i2c_transfer_buffer, 2, IS31FL3731_I2C_TIMEOUT);
#endif
}
@ -67,23 +66,23 @@ void is31fl3731_write_pwm_buffer(uint8_t addr, uint8_t *pwm_buffer) {
// assumes page 0 is already selected
// transmit PWM registers in 9 transfers of 16 bytes
// g_twi_transfer_buffer[] is 20 bytes
// i2c_transfer_buffer[] is 20 bytes
// iterate over the pwm_buffer contents at 16 byte intervals
for (int i = 0; i < IS31FL3731_PWM_REGISTER_COUNT; i += 16) {
// set the first register, e.g. 0x24, 0x34, 0x44, etc.
g_twi_transfer_buffer[0] = 0x24 + i;
i2c_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
memcpy(g_twi_transfer_buffer + 1, pwm_buffer + i, 16);
memcpy(i2c_transfer_buffer + 1, pwm_buffer + i, 16);
#if IS31FL3731_I2C_PERSISTENCE > 0
for (uint8_t i = 0; i < IS31FL3731_I2C_PERSISTENCE; i++) {
if (i2c_transmit(addr << 1, g_twi_transfer_buffer, 17, IS31FL3731_I2C_TIMEOUT) == 0) break;
if (i2c_transmit(addr << 1, i2c_transfer_buffer, 17, IS31FL3731_I2C_TIMEOUT) == 0) break;
}
#else
i2c_transmit(addr << 1, g_twi_transfer_buffer, 17, IS31FL3731_I2C_TIMEOUT);
i2c_transmit(addr << 1, i2c_transfer_buffer, 17, IS31FL3731_I2C_TIMEOUT);
#endif
}
}

View File

@ -63,8 +63,7 @@
# define IS31FL3733_SYNC_4 IS31FL3733_SYNC_NONE
#endif
// Transfer buffer for TWITransmitData()
uint8_t g_twi_transfer_buffer[20];
uint8_t i2c_transfer_buffer[20];
// These buffers match the IS31FL3733 PWM registers.
// The control buffers match the page 0 LED On/Off registers.
@ -80,17 +79,17 @@ bool g_led_control_registers_update_required[IS31FL3733_DRIVER_COUNT]
bool is31fl3733_write_register(uint8_t addr, uint8_t reg, uint8_t data) {
// If the transaction fails function returns false.
g_twi_transfer_buffer[0] = reg;
g_twi_transfer_buffer[1] = data;
i2c_transfer_buffer[0] = reg;
i2c_transfer_buffer[1] = data;
#if IS31FL3733_I2C_PERSISTENCE > 0
for (uint8_t i = 0; i < IS31FL3733_I2C_PERSISTENCE; i++) {
if (i2c_transmit(addr << 1, g_twi_transfer_buffer, 2, IS31FL3733_I2C_TIMEOUT) != 0) {
if (i2c_transmit(addr << 1, i2c_transfer_buffer, 2, IS31FL3733_I2C_TIMEOUT) != 0) {
return false;
}
}
#else
if (i2c_transmit(addr << 1, g_twi_transfer_buffer, 2, IS31FL3733_I2C_TIMEOUT) != 0) {
if (i2c_transmit(addr << 1, i2c_transfer_buffer, 2, IS31FL3733_I2C_TIMEOUT) != 0) {
return false;
}
#endif
@ -106,24 +105,24 @@ bool is31fl3733_write_pwm_buffer(uint8_t addr, uint8_t *pwm_buffer) {
// Assumes page 1 is already selected.
// If any of the transactions fails function returns false.
// Transmit PWM registers in 12 transfers of 16 bytes.
// g_twi_transfer_buffer[] is 20 bytes
// i2c_transfer_buffer[] is 20 bytes
// Iterate over the pwm_buffer contents at 16 byte intervals.
for (int i = 0; i < IS31FL3733_PWM_REGISTER_COUNT; i += 16) {
g_twi_transfer_buffer[0] = i;
i2c_transfer_buffer[0] = i;
// Copy the data from i to i+15.
// Device will auto-increment register for data after the first byte
// Thus this sets registers 0x00-0x0F, 0x10-0x1F, etc. in one transfer.
memcpy(g_twi_transfer_buffer + 1, pwm_buffer + i, 16);
memcpy(i2c_transfer_buffer + 1, pwm_buffer + i, 16);
#if IS31FL3733_I2C_PERSISTENCE > 0
for (uint8_t i = 0; i < IS31FL3733_I2C_PERSISTENCE; i++) {
if (i2c_transmit(addr << 1, g_twi_transfer_buffer, 17, IS31FL3733_I2C_TIMEOUT) != 0) {
if (i2c_transmit(addr << 1, i2c_transfer_buffer, 17, IS31FL3733_I2C_TIMEOUT) != 0) {
return false;
}
}
#else
if (i2c_transmit(addr << 1, g_twi_transfer_buffer, 17, IS31FL3733_I2C_TIMEOUT) != 0) {
if (i2c_transmit(addr << 1, i2c_transfer_buffer, 17, IS31FL3733_I2C_TIMEOUT) != 0) {
return false;
}
#endif

View File

@ -62,8 +62,7 @@
# define IS31FL3733_SYNC_4 IS31FL3733_SYNC_NONE
#endif
// Transfer buffer for TWITransmitData()
uint8_t g_twi_transfer_buffer[20];
uint8_t i2c_transfer_buffer[20];
// These buffers match the IS31FL3733 PWM registers.
// The control buffers match the page 0 LED On/Off registers.
@ -79,17 +78,17 @@ bool g_led_control_registers_update_required[IS31FL3733_DRIVER_COUNT]
bool is31fl3733_write_register(uint8_t addr, uint8_t reg, uint8_t data) {
// If the transaction fails function returns false.
g_twi_transfer_buffer[0] = reg;
g_twi_transfer_buffer[1] = data;
i2c_transfer_buffer[0] = reg;
i2c_transfer_buffer[1] = data;
#if IS31FL3733_I2C_PERSISTENCE > 0
for (uint8_t i = 0; i < IS31FL3733_I2C_PERSISTENCE; i++) {
if (i2c_transmit(addr << 1, g_twi_transfer_buffer, 2, IS31FL3733_I2C_TIMEOUT) != 0) {
if (i2c_transmit(addr << 1, i2c_transfer_buffer, 2, IS31FL3733_I2C_TIMEOUT) != 0) {
return false;
}
}
#else
if (i2c_transmit(addr << 1, g_twi_transfer_buffer, 2, IS31FL3733_I2C_TIMEOUT) != 0) {
if (i2c_transmit(addr << 1, i2c_transfer_buffer, 2, IS31FL3733_I2C_TIMEOUT) != 0) {
return false;
}
#endif
@ -105,24 +104,24 @@ bool is31fl3733_write_pwm_buffer(uint8_t addr, uint8_t *pwm_buffer) {
// Assumes page 1 is already selected.
// If any of the transactions fails function returns false.
// Transmit PWM registers in 12 transfers of 16 bytes.
// g_twi_transfer_buffer[] is 20 bytes
// i2c_transfer_buffer[] is 20 bytes
// Iterate over the pwm_buffer contents at 16 byte intervals.
for (int i = 0; i < IS31FL3733_PWM_REGISTER_COUNT; i += 16) {
g_twi_transfer_buffer[0] = i;
i2c_transfer_buffer[0] = i;
// Copy the data from i to i+15.
// Device will auto-increment register for data after the first byte
// Thus this sets registers 0x00-0x0F, 0x10-0x1F, etc. in one transfer.
memcpy(g_twi_transfer_buffer + 1, pwm_buffer + i, 16);
memcpy(i2c_transfer_buffer + 1, pwm_buffer + i, 16);
#if IS31FL3733_I2C_PERSISTENCE > 0
for (uint8_t i = 0; i < IS31FL3733_I2C_PERSISTENCE; i++) {
if (i2c_transmit(addr << 1, g_twi_transfer_buffer, 17, IS31FL3733_I2C_TIMEOUT) != 0) {
if (i2c_transmit(addr << 1, i2c_transfer_buffer, 17, IS31FL3733_I2C_TIMEOUT) != 0) {
return false;
}
}
#else
if (i2c_transmit(addr << 1, g_twi_transfer_buffer, 17, IS31FL3733_I2C_TIMEOUT) != 0) {
if (i2c_transmit(addr << 1, i2c_transfer_buffer, 17, IS31FL3733_I2C_TIMEOUT) != 0) {
return false;
}
#endif

View File

@ -47,8 +47,7 @@
# define IS31FL3736_GLOBAL_CURRENT 0xFF
#endif
// Transfer buffer for TWITransmitData()
uint8_t g_twi_transfer_buffer[20];
uint8_t i2c_transfer_buffer[20];
// These buffers match the IS31FL3736 PWM registers.
// The control buffers match the page 0 LED On/Off registers.
@ -63,15 +62,15 @@ uint8_t g_led_control_registers[IS31FL3736_DRIVER_COUNT][IS31FL3736_LED_CONTROL_
bool g_led_control_registers_update_required[IS31FL3736_DRIVER_COUNT] = {false};
void is31fl3736_write_register(uint8_t addr, uint8_t reg, uint8_t data) {
g_twi_transfer_buffer[0] = reg;
g_twi_transfer_buffer[1] = data;
i2c_transfer_buffer[0] = reg;
i2c_transfer_buffer[1] = data;
#if IS31FL3736_I2C_PERSISTENCE > 0
for (uint8_t i = 0; i < IS31FL3736_I2C_PERSISTENCE; i++) {
if (i2c_transmit(addr << 1, g_twi_transfer_buffer, 2, IS31FL3736_I2C_TIMEOUT) == 0) break;
if (i2c_transmit(addr << 1, i2c_transfer_buffer, 2, IS31FL3736_I2C_TIMEOUT) == 0) break;
}
#else
i2c_transmit(addr << 1, g_twi_transfer_buffer, 2, IS31FL3736_I2C_TIMEOUT);
i2c_transmit(addr << 1, i2c_transfer_buffer, 2, IS31FL3736_I2C_TIMEOUT);
#endif
}
@ -84,22 +83,22 @@ void is31fl3736_write_pwm_buffer(uint8_t addr, uint8_t *pwm_buffer) {
// assumes page 1 is already selected
// transmit PWM registers in 12 transfers of 16 bytes
// g_twi_transfer_buffer[] is 20 bytes
// i2c_transfer_buffer[] is 20 bytes
// iterate over the pwm_buffer contents at 16 byte intervals
for (int i = 0; i < IS31FL3736_PWM_REGISTER_COUNT; i += 16) {
g_twi_transfer_buffer[0] = i;
i2c_transfer_buffer[0] = i;
// copy the data from i to i+15
// device will auto-increment register for data after the first byte
// thus this sets registers 0x00-0x0F, 0x10-0x1F, etc. in one transfer
memcpy(g_twi_transfer_buffer + 1, pwm_buffer + i, 16);
memcpy(i2c_transfer_buffer + 1, pwm_buffer + i, 16);
#if IS31FL3736_I2C_PERSISTENCE > 0
for (uint8_t i = 0; i < IS31FL3736_I2C_PERSISTENCE; i++) {
if (i2c_transmit(addr << 1, g_twi_transfer_buffer, 17, IS31FL3736_I2C_TIMEOUT) == 0) break;
if (i2c_transmit(addr << 1, i2c_transfer_buffer, 17, IS31FL3736_I2C_TIMEOUT) == 0) break;
}
#else
i2c_transmit(addr << 1, g_twi_transfer_buffer, 17, IS31FL3736_I2C_TIMEOUT);
i2c_transmit(addr << 1, i2c_transfer_buffer, 17, IS31FL3736_I2C_TIMEOUT);
#endif
}
}

View File

@ -47,8 +47,7 @@
# define IS31FL3736_GLOBAL_CURRENT 0xFF
#endif
// Transfer buffer for TWITransmitData()
uint8_t g_twi_transfer_buffer[20];
uint8_t i2c_transfer_buffer[20];
// These buffers match the IS31FL3736 PWM registers.
// The control buffers match the page 0 LED On/Off registers.
@ -63,15 +62,15 @@ uint8_t g_led_control_registers[IS31FL3736_DRIVER_COUNT][IS31FL3736_LED_CONTROL_
bool g_led_control_registers_update_required[IS31FL3736_DRIVER_COUNT] = {false};
void is31fl3736_write_register(uint8_t addr, uint8_t reg, uint8_t data) {
g_twi_transfer_buffer[0] = reg;
g_twi_transfer_buffer[1] = data;
i2c_transfer_buffer[0] = reg;
i2c_transfer_buffer[1] = data;
#if IS31FL3736_I2C_PERSISTENCE > 0
for (uint8_t i = 0; i < IS31FL3736_I2C_PERSISTENCE; i++) {
if (i2c_transmit(addr << 1, g_twi_transfer_buffer, 2, IS31FL3736_I2C_TIMEOUT) == 0) break;
if (i2c_transmit(addr << 1, i2c_transfer_buffer, 2, IS31FL3736_I2C_TIMEOUT) == 0) break;
}
#else
i2c_transmit(addr << 1, g_twi_transfer_buffer, 2, IS31FL3736_I2C_TIMEOUT);
i2c_transmit(addr << 1, i2c_transfer_buffer, 2, IS31FL3736_I2C_TIMEOUT);
#endif
}
@ -84,22 +83,22 @@ void is31fl3736_write_pwm_buffer(uint8_t addr, uint8_t *pwm_buffer) {
// assumes page 1 is already selected
// transmit PWM registers in 12 transfers of 16 bytes
// g_twi_transfer_buffer[] is 20 bytes
// i2c_transfer_buffer[] is 20 bytes
// iterate over the pwm_buffer contents at 16 byte intervals
for (int i = 0; i < IS31FL3736_PWM_REGISTER_COUNT; i += 16) {
g_twi_transfer_buffer[0] = i;
i2c_transfer_buffer[0] = i;
// copy the data from i to i+15
// device will auto-increment register for data after the first byte
// thus this sets registers 0x00-0x0F, 0x10-0x1F, etc. in one transfer
memcpy(g_twi_transfer_buffer + 1, pwm_buffer + i, 16);
memcpy(i2c_transfer_buffer + 1, pwm_buffer + i, 16);
#if IS31FL3736_I2C_PERSISTENCE > 0
for (uint8_t i = 0; i < IS31FL3736_I2C_PERSISTENCE; i++) {
if (i2c_transmit(addr << 1, g_twi_transfer_buffer, 17, IS31FL3736_I2C_TIMEOUT) == 0) break;
if (i2c_transmit(addr << 1, i2c_transfer_buffer, 17, IS31FL3736_I2C_TIMEOUT) == 0) break;
}
#else
i2c_transmit(addr << 1, g_twi_transfer_buffer, 17, IS31FL3736_I2C_TIMEOUT);
i2c_transmit(addr << 1, i2c_transfer_buffer, 17, IS31FL3736_I2C_TIMEOUT);
#endif
}
}

View File

@ -49,8 +49,7 @@
# define IS31FL3737_GLOBAL_CURRENT 0xFF
#endif
// Transfer buffer for TWITransmitData()
uint8_t g_twi_transfer_buffer[20];
uint8_t i2c_transfer_buffer[20];
// These buffers match the IS31FL3737 PWM registers.
// The control buffers match the page 0 LED On/Off registers.
@ -66,15 +65,15 @@ uint8_t g_led_control_registers[IS31FL3737_DRIVER_COUNT][IS31FL3737_LED_CONTROL_
bool g_led_control_registers_update_required[IS31FL3737_DRIVER_COUNT] = {false};
void is31fl3737_write_register(uint8_t addr, uint8_t reg, uint8_t data) {
g_twi_transfer_buffer[0] = reg;
g_twi_transfer_buffer[1] = data;
i2c_transfer_buffer[0] = reg;
i2c_transfer_buffer[1] = data;
#if IS31FL3737_I2C_PERSISTENCE > 0
for (uint8_t i = 0; i < IS31FL3737_I2C_PERSISTENCE; i++) {
if (i2c_transmit(addr << 1, g_twi_transfer_buffer, 2, IS31FL3737_I2C_TIMEOUT) == 0) break;
if (i2c_transmit(addr << 1, i2c_transfer_buffer, 2, IS31FL3737_I2C_TIMEOUT) == 0) break;
}
#else
i2c_transmit(addr << 1, g_twi_transfer_buffer, 2, IS31FL3737_I2C_TIMEOUT);
i2c_transmit(addr << 1, i2c_transfer_buffer, 2, IS31FL3737_I2C_TIMEOUT);
#endif
}
@ -87,22 +86,22 @@ void is31fl3737_write_pwm_buffer(uint8_t addr, uint8_t *pwm_buffer) {
// assumes page 1 is already selected
// transmit PWM registers in 12 transfers of 16 bytes
// g_twi_transfer_buffer[] is 20 bytes
// i2c_transfer_buffer[] is 20 bytes
// iterate over the pwm_buffer contents at 16 byte intervals
for (int i = 0; i < IS31FL3737_PWM_REGISTER_COUNT; i += 16) {
g_twi_transfer_buffer[0] = i;
i2c_transfer_buffer[0] = i;
// copy the data from i to i+15
// device will auto-increment register for data after the first byte
// thus this sets registers 0x00-0x0F, 0x10-0x1F, etc. in one transfer
memcpy(g_twi_transfer_buffer + 1, pwm_buffer + i, 16);
memcpy(i2c_transfer_buffer + 1, pwm_buffer + i, 16);
#if IS31FL3737_I2C_PERSISTENCE > 0
for (uint8_t i = 0; i < IS31FL3737_I2C_PERSISTENCE; i++) {
if (i2c_transmit(addr << 1, g_twi_transfer_buffer, 17, IS31FL3737_I2C_TIMEOUT) == 0) break;
if (i2c_transmit(addr << 1, i2c_transfer_buffer, 17, IS31FL3737_I2C_TIMEOUT) == 0) break;
}
#else
i2c_transmit(addr << 1, g_twi_transfer_buffer, 17, IS31FL3737_I2C_TIMEOUT);
i2c_transmit(addr << 1, i2c_transfer_buffer, 17, IS31FL3737_I2C_TIMEOUT);
#endif
}
}

View File

@ -49,8 +49,7 @@
# define IS31FL3737_GLOBAL_CURRENT 0xFF
#endif
// Transfer buffer for TWITransmitData()
uint8_t g_twi_transfer_buffer[20];
uint8_t i2c_transfer_buffer[20];
// These buffers match the IS31FL3737 PWM registers.
// The control buffers match the page 0 LED On/Off registers.
@ -66,15 +65,15 @@ uint8_t g_led_control_registers[IS31FL3737_DRIVER_COUNT][IS31FL3737_LED_CONTROL_
bool g_led_control_registers_update_required[IS31FL3737_DRIVER_COUNT] = {false};
void is31fl3737_write_register(uint8_t addr, uint8_t reg, uint8_t data) {
g_twi_transfer_buffer[0] = reg;
g_twi_transfer_buffer[1] = data;
i2c_transfer_buffer[0] = reg;
i2c_transfer_buffer[1] = data;
#if IS31FL3737_I2C_PERSISTENCE > 0
for (uint8_t i = 0; i < IS31FL3737_I2C_PERSISTENCE; i++) {
if (i2c_transmit(addr << 1, g_twi_transfer_buffer, 2, IS31FL3737_I2C_TIMEOUT) == 0) break;
if (i2c_transmit(addr << 1, i2c_transfer_buffer, 2, IS31FL3737_I2C_TIMEOUT) == 0) break;
}
#else
i2c_transmit(addr << 1, g_twi_transfer_buffer, 2, IS31FL3737_I2C_TIMEOUT);
i2c_transmit(addr << 1, i2c_transfer_buffer, 2, IS31FL3737_I2C_TIMEOUT);
#endif
}
@ -87,22 +86,22 @@ void is31fl3737_write_pwm_buffer(uint8_t addr, uint8_t *pwm_buffer) {
// assumes page 1 is already selected
// transmit PWM registers in 12 transfers of 16 bytes
// g_twi_transfer_buffer[] is 20 bytes
// i2c_transfer_buffer[] is 20 bytes
// iterate over the pwm_buffer contents at 16 byte intervals
for (int i = 0; i < IS31FL3737_PWM_REGISTER_COUNT; i += 16) {
g_twi_transfer_buffer[0] = i;
i2c_transfer_buffer[0] = i;
// copy the data from i to i+15
// device will auto-increment register for data after the first byte
// thus this sets registers 0x00-0x0F, 0x10-0x1F, etc. in one transfer
memcpy(g_twi_transfer_buffer + 1, pwm_buffer + i, 16);
memcpy(i2c_transfer_buffer + 1, pwm_buffer + i, 16);
#if IS31FL3737_I2C_PERSISTENCE > 0
for (uint8_t i = 0; i < IS31FL3737_I2C_PERSISTENCE; i++) {
if (i2c_transmit(addr << 1, g_twi_transfer_buffer, 17, IS31FL3737_I2C_TIMEOUT) == 0) break;
if (i2c_transmit(addr << 1, i2c_transfer_buffer, 17, IS31FL3737_I2C_TIMEOUT) == 0) break;
}
#else
i2c_transmit(addr << 1, g_twi_transfer_buffer, 17, IS31FL3737_I2C_TIMEOUT);
i2c_transmit(addr << 1, i2c_transfer_buffer, 17, IS31FL3737_I2C_TIMEOUT);
#endif
}
}

View File

@ -52,8 +52,7 @@
# define IS31FL3741_GLOBAL_CURRENT 0xFF
#endif
// Transfer buffer for TWITransmitData()
uint8_t g_twi_transfer_buffer[20] = {0xFF};
uint8_t i2c_transfer_buffer[20] = {0xFF};
// These buffers match the IS31FL3741 and IS31FL3741A PWM registers.
// The scaling buffers match the page 2 and 3 LED On/Off registers.
@ -68,15 +67,15 @@ bool g_scaling_registers_update_required[IS31FL3741_DRIVER_COUNT] = {false};
uint8_t g_scaling_registers[IS31FL3741_DRIVER_COUNT][IS31FL3741_PWM_REGISTER_COUNT];
void is31fl3741_write_register(uint8_t addr, uint8_t reg, uint8_t data) {
g_twi_transfer_buffer[0] = reg;
g_twi_transfer_buffer[1] = data;
i2c_transfer_buffer[0] = reg;
i2c_transfer_buffer[1] = data;
#if IS31FL3741_I2C_PERSISTENCE > 0
for (uint8_t i = 0; i < IS31FL3741_I2C_PERSISTENCE; i++) {
if (i2c_transmit(addr << 1, g_twi_transfer_buffer, 2, IS31FL3741_I2C_TIMEOUT) == 0) break;
if (i2c_transmit(addr << 1, i2c_transfer_buffer, 2, IS31FL3741_I2C_TIMEOUT) == 0) break;
}
#else
i2c_transmit(addr << 1, g_twi_transfer_buffer, 2, IS31FL3741_I2C_TIMEOUT);
i2c_transmit(addr << 1, i2c_transfer_buffer, 2, IS31FL3741_I2C_TIMEOUT);
#endif
}
@ -93,34 +92,34 @@ bool is31fl3741_write_pwm_buffer(uint8_t addr, uint8_t *pwm_buffer) {
is31fl3741_select_page(addr, IS31FL3741_COMMAND_PWM_1);
}
g_twi_transfer_buffer[0] = i % 180;
memcpy(g_twi_transfer_buffer + 1, pwm_buffer + i, 18);
i2c_transfer_buffer[0] = i % 180;
memcpy(i2c_transfer_buffer + 1, pwm_buffer + i, 18);
#if IS31FL3741_I2C_PERSISTENCE > 0
for (uint8_t i = 0; i < IS31FL3741_I2C_PERSISTENCE; i++) {
if (i2c_transmit(addr << 1, g_twi_transfer_buffer, 19, IS31FL3741_I2C_TIMEOUT) != 0) {
if (i2c_transmit(addr << 1, i2c_transfer_buffer, 19, IS31FL3741_I2C_TIMEOUT) != 0) {
return false;
}
}
#else
if (i2c_transmit(addr << 1, g_twi_transfer_buffer, 19, IS31FL3741_I2C_TIMEOUT) != 0) {
if (i2c_transmit(addr << 1, i2c_transfer_buffer, 19, IS31FL3741_I2C_TIMEOUT) != 0) {
return false;
}
#endif
}
// transfer the left cause the total number is 351
g_twi_transfer_buffer[0] = 162;
memcpy(g_twi_transfer_buffer + 1, pwm_buffer + 342, 9);
i2c_transfer_buffer[0] = 162;
memcpy(i2c_transfer_buffer + 1, pwm_buffer + 342, 9);
#if IS31FL3741_I2C_PERSISTENCE > 0
for (uint8_t i = 0; i < IS31FL3741_I2C_PERSISTENCE; i++) {
if (i2c_transmit(addr << 1, g_twi_transfer_buffer, 10, IS31FL3741_I2C_TIMEOUT) != 0) {
if (i2c_transmit(addr << 1, i2c_transfer_buffer, 10, IS31FL3741_I2C_TIMEOUT) != 0) {
return false;
}
}
#else
if (i2c_transmit(addr << 1, g_twi_transfer_buffer, 10, IS31FL3741_I2C_TIMEOUT) != 0) {
if (i2c_transmit(addr << 1, i2c_transfer_buffer, 10, IS31FL3741_I2C_TIMEOUT) != 0) {
return false;
}
#endif

View File

@ -52,8 +52,7 @@
# define IS31FL3741_GLOBAL_CURRENT 0xFF
#endif
// Transfer buffer for TWITransmitData()
uint8_t g_twi_transfer_buffer[20] = {0xFF};
uint8_t i2c_transfer_buffer[20] = {0xFF};
// These buffers match the IS31FL3741 and IS31FL3741A PWM registers.
// The scaling buffers match the page 2 and 3 LED On/Off registers.
@ -68,15 +67,15 @@ bool g_scaling_registers_update_required[IS31FL3741_DRIVER_COUNT] = {false};
uint8_t g_scaling_registers[IS31FL3741_DRIVER_COUNT][IS31FL3741_PWM_REGISTER_COUNT];
void is31fl3741_write_register(uint8_t addr, uint8_t reg, uint8_t data) {
g_twi_transfer_buffer[0] = reg;
g_twi_transfer_buffer[1] = data;
i2c_transfer_buffer[0] = reg;
i2c_transfer_buffer[1] = data;
#if IS31FL3741_I2C_PERSISTENCE > 0
for (uint8_t i = 0; i < IS31FL3741_I2C_PERSISTENCE; i++) {
if (i2c_transmit(addr << 1, g_twi_transfer_buffer, 2, IS31FL3741_I2C_TIMEOUT) == 0) break;
if (i2c_transmit(addr << 1, i2c_transfer_buffer, 2, IS31FL3741_I2C_TIMEOUT) == 0) break;
}
#else
i2c_transmit(addr << 1, g_twi_transfer_buffer, 2, IS31FL3741_I2C_TIMEOUT);
i2c_transmit(addr << 1, i2c_transfer_buffer, 2, IS31FL3741_I2C_TIMEOUT);
#endif
}
@ -93,34 +92,34 @@ bool is31fl3741_write_pwm_buffer(uint8_t addr, uint8_t *pwm_buffer) {
is31fl3741_select_page(addr, IS31FL3741_COMMAND_PWM_1);
}
g_twi_transfer_buffer[0] = i % 180;
memcpy(g_twi_transfer_buffer + 1, pwm_buffer + i, 18);
i2c_transfer_buffer[0] = i % 180;
memcpy(i2c_transfer_buffer + 1, pwm_buffer + i, 18);
#if IS31FL3741_I2C_PERSISTENCE > 0
for (uint8_t i = 0; i < IS31FL3741_I2C_PERSISTENCE; i++) {
if (i2c_transmit(addr << 1, g_twi_transfer_buffer, 19, IS31FL3741_I2C_TIMEOUT) != 0) {
if (i2c_transmit(addr << 1, i2c_transfer_buffer, 19, IS31FL3741_I2C_TIMEOUT) != 0) {
return false;
}
}
#else
if (i2c_transmit(addr << 1, g_twi_transfer_buffer, 19, IS31FL3741_I2C_TIMEOUT) != 0) {
if (i2c_transmit(addr << 1, i2c_transfer_buffer, 19, IS31FL3741_I2C_TIMEOUT) != 0) {
return false;
}
#endif
}
// transfer the left cause the total number is 351
g_twi_transfer_buffer[0] = 162;
memcpy(g_twi_transfer_buffer + 1, pwm_buffer + 342, 9);
i2c_transfer_buffer[0] = 162;
memcpy(i2c_transfer_buffer + 1, pwm_buffer + 342, 9);
#if IS31FL3741_I2C_PERSISTENCE > 0
for (uint8_t i = 0; i < IS31FL3741_I2C_PERSISTENCE; i++) {
if (i2c_transmit(addr << 1, g_twi_transfer_buffer, 10, IS31FL3741_I2C_TIMEOUT) != 0) {
if (i2c_transmit(addr << 1, i2c_transfer_buffer, 10, IS31FL3741_I2C_TIMEOUT) != 0) {
return false;
}
}
#else
if (i2c_transmit(addr << 1, g_twi_transfer_buffer, 10, IS31FL3741_I2C_TIMEOUT) != 0) {
if (i2c_transmit(addr << 1, i2c_transfer_buffer, 10, IS31FL3741_I2C_TIMEOUT) != 0) {
return false;
}
#endif

View File

@ -31,8 +31,7 @@
# define ISSI_PERSISTENCE 0
#endif
// Transfer buffer for TWITransmitData()
uint8_t g_twi_transfer_buffer[20];
uint8_t i2c_transfer_buffer[20];
// These buffers match the PWM & scaling registers.
// Storing them like this is optimal for I2C transfers to the registers.
@ -45,15 +44,15 @@ bool g_scaling_buffer_update_required[DRIVER_COUNT] = {false};
// For writing of single register entry
void IS31FL_write_single_register(uint8_t addr, uint8_t reg, uint8_t data) {
// Set register address and register data ready to write
g_twi_transfer_buffer[0] = reg;
g_twi_transfer_buffer[1] = data;
i2c_transfer_buffer[0] = reg;
i2c_transfer_buffer[1] = data;
#if ISSI_PERSISTENCE > 0
for (uint8_t i = 0; i < ISSI_PERSISTENCE; i++) {
if (i2c_transmit(addr << 1, g_twi_transfer_buffer, 2, ISSI_TIMEOUT) == 0) break;
if (i2c_transmit(addr << 1, i2c_transfer_buffer, 2, ISSI_TIMEOUT) == 0) break;
}
#else
i2c_transmit(addr << 1, g_twi_transfer_buffer, 2, ISSI_TIMEOUT);
i2c_transmit(addr << 1, i2c_transfer_buffer, 2, ISSI_TIMEOUT);
#endif
}
@ -64,18 +63,18 @@ bool IS31FL_write_multi_registers(uint8_t addr, uint8_t *source_buffer, uint8_t
// Split the buffer into chunks to transfer
for (int i = 0; i < buffer_size; i += transfer_size) {
// Set the first entry of transfer buffer to the first register we want to write
g_twi_transfer_buffer[0] = i + start_reg_addr;
i2c_transfer_buffer[0] = i + start_reg_addr;
// Copy the section of our source buffer into the transfer buffer after first register address
memcpy(g_twi_transfer_buffer + 1, source_buffer + i, transfer_size);
memcpy(i2c_transfer_buffer + 1, source_buffer + i, transfer_size);
#if ISSI_PERSISTENCE > 0
for (uint8_t i = 0; i < ISSI_PERSISTENCE; i++) {
if (i2c_transmit(addr << 1, g_twi_transfer_buffer, transfer_size + 1, ISSI_TIMEOUT) != 0) {
if (i2c_transmit(addr << 1, i2c_transfer_buffer, transfer_size + 1, ISSI_TIMEOUT) != 0) {
return false;
}
}
#else
if (i2c_transmit(addr << 1, g_twi_transfer_buffer, transfer_size + 1, ISSI_TIMEOUT) != 0) {
if (i2c_transmit(addr << 1, i2c_transfer_buffer, transfer_size + 1, ISSI_TIMEOUT) != 0) {
return false;
}
#endif

View File

@ -37,8 +37,7 @@
{ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }
#endif
// Transfer buffer for TWITransmitData()
uint8_t g_twi_transfer_buffer[20];
uint8_t i2c_transfer_buffer[20];
// These buffers match the SNLED27351 PWM registers.
// The control buffers match the PG0 LED On/Off registers.
@ -54,17 +53,17 @@ bool g_led_control_registers_update_required[SNLED27351_DRIVER_COUNT]
bool snled27351_write_register(uint8_t addr, uint8_t reg, uint8_t data) {
// If the transaction fails function returns false.
g_twi_transfer_buffer[0] = reg;
g_twi_transfer_buffer[1] = data;
i2c_transfer_buffer[0] = reg;
i2c_transfer_buffer[1] = data;
#if SNLED27351_I2C_PERSISTENCE > 0
for (uint8_t i = 0; i < SNLED27351_I2C_PERSISTENCE; i++) {
if (i2c_transmit(addr << 1, g_twi_transfer_buffer, 2, SNLED27351_I2C_TIMEOUT) != 0) {
if (i2c_transmit(addr << 1, i2c_transfer_buffer, 2, SNLED27351_I2C_TIMEOUT) != 0) {
return false;
}
}
#else
if (i2c_transmit(addr << 1, g_twi_transfer_buffer, 2, SNLED27351_I2C_TIMEOUT) != 0) {
if (i2c_transmit(addr << 1, i2c_transfer_buffer, 2, SNLED27351_I2C_TIMEOUT) != 0) {
return false;
}
#endif
@ -79,26 +78,26 @@ bool snled27351_write_pwm_buffer(uint8_t addr, uint8_t *pwm_buffer) {
// Assumes PG1 is already selected.
// If any of the transactions fails function returns false.
// Transmit PWM registers in 12 transfers of 16 bytes.
// g_twi_transfer_buffer[] is 20 bytes
// i2c_transfer_buffer[] is 20 bytes
// Iterate over the pwm_buffer contents at 16 byte intervals.
for (int i = 0; i < SNLED27351_PWM_REGISTER_COUNT; i += 16) {
g_twi_transfer_buffer[0] = i;
i2c_transfer_buffer[0] = i;
// Copy the data from i to i+15.
// Device will auto-increment register for data after the first byte
// Thus this sets registers 0x00-0x0F, 0x10-0x1F, etc. in one transfer.
for (int j = 0; j < 16; j++) {
g_twi_transfer_buffer[1 + j] = pwm_buffer[i + j];
i2c_transfer_buffer[1 + j] = pwm_buffer[i + j];
}
#if SNLED27351_I2C_PERSISTENCE > 0
for (uint8_t i = 0; i < SNLED27351_I2C_PERSISTENCE; i++) {
if (i2c_transmit(addr << 1, g_twi_transfer_buffer, 17, SNLED27351_I2C_TIMEOUT) != 0) {
if (i2c_transmit(addr << 1, i2c_transfer_buffer, 17, SNLED27351_I2C_TIMEOUT) != 0) {
return false;
}
}
#else
if (i2c_transmit(addr << 1, g_twi_transfer_buffer, 17, SNLED27351_I2C_TIMEOUT) != 0) {
if (i2c_transmit(addr << 1, i2c_transfer_buffer, 17, SNLED27351_I2C_TIMEOUT) != 0) {
return false;
}
#endif

View File

@ -37,8 +37,7 @@
{ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }
#endif
// Transfer buffer for TWITransmitData()
uint8_t g_twi_transfer_buffer[65];
uint8_t i2c_transfer_buffer[65];
// These buffers match the SNLED27351 PWM registers.
// The control buffers match the PG0 LED On/Off registers.
@ -54,17 +53,17 @@ bool g_led_control_registers_update_required[SNLED27351_DRIVER_COUNT]
bool snled27351_write_register(uint8_t addr, uint8_t reg, uint8_t data) {
// If the transaction fails function returns false.
g_twi_transfer_buffer[0] = reg;
g_twi_transfer_buffer[1] = data;
i2c_transfer_buffer[0] = reg;
i2c_transfer_buffer[1] = data;
#if SNLED27351_I2C_PERSISTENCE > 0
for (uint8_t i = 0; i < SNLED27351_I2C_PERSISTENCE; i++) {
if (i2c_transmit(addr << 1, g_twi_transfer_buffer, 2, SNLED27351_I2C_TIMEOUT) != 0) {
if (i2c_transmit(addr << 1, i2c_transfer_buffer, 2, SNLED27351_I2C_TIMEOUT) != 0) {
return false;
}
}
#else
if (i2c_transmit(addr << 1, g_twi_transfer_buffer, 2, SNLED27351_I2C_TIMEOUT) != 0) {
if (i2c_transmit(addr << 1, i2c_transfer_buffer, 2, SNLED27351_I2C_TIMEOUT) != 0) {
return false;
}
#endif
@ -82,22 +81,22 @@ bool snled27351_write_pwm_buffer(uint8_t addr, uint8_t *pwm_buffer) {
// Iterate over the pwm_buffer contents at 64 byte intervals.
for (uint8_t i = 0; i < SNLED27351_PWM_REGISTER_COUNT; i += 64) {
g_twi_transfer_buffer[0] = i;
i2c_transfer_buffer[0] = i;
// Copy the data from i to i+63.
// Device will auto-increment register for data after the first byte
// Thus this sets registers 0x00-0x0F, 0x10-0x1F, etc. in one transfer.
for (uint8_t j = 0; j < 64; j++) {
g_twi_transfer_buffer[1 + j] = pwm_buffer[i + j];
i2c_transfer_buffer[1 + j] = pwm_buffer[i + j];
}
#if SNLED27351_I2C_PERSISTENCE > 0
for (uint8_t i = 0; i < SNLED27351_I2C_PERSISTENCE; i++) {
if (i2c_transmit(addr << 1, g_twi_transfer_buffer, 65, SNLED27351_I2C_TIMEOUT) != 0) {
if (i2c_transmit(addr << 1, i2c_transfer_buffer, 65, SNLED27351_I2C_TIMEOUT) != 0) {
return false;
}
}
#else
if (i2c_transmit(addr << 1, g_twi_transfer_buffer, 65, SNLED27351_I2C_TIMEOUT) != 0) {
if (i2c_transmit(addr << 1, i2c_transfer_buffer, 65, SNLED27351_I2C_TIMEOUT) != 0) {
return false;
}
#endif

View File

@ -60,8 +60,7 @@
# define IS31FL3733_SYNC_4 IS31FL3733_SYNC_NONE
#endif
// Transfer buffer for TWITransmitData()
uint8_t g_twi_transfer_buffer[20];
uint8_t i2c_transfer_buffer[20];
// These buffers match the IS31FL3733 PWM registers.
// The control buffers match the page 0 LED On/Off registers.
@ -77,17 +76,17 @@ bool g_led_control_registers_update_required[IS31FL3733_DRIVER_COUNT]
bool is31fl3733_write_register(uint8_t index, uint8_t addr, uint8_t reg, uint8_t data) {
// If the transaction fails function returns false.
g_twi_transfer_buffer[0] = reg;
g_twi_transfer_buffer[1] = data;
i2c_transfer_buffer[0] = reg;
i2c_transfer_buffer[1] = data;
#if IS31FL3733_I2C_PERSISTENCE > 0
for (uint8_t i = 0; i < IS31FL3733_I2C_PERSISTENCE; i++) {
if (i2c_transmit(index, addr << 1, g_twi_transfer_buffer, 2, IS31FL3733_I2C_TIMEOUT) != 0) {
if (i2c_transmit(index, addr << 1, i2c_transfer_buffer, 2, IS31FL3733_I2C_TIMEOUT) != 0) {
return false;
}
}
#else
if (i2c_transmit(index, addr << 1, g_twi_transfer_buffer, 2, IS31FL3733_I2C_TIMEOUT) != 0) {
if (i2c_transmit(index, addr << 1, i2c_transfer_buffer, 2, IS31FL3733_I2C_TIMEOUT) != 0) {
return false;
}
#endif
@ -103,26 +102,26 @@ bool is31fl3733_write_pwm_buffer(uint8_t index, uint8_t addr, uint8_t *pwm_buffe
// Assumes page 1 is already selected.
// If any of the transactions fails function returns false.
// Transmit PWM registers in 12 transfers of 16 bytes.
// g_twi_transfer_buffer[] is 20 bytes
// i2c_transfer_buffer[] is 20 bytes
// Iterate over the pwm_buffer contents at 16 byte intervals.
for (int i = 0; i < IS31FL3733_PWM_REGISTER_COUNT; i += 16) {
g_twi_transfer_buffer[0] = i;
i2c_transfer_buffer[0] = i;
// Copy the data from i to i+15.
// Device will auto-increment register for data after the first byte
// Thus this sets registers 0x00-0x0F, 0x10-0x1F, etc. in one transfer.
for (int j = 0; j < 16; j++) {
g_twi_transfer_buffer[1 + j] = pwm_buffer[i + j];
i2c_transfer_buffer[1 + j] = pwm_buffer[i + j];
}
#if IS31FL3733_I2C_PERSISTENCE > 0
for (uint8_t i = 0; i < IS31FL3733_I2C_PERSISTENCE; i++) {
if (i2c_transmit(index, addr << 1, g_twi_transfer_buffer, 17, IS31FL3733_I2C_TIMEOUT) != 0) {
if (i2c_transmit(index, addr << 1, i2c_transfer_buffer, 17, IS31FL3733_I2C_TIMEOUT) != 0) {
return false;
}
}
#else
if (i2c_transmit(index, addr << 1, g_twi_transfer_buffer, 17, IS31FL3733_I2C_TIMEOUT) != 0) {
if (i2c_transmit(index, addr << 1, i2c_transfer_buffer, 17, IS31FL3733_I2C_TIMEOUT) != 0) {
return false;
}
#endif