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.c11
-rw-r--r--quantum/quantum.c32
-rw-r--r--quantum/visualizer/visualizer.c58
-rw-r--r--quantum/visualizer/visualizer.h9
8 files changed, 129 insertions, 6 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 a30e93ae3..9995ba9bd 100644
--- a/quantum/process_keycode/process_unicode.c
+++ b/quantum/process_keycode/process_unicode.c
@@ -141,7 +141,16 @@ bool process_unicode_map(uint16_t keycode, keyrecord_t *record) {
141 const uint32_t* map = unicode_map; 141 const uint32_t* map = unicode_map;
142 uint16_t index = keycode & 0x7FF; 142 uint16_t index = keycode & 0x7FF;
143 uint32_t code = pgm_read_dword_far(&map[index]); 143 uint32_t code = pgm_read_dword_far(&map[index]);
144 if ((code > 0xFFFF && input_mode == UC_OSX) || (code > 0xFFFFF && input_mode == UC_LNX)) { 144 if (code > 0xFFFF && code <= 0x10ffff && input_mode == UC_OSX) {
145 // Convert to UTF-16 surrogate pair
146 code -= 0x10000;
147 uint32_t lo = code & 0x3ff;
148 uint32_t hi = (code & 0xffc00) >> 10;
149 unicode_input_start();
150 register_hex32(hi + 0xd800);
151 register_hex32(lo + 0xdc00);
152 unicode_input_finish();
153 } else if ((code > 0x10ffff && input_mode == UC_OSX) || (code > 0xFFFFF && input_mode == UC_LNX)) {
145 // when character is out of range supported by the OS 154 // when character is out of range supported by the OS
146 unicode_map_input_error(); 155 unicode_map_input_error();
147 } else { 156 } else {
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/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);