Skip to content

Commit 2add5c6

Browse files
committed
Merge branch 'dualrgb' into develop
2 parents 9406566 + 4bb9639 commit 2add5c6

File tree

3 files changed

+60
-60
lines changed

3 files changed

+60
-60
lines changed

docs/feature_rgb_matrix.md

Lines changed: 20 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -145,9 +145,22 @@ There is basic support for addressable RGB matrix lighting with the I2C IS31FL37
145145
RGB_MATRIX_ENABLE = yes
146146
RGB_MATRIX_DRIVER = IS31FL3737
147147
```
148+
You can use between 1 and 2 IS31FL3737 IC's. Do not specify `DRIVER_ADDR_2` define for second IC if not present on your keyboard.
148149

149150
Configure the hardware via your `config.h`:
150151

152+
| Variable | Description | Default |
153+
|----------|-------------|---------|
154+
| `ISSI_TIMEOUT` | (Optional) How long to wait for i2c messages, in milliseconds | 100 |
155+
| `ISSI_PERSISTENCE` | (Optional) Retry failed messages this many times | 0 |
156+
| `DRIVER_COUNT` | (Required) How many RGB driver IC's are present | |
157+
| `DRIVER_LED_TOTAL` | (Required) How many RGB lights are present across all drivers | |
158+
| `DRIVER_ADDR_1` | (Required) Address for the first RGB driver | |
159+
| `DRIVER_ADDR_2` | (Optional) Address for the second RGB driver | |
160+
161+
162+
Here is an example using 2 drivers.
163+
151164
```c
152165
// This is a 7-bit address, that gets left-shifted and bit 0
153166
// set to 0 for write, 1 for read (as per I2C protocol)
@@ -159,14 +172,16 @@ Configure the hardware via your `config.h`:
159172
// ADDR represents A3:A0 of the 7-bit address.
160173
// The result is: 0b101(ADDR)
161174
#define DRIVER_ADDR_1 0b1010000
162-
#define DRIVER_ADDR_2 0b1010000 // this is here for compliancy reasons.
175+
#define DRIVER_ADDR_2 0b1010001
163176

164177
#define DRIVER_COUNT 2
165-
#define DRIVER_1_LED_TOTAL 64
166-
#define DRIVER_LED_TOTAL DRIVER_1_LED_TOTAL
178+
#define DRIVER_1_LED_TOTAL 30
179+
#define DRIVER_2_LED_TOTAL 36
180+
#define DRIVER_LED_TOTAL (DRIVER_1_LED_TOTAL + DRIVER_2_LED_TOTAL)
167181
```
182+
!> Note the parentheses, this is so when `DRIVER_LED_TOTAL` is used in code and expanded, the values are added together before any additional math is applied to them. As an example, `rand() % (DRIVER_1_LED_TOTAL + DRIVER_2_LED_TOTAL)` will give very different results than `rand() % DRIVER_1_LED_TOTAL + DRIVER_2_LED_TOTAL`.
168183
169-
Currently only a single drivers is supported, but it would be trivial to support all 4 combinations. For now define `DRIVER_ADDR_2` as `DRIVER_ADDR_1`
184+
Currently only two drivers are supported, but it would be trivial to support all 4 combinations.
170185
171186
Define these arrays listing all the LEDs in your `<keyboard>.c`:
172187
@@ -183,7 +198,7 @@ const is31_led g_is31_leds[DRIVER_LED_TOTAL] = {
183198
}
184199
```
185200

186-
Where `X_Y` is the location of the LED in the matrix defined by [the datasheet](https://www.issi.com/WW/pdf/31FL3737.pdf) and the header file `drivers/issi/is31fl3737.h`. The `driver` is the index of the driver you defined in your `config.h` (Only `0` right now).
201+
Where `X_Y` is the location of the LED in the matrix defined by [the datasheet](https://www.issi.com/WW/pdf/31FL3737.pdf) and the header file `drivers/issi/is31fl3737.h`. The `driver` is the index of the driver you defined in your `config.h` (Only `0`, `1` for now).
187202

188203
---
189204

@@ -694,39 +709,6 @@ void rgb_matrix_indicators_advanced_user(uint8_t led_min, uint8_t led_max) {
694709
}
695710
```
696711
697-
### Indicator Examples :id=indicator-examples
698-
699-
Caps Lock indicator on alphanumeric flagged keys:
700-
```c
701-
void rgb_matrix_indicators_advanced_user(uint8_t led_min, uint8_t led_max) {
702-
if (host_keyboard_led_state().caps_lock) {
703-
for (uint8_t i = led_min; i <= led_max; i++) {
704-
if (g_led_config.flags[i] & LED_FLAG_KEYLIGHT) {
705-
rgb_matrix_set_color(i, RGB_RED);
706-
}
707-
}
708-
}
709-
}
710-
```
711-
712-
Layer indicator on all flagged keys:
713-
```c
714-
void rgb_matrix_indicators_advanced_user(uint8_t led_min, uint8_t led_max) {
715-
for (uint8_t i = led_min; i <= led_max; i++) {
716-
switch(get_highest_layer(layer_state|default_layer_state)) {
717-
case RAISE:
718-
rgb_matrix_set_color(i, RGB_BLUE);
719-
break;
720-
case LOWER:
721-
rgb_matrix_set_color(i, RGB_YELLOW);
722-
break;
723-
default:
724-
break;
725-
}
726-
}
727-
}
728-
```
729-
730712
### Suspended state :id=suspended-state
731713
To use the suspend feature, make sure that `#define RGB_DISABLE_WHEN_USB_SUSPENDED true` is added to the `config.h` file.
732714

drivers/issi/is31fl3737.c

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "is31fl3737.h"
2020
#include "i2c_master.h"
2121
#include "wait.h"
22+
#include "progmem.h"
2223

2324
// This is a 7-bit address, that gets left-shifted and bit 0
2425
// set to 0 for write, 1 for read (as per I2C protocol)
@@ -65,11 +66,15 @@ uint8_t g_twi_transfer_buffer[20];
6566
// We could optimize this and take out the unused registers from these
6667
// buffers and the transfers in IS31FL3737_write_pwm_buffer() but it's
6768
// probably not worth the extra complexity.
68-
uint8_t g_pwm_buffer[DRIVER_COUNT][192];
69-
bool g_pwm_buffer_update_required = false;
7069

71-
uint8_t g_led_control_registers[DRIVER_COUNT][24] = {{0}};
72-
bool g_led_control_registers_update_required = false;
70+
71+
72+
73+
uint8_t g_pwm_buffer[DRIVER_COUNT][(192)];
74+
bool g_pwm_buffer_update_required[DRIVER_COUNT] = {false};
75+
76+
uint8_t g_led_control_registers[DRIVER_COUNT][24] = {0};
77+
bool g_led_control_registers_update_required[DRIVER_COUNT] = {false};
7378

7479
void IS31FL3737_write_register(uint8_t addr, uint8_t reg, uint8_t data) {
7580
g_twi_transfer_buffer[0] = reg;
@@ -158,7 +163,7 @@ void IS31FL3737_set_color(int index, uint8_t red, uint8_t green, uint8_t blue) {
158163
g_pwm_buffer[led.driver][led.r] = red;
159164
g_pwm_buffer[led.driver][led.g] = green;
160165
g_pwm_buffer[led.driver][led.b] = blue;
161-
g_pwm_buffer_update_required = true;
166+
g_pwm_buffer_update_required[led.driver] = true;
162167
}
163168
}
164169

@@ -194,30 +199,31 @@ void IS31FL3737_set_led_control_register(uint8_t index, bool red, bool green, bo
194199
g_led_control_registers[led.driver][control_register_b] &= ~(1 << bit_b);
195200
}
196201

197-
g_led_control_registers_update_required = true;
202+
g_led_control_registers_update_required[led.driver] = true;
198203
}
199204

200-
void IS31FL3737_update_pwm_buffers(uint8_t addr1, uint8_t addr2) {
201-
if (g_pwm_buffer_update_required) {
205+
void IS31FL3737_update_pwm_buffers(uint8_t addr, uint8_t index) {
206+
if (g_pwm_buffer_update_required[index]) {
202207
// Firstly we need to unlock the command register and select PG1
203-
IS31FL3737_write_register(addr1, ISSI_COMMANDREGISTER_WRITELOCK, 0xC5);
204-
IS31FL3737_write_register(addr1, ISSI_COMMANDREGISTER, ISSI_PAGE_PWM);
208+
IS31FL3737_write_register(addr, ISSI_COMMANDREGISTER_WRITELOCK, 0xC5);
209+
IS31FL3737_write_register(addr, ISSI_COMMANDREGISTER, ISSI_PAGE_PWM);
210+
211+
IS31FL3737_write_pwm_buffer(addr, g_pwm_buffer[index]);
212+
205213

206-
IS31FL3737_write_pwm_buffer(addr1, g_pwm_buffer[0]);
207-
// IS31FL3737_write_pwm_buffer(addr2, g_pwm_buffer[1]);
208214
}
209-
g_pwm_buffer_update_required = false;
215+
g_pwm_buffer_update_required[index] = false;
210216
}
211217

212-
void IS31FL3737_update_led_control_registers(uint8_t addr1, uint8_t addr2) {
213-
if (g_led_control_registers_update_required) {
218+
void IS31FL3737_update_led_control_registers(uint8_t addr, uint8_t index) {
219+
if (g_led_control_registers_update_required[index]) {
214220
// Firstly we need to unlock the command register and select PG0
215-
IS31FL3737_write_register(addr1, ISSI_COMMANDREGISTER_WRITELOCK, 0xC5);
216-
IS31FL3737_write_register(addr1, ISSI_COMMANDREGISTER, ISSI_PAGE_LEDCONTROL);
221+
IS31FL3737_write_register(addr, ISSI_COMMANDREGISTER_WRITELOCK, 0xC5);
222+
IS31FL3737_write_register(addr, ISSI_COMMANDREGISTER, ISSI_PAGE_LEDCONTROL);
217223
for (int i = 0; i < 24; i++) {
218-
IS31FL3737_write_register(addr1, i, g_led_control_registers[0][i]);
219-
// IS31FL3737_write_register(addr2, i, g_led_control_registers[1][i]);
224+
IS31FL3737_write_register(addr, i, g_led_control_registers[index][i]);
220225
}
221-
g_led_control_registers_update_required = false;
222226
}
227+
g_led_control_registers_update_required[index] = false;
223228
}
229+

quantum/rgb_matrix/rgb_matrix_drivers.c

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@ static void init(void) {
6565
# endif
6666
# elif defined(IS31FL3737)
6767
IS31FL3737_init(DRIVER_ADDR_1);
68+
# if defined(DRIVER_ADDR_2) && (DRIVER_ADDR_2 != DRIVER_ADDR_1) // provides backward compatibility
69+
IS31FL3737_init(DRIVER_ADDR_2);
70+
# endif
6871
# else
6972
IS31FL3741_init(DRIVER_ADDR_1);
7073
# endif
@@ -105,7 +108,10 @@ static void init(void) {
105108
IS31FL3733_update_led_control_registers(DRIVER_ADDR_4, 3);
106109
# endif
107110
# elif defined(IS31FL3737)
108-
IS31FL3737_update_led_control_registers(DRIVER_ADDR_1, DRIVER_ADDR_2);
111+
IS31FL3737_update_led_control_registers(DRIVER_ADDR_1, 0);
112+
# if defined(DRIVER_ADDR_2) && (DRIVER_ADDR_2 != DRIVER_ADDR_1) // provides backward compatibility
113+
IS31FL3737_update_led_control_registers(DRIVER_ADDR_2, 1);
114+
# endif
109115
# else
110116
IS31FL3741_update_led_control_registers(DRIVER_ADDR_1, 0);
111117
# endif
@@ -152,7 +158,12 @@ const rgb_matrix_driver_t rgb_matrix_driver = {
152158
.set_color_all = IS31FL3733_set_color_all,
153159
};
154160
# elif defined(IS31FL3737)
155-
static void flush(void) { IS31FL3737_update_pwm_buffers(DRIVER_ADDR_1, DRIVER_ADDR_2); }
161+
static void flush(void) {
162+
IS31FL3737_update_pwm_buffers(DRIVER_ADDR_1, 0);
163+
# if defined(DRIVER_ADDR_2) && (DRIVER_ADDR_2 != DRIVER_ADDR_1) // provides backward compatibility
164+
IS31FL3737_update_pwm_buffers(DRIVER_ADDR_2, 1);
165+
# endif
166+
}
156167

157168
const rgb_matrix_driver_t rgb_matrix_driver = {
158169
.init = init,
@@ -226,3 +237,4 @@ const rgb_matrix_driver_t rgb_matrix_driver = {
226237
.set_color_all = setled_all,
227238
};
228239
#endif
240+
// touching file ccullin

0 commit comments

Comments
 (0)