2017-11-17 20:59:54 +01:00
|
|
|
/*
|
|
|
|
Copyright 2017 Christopher Courtney <drashna@live.com> @drashna
|
|
|
|
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2017-11-07 06:11:08 +01:00
|
|
|
#include "drashna.h"
|
|
|
|
|
2018-05-02 17:39:46 +02:00
|
|
|
userspace_config_t userspace_config;
|
2018-11-06 06:36:26 +01:00
|
|
|
#if (defined(UNICODE_ENABLE) || defined(UNICODEMAP_ENABLE) || defined(UCIS_ENABLE))
|
2019-07-23 05:22:33 +02:00
|
|
|
# define DRASHNA_UNICODE_MODE UC_WIN
|
2018-11-06 06:36:26 +01:00
|
|
|
#else
|
2019-07-23 05:22:33 +02:00
|
|
|
// set to 2 for UC_WIN, set to 4 for UC_WINC
|
|
|
|
# define DRASHNA_UNICODE_MODE 2
|
2018-11-06 06:36:26 +01:00
|
|
|
#endif
|
2018-05-02 17:39:46 +02:00
|
|
|
|
2019-09-07 17:57:30 +02:00
|
|
|
|
2018-03-01 16:46:57 +01:00
|
|
|
|
2019-07-23 05:22:33 +02:00
|
|
|
bool mod_key_press_timer(uint16_t code, uint16_t mod_code, bool pressed) {
|
2019-05-07 07:34:09 +02:00
|
|
|
static uint16_t this_timer;
|
2019-07-23 05:22:33 +02:00
|
|
|
if (pressed) {
|
|
|
|
this_timer = timer_read();
|
2019-05-07 07:34:09 +02:00
|
|
|
} else {
|
2019-07-23 05:22:33 +02:00
|
|
|
if (timer_elapsed(this_timer) < TAPPING_TERM) {
|
2019-05-07 07:34:09 +02:00
|
|
|
tap_code(code);
|
|
|
|
} else {
|
|
|
|
register_code(mod_code);
|
|
|
|
tap_code(code);
|
|
|
|
unregister_code(mod_code);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
2018-07-17 03:04:32 +02:00
|
|
|
}
|
|
|
|
|
2019-07-23 05:22:33 +02:00
|
|
|
bool mod_key_press(uint16_t code, uint16_t mod_code, bool pressed, uint16_t this_timer) {
|
|
|
|
if (pressed) {
|
|
|
|
this_timer = timer_read();
|
2019-05-07 07:34:09 +02:00
|
|
|
} else {
|
2019-07-23 05:22:33 +02:00
|
|
|
if (timer_elapsed(this_timer) < TAPPING_TERM) {
|
2019-05-07 07:34:09 +02:00
|
|
|
tap_code(code);
|
|
|
|
} else {
|
|
|
|
register_code(mod_code);
|
|
|
|
tap_code(code);
|
|
|
|
unregister_code(mod_code);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
2018-07-17 03:04:32 +02:00
|
|
|
}
|
2017-11-17 20:59:54 +01:00
|
|
|
|
2018-10-26 07:08:49 +02:00
|
|
|
void bootmagic_lite(void) {
|
2019-05-07 07:34:09 +02:00
|
|
|
matrix_scan();
|
2019-07-23 05:22:33 +02:00
|
|
|
#if defined(DEBOUNCING_DELAY) && DEBOUNCING_DELAY > 0
|
|
|
|
wait_ms(DEBOUNCING_DELAY * 2);
|
|
|
|
#elif defined(DEBOUNCE) && DEBOUNCE > 0
|
|
|
|
wait_ms(DEBOUNCE * 2);
|
|
|
|
#else
|
|
|
|
wait_ms(30);
|
|
|
|
#endif
|
2019-05-07 07:34:09 +02:00
|
|
|
matrix_scan();
|
|
|
|
if (matrix_get_row(BOOTMAGIC_LITE_ROW) & (1 << BOOTMAGIC_LITE_COLUMN)) {
|
|
|
|
bootloader_jump();
|
|
|
|
}
|
2018-10-26 07:08:49 +02:00
|
|
|
}
|
|
|
|
|
2017-11-11 04:58:53 +01:00
|
|
|
// Add reconfigurable functions here, for keymap customization
|
|
|
|
// This allows for a global, userspace functions, and continued
|
|
|
|
// customization of the keymap. Use _keymap instead of _user
|
|
|
|
// functions in the keymaps
|
2019-07-23 05:22:33 +02:00
|
|
|
__attribute__((weak))
|
2017-11-07 06:11:08 +01:00
|
|
|
void matrix_init_keymap(void) {}
|
|
|
|
|
2017-11-11 04:58:53 +01:00
|
|
|
// Call user matrix init, set default RGB colors and then
|
|
|
|
// call the keymap's init function
|
2017-11-07 06:11:08 +01:00
|
|
|
void matrix_init_user(void) {
|
2019-05-07 07:34:09 +02:00
|
|
|
userspace_config.raw = eeconfig_read_user();
|
2018-06-01 07:11:06 +02:00
|
|
|
|
2019-07-23 05:22:33 +02:00
|
|
|
#ifdef BOOTLOADER_CATERINA
|
|
|
|
DDRD &= ~(1 << 5);
|
|
|
|
PORTD &= ~(1 << 5);
|
2017-11-07 06:11:08 +01:00
|
|
|
|
2019-07-23 05:22:33 +02:00
|
|
|
DDRB &= ~(1 << 0);
|
|
|
|
PORTB &= ~(1 << 0);
|
|
|
|
#endif
|
2018-05-16 04:34:34 +02:00
|
|
|
|
2019-07-23 05:22:33 +02:00
|
|
|
#if (defined(UNICODE_ENABLE) || defined(UNICODEMAP_ENABLE) || defined(UCIS_ENABLE))
|
|
|
|
set_unicode_input_mode(DRASHNA_UNICODE_MODE);
|
|
|
|
get_unicode_input_mode();
|
|
|
|
#endif // UNICODE_ENABLE
|
2019-05-07 07:34:09 +02:00
|
|
|
matrix_init_keymap();
|
2018-11-27 01:45:24 +01:00
|
|
|
}
|
|
|
|
|
2019-02-17 03:28:04 +01:00
|
|
|
__attribute__((weak))
|
2019-07-23 05:22:33 +02:00
|
|
|
void keyboard_post_init_keymap(void) {}
|
2019-02-17 03:28:04 +01:00
|
|
|
|
2019-07-23 05:22:33 +02:00
|
|
|
void keyboard_post_init_user(void) {
|
2019-09-07 17:57:30 +02:00
|
|
|
#if defined(RGBLIGHT_ENABLE) || defined(RGB_MATRIX_ENABLE)
|
2019-05-07 07:34:09 +02:00
|
|
|
keyboard_post_init_rgb();
|
2019-02-17 03:28:04 +01:00
|
|
|
#endif
|
2019-05-07 07:34:09 +02:00
|
|
|
keyboard_post_init_keymap();
|
2019-02-17 03:28:04 +01:00
|
|
|
}
|
2018-12-04 22:27:41 +01:00
|
|
|
|
2019-07-23 05:22:33 +02:00
|
|
|
__attribute__((weak))
|
2018-12-04 22:27:41 +01:00
|
|
|
void shutdown_keymap(void) {}
|
2018-07-17 03:04:32 +02:00
|
|
|
|
2019-09-07 17:57:30 +02:00
|
|
|
void rgb_matrix_update_pwm_buffers(void);
|
|
|
|
|
2019-07-23 05:22:33 +02:00
|
|
|
void shutdown_user(void) {
|
|
|
|
#ifdef RGBLIGHT_ENABLE
|
|
|
|
rgblight_enable_noeeprom();
|
|
|
|
rgblight_mode_noeeprom(1);
|
|
|
|
rgblight_setrgb_red();
|
|
|
|
#endif // RGBLIGHT_ENABLE
|
|
|
|
#ifdef RGB_MATRIX_ENABLE
|
2019-09-07 17:57:30 +02:00
|
|
|
rgb_matrix_set_color_all( 0xFF, 0x00, 0x00 );
|
|
|
|
rgb_matrix_update_pwm_buffers();
|
|
|
|
|
2019-07-23 05:22:33 +02:00
|
|
|
#endif // RGB_MATRIX_ENABLE
|
2019-05-07 07:34:09 +02:00
|
|
|
shutdown_keymap();
|
2018-08-29 19:42:15 +02:00
|
|
|
}
|
|
|
|
|
2019-07-23 05:22:33 +02:00
|
|
|
__attribute__((weak))
|
2018-12-04 22:27:41 +01:00
|
|
|
void suspend_power_down_keymap(void) {}
|
|
|
|
|
2018-10-02 03:00:14 +02:00
|
|
|
void suspend_power_down_user(void) {
|
2018-07-17 03:04:32 +02:00
|
|
|
suspend_power_down_keymap();
|
|
|
|
}
|
|
|
|
|
2019-07-23 05:22:33 +02:00
|
|
|
__attribute__((weak))
|
2018-12-04 22:27:41 +01:00
|
|
|
void suspend_wakeup_init_keymap(void) {}
|
|
|
|
|
2018-10-02 03:00:14 +02:00
|
|
|
void suspend_wakeup_init_user(void) {
|
2019-05-07 07:34:09 +02:00
|
|
|
suspend_wakeup_init_keymap();
|
2018-07-17 03:04:32 +02:00
|
|
|
}
|
|
|
|
|
2019-07-23 05:22:33 +02:00
|
|
|
__attribute__((weak))
|
2018-12-04 22:27:41 +01:00
|
|
|
void matrix_scan_keymap(void) {}
|
|
|
|
|
2018-03-25 22:01:15 +02:00
|
|
|
// No global matrix scan code, so just run keymap's matrix
|
2017-11-11 04:58:53 +01:00
|
|
|
// scan function
|
2017-11-07 06:11:08 +01:00
|
|
|
void matrix_scan_user(void) {
|
2019-05-07 07:34:09 +02:00
|
|
|
static bool has_ran_yet;
|
|
|
|
if (!has_ran_yet) {
|
|
|
|
has_ran_yet = true;
|
|
|
|
startup_user();
|
|
|
|
}
|
2018-05-02 17:39:46 +02:00
|
|
|
|
2017-11-17 20:59:54 +01:00
|
|
|
#ifdef TAP_DANCE_ENABLE // Run Diablo 3 macro checking code.
|
2019-05-07 07:34:09 +02:00
|
|
|
run_diablo_macro_check();
|
2019-07-23 05:22:33 +02:00
|
|
|
#endif // TAP_DANCE_ENABLE
|
2018-05-02 17:39:46 +02:00
|
|
|
|
2019-09-07 17:57:30 +02:00
|
|
|
#if defined(RGBLIGHT_ENABLE) || defined(RGB_MATRIX_ENABLE)
|
2019-05-07 07:34:09 +02:00
|
|
|
matrix_scan_rgb();
|
2019-07-23 05:22:33 +02:00
|
|
|
#endif // RGBLIGHT_ENABLE
|
2018-06-01 07:11:06 +02:00
|
|
|
|
2019-05-07 07:34:09 +02:00
|
|
|
matrix_scan_keymap();
|
2017-11-07 06:11:08 +01:00
|
|
|
}
|
|
|
|
|
2019-07-23 05:22:33 +02:00
|
|
|
__attribute__((weak))
|
|
|
|
layer_state_t layer_state_set_keymap(layer_state_t state) { return state; }
|
2017-11-07 06:11:08 +01:00
|
|
|
|
2017-11-11 04:58:53 +01:00
|
|
|
// on layer change, no matter where the change was initiated
|
|
|
|
// Then runs keymap's layer change check
|
2019-05-18 00:21:45 +02:00
|
|
|
layer_state_t layer_state_set_user(layer_state_t state) {
|
2019-05-07 07:34:09 +02:00
|
|
|
state = update_tri_layer_state(state, _RAISE, _LOWER, _ADJUST);
|
2019-09-07 17:57:30 +02:00
|
|
|
#if defined(RGBLIGHT_ENABLE) || defined(RGB_MATRIX_ENABLE)
|
2019-05-07 07:34:09 +02:00
|
|
|
state = layer_state_set_rgb(state);
|
2019-07-23 05:22:33 +02:00
|
|
|
#endif // RGBLIGHT_ENABLE
|
|
|
|
return layer_state_set_keymap(state);
|
2017-11-07 06:11:08 +01:00
|
|
|
}
|
2017-11-17 20:59:54 +01:00
|
|
|
|
2019-07-23 05:22:33 +02:00
|
|
|
__attribute__((weak))
|
|
|
|
layer_state_t default_layer_state_set_keymap(layer_state_t state) { return state; }
|
2018-12-04 22:27:41 +01:00
|
|
|
|
|
|
|
// Runs state check and changes underglow color and animation
|
2019-05-18 00:21:45 +02:00
|
|
|
layer_state_t default_layer_state_set_user(layer_state_t state) {
|
2019-05-07 07:34:09 +02:00
|
|
|
state = default_layer_state_set_keymap(state);
|
2019-02-17 03:28:04 +01:00
|
|
|
#if 0
|
2019-09-07 17:57:30 +02:00
|
|
|
#if defined(RGBLIGHT_ENABLE) || defined(RGB_MATRIX_ENABLE)
|
2018-11-27 01:45:24 +01:00
|
|
|
state = default_layer_state_set_rgb(state);
|
2019-07-23 05:22:33 +02:00
|
|
|
# endif // RGBLIGHT_ENABLE
|
2019-02-17 03:28:04 +01:00
|
|
|
#endif
|
2019-05-07 07:34:09 +02:00
|
|
|
return state;
|
2018-07-17 03:04:32 +02:00
|
|
|
}
|
|
|
|
|
2019-07-23 05:22:33 +02:00
|
|
|
__attribute__((weak))
|
2018-12-04 22:27:41 +01:00
|
|
|
void led_set_keymap(uint8_t usb_led) {}
|
2018-07-17 03:04:32 +02:00
|
|
|
|
2018-03-01 16:46:57 +01:00
|
|
|
// Any custom LED code goes here.
|
|
|
|
// So far, I only have keyboard specific code,
|
2018-03-25 22:01:15 +02:00
|
|
|
// So nothing goes here.
|
2018-03-01 16:46:57 +01:00
|
|
|
void led_set_user(uint8_t usb_led) {
|
2019-05-07 07:34:09 +02:00
|
|
|
led_set_keymap(usb_led);
|
2018-03-01 16:46:57 +01:00
|
|
|
}
|
2018-10-15 21:34:49 +02:00
|
|
|
|
2019-07-23 05:22:33 +02:00
|
|
|
__attribute__((weak))
|
2018-12-04 22:27:41 +01:00
|
|
|
void eeconfig_init_keymap(void) {}
|
|
|
|
|
2018-10-15 21:34:49 +02:00
|
|
|
void eeconfig_init_user(void) {
|
2019-07-23 05:22:33 +02:00
|
|
|
userspace_config.raw = 0;
|
2019-05-07 07:34:09 +02:00
|
|
|
userspace_config.rgb_layer_change = true;
|
|
|
|
eeconfig_update_user(userspace_config.raw);
|
2019-07-23 05:22:33 +02:00
|
|
|
#if (defined(UNICODE_ENABLE) || defined(UNICODEMAP_ENABLE) || defined(UCIS_ENABLE))
|
2018-11-06 06:36:26 +01:00
|
|
|
set_unicode_input_mode(DRASHNA_UNICODE_MODE);
|
|
|
|
get_unicode_input_mode();
|
2019-07-23 05:22:33 +02:00
|
|
|
#else
|
2018-11-06 06:36:26 +01:00
|
|
|
eeprom_update_byte(EECONFIG_UNICODEMODE, DRASHNA_UNICODE_MODE);
|
2019-07-23 05:22:33 +02:00
|
|
|
#endif
|
|
|
|
eeconfig_init_keymap();
|
|
|
|
keyboard_init();
|
2018-10-15 21:34:49 +02:00
|
|
|
}
|