summaryrefslogtreecommitdiffstats
path: root/quantum
diff options
context:
space:
mode:
Diffstat (limited to 'quantum')
-rw-r--r--quantum/keymap_extras/keymap_br_abnt2.h58
-rw-r--r--quantum/keymap_extras/keymap_jp.h62
-rw-r--r--quantum/matrix.c326
-rw-r--r--quantum/quantum.c11
-rw-r--r--quantum/variable_trace.c110
-rw-r--r--quantum/variable_trace.h34
6 files changed, 494 insertions, 107 deletions
diff --git a/quantum/keymap_extras/keymap_br_abnt2.h b/quantum/keymap_extras/keymap_br_abnt2.h
new file mode 100644
index 000000000..0df177721
--- /dev/null
+++ b/quantum/keymap_extras/keymap_br_abnt2.h
@@ -0,0 +1,58 @@
+#ifndef KEYMAP_BR_ABNT2_H
+#define KEYMAP_BR_ABNT2_H
+
+#include "keymap_common.h"
+
+/* Scan codes for the Brazilian ABNT2 keyboard layout */
+
+#define BR_CCDL KC_SCLN // Ç same scancode as ;: on US layout
+#define BR_SCLN KC_SLSH // ;: same scancode as /? on US layout
+#define BR_QUOT KC_GRV // '" same scancode as `~ on US layout
+#define BR_TILD KC_QUOT // ~^ dead keys, same scancode as '" on US layout
+#define BR_ACUT KC_LBRC // ´` dead keys, same scancode as [{ on US layout
+#define BR_LBRC KC_RBRC // [{ same scancode as ]} on US layout
+#define BR_RBRC KC_BSLS // ]} same scancode as \| on US layout
+#define BR_BSLS KC_NUBS // \| uses the non-US hash scancode (#~, sometimes §±)
+#define BR_SLSH KC_INT1 // /? uses the INTL1 scancode
+
+#define BR_COLN LSFT(BR_SCLN) // shifted :
+#define BR_DQT LSFT(BR_QUOT) // shifted "
+#define BR_CIRC LSFT(BR_TILD) // shifted ^ (dead key)
+#define BR_GRAV LSFT(BR_ACUT) // shifted ` (dead key)
+#define BR_LCBR LSFT(BR_LBRC) // shifted {
+#define BR_RCBR LSFT(BR_RBRC) // shifted }
+#define BR_PIPE LSFT(BR_BSLS) // shifted |
+#define BR_QUES LSFT(BR_SLSH) // shifted ?
+#define BR_TRMA LSFT(KC_6) // shifted ¨ (dead key - trema accent)
+
+// On the ABNT2 the keypad comma and the keypad dot scancodes are switched
+// (presumably because in Brazil comma is used as the decimal separator)
+#define BR_KPDT KC_KP_COMMA // keypad .
+#define BR_KPCM KC_KP_DOT // keypad ,
+
+#define BR_1UP LALT(KC_1) // 1 superscript ¹ alt+1
+#define BR_2UP LALT(KC_2) // 2 superscript ² alt+2
+#define BR_3UP LALT(KC_3) // 3 superscript ³ alt+3
+#define BR_PND LALT(KC_4) // Pound sign £ alt+4
+#define BR_CENT LALT(KC_5) // Cent sign ¢ alt+5
+#define BR_NOT LALT(KC_6) // Not sign ¬ alt+6
+#define BR_SECT LALT(KC_EQL) // Section sign § alt+=
+#define BR_FORD LALT(BR_LBRC) // Feminine Ordinal Sign ª alt+[
+#define BR_MORD LALT(BR_RBRC) // Masculine Ordinal Sign º alt+]
+#define BR_DGRE LALT(BR_SLSH) // Degree sign ° alt+/
+
+#define BR_EURO LALT(KC_E) // Euro sign € alt+e
+#define BR_NDTD LALT(BR_TILD) // Non-dead key tilde ~ alt+~
+#define BR_NDAC LALT(BR_ACUT) // Non-dead key acute accent ´ alt+´
+#define BR_NDGV LALT(BR_QUOT) // Non-dead key grave accent ` alt+'
+#define BR_NDCR LALT(BR_CIRC) // Non-dead key circumflex accent ^ alt+^ (alt+shift+~)
+#define BR_NDTR LALT(BR_TRMA) // Non-dead key trema accent ¨ alt+¨ (alt+shift+6)
+
+// For 101-key keyboard layouts, the ABNT2 layout allows
+// the slash and question mark to be typed using alt+q and alt+w.
+// The shortcuts are provided here for completeness' sake,
+// but it's recommended to use BR_SLSH and BR_QUES instead
+#define BR_ASLS LALT(KC_Q)
+#define BR_AQST LALT(KC_W)
+
+#endif
diff --git a/quantum/keymap_extras/keymap_jp.h b/quantum/keymap_extras/keymap_jp.h
new file mode 100644
index 000000000..e81b5952e
--- /dev/null
+++ b/quantum/keymap_extras/keymap_jp.h
@@ -0,0 +1,62 @@
+/* JP106-layout (Japanese Standard)
+ *
+ * For more information, see
+ * http://www2d.biglobe.ne.jp/~msyk/keyboard/layout/usbkeycode.html
+ * note: This website is written in Japanese.
+ */
+
+
+#ifndef KEYMAP_JP_H
+#define KEYMAP_JP_H
+
+
+#include "keymap.h"
+
+
+#define JP_ZHTG KC_GRV // hankaku/zenkaku|kanzi
+#define JP_YEN KC_INT3 // yen, |
+#define JP_CIRC KC_EQL // ^, ~
+#define JP_AT KC_LBRC // @, `
+#define JP_LBRC KC_RBRC // [, {
+#define JP_COLN KC_QUOT // :, *
+#define JP_RBRC KC_NUHS // ], }
+#define JP_BSLS KC_INT1 // \, _
+#define JP_MHEN KC_INT5 // muhenkan
+#define JP_HENK KC_INT4 // henkan
+#define JP_KANA KC_INT2 // katakana/hiragana|ro-mazi
+
+
+//Aliases for shifted symbols
+#define JP_DQT LSFT(KC_2) // "
+#define JP_AMPR LSFT(KC_6) // &
+#define JP_QUOT LSFT(KC_7) // '
+#define JP_LPRN LSFT(KC_8) // (
+#define JP_RPRN LSFT(KC_9) // )
+#define JP_EQL LSFT(KC_MINS) // =
+#define JP_TILD LSFT(JP_CIRC) // ~
+#define JP_PIPE LSFT(JP_YEN) // |
+#define JP_GRV LSFT(JP_AT) // `
+#define JP_LCBR LSFT(JP_LBRC) // {
+#define JP_PLUS LSFT(KC_SCLN) // +
+#define JP_ASTR LSFT(JP_COLN) // *
+#define JP_RCBR LSFT(JP_RBRC) // }
+#define JP_UNDS LSFT(JP_BSLS) // _
+
+
+// These symbols are correspond to US101-layout.
+#define JP_MINS KC_MINS // -
+#define JP_SCLN KC_SCLN // ;
+#define JP_COMM KC_COMM // ,
+#define JP_DOT KC_DOT // .
+#define JP_SLSH KC_SLSH // /
+// shifted
+#define JP_EXLM KC_EXLM // !
+#define JP_HASH KC_HASH // #
+#define JP_DLR KC_DLR // $
+#define JP_PERC KC_PERC // %
+#define JP_LT KC_LT // <
+#define JP_GT KC_GT // >
+#define JP_QUES KC_QUES // ?
+
+
+#endif
diff --git a/quantum/matrix.c b/quantum/matrix.c
index 3174e0739..07eb87bc3 100644
--- a/quantum/matrix.c
+++ b/quantum/matrix.c
@@ -25,37 +25,65 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "debug.h"
#include "util.h"
#include "matrix.h"
+#include "timer.h"
+
/* Set 0 if debouncing isn't needed */
#ifndef DEBOUNCING_DELAY
# define DEBOUNCING_DELAY 5
#endif
-static uint8_t debouncing = DEBOUNCING_DELAY;
+
+#if (DEBOUNCING_DELAY > 0)
+ static uint16_t debouncing_time;
+ static bool debouncing = false;
+#endif
+
+#if (MATRIX_COLS <= 8)
+# define print_matrix_header() print("\nr/c 01234567\n")
+# define print_matrix_row(row) print_bin_reverse8(matrix_get_row(row))
+# define matrix_bitpop(i) bitpop(matrix[i])
+# define ROW_SHIFTER ((uint8_t)1)
+#elif (MATRIX_COLS <= 16)
+# define print_matrix_header() print("\nr/c 0123456789ABCDEF\n")
+# define print_matrix_row(row) print_bin_reverse16(matrix_get_row(row))
+# define matrix_bitpop(i) bitpop16(matrix[i])
+# define ROW_SHIFTER ((uint16_t)1)
+#elif (MATRIX_COLS <= 32)
+# define print_matrix_header() print("\nr/c 0123456789ABCDEF0123456789ABCDEF\n")
+# define print_matrix_row(row) print_bin_reverse32(matrix_get_row(row))
+# define matrix_bitpop(i) bitpop32(matrix[i])
+# define ROW_SHIFTER ((uint32_t)1)
+#endif
+
+#ifdef MATRIX_MASKED
+ extern const matrix_row_t matrix_mask[];
+#endif
static const uint8_t row_pins[MATRIX_ROWS] = MATRIX_ROW_PINS;
static const uint8_t col_pins[MATRIX_COLS] = MATRIX_COL_PINS;
/* matrix state(1:on, 0:off) */
static matrix_row_t matrix[MATRIX_ROWS];
+
+static matrix_row_t matrix_raw[MATRIX_ROWS];
static matrix_row_t matrix_debouncing[MATRIX_ROWS];
-#if DIODE_DIRECTION == ROW2COL
- static matrix_row_t matrix_reversed[MATRIX_COLS];
- static matrix_row_t matrix_reversed_debouncing[MATRIX_COLS];
-#endif
-#if MATRIX_COLS > 16
- #define SHIFTER 1UL
-#else
- #define SHIFTER 1
+#if (DIODE_DIRECTION == COL2ROW)
+ static void init_cols(void);
+ static bool read_cols_on_row(matrix_row_t current_matrix[], uint8_t current_row);
+ static void unselect_rows(void);
+ static void select_row(uint8_t row);
+ static void unselect_row(uint8_t row);
+#else // ROW2COL
+ static void init_rows(void);
+ static bool read_rows_on_col(matrix_row_t current_matrix[], uint8_t current_col);
+ static void unselect_cols(void);
+ static void unselect_col(uint8_t col);
+ static void select_col(uint8_t col);
#endif
-static matrix_row_t read_cols(void);
-static void init_cols(void);
-static void unselect_rows(void);
-static void select_row(uint8_t row);
-
__attribute__ ((weak))
void matrix_init_quantum(void) {
matrix_init_kb();
@@ -95,7 +123,7 @@ uint8_t matrix_cols(void) {
}
// void matrix_power_up(void) {
-// #if DIODE_DIRECTION == COL2ROW
+// #if (DIODE_DIRECTION == COL2ROW)
// for (int8_t r = MATRIX_ROWS - 1; r >= 0; --r) {
// /* DDRxn */
// _SFR_IO8((row_pins[r] >> 4) + 1) |= _BV(row_pins[r] & 0xF);
@@ -119,19 +147,26 @@ uint8_t matrix_cols(void) {
// }
void matrix_init(void) {
+
// To use PORTF disable JTAG with writing JTD bit twice within four cycles.
- #ifdef __AVR_ATmega32U4__
+ #if (defined(__AVR_AT90USB1286__) || defined(__AVR_AT90USB1287__) || defined(__AVR_ATmega32U4__))
MCUCR |= _BV(JTD);
MCUCR |= _BV(JTD);
#endif
// initialize row and col
+#if (DIODE_DIRECTION == COL2ROW)
unselect_rows();
init_cols();
+#else // ROW2COL
+ unselect_cols();
+ init_rows();
+#endif
// initialize matrix state: all keys off
for (uint8_t i=0; i < MATRIX_ROWS; i++) {
matrix[i] = 0;
+ matrix_raw[i] = 0;
matrix_debouncing[i] = 0;
}
@@ -141,71 +176,60 @@ void matrix_init(void) {
uint8_t matrix_scan(void)
{
-#if DIODE_DIRECTION == COL2ROW
- for (uint8_t i = 0; i < MATRIX_ROWS; i++) {
- select_row(i);
- wait_us(30); // without this wait read unstable value.
- matrix_row_t cols = read_cols();
- if (matrix_debouncing[i] != cols) {
- matrix_debouncing[i] = cols;
- if (debouncing) {
- debug("bounce!: "); debug_hex(debouncing); debug("\n");
- }
- debouncing = DEBOUNCING_DELAY;
- }
- unselect_rows();
- }
+#if (DIODE_DIRECTION == COL2ROW)
- if (debouncing) {
- if (--debouncing) {
- wait_ms(1);
- } else {
- for (uint8_t i = 0; i < MATRIX_ROWS; i++) {
- matrix[i] = matrix_debouncing[i];
+ // Set row, read cols
+ for (uint8_t current_row = 0; current_row < MATRIX_ROWS; current_row++) {
+# if (DEBOUNCING_DELAY > 0)
+ bool matrix_changed = read_cols_on_row(matrix_debouncing, current_row);
+
+ if (matrix_changed) {
+ debouncing = true;
+ debouncing_time = timer_read();
}
- }
+
+# else
+ read_cols_on_row(matrix, current_row);
+# endif
+
}
-#else
- for (uint8_t i = 0; i < MATRIX_COLS; i++) {
- select_row(i);
- wait_us(30); // without this wait read unstable value.
- matrix_row_t rows = read_cols();
- if (matrix_reversed_debouncing[i] != rows) {
- matrix_reversed_debouncing[i] = rows;
- if (debouncing) {
- debug("bounce!: "); debug_hex(debouncing); debug("\n");
+
+#else // ROW2COL
+
+ // Set col, read rows
+ for (uint8_t current_col = 0; current_col < MATRIX_COLS; current_col++) {
+# if (DEBOUNCING_DELAY > 0)
+ bool matrix_changed = read_rows_on_col(matrix_debouncing, current_col);
+ if (matrix_changed) {
+ debouncing = true;
+ debouncing_time = timer_read();
}
- debouncing = DEBOUNCING_DELAY;
- }
- unselect_rows();
+# else
+ read_rows_on_col(matrix, current_col);
+# endif
+
}
- if (debouncing) {
- if (--debouncing) {
- wait_ms(1);
- } else {
- for (uint8_t i = 0; i < MATRIX_COLS; i++) {
- matrix_reversed[i] = matrix_reversed_debouncing[i];
+#endif
+
+# if (DEBOUNCING_DELAY > 0)
+ if (debouncing && (timer_elapsed(debouncing_time) > DEBOUNCING_DELAY)) {
+ for (uint8_t i = 0; i < MATRIX_ROWS; i++) {
+ matrix[i] = matrix_debouncing[i];
}
+ debouncing = false;
}
- }
- for (uint8_t y = 0; y < MATRIX_ROWS; y++) {
- matrix_row_t row = 0;
- for (uint8_t x = 0; x < MATRIX_COLS; x++) {
- row |= ((matrix_reversed[x] & (1<<y)) >> y) << x;
- }
- matrix[y] = row;
- }
-#endif
+# endif
matrix_scan_quantum();
-
return 1;
}
bool matrix_is_modified(void)
{
+#if (DEBOUNCING_DELAY > 0)
if (debouncing) return false;
+#endif
return true;
}
@@ -218,15 +242,22 @@ bool matrix_is_on(uint8_t row, uint8_t col)
inline
matrix_row_t matrix_get_row(uint8_t row)
{
+ // Matrix mask lets you disable switches in the returned matrix data. For example, if you have a
+ // switch blocker installed and the switch is always pressed.
+#ifdef MATRIX_MASKED
+ return matrix[row] & matrix_mask[row];
+#else
return matrix[row];
+#endif
}
void matrix_print(void)
{
- print("\nr/c 0123456789ABCDEF\n");
+ print_matrix_header();
+
for (uint8_t row = 0; row < MATRIX_ROWS; row++) {
phex(row); print(": ");
- pbin_reverse16(matrix_get_row(row));
+ print_matrix_row(row);
print("\n");
}
}
@@ -235,63 +266,148 @@ uint8_t matrix_key_count(void)
{
uint8_t count = 0;
for (uint8_t i = 0; i < MATRIX_ROWS; i++) {
- count += bitpop16(matrix[i]);
+ count += matrix_bitpop(i);
}
return count;
}
+
+
+#if (DIODE_DIRECTION == COL2ROW)
+
static void init_cols(void)
{
-#if DIODE_DIRECTION == COL2ROW
- for(int x = 0; x < MATRIX_COLS; x++) {
- int pin = col_pins[x];
-#else
- for(int x = 0; x < MATRIX_ROWS; x++) {
- int pin = row_pins[x];
-#endif
- _SFR_IO8((pin >> 4) + 1) &= ~_BV(pin & 0xF);
- _SFR_IO8((pin >> 4) + 2) |= _BV(pin & 0xF);
+ for(uint8_t x = 0; x < MATRIX_COLS; x++) {
+ uint8_t pin = col_pins[x];
+ _SFR_IO8((pin >> 4) + 1) &= ~_BV(pin & 0xF); // IN
+ _SFR_IO8((pin >> 4) + 2) |= _BV(pin & 0xF); // HI
}
}
-static matrix_row_t read_cols(void)
+static bool read_cols_on_row(matrix_row_t current_matrix[], uint8_t current_row)
{
- matrix_row_t result = 0;
+ // Store last value of row prior to reading
+ matrix_row_t last_row_value = current_matrix[current_row];
-#if DIODE_DIRECTION == COL2ROW
- for(int x = 0; x < MATRIX_COLS; x++) {
- int pin = col_pins[x];
-#else
- for(int x = 0; x < MATRIX_ROWS; x++) {
- int pin = row_pins[x];
-#endif
- result |= (_SFR_IO8(pin >> 4) & _BV(pin & 0xF)) ? 0 : (SHIFTER << x);
+ // Clear data in matrix row
+ current_matrix[current_row] = 0;
+
+ // Select row and wait for row selecton to stabilize
+ select_row(current_row);
+ wait_us(30);
+
+ // For each col...
+ for(uint8_t col_index = 0; col_index < MATRIX_COLS; col_index++) {
+
+ // Select the col pin to read (active low)
+ uint8_t pin = col_pins[col_index];
+ uint8_t pin_state = (_SFR_IO8(pin >> 4) & _BV(pin & 0xF));
+
+ // Populate the matrix row with the state of the col pin
+ current_matrix[current_row] |= pin_state ? 0 : (ROW_SHIFTER << col_index);
}
- return result;
+
+ // Unselect row
+ unselect_row(current_row);
+
+ return (last_row_value != current_matrix[current_row]);
+}
+
+static void select_row(uint8_t row)
+{
+ uint8_t pin = row_pins[row];
+ _SFR_IO8((pin >> 4) + 1) |= _BV(pin & 0xF); // OUT
+ _SFR_IO8((pin >> 4) + 2) &= ~_BV(pin & 0xF); // LOW
+}
+
+static void unselect_row(uint8_t row)
+{
+ uint8_t pin = row_pins[row];
+ _SFR_IO8((pin >> 4) + 1) &= ~_BV(pin & 0xF); // IN
+ _SFR_IO8((pin >> 4) + 2) |= _BV(pin & 0xF); // HI
}
static void unselect_rows(void)
{
-#if DIODE_DIRECTION == COL2ROW
- for(int x = 0; x < MATRIX_ROWS; x++) {
- int pin = row_pins[x];
-#else
- for(int x = 0; x < MATRIX_COLS; x++) {
- int pin = col_pins[x];
-#endif
- _SFR_IO8((pin >> 4) + 1) &= ~_BV(pin & 0xF);
- _SFR_IO8((pin >> 4) + 2) |= _BV(pin & 0xF);
+ for(uint8_t x = 0; x < MATRIX_ROWS; x++) {
+ uint8_t pin = row_pins[x];
+ _SFR_IO8((pin >> 4) + 1) &= ~_BV(pin & 0xF); // IN
+ _SFR_IO8((pin >> 4) + 2) |= _BV(pin & 0xF); // HI
}
}
-static void select_row(uint8_t row)
+#else // ROW2COL
+
+static void init_rows(void)
{
+ for(uint8_t x = 0; x < MATRIX_ROWS; x++) {
+ uint8_t pin = row_pins[x];
+ _SFR_IO8((pin >> 4) + 1) &= ~_BV(pin & 0xF); // IN
+ _SFR_IO8((pin >> 4) + 2) |= _BV(pin & 0xF); // HI
+ }
+}
-#if DIODE_DIRECTION == COL2ROW
- int pin = row_pins[row];
-#else
- int pin = col_pins[row];
-#endif
- _SFR_IO8((pin >> 4) + 1) |= _BV(pin & 0xF);
- _SFR_IO8((pin >> 4) + 2) &= ~_BV(pin & 0xF);
+static bool read_rows_on_col(matrix_row_t current_matrix[], uint8_t current_col)
+{
+ bool matrix_changed = false;
+
+ // Select col and wait for col selecton to stabilize
+ select_col(current_col);
+ wait_us(30);
+
+ // For each row...
+ for(uint8_t row_index = 0; row_index < MATRIX_ROWS; row_index++)
+ {
+
+ // Store last value of row prior to reading
+ matrix_row_t last_row_value = current_matrix[row_index];
+
+ // Check row pin state
+ if ((_SFR_IO8(row_pins[row_index] >> 4) & _BV(row_pins[row_index] & 0xF)) == 0)
+ {
+ // Pin LO, set col bit
+ current_matrix[row_index] |= (ROW_SHIFTER << current_col);
+ }
+ else
+ {
+ // Pin HI, clear col bit
+ current_matrix[row_index] &= ~(ROW_SHIFTER << current_col);
+ }
+
+ // Determine if the matrix changed state
+ if ((last_row_value != current_matrix[row_index]) && !(matrix_changed))
+ {
+ matrix_changed = true;
+ }
+ }
+
+ // Unselect col
+ unselect_col(current_col);
+
+ return matrix_changed;
}
+
+static void select_col(uint8_t col)
+{
+ uint8_t pin = col_pins[col];
+ _SFR_IO8((pin >> 4) + 1) |= _BV(pin & 0xF); // OUT
+ _SFR_IO8((pin >> 4) + 2) &= ~_BV(pin & 0xF); // LOW
+}
+
+static void unselect_col(uint8_t col)
+{
+ uint8_t pin = col_pins[col];
+ _SFR_IO8((pin >> 4) + 1) &= ~_BV(pin & 0xF); // IN
+ _SFR_IO8((pin >> 4) + 2) |= _BV(pin & 0xF); // HI
+}
+
+static void unselect_cols(void)
+{
+ for(uint8_t x = 0; x < MATRIX_COLS; x++) {
+ uint8_t pin = col_pins[x];
+ _SFR_IO8((pin >> 4) + 1) &= ~_BV(pin & 0xF); // IN
+ _SFR_IO8((pin >> 4) + 2) |= _BV(pin & 0xF); // HI
+ }
+}
+
+#endif
diff --git a/quantum/quantum.c b/quantum/quantum.c
index 098312e6e..b5e2d60b9 100644
--- a/quantum/quantum.c
+++ b/quantum/quantum.c
@@ -1,5 +1,9 @@
#include "quantum.h"
+#ifndef TAPPING_TERM
+#define TAPPING_TERM 200
+#endif
+
static void do_code16 (uint16_t code, void (*f) (uint8_t)) {
switch (code) {
case QK_MODS ... QK_MODS_MAX:
@@ -75,6 +79,7 @@ void reset_keyboard(void) {
#endif
static bool shift_interrupted[2] = {0, 0};
+static uint16_t scs_timer = 0;
bool process_record_quantum(keyrecord_t *record) {
@@ -283,6 +288,7 @@ bool process_record_quantum(keyrecord_t *record) {
case KC_LSPO: {
if (record->event.pressed) {
shift_interrupted[0] = false;
+ scs_timer = timer_read ();
register_mods(MOD_BIT(KC_LSFT));
}
else {
@@ -292,7 +298,7 @@ bool process_record_quantum(keyrecord_t *record) {
shift_interrupted[1] = true;
}
#endif
- if (!shift_interrupted[0]) {
+ if (!shift_interrupted[0] && timer_elapsed(scs_timer) < TAPPING_TERM) {
register_code(LSPO_KEY);
unregister_code(LSPO_KEY);
}
@@ -305,6 +311,7 @@ bool process_record_quantum(keyrecord_t *record) {
case KC_RSPC: {
if (record->event.pressed) {
shift_interrupted[1] = false;
+ scs_timer = timer_read ();
register_mods(MOD_BIT(KC_RSFT));
}
else {
@@ -314,7 +321,7 @@ bool process_record_quantum(keyrecord_t *record) {
shift_interrupted[1] = true;
}
#endif
- if (!shift_interrupted[1]) {
+ if (!shift_interrupted[1] && timer_elapsed(scs_timer) < TAPPING_TERM) {
register_code(RSPC_KEY);
unregister_code(RSPC_KEY);
}
diff --git a/quantum/variable_trace.c b/quantum/variable_trace.c
new file mode 100644
index 000000000..de580244c
--- /dev/null
+++ b/quantum/variable_trace.c
@@ -0,0 +1,110 @@
+#include "variable_trace.h"
+#include <stddef.h>
+#include <string.h>
+
+#ifdef NO_PRINT
+#error "You need undef NO_PRINT to use the variable trace feature"
+#endif
+
+#ifndef CONSOLE_ENABLE
+#error "The console needs to be enabled in the makefile to use the variable trace feature"
+#endif
+
+
+#define NUM_TRACED_VARIABLES 1
+#ifndef MAX_VARIABLE_TRACE_SIZE
+ #define MAX_VARIABLE_TRACE_SIZE 4
+#endif
+
+typedef struct {
+ const char* name;
+ void* addr;
+ unsigned size;
+ const char* func;
+ int line;
+ uint8_t last_value[MAX_VARIABLE_TRACE_SIZE];
+
+} traced_variable_t;
+
+static traced_variable_t traced_variables[NUM_TRACED_VARIABLES];
+
+void add_traced_variable(const char* name, void* addr, unsigned size, const char* func, int line) {
+ verify_traced_variables(func, line);
+ if (size > MAX_VARIABLE_TRACE_SIZE) {
+#if defined(__AVR__)
+ xprintf("Traced variable \"%S\" exceeds the maximum size %d\n", name, size);
+#else
+ xprintf("Traced variable \"%s\" exceeds the maximum size %d\n", name, size);
+#endif
+ size = MAX_VARIABLE_TRACE_SIZE;
+ }
+ int index = -1;
+ for (int i = 0; i < NUM_TRACED_VARIABLES; i++) {
+ if (index == -1 && traced_variables[i].addr == NULL){
+ index = i;
+ }
+ else if (strcmp_P(name, traced_variables[i].name)==0) {
+ index = i;
+ break;
+ }
+ }
+
+ if (index == -1) {
+ xprintf("You can only trace %d variables at the same time\n", NUM_TRACED_VARIABLES);
+ return;
+ }
+
+ traced_variable_t* t = &traced_variables[index];
+ t->name = name;
+ t->addr = addr;
+ t->size = size;
+ t->func = func;
+ t->line = line;
+ memcpy(&t->last_value[0], addr, size);
+
+}
+
+void remove_traced_variable(const char* name, const char* func, int line) {
+ verify_traced_variables(func, line);
+ for (int i = 0; i < NUM_TRACED_VARIABLES; i++) {
+ if (strcmp_P(name, traced_variables[i].name)==0) {
+ traced_variables[i].name = 0;
+ traced_variables[i].addr = NULL;
+ break;
+ }
+ }
+}
+
+void verify_traced_variables(const char* func, int line) {
+ for (int i = 0; i < NUM_TRACED_VARIABLES; i++) {
+ traced_variable_t* t = &traced_variables[i];
+ if (t->addr != NULL && t->name != NULL) {
+ if (memcmp(t->last_value, t->addr, t->size)!=0){
+#if defined(__AVR__)
+ xprintf("Traced variable \"%S\" has been modified\n", t->name);
+ xprintf("Between %S:%d\n", t->func, t->line);
+ xprintf("And %S:%d\n", func, line);
+
+#else
+ xprintf("Traced variable \"%s\" has been modified\n", t->name);
+ xprintf("Between %s:%d\n", t->func, t->line);
+ xprintf("And %s:%d\n", func, line);
+#endif
+ xprintf("Previous value ");
+ for (int j=0; j<t->size;j++) {
+ print_hex8(t->last_value[j]);
+ }
+ xprintf("\nNew value ");
+ uint8_t* addr = (uint8_t*)(t->addr);
+ for (int j=0; j<t->size;j++) {
+ print_hex8(addr[j]);
+ }
+ xprintf("\n");
+ memcpy(t->last_value, addr, t->size);
+ }
+ }
+
+ t->func = func;
+ t->line = line;
+ }
+}
diff --git a/quantum/variable_trace.h b/quantum/variable_trace.h
new file mode 100644
index 000000000..46bd82786
--- /dev/null
+++ b/quantum/variable_trace.h
@@ -0,0 +1,34 @@
+#ifndef VARIABLE_TRACE_H
+#define VARIABLE_TRACE_H
+
+// For more information about the variable tracing see the readme.
+
+#include "print.h"
+
+#ifdef NUM_TRACED_VARIABLES
+
+// Start tracing a variable at the memory address addr
+// The name can be anything and is used only for reporting
+// The size should usually be the same size as the variable you are interested in
+#define ADD_TRACED_VARIABLE(name, addr, size) \
+ add_traced_variable(PSTR(name), (void*)addr, size, PSTR(__FILE__), __LINE__)
+
+// Stop tracing the variable with the given name
+#define REMOVE_TRACED_VARIABLE(name) remove_traced_variable(PSTR(name), PSTR(__FILE__), __LINE__)
+
+// Call to get messages when the variable has been changed
+#define VERIFY_TRACED_VARIABLES() verify_traced_variables(PSTR(__FILE__), __LINE__)
+
+#else
+
+#define ADD_TRACED_VARIABLE(name, addr, size)
+#define REMOVE_TRACED_VARIABLE(name)
+#define VERIFY_TRACED_VARIABLES()
+
+#endif
+
+// Don't call directly, use the macros instead
+void add_traced_variable(const char* name, void* addr, unsigned size, const char* func, int line);
+void remove_traced_variable(const char* name, const char* func, int line);
+void verify_traced_variables(const char* func, int line);
+#endif