diff options
Diffstat (limited to 'keyboards/crkbd/r2g/r2g.c')
-rw-r--r-- | keyboards/crkbd/r2g/r2g.c | 240 |
1 files changed, 240 insertions, 0 deletions
diff --git a/keyboards/crkbd/r2g/r2g.c b/keyboards/crkbd/r2g/r2g.c new file mode 100644 index 000000000..7fb95c043 --- /dev/null +++ b/keyboards/crkbd/r2g/r2g.c | |||
@@ -0,0 +1,240 @@ | |||
1 | /* | ||
2 | Copyright 2019 @foostan | ||
3 | Copyright 2020 Drashna Jaelre <@drashna> | ||
4 | Copyright 2021 Elliot Powell @e11i0t23 | ||
5 | |||
6 | This program is free software: you can redistribute it and/or modify | ||
7 | it under the terms of the GNU General Public License as published by | ||
8 | the Free Software Foundation, either version 2 of the License, or | ||
9 | (at your option) any later version. | ||
10 | |||
11 | This program is distributed in the hope that it will be useful, | ||
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
14 | GNU General Public License for more details. | ||
15 | |||
16 | You should have received a copy of the GNU General Public License | ||
17 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
18 | */ | ||
19 | #include "r2g.h" | ||
20 | |||
21 | #ifdef RGB_MATRIX_ENABLE | ||
22 | |||
23 | // Logical Layout | ||
24 | // Columns | ||
25 | // Left | ||
26 | // 0 1 2 3 4 5 | ||
27 | // ROWS | ||
28 | // 25 24 19 18 11 10 0 | ||
29 | // 03 02 01 | ||
30 | // 26 23 20 17 12 09 1 | ||
31 | // 04 05 06 | ||
32 | // 27 22 21 16 13 08 2 | ||
33 | // | ||
34 | // 15 14 07 3 | ||
35 | // | ||
36 | // Right | ||
37 | // 0 1 2 3 4 5 | ||
38 | // ROWS | ||
39 | // 25 24 19 18 11 10 4 | ||
40 | // 03 02 01 | ||
41 | // 26 23 20 17 12 09 5 | ||
42 | // 04 05 06 | ||
43 | // 27 22 21 16 13 08 6 | ||
44 | // | ||
45 | // 15 14 07 7 | ||
46 | // | ||
47 | // Physical Layout | ||
48 | // Columns | ||
49 | // 0 1 2 3 4 5 6 7 8 9 10 11 12 13 | ||
50 | // ROWS | ||
51 | // 25 24 19 18 11 10 10 11 18 19 24 25 0 | ||
52 | // 03 02 01 01 02 03 | ||
53 | // 26 23 20 17 12 09 09 12 17 20 23 26 1 | ||
54 | // 04 04 | ||
55 | // 27 22 21 16 13 08 08 13 16 21 22 27 2 | ||
56 | // 05 06 06 05 | ||
57 | // 15 14 07 07 14 15 3 | ||
58 | |||
59 | led_config_t g_led_config = { { | ||
60 | { 24, 23, 18, 17, 10, 9 }, | ||
61 | { 25, 22, 19, 16, 11, 8 }, | ||
62 | { 26, 21, 20, 15, 12, 7 }, | ||
63 | { NO_LED, NO_LED, NO_LED, 14, 13, 6 }, | ||
64 | { 51, 50, 45, 44, 37, 36 }, | ||
65 | { 52, 49, 46, 43, 38, 35 }, | ||
66 | { 53, 48, 47, 42, 39, 34 }, | ||
67 | { NO_LED, NO_LED, NO_LED, 41, 40, 33 } | ||
68 | }, { | ||
69 | { 85, 16 }, { 50, 13 }, { 16, 20 }, { 16, 38 }, { 50, 48 }, { 85, 52 }, { 95, 63 }, | ||
70 | { 85, 39 }, { 85, 21 }, { 85, 4 }, { 68, 2 }, { 68, 19 }, { 68, 37 }, { 80, 58 }, | ||
71 | { 60, 55 }, { 50, 35 }, { 50, 13 }, { 50, 0 }, { 33, 3 }, { 33, 20 }, { 33, 37 }, | ||
72 | { 16, 42 }, { 16, 24 }, { 16, 7 }, { 0, 7 }, { 0, 24 }, { 0, 41 }, { 139, 16 }, | ||
73 | { 174, 13 }, { 208, 20 }, { 208, 38 }, { 174, 48 }, { 139, 52 }, { 129, 63 }, { 139, 39 }, | ||
74 | { 139, 21 }, { 139, 4 }, { 156, 2 }, { 156, 19 }, { 156, 37 }, { 144, 58 }, { 164, 55 }, | ||
75 | { 174, 35 }, { 174, 13 }, { 174, 0 }, { 191, 3 }, { 191, 20 }, { 191, 37 }, { 208, 42 }, | ||
76 | { 208, 24 }, { 208, 7 }, { 224, 7 }, { 224, 24 }, { 224, 41 } | ||
77 | }, { | ||
78 | 2, 2, 2, 2, 2, 2, 1, | ||
79 | 4, 4, 4, 4, 4, 4, 1, | ||
80 | 1, 4, 4, 4, 4, 4, 4, | ||
81 | 4, 4, 4, 1, 1, 1, 2, | ||
82 | 2, 2, 2, 2, 2, 1, 4, | ||
83 | 4, 4, 4, 4, 4, 1, 1, | ||
84 | 4, 4, 4, 4, 4, 4, 4, | ||
85 | 4, 4, 1, 1, 1 | ||
86 | } }; | ||
87 | |||
88 | #endif | ||
89 | |||
90 | #ifdef OLED_ENABLE | ||
91 | |||
92 | oled_rotation_t oled_init_kb(oled_rotation_t rotation) { | ||
93 | if (!is_keyboard_master()) { | ||
94 | return OLED_ROTATION_180; // flips the display 180 degrees if offhand | ||
95 | } | ||
96 | return rotation; | ||
97 | } | ||
98 | |||
99 | enum Layers{ | ||
100 | L_BASE, L_LOWER, L_RAISE, L_ADJUST | ||
101 | }; | ||
102 | |||
103 | void oled_render_layer_state_r2g(void) { | ||
104 | oled_write_P(PSTR("Layer: "), false); | ||
105 | switch (get_highest_layer(layer_state)) { | ||
106 | case L_BASE: | ||
107 | oled_write_ln_P(PSTR("Default"), false); | ||
108 | break; | ||
109 | case L_LOWER: | ||
110 | oled_write_ln_P(PSTR("Lower"), false); | ||
111 | break; | ||
112 | case L_RAISE: | ||
113 | oled_write_ln_P(PSTR("Raise"), false); | ||
114 | break; | ||
115 | case L_ADJUST: | ||
116 | oled_write_ln_P(PSTR("Adjust"), false); | ||
117 | break; | ||
118 | } | ||
119 | } | ||
120 | |||
121 | //char keylog_str_r2g[24] = {}; | ||
122 | |||
123 | const char code_to_name_r2g[60] = { | ||
124 | ' ', ' ', ' ', ' ', 'a', 'b', 'c', 'd', 'e', 'f', | ||
125 | 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', | ||
126 | 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', | ||
127 | '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', | ||
128 | 'R', 'E', 'B', 'T', '_', '-', '=', '[', ']', '\\', | ||
129 | '#', ';', '\'', '`', ',', '.', '/', ' ', ' ', ' '}; | ||
130 | |||
131 | char key_name_r2g = ' '; | ||
132 | uint16_t last_keycode_r2g; | ||
133 | uint8_t last_row_r2g; | ||
134 | uint8_t last_col_r2g; | ||
135 | |||
136 | void set_keylog_r2g(uint16_t keycode, keyrecord_t *record) { | ||
137 | key_name_r2g = ' '; | ||
138 | last_keycode_r2g = keycode; | ||
139 | if ((keycode >= QK_MOD_TAP && keycode <= QK_MOD_TAP_MAX) || | ||
140 | (keycode >= QK_LAYER_TAP && keycode <= QK_LAYER_TAP_MAX)) { last_keycode_r2g = keycode & 0xFF; } | ||
141 | if (keycode < 60) { | ||
142 | key_name_r2g = code_to_name_r2g[keycode]; | ||
143 | } | ||
144 | last_row_r2g = record->event.key.row; | ||
145 | last_col_r2g = record->event.key.col; | ||
146 | } | ||
147 | |||
148 | const char *depad_str(const char *depad_str, char depad_char) { | ||
149 | while (*depad_str == depad_char) ++depad_str; | ||
150 | return depad_str; | ||
151 | } | ||
152 | |||
153 | void oled_render_keylog_r2g(void) { | ||
154 | //oled_write(keylog_str_r2g, false); | ||
155 | const char *last_row_r2g_str = get_u8_str(last_row_r2g, ' '); | ||
156 | oled_write(depad_str(last_row_r2g_str, ' '), false); | ||
157 | oled_write_P(PSTR("x"), false); | ||
158 | const char *last_col_r2g_str = get_u8_str(last_col_r2g, ' '); | ||
159 | oled_write(depad_str(last_col_r2g_str, ' '), false); | ||
160 | oled_write_P(PSTR(", k"), false); | ||
161 | const char *last_keycode_r2g_str = get_u16_str(last_keycode_r2g, ' '); | ||
162 | oled_write(depad_str(last_keycode_r2g_str, ' '), false); | ||
163 | oled_write_P(PSTR(":"), false); | ||
164 | oled_write_char(key_name_r2g, false); | ||
165 | } | ||
166 | |||
167 | void render_bootmagic_status_r2g(bool status) { | ||
168 | /* Show Ctrl-Gui Swap options */ | ||
169 | static const char PROGMEM logo[][2][3] = { | ||
170 | {{0x97, 0x98, 0}, {0xb7, 0xb8, 0}}, | ||
171 | {{0x95, 0x96, 0}, {0xb5, 0xb6, 0}}, | ||
172 | }; | ||
173 | if (status) { | ||
174 | oled_write_ln_P(logo[0][0], false); | ||
175 | oled_write_ln_P(logo[0][1], false); | ||
176 | } else { | ||
177 | oled_write_ln_P(logo[1][0], false); | ||
178 | oled_write_ln_P(logo[1][1], false); | ||
179 | } | ||
180 | } | ||
181 | |||
182 | void oled_render_logo_r2g(void) { | ||
183 | static const char PROGMEM mb_logo[] = { | ||
184 | 0x00, 0x00, 0x00, 0x00, 0x00, 0xfe, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, | ||
185 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, | ||
186 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x0f, 0x0f, 0x0f, 0x0f, | ||
187 | 0x0f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, | ||
188 | 0xff, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
189 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
190 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
191 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
192 | 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x83, 0x83, 0x83, 0x83, 0x83, 0xff, 0xff, | ||
193 | 0x83, 0x83, 0x83, 0x83, 0xff, 0xff, 0x83, 0x83, 0x83, 0x83, 0x83, 0xff, 0xff, 0x83, 0x83, 0x83, | ||
194 | 0x83, 0xff, 0xff, 0x83, 0x83, 0x83, 0x83, 0x83, 0xff, 0xff, 0xff, 0xff, 0x82, 0x82, 0x82, 0x82, | ||
195 | 0x82, 0xff, 0xff, 0x83, 0x83, 0x83, 0x83, 0xff, 0xff, 0x83, 0x83, 0x83, 0x83, 0x83, 0xff, 0xff, | ||
196 | 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0xfc, 0xfc, 0xfc, | ||
197 | 0x9c, 0x9c, 0xfc, 0xfc, 0xf8, 0xf8, 0x70, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x78, 0x7c, 0x3c, | ||
198 | 0x9c, 0xfc, 0xfc, 0xf8, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0xf0, 0xf8, 0xf8, 0x3c, 0x3c, | ||
199 | 0x9c, 0xbc, 0xfc, 0xb8, 0xb8, 0xa0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
200 | 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x41, 0x41, 0x41, 0x41, 0x41, 0xff, 0xff, | ||
201 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x41, 0x41, 0x41, 0x41, 0x41, 0xff, 0xff, 0xff, 0xff, 0xff, | ||
202 | 0xff, 0xff, 0xff, 0x41, 0x41, 0x41, 0x41, 0x41, 0xff, 0xff, 0xff, 0xff, 0x41, 0x41, 0x41, 0x41, | ||
203 | 0x41, 0xff, 0xff, 0x7f, 0x7f, 0x7f, 0x7f, 0xff, 0xff, 0x41, 0x41, 0x41, 0x41, 0x41, 0xff, 0xff, | ||
204 | 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3f, 0x3f, 0x3f, 0x3f, | ||
205 | 0x03, 0x07, 0x0f, 0x3f, 0x3f, 0x3e, 0x38, 0x20, 0x00, 0x00, 0x00, 0x00, 0x38, 0x3c, 0x3e, 0x3f, | ||
206 | 0x3f, 0x3f, 0x3b, 0x39, 0x38, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x0f, 0x1f, 0x3f, 0x3c, 0x38, | ||
207 | 0x3b, 0x3b, 0x3f, 0x1f, 0x1f, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
208 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x7f, 0xff, 0xff, 0xff, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xff, 0xff, | ||
209 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xff, 0xff, 0xff, 0xff, 0xff, | ||
210 | 0xff, 0xff, 0xff, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xff, 0xff, 0xff, 0xff, 0xf0, 0xf0, 0xf0, 0xf0, | ||
211 | 0xf0, 0xff, 0xff, 0xf0, 0xf0, 0xf0, 0xf0, 0xff, 0xff, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xff, 0xff, | ||
212 | 0xff, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
213 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
214 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
215 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 | ||
216 | }; | ||
217 | oled_write_raw_P(mb_logo, sizeof(mb_logo)); | ||
218 | //oled_set_cursor(oled_max_chars()/2,oled_max_lines()/2); | ||
219 | //oled_write_P(PSTR("R2G"), false); | ||
220 | } | ||
221 | |||
222 | bool oled_task_kb(void) { | ||
223 | if (!oled_task_user()) { return false; } | ||
224 | if (is_keyboard_master()) { | ||
225 | oled_render_layer_state_r2g(); | ||
226 | oled_render_keylog_r2g(); | ||
227 | } else { | ||
228 | oled_render_logo_r2g(); | ||
229 | } | ||
230 | return false; | ||
231 | } | ||
232 | |||
233 | bool process_record_kb(uint16_t keycode, keyrecord_t *record) { | ||
234 | if (record->event.pressed) { | ||
235 | set_keylog_r2g(keycode, record); | ||
236 | } | ||
237 | return process_record_user(keycode, record); | ||
238 | } | ||
239 | #endif // OLED_ENABLE | ||
240 | |||