aboutsummaryrefslogtreecommitdiff
path: root/keyboards/massdrop/ctrl/keymaps/foxx1337/keymap.c
diff options
context:
space:
mode:
Diffstat (limited to 'keyboards/massdrop/ctrl/keymaps/foxx1337/keymap.c')
-rw-r--r--keyboards/massdrop/ctrl/keymaps/foxx1337/keymap.c268
1 files changed, 268 insertions, 0 deletions
diff --git a/keyboards/massdrop/ctrl/keymaps/foxx1337/keymap.c b/keyboards/massdrop/ctrl/keymaps/foxx1337/keymap.c
new file mode 100644
index 000000000..299251e45
--- /dev/null
+++ b/keyboards/massdrop/ctrl/keymaps/foxx1337/keymap.c
@@ -0,0 +1,268 @@
1/*
2 * Copyright 2021 foxx1337 at yahoo dot com
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#include QMK_KEYBOARD_H
19#include "hid_protocol.h"
20
21enum ctrl_keycodes {
22 U_T_AUTO = SAFE_RANGE, //USB Extra Port Toggle Auto Detect / Always Active
23 U_T_AGCR, //USB Toggle Automatic GCR control
24 DBG_TOG, //DEBUG Toggle On / Off
25 DBG_MTRX, //DEBUG Toggle Matrix Prints
26 DBG_KBD, //DEBUG Toggle Keyboard Prints
27 DBG_MOU, //DEBUG Toggle Mouse Prints
28 MD_BOOT, //Restart into bootloader after hold timeout
29};
30
31#define TIMEOUT_ACTIVITY 300000 // 300 seconds before lights go off
32
33uint32_t time_last_activity;
34bool is_led_timeout;
35led_flags_t led_state;
36
37keymap_config_t keymap_config;
38
39const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
40 [0] = LAYOUT(
41 KC_ESC, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, KC_PSCR, KC_SLCK, KC_PAUS, \
42 KC_GRV, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_MINS, KC_EQL, KC_BSPC, KC_INS, KC_HOME, KC_PGUP, \
43 KC_TAB, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_LBRC, KC_RBRC, KC_BSLS, KC_DEL, KC_END, KC_PGDN, \
44 KC_CAPS, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN, KC_QUOT, KC_ENT, \
45 KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_RSFT, KC_UP, \
46 KC_LCTL, KC_LGUI, KC_LALT, KC_SPC, KC_RALT, MO(1), KC_APP, KC_RCTL, KC_LEFT, KC_DOWN, KC_RGHT \
47 ),
48 [1] = LAYOUT(
49 _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, KC_MUTE, _______, _______, \
50 _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, KC_MPLY, KC_MSTP, KC_VOLU, \
51 _______, RGB_SPD, RGB_VAI, RGB_SPI, RGB_HUI, RGB_SAI, _______, U_T_AUTO,U_T_AGCR,_______, _______, _______, _______, _______, KC_MPRV, KC_MNXT, KC_VOLD, \
52 _______, RGB_RMOD,RGB_VAD, RGB_MOD, RGB_HUD, RGB_SAD, _______, _______, _______, _______, _______, _______, _______, \
53 _______, RGB_TOG, _______, _______, _______, MD_BOOT, NK_TOGG, _______, _______, _______, _______, _______, _______, \
54 _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______ \
55 ),
56 /*
57 [X] = LAYOUT(
58 _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, \
59 _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, \
60 _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, \
61 _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, \
62 _______, _______, _______, _______, _______, _______, NK_TOGG, _______, _______, _______, _______, _______, _______, \
63 _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______ \
64 ),
65 */
66};
67
68void change_led_state(bool is_off) {
69 is_led_timeout = is_off;
70
71 if (is_led_timeout) {
72 led_state = rgb_matrix_get_flags();
73 if (led_state != LED_FLAG_NONE) {
74 rgb_matrix_set_flags(LED_FLAG_NONE);
75 rgb_matrix_disable_noeeprom();
76 }
77 } else {
78 if (led_state != LED_FLAG_NONE) {
79 rgb_matrix_set_flags(led_state);
80 rgb_matrix_enable_noeeprom();
81 }
82 }
83}
84
85// Runs just one time when the keyboard initializes.
86void matrix_init_user(void) {
87 time_last_activity = timer_read32();
88};
89
90// Runs constantly in the background, in a loop.
91void matrix_scan_user(void) {
92 if (!is_led_timeout && timer_elapsed32(time_last_activity) > TIMEOUT_ACTIVITY) {
93 change_led_state(true);
94 }
95};
96
97#define MODS_SHIFT (get_mods() & MOD_MASK_SHIFT)
98#define MODS_CTRL (get_mods() & MOD_MASK_CTRL)
99#define MODS_ALT (get_mods() & MOD_MASK_ALT)
100
101bool process_record_user(uint16_t keycode, keyrecord_t *record) {
102 static uint32_t key_timer;
103
104 time_last_activity = timer_read32();
105 if (is_led_timeout) {
106 change_led_state(false);
107 }
108
109 switch (keycode) {
110 case U_T_AUTO:
111 if (record->event.pressed && MODS_SHIFT && MODS_CTRL) {
112 TOGGLE_FLAG_AND_PRINT(usb_extra_manual, "USB extra port manual mode");
113 }
114 return false;
115 case U_T_AGCR:
116 if (record->event.pressed && MODS_SHIFT && MODS_CTRL) {
117 TOGGLE_FLAG_AND_PRINT(usb_gcr_auto, "USB GCR auto mode");
118 }
119 return false;
120 case DBG_TOG:
121 if (record->event.pressed) {
122 TOGGLE_FLAG_AND_PRINT(debug_enable, "Debug mode");
123 }
124 return false;
125 case DBG_MTRX:
126 if (record->event.pressed) {
127 TOGGLE_FLAG_AND_PRINT(debug_matrix, "Debug matrix");
128 }
129 return false;
130 case DBG_KBD:
131 if (record->event.pressed) {
132 TOGGLE_FLAG_AND_PRINT(debug_keyboard, "Debug keyboard");
133 }
134 return false;
135 case DBG_MOU:
136 if (record->event.pressed) {
137 TOGGLE_FLAG_AND_PRINT(debug_mouse, "Debug mouse");
138 }
139 return false;
140 case MD_BOOT:
141 if (record->event.pressed) {
142 key_timer = timer_read32();
143 } else {
144 if (timer_elapsed32(key_timer) >= 500) {
145 reset_keyboard();
146 }
147 }
148 return false;
149 case RGB_TOG:
150 if (record->event.pressed) {
151 switch (rgb_matrix_get_flags()) {
152 case LED_FLAG_ALL: {
153 rgb_matrix_set_flags(LED_FLAG_KEYLIGHT | LED_FLAG_MODIFIER);
154 rgb_matrix_set_color_all(0, 0, 0);
155 }
156 break;
157 case LED_FLAG_KEYLIGHT | LED_FLAG_MODIFIER: {
158 rgb_matrix_set_flags(LED_FLAG_UNDERGLOW);
159 rgb_matrix_set_color_all(0, 0, 0);
160 }
161 break;
162 case LED_FLAG_UNDERGLOW: {
163 rgb_matrix_set_flags(LED_FLAG_NONE);
164 rgb_matrix_disable_noeeprom();
165 }
166 break;
167 default: {
168 rgb_matrix_set_flags(LED_FLAG_ALL);
169 rgb_matrix_enable_noeeprom();
170 }
171 break;
172 }
173 }
174 return false;
175 default:
176 return true; //Process all other keycodes normally
177 }
178}
179
180void raw_hid_say_hello(void) {
181 const char *ctrl = CTRL_HID_GREETING_VERSION;
182 uint8_t i = 0;
183 while (ctrl[i] != 0 && i + 2 < RAW_EPSIZE) {
184 raw_hid_buffer[1 + i] = ctrl[i];
185 i++;
186 }
187 raw_hid_buffer[i] = CTRL_HID_EOM;
188}
189
190void raw_hid_lights_toggle(void) {
191 change_led_state(!is_led_timeout);
192
193 raw_hid_buffer[1] = CTRL_HID_OK;
194 raw_hid_buffer[2] = (uint8_t) is_led_timeout;
195 raw_hid_buffer[3] = CTRL_HID_EOM;
196}
197
198void raw_hid_led(uint8_t *data) {
199 //rgb_matrix_set_color(data[1], data[2], data[3], data[4]);
200 const uint8_t led = data[1];
201
202 if (led >= DRIVER_LED_TOTAL) {
203 raw_hid_buffer[1] = CTRL_HID_NOK;
204 raw_hid_buffer[2] = DRIVER_LED_TOTAL;
205 raw_hid_buffer[3] = CTRL_HID_EOM;
206 return;
207 }
208
209 rgb_matrix_led_state[led].r = data[2];
210 rgb_matrix_led_state[led].g = data[3];
211 rgb_matrix_led_state[led].b = data[4];
212
213 raw_hid_buffer[1] = CTRL_HID_OK;
214 raw_hid_buffer[2] = CTRL_HID_EOM;
215}
216
217void raw_hid_leds(uint8_t *data) {
218 const uint8_t first_led = data[1];
219 const uint8_t number_leds = data[2];
220
221 uint8_t i = 0;
222 while (i < number_leds && first_led + i < DRIVER_LED_TOTAL && i * 3 + 5 < RAW_EPSIZE) {
223 rgb_matrix_led_state[first_led + i].r = data[3 + i * 3 + 0];
224 rgb_matrix_led_state[first_led + i].g = data[3 + i * 3 + 1];
225 rgb_matrix_led_state[first_led + i].b = data[3 + i * 3 + 2];
226 i++;
227 }
228
229 raw_hid_buffer[1] = CTRL_HID_OK;
230 raw_hid_buffer[2] = i;
231 raw_hid_buffer[3] = CTRL_HID_EOM;
232}
233
234void raw_hid_rgbmatrix_mode(uint8_t *data) {
235 const uint8_t mode = data[1];
236 if (mode >= RGB_MATRIX_EFFECT_MAX) {
237 raw_hid_buffer[1] = CTRL_HID_NOK;
238 raw_hid_buffer[2] = RGB_MATRIX_EFFECT_MAX - 1;
239 raw_hid_buffer[3] = CTRL_HID_EOM;
240 return;
241 }
242 rgb_matrix_mode_noeeprom(mode);
243
244 raw_hid_buffer[1] = CTRL_HID_OK;
245 raw_hid_buffer[2] = CTRL_HID_EOM;
246}
247
248void raw_hid_receive(uint8_t *data, uint8_t length) {
249 switch (*data) {
250 case CTRL_HID_HELLO:
251 raw_hid_say_hello();
252 break;
253 case CTRL_HID_LIGHTS_TOGGLE:
254 raw_hid_lights_toggle();
255 break;
256 case CTRL_HID_LED:
257 raw_hid_led(data);
258 break;
259 case CTRL_HID_LEDS:
260 raw_hid_leds(data);
261 break;
262 case CTRL_HID_RGBMATRIX_MODE:
263 raw_hid_rgbmatrix_mode(data);
264 break;
265 }
266
267 raw_hid_perform_send();
268}