Skip to content

Commit

Permalink
Update ISSI3741 (qmk#9912)
Browse files Browse the repository at this point in the history
* [Driver] bugfix reset the scaling register flag to FALSE

* Update drivers/issi/is31fl3741.c

Co-authored-by: Ryan <[email protected]>

* Add CS & SW defines for ISSI3741

* Make IS31FL3741 control register update clearer

Co-authored-by: Ryan <[email protected]>
Co-authored-by: Jumail Mundekkat <[email protected]>
  • Loading branch information
3 people authored and rgoulter committed Oct 4, 2020
1 parent 246486d commit 7b5aa94
Show file tree
Hide file tree
Showing 2 changed files with 394 additions and 61 deletions.
76 changes: 21 additions & 55 deletions drivers/issi/is31fl3741.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,22 +78,6 @@ bool g_scaling_registers_update_required[DRIVER_COUNT] = {false};

uint8_t g_scaling_registers[DRIVER_COUNT][ISSI_MAX_LEDS];

uint32_t IS31FL3741_get_cw_sw_position(uint8_t cs, uint8_t sw) {
uint32_t pos = 0;

if (cs < 31) {
if (sw < 7) {
pos = (sw - 1) * 30 + (cs - 1);

} else {
pos = 0xB4 + (sw - 7) * 30 + (cs - 1);
}
} else {
pos = 0xB4 + 0x5A + (sw - 1) * 9 + (cs - 31);
}

return pos;
}

void IS31FL3741_write_register(uint8_t addr, uint8_t reg, uint8_t data) {
g_twi_transfer_buffer[0] = reg;
Expand Down Expand Up @@ -186,15 +170,10 @@ void IS31FL3741_init(uint8_t addr) {
void IS31FL3741_set_color(int index, uint8_t red, uint8_t green, uint8_t blue) {
if (index >= 0 && index < DRIVER_LED_TOTAL) {
is31_led led = g_is31_leds[index];
uint32_t rp = 0, gp = 0, bp = 0;

rp = IS31FL3741_get_cw_sw_position(led.rcs, led.rsw);
gp = IS31FL3741_get_cw_sw_position(led.gcs, led.gsw);
bp = IS31FL3741_get_cw_sw_position(led.bcs, led.bsw);

g_pwm_buffer[led.driver][rp] = red;
g_pwm_buffer[led.driver][gp] = green;
g_pwm_buffer[led.driver][bp] = blue;
g_pwm_buffer[led.driver][led.r] = red;
g_pwm_buffer[led.driver][led.g] = green;
g_pwm_buffer[led.driver][led.b] = blue;
g_pwm_buffer_update_required = true;
}
}
Expand All @@ -208,26 +187,22 @@ void IS31FL3741_set_color_all(uint8_t red, uint8_t green, uint8_t blue) {
void IS31FL3741_set_led_control_register(uint8_t index, bool red, bool green, bool blue) {
is31_led led = g_is31_leds[index];

uint32_t scaling_register_r = IS31FL3741_get_cw_sw_position(led.rcs, led.rsw);
uint32_t scaling_register_g = IS31FL3741_get_cw_sw_position(led.gcs, led.gsw);
uint32_t scaling_register_b = IS31FL3741_get_cw_sw_position(led.bcs, led.bsw);

if (red) {
g_scaling_registers[led.driver][scaling_register_r] = 0xFF;
g_scaling_registers[led.driver][led.r] = 0xFF;
} else {
g_scaling_registers[led.driver][scaling_register_r] = 0x00;
g_scaling_registers[led.driver][led.r] = 0x00;
}

if (green) {
g_scaling_registers[led.driver][scaling_register_g] = 0xFF;
g_scaling_registers[led.driver][led.g] = 0xFF;
} else {
g_scaling_registers[led.driver][scaling_register_g] = 0x00;
g_scaling_registers[led.driver][led.g] = 0x00;
}

if (blue) {
g_scaling_registers[led.driver][scaling_register_b] = 0xFF;
g_scaling_registers[led.driver][led.b] = 0xFF;
} else {
g_scaling_registers[led.driver][scaling_register_b] = 0x00;
g_scaling_registers[led.driver][led.b] = 0x00;
}

g_scaling_registers_update_required[led.driver] = true;
Expand All @@ -242,15 +217,9 @@ void IS31FL3741_update_pwm_buffers(uint8_t addr1, uint8_t addr2) {
}

void IS31FL3741_set_pwm_buffer(const is31_led *pled, uint8_t red, uint8_t green, uint8_t blue) {
uint32_t rp = 0, gp = 0, bp = 0;

rp = IS31FL3741_get_cw_sw_position(pled->rcs, pled->rsw);
gp = IS31FL3741_get_cw_sw_position(pled->gcs, pled->gsw);
bp = IS31FL3741_get_cw_sw_position(pled->bcs, pled->bsw);

g_pwm_buffer[pled->driver][rp] = red;
g_pwm_buffer[pled->driver][gp] = green;
g_pwm_buffer[pled->driver][bp] = blue;
g_pwm_buffer[pled->driver][pled->r] = red;
g_pwm_buffer[pled->driver][pled->g] = green;
g_pwm_buffer[pled->driver][pled->b] = blue;

g_pwm_buffer_update_required = true;
}
Expand All @@ -261,30 +230,27 @@ void IS31FL3741_update_led_control_registers(uint8_t addr, uint8_t index) {
IS31FL3741_write_register(addr, ISSI_COMMANDREGISTER_WRITELOCK, 0xC5);
IS31FL3741_write_register(addr, ISSI_COMMANDREGISTER, ISSI_PAGE_SCALING_0);

for (int i = 0; i < 180; ++i) {
// CS1_SW1 to CS30_SW6 are on PG2
for (int i = CS1_SW1; i <= CS30_SW6; ++i) {
IS31FL3741_write_register(addr, i, g_scaling_registers[0][i]);
}

// unlock the command register and select PG3
IS31FL3741_write_register(addr, ISSI_COMMANDREGISTER_WRITELOCK, 0xC5);
IS31FL3741_write_register(addr, ISSI_COMMANDREGISTER, ISSI_PAGE_SCALING_1);

for (int i = 0; i < 171; ++i) {
IS31FL3741_write_register(addr, i, g_scaling_registers[0][180 + i]);
// CS1_SW7 to CS39_SW9 are on PG3
for (int i = CS1_SW7; i <= CS39_SW9; ++i) {
IS31FL3741_write_register(addr, i - CS1_SW7, g_scaling_registers[0][i]);
}

g_scaling_registers_update_required[index] = false;
}
}

void IS31FL3741_set_scaling_registers(const is31_led *pled, uint8_t red, uint8_t green, uint8_t blue) {
uint32_t rp = 0, gp = 0, bp = 0;

rp = IS31FL3741_get_cw_sw_position(pled->rcs, pled->rsw);
gp = IS31FL3741_get_cw_sw_position(pled->gcs, pled->gsw);
bp = IS31FL3741_get_cw_sw_position(pled->bcs, pled->bsw);

g_scaling_registers[pled->driver][rp] = red;
g_scaling_registers[pled->driver][gp] = green;
g_scaling_registers[pled->driver][bp] = blue;
g_scaling_registers[pled->driver][pled->r] = red;
g_scaling_registers[pled->driver][pled->g] = green;
g_scaling_registers[pled->driver][pled->b] = blue;
}

Loading

0 comments on commit 7b5aa94

Please sign in to comment.