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)
31 #ifdef BACKLIGHT_ENABLE
32 # ifdef LED_MATRIX_ENABLE
33 # include "ledmatrix.h"
35 # include "backlight.h"
39 #if defined(RGBLIGHT_ENABLE)
40 # include "rgblight.h"
41 #elif defined(RGB_MATRIX_ENABLE)
42 // Dummy define RGBLIGHT_MODE_xxxx
43 # define RGBLIGHT_H_DUMMY_DEFINE
44 # include "rgblight.h"
47 #ifdef RGB_MATRIX_ENABLE
48 # include "rgb_matrix.h"
51 #include "action_layer.h"
53 #include "bootloader.h"
55 #include "config_common.h"
57 #include "action_util.h"
59 #include "send_string_keycodes.h"
64 extern layer_state_t default_layer_state;
66 #ifndef NO_ACTION_LAYER
67 extern layer_state_t layer_state;
70 #if defined(MIDI_ENABLE) && defined(MIDI_ADVANCED)
71 # include "process_midi.h"
76 # include "process_audio.h"
78 # include "process_clicky.h"
83 # include "process_steno.h"
86 #if defined(AUDIO_ENABLE) || (defined(MIDI_ENABLE) && defined(MIDI_BASIC))
87 # include "process_music.h"
91 # include "process_leader.h"
95 # include "process_unicode.h"
99 # include "process_ucis.h"
102 #ifdef UNICODEMAP_ENABLE
103 # include "process_unicodemap.h"
106 #ifdef TAP_DANCE_ENABLE
107 # include "process_tap_dance.h"
110 #ifdef PRINTING_ENABLE
111 # include "process_printer.h"
114 #ifdef AUTO_SHIFT_ENABLE
115 # include "process_auto_shift.h"
119 # include "process_combo.h"
122 #ifdef KEY_LOCK_ENABLE
123 # include "process_key_lock.h"
126 #ifdef TERMINAL_ENABLE
127 # include "process_terminal.h"
129 # include "process_terminal_nop.h"
132 #ifdef SPACE_CADET_ENABLE
133 # include "process_space_cadet.h"
136 #ifdef HD44780_ENABLE
137 # include "hd44780.h"
144 #ifdef OLED_DRIVER_ENABLE
145 # include "oled_driver.h"
148 #ifdef DIP_SWITCH_ENABLE
149 #include "dip_switch.h"
152 #ifdef DYNAMIC_MACRO_ENABLE
153 #include "process_dynamic_macro.h"
157 // Function substitutions to ease GPIO manipulation
159 typedef uint8_t pin_t;
161 # define setPinInput(pin) (DDRx_ADDRESS(pin) &= ~_BV((pin)&0xF))
162 # define setPinInputHigh(pin) (DDRx_ADDRESS(pin) &= ~_BV((pin)&0xF), PORTx_ADDRESS(pin) |= _BV((pin)&0xF))
163 # define setPinInputLow(pin) _Static_assert(0, "AVR processors cannot implement an input as pull low")
164 # define setPinOutput(pin) (DDRx_ADDRESS(pin) |= _BV((pin)&0xF))
166 # define writePinHigh(pin) (PORTx_ADDRESS(pin) |= _BV((pin)&0xF))
167 # define writePinLow(pin) (PORTx_ADDRESS(pin) &= ~_BV((pin)&0xF))
168 # define writePin(pin, level) ((level) ? writePinHigh(pin) : writePinLow(pin))
170 # define readPin(pin) ((bool)(PINx_ADDRESS(pin) & _BV((pin)&0xF)))
171 #elif defined(PROTOCOL_CHIBIOS)
172 typedef ioline_t pin_t;
174 # define setPinInput(pin) palSetLineMode(pin, PAL_MODE_INPUT)
175 # define setPinInputHigh(pin) palSetLineMode(pin, PAL_MODE_INPUT_PULLUP)
176 # define setPinInputLow(pin) palSetLineMode(pin, PAL_MODE_INPUT_PULLDOWN)
177 # define setPinOutput(pin) palSetLineMode(pin, PAL_MODE_OUTPUT_PUSHPULL)
179 # define writePinHigh(pin) palSetLine(pin)
180 # define writePinLow(pin) palClearLine(pin)
181 # define writePin(pin, level) ((level) ? writePinHigh(pin) : writePinLow(pin))
183 # define readPin(pin) palReadLine(pin)
186 // Send string macros
187 #define STRINGIZE(z) #z
188 #define ADD_SLASH_X(y) STRINGIZE(\x##y)
189 #define SYMBOL_STR(x) ADD_SLASH_X(x)
191 #define SS_TAP_CODE 1
192 #define SS_DOWN_CODE 2
195 #define SS_TAP(keycode) "\1" SYMBOL_STR(keycode)
196 #define SS_DOWN(keycode) "\2" SYMBOL_STR(keycode)
197 #define SS_UP(keycode) "\3" SYMBOL_STR(keycode)
199 // `string` arguments must not be parenthesized
200 #define SS_LCTRL(string) SS_DOWN(X_LCTRL) string SS_UP(X_LCTRL)
201 #define SS_LGUI(string) SS_DOWN(X_LGUI) string SS_UP(X_LGUI)
202 #define SS_LCMD(string) SS_LGUI(string)
203 #define SS_LWIN(string) SS_LGUI(string)
204 #define SS_LALT(string) SS_DOWN(X_LALT) string SS_UP(X_LALT)
205 #define SS_LSFT(string) SS_DOWN(X_LSHIFT) string SS_UP(X_LSHIFT)
206 #define SS_RALT(string) SS_DOWN(X_RALT) string SS_UP(X_RALT)
207 #define SS_ALGR(string) SS_RALT(string)
209 #define SEND_STRING(string) send_string_P(PSTR(string))
211 extern const bool ascii_to_shift_lut[128];
212 extern const bool ascii_to_altgr_lut[128];
213 extern const uint8_t ascii_to_keycode_lut[128];
215 void send_string(const char *str);
216 void send_string_with_delay(const char *str, uint8_t interval);
217 void send_string_P(const char *str);
218 void send_string_with_delay_P(const char *str, uint8_t interval);
219 void send_char(char ascii_code);
222 void update_tri_layer(uint8_t layer1, uint8_t layer2, uint8_t layer3);
223 layer_state_t update_tri_layer_state(layer_state_t state, uint8_t layer1, uint8_t layer2, uint8_t layer3);
225 void set_single_persistent_default_layer(uint8_t default_layer);
227 void tap_random_base64(void);
229 #define IS_LAYER_ON(layer) (layer_state & (1UL << (layer)))
230 #define IS_LAYER_OFF(layer) (~layer_state & (1UL << (layer)))
232 void matrix_init_kb(void);
233 void matrix_scan_kb(void);
234 void matrix_init_user(void);
235 void matrix_scan_user(void);
236 uint16_t get_record_keycode(keyrecord_t *record);
237 uint16_t get_event_keycode(keyevent_t event);
238 bool process_action_kb(keyrecord_t *record);
239 bool process_record_kb(uint16_t keycode, keyrecord_t *record);
240 bool process_record_user(uint16_t keycode, keyrecord_t *record);
242 #ifndef BOOTMAGIC_LITE_COLUMN
243 # define BOOTMAGIC_LITE_COLUMN 0
245 #ifndef BOOTMAGIC_LITE_ROW
246 # define BOOTMAGIC_LITE_ROW 0
249 void bootmagic_lite(void);
251 void reset_keyboard(void);
253 void startup_user(void);
254 void shutdown_user(void);
256 void register_code16(uint16_t code);
257 void unregister_code16(uint16_t code);
258 void tap_code16(uint16_t code);
260 #ifdef BACKLIGHT_ENABLE
261 void backlight_init_ports(void);
262 void backlight_task(void);
263 void backlight_task_internal(void);
264 void backlight_on(pin_t backlight_pin);
265 void backlight_off(pin_t backlight_pin);
267 # ifdef BACKLIGHT_BREATHING
268 void breathing_task(void);
269 void breathing_enable(void);
270 void breathing_pulse(void);
271 void breathing_disable(void);
272 void breathing_self_disable(void);
273 void breathing_toggle(void);
274 bool is_breathing(void);
276 void breathing_intensity_default(void);
277 void breathing_period_default(void);
278 void breathing_period_set(uint8_t value);
279 void breathing_period_inc(void);
280 void breathing_period_dec(void);
284 void send_dword(uint32_t number);
285 void send_word(uint16_t number);
286 void send_byte(uint8_t number);
287 void send_nibble(uint8_t number);
288 uint16_t hex_to_keycode(uint8_t hex);
290 void led_set_user(uint8_t usb_led);
291 void led_set_kb(uint8_t usb_led);
292 bool led_update_user(led_t led_state);
293 bool led_update_kb(led_t led_state);
295 void api_send_unicode(uint32_t unicode);