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