Allow RGBLIGHT_ANIMATIONS to work on keebio/iris configurator builds (#8482)
[jackhill/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 # include "chibios_config.h"
26 #endif
27
28 #include "wait.h"
29 #include "matrix.h"
30 #include "keymap.h"
31
32 #ifdef BACKLIGHT_ENABLE
33 # ifdef LED_MATRIX_ENABLE
34 # include "ledmatrix.h"
35 # else
36 # include "backlight.h"
37 # endif
38 #endif
39
40 #if defined(RGBLIGHT_ENABLE)
41 # include "rgblight.h"
42 #elif defined(RGB_MATRIX_ENABLE)
43 // Dummy define RGBLIGHT_MODE_xxxx
44 # define RGBLIGHT_H_DUMMY_DEFINE
45 # include "rgblight.h"
46 #endif
47
48 #ifdef RGB_MATRIX_ENABLE
49 # include "rgb_matrix.h"
50 #endif
51
52 #include "action_layer.h"
53 #include "eeconfig.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 "print.h"
60 #include "send_string_keycodes.h"
61 #include "suspend.h"
62 #include <stddef.h>
63 #include <stdlib.h>
64
65 extern layer_state_t default_layer_state;
66
67 #ifndef NO_ACTION_LAYER
68 extern layer_state_t layer_state;
69 #endif
70
71 #if defined(MIDI_ENABLE) && defined(MIDI_ADVANCED)
72 # include "process_midi.h"
73 #endif
74
75 #ifdef AUDIO_ENABLE
76 # include "audio.h"
77 # include "process_audio.h"
78 # ifdef AUDIO_CLICKY
79 # include "process_clicky.h"
80 # endif
81 #endif
82
83 #ifdef STENO_ENABLE
84 # include "process_steno.h"
85 #endif
86
87 #if defined(AUDIO_ENABLE) || (defined(MIDI_ENABLE) && defined(MIDI_BASIC))
88 # include "process_music.h"
89 #endif
90
91 #ifdef BACKLIGHT_ENABLE
92 # include "process_backlight.h"
93 #endif
94
95 #ifdef LEADER_ENABLE
96 # include "process_leader.h"
97 #endif
98
99 #ifdef UNICODE_ENABLE
100 # include "process_unicode.h"
101 #endif
102
103 #ifdef UCIS_ENABLE
104 # include "process_ucis.h"
105 #endif
106
107 #ifdef UNICODEMAP_ENABLE
108 # include "process_unicodemap.h"
109 #endif
110
111 #ifdef TAP_DANCE_ENABLE
112 # include "process_tap_dance.h"
113 #endif
114
115 #ifdef PRINTING_ENABLE
116 # include "process_printer.h"
117 #endif
118
119 #ifdef AUTO_SHIFT_ENABLE
120 # include "process_auto_shift.h"
121 #endif
122
123 #ifdef COMBO_ENABLE
124 # include "process_combo.h"
125 #endif
126
127 #ifdef KEY_LOCK_ENABLE
128 # include "process_key_lock.h"
129 #endif
130
131 #ifdef TERMINAL_ENABLE
132 # include "process_terminal.h"
133 #else
134 # include "process_terminal_nop.h"
135 #endif
136
137 #ifdef SPACE_CADET_ENABLE
138 # include "process_space_cadet.h"
139 #endif
140
141 #ifdef MAGIC_KEYCODE_ENABLE
142 # include "process_magic.h"
143 #endif
144
145 #ifdef GRAVE_ESC_ENABLE
146 # include "process_grave_esc.h"
147 #endif
148
149 #if defined(RGBLIGHT_ENABLE) || defined(RGB_MATRIX_ENABLE)
150 # include "process_rgb.h"
151 #endif
152
153 #ifdef HD44780_ENABLE
154 # include "hd44780.h"
155 #endif
156
157 #ifdef HAPTIC_ENABLE
158 # include "haptic.h"
159 #endif
160
161 #ifdef OLED_DRIVER_ENABLE
162 # include "oled_driver.h"
163 #endif
164
165 #ifdef DIP_SWITCH_ENABLE
166 # include "dip_switch.h"
167 #endif
168
169 #ifdef DYNAMIC_MACRO_ENABLE
170 # include "process_dynamic_macro.h"
171 #endif
172
173 #ifdef DYNAMIC_KEYMAP_ENABLE
174 # include "dynamic_keymap.h"
175 #endif
176
177 #ifdef VIA_ENABLE
178 # include "via.h"
179 #endif
180
181 // Function substitutions to ease GPIO manipulation
182 #if defined(__AVR__)
183 typedef uint8_t pin_t;
184
185 # define setPinInput(pin) (DDRx_ADDRESS(pin) &= ~_BV((pin)&0xF), PORTx_ADDRESS(pin) &= ~_BV((pin)&0xF))
186 # define setPinInputHigh(pin) (DDRx_ADDRESS(pin) &= ~_BV((pin)&0xF), PORTx_ADDRESS(pin) |= _BV((pin)&0xF))
187 # define setPinInputLow(pin) _Static_assert(0, "AVR processors cannot implement an input as pull low")
188 # define setPinOutput(pin) (DDRx_ADDRESS(pin) |= _BV((pin)&0xF))
189
190 # define writePinHigh(pin) (PORTx_ADDRESS(pin) |= _BV((pin)&0xF))
191 # define writePinLow(pin) (PORTx_ADDRESS(pin) &= ~_BV((pin)&0xF))
192 # define writePin(pin, level) ((level) ? writePinHigh(pin) : writePinLow(pin))
193
194 # define readPin(pin) ((bool)(PINx_ADDRESS(pin) & _BV((pin)&0xF)))
195
196 #elif defined(PROTOCOL_CHIBIOS)
197 typedef ioline_t pin_t;
198
199 # define setPinInput(pin) palSetLineMode(pin, PAL_MODE_INPUT)
200 # define setPinInputHigh(pin) palSetLineMode(pin, PAL_MODE_INPUT_PULLUP)
201 # define setPinInputLow(pin) palSetLineMode(pin, PAL_MODE_INPUT_PULLDOWN)
202 # define setPinOutput(pin) palSetLineMode(pin, PAL_MODE_OUTPUT_PUSHPULL)
203
204 # define writePinHigh(pin) palSetLine(pin)
205 # define writePinLow(pin) palClearLine(pin)
206 # define writePin(pin, level) ((level) ? writePinHigh(pin) : writePinLow(pin))
207
208 # define readPin(pin) palReadLine(pin)
209 #endif
210
211 #define SEND_STRING(string) send_string_P(PSTR(string))
212 #define SEND_STRING_DELAY(string, interval) send_string_with_delay_P(PSTR(string), interval)
213
214 // Look-Up Tables (LUTs) to convert ASCII character to keycode sequence.
215 extern const uint8_t ascii_to_keycode_lut[128];
216 extern const uint8_t ascii_to_shift_lut[16];
217 extern const uint8_t ascii_to_altgr_lut[16];
218 // clang-format off
219 #define KCLUT_ENTRY(a, b, c, d, e, f, g, h) \
220 ( ((a) ? 1 : 0) << 0 \
221 | ((b) ? 1 : 0) << 1 \
222 | ((c) ? 1 : 0) << 2 \
223 | ((d) ? 1 : 0) << 3 \
224 | ((e) ? 1 : 0) << 4 \
225 | ((f) ? 1 : 0) << 5 \
226 | ((g) ? 1 : 0) << 6 \
227 | ((h) ? 1 : 0) << 7 )
228 // clang-format on
229
230 void send_string(const char *str);
231 void send_string_with_delay(const char *str, uint8_t interval);
232 void send_string_P(const char *str);
233 void send_string_with_delay_P(const char *str, uint8_t interval);
234 void send_char(char ascii_code);
235
236 // For tri-layer
237 void update_tri_layer(uint8_t layer1, uint8_t layer2, uint8_t layer3);
238 layer_state_t update_tri_layer_state(layer_state_t state, uint8_t layer1, uint8_t layer2, uint8_t layer3);
239
240 void set_single_persistent_default_layer(uint8_t default_layer);
241
242 void tap_random_base64(void);
243
244 #define IS_LAYER_ON(layer) (layer_state & (1UL << (layer)))
245 #define IS_LAYER_OFF(layer) (~layer_state & (1UL << (layer)))
246
247 void matrix_init_kb(void);
248 void matrix_scan_kb(void);
249 void matrix_init_user(void);
250 void matrix_scan_user(void);
251 uint16_t get_record_keycode(keyrecord_t *record);
252 uint16_t get_event_keycode(keyevent_t event);
253 bool process_action_kb(keyrecord_t *record);
254 bool process_record_kb(uint16_t keycode, keyrecord_t *record);
255 bool process_record_user(uint16_t keycode, keyrecord_t *record);
256
257 #ifndef BOOTMAGIC_LITE_COLUMN
258 # define BOOTMAGIC_LITE_COLUMN 0
259 #endif
260 #ifndef BOOTMAGIC_LITE_ROW
261 # define BOOTMAGIC_LITE_ROW 0
262 #endif
263
264 void bootmagic_lite(void);
265
266 void reset_keyboard(void);
267
268 void startup_user(void);
269 void shutdown_user(void);
270
271 void register_code16(uint16_t code);
272 void unregister_code16(uint16_t code);
273 void tap_code16(uint16_t code);
274
275 void send_dword(uint32_t number);
276 void send_word(uint16_t number);
277 void send_byte(uint8_t number);
278 void send_nibble(uint8_t number);
279 uint16_t hex_to_keycode(uint8_t hex);
280
281 void led_set_user(uint8_t usb_led);
282 void led_set_kb(uint8_t usb_led);
283 bool led_update_user(led_t led_state);
284 bool led_update_kb(led_t led_state);
285
286 void api_send_unicode(uint32_t unicode);