diff options
Diffstat (limited to 'users/drashna')
47 files changed, 1154 insertions, 819 deletions
diff --git a/users/drashna/callbacks.c b/users/drashna/callbacks.c new file mode 100644 index 0000000000..48b076b6ba --- /dev/null +++ b/users/drashna/callbacks.c @@ -0,0 +1,215 @@ +// Copyright 2021 Christopher Courtney, aka Drashna Jael're (@drashna) <drashna@live.com> +// SPDX-License-Identifier: GPL-2.0-or-later + +#include "drashna.h" + +__attribute__((weak)) void keyboard_pre_init_keymap(void) {} +void keyboard_pre_init_user(void) { + userspace_config.raw = eeconfig_read_user(); + keyboard_pre_init_keymap(); +} +// 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 +__attribute__((weak)) void matrix_init_keymap(void) {} +__attribute__((weak)) void matrix_init_secret(void) {} +void matrix_init_user(void) { +#if defined(BOOTLOADER_CATERINA) && defined(__AVR__) && defined(__AVR_ATmega32U4__) + DDRD &= ~(1 << 5); + PORTD &= ~(1 << 5); + + DDRB &= ~(1 << 0); + PORTB &= ~(1 << 0); +#endif +#ifdef CUSTOM_UNICODE_ENABLE + matrix_init_unicode(); +#endif + matrix_init_secret(); + matrix_init_keymap(); +} + +__attribute__((weak)) void keyboard_post_init_keymap(void) {} +void keyboard_post_init_user(void) { +#if defined(RGBLIGHT_ENABLE) + keyboard_post_init_rgb_light(); +#endif +#if defined(RGB_MATRIX_ENABLE) + keyboard_post_init_rgb_matrix(); +#endif +#if defined(SPLIT_KEYBOARD) && defined(SPLIT_TRANSACTION_IDS_USER) + keyboard_post_init_transport_sync(); +#endif + keyboard_post_init_keymap(); +} + +#ifdef RGB_MATRIX_ENABLE +void rgb_matrix_update_pwm_buffers(void); +#endif + +__attribute__((weak)) void shutdown_keymap(void) {} +void shutdown_user(void) { +#ifdef RGBLIGHT_ENABLE + rgblight_enable_noeeprom(); + rgblight_mode_noeeprom(1); + rgblight_setrgb_red(); +#endif // RGBLIGHT_ENABLE +#ifdef RGB_MATRIX_ENABLE + rgb_matrix_set_color_all(0xFF, 0x00, 0x00); + rgb_matrix_update_pwm_buffers(); +#endif // RGB_MATRIX_ENABLE +#ifdef OLED_ENABLE + oled_off(); +#endif + + shutdown_keymap(); +} + +__attribute__((weak)) void suspend_power_down_keymap(void) {} + +void suspend_power_down_user(void) { +#ifdef OLED_ENABLE + oled_off(); +#endif + suspend_power_down_keymap(); +} + +__attribute__((weak)) void suspend_wakeup_init_keymap(void) {} +void suspend_wakeup_init_user(void) { + if (layer_state_is(_GAMEPAD)) { + layer_off(_GAMEPAD); + } + if (layer_state_is(_DIABLO)) { + layer_off(_DIABLO); + } + suspend_wakeup_init_keymap(); +} + +// No global matrix scan code, so just run keymap's matrix +// scan function +__attribute__((weak)) void matrix_scan_keymap(void) {} +__attribute__((weak)) void matrix_scan_secret(void) {} +void matrix_scan_user(void) { + static bool has_ran_yet; + if (!has_ran_yet) { + has_ran_yet = true; + startup_user(); + } + +#ifdef TAP_DANCE_ENABLE // Run Diablo 3 macro checking code. + run_diablo_macro_check(); +#endif // TAP_DANCE_ENABLE + +#if defined(RGBLIGHT_ENABLE) + matrix_scan_rgb_light(); +#endif // RGBLIGHT_ENABLE +#if defined(RGB_MATRIX_ENABLE) + matrix_scan_rgb_matrix(); +#endif +#if defined(POINTING_DEVICE_ENABLE) + matrix_scan_pointing(); +#endif + + matrix_scan_secret(); + + matrix_scan_keymap(); +} + +#ifdef AUDIO_ENABLE +float doom_song[][2] = SONG(E1M1_DOOM); +#endif + +// on layer change, no matter where the change was initiated +// Then runs keymap's layer change check +__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) { + if (!is_keyboard_master()) { + return state; + } + + state = update_tri_layer_state(state, _RAISE, _LOWER, _ADJUST); +#if defined(POINTING_DEVICE_ENABLE) + state = layer_state_set_pointing(state); +#endif +#if defined(RGBLIGHT_ENABLE) + state = layer_state_set_rgb_light(state); +#endif // RGBLIGHT_ENABLE +#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 + state = layer_state_set_keymap(state); + return state; +} + +// Runs state check and changes underglow color and animation +__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) { + if (!is_keyboard_master()) { + return state; + } + + state = default_layer_state_set_keymap(state); +#if 0 +# if defined(RGBLIGHT_ENABLE) || defined(RGB_MATRIX_ENABLE) + state = default_layer_state_set_rgb(state); +# endif // RGBLIGHT_ENABLE +#endif + return state; +} + +__attribute__((weak)) void led_set_keymap(uint8_t usb_led) {} +void led_set_user(uint8_t usb_led) { led_set_keymap(usb_led); } + +__attribute__((weak)) void eeconfig_init_keymap(void) {} +void eeconfig_init_user(void) { + userspace_config.raw = 0; + userspace_config.rgb_layer_change = true; + eeconfig_update_user(userspace_config.raw); + eeconfig_init_keymap(); +} + +#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 +# ifdef AUDIO_INIT_DELAY + if (!is_keyboard_master()) { + static bool delayed_tasks_run = false; + 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; + } + } + } +# endif +# 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 diff --git a/users/drashna/callbacks.h b/users/drashna/callbacks.h new file mode 100644 index 0000000000..f6ac6b88de --- /dev/null +++ b/users/drashna/callbacks.h @@ -0,0 +1,25 @@ +// Copyright 2021 Christopher Courtney, aka Drashna Jael're (@drashna) <drashna@live.com> +// SPDX-License-Identifier: GPL-2.0-or-later + +#pragma once + +#include "quantum.h" + +void matrix_init_keymap(void); +void matrix_init_secret(void); +void shutdown_keymap(void); +void suspend_power_down_keymap(void); +void suspend_wakeup_init_keymap(void); +void matrix_scan_keymap(void); +void matrix_scan_secret(void); +layer_state_t layer_state_set_keymap(layer_state_t state); +layer_state_t default_layer_state_set_keymap(layer_state_t state); +void led_set_keymap(uint8_t usb_led); +void eeconfig_init_keymap(void); + +#ifdef CUSTOM_UNICODE_ENABLE +void matrix_init_unicode(void); +#endif +#ifdef SPLIT_KEYBOARD +void matrix_slave_scan_keymap(void); +#endif diff --git a/users/drashna/callbacks.md b/users/drashna/callbacks.md new file mode 100644 index 0000000000..a0f0d9fdae --- /dev/null +++ b/users/drashna/callbacks.md @@ -0,0 +1,71 @@ +# Custom Userspace Callback Functions + +Specifically QMK works by using customized callback functions for everything. This allows for multiple levels of customization. + +`matrix_scan` calls `matrix_scan_quantum`, which calls `matrix_scan_kb`, which calls `matrix_scan_user`. +`process_record` calls a bunch of stuff, but eventually calls `process_record_kb` which calls `process_record_user` +The same goes for `matrix_init`, `layer_state_set`, `led_set`, and a few other functions. + +All (most) `_user` functions are handled here, in the userspace instead. To allow keyboard specific configuration, I've created `_keymap` functions that can be called by the keymap.c files instead. + +This allows for keyboard specific configuration while maintaining the ability to customize the board. + +My [Ergodox EZ Keymap](https://github.com/qmk/qmk_firmware/blob/master/layouts/community/ergodox/drashna/keymap.c) is a good example of this, as it uses the LEDs as modifier indicators. + +You can see a list of these files in [callbacks.c](callbacks.c), or a shortend list here + +```c +__attribute__((weak)) void matrix_init_keymap(void) {} +void matrix_init_user(void) { + matrix_init_keymap(); +} + +__attribute__((weak)) void keyboard_post_init_keymap(void) {} +void keyboard_post_init_user(void) { + keyboard_post_init_keymap(); +} + +__attribute__((weak)) void matrix_scan_keymap(void) {} +void matrix_scan_user(void) { + matrix_scan_keymap(); +} + +__attribute__ ((weak)) bool process_record_keymap(uint16_t keycode, keyrecord_t *record) { return true; } +bool process_record_user(uint16_t keycode, keyrecord_t *record) { + if (!process_record_keymap(keycode, record)) { return false; } + return true; +} + +__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) { + state = layer_state_set_keymap(state); + return state; +} + +__attribute__ ((weak)) void led_set_keymap(uint8_t usb_led) {} +void led_set_user(uint8_t usb_led) { + led_set_keymap(usb_led); +} + +__attribute__ ((weak)) void suspend_power_down_keymap(void) {} +void suspend_power_down_user(void) { + suspend_power_down_keymap(); +} + +__attribute__ ((weak)) void suspend_wakeup_init_keymap(void) {} +void suspend_wakeup_init_user(void) { + suspend_wakeup_init_keymap(); +} + + +__attribute__ ((weak)) void shutdown_keymap(void) {} +void shutdown_user (void) { + shutdown_keymap(); +} + +__attribute__ ((weak)) void eeconfig_init_keymap(void) {} +void eeconfig_init_user(void) { + eeconfig_update_user(0); + eeconfig_init_keymap(); +} +``` diff --git a/users/drashna/config.h b/users/drashna/config.h index cc8f9ac83c..46cd276dd4 100644 --- a/users/drashna/config.h +++ b/users/drashna/config.h @@ -1,24 +1,16 @@ -/* 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/>. - */ +// Copyright 2020 Christopher Courtney, aka Drashna Jael're (@drashna) <drashna@live.com> +// SPDX-License-Identifier: GPL-2.0-or-later #pragma once // Use custom magic number so that when switching branches, EEPROM always gets reset #define EECONFIG_MAGIC_NUMBER (uint16_t)0x1339 +#ifdef IS_COMMAND +#undef IS_COMMAND +#endif +#define IS_COMMAND() (((get_mods() | get_oneshot_mods()) & MOD_MASK_SHIFT) == MOD_MASK_SHIFT) + /* Set Polling rate to 1000Hz */ #define USB_POLLING_INTERVAL_MS 1 @@ -37,7 +29,7 @@ # define SELECT_SOFT_SERIAL_SPEED 1 # endif # ifdef CUSTOM_SPLIT_TRANSPORT_SYNC -# define SPLIT_TRANSACTION_IDS_USER RPC_ID_USER_STATE_SYNC, RPC_ID_USER_KEYMAP_SYNC, RPC_ID_USER_CONFIG_SYNC +# define SPLIT_TRANSACTION_IDS_USER RPC_ID_USER_STATE_SYNC, RPC_ID_USER_KEYMAP_SYNC, RPC_ID_USER_CONFIG_SYNC, RPC_ID_USER_WATCHDOG_SYNC # endif #endif @@ -251,17 +243,6 @@ # define TAPPING_TOGGLE 1 #endif -#ifdef TAPPING_TERM -# undef TAPPING_TERM -#endif // TAPPING_TERM -#if defined(KEYBOARD_ergodox_ez) -# define TAPPING_TERM 185 -#elif defined(KEYBOARD_crkbd) -# define TAPPING_TERM 200 -#else -# define TAPPING_TERM 175 -#endif - #define TAP_CODE_DELAY 5 /* Disable unused and unneeded features to reduce on firmware size */ diff --git a/users/drashna/drashna.c b/users/drashna/drashna.c index 9c1233ed90..9128a89bc6 100644 --- a/users/drashna/drashna.c +++ b/users/drashna/drashna.c @@ -1,18 +1,5 @@ -/* 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/>. - */ +// Copyright 2020 Christopher Courtney, aka Drashna Jael're (@drashna) <drashna@live.com> +// SPDX-License-Identifier: GPL-2.0-or-later #include "drashna.h" @@ -49,182 +36,6 @@ bool mod_key_press(uint16_t code, uint16_t mod_code, bool pressed, uint16_t this return false; } -__attribute__((weak)) void keyboard_pre_init_keymap(void) {} -void keyboard_pre_init_user(void) { - userspace_config.raw = eeconfig_read_user(); - keyboard_pre_init_keymap(); -} -// 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 -__attribute__((weak)) void matrix_init_keymap(void) {} -__attribute__((weak)) void matrix_init_secret(void) {} -void matrix_init_user(void) { -#if defined(BOOTLOADER_CATERINA) && defined(__AVR__) - DDRD &= ~(1 << 5); - PORTD &= ~(1 << 5); - - DDRB &= ~(1 << 0); - PORTB &= ~(1 << 0); -#endif -#ifdef CUSTOM_UNICODE_ENABLE - matrix_init_unicode(); -#endif - matrix_init_secret(); - matrix_init_keymap(); -} - -__attribute__((weak)) void keyboard_post_init_keymap(void) {} -void keyboard_post_init_user(void) { -#if defined(RGBLIGHT_ENABLE) - keyboard_post_init_rgb_light(); -#endif -#if defined(RGB_MATRIX_ENABLE) - keyboard_post_init_rgb_matrix(); -#endif -#if defined(SPLIT_KEYBOARD) && defined(SPLIT_TRANSACTION_IDS_USER) - keyboard_post_init_transport_sync(); -#endif - keyboard_post_init_keymap(); -} - -#ifdef RGB_MATRIX_ENABLE -void rgb_matrix_update_pwm_buffers(void); -#endif - -__attribute__((weak)) void shutdown_keymap(void) {} -void shutdown_user(void) { -#ifdef RGBLIGHT_ENABLE - rgblight_enable_noeeprom(); - rgblight_mode_noeeprom(1); - rgblight_setrgb_red(); -#endif // RGBLIGHT_ENABLE -#ifdef RGB_MATRIX_ENABLE - rgb_matrix_set_color_all(0xFF, 0x00, 0x00); - rgb_matrix_update_pwm_buffers(); -#endif // RGB_MATRIX_ENABLE -#ifdef OLED_ENABLE - oled_off(); -#endif - - shutdown_keymap(); -} - -__attribute__((weak)) void suspend_power_down_keymap(void) {} - -void suspend_power_down_user(void) { -#ifdef OLED_ENABLE - oled_off(); -#endif - suspend_power_down_keymap(); -} - -__attribute__((weak)) void suspend_wakeup_init_keymap(void) {} -void suspend_wakeup_init_user(void) { - if (layer_state_is(_GAMEPAD)) { - layer_off(_GAMEPAD); - } - if (layer_state_is(_DIABLO)) { - layer_off(_DIABLO); - } - suspend_wakeup_init_keymap(); -} - -// No global matrix scan code, so just run keymap's matrix -// scan function -__attribute__((weak)) void matrix_scan_keymap(void) {} -__attribute__((weak)) void matrix_scan_secret(void) {} -void matrix_scan_user(void) { - static bool has_ran_yet; - if (!has_ran_yet) { - has_ran_yet = true; - startup_user(); - } - -#ifdef TAP_DANCE_ENABLE // Run Diablo 3 macro checking code. - run_diablo_macro_check(); -#endif // TAP_DANCE_ENABLE - -#if defined(RGBLIGHT_ENABLE) - matrix_scan_rgb_light(); -#endif // RGBLIGHT_ENABLE -#if defined(RGB_MATRIX_ENABLE) - matrix_scan_rgb_matrix(); -#endif -#if defined(POINTING_DEVICE_ENABLE) - matrix_scan_pointing(); -#endif - - matrix_scan_secret(); - - matrix_scan_keymap(); -} - -#ifdef AUDIO_ENABLE -float doom_song[][2] = SONG(E1M1_DOOM); -#endif - -// on layer change, no matter where the change was initiated -// Then runs keymap's layer change check -__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) { - if (!is_keyboard_master()) { - return state; - } - - state = update_tri_layer_state(state, _RAISE, _LOWER, _ADJUST); -#if defined(POINTING_DEVICE_ENABLE) - state = layer_state_set_pointing(state); -#endif -#if defined(RGBLIGHT_ENABLE) - state = layer_state_set_rgb_light(state); -#endif // RGBLIGHT_ENABLE -#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 - state = layer_state_set_keymap(state); - return state; -} - -// Runs state check and changes underglow color and animation -__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) { - if (!is_keyboard_master()) { - return state; - } - - state = default_layer_state_set_keymap(state); -#if 0 -# if defined(RGBLIGHT_ENABLE) || defined(RGB_MATRIX_ENABLE) - state = default_layer_state_set_rgb(state); -# endif // RGBLIGHT_ENABLE -#endif - return state; -} - -__attribute__((weak)) void led_set_keymap(uint8_t usb_led) {} -void led_set_user(uint8_t usb_led) { led_set_keymap(usb_led); } - -__attribute__((weak)) void eeconfig_init_keymap(void) {} -void eeconfig_init_user(void) { - userspace_config.raw = 0; - userspace_config.rgb_layer_change = true; - eeconfig_update_user(userspace_config.raw); - eeconfig_init_keymap(); - keyboard_init(); -} - bool hasAllBitsInMask(uint8_t value, uint8_t mask) { value &= 0xF; mask &= 0xF; @@ -232,96 +43,10 @@ bool hasAllBitsInMask(uint8_t value, uint8_t mask) { return (value & mask) == mask; } -#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 -# ifdef AUDIO_INIT_DELAY - if (!is_keyboard_master()) { - static bool delayed_tasks_run = false; - 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; - } - } - } -# endif -# 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 - -__attribute__((weak)) uint16_t get_tapping_term(uint16_t keycode, keyrecord_t *record) { - switch (keycode) { - default: - return TAPPING_TERM; - } -} - -__attribute__((weak)) bool get_permissive_hold(uint16_t keycode, keyrecord_t *record) { - // Immediately select the hold action when another key is tapped: - // return true; - // Do not select the hold action when another key is tapped. - // return false; - switch (keycode) { - default: - return false; - } -} - -__attribute__((weak)) bool get_hold_on_other_key_press(uint16_t keycode, keyrecord_t *record) { - // Immediately select the hold action when another key is pressed. - // return true; - // Do not select the hold action when another key is pressed. - // return false; - switch (keycode) { - case QK_LAYER_TAP ... QK_LAYER_TAP_MAX: - return true; - default: |