Commit | Line | Data |
---|---|---|
7fe03d08 | 1 | /* Copyright 2016-2018 Erez Zukerman, Jack Humbert, Yiancar |
23839b8c | 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 | */ | |
c6906046 | 16 | #pragma once |
1a8c0dd2 | 17 | |
4d4f7684 | 18 | #if defined(__AVR__) |
b624f32f | 19 | # include <avr/pgmspace.h> |
20 | # include <avr/io.h> | |
21 | # include <avr/interrupt.h> | |
7fe03d08 | 22 | #endif |
23 | #if defined(PROTOCOL_CHIBIOS) | |
b624f32f | 24 | # include "hal.h" |
4d4f7684 | 25 | #endif |
c6906046 | 26 | |
4d4f7684 | 27 | #include "wait.h" |
1a8c0dd2 | 28 | #include "matrix.h" |
db32864c | 29 | #include "keymap.h" |
c6906046 | 30 | |
1a8c0dd2 | 31 | #ifdef BACKLIGHT_ENABLE |
b624f32f | 32 | # ifdef LED_MATRIX_ENABLE |
33 | # include "ledmatrix.h" | |
34 | # else | |
35 | # include "backlight.h" | |
36 | # endif | |
1a8c0dd2 | 37 | #endif |
c6906046 KĐ |
38 | |
39 | #if defined(RGBLIGHT_ENABLE) | |
b624f32f | 40 | # include "rgblight.h" |
c6906046 | 41 | #elif defined(RGB_MATRIX_ENABLE) |
b624f32f | 42 | // Dummy define RGBLIGHT_MODE_xxxx |
43 | # define RGBLIGHT_H_DUMMY_DEFINE | |
44 | # include "rgblight.h" | |
1a8c0dd2 | 45 | #endif |
0fab3bbd | 46 | |
14b7602a | 47 | #ifdef RGB_MATRIX_ENABLE |
b624f32f | 48 | # include "rgb_matrix.h" |
14b7602a | 49 | #endif |
0fab3bbd | 50 | |
1a8c0dd2 EZ |
51 | #include "action_layer.h" |
52 | #include "eeconfig.h" | |
db32864c JH |
53 | #include "bootloader.h" |
54 | #include "timer.h" | |
13bb6b4b | 55 | #include "config_common.h" |
13bb6b4b JH |
56 | #include "led.h" |
57 | #include "action_util.h" | |
e01b4c3f | 58 | #include "print.h" |
7ad924ba | 59 | #include "send_string_keycodes.h" |
23d68d0b | 60 | #include "suspend.h" |
c6906046 KĐ |
61 | #include <stddef.h> |
62 | #include <stdlib.h> | |
65faab3b | 63 | |
00d1d782 | 64 | extern layer_state_t default_layer_state; |
1a8c0dd2 EZ |
65 | |
66 | #ifndef NO_ACTION_LAYER | |
b624f32f | 67 | extern layer_state_t layer_state; |
1a8c0dd2 EZ |
68 | #endif |
69 | ||
c6906046 | 70 | #if defined(MIDI_ENABLE) && defined(MIDI_ADVANCED) |
b624f32f | 71 | # include "process_midi.h" |
65faab3b JH |
72 | #endif |
73 | ||
b732b79b | 74 | #ifdef AUDIO_ENABLE |
b624f32f | 75 | # include "audio.h" |
76 | # include "process_audio.h" | |
77 | # ifdef AUDIO_CLICKY | |
78 | # include "process_clicky.h" | |
79 | # endif | |
1000799d GY |
80 | #endif |
81 | ||
5987f679 | 82 | #ifdef STENO_ENABLE |
b624f32f | 83 | # include "process_steno.h" |
5987f679 JW |
84 | #endif |
85 | ||
1000799d | 86 | #if defined(AUDIO_ENABLE) || (defined(MIDI_ENABLE) && defined(MIDI_BASIC)) |
b624f32f | 87 | # include "process_music.h" |
b732b79b | 88 | #endif |
1a8c0dd2 | 89 | |
74344947 | 90 | #ifdef LEADER_ENABLE |
b624f32f | 91 | # include "process_leader.h" |
65faab3b | 92 | #endif |
1a8c0dd2 | 93 | |
65faab3b | 94 | #ifdef UNICODE_ENABLE |
b624f32f | 95 | # include "process_unicode.h" |
1a8c0dd2 | 96 | #endif |
1a8c0dd2 | 97 | |
cbabb4d4 | 98 | #ifdef UCIS_ENABLE |
b624f32f | 99 | # include "process_ucis.h" |
cbabb4d4 JH |
100 | #endif |
101 | ||
102 | #ifdef UNICODEMAP_ENABLE | |
b624f32f | 103 | # include "process_unicodemap.h" |
cbabb4d4 JH |
104 | #endif |
105 | ||
9d949389 | 106 | #ifdef TAP_DANCE_ENABLE |
b624f32f | 107 | # include "process_tap_dance.h" |
9d949389 | 108 | #endif |
65faab3b | 109 | |
5f91fb41 | 110 | #ifdef PRINTING_ENABLE |
b624f32f | 111 | # include "process_printer.h" |
5f91fb41 JH |
112 | #endif |
113 | ||
abba393f | 114 | #ifdef AUTO_SHIFT_ENABLE |
b624f32f | 115 | # include "process_auto_shift.h" |
abba393f JC |
116 | #endif |
117 | ||
eac8fa79 | 118 | #ifdef COMBO_ENABLE |
b624f32f | 119 | # include "process_combo.h" |
eac8fa79 OP |
120 | #endif |
121 | ||
8e1be7c7 | 122 | #ifdef KEY_LOCK_ENABLE |
b624f32f | 123 | # include "process_key_lock.h" |
8e1be7c7 FS |
124 | #endif |
125 | ||
7ad924ba | 126 | #ifdef TERMINAL_ENABLE |
b624f32f | 127 | # include "process_terminal.h" |
7ad924ba | 128 | #else |
b624f32f | 129 | # include "process_terminal_nop.h" |
7ad924ba JH |
130 | #endif |
131 | ||
c745d9b8 | 132 | #ifdef SPACE_CADET_ENABLE |
b624f32f | 133 | # include "process_space_cadet.h" |
c745d9b8 X |
134 | #endif |
135 | ||
bbea9dad | 136 | #ifdef HD44780_ENABLE |
b624f32f | 137 | # include "hd44780.h" |
bbea9dad MA |
138 | #endif |
139 | ||
2cee371b | 140 | #ifdef HAPTIC_ENABLE |
b624f32f | 141 | # include "haptic.h" |
2cee371b | 142 | #endif |
143 | ||
0a645225 | 144 | #ifdef OLED_DRIVER_ENABLE |
b624f32f | 145 | # include "oled_driver.h" |
0a645225 RC |
146 | #endif |
147 | ||
dab4967f DJ |
148 | #ifdef DIP_SWITCH_ENABLE |
149 | #include "dip_switch.h" | |
150 | #endif | |
151 | ||
152 | ||
c6906046 KĐ |
153 | // Function substitutions to ease GPIO manipulation |
154 | #if defined(__AVR__) | |
b624f32f | 155 | typedef uint8_t pin_t; |
c6906046 | 156 | |
b624f32f | 157 | # define setPinInput(pin) (DDRx_ADDRESS(pin) &= ~_BV((pin)&0xF)) |
158 | # define setPinInputHigh(pin) (DDRx_ADDRESS(pin) &= ~_BV((pin)&0xF), PORTx_ADDRESS(pin) |= _BV((pin)&0xF)) | |
159 | # define setPinInputLow(pin) _Static_assert(0, "AVR processors cannot implement an input as pull low") | |
160 | # define setPinOutput(pin) (DDRx_ADDRESS(pin) |= _BV((pin)&0xF)) | |
c6906046 | 161 | |
b624f32f | 162 | # define writePinHigh(pin) (PORTx_ADDRESS(pin) |= _BV((pin)&0xF)) |
163 | # define writePinLow(pin) (PORTx_ADDRESS(pin) &= ~_BV((pin)&0xF)) | |
164 | # define writePin(pin, level) ((level) ? writePinHigh(pin) : writePinLow(pin)) | |
c6906046 | 165 | |
b624f32f | 166 | # define readPin(pin) ((bool)(PINx_ADDRESS(pin) & _BV((pin)&0xF))) |
7fe03d08 | 167 | #elif defined(PROTOCOL_CHIBIOS) |
b624f32f | 168 | typedef ioline_t pin_t; |
c6906046 | 169 | |
b624f32f | 170 | # define setPinInput(pin) palSetLineMode(pin, PAL_MODE_INPUT) |
171 | # define setPinInputHigh(pin) palSetLineMode(pin, PAL_MODE_INPUT_PULLUP) | |
172 | # define setPinInputLow(pin) palSetLineMode(pin, PAL_MODE_INPUT_PULLDOWN) | |
173 | # define setPinOutput(pin) palSetLineMode(pin, PAL_MODE_OUTPUT_PUSHPULL) | |
c6906046 | 174 | |
b624f32f | 175 | # define writePinHigh(pin) palSetLine(pin) |
176 | # define writePinLow(pin) palClearLine(pin) | |
177 | # define writePin(pin, level) ((level) ? writePinHigh(pin) : writePinLow(pin)) | |
c6906046 | 178 | |
b624f32f | 179 | # define readPin(pin) palReadLine(pin) |
7fe03d08 | 180 | #endif |
181 | ||
c6906046 | 182 | // Send string macros |
7ad924ba | 183 | #define STRINGIZE(z) #z |
b624f32f | 184 | #define ADD_SLASH_X(y) STRINGIZE(\x##y) |
7ad924ba JH |
185 | #define SYMBOL_STR(x) ADD_SLASH_X(x) |
186 | ||
d15bb05c W |
187 | #define SS_TAP_CODE 1 |
188 | #define SS_DOWN_CODE 2 | |
189 | #define SS_UP_CODE 3 | |
190 | ||
7ad924ba JH |
191 | #define SS_TAP(keycode) "\1" SYMBOL_STR(keycode) |
192 | #define SS_DOWN(keycode) "\2" SYMBOL_STR(keycode) | |
193 | #define SS_UP(keycode) "\3" SYMBOL_STR(keycode) | |
194 | ||
c6906046 | 195 | // `string` arguments must not be parenthesized |
7ad924ba JH |
196 | #define SS_LCTRL(string) SS_DOWN(X_LCTRL) string SS_UP(X_LCTRL) |
197 | #define SS_LGUI(string) SS_DOWN(X_LGUI) string SS_UP(X_LGUI) | |
a2e12faa | 198 | #define SS_LCMD(string) SS_LGUI(string) |
199 | #define SS_LWIN(string) SS_LGUI(string) | |
7ad924ba | 200 | #define SS_LALT(string) SS_DOWN(X_LALT) string SS_UP(X_LALT) |
7ff96877 | 201 | #define SS_LSFT(string) SS_DOWN(X_LSHIFT) string SS_UP(X_LSHIFT) |
3f1d1475 | 202 | #define SS_RALT(string) SS_DOWN(X_RALT) string SS_UP(X_RALT) |
28fbf84c | 203 | #define SS_ALGR(string) SS_RALT(string) |
7ad924ba | 204 | |
c6906046 KĐ |
205 | #define SEND_STRING(string) send_string_P(PSTR(string)) |
206 | ||
b624f32f | 207 | extern const bool ascii_to_shift_lut[128]; |
208 | extern const bool ascii_to_altgr_lut[128]; | |
a5ecf146 | 209 | extern const uint8_t ascii_to_keycode_lut[128]; |
c6906046 | 210 | |
794aed37 | 211 | void send_string(const char *str); |
fdc2e805 | 212 | void send_string_with_delay(const char *str, uint8_t interval); |
7ad924ba JH |
213 | void send_string_P(const char *str); |
214 | void send_string_with_delay_P(const char *str, uint8_t interval); | |
215 | void send_char(char ascii_code); | |
1c9f33c0 | 216 | |
db32864c | 217 | // For tri-layer |
b624f32f | 218 | void update_tri_layer(uint8_t layer1, uint8_t layer2, uint8_t layer3); |
b62e160a | 219 | layer_state_t update_tri_layer_state(layer_state_t state, uint8_t layer1, uint8_t layer2, uint8_t layer3); |
197f152d | 220 | |
6a3c6677 JH |
221 | void set_single_persistent_default_layer(uint8_t default_layer); |
222 | ||
197f152d JH |
223 | void tap_random_base64(void); |
224 | ||
b624f32f | 225 | #define IS_LAYER_ON(layer) (layer_state & (1UL << (layer))) |
db32864c JH |
226 | #define IS_LAYER_OFF(layer) (~layer_state & (1UL << (layer))) |
227 | ||
b624f32f | 228 | void matrix_init_kb(void); |
229 | void matrix_scan_kb(void); | |
230 | void matrix_init_user(void); | |
231 | void matrix_scan_user(void); | |
5701b75e DJ |
232 | uint16_t get_record_keycode(keyrecord_t *record); |
233 | uint16_t get_event_keycode(keyevent_t event); | |
b624f32f | 234 | bool process_action_kb(keyrecord_t *record); |
235 | bool process_record_kb(uint16_t keycode, keyrecord_t *record); | |
236 | bool process_record_user(uint16_t keycode, keyrecord_t *record); | |
17977a7e | 237 | |
4ffcacd9 | 238 | #ifndef BOOTMAGIC_LITE_COLUMN |
b624f32f | 239 | # define BOOTMAGIC_LITE_COLUMN 0 |
4ffcacd9 DJ |
240 | #endif |
241 | #ifndef BOOTMAGIC_LITE_ROW | |
b624f32f | 242 | # define BOOTMAGIC_LITE_ROW 0 |
4ffcacd9 DJ |
243 | #endif |
244 | ||
245 | void bootmagic_lite(void); | |
246 | ||
a28a6e5b PV |
247 | void reset_keyboard(void); |
248 | ||
287eb7ad JH |
249 | void startup_user(void); |
250 | void shutdown_user(void); | |
0428214b | 251 | |
e4dfcf89 KĐ |
252 | void register_code16(uint16_t code); |
253 | void unregister_code16(uint16_t code); | |
02d44beb | 254 | void tap_code16(uint16_t code); |
0d28787c | 255 | |
13bb6b4b JH |
256 | #ifdef BACKLIGHT_ENABLE |
257 | void backlight_init_ports(void); | |
8d0fdf10 | 258 | void backlight_task(void); |
b61baf42 BF |
259 | void backlight_task_internal(void); |
260 | void backlight_on(uint8_t backlight_pin); | |
261 | void backlight_off(uint8_t backlight_pin); | |
13bb6b4b | 262 | |
b624f32f | 263 | # ifdef BACKLIGHT_BREATHING |
b61baf42 | 264 | void breathing_task(void); |
13bb6b4b JH |
265 | void breathing_enable(void); |
266 | void breathing_pulse(void); | |
267 | void breathing_disable(void); | |
268 | void breathing_self_disable(void); | |
269 | void breathing_toggle(void); | |
270 | bool is_breathing(void); | |
271 | ||
13bb6b4b | 272 | void breathing_intensity_default(void); |
4931510a BG |
273 | void breathing_period_default(void); |
274 | void breathing_period_set(uint8_t value); | |
275 | void breathing_period_inc(void); | |
276 | void breathing_period_dec(void); | |
b624f32f | 277 | # endif |
13bb6b4b JH |
278 | #endif |
279 | ||
b624f32f | 280 | void send_dword(uint32_t number); |
281 | void send_word(uint16_t number); | |
282 | void send_byte(uint8_t number); | |
283 | void send_nibble(uint8_t number); | |
cbabb4d4 | 284 | uint16_t hex_to_keycode(uint8_t hex); |
13bb6b4b JH |
285 | |
286 | void led_set_user(uint8_t usb_led); | |
287 | void led_set_kb(uint8_t usb_led); | |
288 | ||
7edac212 | 289 | void api_send_unicode(uint32_t unicode); |