]> git.donarmstrong.com Git - qmk_firmware.git/blob - users/drashna/drashna.c
Fix enables for Haptic Feedback (#6707)
[qmk_firmware.git] / users / drashna / drashna.c
1 /*
2 Copyright 2017 Christopher Courtney <drashna@live.com> @drashna
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 "drashna.h"
19
20 userspace_config_t userspace_config;
21 #if (defined(UNICODE_ENABLE) || defined(UNICODEMAP_ENABLE) || defined(UCIS_ENABLE))
22 #    define DRASHNA_UNICODE_MODE UC_WIN
23 #else
24 // set to 2 for UC_WIN, set to 4 for UC_WINC
25 #    define DRASHNA_UNICODE_MODE 2
26 #endif
27
28
29
30 bool mod_key_press_timer(uint16_t code, uint16_t mod_code, bool pressed) {
31     static uint16_t this_timer;
32     if (pressed) {
33         this_timer = timer_read();
34     } else {
35         if (timer_elapsed(this_timer) < TAPPING_TERM) {
36             tap_code(code);
37         } else {
38             register_code(mod_code);
39             tap_code(code);
40             unregister_code(mod_code);
41         }
42     }
43     return false;
44 }
45
46 bool mod_key_press(uint16_t code, uint16_t mod_code, bool pressed, uint16_t this_timer) {
47     if (pressed) {
48         this_timer = timer_read();
49     } else {
50         if (timer_elapsed(this_timer) < TAPPING_TERM) {
51             tap_code(code);
52         } else {
53             register_code(mod_code);
54             tap_code(code);
55             unregister_code(mod_code);
56         }
57     }
58     return false;
59 }
60
61 void bootmagic_lite(void) {
62     matrix_scan();
63 #if defined(DEBOUNCING_DELAY) && DEBOUNCING_DELAY > 0
64     wait_ms(DEBOUNCING_DELAY * 2);
65 #elif defined(DEBOUNCE) && DEBOUNCE > 0
66     wait_ms(DEBOUNCE * 2);
67 #else
68     wait_ms(30);
69 #endif
70     matrix_scan();
71     if (matrix_get_row(BOOTMAGIC_LITE_ROW) & (1 << BOOTMAGIC_LITE_COLUMN)) {
72         bootloader_jump();
73     }
74 }
75
76 // Add reconfigurable functions here, for keymap customization
77 // This allows for a global, userspace functions, and continued
78 // customization of the keymap.  Use _keymap instead of _user
79 // functions in the keymaps
80 __attribute__((weak))
81 void matrix_init_keymap(void) {}
82
83 // Call user matrix init, set default RGB colors and then
84 // call the keymap's init function
85 void matrix_init_user(void) {
86     userspace_config.raw = eeconfig_read_user();
87
88 #ifdef BOOTLOADER_CATERINA
89     DDRD &= ~(1 << 5);
90     PORTD &= ~(1 << 5);
91
92     DDRB &= ~(1 << 0);
93     PORTB &= ~(1 << 0);
94 #endif
95
96 #if (defined(UNICODE_ENABLE) || defined(UNICODEMAP_ENABLE) || defined(UCIS_ENABLE))
97     set_unicode_input_mode(DRASHNA_UNICODE_MODE);
98     get_unicode_input_mode();
99 #endif  // UNICODE_ENABLE
100     matrix_init_keymap();
101 }
102
103 __attribute__((weak))
104 void keyboard_post_init_keymap(void) {}
105
106 void keyboard_post_init_user(void) {
107 #if defined(RGBLIGHT_ENABLE) || defined(RGB_MATRIX_ENABLE)
108     keyboard_post_init_rgb();
109 #endif
110     keyboard_post_init_keymap();
111 }
112
113 __attribute__((weak))
114 void shutdown_keymap(void) {}
115
116  void rgb_matrix_update_pwm_buffers(void);
117
118 void shutdown_user(void) {
119 #ifdef RGBLIGHT_ENABLE
120     rgblight_enable_noeeprom();
121     rgblight_mode_noeeprom(1);
122     rgblight_setrgb_red();
123 #endif  // RGBLIGHT_ENABLE
124 #ifdef RGB_MATRIX_ENABLE
125     rgb_matrix_set_color_all( 0xFF, 0x00, 0x00 );
126     rgb_matrix_update_pwm_buffers();
127
128 #endif  // RGB_MATRIX_ENABLE
129     shutdown_keymap();
130 }
131
132 __attribute__((weak))
133 void suspend_power_down_keymap(void) {}
134
135 void suspend_power_down_user(void) {
136     suspend_power_down_keymap();
137 }
138
139 __attribute__((weak))
140 void suspend_wakeup_init_keymap(void) {}
141
142 void suspend_wakeup_init_user(void) {
143     suspend_wakeup_init_keymap();
144 }
145
146 __attribute__((weak))
147 void matrix_scan_keymap(void) {}
148
149 // No global matrix scan code, so just run keymap's matrix
150 // scan function
151 void matrix_scan_user(void) {
152     static bool has_ran_yet;
153     if (!has_ran_yet) {
154         has_ran_yet = true;
155         startup_user();
156     }
157
158 #ifdef TAP_DANCE_ENABLE  // Run Diablo 3 macro checking code.
159     run_diablo_macro_check();
160 #endif  // TAP_DANCE_ENABLE
161
162 #if defined(RGBLIGHT_ENABLE) || defined(RGB_MATRIX_ENABLE)
163     matrix_scan_rgb();
164 #endif  // RGBLIGHT_ENABLE
165
166     matrix_scan_keymap();
167 }
168
169 __attribute__((weak))
170 layer_state_t layer_state_set_keymap(layer_state_t state) { return state; }
171
172 // on layer change, no matter where the change was initiated
173 // Then runs keymap's layer change check
174 layer_state_t layer_state_set_user(layer_state_t state) {
175     state = update_tri_layer_state(state, _RAISE, _LOWER, _ADJUST);
176 #if defined(RGBLIGHT_ENABLE) || defined(RGB_MATRIX_ENABLE)
177     state = layer_state_set_rgb(state);
178 #endif  // RGBLIGHT_ENABLE
179     return layer_state_set_keymap(state);
180 }
181
182 __attribute__((weak))
183 layer_state_t default_layer_state_set_keymap(layer_state_t state) { return state; }
184
185 // Runs state check and changes underglow color and animation
186 layer_state_t default_layer_state_set_user(layer_state_t state) {
187     state = default_layer_state_set_keymap(state);
188 #if 0
189 #if defined(RGBLIGHT_ENABLE) || defined(RGB_MATRIX_ENABLE)
190   state = default_layer_state_set_rgb(state);
191 #    endif  // RGBLIGHT_ENABLE
192 #endif
193     return state;
194 }
195
196 __attribute__((weak))
197 void led_set_keymap(uint8_t usb_led) {}
198
199 // Any custom LED code goes here.
200 // So far, I only have keyboard specific code,
201 // So nothing goes here.
202 void led_set_user(uint8_t usb_led) {
203     led_set_keymap(usb_led);
204 }
205
206 __attribute__((weak))
207 void eeconfig_init_keymap(void) {}
208
209 void eeconfig_init_user(void) {
210     userspace_config.raw              = 0;
211     userspace_config.rgb_layer_change = true;
212     eeconfig_update_user(userspace_config.raw);
213 #if (defined(UNICODE_ENABLE) || defined(UNICODEMAP_ENABLE) || defined(UCIS_ENABLE))
214     set_unicode_input_mode(DRASHNA_UNICODE_MODE);
215     get_unicode_input_mode();
216 #else
217     eeprom_update_byte(EECONFIG_UNICODEMODE, DRASHNA_UNICODE_MODE);
218 #endif
219     eeconfig_init_keymap();
220     keyboard_init();
221 }