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