diff options
Diffstat (limited to 'quantum')
-rw-r--r-- | quantum/bootmagic/bootmagic.h | 24 | ||||
-rw-r--r-- | quantum/bootmagic/bootmagic_full.c | 147 | ||||
-rw-r--r-- | quantum/bootmagic/bootmagic_full.h | 115 | ||||
-rw-r--r-- | quantum/bootmagic/bootmagic_lite.c | 66 | ||||
-rw-r--r-- | quantum/bootmagic/bootmagic_lite.h | 25 | ||||
-rw-r--r-- | quantum/bootmagic/magic.c | 54 | ||||
-rw-r--r-- | quantum/bootmagic/magic.h | 18 | ||||
-rw-r--r-- | quantum/keycode_config.h | 1 | ||||
-rw-r--r-- | quantum/led_matrix.c | 8 | ||||
-rw-r--r-- | quantum/led_matrix.h | 4 | ||||
-rw-r--r-- | quantum/process_keycode/process_backlight.c | 29 | ||||
-rw-r--r-- | quantum/quantum.c | 28 | ||||
-rw-r--r-- | quantum/quantum.h | 22 | ||||
-rw-r--r-- | quantum/quantum_keycodes.h | 9 | ||||
-rw-r--r-- | quantum/rgb_matrix.c | 34 | ||||
-rw-r--r-- | quantum/rgb_matrix_types.h | 9 | ||||
-rw-r--r-- | quantum/split_common/split_util.c | 70 | ||||
-rw-r--r-- | quantum/split_common/transport.c | 45 |
18 files changed, 609 insertions, 99 deletions
diff --git a/quantum/bootmagic/bootmagic.h b/quantum/bootmagic/bootmagic.h new file mode 100644 index 000000000..959750178 --- /dev/null +++ b/quantum/bootmagic/bootmagic.h | |||
@@ -0,0 +1,24 @@ | |||
1 | /* Copyright 2021 QMK | ||
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 3 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 | #pragma once | ||
17 | |||
18 | #if defined(BOOTMAGIC_ENABLE) | ||
19 | # include "bootmagic_full.h" | ||
20 | #elif defined(BOOTMAGIC_LITE) | ||
21 | # include "bootmagic_lite.h" | ||
22 | #endif | ||
23 | |||
24 | void bootmagic(void); | ||
diff --git a/quantum/bootmagic/bootmagic_full.c b/quantum/bootmagic/bootmagic_full.c new file mode 100644 index 000000000..a7a0dcfcb --- /dev/null +++ b/quantum/bootmagic/bootmagic_full.c | |||
@@ -0,0 +1,147 @@ | |||
1 | /* Copyright 2021 QMK | ||
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 3 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 | #include <stdint.h> | ||
17 | #include <stdbool.h> | ||
18 | #include "wait.h" | ||
19 | #include "matrix.h" | ||
20 | #include "bootloader.h" | ||
21 | #include "debug.h" | ||
22 | #include "keymap.h" | ||
23 | #include "host.h" | ||
24 | #include "action_layer.h" | ||
25 | #include "eeconfig.h" | ||
26 | #include "bootmagic.h" | ||
27 | |||
28 | /** \brief Scan Keycode | ||
29 | * | ||
30 | * FIXME: needs doc | ||
31 | */ | ||
32 | static bool scan_keycode(uint8_t keycode) { | ||
33 | for (uint8_t r = 0; r < MATRIX_ROWS; r++) { | ||
34 | matrix_row_t matrix_row = matrix_get_row(r); | ||
35 | for (uint8_t c = 0; c < MATRIX_COLS; c++) { | ||
36 | if (matrix_row & ((matrix_row_t)1 << c)) { | ||
37 | if (keycode == keymap_key_to_keycode(0, (keypos_t){.row = r, .col = c})) { | ||
38 | return true; | ||
39 | } | ||
40 | } | ||
41 | } | ||
42 | } | ||
43 | return false; | ||
44 | } | ||
45 | |||
46 | /** \brief Bootmagic Scan Keycode | ||
47 | * | ||
48 | * FIXME: needs doc | ||
49 | */ | ||
50 | static bool bootmagic_scan_keycode(uint8_t keycode) { | ||
51 | if (!scan_keycode(BOOTMAGIC_KEY_SALT)) return false; | ||
52 | |||
53 | return scan_keycode(keycode); | ||
54 | } | ||
55 | |||
56 | void bootmagic(void) { | ||
57 | /* do scans in case of bounce */ | ||
58 | print("bootmagic scan: ... "); | ||
59 | uint8_t scan = 100; | ||
60 | while (scan--) { | ||
61 | matrix_scan(); | ||
62 | wait_ms(10); | ||
63 | } | ||
64 | print("done.\n"); | ||
65 | |||
66 | /* bootmagic skip */ | ||
67 | if (bootmagic_scan_keycode(BOOTMAGIC_KEY_SKIP)) { | ||
68 | return; | ||
69 | } | ||
70 | |||
71 | /* eeconfig clear */ | ||
72 | if (bootmagic_scan_keycode(BOOTMAGIC_KEY_EEPROM_CLEAR)) { | ||
73 | eeconfig_init(); | ||
74 | } | ||
75 | |||
76 | /* bootloader */ | ||
77 | if (bootmagic_scan_keycode(BOOTMAGIC_KEY_BOOTLOADER)) { | ||
78 | bootloader_jump(); | ||
79 | } | ||
80 | |||
81 | if (bootmagic_scan_keycode(BOOTMAGIC_KEY_DEBUG_ENABLE)) { | ||
82 | if (bootmagic_scan_keycode(BOOTMAGIC_KEY_DEBUG_MATRIX)) { | ||
83 | debug_config.matrix = !debug_config.matrix; | ||
84 | } else if (bootmagic_scan_keycode(BOOTMAGIC_KEY_DEBUG_KEYBOARD)) { | ||
85 | debug_config.keyboard = !debug_config.keyboard; | ||
86 | } else if (bootmagic_scan_keycode(BOOTMAGIC_KEY_DEBUG_MOUSE)) { | ||
87 | debug_config.mouse = !debug_config.mouse; | ||
88 | } else { | ||
89 | debug_config.enable = !debug_config.enable; | ||
90 | } | ||
91 | } | ||
92 | eeconfig_update_debug(debug_config.raw); | ||
93 | |||
94 | if (bootmagic_scan_keycode(BOOTMAGIC_KEY_SWAP_CONTROL_CAPSLOCK)) { | ||
95 | keymap_config.swap_control_capslock = !keymap_config.swap_control_capslock; | ||
96 | } | ||
97 | if (bootmagic_scan_keycode(BOOTMAGIC_KEY_CAPSLOCK_TO_CONTROL)) { | ||
98 | keymap_config.capslock_to_control = !keymap_config.capslock_to_control; | ||
99 | } | ||
100 | if (bootmagic_scan_keycode(BOOTMAGIC_KEY_SWAP_LALT_LGUI)) { | ||
101 | keymap_config.swap_lalt_lgui = !keymap_config.swap_lalt_lgui; | ||
102 | } | ||
103 | if (bootmagic_scan_keycode(BOOTMAGIC_KEY_SWAP_RALT_RGUI)) { | ||
104 | keymap_config.swap_ralt_rgui = !keymap_config.swap_ralt_rgui; | ||
105 | } | ||
106 | if (bootmagic_scan_keycode(BOOTMAGIC_KEY_NO_GUI)) { | ||
107 | keymap_config.no_gui = !keymap_config.no_gui; | ||
108 | } | ||
109 | if (bootmagic_scan_keycode(BOOTMAGIC_KEY_SWAP_GRAVE_ESC)) { | ||
110 | keymap_config.swap_grave_esc = !keymap_config.swap_grave_esc; | ||
111 | } | ||
112 | if (bootmagic_scan_keycode(BOOTMAGIC_KEY_SWAP_BACKSLASH_BACKSPACE)) { | ||
113 | keymap_config.swap_backslash_backspace = !keymap_config.swap_backslash_backspace; | ||
114 | } | ||
115 | if (bootmagic_scan_keycode(BOOTMAGIC_HOST_NKRO)) { | ||
116 | keymap_config.nkro = !keymap_config.nkro; | ||
117 | } | ||
118 | eeconfig_update_keymap(keymap_config.raw); | ||
119 | |||
120 | /* default layer */ | ||
121 | uint8_t default_layer = 0; | ||
122 | if (bootmagic_scan_keycode(BOOTMAGIC_KEY_DEFAULT_LAYER_0)) { | ||
123 | default_layer |= (1 << 0); | ||
124 | } else if (bootmagic_scan_keycode(BOOTMAGIC_KEY_DEFAULT_LAYER_1)) { | ||
125 | default_layer |= (1 << 1); | ||
126 | } else if (bootmagic_scan_keycode(BOOTMAGIC_KEY_DEFAULT_LAYER_2)) { | ||
127 | default_layer |= (1 << 2); | ||
128 | } else if (bootmagic_scan_keycode(BOOTMAGIC_KEY_DEFAULT_LAYER_3)) { | ||
129 | default_layer |= (1 << 3); | ||
130 | } else if (bootmagic_scan_keycode(BOOTMAGIC_KEY_DEFAULT_LAYER_4)) { | ||
131 | default_layer |= (1 << 4); | ||
132 | } else if (bootmagic_scan_keycode(BOOTMAGIC_KEY_DEFAULT_LAYER_5)) { | ||
133 | default_layer |= (1 << 5); | ||
134 | } else if (bootmagic_scan_keycode(BOOTMAGIC_KEY_DEFAULT_LAYER_6)) { | ||
135 | default_layer |= (1 << 6); | ||
136 | } else if (bootmagic_scan_keycode(BOOTMAGIC_KEY_DEFAULT_LAYER_7)) { | ||
137 | default_layer |= (1 << 7); | ||
138 | } | ||
139 | eeconfig_update_default_layer(default_layer); | ||
140 | |||
141 | /* EE_HANDS handedness */ | ||
142 | if (bootmagic_scan_keycode(BOOTMAGIC_KEY_EE_HANDS_LEFT)) { | ||
143 | eeconfig_update_handedness(true); | ||
144 | } else if (bootmagic_scan_keycode(BOOTMAGIC_KEY_EE_HANDS_RIGHT)) { | ||
145 | eeconfig_update_handedness(false); | ||
146 | } | ||
147 | } | ||
diff --git a/quantum/bootmagic/bootmagic_full.h b/quantum/bootmagic/bootmagic_full.h new file mode 100644 index 000000000..28f914c1b --- /dev/null +++ b/quantum/bootmagic/bootmagic_full.h | |||
@@ -0,0 +1,115 @@ | |||
1 | /* Copyright 2021 QMK | ||
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 3 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 | /* FIXME: Add special doxygen comments for defines here. */ | ||
20 | |||
21 | /* bootmagic salt key */ | ||
22 | #ifndef BOOTMAGIC_KEY_SALT | ||
23 | # define BOOTMAGIC_KEY_SALT KC_SPACE | ||
24 | #endif | ||
25 | |||
26 | /* skip bootmagic and eeconfig */ | ||
27 | #ifndef BOOTMAGIC_KEY_SKIP | ||
28 | # define BOOTMAGIC_KEY_SKIP KC_ESC | ||
29 | #endif | ||
30 | |||
31 | /* eeprom clear */ | ||
32 | #ifndef BOOTMAGIC_KEY_EEPROM_CLEAR | ||
33 | # define BOOTMAGIC_KEY_EEPROM_CLEAR KC_BSPACE | ||
34 | #endif | ||
35 | |||
36 | /* kick up bootloader */ | ||
37 | #ifndef BOOTMAGIC_KEY_BOOTLOADER | ||
38 | # define BOOTMAGIC_KEY_BOOTLOADER KC_B | ||
39 | #endif | ||
40 | |||
41 | /* debug enable */ | ||
42 | #ifndef BOOTMAGIC_KEY_DEBUG_ENABLE | ||
43 | # define BOOTMAGIC_KEY_DEBUG_ENABLE KC_D | ||
44 | #endif | ||
45 | #ifndef BOOTMAGIC_KEY_DEBUG_MATRIX | ||
46 | # define BOOTMAGIC_KEY_DEBUG_MATRIX KC_X | ||
47 | #endif | ||
48 | #ifndef BOOTMAGIC_KEY_DEBUG_KEYBOARD | ||
49 | # define BOOTMAGIC_KEY_DEBUG_KEYBOARD KC_K | ||
50 | #endif | ||
51 | #ifndef BOOTMAGIC_KEY_DEBUG_MOUSE | ||
52 | # define BOOTMAGIC_KEY_DEBUG_MOUSE KC_M | ||
53 | #endif | ||
54 | #ifndef BOOTMAGIC_KEY_EE_HANDS_LEFT | ||
55 | # define BOOTMAGIC_KEY_EE_HANDS_LEFT KC_L | ||
56 | #endif | ||
57 | #ifndef BOOTMAGIC_KEY_EE_HANDS_RIGHT | ||
58 | # define BOOTMAGIC_KEY_EE_HANDS_RIGHT KC_R | ||
59 | #endif | ||
60 | |||
61 | /* | ||
62 | * keymap config | ||
63 | */ | ||
64 | #ifndef BOOTMAGIC_KEY_SWAP_CONTROL_CAPSLOCK | ||
65 | # define BOOTMAGIC_KEY_SWAP_CONTROL_CAPSLOCK KC_LCTRL | ||
66 | #endif | ||
67 | #ifndef BOOTMAGIC_KEY_CAPSLOCK_TO_CONTROL | ||
68 | # define BOOTMAGIC_KEY_CAPSLOCK_TO_CONTROL KC_CAPSLOCK | ||
69 | #endif | ||
70 | #ifndef BOOTMAGIC_KEY_SWAP_LALT_LGUI | ||
71 | # define BOOTMAGIC_KEY_SWAP_LALT_LGUI KC_LALT | ||
72 | #endif | ||
73 | #ifndef BOOTMAGIC_KEY_SWAP_RALT_RGUI | ||
74 | # define BOOTMAGIC_KEY_SWAP_RALT_RGUI KC_RALT | ||
75 | #endif | ||
76 | #ifndef BOOTMAGIC_KEY_NO_GUI | ||
77 | # define BOOTMAGIC_KEY_NO_GUI KC_LGUI | ||
78 | #endif | ||
79 | #ifndef BOOTMAGIC_KEY_SWAP_GRAVE_ESC | ||
80 | # define BOOTMAGIC_KEY_SWAP_GRAVE_ESC KC_GRAVE | ||
81 | #endif | ||
82 | #ifndef BOOTMAGIC_KEY_SWAP_BACKSLASH_BACKSPACE | ||
83 | # define BOOTMAGIC_KEY_SWAP_BACKSLASH_BACKSPACE KC_BSLASH | ||
84 | #endif | ||
85 | #ifndef BOOTMAGIC_HOST_NKRO | ||
86 | # define BOOTMAGIC_HOST_NKRO KC_N | ||
87 | #endif | ||
88 | |||
89 | /* | ||
90 | * change default layer | ||
91 | */ | ||
92 | #ifndef BOOTMAGIC_KEY_DEFAULT_LAYER_0 | ||
93 | # define BOOTMAGIC_KEY_DEFAULT_LAYER_0 KC_0 | ||
94 | #endif | ||
95 | #ifndef BOOTMAGIC_KEY_DEFAULT_LAYER_1 | ||
96 | # define BOOTMAGIC_KEY_DEFAULT_LAYER_1 KC_1 | ||
97 | #endif | ||
98 | #ifndef BOOTMAGIC_KEY_DEFAULT_LAYER_2 | ||
99 | # define BOOTMAGIC_KEY_DEFAULT_LAYER_2 KC_2 | ||
100 | #endif | ||
101 | #ifndef BOOTMAGIC_KEY_DEFAULT_LAYER_3 | ||
102 | # define BOOTMAGIC_KEY_DEFAULT_LAYER_3 KC_3 | ||
103 | #endif | ||
104 | #ifndef BOOTMAGIC_KEY_DEFAULT_LAYER_4 | ||
105 | # define BOOTMAGIC_KEY_DEFAULT_LAYER_4 KC_4 | ||
106 | #endif | ||
107 | #ifndef BOOTMAGIC_KEY_DEFAULT_LAYER_5 | ||
108 | # define BOOTMAGIC_KEY_DEFAULT_LAYER_5 KC_5 | ||
109 | #endif | ||
110 | #ifndef BOOTMAGIC_KEY_DEFAULT_LAYER_6 | ||
111 | # define BOOTMAGIC_KEY_DEFAULT_LAYER_6 KC_6 | ||
112 | #endif | ||
113 | #ifndef BOOTMAGIC_KEY_DEFAULT_LAYER_7 | ||
114 | # define BOOTMAGIC_KEY_DEFAULT_LAYER_7 KC_7 | ||
115 | #endif \ No newline at end of file | ||
diff --git a/quantum/bootmagic/bootmagic_lite.c b/quantum/bootmagic/bootmagic_lite.c new file mode 100644 index 000000000..9cbdcb0bb --- /dev/null +++ b/quantum/bootmagic/bootmagic_lite.c | |||
@@ -0,0 +1,66 @@ | |||
1 | /* Copyright 2021 QMK | ||
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 3 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 | #include "quantum.h" | ||
17 | |||
18 | /** \brief Reset eeprom | ||
19 | * | ||
20 | * ...just incase someone wants to only change the eeprom behaviour | ||
21 | */ | ||
22 | __attribute__((weak)) void bootmagic_lite_reset_eeprom(void) { | ||
23 | #if defined(VIA_ENABLE) | ||
24 | via_eeprom_reset(); | ||
25 | #else | ||
26 | eeconfig_disable(); | ||
27 | #endif | ||
28 | } | ||
29 | |||
30 | /** \brief The lite version of TMK's bootmagic based on Wilba. | ||
31 | * | ||
32 | * 100% less potential for accidentally making the keyboard do stupid things. | ||
33 | */ | ||
34 | __attribute__((weak)) void bootmagic_lite(void) { | ||
35 | // We need multiple scans because debouncing can't be turned off. | ||
36 | matrix_scan(); | ||
37 | #if defined(DEBOUNCE) && DEBOUNCE > 0 | ||
38 | wait_ms(DEBOUNCE * 2); | ||
39 | #else | ||
40 | wait_ms(30); | ||
41 | #endif | ||
42 | matrix_scan(); | ||
43 | |||
44 | // If the configured key (commonly Esc) is held down on power up, | ||
45 | // reset the EEPROM valid state and jump to bootloader. | ||
46 | // This isn't very generalized, but we need something that doesn't | ||
47 | // rely on user's keymaps in firmware or EEPROM. | ||
48 | uint8_t row = BOOTMAGIC_LITE_ROW; | ||
49 | uint8_t col = BOOTMAGIC_LITE_COLUMN; | ||
50 | |||
51 | #if defined(SPLIT_KEYBOARD) && defined(BOOTMAGIC_LITE_ROW_RIGHT) && defined(BOOTMAGIC_LITE_COLUMN_RIGHT) | ||
52 | if (!is_keyboard_left()) { | ||
53 | row = BOOTMAGIC_LITE_ROW_RIGHT; | ||
54 | col = BOOTMAGIC_LITE_COLUMN_RIGHT; | ||
55 | } | ||
56 | #endif | ||
57 | |||
58 | if (matrix_get_row(row) & (1 << col)) { | ||
59 | bootmagic_lite_reset_eeprom(); | ||
60 | |||
61 | // Jump to bootloader. | ||
62 | bootloader_jump(); | ||
63 | } | ||
64 | } | ||
65 | |||
66 | void bootmagic(void) { bootmagic_lite(); } | ||
diff --git a/quantum/bootmagic/bootmagic_lite.h b/quantum/bootmagic/bootmagic_lite.h new file mode 100644 index 000000000..17777e6b4 --- /dev/null +++ b/quantum/bootmagic/bootmagic_lite.h | |||
@@ -0,0 +1,25 @@ | |||
1 | /* Copyright 2021 QMK | ||
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 3 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 | #pragma once | ||
17 | |||
18 | #ifndef BOOTMAGIC_LITE_COLUMN | ||
19 | # define BOOTMAGIC_LITE_COLUMN 0 | ||
20 | #endif | ||
21 | #ifndef BOOTMAGIC_LITE_ROW | ||
22 | # define BOOTMAGIC_LITE_ROW 0 | ||
23 | #endif | ||
24 | |||
25 | void bootmagic_lite(void); | ||
diff --git a/quantum/bootmagic/magic.c b/quantum/bootmagic/magic.c new file mode 100644 index 000000000..f1cb11c39 --- /dev/null +++ b/quantum/bootmagic/magic.c | |||
@@ -0,0 +1,54 @@ | |||
1 | /* Copyright 2021 QMK | ||
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 3 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 | #include <stdint.h> | ||
17 | #include <stdbool.h> | ||
18 | #include "wait.h" | ||
19 | #include "matrix.h" | ||
20 | #include "bootloader.h" | ||
21 | #include "debug.h" | ||
22 | #include "keymap.h" | ||
23 | #include "host.h" | ||
24 | #include "action_layer.h" | ||
25 | #include "eeconfig.h" | ||
26 | #include "bootmagic.h" | ||
27 | |||
28 | keymap_config_t keymap_config; | ||
29 | |||
30 | __attribute__((weak)) void bootmagic(void) {} | ||
31 | |||
32 | /** \brief Magic | ||
33 | * | ||
34 | * FIXME: Needs doc | ||
35 | */ | ||
36 | void magic(void) { | ||
37 | /* check signature */ | ||
38 | if (!eeconfig_is_enabled()) { | ||
39 | eeconfig_init(); | ||
40 | } | ||
41 | |||
42 | /* init globals */ | ||
43 | debug_config.raw = eeconfig_read_debug(); | ||
44 | keymap_config.raw = eeconfig_read_keymap(); | ||
45 | |||
46 | bootmagic(); | ||
47 | |||
48 | /* read here just incase bootmagic process changed its value */ | ||
49 | layer_state_t default_layer = (layer_state_t)eeconfig_read_default_layer(); | ||
50 | default_layer_set(default_layer); | ||
51 | |||
52 | /* Also initialize layer state to trigger callback functions for layer_state */ | ||
53 | layer_state_set_kb((layer_state_t)layer_state); | ||
54 | } | ||
diff --git a/quantum/bootmagic/magic.h b/quantum/bootmagic/magic.h new file mode 100644 index 000000000..2c3969b85 --- /dev/null +++ b/quantum/bootmagic/magic.h | |||
@@ -0,0 +1,18 @@ | |||
1 | /* Copyright 2021 QMK | ||
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 3 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 | #pragma once | ||
17 | |||
18 | void magic(void); | ||
diff --git a/quantum/keycode_config.h b/quantum/keycode_config.h index f878168c5..d7e334fdc 100644 --- a/quantum/keycode_config.h +++ b/quantum/keycode_config.h | |||
@@ -37,6 +37,7 @@ typedef union { | |||
37 | bool nkro : 1; | 37 | bool nkro : 1; |
38 | bool swap_lctl_lgui : 1; | 38 | bool swap_lctl_lgui : 1; |
39 | bool swap_rctl_rgui : 1; | 39 | bool swap_rctl_rgui : 1; |
40 | bool oneshot_disable : 1; | ||
40 | }; | 41 | }; |
41 | } keymap_config_t; | 42 | } keymap_config_t; |
42 | 43 | ||
diff --git a/quantum/led_matrix.c b/quantum/led_matrix.c index 4f1f06c7a..39bccdd58 100644 --- a/quantum/led_matrix.c +++ b/quantum/led_matrix.c | |||
@@ -45,10 +45,6 @@ led_eeconfig_t led_matrix_eeconfig; | |||
45 | # define LED_DISABLE_WHEN_USB_SUSPENDED false | 45 | # define LED_DISABLE_WHEN_USB_SUSPENDED false |
46 | #endif | 46 | #endif |
47 | 47 | ||
48 | #ifndef EECONFIG_LED_MATRIX | ||
49 | # define EECONFIG_LED_MATRIX EECONFIG_RGBLIGHT | ||
50 | #endif | ||
51 | |||
52 | #if !defined(LED_MATRIX_MAXIMUM_BRIGHTNESS) || LED_MATRIX_MAXIMUM_BRIGHTNESS > 255 | 48 | #if !defined(LED_MATRIX_MAXIMUM_BRIGHTNESS) || LED_MATRIX_MAXIMUM_BRIGHTNESS > 255 |
53 | # define LED_MATRIX_MAXIMUM_BRIGHTNESS 255 | 49 | # define LED_MATRIX_MAXIMUM_BRIGHTNESS 255 |
54 | #endif | 50 | #endif |
@@ -135,7 +131,7 @@ void led_matrix_set_suspend_state(bool state) { g_suspend_state = state; } | |||
135 | void led_matrix_all_off(void) { led_matrix_set_index_value_all(0); } | 131 | void led_matrix_all_off(void) { led_matrix_set_index_value_all(0); } |
136 | 132 | ||
137 | // Uniform brightness | 133 | // Uniform brightness |
138 | void led_matrix_uniform_brightness(void) { led_matrix_set_index_value_all(LED_MATRIX_MAXIMUM_BRIGHTNESS / BACKLIGHT_LEVELS * led_matrix_eeconfig.val); } | 134 | void led_matrix_uniform_brightness(void) { led_matrix_set_index_value_all(led_matrix_eeconfig.val); } |
139 | 135 | ||
140 | void led_matrix_custom(void) {} | 136 | void led_matrix_custom(void) {} |
141 | 137 | ||
@@ -344,5 +340,3 @@ void led_matrix_set_value(uint8_t val) { | |||
344 | led_matrix_set_value_noeeprom(val); | 340 | led_matrix_set_value_noeeprom(val); |
345 | eeconfig_update_led_matrix(led_matrix_eeconfig.raw); | 341 | eeconfig_update_led_matrix(led_matrix_eeconfig.raw); |
346 | } | 342 | } |
347 | |||
348 | void backlight_set(uint8_t val) { led_matrix_set_value(val); } | ||
diff --git a/quantum/led_matrix.h b/quantum/led_matrix.h index 85bae43c1..0817d1357 100644 --- a/quantum/led_matrix.h +++ b/quantum/led_matrix.h | |||
@@ -21,10 +21,6 @@ | |||
21 | 21 | ||
22 | #include "led_matrix_types.h" | 22 | #include "led_matrix_types.h" |
23 | 23 | ||
24 | #ifndef BACKLIGHT_ENABLE | ||
25 | # error You must define BACKLIGHT_ENABLE with LED_MATRIX_ENABLE | ||
26 | #endif | ||
27 | |||
28 | enum led_matrix_effects { | 24 | enum led_matrix_effects { |
29 | LED_MATRIX_UNIFORM_BRIGHTNESS = 1, | 25 | LED_MATRIX_UNIFORM_BRIGHTNESS = 1, |
30 | // All new effects go above this line | 26 | // All new effects go above this line |
diff --git a/quantum/process_keycode/process_backlight.c b/quantum/process_keycode/process_backlight.c index 4d12f6813..8b70339a5 100644 --- a/quantum/process_keycode/process_backlight.c +++ b/quantum/process_keycode/process_backlight.c | |||
@@ -16,11 +16,35 @@ | |||
16 | 16 | ||
17 | #include "process_backlight.h" | 17 | #include "process_backlight.h" |
18 | 18 | ||
19 | #include "backlight.h" | 19 | #ifdef LED_MATRIX_ENABLE |
20 | # include "led_matrix.h" | ||
21 | #else | ||
22 | # include "backlight.h" | ||
23 | #endif | ||
20 | 24 | ||
21 | bool process_backlight(uint16_t keycode, keyrecord_t *record) { | 25 | bool process_backlight(uint16_t keycode, keyrecord_t *record) { |
22 | if (record->event.pressed) { | 26 | if (record->event.pressed) { |
23 | switch (keycode) { | 27 | switch (keycode) { |
28 | #ifdef LED_MATRIX_ENABLE | ||
29 | case BL_ON: | ||
30 | led_matrix_enable(); | ||
31 | return false; | ||
32 | case BL_OFF: | ||
33 | led_matrix_disable(); | ||
34 | return false; | ||
35 | case BL_DEC: | ||
36 | led_matrix_decrease_val(); | ||
37 | return false; | ||
38 | case BL_INC: | ||
39 | led_matrix_increase_val(); | ||
40 | return false; | ||
41 | case BL_TOGG: | ||
42 | led_matrix_toggle(); | ||
43 | return false; | ||
44 | case BL_STEP: | ||
45 | led_matrix_step(); | ||
46 | return false; | ||
47 | #else | ||
24 | case BL_ON: | 48 | case BL_ON: |
25 | backlight_level(BACKLIGHT_LEVELS); | 49 | backlight_level(BACKLIGHT_LEVELS); |
26 | return false; | 50 | return false; |
@@ -39,10 +63,11 @@ bool process_backlight(uint16_t keycode, keyrecord_t *record) { | |||
39 | case BL_STEP: | 63 | case BL_STEP: |
40 | backlight_step(); | 64 | backlight_step(); |
41 | return false; | 65 | return false; |
42 | #ifdef BACKLIGHT_BREATHING | 66 | # ifdef BACKLIGHT_BREATHING |
43 | case BL_BRTG: | 67 | case BL_BRTG: |
44 | backlight_toggle_breathing(); | 68 | backlight_toggle_breathing(); |
45 | return false; | 69 | return false; |
70 | # endif | ||
46 | #endif | 71 | #endif |
47 | } | 72 | } |
48 | } | 73 | } |
diff --git a/quantum/quantum.c b/quantum/quantum.c index 80c4e8f00..59d95f2f5 100644 --- a/quantum/quantum.c +++ b/quantum/quantum.c | |||
@@ -15,6 +15,7 @@ | |||
15 | */ | 15 | */ |
16 | 16 | ||
17 | #include "quantum.h" | 17 | #include "quantum.h" |
18 | #include "magic.h" | ||
18 | 19 | ||
19 | #ifdef BLUETOOTH_ENABLE | 20 | #ifdef BLUETOOTH_ENABLE |
20 | # include "outputselect.h" | 21 | # include "outputselect.h" |
@@ -233,7 +234,7 @@ bool process_record_quantum(keyrecord_t *record) { | |||
233 | #ifdef AUDIO_ENABLE | 234 | #ifdef AUDIO_ENABLE |
234 | process_audio(keycode, record) && | 235 | process_audio(keycode, record) && |
235 | #endif | 236 | #endif |
236 | #ifdef BACKLIGHT_ENABLE | 237 | #if defined(BACKLIGHT_ENABLE) || defined(LED_MATRIX_ENABLE) |
237 | process_backlight(keycode, record) && | 238 | process_backlight(keycode, record) && |
238 | #endif | 239 | #endif |
239 | #ifdef STENO_ENABLE | 240 | #ifdef STENO_ENABLE |
@@ -318,6 +319,17 @@ bool process_record_quantum(keyrecord_t *record) { | |||
318 | set_output(OUTPUT_BLUETOOTH); | 319 | set_output(OUTPUT_BLUETOOTH); |
319 | return false; | 320 | return false; |
320 | #endif | 321 | #endif |
322 | #ifndef NO_ACTION_ONESHOT | ||
323 | case ONESHOT_TOGGLE: | ||
324 | oneshot_toggle(); | ||
325 | break; | ||
326 | case ONESHOT_ENABLE: | ||
327 | oneshot_enable(); | ||
328 | break; | ||
329 | case ONESHOT_DISABLE: | ||
330 | oneshot_disable(); | ||
331 | break; | ||
332 | #endif | ||
321 | } | 333 | } |
322 | } | 334 | } |
323 | 335 | ||
@@ -369,26 +381,20 @@ void tap_random_base64(void) { | |||
369 | } | 381 | } |
370 | 382 | ||
371 | void matrix_init_quantum() { | 383 | void matrix_init_quantum() { |
372 | #ifdef BOOTMAGIC_LITE | 384 | magic(); |
373 | bootmagic_lite(); | ||
374 | #endif | ||
375 | if (!eeconfig_is_enabled()) { | ||
376 | eeconfig_init(); | ||
377 | } | ||
378 | #if defined(LED_NUM_LOCK_PIN) || defined(LED_CAPS_LOCK_PIN) || defined(LED_SCROLL_LOCK_PIN) || defined(LED_COMPOSE_PIN) || defined(LED_KANA_PIN) | 385 | #if defined(LED_NUM_LOCK_PIN) || defined(LED_CAPS_LOCK_PIN) || defined(LED_SCROLL_LOCK_PIN) || defined(LED_COMPOSE_PIN) || defined(LED_KANA_PIN) |
379 | // TODO: remove calls to led_init_ports from keyboards and remove ifdef | 386 | // TODO: remove calls to led_init_ports from keyboards and remove ifdef |
380 | led_init_ports(); | 387 | led_init_ports(); |
381 | #endif | 388 | #endif |
382 | #ifdef BACKLIGHT_ENABLE | 389 | #ifdef BACKLIGHT_ENABLE |
383 | # ifdef LED_MATRIX_ENABLE | ||
384 | led_matrix_init(); | ||
385 | # else | ||
386 | backlight_init_ports(); | 390 | backlight_init_ports(); |
387 | # endif | ||
388 | #endif | 391 | #endif |
389 | #ifdef AUDIO_ENABLE | 392 | #ifdef AUDIO_ENABLE |
390 | audio_init(); | 393 | audio_init(); |
391 | #endif | 394 | #endif |
395 | #ifdef LED_MATRIX_ENABLE | ||
396 | led_matrix_init(); | ||
397 | #endif | ||
392 | #ifdef RGB_MATRIX_ENABLE | 398 | #ifdef RGB_MATRIX_ENABLE |
393 | rgb_matrix_init(); | 399 | rgb_matrix_init(); |
394 | #endif | 400 | #endif |
diff --git a/quantum/quantum.h b/quantum/quantum.h index b1600dd72..7c2dcaa82 100644 --- a/quantum/quantum.h +++ b/quantum/quantum.h | |||
@@ -30,11 +30,11 @@ | |||
30 | #include "keymap.h" | 30 | #include "keymap.h" |
31 | 31 | ||
32 | #ifdef BACKLIGHT_ENABLE | 32 | #ifdef BACKLIGHT_ENABLE |
33 | # ifdef LED_MATRIX_ENABLE | 33 | # include "backlight.h" |
34 | # include "led_matrix.h" | 34 | #endif |
35 | # else | 35 | |
36 | # include "backlight.h" | 36 | #ifdef LED_MATRIX_ENABLE |
37 | # endif | 37 | # include "led_matrix.h" |
38 | #endif | 38 | #endif |
39 | 39 | ||
40 | #if defined(RGBLIGHT_ENABLE) | 40 | #if defined(RGBLIGHT_ENABLE) |
@@ -52,6 +52,7 @@ | |||
52 | #include "action_layer.h" | 52 | #include "action_layer.h" |
53 | #include "eeconfig.h" | 53 | #include "eeconfig.h" |
54 | #include "bootloader.h" | 54 | #include "bootloader.h" |
55 | #include "bootmagic.h" | ||
55 | #include "timer.h" | 56 | #include "timer.h" |
56 | #include "sync_timer.h" | 57 | #include "sync_timer.h" |
57 | #include "config_common.h" | 58 | #include "config_common.h" |
@@ -97,7 +98,7 @@ extern layer_state_t layer_state; | |||
97 | # include "process_music.h" | 98 | # include "process_music.h" |
98 | #endif | 99 | #endif |
99 | 100 | ||
100 | #ifdef BACKLIGHT_ENABLE | 101 | #if defined(BACKLIGHT_ENABLE) || defined(LED_MATRIX_ENABLE) |
101 | # include "process_backlight.h" | 102 | # include "process_backlight.h" |
102 | #endif | 103 | #endif |
103 | 104 | ||
@@ -258,15 +259,6 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record); | |||
258 | void post_process_record_kb(uint16_t keycode, keyrecord_t *record); | 259 | void post_process_record_kb(uint16_t keycode, keyrecord_t *record); |
259 | void post_process_record_user(uint16_t keycode, keyrecord_t *record); | 260 | void post_process_record_user(uint16_t keycode, keyrecord_t *record); |
260 | 261 | ||
261 | #ifndef BOOTMAGIC_LITE_COLUMN | ||
262 | # define BOOTMAGIC_LITE_COLUMN 0 | ||
263 | #endif | ||
264 | #ifndef BOOTMAGIC_LITE_ROW | ||
265 | # define BOOTMAGIC_LITE_ROW 0 | ||
266 | #endif | ||
267 | |||
268 | void bootmagic_lite(void); | ||
269 | |||
270 | void reset_keyboard(void); | 262 | void reset_keyboard(void); |
271 | 263 | ||
272 | void startup_user(void); | 264 | void startup_user(void); |
diff --git a/quantum/quantum_keycodes.h b/quantum/quantum_keycodes.h index 1863a7943..e697b71ba 100644 --- a/quantum/quantum_keycodes.h +++ b/quantum/quantum_keycodes.h | |||
@@ -569,6 +569,10 @@ enum quantum_keycodes { | |||
569 | 569 | ||
570 | #endif | 570 | #endif |
571 | 571 | ||
572 | ONESHOT_ENABLE, | ||
573 | ONESHOT_DISABLE, | ||
574 | ONESHOT_TOGGLE, | ||
575 | |||
572 | // always leave at the end | 576 | // always leave at the end |
573 | SAFE_RANGE | 577 | SAFE_RANGE |
574 | }; | 578 | }; |
@@ -870,3 +874,8 @@ enum quantum_keycodes { | |||
870 | #define DM_RSTP DYN_REC_STOP | 874 | #define DM_RSTP DYN_REC_STOP |
871 | #define DM_PLY1 DYN_MACRO_PLAY1 | 875 | #define DM_PLY1 DYN_MACRO_PLAY1 |
872 | #define DM_PLY2 DYN_MACRO_PLAY2 | 876 | #define DM_PLY2 DYN_MACRO_PLAY2 |
877 | |||
878 | // One Shot toggle | ||
879 | #define OS_TOGG ONESHOT_TOGGLE | ||
880 | #define OS_ON ONESHOT_ENABLE | ||
881 | #define OS_OFF ONESHOT_DISABLE | ||
diff --git a/quantum/rgb_matrix.c b/quantum/rgb_matrix.c index ec17b4d72..8aae48603 100644 --- a/quantum/rgb_matrix.c +++ b/quantum/rgb_matrix.c | |||
@@ -131,7 +131,7 @@ last_hit_t g_last_hit_tracker; | |||
131 | // internals | 131 | // internals |
132 | static uint8_t rgb_last_enable = UINT8_MAX; | 132 | static uint8_t rgb_last_enable = UINT8_MAX; |
133 | static uint8_t rgb_last_effect = UINT8_MAX; | 133 | static uint8_t rgb_last_effect = UINT8_MAX; |
134 | static effect_params_t rgb_effect_params = {0, 0xFF}; | 134 | static effect_params_t rgb_effect_params = {0, LED_FLAG_ALL, false}; |
135 | static rgb_task_states rgb_task_state = SYNCING; | 135 | static rgb_task_states rgb_task_state = SYNCING; |
136 | #if RGB_DISABLE_TIMEOUT > 0 | 136 | #if RGB_DISABLE_TIMEOUT > 0 |
137 | static uint32_t rgb_anykey_timer; | 137 | static uint32_t rgb_anykey_timer; |
@@ -143,6 +143,11 @@ static uint32_t rgb_timer_buffer; | |||
143 | static last_hit_t last_hit_buffer; | 143 | static last_hit_t last_hit_buffer; |
144 | #endif // RGB_MATRIX_KEYREACTIVE_ENABLED | 144 | #endif // RGB_MATRIX_KEYREACTIVE_ENABLED |
145 | 145 | ||
146 | // split rgb matrix | ||
147 | #if defined(RGB_MATRIX_ENABLE) && defined(RGB_MATRIX_SPLIT) | ||
148 | const uint8_t k_rgb_matrix_split[2] = RGB_MATRIX_SPLIT; | ||
149 | #endif | ||
150 | |||
146 | void eeconfig_read_rgb_matrix(void) { eeprom_read_block(&rgb_matrix_config, EECONFIG_RGB_MATRIX, sizeof(rgb_matrix_config)); } | 151 | void eeconfig_read_rgb_matrix(void) { eeprom_read_block(&rgb_matrix_config, EECONFIG_RGB_MATRIX, sizeof(rgb_matrix_config)); } |
147 | 152 | ||
148 | void eeconfig_update_rgb_matrix(void) { eeprom_update_block(&rgb_matrix_config, EECONFIG_RGB_MATRIX, sizeof(rgb_matrix_config)); } | 153 | void eeconfig_update_rgb_matrix(void) { eeprom_update_block(&rgb_matrix_config, EECONFIG_RGB_MATRIX, sizeof(rgb_matrix_config)); } |
@@ -153,6 +158,7 @@ void eeconfig_update_rgb_matrix_default(void) { | |||
153 | rgb_matrix_config.mode = RGB_MATRIX_STARTUP_MODE; | 158 | rgb_matrix_config.mode = RGB_MATRIX_STARTUP_MODE; |
154 | rgb_matrix_config.hsv = (HSV){RGB_MATRIX_STARTUP_HUE, RGB_MATRIX_STARTUP_SAT, RGB_MATRIX_STARTUP_VAL}; | 159 | rgb_matrix_config.hsv = (HSV){RGB_MATRIX_STARTUP_HUE, RGB_MATRIX_STARTUP_SAT, RGB_MATRIX_STARTUP_VAL}; |
155 | rgb_matrix_config.speed = RGB_MATRIX_STARTUP_SPD; | 160 | rgb_matrix_config.speed = RGB_MATRIX_STARTUP_SPD; |
161 | rgb_matrix_config.flags = LED_FLAG_ALL; | ||
156 | eeconfig_update_rgb_matrix(); | 162 | eeconfig_update_rgb_matrix(); |
157 | } | 163 | } |
158 | 164 | ||
@@ -164,6 +170,7 @@ void eeconfig_debug_rgb_matrix(void) { | |||
164 | dprintf("rgb_matrix_config.hsv.s = %d\n", rgb_matrix_config.hsv.s); | 170 | dprintf("rgb_matrix_config.hsv.s = %d\n", rgb_matrix_config.hsv.s); |
165 | dprintf("rgb_matrix_config.hsv.v = %d\n", rgb_matrix_config.hsv.v); | 171 | dprintf("rgb_matrix_config.hsv.v = %d\n", rgb_matrix_config.hsv.v); |
166 | dprintf("rgb_matrix_config.speed = %d\n", rgb_matrix_config.speed); | 172 | dprintf("rgb_matrix_config.speed = %d\n", rgb_matrix_config.speed); |
173 | dprintf("rgb_matrix_config.flags = %d\n", rgb_matrix_config.flags); | ||
167 | } | 174 | } |
168 | 175 | ||
169 | __attribute__((weak)) uint8_t rgb_matrix_map_row_column_to_led_kb(uint8_t row, uint8_t column, uint8_t *led_i) { return 0; } | 176 | __attribute__((weak)) uint8_t rgb_matrix_map_row_column_to_led_kb(uint8_t row, uint8_t column, uint8_t *led_i) { return 0; } |
@@ -180,9 +187,22 @@ uint8_t rgb_matrix_map_row_column_to_led(uint8_t row, uint8_t column, uint8_t *l | |||
180 | 187 | ||
181 | void rgb_matrix_update_pwm_buffers(void) { rgb_matrix_driver.flush(); } | 188 | void rgb_matrix_update_pwm_buffers(void) { rgb_matrix_driver.flush(); } |
182 | 189 | ||
183 | void rgb_matrix_set_color(int index, uint8_t red, uint8_t green, uint8_t blue) { rgb_matrix_driver.set_color(index, red, green, blue); } | 190 | void rgb_matrix_set_color(int index, uint8_t red, uint8_t green, uint8_t blue) { |
191 | #if defined(RGB_MATRIX_ENABLE) && defined(RGB_MATRIX_SPLIT) | ||
192 | if (!is_keyboard_left() && index >= k_rgb_matrix_split[0]) | ||
193 | rgb_matrix_driver.set_color(index - k_rgb_matrix_split[0], red, green, blue); | ||
194 | else if (is_keyboard_left() && index < k_rgb_matrix_split[0]) | ||
195 | #endif | ||
196 | rgb_matrix_driver.set_color(index, red, green, blue); | ||
197 | } | ||
184 | 198 | ||
185 | void rgb_matrix_set_color_all(uint8_t red, uint8_t green, uint8_t blue) { rgb_matrix_driver.set_color_all(red, green, blue); } | 199 | void rgb_matrix_set_color_all(uint8_t red, uint8_t green, uint8_t blue) { |
200 | #if defined(RGB_MATRIX_ENABLE) && defined(RGB_MATRIX_SPLIT) | ||
201 | for (uint8_t i = 0; i < DRIVER_LED_TOTAL; i++) rgb_matrix_set_color(i, red, green, blue); | ||
202 | #else | ||
203 | rgb_matrix_driver.set_color_all(red, green, blue); | ||
204 | #endif | ||
205 | } | ||
186 | 206 | ||
187 | void process_rgb_matrix(uint8_t row, uint8_t col, bool pressed) { | 207 | void process_rgb_matrix(uint8_t row, uint8_t col, bool pressed) { |
188 | #ifndef RGB_MATRIX_SPLIT | 208 | #ifndef RGB_MATRIX_SPLIT |
@@ -315,6 +335,10 @@ static void rgb_task_start(void) { | |||
315 | static void rgb_task_render(uint8_t effect) { | 335 | static void rgb_task_render(uint8_t effect) { |
316 | bool rendering = false; | 336 | bool rendering = false; |
317 | rgb_effect_params.init = (effect != rgb_last_effect) || (rgb_matrix_config.enable != rgb_last_enable); | 337 | rgb_effect_params.init = (effect != rgb_last_effect) || (rgb_matrix_config.enable != rgb_last_enable); |
338 | if (rgb_effect_params.flags != rgb_matrix_config.flags) { | ||
339 | rgb_effect_params.flags = rgb_matrix_config.flags; | ||
340 | rgb_matrix_set_color_all(0, 0, 0); | ||
341 | } | ||
318 | 342 | ||
319 | // each effect can opt to do calculations | 343 | // each effect can opt to do calculations |
320 | // and/or request PWM buffer updates. | 344 | // and/or request PWM buffer updates. |
@@ -618,6 +642,6 @@ void rgb_matrix_decrease_speed_helper(bool write_to_eeprom) { rgb_matrix_set_spe | |||
618 | void rgb_matrix_decrease_speed_noeeprom(void) { rgb_matrix_decrease_speed_helper(false); } | 642 | void rgb_matrix_decrease_speed_noeeprom(void) { rgb_matrix_decrease_speed_helper(false); } |
619 | void rgb_matrix_decrease_speed(void) { rgb_matrix_decrease_speed_helper(true); } | 643 | void rgb_matrix_decrease_speed(void) { rgb_matrix_decrease_speed_helper(true); } |
620 | 644 | ||
621 | led_flags_t rgb_matrix_get_flags(void) { return rgb_effect_params.flags; } | 645 | led_flags_t rgb_matrix_get_flags(void) { return rgb_matrix_config.flags; } |
622 | 646 | ||
623 | void rgb_matrix_set_flags(led_flags_t flags) { rgb_effect_params.flags = flags; } | 647 | void rgb_matrix_set_flags(led_flags_t flags) { rgb_matrix_config.flags = flags; } |
diff --git a/quantum/rgb_matrix_types.h b/quantum/rgb_matrix_types.h index 7b8171fb2..1a37922af 100644 --- a/quantum/rgb_matrix_types.h +++ b/quantum/rgb_matrix_types.h | |||
@@ -85,10 +85,11 @@ typedef struct PACKED { | |||
85 | typedef union { | 85 | typedef union { |
86 | uint32_t raw; | 86 | uint32_t raw; |
87 | struct PACKED { | 87 | struct PACKED { |
88 | uint8_t enable : 2; | 88 | uint8_t enable : 2; |
89 | uint8_t mode : 6; | 89 | uint8_t mode : 6; |
90 | HSV hsv; | 90 | HSV hsv; |
91 | uint8_t speed; // EECONFIG needs to be increased to support this | 91 | uint8_t speed; // EECONFIG needs to be increased to support this |
92 | led_flags_t flags; | ||
92 | }; | 93 | }; |
93 | } rgb_config_t; | 94 | } rgb_config_t; |
94 | 95 | ||
diff --git a/quantum/split_common/split_util.c b/quantum/split_common/split_util.c index 2ae44e6e1..9e75e19ce 100644 --- a/quantum/split_common/split_util.c +++ b/quantum/split_common/split_util.c | |||
@@ -1,3 +1,18 @@ | |||
1 | /* Copyright 2021 QMK | ||
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 3 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 | */ | ||
1 | #include "split_util.h" | 16 | #include "split_util.h" |
2 | #include "matrix.h" | 17 | #include "matrix.h" |
3 | #include "keyboard.h" | 18 | #include "keyboard.h" |
@@ -6,14 +21,7 @@ | |||
6 | #include "transport.h" | 21 | #include "transport.h" |
7 | #include "quantum.h" | 22 | #include "quantum.h" |
8 | #include "wait.h" | 23 | #include "wait.h" |
9 | 24 | #include "usb_util.h" | |
10 | #ifdef PROTOCOL_LUFA | ||
11 | # include <LUFA/Drivers/USB/USB.h> | ||
12 | #endif | ||
13 | |||
14 | #ifdef PROTOCOL_VUSB | ||
15 | # include <usbdrv/usbdrv.h> | ||
16 | #endif | ||
17 | 25 | ||
18 | #ifdef EE_HANDS | 26 | #ifdef EE_HANDS |
19 | # include "eeconfig.h" | 27 | # include "eeconfig.h" |
@@ -31,56 +39,21 @@ | |||
31 | # define SPLIT_USB_TIMEOUT_POLL 10 | 39 | # define SPLIT_USB_TIMEOUT_POLL 10 |
32 | #endif | 40 | #endif |
33 | 41 | ||
34 | #ifdef PROTOCOL_CHIBIOS | ||
35 | # define SPLIT_USB_DETECT // Force this on for now | ||
36 | #endif | ||
37 | |||
38 | volatile bool isLeftHand = true; | 42 | volatile bool isLeftHand = true; |
39 | 43 | ||
40 | #if defined(SPLIT_USB_DETECT) | 44 | #if defined(SPLIT_USB_DETECT) |
41 | # if defined(PROTOCOL_LUFA) | 45 | static bool usbIsActive(void) { |
42 | static inline bool usbHasActiveConnection(void) { return USB_Device_IsAddressSet(); } | ||
43 | static inline void usbDisable(void) { | ||
44 | USB_Disable(); | ||
45 | USB_DeviceState = DEVICE_STATE_Unattached; | ||
46 | } | ||
47 | # elif defined(PROTOCOL_CHIBIOS) | ||
48 | static inline bool usbHasActiveConnection(void) { return usbGetDriverStateI(&USBD1) == USB_ACTIVE; } | ||
49 | static inline void usbDisable(void) { usbStop(&USBD1); } | ||
50 | # elif defined(PROTOCOL_VUSB) | ||
51 | static inline bool usbHasActiveConnection(void) { | ||
52 | usbPoll(); | ||
53 | return usbConfiguration; | ||
54 | } | ||
55 | static inline void usbDisable(void) { usbDeviceDisconnect(); } | ||
56 | # else | ||
57 | static inline bool usbHasActiveConnection(void) { return true; } | ||
58 | static inline void usbDisable(void) {} | ||
59 | # endif | ||
60 | |||
61 | bool usbIsActive(void) { | ||
62 | for (uint8_t i = 0; i < (SPLIT_USB_TIMEOUT / SPLIT_USB_TIMEOUT_POLL); i++) { | 46 | for (uint8_t i = 0; i < (SPLIT_USB_TIMEOUT / SPLIT_USB_TIMEOUT_POLL); i++) { |
63 | // This will return true if a USB connection has been established | 47 | // This will return true if a USB connection has been established |
64 | if (usbHasActiveConnection()) { | 48 | if (usb_connected_state()) { |
65 | return true; | 49 | return true; |
66 | } | 50 | } |
67 | wait_ms(SPLIT_USB_TIMEOUT_POLL); | 51 | wait_ms(SPLIT_USB_TIMEOUT_POLL); |
68 | } | 52 | } |
69 | |||
70 | // Avoid NO_USB_STARTUP_CHECK - Disable USB as the previous checks seem to enable it somehow | ||
71 | usbDisable(); | ||
72 | |||
73 | return false; | 53 | return false; |
74 | } | 54 | } |
75 | #elif defined(PROTOCOL_LUFA) && defined(OTGPADE) | ||
76 | static inline bool usbIsActive(void) { | ||
77 | USB_OTGPAD_On(); // enables VBUS pad | ||
78 | wait_us(5); | ||
79 | |||
80 | return USB_VBUS_GetStatus(); // checks state of VBUS | ||
81 | } | ||
82 | #else | 55 | #else |
83 | static inline bool usbIsActive(void) { return true; } | 56 | static inline bool usbIsActive(void) { return usb_vbus_state(); } |
84 | #endif | 57 | #endif |
85 | 58 | ||
86 | #ifdef SPLIT_HAND_MATRIX_GRID | 59 | #ifdef SPLIT_HAND_MATRIX_GRID |
@@ -126,6 +99,11 @@ __attribute__((weak)) bool is_keyboard_master(void) { | |||
126 | // only check once, as this is called often | 99 | // only check once, as this is called often |
127 | if (usbstate == UNKNOWN) { | 100 | if (usbstate == UNKNOWN) { |
128 | usbstate = usbIsActive() ? MASTER : SLAVE; | 101 | usbstate = usbIsActive() ? MASTER : SLAVE; |
102 | |||
103 | // Avoid NO_USB_STARTUP_CHECK - Disable USB as the previous checks seem to enable it somehow | ||
104 | if (usbstate == SLAVE) { | ||
105 | usb_disable(); | ||
106 | } | ||
129 | } | 107 | } |
130 | 108 | ||
131 | return (usbstate == MASTER); | 109 | return (usbstate == MASTER); |
diff --git a/quantum/split_common/transport.c b/quantum/split_common/transport.c index 61b61ea08..27a1c0d3a 100644 --- a/quantum/split_common/transport.c +++ b/quantum/split_common/transport.c | |||
@@ -22,6 +22,10 @@ static pin_t encoders_pad[] = ENCODERS_PAD_A; | |||
22 | # define NUMBER_OF_ENCODERS (sizeof(encoders_pad) / sizeof(pin_t)) | 22 | # define NUMBER_OF_ENCODERS (sizeof(encoders_pad) / sizeof(pin_t)) |
23 | #endif | 23 | #endif |
24 | 24 | ||
25 | #if defined(RGB_MATRIX_ENABLE) && defined(RGB_MATRIX_SPLIT) | ||
26 | # include "rgb_matrix.h" | ||
27 | #endif | ||
28 | |||
25 | #if defined(USE_I2C) | 29 | #if defined(USE_I2C) |
26 | 30 | ||
27 | # include "i2c_master.h" | 31 | # include "i2c_master.h" |
@@ -54,6 +58,10 @@ typedef struct _I2C_slave_buffer_t { | |||
54 | # ifdef WPM_ENABLE | 58 | # ifdef WPM_ENABLE |
55 | uint8_t current_wpm; | 59 | uint8_t current_wpm; |
56 | # endif | 60 | # endif |
61 | # if defined(RGB_MATRIX_ENABLE) && defined(RGB_MATRIX_SPLIT) | ||
62 | rgb_config_t rgb_matrix; | ||
63 | bool rgb_suspend_state; | ||
64 | # endif | ||
57 | } I2C_slave_buffer_t; | 65 | } I2C_slave_buffer_t; |
58 | 66 | ||
59 | static I2C_slave_buffer_t *const i2c_buffer = (I2C_slave_buffer_t *)i2c_slave_reg; | 67 | static I2C_slave_buffer_t *const i2c_buffer = (I2C_slave_buffer_t *)i2c_slave_reg; |
@@ -68,6 +76,8 @@ static I2C_slave_buffer_t *const i2c_buffer = (I2C_slave_buffer_t *)i2c_slave_re | |||
68 | # define I2C_RGB_START offsetof(I2C_slave_buffer_t, rgblight_sync) | 76 | # define I2C_RGB_START offsetof(I2C_slave_buffer_t, rgblight_sync) |
69 | # define I2C_ENCODER_START offsetof(I2C_slave_buffer_t, encoder_state) | 77 | # define I2C_ENCODER_START offsetof(I2C_slave_buffer_t, encoder_state) |
70 | # define I2C_WPM_START offsetof(I2C_slave_buffer_t, current_wpm) | 78 | # define I2C_WPM_START offsetof(I2C_slave_buffer_t, current_wpm) |
79 | # define I2C_RGB_MATRIX_START offsetof(I2C_slave_buffer_t, rgb_matrix) | ||
80 | # define I2C_RGB_SUSPEND_START offsetof(I2C_slave_buffer_t, rgb_suspend_state) | ||
71 | 81 | ||
72 | # define TIMEOUT 100 | 82 | # define TIMEOUT 100 |
73 | 83 | ||
@@ -141,6 +151,11 @@ bool transport_master(matrix_row_t master_matrix[], matrix_row_t slave_matrix[]) | |||
141 | # endif | 151 | # endif |
142 | # endif | 152 | # endif |
143 | 153 | ||
154 | # if defined(RGB_MATRIX_ENABLE) && defined(RGB_MATRIX_SPLIT) | ||
155 | i2c_writeReg(SLAVE_I2C_ADDRESS, I2C_RGB_MATRIX_START, (void *)rgb_matrix_config, sizeof(i2c_buffer->rgb_matrix), TIMEOUT); | ||
156 | i2c_writeReg(SLAVE_I2C_ADDRESS, I2C_RGB_SUSPEND_START, (void *)g_suspend_state, sizeof(i2c_buffer->rgb_suspend_state), TIMEOUT); | ||
157 | # endif | ||
158 | |||
144 | # ifndef DISABLE_SYNC_TIMER | 159 | # ifndef DISABLE_SYNC_TIMER |
145 | i2c_buffer->sync_timer = sync_timer_read32() + SYNC_TIMER_OFFSET; | 160 | i2c_buffer->sync_timer = sync_timer_read32() + SYNC_TIMER_OFFSET; |
146 | i2c_writeReg(SLAVE_I2C_ADDRESS, I2C_SYNC_TIME_START, (void *)&i2c_buffer->sync_timer, sizeof(i2c_buffer->sync_timer), TIMEOUT); | 161 | i2c_writeReg(SLAVE_I2C_ADDRESS, I2C_SYNC_TIME_START, (void *)&i2c_buffer->sync_timer, sizeof(i2c_buffer->sync_timer), TIMEOUT); |
@@ -186,6 +201,11 @@ void transport_slave(matrix_row_t master_matrix[], matrix_row_t slave_matrix[]) | |||
186 | set_oneshot_mods(i2c_buffer->oneshot_mods); | 201 | set_oneshot_mods(i2c_buffer->oneshot_mods); |
187 | # endif | 202 | # endif |
188 | # endif | 203 | # endif |
204 | |||
205 | # if defined(RGB_MATRIX_ENABLE) && defined(RGB_MATRIX_SPLIT) | ||
206 | memcpy((void *)i2c_buffer->rgb_matrix, (void *)rgb_matrix_config, sizeof(i2c_buffer->rgb_matrix)); | ||
207 | memcpy((void *)i2c_buffer->rgb_suspend_state, (void *)g_suspend_state, sizeof(i2c_buffer->rgb_suspend_state)); | ||
208 | # endif | ||
189 | } | 209 | } |
190 | 210 | ||
191 | void transport_master_init(void) { i2c_init(); } | 211 | void transport_master_init(void) { i2c_init(); } |
@@ -226,6 +246,10 @@ typedef struct _Serial_m2s_buffer_t { | |||
226 | # ifdef WPM_ENABLE | 246 | # ifdef WPM_ENABLE |
227 | uint8_t current_wpm; | 247 | uint8_t current_wpm; |
228 | # endif | 248 | # endif |
249 | # if defined(RGB_MATRIX_ENABLE) && defined(RGB_MATRIX_SPLIT) | ||
250 | rgb_config_t rgb_matrix; | ||
251 | bool rgb_suspend_state; | ||
252 | # endif | ||
229 | } Serial_m2s_buffer_t; | 253 | } Serial_m2s_buffer_t; |
230 | 254 | ||
231 | # if defined(RGBLIGHT_ENABLE) && defined(RGBLIGHT_SPLIT) | 255 | # if defined(RGBLIGHT_ENABLE) && defined(RGBLIGHT_SPLIT) |
@@ -333,18 +357,24 @@ bool transport_master(matrix_row_t master_matrix[], matrix_row_t slave_matrix[]) | |||
333 | 357 | ||
334 | # ifdef WPM_ENABLE | 358 | # ifdef WPM_ENABLE |
335 | // Write wpm to slave | 359 | // Write wpm to slave |
336 | serial_m2s_buffer.current_wpm = get_current_wpm(); | 360 | serial_m2s_buffer.current_wpm = get_current_wpm(); |
337 | # endif | 361 | # endif |
338 | 362 | ||
339 | # ifdef SPLIT_MODS_ENABLE | 363 | # ifdef SPLIT_MODS_ENABLE |
340 | serial_m2s_buffer.real_mods = get_mods(); | 364 | serial_m2s_buffer.real_mods = get_mods(); |
341 | serial_m2s_buffer.weak_mods = get_weak_mods(); | 365 | serial_m2s_buffer.weak_mods = get_weak_mods(); |
342 | # ifndef NO_ACTION_ONESHOT | 366 | # ifndef NO_ACTION_ONESHOT |
343 | serial_m2s_buffer.oneshot_mods = get_oneshot_mods(); | 367 | serial_m2s_buffer.oneshot_mods = get_oneshot_mods(); |
344 | # endif | 368 | # endif |
345 | # endif | 369 | # endif |
370 | |||
371 | # if defined(RGB_MATRIX_ENABLE) && defined(RGB_MATRIX_SPLIT) | ||
372 | serial_m2s_buffer.rgb_matrix = rgb_matrix_config; | ||
373 | serial_m2s_buffer.rgb_suspend_state = g_suspend_state; | ||
374 | # endif | ||
375 | |||
346 | # ifndef DISABLE_SYNC_TIMER | 376 | # ifndef DISABLE_SYNC_TIMER |
347 | serial_m2s_buffer.sync_timer = sync_timer_read32() + SYNC_TIMER_OFFSET; | 377 | serial_m2s_buffer.sync_timer = sync_timer_read32() + SYNC_TIMER_OFFSET; |
348 | # endif | 378 | # endif |
349 | return true; | 379 | return true; |
350 | } | 380 | } |
@@ -381,6 +411,11 @@ void transport_slave(matrix_row_t master_matrix[], matrix_row_t slave_matrix[]) | |||
381 | set_oneshot_mods(serial_m2s_buffer.oneshot_mods); | 411 | set_oneshot_mods(serial_m2s_buffer.oneshot_mods); |
382 | # endif | 412 | # endif |
383 | # endif | 413 | # endif |
414 | |||
415 | # if defined(RGB_MATRIX_ENABLE) && defined(RGB_MATRIX_SPLIT) | ||
416 | rgb_matrix_config = serial_m2s_buffer.rgb_matrix; | ||
417 | g_suspend_state = serial_m2s_buffer.rgb_suspend_state; | ||
418 | # endif | ||
384 | } | 419 | } |
385 | 420 | ||
386 | #endif | 421 | #endif |