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/>.
20 #include <avr/pgmspace.h>
22 #include <avr/interrupt.h>
24 #if defined(PROTOCOL_CHIBIOS)
30 #ifdef BACKLIGHT_ENABLE
31 #include "backlight.h"
33 #if !defined(RGBLIGHT_ENABLE) && !defined(RGB_MATRIX_ENABLE)
36 #ifdef RGBLIGHT_ENABLE
39 #ifdef RGB_MATRIX_ENABLE
40 /* dummy define RGBLIGHT_MODE_xxxx */
41 #define RGBLIGHT_H_DUMMY_DEFINE
47 #include "split_flags.h"
50 #ifdef RGB_MATRIX_ENABLE
51 #include "rgb_matrix.h"
54 #include "action_layer.h"
57 #include "bootloader.h"
59 #include "config_common.h"
61 #include "action_util.h"
64 #include "send_string_keycodes.h"
67 extern uint32_t default_layer_state;
69 #ifndef NO_ACTION_LAYER
70 extern uint32_t layer_state;
75 #include "process_midi.h"
81 #include "process_audio.h"
83 #include "process_clicky.h"
84 #endif // AUDIO_CLICKY
88 #include "process_steno.h"
91 #if defined(AUDIO_ENABLE) || (defined(MIDI_ENABLE) && defined(MIDI_BASIC))
92 #include "process_music.h"
96 #include "process_leader.h"
100 #include "process_unicode.h"
104 #include "process_ucis.h"
107 #ifdef UNICODEMAP_ENABLE
108 #include "process_unicodemap.h"
111 #ifdef TAP_DANCE_ENABLE
112 #include "process_tap_dance.h"
115 #ifdef PRINTING_ENABLE
116 #include "process_printer.h"
119 #ifdef AUTO_SHIFT_ENABLE
120 #include "process_auto_shift.h"
124 #include "process_combo.h"
127 #ifdef KEY_LOCK_ENABLE
128 #include "process_key_lock.h"
131 #ifdef TERMINAL_ENABLE
132 #include "process_terminal.h"
134 #include "process_terminal_nop.h"
137 #ifdef HD44780_ENABLE
141 //Function substitutions to ease GPIO manipulation
143 #define PIN_ADDRESS(p, offset) _SFR_IO8(ADDRESS_BASE + (p >> PORT_SHIFTER) + offset)
145 #define pin_t uint8_t
146 #define setPinInput(pin) PIN_ADDRESS(pin, 1) &= ~ _BV(pin & 0xF)
147 #define setPinInputHigh(pin) ({\
148 PIN_ADDRESS(pin, 1) &= ~ _BV(pin & 0xF);\
149 PIN_ADDRESS(pin, 2) |= _BV(pin & 0xF);\
151 #define setPinInputLow(pin) _Static_assert(0, "AVR Processors cannot impliment an input as pull low")
152 #define setPinOutput(pin) PIN_ADDRESS(pin, 1) |= _BV(pin & 0xF)
154 #define writePinHigh(pin) PIN_ADDRESS(pin, 2) |= _BV(pin & 0xF)
155 #define writePinLow(pin) PIN_ADDRESS(pin, 2) &= ~_BV(pin & 0xF)
156 static inline void writePin(pin_t pin, uint8_t level){
158 PIN_ADDRESS(pin, 2) |= _BV(pin & 0xF);
160 PIN_ADDRESS(pin, 2) &= ~_BV(pin & 0xF);
164 #define readPin(pin) ((bool)(PIN_ADDRESS(pin, 0) & _BV(pin & 0xF)))
165 #elif defined(PROTOCOL_CHIBIOS)
166 #define pin_t ioline_t
167 #define setPinInput(pin) palSetLineMode(pin, PAL_MODE_INPUT)
168 #define setPinInputHigh(pin) palSetLineMode(pin, PAL_MODE_INPUT_PULLUP)
169 #define setPinInputLow(pin) palSetLineMode(pin, PAL_MODE_INPUT_PULLDOWN)
170 #define setPinOutput(pin) palSetLineMode(pin, PAL_MODE_OUTPUT_PUSHPULL)
172 #define writePinHigh(pin) palSetLine(pin)
173 #define writePinLow(pin) palClearLine(pin)
174 static inline void writePin(pin_t pin, uint8_t level){
182 #define readPin(pin) palReadLine(pin)
185 #define STRINGIZE(z) #z
186 #define ADD_SLASH_X(y) STRINGIZE(\x ## y)
187 #define SYMBOL_STR(x) ADD_SLASH_X(x)
189 #define SS_TAP(keycode) "\1" SYMBOL_STR(keycode)
190 #define SS_DOWN(keycode) "\2" SYMBOL_STR(keycode)
191 #define SS_UP(keycode) "\3" SYMBOL_STR(keycode)
193 #define SS_LCTRL(string) SS_DOWN(X_LCTRL) string SS_UP(X_LCTRL)
194 #define SS_LGUI(string) SS_DOWN(X_LGUI) string SS_UP(X_LGUI)
195 #define SS_LCMD(string) SS_LGUI(string)
196 #define SS_LWIN(string) SS_LGUI(string)
197 #define SS_LALT(string) SS_DOWN(X_LALT) string SS_UP(X_LALT)
198 #define SS_LSFT(string) SS_DOWN(X_LSHIFT) string SS_UP(X_LSHIFT)
199 #define SS_RALT(string) SS_DOWN(X_RALT) string SS_UP(X_RALT)
200 #define SS_ALGR(string) SS_RALT(string)
202 #define SEND_STRING(str) send_string_P(PSTR(str))
203 extern const bool ascii_to_shift_lut[0x80];
204 extern const uint8_t ascii_to_keycode_lut[0x80];
205 void send_string(const char *str);
206 void send_string_with_delay(const char *str, uint8_t interval);
207 void send_string_P(const char *str);
208 void send_string_with_delay_P(const char *str, uint8_t interval);
209 void send_char(char ascii_code);
212 void update_tri_layer(uint8_t layer1, uint8_t layer2, uint8_t layer3);
213 uint32_t update_tri_layer_state(uint32_t state, uint8_t layer1, uint8_t layer2, uint8_t layer3);
215 void set_single_persistent_default_layer(uint8_t default_layer);
217 void tap_random_base64(void);
219 #define IS_LAYER_ON(layer) (layer_state & (1UL << (layer)))
220 #define IS_LAYER_OFF(layer) (~layer_state & (1UL << (layer)))
222 void matrix_init_kb(void);
223 void matrix_scan_kb(void);
224 void matrix_init_user(void);
225 void matrix_scan_user(void);
226 bool process_action_kb(keyrecord_t *record);
227 bool process_record_kb(uint16_t keycode, keyrecord_t *record);
228 bool process_record_user(uint16_t keycode, keyrecord_t *record);
230 #ifndef BOOTMAGIC_LITE_COLUMN
231 #define BOOTMAGIC_LITE_COLUMN 0
233 #ifndef BOOTMAGIC_LITE_ROW
234 #define BOOTMAGIC_LITE_ROW 0
237 void bootmagic_lite(void);
239 void reset_keyboard(void);
241 void startup_user(void);
242 void shutdown_user(void);
244 void register_code16(uint16_t code);
245 void unregister_code16(uint16_t code);
246 void tap_code16(uint16_t code);
248 #ifdef BACKLIGHT_ENABLE
249 void backlight_init_ports(void);
250 void backlight_task(void);
252 #ifdef BACKLIGHT_BREATHING
253 void breathing_enable(void);
254 void breathing_pulse(void);
255 void breathing_disable(void);
256 void breathing_self_disable(void);
257 void breathing_toggle(void);
258 bool is_breathing(void);
260 void breathing_intensity_default(void);
261 void breathing_period_default(void);
262 void breathing_period_set(uint8_t value);
263 void breathing_period_inc(void);
264 void breathing_period_dec(void);
268 void send_dword(uint32_t number);
269 void send_word(uint16_t number);
270 void send_byte(uint8_t number);
271 void send_nibble(uint8_t number);
272 uint16_t hex_to_keycode(uint8_t hex);
274 void led_set_user(uint8_t usb_led);
275 void led_set_kb(uint8_t usb_led);
277 void api_send_unicode(uint32_t unicode);