aboutsummaryrefslogtreecommitdiff
path: root/users/drashna/drashna.c
diff options
context:
space:
mode:
Diffstat (limited to 'users/drashna/drashna.c')
-rw-r--r--users/drashna/drashna.c96
1 files changed, 84 insertions, 12 deletions
diff --git a/users/drashna/drashna.c b/users/drashna/drashna.c
index 9128a89bc..6e8d4ac9b 100644
--- a/users/drashna/drashna.c
+++ b/users/drashna/drashna.c
@@ -2,25 +2,37 @@
2// SPDX-License-Identifier: GPL-2.0-or-later 2// SPDX-License-Identifier: GPL-2.0-or-later
3 3
4#include "drashna.h" 4#include "drashna.h"
5#ifdef __AVR__
6# include <avr/wdt.h>
7#endif
5 8
6userspace_config_t userspace_config; 9userspace_config_t userspace_config;
7 10
11/**
12 * @brief Handle registering a keycode, with optional modifer based on timed event
13 *
14 * @param code keycode to send to host
15 * @param mod_code modifier to send with code, if held for tapping term or longer
16 * @param pressed the press/release event (can use "record->event.pressed" for this)
17 * @return true exits function
18 * @return false exits function
19 */
8bool mod_key_press_timer(uint16_t code, uint16_t mod_code, bool pressed) { 20bool mod_key_press_timer(uint16_t code, uint16_t mod_code, bool pressed) {
9 static uint16_t this_timer; 21 static uint16_t this_timer;
10 if (pressed) { 22 mod_key_press(code, mod_code, pressed, this_timer);
11 this_timer = timer_read();
12 } else {
13 if (timer_elapsed(this_timer) < TAPPING_TERM) {
14 tap_code(code);
15 } else {
16 register_code(mod_code);
17 tap_code(code);
18 unregister_code(mod_code);
19 }
20 }
21 return false; 23 return false;
22} 24}
23 25
26/**
27 * @brief Handle registation of keycode, with optional modifier based on custom timer
28 *
29 * @param code keycode to send to host
30 * @param mod_code modifier keycode to send with code, if held for tapping term or longer
31 * @param pressed the press/release event
32 * @param this_timer custom timer to use
33 * @return true
34 * @return false
35 */
24bool mod_key_press(uint16_t code, uint16_t mod_code, bool pressed, uint16_t this_timer) { 36bool mod_key_press(uint16_t code, uint16_t mod_code, bool pressed, uint16_t this_timer) {
25 if (pressed) { 37 if (pressed) {
26 this_timer = timer_read(); 38 this_timer = timer_read();
@@ -36,6 +48,14 @@ bool mod_key_press(uint16_t code, uint16_t mod_code, bool pressed, uint16_t this
36 return false; 48 return false;
37} 49}
38 50
51/**
52 * @brief Performs exact match for modifier values
53 *
54 * @param value the modifer varible (get_mods/get_oneshot_mods/get_weak_mods)
55 * @param mask the modifier mask to check for
56 * @return true Has the exact modifiers specifed
57 * @return false Does not have the exact modifiers specified
58 */
39bool hasAllBitsInMask(uint8_t value, uint8_t mask) { 59bool hasAllBitsInMask(uint8_t value, uint8_t mask) {
40 value &= 0xF; 60 value &= 0xF;
41 mask &= 0xF; 61 mask &= 0xF;
@@ -43,10 +63,62 @@ bool hasAllBitsInMask(uint8_t value, uint8_t mask) {
43 return (value & mask) == mask; 63 return (value & mask) == mask;
44} 64}
45 65
46void tap_code16_nomods(uint8_t kc) { 66/**
67 * @brief Tap keycode, with no mods
68 *
69 * @param kc keycode to use
70 */
71void tap_code16_nomods(uint16_t kc) {
47 uint8_t temp_mod = get_mods(); 72 uint8_t temp_mod = get_mods();
48 clear_mods(); 73 clear_mods();
49 clear_oneshot_mods(); 74 clear_oneshot_mods();
50 tap_code16(kc); 75 tap_code16(kc);
51 set_mods(temp_mod); 76 set_mods(temp_mod);
52} 77}
78
79/**
80 * @brief Run shutdown routine and soft reboot firmware.
81 *
82 */
83
84#ifdef HAPTIC_ENABLE
85# include "haptic.h"
86#endif
87
88#ifdef AUDIO_ENABLE
89# ifndef GOODBYE_SONG
90# define GOODBYE_SONG SONG(GOODBYE_SOUND)
91# endif
92float reset_song[][2] = GOODBYE_SONG;
93#endif
94
95void software_reset(void) {
96 clear_keyboard();
97#if defined(MIDI_ENABLE) && defined(MIDI_BASIC)
98 process_midi_all_notes_off();
99#endif
100#ifdef AUDIO_ENABLE
101# ifndef NO_MUSIC_MODE
102 music_all_notes_off();
103# endif
104 uint16_t timer_start = timer_read();
105 PLAY_SONG(reset_song);
106 shutdown_user();
107 while (timer_elapsed(timer_start) < 250) wait_ms(1);
108 stop_all_notes();
109#else
110 shutdown_user();
111 wait_ms(250);
112#endif
113#ifdef HAPTIC_ENABLE
114 haptic_shutdown();
115#endif
116
117#if defined(PROTOCOL_LUFA)
118 wdt_enable(WDTO_250MS);
119#elif defined(PROTOCOL_CHIBIOS)
120# if defined(MCU_STM32) || defined(MCU_KINETIS)
121 NVIC_SystemReset();
122# endif
123#endif
124}