aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDonald Kjer <don.kjer@gmail.com>2021-05-21 21:42:39 -0700
committerGitHub <noreply@github.com>2021-05-21 21:42:39 -0700
commit8e96c5a060896c4aa5ed181d9c86c4e66bb78cfc (patch)
tree0c8b2755864b76654441258a2892a592db655a88
parent81821f0a1207ffa0b533a09e6ac34c068b23fe49 (diff)
downloadqmk_firmware-8e96c5a060896c4aa5ed181d9c86c4e66bb78cfc.tar.gz
qmk_firmware-8e96c5a060896c4aa5ed181d9c86c4e66bb78cfc.zip
Add support for up to 4 IS31FL3733 drivers (#12342)
Co-authored-by: James Young <18669334+noroadsleft@users.noreply.github.com>
-rw-r--r--docs/feature_led_matrix.md31
-rw-r--r--docs/feature_rgb_matrix.md96
-rw-r--r--drivers/issi/is31fl3733.c2
-rw-r--r--quantum/led_matrix_drivers.c22
-rw-r--r--quantum/rgb_matrix_drivers.c45
5 files changed, 167 insertions, 29 deletions
diff --git a/docs/feature_led_matrix.md b/docs/feature_led_matrix.md
index 7834b940d..e56caabfe 100644
--- a/docs/feature_led_matrix.md
+++ b/docs/feature_led_matrix.md
@@ -15,7 +15,20 @@ LED_MATRIX_ENABLE = yes
15LED_MATRIX_DRIVER = IS31FL3731 15LED_MATRIX_DRIVER = IS31FL3731
16``` 16```
17 17
18Configure the hardware via your `config.h`: 18You can use between 1 and 4 IS31FL3731 IC's. Do not specify `LED_DRIVER_ADDR_<N>` defines for IC's that are not present on your keyboard. You can define the following items in `config.h`:
19
20| Variable | Description | Default |
21|----------|-------------|---------|
22| `ISSI_TIMEOUT` | (Optional) How long to wait for i2c messages, in milliseconds | 100 |
23| `ISSI_PERSISTENCE` | (Optional) Retry failed messages this many times | 0 |
24| `LED_DRIVER_COUNT` | (Required) How many LED driver IC's are present | |
25| `DRIVER_LED_TOTAL` | (Required) How many LED lights are present across all drivers | |
26| `LED_DRIVER_ADDR_1` | (Required) Address for the first LED driver | |
27| `LED_DRIVER_ADDR_2` | (Optional) Address for the second LED driver | |
28| `LED_DRIVER_ADDR_3` | (Optional) Address for the third LED driver | |
29| `LED_DRIVER_ADDR_4` | (Optional) Address for the fourth LED driver | |
30
31Here is an example using 2 drivers.
19 32
20```c 33```c
21// This is a 7-bit address, that gets left-shifted and bit 0 34// This is a 7-bit address, that gets left-shifted and bit 0
@@ -25,18 +38,16 @@ Configure the hardware via your `config.h`:
25// 0b1110111 AD <-> VCC 38// 0b1110111 AD <-> VCC
26// 0b1110101 AD <-> SCL 39// 0b1110101 AD <-> SCL
27// 0b1110110 AD <-> SDA 40// 0b1110110 AD <-> SDA
28#define DRIVER_ADDR_1 0b1110100 41#define LED_DRIVER_ADDR_1 0b1110100
29#define DRIVER_ADDR_2 0b1110110 42#define LED_DRIVER_ADDR_2 0b1110110
30 43
31#define DRIVER_COUNT 2 44#define LED_DRIVER_COUNT 2
32#define DRIVER_1_LED_TOTAL 25 45#define LED_DRIVER_1_LED_TOTAL 25
33#define DRIVER_2_LED_TOTAL 24 46#define LED_DRIVER_2_LED_TOTAL 24
34#define DRIVER_LED_TOTAL (DRIVER_1_LED_TOTAL + DRIVER_2_LED_TOTAL) 47#define DRIVER_LED_TOTAL (LED_DRIVER_1_LED_TOTAL + LED_DRIVER_2_LED_TOTAL)
35``` 48```
36 49
37!> 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`. 50!> Note the parentheses, this is so when `LED_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() % (LED_DRIVER_1_LED_TOTAL + LED_DRIVER_2_LED_TOTAL)` will give very different results than `rand() % LED_DRIVER_1_LED_TOTAL + LED_DRIVER_2_LED_TOTAL`.
38
39Currently only 2 drivers are supported, but it would be trivial to support all 4 combinations.
40 51
41Define these arrays listing all the LEDs in your `<keyboard>.c`: 52Define these arrays listing all the LEDs in your `<keyboard>.c`:
42 53
diff --git a/docs/feature_rgb_matrix.md b/docs/feature_rgb_matrix.md
index ffbb8c0b6..a29d5c624 100644
--- a/docs/feature_rgb_matrix.md
+++ b/docs/feature_rgb_matrix.md
@@ -15,7 +15,20 @@ RGB_MATRIX_ENABLE = yes
15RGB_MATRIX_DRIVER = IS31FL3731 15RGB_MATRIX_DRIVER = IS31FL3731
16``` 16```
17 17
18Configure the hardware via your `config.h`: 18You can use between 1 and 4 IS31FL3731 IC's. Do not specify `DRIVER_ADDR_<N>` defines for IC's that are not present on your keyboard. You can define the following items in `config.h`:
19
20| Variable | Description | Default |
21|----------|-------------|---------|
22| `ISSI_TIMEOUT` | (Optional) How long to wait for i2c messages, in milliseconds | 100 |
23| `ISSI_PERSISTENCE` | (Optional) Retry failed messages this many times | 0 |
24| `DRIVER_COUNT` | (Required) How many RGB driver IC's are present | |
25| `DRIVER_LED_TOTAL` | (Required) How many RGB lights are present across all drivers | |
26| `DRIVER_ADDR_1` | (Required) Address for the first RGB driver | |
27| `DRIVER_ADDR_2` | (Optional) Address for the second RGB driver | |
28| `DRIVER_ADDR_3` | (Optional) Address for the third RGB driver | |
29| `DRIVER_ADDR_4` | (Optional) Address for the fourth RGB driver | |
30
31Here is an example using 2 drivers.
19 32
20```c 33```c
21// This is a 7-bit address, that gets left-shifted and bit 0 34// This is a 7-bit address, that gets left-shifted and bit 0
@@ -36,8 +49,6 @@ Configure the hardware via your `config.h`:
36 49
37!> 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`. 50!> 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`.
38 51
39Currently only 2 drivers are supported, but it would be trivial to support all 4 combinations.
40
41Define these arrays listing all the LEDs in your `<keyboard>.c`: 52Define these arrays listing all the LEDs in your `<keyboard>.c`:
42 53
43```c 54```c
@@ -53,12 +64,10 @@ const is31_led g_is31_leds[DRIVER_LED_TOTAL] = {
53} 64}
54``` 65```
55 66
56Where `Cx_y` is the location of the LED in the matrix defined by [the datasheet](https://www.issi.com/WW/pdf/31FL3731.pdf) and the header file `drivers/issi/is31fl3731.h`. The `driver` is the index of the driver you defined in your `config.h` (`0` or `1` right now). 67Where `Cx_y` is the location of the LED in the matrix defined by [the datasheet](https://www.issi.com/WW/pdf/31FL3731.pdf) and the header file `drivers/issi/is31fl3731.h`. The `driver` is the index of the driver you defined in your `config.h` (`0`, `1`, `2`, or `3`).
57 68
58--- 69---
59### IS31FL3733/IS31FL3737 :id=is31fl3733is31fl3737 70### IS31FL3733 :id=is31fl3733
60
61!> For the IS31FL3737, replace all instances of `IS31FL3733` below with `IS31FL3737`.
62 71
63There is basic support for addressable RGB matrix lighting with the I2C IS31FL3733 RGB controller. To enable it, add this to your `rules.mk`: 72There is basic support for addressable RGB matrix lighting with the I2C IS31FL3733 RGB controller. To enable it, add this to your `rules.mk`:
64 73
@@ -67,7 +76,24 @@ RGB_MATRIX_ENABLE = yes
67RGB_MATRIX_DRIVER = IS31FL3733 76RGB_MATRIX_DRIVER = IS31FL3733
68``` 77```
69 78
70Configure the hardware via your `config.h`: 79You can use between 1 and 4 IS31FL3733 IC's. Do not specify `DRIVER_ADDR_<N>` defines for IC's that are not present on your keyboard. You can define the following items in `config.h`:
80
81| Variable | Description | Default |
82|----------|-------------|---------|
83| `ISSI_TIMEOUT` | (Optional) How long to wait for i2c messages, in milliseconds | 100 |
84| `ISSI_PERSISTENCE` | (Optional) Retry failed messages this many times | 0 |
85| `DRIVER_COUNT` | (Required) How many RGB driver IC's are present | |
86| `DRIVER_LED_TOTAL` | (Required) How many RGB lights are present across all drivers | |
87| `DRIVER_ADDR_1` | (Required) Address for the first RGB driver | |
88| `DRIVER_ADDR_2` | (Optional) Address for the second RGB driver | |
89| `DRIVER_ADDR_3` | (Optional) Address for the third RGB driver | |
90| `DRIVER_ADDR_4` | (Optional) Address for the fourth RGB driver | |
91| `DRIVER_SYNC_1` | (Optional) Sync configuration for the first RGB driver | 0 |
92| `DRIVER_SYNC_2` | (Optional) Sync configuration for the second RGB driver | 0 |
93| `DRIVER_SYNC_3` | (Optional) Sync configuration for the third RGB driver | 0 |
94| `DRIVER_SYNC_4` | (Optional) Sync configuration for the fourth RGB driver | 0 |
95
96Here is an example using 2 drivers.
71 97
72```c 98```c
73// This is a 7-bit address, that gets left-shifted and bit 0 99// This is a 7-bit address, that gets left-shifted and bit 0
@@ -81,6 +107,58 @@ Configure the hardware via your `config.h`:
81// ADDR2 represents A3:A2 of the 7-bit address. 107// ADDR2 represents A3:A2 of the 7-bit address.
82// The result is: 0b101(ADDR2)(ADDR1) 108// The result is: 0b101(ADDR2)(ADDR1)
83#define DRIVER_ADDR_1 0b1010000 109#define DRIVER_ADDR_1 0b1010000
110#define DRIVER_ADDR_2 0b1010011
111
112#define DRIVER_COUNT 2
113#define DRIVER_1_LED_TOTAL 58
114#define DRIVER_2_LED_TOTAL 10
115#define DRIVER_LED_TOTAL (DRIVER_1_LED_TOTAL + DRIVER_2_LED_TOTAL)
116```
117
118!> 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`.
119
120Currently only 4 drivers are supported, but it would be trivial to support all 8 combinations.
121
122Define these arrays listing all the LEDs in your `<keyboard>.c`:
123
124```c
125const is31_led g_is31_leds[DRIVER_LED_TOTAL] = {
126/* Refer to IS31 manual for these locations
127 * driver
128 * | R location
129 * | | G location
130 * | | | B location
131 * | | | | */
132 {0, B_1, A_1, C_1},
133 ....
134}
135```
136
137Where `X_Y` is the location of the LED in the matrix defined by [the datasheet](https://www.issi.com/WW/pdf/31FL3733.pdf) and the header file `drivers/issi/is31fl3733.h`. The `driver` is the index of the driver you defined in your `config.h` (`0`, `1`, `2`, or `3` for now).
138
139---
140### IS31FL3737 :id=is31fl3737
141
142There is basic support for addressable RGB matrix lighting with the I2C IS31FL3737 RGB controller. To enable it, add this to your `rules.mk`:
143
144```makefile
145RGB_MATRIX_ENABLE = yes
146RGB_MATRIX_DRIVER = IS31FL3737
147```
148
149Configure the hardware via your `config.h`:
150
151```c
152// This is a 7-bit address, that gets left-shifted and bit 0
153// set to 0 for write, 1 for read (as per I2C protocol)
154// The address will vary depending on your wiring:
155// 0000 <-> GND
156// 0101 <-> SCL
157// 1010 <-> SDA
158// 1111 <-> VCC
159// ADDR represents A3:A0 of the 7-bit address.
160// The result is: 0b101(ADDR)
161#define DRIVER_ADDR_1 0b1010000
84#define DRIVER_ADDR_2 0b1010000 // this is here for compliancy reasons. 162#define DRIVER_ADDR_2 0b1010000 // this is here for compliancy reasons.
85 163
86#define DRIVER_COUNT 2 164#define DRIVER_COUNT 2
@@ -105,7 +183,7 @@ const is31_led g_is31_leds[DRIVER_LED_TOTAL] = {
105} 183}
106``` 184```
107 185
108Where `X_Y` is the location of the LED in the matrix defined by [the datasheet](https://www.issi.com/WW/pdf/31FL3733.pdf) and the header file `drivers/issi/is31fl3733.h`. The `driver` is the index of the driver you defined in your `config.h` (Only `0` right now). 186Where `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).
109 187
110--- 188---
111 189
diff --git a/drivers/issi/is31fl3733.c b/drivers/issi/is31fl3733.c
index dddf0cb73..d99e5339c 100644
--- a/drivers/issi/is31fl3733.c
+++ b/drivers/issi/is31fl3733.c
@@ -68,7 +68,7 @@ uint8_t g_twi_transfer_buffer[20];
68uint8_t g_pwm_buffer[DRIVER_COUNT][192]; 68uint8_t g_pwm_buffer[DRIVER_COUNT][192];
69bool g_pwm_buffer_update_required[DRIVER_COUNT] = {false}; 69bool g_pwm_buffer_update_required[DRIVER_COUNT] = {false};
70 70
71uint8_t g_led_control_registers[DRIVER_COUNT][24] = {{0}, {0}}; 71uint8_t g_led_control_registers[DRIVER_COUNT][24] = {0};
72bool g_led_control_registers_update_required[DRIVER_COUNT] = {false}; 72bool g_led_control_registers_update_required[DRIVER_COUNT] = {false};
73 73
74bool IS31FL3733_write_register(uint8_t addr, uint8_t reg, uint8_t data) { 74bool IS31FL3733_write_register(uint8_t addr, uint8_t reg, uint8_t data) {
diff --git a/quantum/led_matrix_drivers.c b/quantum/led_matrix_drivers.c
index 370c5e685..f3d4bc896 100644
--- a/quantum/led_matrix_drivers.c
+++ b/quantum/led_matrix_drivers.c
@@ -46,16 +46,28 @@ static void init(void) {
46# endif 46# endif
47# else 47# else
48# ifdef LED_DRIVER_ADDR_1 48# ifdef LED_DRIVER_ADDR_1
49 IS31FL3733_init(LED_DRIVER_ADDR_1, 0); 49# ifndef LED_DRIVER_SYNC_1
50# define LED_DRIVER_SYNC_1 0
51# endif
52 IS31FL3733_init(LED_DRIVER_ADDR_1, LED_DRIVER_SYNC_1);
50# endif 53# endif
51# ifdef LED_DRIVER_ADDR_2 54# ifdef LED_DRIVER_ADDR_2
52 IS31FL3733_init(LED_DRIVER_ADDR_2, 0); 55# ifndef LED_DRIVER_SYNC_2
56# define LED_DRIVER_SYNC_2 0
57# endif
58 IS31FL3733_init(LED_DRIVER_ADDR_2, LED_DRIVER_SYNC_2);
53# endif 59# endif
54# ifdef LED_DRIVER_ADDR_3 60# ifdef LED_DRIVER_ADDR_3
55 IS31FL3733_init(LED_DRIVER_ADDR_3, 0); 61# ifndef LED_DRIVER_SYNC_3
62# define LED_DRIVER_SYNC_3 0
63# endif
64 IS31FL3733_init(LED_DRIVER_ADDR_3, LED_DRIVER_SYNC_3);
56# endif 65# endif
57# ifdef LED_DRIVER_ADDR_4 66# ifdef LED_DRIVER_ADDR_4
58 IS31FL3733_init(LED_DRIVER_ADDR_4, 0); 67# ifndef LED_DRIVER_SYNC_4
68# define LED_DRIVER_SYNC_4 0
69# endif
70 IS31FL3733_init(LED_DRIVER_ADDR_4, LED_DRIVER_SYNC_4);
59# endif 71# endif
60# endif 72# endif
61 73
@@ -133,7 +145,7 @@ const led_matrix_driver_t led_matrix_driver = {
133 .set_value = IS31FL3731_set_value, 145 .set_value = IS31FL3731_set_value,
134 .set_value_all = IS31FL3731_set_value_all, 146 .set_value_all = IS31FL3731_set_value_all,
135# else 147# else
136 .set_value = IS31FL3733_set_value, 148 .set_value = IS31FL3733_set_value,
137 .set_value_all = IS31FL3733_set_value_all, 149 .set_value_all = IS31FL3733_set_value_all,
138# endif 150# endif
139}; 151};
diff --git a/quantum/rgb_matrix_drivers.c b/quantum/rgb_matrix_drivers.c
index 2978e7bed..a4db86d19 100644
--- a/quantum/rgb_matrix_drivers.c
+++ b/quantum/rgb_matrix_drivers.c
@@ -41,7 +41,28 @@ static void init(void) {
41 IS31FL3731_init(DRIVER_ADDR_4); 41 IS31FL3731_init(DRIVER_ADDR_4);
42# endif 42# endif
43# elif defined(IS31FL3733) 43# elif defined(IS31FL3733)
44 IS31FL3733_init(DRIVER_ADDR_1, 0); 44# ifndef DRIVER_SYNC_1
45# define DRIVER_SYNC_1 0
46# endif
47 IS31FL3733_init(DRIVER_ADDR_1, DRIVER_SYNC_1);
48# if defined DRIVER_ADDR_2 && (DRIVER_ADDR_1 != DRIVER_ADDR_2)
49# ifndef DRIVER_SYNC_2
50# define DRIVER_SYNC_2 0
51# endif
52 IS31FL3733_init(DRIVER_ADDR_2, DRIVER_SYNC_2);
53# endif
54# ifdef DRIVER_ADDR_3
55# ifndef DRIVER_SYNC_3
56# define DRIVER_SYNC_3 0
57# endif
58 IS31FL3733_init(DRIVER_ADDR_3, DRIVER_SYNC_3);
59# endif
60# ifdef DRIVER_ADDR_4
61# ifndef DRIVER_SYNC_4
62# define DRIVER_SYNC_4 0
63# endif
64 IS31FL3733_init(DRIVER_ADDR_4, DRIVER_SYNC_4);
65# endif
45# elif defined(IS31FL3737) 66# elif defined(IS31FL3737)
46 IS31FL3737_init(DRIVER_ADDR_1); 67 IS31FL3737_init(DRIVER_ADDR_1);
47# else 68# else
@@ -74,7 +95,15 @@ static void init(void) {
74# endif 95# endif
75# elif defined(IS31FL3733) 96# elif defined(IS31FL3733)
76 IS31FL3733_update_led_control_registers(DRIVER_ADDR_1, 0); 97 IS31FL3733_update_led_control_registers(DRIVER_ADDR_1, 0);
98# ifdef DRIVER_ADDR_2
77 IS31FL3733_update_led_control_registers(DRIVER_ADDR_2, 1); 99 IS31FL3733_update_led_control_registers(DRIVER_ADDR_2, 1);
100# endif
101# ifdef DRIVER_ADDR_3
102 IS31FL3733_update_led_control_registers(DRIVER_ADDR_3, 2);
103# endif
104# ifdef DRIVER_ADDR_4
105 IS31FL3733_update_led_control_registers(DRIVER_ADDR_4, 3);
106# endif
78# elif defined(IS31FL3737) 107# elif defined(IS31FL3737)
79 IS31FL3737_update_led_control_registers(DRIVER_ADDR_1, DRIVER_ADDR_2); 108 IS31FL3737_update_led_control_registers(DRIVER_ADDR_1, DRIVER_ADDR_2);
80# else 109# else
@@ -105,13 +134,21 @@ const rgb_matrix_driver_t rgb_matrix_driver = {
105# elif defined(IS31FL3733) 134# elif defined(IS31FL3733)
106static void flush(void) { 135static void flush(void) {
107 IS31FL3733_update_pwm_buffers(DRIVER_ADDR_1, 0); 136 IS31FL3733_update_pwm_buffers(DRIVER_ADDR_1, 0);
137# ifdef DRIVER_ADDR_2
108 IS31FL3733_update_pwm_buffers(DRIVER_ADDR_2, 1); 138 IS31FL3733_update_pwm_buffers(DRIVER_ADDR_2, 1);
139# endif
140# ifdef DRIVER_ADDR_3
141 IS31FL3733_update_pwm_buffers(DRIVER_ADDR_3, 2);
142# endif
143# ifdef DRIVER_ADDR_4
144 IS31FL3733_update_pwm_buffers(DRIVER_ADDR_4, 3);
145# endif
109} 146}
110 147
111const rgb_matrix_driver_t rgb_matrix_driver = { 148const rgb_matrix_driver_t rgb_matrix_driver = {
112 .init = init, 149 .init = init,
113 .flush = flush, 150 .flush = flush,
114 .set_color = IS31FL3733_set_color, 151 .set_color = IS31FL3733_set_color,
115 .set_color_all = IS31FL3733_set_color_all, 152 .set_color_all = IS31FL3733_set_color_all,
116}; 153};
117# elif defined(IS31FL3737) 154# elif defined(IS31FL3737)