mirror of
https://github.com/qmk/qmk_firmware.git
synced 2024-11-25 04:43:02 +00:00
Keychron Q3 I2C & CKLED2001 transfer speedup (#18780)
This commit is contained in:
parent
93a0995e48
commit
2c3859fbf7
@ -36,7 +36,7 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Transfer buffer for TWITransmitData()
|
// Transfer buffer for TWITransmitData()
|
||||||
uint8_t g_twi_transfer_buffer[20];
|
uint8_t g_twi_transfer_buffer[65];
|
||||||
|
|
||||||
// These buffers match the CKLED2001 PWM registers.
|
// These buffers match the CKLED2001 PWM registers.
|
||||||
// The control buffers match the PG0 LED On/Off registers.
|
// The control buffers match the PG0 LED On/Off registers.
|
||||||
@ -72,27 +72,26 @@ bool CKLED2001_write_register(uint8_t addr, uint8_t reg, uint8_t data) {
|
|||||||
bool CKLED2001_write_pwm_buffer(uint8_t addr, uint8_t *pwm_buffer) {
|
bool CKLED2001_write_pwm_buffer(uint8_t addr, uint8_t *pwm_buffer) {
|
||||||
// Assumes PG1 is already selected.
|
// Assumes PG1 is already selected.
|
||||||
// If any of the transactions fails function returns false.
|
// If any of the transactions fails function returns false.
|
||||||
// Transmit PWM registers in 12 transfers of 16 bytes.
|
// Transmit PWM registers in 3 transfers of 64 bytes.
|
||||||
// g_twi_transfer_buffer[] is 20 bytes
|
|
||||||
|
|
||||||
// Iterate over the pwm_buffer contents at 16 byte intervals.
|
// Iterate over the pwm_buffer contents at 64 byte intervals.
|
||||||
for (int i = 0; i < 192; i += 16) {
|
for (uint8_t i = 0; i < 192; i += 64) {
|
||||||
g_twi_transfer_buffer[0] = i;
|
g_twi_transfer_buffer[0] = i;
|
||||||
// Copy the data from i to i+15.
|
// Copy the data from i to i+63.
|
||||||
// Device will auto-increment register for data after the first byte
|
// Device will auto-increment register for data after the first byte
|
||||||
// Thus this sets registers 0x00-0x0F, 0x10-0x1F, etc. in one transfer.
|
// Thus this sets registers 0x00-0x0F, 0x10-0x1F, etc. in one transfer.
|
||||||
for (int j = 0; j < 16; j++) {
|
for (uint8_t j = 0; j < 64; j++) {
|
||||||
g_twi_transfer_buffer[1 + j] = pwm_buffer[i + j];
|
g_twi_transfer_buffer[1 + j] = pwm_buffer[i + j];
|
||||||
}
|
}
|
||||||
|
|
||||||
#if CKLED2001_PERSISTENCE > 0
|
#if CKLED2001_PERSISTENCE > 0
|
||||||
for (uint8_t i = 0; i < CKLED2001_PERSISTENCE; i++) {
|
for (uint8_t i = 0; i < CKLED2001_PERSISTENCE; i++) {
|
||||||
if (i2c_transmit(addr << 1, g_twi_transfer_buffer, 17, CKLED2001_TIMEOUT) != 0) {
|
if (i2c_transmit(addr << 1, g_twi_transfer_buffer, 65, CKLED2001_TIMEOUT) != 0) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
if (i2c_transmit(addr << 1, g_twi_transfer_buffer, 17, CKLED2001_TIMEOUT) != 0) {
|
if (i2c_transmit(addr << 1, g_twi_transfer_buffer, 65, CKLED2001_TIMEOUT) != 0) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -31,6 +31,13 @@
|
|||||||
#define DRIVER_ADDR_1 0b1110111
|
#define DRIVER_ADDR_1 0b1110111
|
||||||
#define DRIVER_ADDR_2 0b1110100
|
#define DRIVER_ADDR_2 0b1110100
|
||||||
|
|
||||||
|
/* Increase I2C speed to 1000 KHz */
|
||||||
|
#define I2C1_TIMINGR_PRESC 0U
|
||||||
|
#define I2C1_TIMINGR_SCLDEL 3U
|
||||||
|
#define I2C1_TIMINGR_SDADEL 0U
|
||||||
|
#define I2C1_TIMINGR_SCLH 15U
|
||||||
|
#define I2C1_TIMINGR_SCLL 51U
|
||||||
|
|
||||||
/* Scan phase of led driver set as MSKPHASE_9CHANNEL(defined as 0x03 in CKLED2001.h) */
|
/* Scan phase of led driver set as MSKPHASE_9CHANNEL(defined as 0x03 in CKLED2001.h) */
|
||||||
#define PHASE_CHANNEL MSKPHASE_9CHANNEL
|
#define PHASE_CHANNEL MSKPHASE_9CHANNEL
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user