Reduce PROGMEM usage for sendstring LUT (#8109)
[jackhill/qmk/firmware.git] / quantum / quantum.h
CommitLineData
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"
376419a4 25# include "chibios_config.h"
4d4f7684 26#endif
c6906046 27
4d4f7684 28#include "wait.h"
1a8c0dd2 29#include "matrix.h"
db32864c 30#include "keymap.h"
c6906046 31
1a8c0dd2 32#ifdef BACKLIGHT_ENABLE
b624f32f 33# ifdef LED_MATRIX_ENABLE
34# include "ledmatrix.h"
35# else
36# include "backlight.h"
37# endif
1a8c0dd2 38#endif
c6906046
39
40#if defined(RGBLIGHT_ENABLE)
b624f32f 41# include "rgblight.h"
c6906046 42#elif defined(RGB_MATRIX_ENABLE)
b624f32f 43// Dummy define RGBLIGHT_MODE_xxxx
44# define RGBLIGHT_H_DUMMY_DEFINE
45# include "rgblight.h"
1a8c0dd2 46#endif
0fab3bbd 47
14b7602a 48#ifdef RGB_MATRIX_ENABLE
b624f32f 49# include "rgb_matrix.h"
14b7602a 50#endif
0fab3bbd 51
1a8c0dd2
EZ
52#include "action_layer.h"
53#include "eeconfig.h"
db32864c
JH
54#include "bootloader.h"
55#include "timer.h"
13bb6b4b 56#include "config_common.h"
13bb6b4b
JH
57#include "led.h"
58#include "action_util.h"
e01b4c3f 59#include "print.h"
7ad924ba 60#include "send_string_keycodes.h"
23d68d0b 61#include "suspend.h"
c6906046
62#include <stddef.h>
63#include <stdlib.h>
65faab3b 64
00d1d782 65extern layer_state_t default_layer_state;
1a8c0dd2
EZ
66
67#ifndef NO_ACTION_LAYER
b624f32f 68extern layer_state_t layer_state;
1a8c0dd2
EZ
69#endif
70
c6906046 71#if defined(MIDI_ENABLE) && defined(MIDI_ADVANCED)
b624f32f 72# include "process_midi.h"
65faab3b
JH
73#endif
74
b732b79b 75#ifdef AUDIO_ENABLE
b624f32f 76# include "audio.h"
77# include "process_audio.h"
78# ifdef AUDIO_CLICKY
79# include "process_clicky.h"
80# endif
1000799d
GY
81#endif
82
5987f679 83#ifdef STENO_ENABLE
b624f32f 84# include "process_steno.h"
5987f679
JW
85#endif
86
1000799d 87#if defined(AUDIO_ENABLE) || (defined(MIDI_ENABLE) && defined(MIDI_BASIC))
b624f32f 88# include "process_music.h"
b732b79b 89#endif
1a8c0dd2 90
26eef35f
JY
91#ifdef BACKLIGHT_ENABLE
92# include "process_backlight.h"
93#endif
94
74344947 95#ifdef LEADER_ENABLE
b624f32f 96# include "process_leader.h"
65faab3b 97#endif
1a8c0dd2 98
65faab3b 99#ifdef UNICODE_ENABLE
b624f32f 100# include "process_unicode.h"
1a8c0dd2 101#endif
1a8c0dd2 102
cbabb4d4 103#ifdef UCIS_ENABLE
b624f32f 104# include "process_ucis.h"
cbabb4d4
JH
105#endif
106
107#ifdef UNICODEMAP_ENABLE
b624f32f 108# include "process_unicodemap.h"
cbabb4d4
JH
109#endif
110
9d949389 111#ifdef TAP_DANCE_ENABLE
b624f32f 112# include "process_tap_dance.h"
9d949389 113#endif
65faab3b 114
5f91fb41 115#ifdef PRINTING_ENABLE
b624f32f 116# include "process_printer.h"
5f91fb41
JH
117#endif
118
abba393f 119#ifdef AUTO_SHIFT_ENABLE
b624f32f 120# include "process_auto_shift.h"
abba393f
JC
121#endif
122
eac8fa79 123#ifdef COMBO_ENABLE
b624f32f 124# include "process_combo.h"
eac8fa79
OP
125#endif
126
8e1be7c7 127#ifdef KEY_LOCK_ENABLE
b624f32f 128# include "process_key_lock.h"
8e1be7c7
FS
129#endif
130
7ad924ba 131#ifdef TERMINAL_ENABLE
b624f32f 132# include "process_terminal.h"
7ad924ba 133#else
b624f32f 134# include "process_terminal_nop.h"
7ad924ba
JH
135#endif
136
c745d9b8 137#ifdef SPACE_CADET_ENABLE
b624f32f 138# include "process_space_cadet.h"
c745d9b8
X
139#endif
140
d598f01c
JC
141#ifdef MAGIC_KEYCODE_ENABLE
142# include "process_magic.h"
143#endif
144
393937b4
JC
145#ifdef GRAVE_ESC_ENABLE
146# include "process_grave_esc.h"
147#endif
148
ae40fc49
JC
149#if defined(RGBLIGHT_ENABLE) || defined(RGB_MATRIX_ENABLE)
150# include "process_rgb.h"
151#endif
152
bbea9dad 153#ifdef HD44780_ENABLE
b624f32f 154# include "hd44780.h"
bbea9dad
MA
155#endif
156
2cee371b 157#ifdef HAPTIC_ENABLE
b624f32f 158# include "haptic.h"
2cee371b 159#endif
160
0a645225 161#ifdef OLED_DRIVER_ENABLE
b624f32f 162# include "oled_driver.h"
0a645225
RC
163#endif
164
dab4967f 165#ifdef DIP_SWITCH_ENABLE
a91c0c47 166# include "dip_switch.h"
dab4967f
DJ
167#endif
168
542cb0a8 169#ifdef DYNAMIC_MACRO_ENABLE
a91c0c47 170# include "process_dynamic_macro.h"
542cb0a8
DJ
171#endif
172
320822d7 173#ifdef DYNAMIC_KEYMAP_ENABLE
667045b4 174# include "dynamic_keymap.h"
320822d7
W
175#endif
176
177#ifdef VIA_ENABLE
667045b4 178# include "via.h"
320822d7
W
179#endif
180
c6906046
181// Function substitutions to ease GPIO manipulation
182#if defined(__AVR__)
b624f32f 183typedef uint8_t pin_t;
c6906046 184
05d6e6ca 185# define setPinInput(pin) (DDRx_ADDRESS(pin) &= ~_BV((pin)&0xF), PORTx_ADDRESS(pin) &= ~_BV((pin)&0xF))
b624f32f 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))
c6906046 189
b624f32f 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))
c6906046 193
b624f32f 194# define readPin(pin) ((bool)(PINx_ADDRESS(pin) & _BV((pin)&0xF)))
05d6e6ca 195
7fe03d08 196#elif defined(PROTOCOL_CHIBIOS)
b624f32f 197typedef ioline_t pin_t;
c6906046 198
b624f32f 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)
c6906046 203
b624f32f 204# define writePinHigh(pin) palSetLine(pin)
205# define writePinLow(pin) palClearLine(pin)
206# define writePin(pin, level) ((level) ? writePinHigh(pin) : writePinLow(pin))
c6906046 207
b624f32f 208# define readPin(pin) palReadLine(pin)
7fe03d08 209#endif
210
c6906046 211#define SEND_STRING(string) send_string_P(PSTR(string))
5a6737a7 212#define SEND_STRING_DELAY(string, interval) send_string_with_delay_P(PSTR(string), interval)
c6906046 213
552f8d81 214// Look-Up Tables (LUTs) to convert ASCII character to keycode sequence.
a5ecf146 215extern const uint8_t ascii_to_keycode_lut[128];
552f8d81
TL
216extern const uint8_t ascii_to_shift_lut[16];
217extern 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
c6906046 229
794aed37 230void send_string(const char *str);
fdc2e805 231void send_string_with_delay(const char *str, uint8_t interval);
7ad924ba
JH
232void send_string_P(const char *str);
233void send_string_with_delay_P(const char *str, uint8_t interval);
234void send_char(char ascii_code);
1c9f33c0 235
db32864c 236// For tri-layer
b624f32f 237void update_tri_layer(uint8_t layer1, uint8_t layer2, uint8_t layer3);
b62e160a 238layer_state_t update_tri_layer_state(layer_state_t state, uint8_t layer1, uint8_t layer2, uint8_t layer3);
197f152d 239
6a3c6677
JH
240void set_single_persistent_default_layer(uint8_t default_layer);
241
197f152d
JH
242void tap_random_base64(void);
243
b624f32f 244#define IS_LAYER_ON(layer) (layer_state & (1UL << (layer)))
db32864c
JH
245#define IS_LAYER_OFF(layer) (~layer_state & (1UL << (layer)))
246
b624f32f 247void matrix_init_kb(void);
248void matrix_scan_kb(void);
249void matrix_init_user(void);
250void matrix_scan_user(void);
5701b75e
DJ
251uint16_t get_record_keycode(keyrecord_t *record);
252uint16_t get_event_keycode(keyevent_t event);
b624f32f 253bool process_action_kb(keyrecord_t *record);
254bool process_record_kb(uint16_t keycode, keyrecord_t *record);
255bool process_record_user(uint16_t keycode, keyrecord_t *record);
17977a7e 256
4ffcacd9 257#ifndef BOOTMAGIC_LITE_COLUMN
b624f32f 258# define BOOTMAGIC_LITE_COLUMN 0
4ffcacd9
DJ
259#endif
260#ifndef BOOTMAGIC_LITE_ROW
b624f32f 261# define BOOTMAGIC_LITE_ROW 0
4ffcacd9
DJ
262#endif
263
264void bootmagic_lite(void);
265
a28a6e5b
PV
266void reset_keyboard(void);
267
287eb7ad
JH
268void startup_user(void);
269void shutdown_user(void);
0428214b 270
e4dfcf89
271void register_code16(uint16_t code);
272void unregister_code16(uint16_t code);
02d44beb 273void tap_code16(uint16_t code);
0d28787c 274
b624f32f 275void send_dword(uint32_t number);
276void send_word(uint16_t number);
277void send_byte(uint8_t number);
278void send_nibble(uint8_t number);
cbabb4d4 279uint16_t hex_to_keycode(uint8_t hex);
13bb6b4b
JH
280
281void led_set_user(uint8_t usb_led);
282void led_set_kb(uint8_t usb_led);
dfb78d2a 283bool led_update_user(led_t led_state);
284bool led_update_kb(led_t led_state);
13bb6b4b 285
7edac212 286void api_send_unicode(uint32_t unicode);