Add customisable EEPROM driver selection (#7274)
[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
74344947 91#ifdef LEADER_ENABLE
b624f32f 92# include "process_leader.h"
65faab3b 93#endif
1a8c0dd2 94
65faab3b 95#ifdef UNICODE_ENABLE
b624f32f 96# include "process_unicode.h"
1a8c0dd2 97#endif
1a8c0dd2 98
cbabb4d4 99#ifdef UCIS_ENABLE
b624f32f 100# include "process_ucis.h"
cbabb4d4
JH
101#endif
102
103#ifdef UNICODEMAP_ENABLE
b624f32f 104# include "process_unicodemap.h"
cbabb4d4
JH
105#endif
106
9d949389 107#ifdef TAP_DANCE_ENABLE
b624f32f 108# include "process_tap_dance.h"
9d949389 109#endif
65faab3b 110
5f91fb41 111#ifdef PRINTING_ENABLE
b624f32f 112# include "process_printer.h"
5f91fb41
JH
113#endif
114
abba393f 115#ifdef AUTO_SHIFT_ENABLE
b624f32f 116# include "process_auto_shift.h"
abba393f
JC
117#endif
118
eac8fa79 119#ifdef COMBO_ENABLE
b624f32f 120# include "process_combo.h"
eac8fa79
OP
121#endif
122
8e1be7c7 123#ifdef KEY_LOCK_ENABLE
b624f32f 124# include "process_key_lock.h"
8e1be7c7
FS
125#endif
126
7ad924ba 127#ifdef TERMINAL_ENABLE
b624f32f 128# include "process_terminal.h"
7ad924ba 129#else
b624f32f 130# include "process_terminal_nop.h"
7ad924ba
JH
131#endif
132
c745d9b8 133#ifdef SPACE_CADET_ENABLE
b624f32f 134# include "process_space_cadet.h"
c745d9b8
X
135#endif
136
d598f01c
JC
137#ifdef MAGIC_KEYCODE_ENABLE
138# include "process_magic.h"
139#endif
140
ae40fc49
JC
141#if defined(RGBLIGHT_ENABLE) || defined(RGB_MATRIX_ENABLE)
142# include "process_rgb.h"
143#endif
144
bbea9dad 145#ifdef HD44780_ENABLE
b624f32f 146# include "hd44780.h"
bbea9dad
MA
147#endif
148
2cee371b 149#ifdef HAPTIC_ENABLE
b624f32f 150# include "haptic.h"
2cee371b 151#endif
152
0a645225 153#ifdef OLED_DRIVER_ENABLE
b624f32f 154# include "oled_driver.h"
0a645225
RC
155#endif
156
dab4967f 157#ifdef DIP_SWITCH_ENABLE
a91c0c47 158# include "dip_switch.h"
dab4967f
DJ
159#endif
160
542cb0a8 161#ifdef DYNAMIC_MACRO_ENABLE
a91c0c47 162# include "process_dynamic_macro.h"
542cb0a8
DJ
163#endif
164
320822d7 165#ifdef DYNAMIC_KEYMAP_ENABLE
667045b4 166# include "dynamic_keymap.h"
320822d7
W
167#endif
168
169#ifdef VIA_ENABLE
667045b4 170# include "via.h"
320822d7
W
171#endif
172
c6906046
173// Function substitutions to ease GPIO manipulation
174#if defined(__AVR__)
b624f32f 175typedef uint8_t pin_t;
c6906046 176
b624f32f 177# define setPinInput(pin) (DDRx_ADDRESS(pin) &= ~_BV((pin)&0xF))
178# define setPinInputHigh(pin) (DDRx_ADDRESS(pin) &= ~_BV((pin)&0xF), PORTx_ADDRESS(pin) |= _BV((pin)&0xF))
179# define setPinInputLow(pin) _Static_assert(0, "AVR processors cannot implement an input as pull low")
180# define setPinOutput(pin) (DDRx_ADDRESS(pin) |= _BV((pin)&0xF))
c6906046 181
b624f32f 182# define writePinHigh(pin) (PORTx_ADDRESS(pin) |= _BV((pin)&0xF))
183# define writePinLow(pin) (PORTx_ADDRESS(pin) &= ~_BV((pin)&0xF))
184# define writePin(pin, level) ((level) ? writePinHigh(pin) : writePinLow(pin))
c6906046 185
b624f32f 186# define readPin(pin) ((bool)(PINx_ADDRESS(pin) & _BV((pin)&0xF)))
7fe03d08 187#elif defined(PROTOCOL_CHIBIOS)
b624f32f 188typedef ioline_t pin_t;
c6906046 189
b624f32f 190# define setPinInput(pin) palSetLineMode(pin, PAL_MODE_INPUT)
191# define setPinInputHigh(pin) palSetLineMode(pin, PAL_MODE_INPUT_PULLUP)
192# define setPinInputLow(pin) palSetLineMode(pin, PAL_MODE_INPUT_PULLDOWN)
193# define setPinOutput(pin) palSetLineMode(pin, PAL_MODE_OUTPUT_PUSHPULL)
c6906046 194
b624f32f 195# define writePinHigh(pin) palSetLine(pin)
196# define writePinLow(pin) palClearLine(pin)
197# define writePin(pin, level) ((level) ? writePinHigh(pin) : writePinLow(pin))
c6906046 198
b624f32f 199# define readPin(pin) palReadLine(pin)
7fe03d08 200#endif
201
c6906046 202#define SEND_STRING(string) send_string_P(PSTR(string))
5a6737a7 203#define SEND_STRING_DELAY(string, interval) send_string_with_delay_P(PSTR(string), interval)
c6906046 204
b624f32f 205extern const bool ascii_to_shift_lut[128];
206extern const bool ascii_to_altgr_lut[128];
a5ecf146 207extern const uint8_t ascii_to_keycode_lut[128];
c6906046 208
794aed37 209void send_string(const char *str);
fdc2e805 210void send_string_with_delay(const char *str, uint8_t interval);
7ad924ba
JH
211void send_string_P(const char *str);
212void send_string_with_delay_P(const char *str, uint8_t interval);
213void send_char(char ascii_code);
1c9f33c0 214
db32864c 215// For tri-layer
b624f32f 216void update_tri_layer(uint8_t layer1, uint8_t layer2, uint8_t layer3);
b62e160a 217layer_state_t update_tri_layer_state(layer_state_t state, uint8_t layer1, uint8_t layer2, uint8_t layer3);
197f152d 218
6a3c6677
JH
219void set_single_persistent_default_layer(uint8_t default_layer);
220
197f152d
JH
221void tap_random_base64(void);
222
b624f32f 223#define IS_LAYER_ON(layer) (layer_state & (1UL << (layer)))
db32864c
JH
224#define IS_LAYER_OFF(layer) (~layer_state & (1UL << (layer)))
225
b624f32f 226void matrix_init_kb(void);
227void matrix_scan_kb(void);
228void matrix_init_user(void);
229void matrix_scan_user(void);
5701b75e
DJ
230uint16_t get_record_keycode(keyrecord_t *record);
231uint16_t get_event_keycode(keyevent_t event);
b624f32f 232bool process_action_kb(keyrecord_t *record);
233bool process_record_kb(uint16_t keycode, keyrecord_t *record);
234bool process_record_user(uint16_t keycode, keyrecord_t *record);
17977a7e 235
4ffcacd9 236#ifndef BOOTMAGIC_LITE_COLUMN
b624f32f 237# define BOOTMAGIC_LITE_COLUMN 0
4ffcacd9
DJ
238#endif
239#ifndef BOOTMAGIC_LITE_ROW
b624f32f 240# define BOOTMAGIC_LITE_ROW 0
4ffcacd9
DJ
241#endif
242
243void bootmagic_lite(void);
244
a28a6e5b
PV
245void reset_keyboard(void);
246
287eb7ad
JH
247void startup_user(void);
248void shutdown_user(void);
0428214b 249
e4dfcf89
250void register_code16(uint16_t code);
251void unregister_code16(uint16_t code);
02d44beb 252void tap_code16(uint16_t code);
0d28787c 253
b624f32f 254void send_dword(uint32_t number);
255void send_word(uint16_t number);
256void send_byte(uint8_t number);
257void send_nibble(uint8_t number);
cbabb4d4 258uint16_t hex_to_keycode(uint8_t hex);
13bb6b4b
JH
259
260void led_set_user(uint8_t usb_led);
261void led_set_kb(uint8_t usb_led);
dfb78d2a 262bool led_update_user(led_t led_state);
263bool led_update_kb(led_t led_state);
13bb6b4b 264
7edac212 265void api_send_unicode(uint32_t unicode);