1 /* Copyright 2016-2018 Erez Zukerman, Jack Humbert, Yiancar
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.
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.
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/>.
19 # include <avr/pgmspace.h>
21 # include <avr/interrupt.h>
23 #if defined(PROTOCOL_CHIBIOS)
25 # include "chibios_config.h"
32 #ifdef BACKLIGHT_ENABLE
33 # ifdef LED_MATRIX_ENABLE
34 # include "ledmatrix.h"
36 # include "backlight.h"
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"
48 #ifdef RGB_MATRIX_ENABLE
49 # include "rgb_matrix.h"
52 #include "action_layer.h"
54 #include "bootloader.h"
56 #include "config_common.h"
58 #include "action_util.h"
60 #include "send_string_keycodes.h"
65 extern layer_state_t default_layer_state
;
67 #ifndef NO_ACTION_LAYER
68 extern layer_state_t layer_state
;
71 #if defined(MIDI_ENABLE) && defined(MIDI_ADVANCED)
72 # include "process_midi.h"
77 # include "process_audio.h"
79 # include "process_clicky.h"
84 # include "process_steno.h"
87 #if defined(AUDIO_ENABLE) || (defined(MIDI_ENABLE) && defined(MIDI_BASIC))
88 # include "process_music.h"
92 # include "process_leader.h"
96 # include "process_unicode.h"
100 # include "process_ucis.h"
103 #ifdef UNICODEMAP_ENABLE
104 # include "process_unicodemap.h"
107 #ifdef TAP_DANCE_ENABLE
108 # include "process_tap_dance.h"
111 #ifdef PRINTING_ENABLE
112 # include "process_printer.h"
115 #ifdef AUTO_SHIFT_ENABLE
116 # include "process_auto_shift.h"
120 # include "process_combo.h"
123 #ifdef KEY_LOCK_ENABLE
124 # include "process_key_lock.h"
127 #ifdef TERMINAL_ENABLE
128 # include "process_terminal.h"
130 # include "process_terminal_nop.h"
133 #ifdef SPACE_CADET_ENABLE
134 # include "process_space_cadet.h"
137 #ifdef MAGIC_KEYCODE_ENABLE
138 # include "process_magic.h"
141 #ifdef GRAVE_ESC_ENABLE
142 # include "process_grave_esc.h"
145 #if defined(RGBLIGHT_ENABLE) || defined(RGB_MATRIX_ENABLE)
146 # include "process_rgb.h"
149 #ifdef HD44780_ENABLE
150 # include "hd44780.h"
157 #ifdef OLED_DRIVER_ENABLE
158 # include "oled_driver.h"
161 #ifdef DIP_SWITCH_ENABLE
162 # include "dip_switch.h"
165 #ifdef DYNAMIC_MACRO_ENABLE
166 # include "process_dynamic_macro.h"
169 #ifdef DYNAMIC_KEYMAP_ENABLE
170 # include "dynamic_keymap.h"
177 // Function substitutions to ease GPIO manipulation
179 typedef uint8_t pin_t
;
181 # define setPinInput(pin) (DDRx_ADDRESS(pin) &= ~_BV((pin)&0xF), PORTx_ADDRESS(pin) &= ~_BV((pin)&0xF))
182 # define setPinInputHigh(pin) (DDRx_ADDRESS(pin) &= ~_BV((pin)&0xF), PORTx_ADDRESS(pin) |= _BV((pin)&0xF))
183 # define setPinInputLow(pin) _Static_assert(0, "AVR processors cannot implement an input as pull low")
184 # define setPinOutput(pin) (DDRx_ADDRESS(pin) |= _BV((pin)&0xF))
186 # define writePinHigh(pin) (PORTx_ADDRESS(pin) |= _BV((pin)&0xF))
187 # define writePinLow(pin) (PORTx_ADDRESS(pin) &= ~_BV((pin)&0xF))
188 # define writePin(pin, level) ((level) ? writePinHigh(pin) : writePinLow(pin))
190 # define readPin(pin) ((bool)(PINx_ADDRESS(pin) & _BV((pin)&0xF)))
192 #elif defined(PROTOCOL_CHIBIOS)
193 typedef ioline_t pin_t
;
195 # define setPinInput(pin) palSetLineMode(pin, PAL_MODE_INPUT)
196 # define setPinInputHigh(pin) palSetLineMode(pin, PAL_MODE_INPUT_PULLUP)
197 # define setPinInputLow(pin) palSetLineMode(pin, PAL_MODE_INPUT_PULLDOWN)
198 # define setPinOutput(pin) palSetLineMode(pin, PAL_MODE_OUTPUT_PUSHPULL)
200 # define writePinHigh(pin) palSetLine(pin)
201 # define writePinLow(pin) palClearLine(pin)
202 # define writePin(pin, level) ((level) ? writePinHigh(pin) : writePinLow(pin))
204 # define readPin(pin) palReadLine(pin)
207 #define SEND_STRING(string) send_string_P(PSTR(string))
208 #define SEND_STRING_DELAY(string, interval) send_string_with_delay_P(PSTR(string), interval)
210 extern const bool ascii_to_shift_lut
[128];
211 extern const bool ascii_to_altgr_lut
[128];
212 extern const uint8_t ascii_to_keycode_lut
[128];
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
);
221 void update_tri_layer(uint8_t layer1
, uint8_t layer2
, uint8_t layer3
);
222 layer_state_t
update_tri_layer_state(layer_state_t state
, uint8_t layer1
, uint8_t layer2
, uint8_t layer3
);
224 void set_single_persistent_default_layer(uint8_t default_layer
);
226 void tap_random_base64(void);
228 #define IS_LAYER_ON(layer) (layer_state & (1UL << (layer)))
229 #define IS_LAYER_OFF(layer) (~layer_state & (1UL << (layer)))
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 uint16_t get_record_keycode(keyrecord_t
*record
);
236 uint16_t get_event_keycode(keyevent_t event
);
237 bool process_action_kb(keyrecord_t
*record
);
238 bool process_record_kb(uint16_t keycode
, keyrecord_t
*record
);
239 bool process_record_user(uint16_t keycode
, keyrecord_t
*record
);
241 #ifndef BOOTMAGIC_LITE_COLUMN
242 # define BOOTMAGIC_LITE_COLUMN 0
244 #ifndef BOOTMAGIC_LITE_ROW
245 # define BOOTMAGIC_LITE_ROW 0
248 void bootmagic_lite(void);
250 void reset_keyboard(void);
252 void startup_user(void);
253 void shutdown_user(void);
255 void register_code16(uint16_t code
);
256 void unregister_code16(uint16_t code
);
257 void tap_code16(uint16_t code
);
259 void send_dword(uint32_t number
);
260 void send_word(uint16_t number
);
261 void send_byte(uint8_t number
);
262 void send_nibble(uint8_t number
);
263 uint16_t hex_to_keycode(uint8_t hex
);
265 void led_set_user(uint8_t usb_led
);
266 void led_set_kb(uint8_t usb_led
);
267 bool led_update_user(led_t led_state
);
268 bool led_update_kb(led_t led_state
);
270 void api_send_unicode(uint32_t unicode
);