2020-10-18 00:46:57 +06:00
|
|
|
/* Copyright 2020 Christopher Courtney, aka Drashna Jael're (@drashna) <drashna@live.com>
|
|
|
|
*
|
|
|
|
* 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-18 01:59:54 +06:00
|
|
|
|
2017-11-07 11:11:08 +06:00
|
|
|
#include "drashna.h"
|
|
|
|
|
2018-05-02 21:39:46 +06:00
|
|
|
userspace_config_t userspace_config;
|
|
|
|
|
2019-07-23 09:22:33 +06:00
|
|
|
bool mod_key_press_timer(uint16_t code, uint16_t mod_code, bool pressed) {
|
2019-05-07 11:34:09 +06:00
|
|
|
static uint16_t this_timer;
|
2019-07-23 09:22:33 +06:00
|
|
|
if (pressed) {
|
|
|
|
this_timer = timer_read();
|
2019-05-07 11:34:09 +06:00
|
|
|
} else {
|
2019-07-23 09:22:33 +06:00
|
|
|
if (timer_elapsed(this_timer) < TAPPING_TERM) {
|
2019-05-07 11:34:09 +06:00
|
|
|
tap_code(code);
|
|
|
|
} else {
|
|
|
|
register_code(mod_code);
|
|
|
|
tap_code(code);
|
|
|
|
unregister_code(mod_code);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
2018-07-17 07:04:32 +06:00
|
|
|
}
|
|
|
|
|
2019-07-23 09:22:33 +06: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 11:34:09 +06:00
|
|
|
} else {
|
2019-07-23 09:22:33 +06:00
|
|
|
if (timer_elapsed(this_timer) < TAPPING_TERM) {
|
2019-05-07 11:34:09 +06:00
|
|
|
tap_code(code);
|
|
|
|
} else {
|
|
|
|
register_code(mod_code);
|
|
|
|
tap_code(code);
|
|
|
|
unregister_code(mod_code);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
2018-07-17 07:04:32 +06:00
|
|
|
}
|
2017-11-18 01:59:54 +06:00
|
|
|
|
2019-11-21 02:37:24 +06:00
|
|
|
__attribute__((weak)) void keyboard_pre_init_keymap(void) {}
|
2021-08-22 02:34:44 +06:00
|
|
|
void keyboard_pre_init_user(void) {
|
2019-11-21 02:37:24 +06:00
|
|
|
userspace_config.raw = eeconfig_read_user();
|
|
|
|
keyboard_pre_init_keymap();
|
|
|
|
}
|
2017-11-11 09:58:53 +06: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
|
|
|
|
// Call user matrix init, set default RGB colors and then
|
|
|
|
// call the keymap's init function
|
2021-08-22 02:34:44 +06:00
|
|
|
__attribute__((weak)) void matrix_init_keymap(void) {}
|
|
|
|
__attribute__((weak)) void matrix_init_secret(void) {}
|
|
|
|
void matrix_init_user(void) {
|
2019-11-21 02:37:24 +06:00
|
|
|
#if defined(BOOTLOADER_CATERINA) && defined(__AVR__)
|
2019-07-23 09:22:33 +06:00
|
|
|
DDRD &= ~(1 << 5);
|
|
|
|
PORTD &= ~(1 << 5);
|
2017-11-07 11:11:08 +06:00
|
|
|
|
2019-07-23 09:22:33 +06:00
|
|
|
DDRB &= ~(1 << 0);
|
|
|
|
PORTB &= ~(1 << 0);
|
|
|
|
#endif
|
2021-01-22 22:23:03 +06:00
|
|
|
|
|
|
|
matrix_init_secret();
|
2019-05-07 11:34:09 +06:00
|
|
|
matrix_init_keymap();
|
2018-11-27 06:45:24 +06:00
|
|
|
}
|
|
|
|
|
2019-11-21 02:37:24 +06:00
|
|
|
__attribute__((weak)) void keyboard_post_init_keymap(void) {}
|
2021-08-22 02:34:44 +06:00
|
|
|
void keyboard_post_init_user(void) {
|
2020-04-01 05:26:43 +06:00
|
|
|
#if defined(RGBLIGHT_ENABLE)
|
|
|
|
keyboard_post_init_rgb_light();
|
|
|
|
#endif
|
|
|
|
#if defined(RGB_MATRIX_ENABLE)
|
|
|
|
keyboard_post_init_rgb_matrix();
|
2021-07-01 13:42:32 +06:00
|
|
|
#endif
|
|
|
|
#if defined(SPLIT_KEYBOARD) && defined(SPLIT_TRANSACTION_IDS_USER)
|
|
|
|
keyboard_post_init_transport_sync();
|
2019-02-17 08:28:04 +06:00
|
|
|
#endif
|
2019-05-07 11:34:09 +06:00
|
|
|
keyboard_post_init_keymap();
|
2019-02-17 08:28:04 +06:00
|
|
|
}
|
2018-12-05 03:27:41 +06:00
|
|
|
|
2021-01-22 22:23:03 +06:00
|
|
|
#ifdef RGB_MATRIX_ENABLE
|
2019-11-21 02:37:24 +06:00
|
|
|
void rgb_matrix_update_pwm_buffers(void);
|
2021-01-22 22:23:03 +06:00
|
|
|
#endif
|
2019-09-07 21:57:30 +06:00
|
|
|
|
2021-08-22 02:34:44 +06:00
|
|
|
__attribute__((weak)) void shutdown_keymap(void) {}
|
|
|
|
void shutdown_user(void) {
|
2019-07-23 09:22:33 +06:00
|
|
|
#ifdef RGBLIGHT_ENABLE
|
|
|
|
rgblight_enable_noeeprom();
|
|
|
|
rgblight_mode_noeeprom(1);
|
|
|
|
rgblight_setrgb_red();
|
2021-07-27 06:59:49 +06:00
|
|
|
#endif // RGBLIGHT_ENABLE
|
2019-07-23 09:22:33 +06:00
|
|
|
#ifdef RGB_MATRIX_ENABLE
|
2019-11-21 02:37:24 +06:00
|
|
|
rgb_matrix_set_color_all(0xFF, 0x00, 0x00);
|
2019-09-07 21:57:30 +06:00
|
|
|
rgb_matrix_update_pwm_buffers();
|
2020-06-15 16:41:28 +06:00
|
|
|
|
2021-07-27 06:59:49 +06:00
|
|
|
#endif // RGB_MATRIX_ENABLE
|
2019-05-07 11:34:09 +06:00
|
|
|
shutdown_keymap();
|
2018-08-29 23:42:15 +06:00
|
|
|
}
|
|
|
|
|
2019-11-21 02:37:24 +06:00
|
|
|
__attribute__((weak)) void suspend_power_down_keymap(void) {}
|
2021-08-24 12:28:26 +06:00
|
|
|
|
|
|
|
void suspend_power_down_user(void) {
|
|
|
|
#ifdef OLED_ENABLE
|
2021-02-24 00:57:24 +06:00
|
|
|
oled_off();
|
|
|
|
#endif
|
|
|
|
suspend_power_down_keymap();
|
|
|
|
}
|
2018-07-17 07:04:32 +06:00
|
|
|
|
2019-11-21 02:37:24 +06:00
|
|
|
__attribute__((weak)) void suspend_wakeup_init_keymap(void) {}
|
2021-08-22 02:34:44 +06:00
|
|
|
void suspend_wakeup_init_user(void) {
|
2021-07-27 06:59:49 +06:00
|
|
|
if (layer_state_is(_GAMEPAD)) {
|
|
|
|
layer_off(_GAMEPAD);
|
|
|
|
}
|
|
|
|
if (layer_state_is(_DIABLO)) {
|
|
|
|
layer_off(_DIABLO);
|
|
|
|
}
|
2021-07-01 13:42:32 +06:00
|
|
|
suspend_wakeup_init_keymap();
|
|
|
|
}
|
2018-07-17 07:04:32 +06:00
|
|
|
|
2018-03-26 02:01:15 +06:00
|
|
|
// No global matrix scan code, so just run keymap's matrix
|
2017-11-11 09:58:53 +06:00
|
|
|
// scan function
|
2021-08-22 02:34:44 +06:00
|
|
|
__attribute__((weak)) void matrix_scan_keymap(void) {}
|
|
|
|
__attribute__((weak)) void matrix_scan_secret(void) {}
|
|
|
|
void matrix_scan_user(void) {
|
2019-05-07 11:34:09 +06:00
|
|
|
static bool has_ran_yet;
|
|
|
|
if (!has_ran_yet) {
|
|
|
|
has_ran_yet = true;
|
|
|
|
startup_user();
|
|
|
|
}
|
2018-05-02 21:39:46 +06:00
|
|
|
|
2021-07-27 06:59:49 +06:00
|
|
|
#ifdef TAP_DANCE_ENABLE // Run Diablo 3 macro checking code.
|
2019-05-07 11:34:09 +06:00
|
|
|
run_diablo_macro_check();
|
2021-07-27 06:59:49 +06:00
|
|
|
#endif // TAP_DANCE_ENABLE
|
2018-05-02 21:39:46 +06:00
|
|
|
|
2020-04-01 05:26:43 +06:00
|
|
|
#if defined(RGBLIGHT_ENABLE)
|
|
|
|
matrix_scan_rgb_light();
|
2021-07-27 06:59:49 +06:00
|
|
|
#endif // RGBLIGHT_ENABLE
|
2020-04-01 05:26:43 +06:00
|
|
|
#if defined(RGB_MATRIX_ENABLE)
|
|
|
|
matrix_scan_rgb_matrix();
|
|
|
|
#endif
|
2018-06-01 11:11:06 +06:00
|
|
|
|
2021-01-22 22:23:03 +06:00
|
|
|
matrix_scan_secret();
|
|
|
|
|
2019-05-07 11:34:09 +06:00
|
|
|
matrix_scan_keymap();
|
2017-11-07 11:11:08 +06:00
|
|
|
}
|
|
|
|
|
2021-02-24 00:57:24 +06:00
|
|
|
#ifdef AUDIO_ENABLE
|
|
|
|
float doom_song[][2] = SONG(E1M1_DOOM);
|
|
|
|
#endif
|
|
|
|
|
2017-11-11 09:58:53 +06:00
|
|
|
// on layer change, no matter where the change was initiated
|
|
|
|
// Then runs keymap's layer change check
|
2021-08-22 02:34:44 +06:00
|
|
|
__attribute__((weak)) layer_state_t layer_state_set_keymap(layer_state_t state) { return state; }
|
|
|
|
layer_state_t layer_state_set_user(layer_state_t state) {
|
2021-07-27 06:59:49 +06:00
|
|
|
if (!is_keyboard_master()) {
|
|
|
|
return state;
|
|
|
|
}
|
2021-02-24 00:57:24 +06:00
|
|
|
|
2019-05-07 11:34:09 +06:00
|
|
|
state = update_tri_layer_state(state, _RAISE, _LOWER, _ADJUST);
|
2020-04-01 05:26:43 +06:00
|
|
|
#if defined(RGBLIGHT_ENABLE)
|
|
|
|
state = layer_state_set_rgb_light(state);
|
2021-07-27 06:59:49 +06:00
|
|
|
#endif // RGBLIGHT_ENABLE
|
2021-02-24 00:57:24 +06:00
|
|
|
#if defined(AUDIO_ENABLE) && !defined(__arm__)
|
|
|
|
static bool is_gamepad_on = false;
|
|
|
|
if (layer_state_cmp(state, _GAMEPAD) != is_gamepad_on) {
|
|
|
|
is_gamepad_on = layer_state_cmp(state, _GAMEPAD);
|
|
|
|
if (is_gamepad_on) {
|
|
|
|
PLAY_LOOP(doom_song);
|
|
|
|
} else {
|
|
|
|
stop_all_notes();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
2021-08-24 14:37:14 +06:00
|
|
|
state = layer_state_set_keymap(state);
|
2021-05-25 22:24:01 +06:00
|
|
|
return state;
|
2017-11-07 11:11:08 +06:00
|
|
|
}
|
2017-11-18 01:59:54 +06:00
|
|
|
|
2018-12-05 03:27:41 +06:00
|
|
|
// Runs state check and changes underglow color and animation
|
2021-08-22 02:34:44 +06:00
|
|
|
__attribute__((weak)) layer_state_t default_layer_state_set_keymap(layer_state_t state) { return state; }
|
|
|
|
layer_state_t default_layer_state_set_user(layer_state_t state) {
|
2021-07-27 06:59:49 +06:00
|
|
|
if (!is_keyboard_master()) {
|
|
|
|
return state;
|
|
|
|
}
|
2021-01-22 22:23:03 +06:00
|
|
|
|
2019-05-07 11:34:09 +06:00
|
|
|
state = default_layer_state_set_keymap(state);
|
2019-02-17 08:28:04 +06:00
|
|
|
#if 0
|
2019-11-21 02:37:24 +06:00
|
|
|
# if defined(RGBLIGHT_ENABLE) || defined(RGB_MATRIX_ENABLE)
|
2018-11-27 06:45:24 +06:00
|
|
|
state = default_layer_state_set_rgb(state);
|
2021-07-27 06:59:49 +06:00
|
|
|
# endif // RGBLIGHT_ENABLE
|
2019-02-17 08:28:04 +06:00
|
|
|
#endif
|
2019-05-07 11:34:09 +06:00
|
|
|
return state;
|
2018-07-17 07:04:32 +06:00
|
|
|
}
|
|
|
|
|
2019-11-21 02:37:24 +06:00
|
|
|
__attribute__((weak)) void led_set_keymap(uint8_t usb_led) {}
|
2021-08-22 02:34:44 +06:00
|
|
|
void led_set_user(uint8_t usb_led) { led_set_keymap(usb_led); }
|
2018-10-16 01:34:49 +06:00
|
|
|
|
2019-11-21 02:37:24 +06:00
|
|
|
__attribute__((weak)) void eeconfig_init_keymap(void) {}
|
2021-08-22 02:34:44 +06:00
|
|
|
void eeconfig_init_user(void) {
|
2019-07-23 09:22:33 +06:00
|
|
|
userspace_config.raw = 0;
|
2019-05-07 11:34:09 +06:00
|
|
|
userspace_config.rgb_layer_change = true;
|
|
|
|
eeconfig_update_user(userspace_config.raw);
|
2019-07-23 09:22:33 +06:00
|
|
|
eeconfig_init_keymap();
|
|
|
|
keyboard_init();
|
2018-10-16 01:34:49 +06:00
|
|
|
}
|
2019-10-17 02:11:22 +06:00
|
|
|
|
|
|
|
bool hasAllBitsInMask(uint8_t value, uint8_t mask) {
|
|
|
|
value &= 0xF;
|
|
|
|
mask &= 0xF;
|
|
|
|
|
|
|
|
return (value & mask) == mask;
|
|
|
|
}
|
2021-08-22 02:34:44 +06:00
|
|
|
|
|
|
|
#ifdef SPLIT_KEYBOARD
|
|
|
|
__attribute__((weak)) void matrix_slave_scan_keymap(void) {}
|
|
|
|
void matrix_slave_scan_user(void) {
|
|
|
|
# if defined(AUDIO_ENABLE)
|
|
|
|
# if !defined(NO_MUSIC_MODE)
|
|
|
|
music_task();
|
|
|
|
# endif
|
2021-09-30 00:16:11 +06:00
|
|
|
# ifdef AUDIO_INIT_DELAY
|
2021-08-22 02:34:44 +06:00
|
|
|
if (!is_keyboard_master()) {
|
2021-09-30 00:16:11 +06:00
|
|
|
static bool delayed_tasks_run = false;
|
2021-08-22 02:34:44 +06:00
|
|
|
static uint16_t delayed_task_timer = 0;
|
|
|
|
if (!delayed_tasks_run) {
|
|
|
|
if (!delayed_task_timer) {
|
|
|
|
delayed_task_timer = timer_read();
|
|
|
|
} else if (timer_elapsed(delayed_task_timer) > 300) {
|
|
|
|
audio_startup();
|
|
|
|
delayed_tasks_run = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-09-30 00:16:11 +06:00
|
|
|
# endif
|
2021-08-22 02:34:44 +06:00
|
|
|
# endif
|
|
|
|
# ifdef SEQUENCER_ENABLE
|
|
|
|
sequencer_task();
|
|
|
|
# endif
|
|
|
|
# ifdef LED_MATRIX_ENABLE
|
|
|
|
led_matrix_task();
|
|
|
|
# endif
|
|
|
|
# ifdef HAPTIC_ENABLE
|
|
|
|
haptic_task();
|
|
|
|
# endif
|
|
|
|
|
|
|
|
matrix_slave_scan_keymap();
|
|
|
|
}
|
|
|
|
#endif
|