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