aboutsummaryrefslogtreecommitdiff
path: root/quantum
diff options
context:
space:
mode:
Diffstat (limited to 'quantum')
-rw-r--r--quantum/keymap_extras/keymap_br_abnt2.h16
-rw-r--r--quantum/process_keycode/process_music.c1
-rw-r--r--quantum/process_keycode/process_tap_dance.c7
-rw-r--r--quantum/process_keycode/process_tap_dance.h1
-rw-r--r--quantum/process_keycode/process_unicode.c41
-rw-r--r--quantum/quantum.c32
-rw-r--r--quantum/quantum_keycodes.h4
-rw-r--r--quantum/visualizer/visualizer.c58
-rw-r--r--quantum/visualizer/visualizer.h9
9 files changed, 156 insertions, 13 deletions
diff --git a/quantum/keymap_extras/keymap_br_abnt2.h b/quantum/keymap_extras/keymap_br_abnt2.h
index 0df177721..b001139dd 100644
--- a/quantum/keymap_extras/keymap_br_abnt2.h
+++ b/quantum/keymap_extras/keymap_br_abnt2.h
@@ -1,3 +1,19 @@
1/* Copyright 2017 Potiguar Faga
2 *
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.
7 *
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.
12 *
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/>.
15 */
16
1#ifndef KEYMAP_BR_ABNT2_H 17#ifndef KEYMAP_BR_ABNT2_H
2#define KEYMAP_BR_ABNT2_H 18#define KEYMAP_BR_ABNT2_H
3 19
diff --git a/quantum/process_keycode/process_music.c b/quantum/process_keycode/process_music.c
index ca68bef6c..1e2648bff 100644
--- a/quantum/process_keycode/process_music.c
+++ b/quantum/process_keycode/process_music.c
@@ -114,6 +114,7 @@ bool process_music(uint16_t keycode, keyrecord_t *record) {
114 music_sequence_interval+=10; 114 music_sequence_interval+=10;
115 return false; 115 return false;
116 } 116 }
117 #define MUSIC_MODE_GUITAR
117 118
118 #ifdef MUSIC_MODE_CHROMATIC 119 #ifdef MUSIC_MODE_CHROMATIC
119 float freq = ((float)220.0)*pow(2.0, -5.0)*pow(2.0,(music_starting_note + record->event.key.col + music_offset)/12.0+(MATRIX_ROWS - record->event.key.row)); 120 float freq = ((float)220.0)*pow(2.0, -5.0)*pow(2.0,(music_starting_note + record->event.key.col + music_offset)/12.0+(MATRIX_ROWS - record->event.key.row));
diff --git a/quantum/process_keycode/process_tap_dance.c b/quantum/process_keycode/process_tap_dance.c
index 6ae362c4c..403dca538 100644
--- a/quantum/process_keycode/process_tap_dance.c
+++ b/quantum/process_keycode/process_tap_dance.c
@@ -43,12 +43,16 @@ static inline void process_tap_dance_action_on_dance_finished (qk_tap_dance_acti
43 if (action->state.finished) 43 if (action->state.finished)
44 return; 44 return;
45 action->state.finished = true; 45 action->state.finished = true;
46 add_mods(action->state.oneshot_mods);
47 send_keyboard_report();
46 _process_tap_dance_action_fn (&action->state, action->user_data, action->fn.on_dance_finished); 48 _process_tap_dance_action_fn (&action->state, action->user_data, action->fn.on_dance_finished);
47} 49}
48 50
49static inline void process_tap_dance_action_on_reset (qk_tap_dance_action_t *action) 51static inline void process_tap_dance_action_on_reset (qk_tap_dance_action_t *action)
50{ 52{
51 _process_tap_dance_action_fn (&action->state, action->user_data, action->fn.on_reset); 53 _process_tap_dance_action_fn (&action->state, action->user_data, action->fn.on_reset);
54 del_mods(action->state.oneshot_mods);
55 send_keyboard_report();
52} 56}
53 57
54bool process_tap_dance(uint16_t keycode, keyrecord_t *record) { 58bool process_tap_dance(uint16_t keycode, keyrecord_t *record) {
@@ -70,6 +74,7 @@ bool process_tap_dance(uint16_t keycode, keyrecord_t *record) {
70 action->state.keycode = keycode; 74 action->state.keycode = keycode;
71 action->state.count++; 75 action->state.count++;
72 action->state.timer = timer_read(); 76 action->state.timer = timer_read();
77 action->state.oneshot_mods = get_oneshot_mods();
73 process_tap_dance_action_on_each_tap (action); 78 process_tap_dance_action_on_each_tap (action);
74 79
75 if (last_td && last_td != keycode) { 80 if (last_td && last_td != keycode) {
@@ -109,7 +114,7 @@ void matrix_scan_tap_dance () {
109 if (highest_td == -1) 114 if (highest_td == -1)
110 return; 115 return;
111 116
112 for (int i = 0; i <= highest_td; i++) { 117for (int i = 0; i <= highest_td; i++) {
113 qk_tap_dance_action_t *action = &tap_dance_actions[i]; 118 qk_tap_dance_action_t *action = &tap_dance_actions[i];
114 119
115 if (action->state.count && timer_elapsed (action->state.timer) > TAPPING_TERM) { 120 if (action->state.count && timer_elapsed (action->state.timer) > TAPPING_TERM) {
diff --git a/quantum/process_keycode/process_tap_dance.h b/quantum/process_keycode/process_tap_dance.h
index f753cbba6..726752ecc 100644
--- a/quantum/process_keycode/process_tap_dance.h
+++ b/quantum/process_keycode/process_tap_dance.h
@@ -9,6 +9,7 @@
9typedef struct 9typedef struct
10{ 10{
11 uint8_t count; 11 uint8_t count;
12 uint8_t oneshot_mods;
12 uint16_t keycode; 13 uint16_t keycode;
13 uint16_t timer; 14 uint16_t timer;
14 bool interrupted; 15 bool interrupted;
diff --git a/quantum/process_keycode/process_unicode.c b/quantum/process_keycode/process_unicode.c
index 2606cf0c8..9995ba9bd 100644
--- a/quantum/process_keycode/process_unicode.c
+++ b/quantum/process_keycode/process_unicode.c
@@ -1,6 +1,8 @@
1#include "process_unicode.h" 1#include "process_unicode.h"
2#include "action_util.h"
2 3
3static uint8_t input_mode; 4static uint8_t input_mode;
5uint8_t mods;
4 6
5__attribute__((weak)) 7__attribute__((weak))
6uint16_t hex_to_keycode(uint8_t hex) 8uint16_t hex_to_keycode(uint8_t hex)
@@ -25,6 +27,19 @@ uint8_t get_unicode_input_mode(void) {
25 27
26__attribute__((weak)) 28__attribute__((weak))
27void unicode_input_start (void) { 29void unicode_input_start (void) {
30 // save current mods
31 mods = keyboard_report->mods;
32
33 // unregister all mods to start from clean state
34 if (mods & MOD_BIT(KC_LSFT)) unregister_code(KC_LSFT);
35 if (mods & MOD_BIT(KC_RSFT)) unregister_code(KC_RSFT);
36 if (mods & MOD_BIT(KC_LCTL)) unregister_code(KC_LCTL);
37 if (mods & MOD_BIT(KC_RCTL)) unregister_code(KC_RCTL);
38 if (mods & MOD_BIT(KC_LALT)) unregister_code(KC_LALT);
39 if (mods & MOD_BIT(KC_RALT)) unregister_code(KC_RALT);
40 if (mods & MOD_BIT(KC_LGUI)) unregister_code(KC_LGUI);
41 if (mods & MOD_BIT(KC_RGUI)) unregister_code(KC_RGUI);
42
28 switch(input_mode) { 43 switch(input_mode) {
29 case UC_OSX: 44 case UC_OSX:
30 register_code(KC_LALT); 45 register_code(KC_LALT);
@@ -54,15 +69,25 @@ void unicode_input_start (void) {
54__attribute__((weak)) 69__attribute__((weak))
55void unicode_input_finish (void) { 70void unicode_input_finish (void) {
56 switch(input_mode) { 71 switch(input_mode) {
57 case UC_OSX: 72 case UC_OSX:
58 case UC_WIN: 73 case UC_WIN:
59 unregister_code(KC_LALT); 74 unregister_code(KC_LALT);
60 break; 75 break;
61 case UC_LNX: 76 case UC_LNX:
62 register_code(KC_SPC); 77 register_code(KC_SPC);
63 unregister_code(KC_SPC); 78 unregister_code(KC_SPC);
64 break; 79 break;
65 } 80 }
81
82 // reregister previously set mods
83 if (mods & MOD_BIT(KC_LSFT)) register_code(KC_LSFT);
84 if (mods & MOD_BIT(KC_RSFT)) register_code(KC_RSFT);
85 if (mods & MOD_BIT(KC_LCTL)) register_code(KC_LCTL);
86 if (mods & MOD_BIT(KC_RCTL)) register_code(KC_RCTL);
87 if (mods & MOD_BIT(KC_LALT)) register_code(KC_LALT);
88 if (mods & MOD_BIT(KC_RALT)) register_code(KC_RALT);
89 if (mods & MOD_BIT(KC_LGUI)) register_code(KC_LGUI);
90 if (mods & MOD_BIT(KC_RGUI)) register_code(KC_RGUI);
66} 91}
67 92
68void register_hex(uint16_t hex) { 93void register_hex(uint16_t hex) {
diff --git a/quantum/quantum.c b/quantum/quantum.c
index 63ffe2074..0aecd238e 100644
--- a/quantum/quantum.c
+++ b/quantum/quantum.c
@@ -33,14 +33,42 @@ static void do_code16 (uint16_t code, void (*f) (uint8_t)) {
33 f(KC_RGUI); 33 f(KC_RGUI);
34} 34}
35 35
36static inline void qk_register_weak_mods(uint8_t kc) {
37 add_weak_mods(MOD_BIT(kc));
38 send_keyboard_report();
39}
40
41static inline void qk_unregister_weak_mods(uint8_t kc) {
42 del_weak_mods(MOD_BIT(kc));
43 send_keyboard_report();
44}
45
46static inline void qk_register_mods(uint8_t kc) {
47 add_weak_mods(MOD_BIT(kc));
48 send_keyboard_report();
49}
50
51static inline void qk_unregister_mods(uint8_t kc) {
52 del_weak_mods(MOD_BIT(kc));
53 send_keyboard_report();
54}
55
36void register_code16 (uint16_t code) { 56void register_code16 (uint16_t code) {
37 do_code16 (code, register_code); 57 if (IS_MOD(code) || code == KC_NO) {
58 do_code16 (code, qk_register_mods);
59 } else {
60 do_code16 (code, qk_register_weak_mods);
61 }
38 register_code (code); 62 register_code (code);
39} 63}
40 64
41void unregister_code16 (uint16_t code) { 65void unregister_code16 (uint16_t code) {
42 unregister_code (code); 66 unregister_code (code);
43 do_code16 (code, unregister_code); 67 if (IS_MOD(code) || code == KC_NO) {
68 do_code16 (code, qk_unregister_mods);
69 } else {
70 do_code16 (code, qk_unregister_weak_mods);
71 }
44} 72}
45 73
46__attribute__ ((weak)) 74__attribute__ ((weak))
diff --git a/quantum/quantum_keycodes.h b/quantum/quantum_keycodes.h
index 5cd3c8e78..4853655f9 100644
--- a/quantum/quantum_keycodes.h
+++ b/quantum/quantum_keycodes.h
@@ -159,6 +159,8 @@ enum quantum_keycodes {
159#define MEH(kc) (kc | QK_LCTL | QK_LSFT | QK_LALT) 159#define MEH(kc) (kc | QK_LCTL | QK_LSFT | QK_LALT)
160#define LCAG(kc) (kc | QK_LCTL | QK_LALT | QK_LGUI) 160#define LCAG(kc) (kc | QK_LCTL | QK_LALT | QK_LGUI)
161#define ALTG(kc) (kc | QK_RCTL | QK_RALT) 161#define ALTG(kc) (kc | QK_RCTL | QK_RALT)
162#define SCMD(kc) (kc | QK_LGUI | QK_LSFT)
163#define SWIN(kc) SCMD(kc)
162 164
163#define MOD_HYPR 0xf 165#define MOD_HYPR 0xf
164#define MOD_MEH 0x7 166#define MOD_MEH 0x7
@@ -293,6 +295,8 @@ enum quantum_keycodes {
293#define MEH_T(kc) MT((MOD_LCTL | MOD_LSFT | MOD_LALT), kc) // Meh is a less hyper version of the Hyper key -- doesn't include Win or Cmd, so just alt+shift+ctrl 295#define MEH_T(kc) MT((MOD_LCTL | MOD_LSFT | MOD_LALT), kc) // Meh is a less hyper version of the Hyper key -- doesn't include Win or Cmd, so just alt+shift+ctrl
294#define LCAG_T(kc) MT((MOD_LCTL | MOD_LALT | MOD_LGUI), kc) // Left control alt and gui 296#define LCAG_T(kc) MT((MOD_LCTL | MOD_LALT | MOD_LGUI), kc) // Left control alt and gui
295#define ALL_T(kc) MT((MOD_LCTL | MOD_LSFT | MOD_LALT | MOD_LGUI), kc) // see http://brettterpstra.com/2012/12/08/a-useful-caps-lock-key/ 297#define ALL_T(kc) MT((MOD_LCTL | MOD_LSFT | MOD_LALT | MOD_LGUI), kc) // see http://brettterpstra.com/2012/12/08/a-useful-caps-lock-key/
298#define SCMD_T(kc) MT((MOD_LGUI | MOD_LSFT), kc)
299#define SWIN_T(kc) SCMD_T(kc)
296 300
297// Dedicated keycode versions for Hyper and Meh, if you want to use them as standalone keys rather than mod-tap 301// Dedicated keycode versions for Hyper and Meh, if you want to use them as standalone keys rather than mod-tap
298#define KC_HYPR HYPR(KC_NO) 302#define KC_HYPR HYPR(KC_NO)
diff --git a/quantum/visualizer/visualizer.c b/quantum/visualizer/visualizer.c
index 54f6faaa4..5826d909e 100644
--- a/quantum/visualizer/visualizer.c
+++ b/quantum/visualizer/visualizer.c
@@ -53,10 +53,13 @@ SOFTWARE.
53#define "Visualizer thread priority not defined" 53#define "Visualizer thread priority not defined"
54#endif 54#endif
55 55
56// mods status
57#include "action_util.h"
56 58
57static visualizer_keyboard_status_t current_status = { 59static visualizer_keyboard_status_t current_status = {
58 .layer = 0xFFFFFFFF, 60 .layer = 0xFFFFFFFF,
59 .default_layer = 0xFFFFFFFF, 61 .default_layer = 0xFFFFFFFF,
62 .mods = 0xFF,
60 .leds = 0xFFFFFFFF, 63 .leds = 0xFFFFFFFF,
61 .suspended = false, 64 .suspended = false,
62}; 65};
@@ -64,6 +67,7 @@ static visualizer_keyboard_status_t current_status = {
64static bool same_status(visualizer_keyboard_status_t* status1, visualizer_keyboard_status_t* status2) { 67static bool same_status(visualizer_keyboard_status_t* status1, visualizer_keyboard_status_t* status2) {
65 return status1->layer == status2->layer && 68 return status1->layer == status2->layer &&
66 status1->default_layer == status2->default_layer && 69 status1->default_layer == status2->default_layer &&
70 status1->mods == status2->mods &&
67 status1->leds == status2->leds && 71 status1->leds == status2->leds &&
68 status1->suspended == status2->suspended; 72 status1->suspended == status2->suspended;
69} 73}
@@ -307,6 +311,45 @@ bool keyframe_display_layer_bitmap(keyframe_animation_t* animation, visualizer_s
307 gdispFlush(); 311 gdispFlush();
308 return false; 312 return false;
309} 313}
314
315static void format_mods_bitmap_string(uint8_t mods, char* buffer) {
316 *buffer = ' ';
317 ++buffer;
318
319 for (int i = 0; i<8; i++)
320 {
321 uint32_t mask = (1u << i);
322 if (mods & mask) {
323 *buffer = '1';
324 } else {
325 *buffer = '0';
326 }
327 ++buffer;
328
329 if (i==3) {
330 *buffer = ' ';
331 ++buffer;
332 }
333 }
334 *buffer = 0;
335}
336
337bool keyframe_display_mods_bitmap(keyframe_animation_t* animation, visualizer_state_t* state) {
338 (void)animation;
339
340 const char* title = "Modifier states";
341 const char* mods_header = " CSAG CSAG ";
342 char status_buffer[12];
343
344 gdispClear(White);
345 gdispDrawString(0, 0, title, state->font_fixed5x8, Black);
346 gdispDrawString(0, 10, mods_header, state->font_fixed5x8, Black);
347 format_mods_bitmap_string(state->status.mods, status_buffer);
348 gdispDrawString(0, 20, status_buffer, state->font_fixed5x8, Black);
349
350 gdispFlush();
351 return false;
352}
310#endif // LCD_ENABLE 353#endif // LCD_ENABLE
311 354
312bool keyframe_disable_lcd_and_backlight(keyframe_animation_t* animation, visualizer_state_t* state) { 355bool keyframe_disable_lcd_and_backlight(keyframe_animation_t* animation, visualizer_state_t* state) {
@@ -350,6 +393,7 @@ static DECLARE_THREAD_FUNCTION(visualizerThread, arg) {
350 visualizer_keyboard_status_t initial_status = { 393 visualizer_keyboard_status_t initial_status = {
351 .default_layer = 0xFFFFFFFF, 394 .default_layer = 0xFFFFFFFF,
352 .layer = 0xFFFFFFFF, 395 .layer = 0xFFFFFFFF,
396 .mods = 0xFF,
353 .leds = 0xFFFFFFFF, 397 .leds = 0xFFFFFFFF,
354 .suspended = false, 398 .suspended = false,
355 }; 399 };
@@ -499,7 +543,18 @@ void update_status(bool changed) {
499#endif 543#endif
500} 544}
501 545
502void visualizer_update(uint32_t default_state, uint32_t state, uint32_t leds) { 546uint8_t visualizer_get_mods() {
547 uint8_t mods = get_mods();
548
549#ifndef NO_ACTION_ONESHOT
550 if (!has_oneshot_mods_timed_out()) {
551 mods |= get_oneshot_mods();
552 }
553#endif
554 return mods;
555}
556
557void visualizer_update(uint32_t default_state, uint32_t state, uint8_t mods, uint32_t leds) {
503 // Note that there's a small race condition here, the thread could read 558 // Note that there's a small race condition here, the thread could read
504 // a state where one of these are set but not the other. But this should 559 // a state where one of these are set but not the other. But this should
505 // not really matter as it will be fixed during the next loop step. 560 // not really matter as it will be fixed during the next loop step.
@@ -523,6 +578,7 @@ void visualizer_update(uint32_t default_state, uint32_t state, uint32_t leds) {
523 visualizer_keyboard_status_t new_status = { 578 visualizer_keyboard_status_t new_status = {
524 .layer = state, 579 .layer = state,
525 .default_layer = default_state, 580 .default_layer = default_state,
581 .mods = mods,
526 .leds = leds, 582 .leds = leds,
527 .suspended = current_status.suspended, 583 .suspended = current_status.suspended,
528 }; 584 };
diff --git a/quantum/visualizer/visualizer.h b/quantum/visualizer/visualizer.h
index 53e250725..315af5022 100644
--- a/quantum/visualizer/visualizer.h
+++ b/quantum/visualizer/visualizer.h
@@ -34,10 +34,14 @@ SOFTWARE.
34#include "lcd_backlight.h" 34#include "lcd_backlight.h"
35#endif 35#endif
36 36
37// use this function to merget both real_mods and oneshot_mods in a uint16_t
38uint8_t visualizer_get_mods(void);
39
37// This need to be called once at the start 40// This need to be called once at the start
38void visualizer_init(void); 41void visualizer_init(void);
39// This should be called at every matrix scan 42// This should be called at every matrix scan
40void visualizer_update(uint32_t default_state, uint32_t state, uint32_t leds); 43void visualizer_update(uint32_t default_state, uint32_t state, uint8_t mods, uint32_t leds);
44
41// This should be called when the keyboard goes to suspend state 45// This should be called when the keyboard goes to suspend state
42void visualizer_suspend(void); 46void visualizer_suspend(void);
43// This should be called when the keyboard wakes up from suspend state 47// This should be called when the keyboard wakes up from suspend state
@@ -61,6 +65,7 @@ struct keyframe_animation_t;
61typedef struct { 65typedef struct {
62 uint32_t layer; 66 uint32_t layer;
63 uint32_t default_layer; 67 uint32_t default_layer;
68 uint8_t mods;
64 uint32_t leds; // See led.h for available statuses 69 uint32_t leds; // See led.h for available statuses
65 bool suspended; 70 bool suspended;
66} visualizer_keyboard_status_t; 71} visualizer_keyboard_status_t;
@@ -129,6 +134,8 @@ bool keyframe_set_backlight_color(keyframe_animation_t* animation, visualizer_st
129bool keyframe_display_layer_text(keyframe_animation_t* animation, visualizer_state_t* state); 134bool keyframe_display_layer_text(keyframe_animation_t* animation, visualizer_state_t* state);
130// Displays a bitmap (0/1) of all the currently active layers 135// Displays a bitmap (0/1) of all the currently active layers
131bool keyframe_display_layer_bitmap(keyframe_animation_t* animation, visualizer_state_t* state); 136bool keyframe_display_layer_bitmap(keyframe_animation_t* animation, visualizer_state_t* state);
137// Displays a bitmap (0/1) of all the currently active mods
138bool keyframe_display_mods_bitmap(keyframe_animation_t* animation, visualizer_state_t* state);
132 139
133bool keyframe_disable_lcd_and_backlight(keyframe_animation_t* animation, visualizer_state_t* state); 140bool keyframe_disable_lcd_and_backlight(keyframe_animation_t* animation, visualizer_state_t* state);
134bool keyframe_enable_lcd_and_backlight(keyframe_animation_t* animation, visualizer_state_t* state); 141bool keyframe_enable_lcd_and_backlight(keyframe_animation_t* animation, visualizer_state_t* state);