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 #ifdef LED_MATRIX_ENABLE
32 #include "ledmatrix.h"
34 #include "backlight.h"
37 #ifdef RGBLIGHT_ENABLE
40 #ifdef RGB_MATRIX_ENABLE
41 /* dummy define RGBLIGHT_MODE_xxxx */
42 #define RGBLIGHT_H_DUMMY_DEFINE
47 #ifdef RGB_MATRIX_ENABLE
48 #include "rgb_matrix.h"
51 #include "action_layer.h"
54 #include "bootloader.h"
56 #include "config_common.h"
58 #include "action_util.h"
61 #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;
72 #include "process_midi.h"
78 #include "process_audio.h"
80 #include "process_clicky.h"
81 #endif // AUDIO_CLICKY
85 #include "process_steno.h"
88 #if defined(AUDIO_ENABLE) || (defined(MIDI_ENABLE) && defined(MIDI_BASIC))
89 #include "process_music.h"
93 #include "process_leader.h"
97 #include "process_unicode.h"
101 #include "process_ucis.h"
104 #ifdef UNICODEMAP_ENABLE
105 #include "process_unicodemap.h"
108 #ifdef TAP_DANCE_ENABLE
109 #include "process_tap_dance.h"
112 #ifdef PRINTING_ENABLE
113 #include "process_printer.h"
116 #ifdef AUTO_SHIFT_ENABLE
117 #include "process_auto_shift.h"
121 #include "process_combo.h"
124 #ifdef KEY_LOCK_ENABLE
125 #include "process_key_lock.h"
128 #ifdef TERMINAL_ENABLE
129 #include "process_terminal.h"
131 #include "process_terminal_nop.h"
134 #ifdef SPACE_CADET_ENABLE
135 #include "process_space_cadet.h"
138 #ifdef HD44780_ENABLE
146 #ifdef OLED_DRIVER_ENABLE
147 #include "oled_driver.h"
150 //Function substitutions to ease GPIO manipulation
152 #define PIN_ADDRESS(p, offset) _SFR_IO8(ADDRESS_BASE + (p >> PORT_SHIFTER) + offset)
154 #define pin_t uint8_t
155 #define setPinInput(pin) PIN_ADDRESS(pin, 1) &= ~ _BV(pin & 0xF)
156 #define setPinInputHigh(pin) ({\
157 PIN_ADDRESS(pin, 1) &= ~ _BV(pin & 0xF);\
158 PIN_ADDRESS(pin, 2) |= _BV(pin & 0xF);\
160 #define setPinInputLow(pin) _Static_assert(0, "AVR Processors cannot impliment an input as pull low")
161 #define setPinOutput(pin) PIN_ADDRESS(pin, 1) |= _BV(pin & 0xF)
163 #define writePinHigh(pin) PIN_ADDRESS(pin, 2) |= _BV(pin & 0xF)
164 #define writePinLow(pin) PIN_ADDRESS(pin, 2) &= ~_BV(pin & 0xF)
165 static inline void writePin(pin_t pin, uint8_t level){
167 PIN_ADDRESS(pin, 2) |= _BV(pin & 0xF);
169 PIN_ADDRESS(pin, 2) &= ~_BV(pin & 0xF);
173 #define readPin(pin) ((bool)(PIN_ADDRESS(pin, 0) & _BV(pin & 0xF)))
174 #elif defined(PROTOCOL_CHIBIOS)
175 #define pin_t ioline_t
176 #define setPinInput(pin) palSetLineMode(pin, PAL_MODE_INPUT)
177 #define setPinInputHigh(pin) palSetLineMode(pin, PAL_MODE_INPUT_PULLUP)
178 #define setPinInputLow(pin) palSetLineMode(pin, PAL_MODE_INPUT_PULLDOWN)
179 #define setPinOutput(pin) palSetLineMode(pin, PAL_MODE_OUTPUT_PUSHPULL)
181 #define writePinHigh(pin) palSetLine(pin)
182 #define writePinLow(pin) palClearLine(pin)
183 static inline void writePin(pin_t pin, uint8_t level){
191 #define readPin(pin) palReadLine(pin)
194 #define STRINGIZE(z) #z
195 #define ADD_SLASH_X(y) STRINGIZE(\x ## y)
196 #define SYMBOL_STR(x) ADD_SLASH_X(x)
198 #define SS_TAP_CODE 1
199 #define SS_DOWN_CODE 2
202 #define SS_TAP(keycode) "\1" SYMBOL_STR(keycode)
203 #define SS_DOWN(keycode) "\2" SYMBOL_STR(keycode)
204 #define SS_UP(keycode) "\3" SYMBOL_STR(keycode)
206 #define SS_LCTRL(string) SS_DOWN(X_LCTRL) string SS_UP(X_LCTRL)
207 #define SS_LGUI(string) SS_DOWN(X_LGUI) string SS_UP(X_LGUI)
208 #define SS_LCMD(string) SS_LGUI(string)
209 #define SS_LWIN(string) SS_LGUI(string)
210 #define SS_LALT(string) SS_DOWN(X_LALT) string SS_UP(X_LALT)
211 #define SS_LSFT(string) SS_DOWN(X_LSHIFT) string SS_UP(X_LSHIFT)
212 #define SS_RALT(string) SS_DOWN(X_RALT) string SS_UP(X_RALT)
213 #define SS_ALGR(string) SS_RALT(string)
215 #define SEND_STRING(str) send_string_P(PSTR(str))
216 extern const bool ascii_to_shift_lut[0x80];
217 extern const bool ascii_to_altgr_lut[0x80];
218 extern const uint8_t ascii_to_keycode_lut[0x80];
219 void send_string(const char *str);
220 void send_string_with_delay(const char *str, uint8_t interval);
221 void send_string_P(const char *str);
222 void send_string_with_delay_P(const char *str, uint8_t interval);
223 void send_char(char ascii_code);
226 void update_tri_layer(uint8_t layer1, uint8_t layer2, uint8_t layer3);
227 uint32_t update_tri_layer_state(uint32_t state, uint8_t layer1, uint8_t layer2, uint8_t layer3);
229 void set_single_persistent_default_layer(uint8_t default_layer);
231 void tap_random_base64(void);
233 #define IS_LAYER_ON(layer) (layer_state & (1UL << (layer)))
234 #define IS_LAYER_OFF(layer) (~layer_state & (1UL << (layer)))
236 void matrix_init_kb(void);
237 void matrix_scan_kb(void);
238 void matrix_init_user(void);
239 void matrix_scan_user(void);
240 uint16_t get_record_keycode(keyrecord_t *record);
241 uint16_t get_event_keycode(keyevent_t event);
242 bool process_action_kb(keyrecord_t *record);
243 bool process_record_kb(uint16_t keycode, keyrecord_t *record);
244 bool process_record_user(uint16_t keycode, keyrecord_t *record);
246 #ifndef BOOTMAGIC_LITE_COLUMN
247 #define BOOTMAGIC_LITE_COLUMN 0
249 #ifndef BOOTMAGIC_LITE_ROW
250 #define BOOTMAGIC_LITE_ROW 0
253 void bootmagic_lite(void);
255 void reset_keyboard(void);
257 void startup_user(void);
258 void shutdown_user(void);
260 void register_code16(uint16_t code);
261 void unregister_code16(uint16_t code);
262 void tap_code16(uint16_t code);
264 #ifdef BACKLIGHT_ENABLE
265 void backlight_init_ports(void);
266 void backlight_task(void);
267 void backlight_task_internal(void);
268 void backlight_on(uint8_t backlight_pin);
269 void backlight_off(uint8_t backlight_pin);
271 #ifdef BACKLIGHT_BREATHING
272 void breathing_task(void);
273 void breathing_enable(void);
274 void breathing_pulse(void);
275 void breathing_disable(void);
276 void breathing_self_disable(void);
277 void breathing_toggle(void);
278 bool is_breathing(void);
280 void breathing_intensity_default(void);
281 void breathing_period_default(void);
282 void breathing_period_set(uint8_t value);
283 void breathing_period_inc(void);
284 void breathing_period_dec(void);
288 void send_dword(uint32_t number);
289 void send_word(uint16_t number);
290 void send_byte(uint8_t number);
291 void send_nibble(uint8_t number);
292 uint16_t hex_to_keycode(uint8_t hex);
294 void led_set_user(uint8_t usb_led);
295 void led_set_kb(uint8_t usb_led);
297 void api_send_unicode(uint32_t unicode);