aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRyan <fauxpark@gmail.com>2021-02-14 12:15:08 +1100
committerGitHub <noreply@github.com>2021-02-14 12:15:08 +1100
commit7ce5ba645abcbf3d859a418d4456a1cc80c73e64 (patch)
tree32de70337d61f36be88d142314a78ba6e8df6300
parentde8caf708c1a9a80527a04be620ed3969262e50b (diff)
downloadqmk_firmware-7ce5ba645abcbf3d859a418d4456a1cc80c73e64.tar.gz
qmk_firmware-7ce5ba645abcbf3d859a418d4456a1cc80c73e64.zip
LED Matrix: add led_matrix_types.h and implement g_led_config (#11741)
* LED Matrix: add led_matrix_types.h and implement g_led_config * Set correct flags for non-"modifier" LEDs * Clean up docs a little * Add license headers for [led,rgb]_matrix_types.h
-rw-r--r--docs/feature_led_matrix.md85
-rw-r--r--keyboards/clueboard/66_hotswap/gen1/gen1.c257
-rw-r--r--quantum/led_matrix.c132
-rw-r--r--quantum/led_matrix.h42
-rw-r--r--quantum/led_matrix_types.h69
-rw-r--r--quantum/rgb_matrix_types.h16
6 files changed, 302 insertions, 299 deletions
diff --git a/docs/feature_led_matrix.md b/docs/feature_led_matrix.md
index 1383c97b4..6de01f31a 100644
--- a/docs/feature_led_matrix.md
+++ b/docs/feature_led_matrix.md
@@ -10,9 +10,11 @@ If you want to use RGB LED's you should use the [RGB Matrix Subsystem](feature_r
10 10
11There is basic support for addressable LED matrix lighting with the I2C IS31FL3731 RGB controller. To enable it, add this to your `rules.mk`: 11There is basic support for addressable LED matrix lighting with the I2C IS31FL3731 RGB controller. To enable it, add this to your `rules.mk`:
12 12
13 LED_MATRIX_ENABLE = yes 13```make
14 LED_MATRIX_DRIVER = IS31FL3731 14LED_MATRIX_ENABLE = yes
15 15LED_MATRIX_DRIVER = IS31FL3731
16```
17
16You 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`: 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`:
17 19
18| Variable | Description | Default | 20| Variable | Description | Default |
@@ -28,33 +30,38 @@ You can use between 1 and 4 IS31FL3731 IC's. Do not specify `LED_DRIVER_ADDR_<N>
28 30
29Here is an example using 2 drivers. 31Here is an example using 2 drivers.
30 32
31 // This is a 7-bit address, that gets left-shifted and bit 0 33```c
32 // set to 0 for write, 1 for read (as per I2C protocol) 34// This is a 7-bit address, that gets left-shifted and bit 0
33 // The address will vary depending on your wiring: 35// set to 0 for write, 1 for read (as per I2C protocol)
34 // 0b1110100 AD <-> GND 36// The address will vary depending on your wiring:
35 // 0b1110111 AD <-> VCC 37// 0b1110100 AD <-> GND
36 // 0b1110101 AD <-> SCL 38// 0b1110111 AD <-> VCC
37 // 0b1110110 AD <-> SDA 39// 0b1110101 AD <-> SCL
38 #define LED_DRIVER_ADDR_1 0b1110100 40// 0b1110110 AD <-> SDA
39 #define LED_DRIVER_ADDR_2 0b1110110 41#define LED_DRIVER_ADDR_1 0b1110100
40 42#define LED_DRIVER_ADDR_2 0b1110110
41 #define LED_DRIVER_COUNT 2 43
42 #define LED_DRIVER_1_LED_COUNT 25 44#define LED_DRIVER_COUNT 2
43 #define LED_DRIVER_2_LED_COUNT 24 45#define LED_DRIVER_1_LED_COUNT 25
44 #define LED_DRIVER_LED_COUNT LED_DRIVER_1_LED_TOTAL + LED_DRIVER_2_LED_TOTAL 46#define LED_DRIVER_2_LED_COUNT 24
47#define LED_DRIVER_LED_COUNT LED_DRIVER_1_LED_TOTAL + LED_DRIVER_2_LED_TOTAL
48```
45 49
46Currently only 2 drivers are supported, but it would be trivial to support all 4 combinations. 50Currently only 2 drivers are supported, but it would be trivial to support all 4 combinations.
47 51
48Define these arrays listing all the LEDs in your `<keyboard>.c`: 52Define these arrays listing all the LEDs in your `<keyboard>.c`:
49 53
50 const is31_led g_is31_leds[DRIVER_LED_TOTAL] = { 54```c
51 /* Refer to IS31 manual for these locations 55 const is31_led g_is31_leds[DRIVER_LED_TOTAL] = {
52 * driver 56 /* Refer to IS31 manual for these locations
53 * | LED address 57 * driver
54 * | | */ 58 * | LED address
55 {0, C3_3}, 59 * | | */
56 .... 60 { 0, C1_1 },
57 } 61 { 0, C1_15 },
62 // ...
63 }
64```
58 65
59Where `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-simple.h`. The `driver` is the index of the driver you defined in your `config.h` (`0`, `1`, `2`, or `3` ). 66Where `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-simple.h`. The `driver` is the index of the driver you defined in your `config.h` (`0`, `1`, `2`, or `3` ).
60 67
@@ -66,26 +73,28 @@ All LED matrix keycodes are currently shared with the [backlight system](feature
66 73
67Currently no LED matrix effects have been created. 74Currently no LED matrix effects have been created.
68 75
69## Custom layer effects 76## Custom Layer Effects
70 77
71Custom layer effects can be done by defining this in your `<keyboard>.c`: 78Custom layer effects can be done by defining this in your `<keyboard>.c`:
72 79
73 void led_matrix_indicators_kb(void) { 80```c
74 led_matrix_set_index_value(index, value); 81void led_matrix_indicators_kb(void) {
75 } 82 led_matrix_set_index_value(index, value);
83}
84```
76 85
77A similar function works in the keymap as `led_matrix_indicators_user`. 86A similar function works in the keymap as `led_matrix_indicators_user`.
78 87
79## Suspended state 88## Suspended State
80 89
81To use the suspend feature, add this to your `<keyboard>.c`: 90To use the suspend feature, add this to your `<keyboard>.c`:
82 91
83 void suspend_power_down_kb(void) 92```c
84 { 93void suspend_power_down_kb(void) {
85 led_matrix_set_suspend_state(true); 94 led_matrix_set_suspend_state(true);
86 } 95}
87 96
88 void suspend_wakeup_init_kb(void) 97void suspend_wakeup_init_kb(void) {
89 { 98 led_matrix_set_suspend_state(false);
90 led_matrix_set_suspend_state(false); 99}
91 } 100``` \ No newline at end of file
diff --git a/keyboards/clueboard/66_hotswap/gen1/gen1.c b/keyboards/clueboard/66_hotswap/gen1/gen1.c
index 3bcf74faa..4bee38dc4 100644
--- a/keyboards/clueboard/66_hotswap/gen1/gen1.c
+++ b/keyboards/clueboard/66_hotswap/gen1/gen1.c
@@ -20,162 +20,109 @@
20 20
21const is31_led g_is31_leds[LED_DRIVER_LED_COUNT] = { 21const is31_led g_is31_leds[LED_DRIVER_LED_COUNT] = {
22/* Refer to IS31 manual for these locations 22/* Refer to IS31 manual for these locations
23 * driver 23 * driver
24 * | LED address 24 * | LED address
25 * | | */ 25 * | | */
26 {0, C1_1}, // k00 KC_GESC 26 { 0, C1_1 }, // k00 KC_GESC
27 {0, C1_2}, // k01 KC_1 27 { 0, C1_2 }, // k01 KC_1
28 {0, C1_3}, // k02 KC_2 28 { 0, C1_3 }, // k02 KC_2
29 {0, C1_4}, // k03 KC_3 29 { 0, C1_4 }, // k03 KC_3
30 {0, C1_5}, // k04 KC_4 30 { 0, C1_5 }, // k04 KC_4
31 {0, C1_6}, // k05 KC_5 31 { 0, C1_6 }, // k05 KC_5
32 {0, C1_7}, // k06 KC_6 32 { 0, C1_7 }, // k06 KC_6
33 {0, C1_8}, // k07 KC_7 33 { 0, C1_8 }, // k07 KC_7
34 {0, C1_9}, // k50 KC_8 34 { 0, C1_9 }, // k50 KC_8
35 {0, C1_10}, // k51 KC_9 35 { 0, C1_10 }, // k51 KC_9
36 {0, C1_11}, // k52 KC_0 36 { 0, C1_11 }, // k52 KC_0
37 {0, C1_12}, // k53 KC_MINS 37 { 0, C1_12 }, // k53 KC_MINS
38 {0, C1_13}, // k54 KC_EQL 38 { 0, C1_13 }, // k54 KC_EQL
39 {0, C1_14}, // k55 KC_BSPC 39 { 0, C1_14 }, // k55 KC_BSPC
40 {0, C1_15}, // k57 KC_PGUP 40 { 0, C1_15 }, // k57 KC_PGUP
41 {0, C2_1}, // k10 KC_TAB 41 { 0, C2_1 }, // k10 KC_TAB
42 {0, C2_2}, // k11 KC_Q 42 { 0, C2_2 }, // k11 KC_Q
43 {0, C2_3}, // k12 KC_W 43 { 0, C2_3 }, // k12 KC_W
44 {0, C2_4}, // k13 KC_E 44 { 0, C2_4 }, // k13 KC_E
45 {0, C2_5}, // k14 KC_R 45 { 0, C2_5 }, // k14 KC_R
46 {0, C2_6}, // k15 KC_T 46 { 0, C2_6 }, // k15 KC_T
47 {0, C2_7}, // k16 KC_Y 47 { 0, C2_7 }, // k16 KC_Y
48 {0, C2_8}, // k17 KC_U 48 { 0, C2_8 }, // k17 KC_U
49 {0, C2_9}, // k60 KC_I 49 { 0, C2_9 }, // k60 KC_I
50 {0, C2_10}, // k61 KC_O 50 { 0, C2_10 }, // k61 KC_O
51 {0, C2_11}, // k62 KC_P 51 { 0, C2_11 }, // k62 KC_P
52 {0, C2_12}, // k63 KC_LBRC 52 { 0, C2_12 }, // k63 KC_LBRC
53 {0, C2_13}, // k64 KC_RBRC 53 { 0, C2_13 }, // k64 KC_RBRC
54 {0, C2_14}, // k65 KC_BSLS 54 { 0, C2_14 }, // k65 KC_BSLS
55 {0, C2_15}, // k67 KC_PGDN 55 { 0, C2_15 }, // k67 KC_PGDN
56 {0, C3_1}, // k20 KC_CAPS 56 { 0, C3_1 }, // k20 KC_CAPS
57 {0, C3_2}, // k21 KC_A 57 { 0, C3_2 }, // k21 KC_A
58 {0, C3_3}, // k22 KC_S 58 { 0, C3_3 }, // k22 KC_S
59 {0, C3_4}, // k23 KC_D 59 { 0, C3_4 }, // k23 KC_D
60 {0, C3_5}, // k24 KC_F 60 { 0, C3_5 }, // k24 KC_F
61 {0, C3_6}, // k25 KC_G 61 { 0, C3_6 }, // k25 KC_G
62 {0, C3_7}, // k26 KC_H 62 { 0, C3_7 }, // k26 KC_H
63 {0, C3_8}, // k27 KC_J 63 { 0, C3_8 }, // k27 KC_J
64 {0, C3_9}, // k70 KC_K 64 { 0, C3_9 }, // k70 KC_K
65 {0, C3_10}, // k71 KC_L 65 { 0, C3_10 }, // k71 KC_L
66 {0, C3_11}, // k72 KC_SCLN 66 { 0, C3_11 }, // k72 KC_SCLN
67 {0, C3_12}, // k73 KC_QUOT 67 { 0, C3_12 }, // k73 KC_QUOT
68 {0, C3_14}, // k75 KC_ENT 68 { 0, C3_14 }, // k75 KC_ENT
69 {0, C4_1}, // k30 KC_LSFT 69 { 0, C4_1 }, // k30 KC_LSFT
70 {0, C4_3}, // k32 KC_Z 70 { 0, C4_3 }, // k32 KC_Z
71 {0, C4_4}, // k33 KC_X 71 { 0, C4_4 }, // k33 KC_X
72 {0, C4_5}, // k34 KC_C 72 { 0, C4_5 }, // k34 KC_C
73 {0, C4_6}, // k35 KC_V 73 { 0, C4_6 }, // k35 KC_V
74 {0, C4_7}, // k36 KC_B 74 { 0, C4_7 }, // k36 KC_B
75 {0, C4_8}, // k37 KC_N 75 { 0, C4_8 }, // k37 KC_N
76 {0, C4_9}, // k80 KC_M 76 { 0, C4_9 }, // k80 KC_M
77 {0, C4_10}, // k81 KC_COMM 77 { 0, C4_10 }, // k81 KC_COMM
78 {0, C4_11}, // k82 KC_DOT 78 { 0, C4_11 }, // k82 KC_DOT
79 {0, C4_12}, // k83 KC_SLSH 79 { 0, C4_12 }, // k83 KC_SLSH
80 {0, C4_13}, // k85 KC_RSFT 80 { 0, C4_13 }, // k85 KC_RSFT
81 {0, C4_14}, // k86 KC_UP 81 { 0, C4_14 }, // k86 KC_UP
82 {0, C5_1}, // k40 KC_LCTL 82 { 0, C5_1 }, // k40 KC_LCTL
83 {0, C5_2}, // k41 KC_LGUI 83 { 0, C5_2 }, // k41 KC_LGUI
84 {0, C5_3}, // k42 KC_LALT 84 { 0, C5_3 }, // k42 KC_LALT
85 {0, C5_4}, // Unassociated between LALT and SPACE_2.75 85 { 0, C5_4 }, // Unassociated between LALT and SPACE_2.75
86 {0, C5_5}, // k45 KC_SPC SPACE_2.75 86 { 0, C5_5 }, // k45 KC_SPC SPACE_2.75
87 {0, C5_6}, // k45 KC_SPC SPACE_6.75 87 { 0, C5_6 }, // k45 KC_SPC SPACE_6.75
88 {0, C5_7}, // k46 KC_SPC SPACE_2.25 88 { 0, C5_7 }, // k46 KC_SPC SPACE_2.25
89 {0, C5_8}, // Unassociated between SPACE_2.25 and SPACE_1.25 89 { 0, C5_8 }, // Unassociated between SPACE_2.25 and SPACE_1.25
90 {0, C5_9}, // k90 KC_RGUI 90 { 0, C5_9 }, // k90 KC_RGUI
91 {0, C5_10}, // k92 KC_RALT 91 { 0, C5_10 }, // k92 KC_RALT
92 {0, C5_11}, // k93 MO(_FL) 92 { 0, C5_11 }, // k93 MO(_FL)
93 {0, C5_12}, // k94 KC_RCTL 93 { 0, C5_12 }, // k94 KC_RCTL
94 {0, C5_13}, // k95 KC_LEFT 94 { 0, C5_13 }, // k95 KC_LEFT
95 {0, C5_14}, // k96 KC_DOWN 95 { 0, C5_14 }, // k96 KC_DOWN
96 {0, C5_15} // k97 KC_RGHT 96 { 0, C5_15 } // k97 KC_RGHT
97}; 97};
98 98
99const led_matrix g_leds[LED_DRIVER_LED_COUNT] = { 99led_config_t g_led_config = {
100 100 {
101 /*{row | col << 4} 101 // Key Matrix to LED Index
102 | LED_ROW_COL(row, col) 102 { 0, 1, 2, 3, 4, 5, 6, 7 },
103 | | modifier 103 { 15, 16, 17, 18, 19, 20, 21, 22 },
104 | | | */ 104 { 30, 31, 32, 33, 34, 35, 36, 37 },
105 {{0|(1<<4)}, {0, 0}, 1}, // k00 KC_GESC 105 { 43, NO_LED, 44, 45, 46, 47, 48, 49 },
106 {{0|(2<<4)}, {14.45, 0}, 0}, // k01 KC_1 106 { 56, 57, 58, NO_LED, NO_LED, 60, 61, NO_LED },
107 {{0|(3<<4)}, {28.9, 0}, 0}, // k02 KC_2 107 { 8, 9, 10, 11, 12, 13, NO_LED, 14 },
108 {{0|(4<<4)}, {43.35, 0}, 0}, // k03 KC_3 108 { 23, 24, 25, 26, 27, 28, NO_LED, 29 },
109 {{0|(5<<4)}, {57.8, 0}, 0}, // k04 KC_4 109 { 38, 39, 40, 41, NO_LED, 42, NO_LED, NO_LED },
110 {{0|(6<<4)}, {72.25, 0}, 0}, // k05 KC_5 110 { 50, 51, 52, 53, NO_LED, 54, 55, NO_LED },
111 {{0|(7<<4)}, {86.7, 0}, 0}, // k06 KC_6 111 { 64, NO_LED, 65, 66, 67, 68, 69, 70 }
112 {{0|(8<<4)}, {101.2, 0}, 0}, // k07 KC_7 112 }, {
113 {{0|(9<<4)}, {115.6, 0}, 0}, // k50 KC_8 113 // LED Index to Physical Position
114 {{0|(10<<4)}, {130, 0}, 0}, // k51 KC_9 114 { 0, 0 }, { 15, 0 }, { 29, 0 }, { 43, 0 }, { 58, 0 }, { 72, 0 }, { 87, 0 }, { 101, 0 }, { 116, 0 }, { 130, 0 }, { 145, 0 }, { 159, 0 }, { 173, 0 }, { 195, 0 }, { 224, 0 },
115 {{0|(11<<4)}, {144.5, 0}, 0}, // k52 KC_0 115 { 4, 16 }, { 22, 16 }, { 36, 16 }, { 51, 16 }, { 65, 16 }, { 80, 16 }, { 94, 16 }, { 108, 16 }, { 123, 16 }, { 137, 16 }, { 152, 16 }, { 166, 16 }, { 181, 16 }, { 199, 16 }, { 224, 16 },
116 {{0|(12<<4)}, {159, 0}, 0}, // k53 KC_MINS 116 { 5, 32 }, { 25, 32 }, { 40, 32 }, { 54, 32 }, { 69, 32 }, { 83, 32 }, { 98, 32 }, { 112, 32 }, { 126, 32 }, { 141, 32 }, { 155, 32 }, { 170, 32 }, { 184, 32 },
117 {{0|(13<<4)}, {173.4, 0}, 0}, // k54 KC_EQL 117 { 16, 48 }, { 33, 48 }, { 47, 48 }, { 61, 48 }, { 76, 48 }, { 90, 48 }, { 105, 48 }, { 119, 48 }, { 134, 48 }, { 148, 48 }, { 163, 48 }, { 188, 48 }, { 210, 48 },
118 {{0|(14<<4)}, {195.1, 0}, 1}, // k55 KC_BSPC 118 { 9, 64 }, { 27, 64 }, { 45, 64 }, { 60, 64 }, { 74, 64 }, { 88, 64 }, { 103, 64 }, { 117, 64 }, { 136, 64 }, { 154, 64 }, { 168, 64 }, { 186, 64 }, { 195, 64 }, { 210, 64 }, { 224, 64 }
119 {{0|(15<<4)}, {224, 0}, 1}, // k57 KC_PGUP 119 }, {
120 120 // LED Index to Flag
121 {{1|(0<<4)}, {3.6125, 16}, 1}, // k10 KC_TAB 121 1, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 1, 1,
122 {{1|(1<<4)}, {21.675, 16}, 0}, // k11 KC_Q 122 1, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 1, 1,
123 {{1|(2<<4)}, {36.125, 16}, 0}, // k12 KC_W 123 1, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 1,
124 {{1|(3<<4)}, {50.575, 16}, 0}, // k13 KC_E 124 1, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 1, 1,
125 {{1|(4<<4)}, {65.025, 16}, 0}, // k14 KC_R 125 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
126 {{1|(5<<4)}, {79.475, 16}, 0}, // k15 KC_T 126 }
127 {{1|(6<<4)}, {93.925, 16}, 0}, // k16 KC_Y
128 {{1|(7<<4)}, {108.375, 16}, 0}, // k17 KC_U
129 {{1|(8<<4)}, {122.825, 16}, 0}, // k60 KC_I
130 {{1|(9<<4)}, {137.275, 16}, 0}, // k61 KC_O
131 {{1|(10<<4)}, {151.725, 16}, 0}, // k62 KC_P
132 {{1|(11<<4)}, {166.175, 16}, 0}, // k63 KC_LBRC
133 {{1|(12<<4)}, {180.625, 16}, 0}, // k64 KC_RBRC
134 {{1|(13<<4)}, {198.6875, 16}, 1}, // k65 KC_BSLS
135 {{1|(14<<4)}, {224, 16}, 1}, // k67 KC_PGDN
136
137 {{2|(0<<4)}, {5.41875, 32}, 1}, // k20 KC_CAPS
138 {{2|(1<<4)}, {25.2875, 32}, 0}, // k21 KC_A
139 {{2|(2<<4)}, {39.7375, 32}, 0}, // k22 KC_S
140 {{2|(3<<4)}, {54.1875, 32}, 0}, // k23 KC_D
141 {{2|(4<<4)}, {68.6375, 32}, 0}, // k24 KC_F
142 {{2|(5<<4)}, {83.0875, 32}, 0}, // k25 KC_G
143 {{2|(6<<4)}, {97.5375, 32}, 0}, // k26 KC_H
144 {{2|(7<<4)}, {111.9875, 32}, 0}, // k27 KC_J
145 {{2|(8<<4)}, {126.4375, 32}, 0}, // k70 KC_K
146 {{2|(9<<4)}, {140.8875, 32}, 0}, // k71 KC_L
147 {{2|(10<<4)}, {155.3375, 32}, 0}, // k72 KC_SCLN
148 {{2|(11<<4)}, {169.7875, 32}, 0}, // k73 KC_QUOT
149 {{2|(12<<4)}, {184.2375, 32}, 1}, // k75 KC_ENT
150
151 {{3|(0<<4)}, {16.25625, 48}, 1}, // k30 KC_LSFT
152 {{3|(1<<4)}, {32.5125, 48}, 0}, // k32 KC_Z
153 {{3|(2<<4)}, {46.9625, 48}, 0}, // k33 KC_X
154 {{3|(3<<4)}, {61.4125, 48}, 0}, // k34 KC_C
155 {{3|(4<<4)}, {75.8625, 48}, 0}, // k35 KC_V
156 {{3|(5<<4)}, {90.3125, 48}, 0}, // k36 KC_B
157 {{3|(6<<4)}, {104.7625, 48}, 0}, // k37 KC_N
158 {{3|(7<<4)}, {119.2125, 48}, 0}, // k80 KC_M
159 {{3|(8<<4)}, {133.6625, 48}, 0}, // k81 KC_COMM
160 {{3|(9<<4)}, {148.1125, 48}, 0}, // k82 KC_DOT
161 {{3|(10<<4)}, {162.5625, 48}, 0}, // k83 KC_SLSH
162 {{3|(11<<4)}, {187.85, 48}, 1}, // k85 KC_RSFT
163 {{3|(12<<4)}, {209.525, 48}, 1}, // k86 KC_UP
164
165 {{4|(0<<4)}, {9.03125, 64}, 1}, // k40 KC_LCTL
166 {{4|(1<<4)}, {27.09375, 64}, 1}, // k41 KC_LGUI
167 {{4|(2<<4)}, {45.15625, 64}, 1}, // k42 KC_LALT
168 {{4|(3<<4)}, {59.45, 64}, 1}, // Unassociated between LALT and SPACE_2.75
169 {{4|(4<<4)}, {73.9, 64}, 1}, // k45 KC_SPC SPACE_2.75
170 {{4|(5<<4)}, {88.35, 64}, 1}, // k45 KC_SPC SPACE_6.25
171 {{4|(6<<4)}, {102.8, 64}, 1}, // k46 KC_SPC SPACE_2.25
172 {{4|(7<<4)}, {117.40625, 64}, 1}, // Unassociated between SPACE_2.25 and SPACE_2.75
173 {{4|(8<<4)}, {135.46875, 64}, 1}, // k90 KC_RGUI
174 {{4|(9<<4)}, {153.53125, 64}, 1}, // k92 KC_RALT
175 {{4|(10<<4)}, {167.98125, 64}, 1}, // k93 MO(_FL)
176 {{4|(11<<4)}, {186.04375, 64}, 1}, // k94 KC_RCTL
177 {{4|(12<<4)}, {195.075, 64}, 1}, // k95 KC_LEFT
178 {{4|(13<<4)}, {209.525, 64}, 1}, // k96 KC_DOWN
179 {{4|(14<<4)}, {224, 64}, 1} // k97 KC_RGHT
180}; 127};
181#endif 128#endif
diff --git a/quantum/led_matrix.c b/quantum/led_matrix.c
index eb523990a..c3538e94d 100644
--- a/quantum/led_matrix.c
+++ b/quantum/led_matrix.c
@@ -27,7 +27,7 @@
27#include <string.h> 27#include <string.h>
28#include <math.h> 28#include <math.h>
29 29
30led_config_t led_matrix_config; 30led_eeconfig_t led_matrix_eeconfig;
31 31
32#ifndef MAX 32#ifndef MAX
33# define MAX(X, Y) ((X) > (Y) ? (X) : (Y)) 33# define MAX(X, Y) ((X) > (Y) ? (X) : (Y))
@@ -70,40 +70,32 @@ void eeconfig_update_led_matrix(uint32_t config_value) { eeprom_update_dword(EEC
70 70
71void eeconfig_update_led_matrix_default(void) { 71void eeconfig_update_led_matrix_default(void) {
72 dprintf("eeconfig_update_led_matrix_default\n"); 72 dprintf("eeconfig_update_led_matrix_default\n");
73 led_matrix_config.enable = 1; 73 led_matrix_eeconfig.enable = 1;
74 led_matrix_config.mode = LED_MATRIX_UNIFORM_BRIGHTNESS; 74 led_matrix_eeconfig.mode = LED_MATRIX_UNIFORM_BRIGHTNESS;
75 led_matrix_config.val = 128; 75 led_matrix_eeconfig.val = 128;
76 led_matrix_config.speed = 0; 76 led_matrix_eeconfig.speed = 0;
77 eeconfig_update_led_matrix(led_matrix_config.raw); 77 eeconfig_update_led_matrix(led_matrix_eeconfig.raw);
78} 78}
79 79
80void eeconfig_debug_led_matrix(void) { 80void eeconfig_debug_led_matrix(void) {
81 dprintf("led_matrix_config eeprom\n"); 81 dprintf("led_matrix_eeconfig eeprom\n");
82 dprintf("led_matrix_config.enable = %d\n", led_matrix_config.enable); 82 dprintf("led_matrix_eeconfig.enable = %d\n", led_matrix_eeconfig.enable);
83 dprintf("led_matrix_config.mode = %d\n", led_matrix_config.mode); 83 dprintf("led_matrix_eeconfig.mode = %d\n", led_matrix_eeconfig.mode);
84 dprintf("led_matrix_config.val = %d\n", led_matrix_config.val); 84 dprintf("led_matrix_eeconfig.val = %d\n", led_matrix_eeconfig.val);
85 dprintf("led_matrix_config.speed = %d\n", led_matrix_config.speed); 85 dprintf("led_matrix_eeconfig.speed = %d\n", led_matrix_eeconfig.speed);
86} 86}
87 87
88// Last led hit
89#ifndef LED_HITS_TO_REMEMBER
90# define LED_HITS_TO_REMEMBER 8
91#endif
92uint8_t g_last_led_hit[LED_HITS_TO_REMEMBER] = {255}; 88uint8_t g_last_led_hit[LED_HITS_TO_REMEMBER] = {255};
93uint8_t g_last_led_count = 0; 89uint8_t g_last_led_count = 0;
94 90
95void map_row_column_to_led(uint8_t row, uint8_t column, uint8_t *led_i, uint8_t *led_count) { 91uint8_t map_row_column_to_led(uint8_t row, uint8_t column, uint8_t *led_i) {
96 led_matrix led; 92 uint8_t led_count = 0;
97 *led_count = 0; 93 uint8_t led_index = g_led_config.matrix_co[row][column];
98 94 if (led_index != NO_LED) {
99 for (uint8_t i = 0; i < LED_DRIVER_LED_COUNT; i++) { 95 led_i[led_count] = led_index;
100 // map_index_to_led(i, &led); 96 led_count++;
101 led = g_leds[i];
102 if (row == led.matrix_co.row && column == led.matrix_co.col) {
103 led_i[*led_count] = i;
104 (*led_count)++;
105 }
106 } 97 }
98 return led_count;
107} 99}
108 100
109void led_matrix_update_pwm_buffers(void) { led_matrix_driver.flush(); } 101void led_matrix_update_pwm_buffers(void) { led_matrix_driver.flush(); }
@@ -114,8 +106,8 @@ void led_matrix_set_index_value_all(uint8_t value) { led_matrix_driver.set_value
114 106
115bool process_led_matrix(uint16_t keycode, keyrecord_t *record) { 107bool process_led_matrix(uint16_t keycode, keyrecord_t *record) {
116 if (record->event.pressed) { 108 if (record->event.pressed) {
117 uint8_t led[8], led_count; 109 uint8_t led[8];
118 map_row_column_to_led(record->event.key.row, record->event.key.col, led, &led_count); 110 uint8_t led_count = map_row_column_to_led(record->event.key.row, record->event.key.col, led);
119 if (led_count > 0) { 111 if (led_count > 0) {
120 for (uint8_t i = LED_HITS_TO_REMEMBER; i > 1; i--) { 112 for (uint8_t i = LED_HITS_TO_REMEMBER; i > 1; i--) {
121 g_last_led_hit[i - 1] = g_last_led_hit[i - 2]; 113 g_last_led_hit[i - 1] = g_last_led_hit[i - 2];
@@ -127,8 +119,8 @@ bool process_led_matrix(uint16_t keycode, keyrecord_t *record) {
127 g_any_key_hit = 0; 119 g_any_key_hit = 0;
128 } else { 120 } else {
129#ifdef LED_MATRIX_KEYRELEASES 121#ifdef LED_MATRIX_KEYRELEASES
130 uint8_t led[8], led_count; 122 uint8_t led[8];
131 map_row_column_to_led(record->event.key.row, record->event.key.col, led, &led_count); 123 uint8_t led_count = map_row_column_to_led(record->event.key.row, record->event.key.col, led);
132 for (uint8_t i = 0; i < led_count; i++) g_key_hit[led[i]] = 255; 124 for (uint8_t i = 0; i < led_count; i++) g_key_hit[led[i]] = 255;
133 125
134 g_any_key_hit = 255; 126 g_any_key_hit = 255;
@@ -143,12 +135,12 @@ void led_matrix_set_suspend_state(bool state) { g_suspend_state = state; }
143void led_matrix_all_off(void) { led_matrix_set_index_value_all(0); } 135void led_matrix_all_off(void) { led_matrix_set_index_value_all(0); }
144 136
145// Uniform brightness 137// Uniform brightness
146void led_matrix_uniform_brightness(void) { led_matrix_set_index_value_all(LED_MATRIX_MAXIMUM_BRIGHTNESS / BACKLIGHT_LEVELS * led_matrix_config.val); } 138void led_matrix_uniform_brightness(void) { led_matrix_set_index_value_all(LED_MATRIX_MAXIMUM_BRIGHTNESS / BACKLIGHT_LEVELS * led_matrix_eeconfig.val); }
147 139
148void led_matrix_custom(void) {} 140void led_matrix_custom(void) {}
149 141
150void led_matrix_task(void) { 142void led_matrix_task(void) {
151 if (!led_matrix_config.enable) { 143 if (!led_matrix_eeconfig.enable) {
152 led_matrix_all_off(); 144 led_matrix_all_off();
153 led_matrix_indicators(); 145 led_matrix_indicators();
154 return; 146 return;
@@ -170,7 +162,7 @@ void led_matrix_task(void) {
170 // Ideally we would also stop sending zeros to the LED driver PWM buffers 162 // Ideally we would also stop sending zeros to the LED driver PWM buffers
171 // while suspended and just do a software shutdown. This is a cheap hack for now. 163 // while suspended and just do a software shutdown. This is a cheap hack for now.
172 bool suspend_backlight = ((g_suspend_state && LED_DISABLE_WHEN_USB_SUSPENDED) || (LED_DISABLE_AFTER_TIMEOUT > 0 && g_any_key_hit > LED_DISABLE_AFTER_TIMEOUT * 60 * 20)); 164 bool suspend_backlight = ((g_suspend_state && LED_DISABLE_WHEN_USB_SUSPENDED) || (LED_DISABLE_AFTER_TIMEOUT > 0 && g_any_key_hit > LED_DISABLE_AFTER_TIMEOUT * 60 * 20));
173 uint8_t effect = suspend_backlight ? 0 : led_matrix_config.mode; 165 uint8_t effect = suspend_backlight ? 0 : led_matrix_eeconfig.mode;
174 166
175 // this gets ticked at 20 Hz. 167 // this gets ticked at 20 Hz.
176 // each effect can opt to do calculations 168 // each effect can opt to do calculations
@@ -211,8 +203,8 @@ __attribute__((weak)) void led_matrix_indicators_user(void) {}
211// else 203// else
212// { 204// {
213// // This needs updated to something like 205// // This needs updated to something like
214// // uint8_t led[8], led_count; 206// // uint8_t led[8];
215// // map_row_column_to_led(row,column,led,&led_count); 207// // uint8_t led_count = map_row_column_to_led(row, column, led);
216// // for(uint8_t i = 0; i < led_count; i++) 208// // for(uint8_t i = 0; i < led_count; i++)
217// map_row_column_to_led(row, column, index); 209// map_row_column_to_led(row, column, index);
218// } 210// }
@@ -235,12 +227,12 @@ void led_matrix_init(void) {
235 eeconfig_update_led_matrix_default(); 227 eeconfig_update_led_matrix_default();
236 } 228 }
237 229
238 led_matrix_config.raw = eeconfig_read_led_matrix(); 230 led_matrix_eeconfig.raw = eeconfig_read_led_matrix();
239 231
240 if (!led_matrix_config.mode) { 232 if (!led_matrix_eeconfig.mode) {
241 dprintf("led_matrix_init_drivers led_matrix_config.mode = 0. Write default values to EEPROM.\n"); 233 dprintf("led_matrix_init_drivers led_matrix_eeconfig.mode = 0. Write default values to EEPROM.\n");
242 eeconfig_update_led_matrix_default(); 234 eeconfig_update_led_matrix_default();
243 led_matrix_config.raw = eeconfig_read_led_matrix(); 235 led_matrix_eeconfig.raw = eeconfig_read_led_matrix();
244 } 236 }
245 237
246 eeconfig_debug_led_matrix(); // display current eeprom values 238 eeconfig_debug_led_matrix(); // display current eeprom values
@@ -270,8 +262,8 @@ static uint8_t decrement(uint8_t value, uint8_t step, uint8_t min, uint8_t max)
270// } 262// }
271 263
272// void backlight_set_key_value(uint8_t row, uint8_t column, uint8_t value) { 264// void backlight_set_key_value(uint8_t row, uint8_t column, uint8_t value) {
273// uint8_t led[8], led_count; 265// uint8_t led[8];
274// map_row_column_to_led(row,column,led,&led_count); 266// uint8_t led_count = map_row_column_to_led(row, column, led);
275// for(uint8_t i = 0; i < led_count; i++) { 267// for(uint8_t i = 0; i < led_count; i++) {
276// if (led[i] < LED_DRIVER_LED_COUNT) { 268// if (led[i] < LED_DRIVER_LED_COUNT) {
277// void *address = backlight_get_custom_key_value_eeprom_address(led[i]); 269// void *address = backlight_get_custom_key_value_eeprom_address(led[i]);
@@ -283,74 +275,74 @@ static uint8_t decrement(uint8_t value, uint8_t step, uint8_t min, uint8_t max)
283uint32_t led_matrix_get_tick(void) { return g_tick; } 275uint32_t led_matrix_get_tick(void) { return g_tick; }
284 276
285void led_matrix_toggle(void) { 277void led_matrix_toggle(void) {
286 led_matrix_config.enable ^= 1; 278 led_matrix_eeconfig.enable ^= 1;
287 eeconfig_update_led_matrix(led_matrix_config.raw); 279 eeconfig_update_led_matrix(led_matrix_eeconfig.raw);
288} 280}
289 281
290void led_matrix_enable(void) { 282void led_matrix_enable(void) {
291 led_matrix_config.enable = 1; 283 led_matrix_eeconfig.enable = 1;
292 eeconfig_update_led_matrix(led_matrix_config.raw); 284 eeconfig_update_led_matrix(led_matrix_eeconfig.raw);
293} 285}
294 286
295void led_matrix_enable_noeeprom(void) { led_matrix_config.enable = 1; } 287void led_matrix_enable_noeeprom(void) { led_matrix_eeconfig.enable = 1; }
296 288
297void led_matrix_disable(void) { 289void led_matrix_disable(void) {
298 led_matrix_config.enable = 0; 290 led_matrix_eeconfig.enable = 0;
299 eeconfig_update_led_matrix(led_matrix_config.raw); 291 eeconfig_update_led_matrix(led_matrix_eeconfig.raw);
300} 292}
301 293
302void led_matrix_disable_noeeprom(void) { led_matrix_config.enable = 0; } 294void led_matrix_disable_noeeprom(void) { led_matrix_eeconfig.enable = 0; }
303 295
304void led_matrix_step(void) { 296void led_matrix_step(void) {
305 led_matrix_config.mode++; 297 led_matrix_eeconfig.mode++;
306 if (led_matrix_config.mode >= LED_MATRIX_EFFECT_MAX) { 298 if (led_matrix_eeconfig.mode >= LED_MATRIX_EFFECT_MAX) {
307 led_matrix_config.mode = 1; 299 led_matrix_eeconfig.mode = 1;
308 } 300 }
309 eeconfig_update_led_matrix(led_matrix_config.raw); 301 eeconfig_update_led_matrix(led_matrix_eeconfig.raw);
310} 302}
311 303
312void led_matrix_step_reverse(void) { 304void led_matrix_step_reverse(void) {
313 led_matrix_config.mode--; 305 led_matrix_eeconfig.mode--;
314 if (led_matrix_config.mode < 1) { 306 if (led_matrix_eeconfig.mode < 1) {
315 led_matrix_config.mode = LED_MATRIX_EFFECT_MAX - 1; 307 led_matrix_eeconfig.mode = LED_MATRIX_EFFECT_MAX - 1;
316 } 308 }
317 eeconfig_update_led_matrix(led_matrix_config.raw); 309 eeconfig_update_led_matrix(led_matrix_eeconfig.raw);
318} 310}
319 311
320void led_matrix_increase_val(void) { 312void led_matrix_increase_val(void) {
321 led_matrix_config.val = increment(led_matrix_config.val, 8, 0, LED_MATRIX_MAXIMUM_BRIGHTNESS); 313 led_matrix_eeconfig.val = increment(led_matrix_eeconfig.val, 8, 0, LED_MATRIX_MAXIMUM_BRIGHTNESS);
322 eeconfig_update_led_matrix(led_matrix_config.raw); 314 eeconfig_update_led_matrix(led_matrix_eeconfig.raw);
323} 315}
324 316
325void led_matrix_decrease_val(void) { 317void led_matrix_decrease_val(void) {
326 led_matrix_config.val = decrement(led_matrix_config.val, 8, 0, LED_MATRIX_MAXIMUM_BRIGHTNESS); 318 led_matrix_eeconfig.val = decrement(led_matrix_eeconfig.val, 8, 0, LED_MATRIX_MAXIMUM_BRIGHTNESS);
327 eeconfig_update_led_matrix(led_matrix_config.raw); 319 eeconfig_update_led_matrix(led_matrix_eeconfig.raw);
328} 320}
329 321
330void led_matrix_increase_speed(void) { 322void led_matrix_increase_speed(void) {
331 led_matrix_config.speed = increment(led_matrix_config.speed, 1, 0, 3); 323 led_matrix_eeconfig.speed = increment(led_matrix_eeconfig.speed, 1, 0, 3);
332 eeconfig_update_led_matrix(led_matrix_config.raw); // EECONFIG needs to be increased to support this 324 eeconfig_update_led_matrix(led_matrix_eeconfig.raw); // EECONFIG needs to be increased to support this
333} 325}
334 326
335void led_matrix_decrease_speed(void) { 327void led_matrix_decrease_speed(void) {
336 led_matrix_config.speed = decrement(led_matrix_config.speed, 1, 0, 3); 328 led_matrix_eeconfig.speed = decrement(led_matrix_eeconfig.speed, 1, 0, 3);
337 eeconfig_update_led_matrix(led_matrix_config.raw); // EECONFIG needs to be increased to support this 329 eeconfig_update_led_matrix(led_matrix_eeconfig.raw); // EECONFIG needs to be increased to support this
338} 330}
339 331
340void led_matrix_mode(uint8_t mode, bool eeprom_write) { 332void led_matrix_mode(uint8_t mode, bool eeprom_write) {
341 led_matrix_config.mode = mode; 333 led_matrix_eeconfig.mode = mode;
342 if (eeprom_write) { 334 if (eeprom_write) {
343 eeconfig_update_led_matrix(led_matrix_config.raw); 335 eeconfig_update_led_matrix(led_matrix_eeconfig.raw);
344 } 336 }
345} 337}
346 338
347uint8_t led_matrix_get_mode(void) { return led_matrix_config.mode; } 339uint8_t led_matrix_get_mode(void) { return led_matrix_eeconfig.mode; }
348 340
349void led_matrix_set_value_noeeprom(uint8_t val) { led_matrix_config.val = val; } 341void led_matrix_set_value_noeeprom(uint8_t val) { led_matrix_eeconfig.val = val; }
350 342
351void led_matrix_set_value(uint8_t val) { 343void led_matrix_set_value(uint8_t val) {
352 led_matrix_set_value_noeeprom(val); 344 led_matrix_set_value_noeeprom(val);
353 eeconfig_update_led_matrix(led_matrix_config.raw); 345 eeconfig_update_led_matrix(led_matrix_eeconfig.raw);
354} 346}
355 347
356void backlight_set(uint8_t val) { led_matrix_set_value(val); } 348void backlight_set(uint8_t val) { led_matrix_set_value(val); }
diff --git a/quantum/led_matrix.h b/quantum/led_matrix.h
index 7dcdf1d48..85bae43c1 100644
--- a/quantum/led_matrix.h
+++ b/quantum/led_matrix.h
@@ -19,46 +19,12 @@
19 19
20#pragma once 20#pragma once
21 21
22#include "led_matrix_types.h"
23
22#ifndef BACKLIGHT_ENABLE 24#ifndef BACKLIGHT_ENABLE
23# error You must define BACKLIGHT_ENABLE with LED_MATRIX_ENABLE 25# error You must define BACKLIGHT_ENABLE with LED_MATRIX_ENABLE
24#endif 26#endif
25 27
26typedef struct Point {
27 uint8_t x;
28 uint8_t y;
29} __attribute__((packed)) Point;
30
31typedef struct led_matrix {
32 union {
33 uint8_t raw;
34 struct {
35 uint8_t row : 4; // 16 max
36 uint8_t col : 4; // 16 max
37 };
38 } matrix_co;
39 Point point;
40 uint8_t modifier : 1;
41} __attribute__((packed)) led_matrix;
42
43extern const led_matrix g_leds[LED_DRIVER_LED_COUNT];
44
45typedef struct {
46 uint8_t index;
47 uint8_t value;
48} led_indicator;
49
50typedef union {
51 uint32_t raw;
52 struct {
53 bool enable : 1;
54 uint8_t mode : 6;
55 uint8_t hue : 8; // Unused by led_matrix
56 uint8_t sat : 8; // Unused by led_matrix
57 uint8_t val : 8;
58 uint8_t speed : 8; // EECONFIG needs to be increased to support this
59 };
60} led_config_t;
61
62enum led_matrix_effects { 28enum led_matrix_effects {
63 LED_MATRIX_UNIFORM_BRIGHTNESS = 1, 29 LED_MATRIX_UNIFORM_BRIGHTNESS = 1,
64 // All new effects go above this line 30 // All new effects go above this line
@@ -122,3 +88,7 @@ typedef struct {
122} led_matrix_driver_t; 88} led_matrix_driver_t;
123 89
124extern const led_matrix_driver_t led_matrix_driver; 90extern const led_matrix_driver_t led_matrix_driver;
91
92extern led_eeconfig_t led_matrix_eeconfig;
93
94extern led_config_t g_led_config;
diff --git a/quantum/led_matrix_types.h b/quantum/led_matrix_types.h
new file mode 100644
index 000000000..2602bf2bf
--- /dev/null
+++ b/quantum/led_matrix_types.h
@@ -0,0 +1,69 @@
1/* Copyright 2021
2 *
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16
17#pragma once
18
19#include <stdint.h>
20#include <stdbool.h>
21
22#if defined(__GNUC__)
23# define PACKED __attribute__((__packed__))
24#else
25# define PACKED
26#endif
27
28#if defined(_MSC_VER)
29# pragma pack(push, 1)
30#endif
31
32// Last led hit
33#ifndef LED_HITS_TO_REMEMBER
34# define LED_HITS_TO_REMEMBER 8
35#endif // LED_HITS_TO_REMEMBER
36
37typedef struct PACKED {
38 uint8_t x;
39 uint8_t y;
40} point_t;
41
42#define LED_FLAG_ALL 0xFF
43#define LED_FLAG_NONE 0x00
44#define LED_FLAG_MODIFIER 0x01
45#define LED_FLAG_KEYLIGHT 0x04
46#define LED_FLAG_INDICATOR 0x08
47
48#define NO_LED 255
49
50typedef struct PACKED {
51 uint8_t matrix_co[MATRIX_ROWS][MATRIX_COLS];
52 point_t point[LED_DRIVER_LED_COUNT];
53 uint8_t flags[LED_DRIVER_LED_COUNT];
54} led_config_t;
55
56typedef union {
57 uint32_t raw;
58 struct PACKED {
59 uint8_t enable : 2;
60 uint8_t mode : 6;
61 uint16_t reserved;
62 uint8_t val;
63 uint8_t speed; // EECONFIG needs to be increased to support this
64 };
65} led_eeconfig_t;
66
67#if defined(_MSC_VER)
68# pragma pack(pop)
69#endif
diff --git a/quantum/rgb_matrix_types.h b/quantum/rgb_matrix_types.h
index f7ebec1d5..7b8171fb2 100644
--- a/quantum/rgb_matrix_types.h
+++ b/quantum/rgb_matrix_types.h
@@ -1,3 +1,19 @@
1/* Copyright 2021
2 *
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16
1#pragma once 17#pragma once
2 18
3#include <stdint.h> 19#include <stdint.h>