From f9c61b1bbe14ffb9d00107fcb68e86dcba6eb22a Mon Sep 17 00:00:00 2001 From: Fred Sundvik Date: Fri, 29 Jun 2018 17:21:00 +0300 Subject: [PATCH] Add a keymatrix_t type This contains both the matrix number and key position, in preparation for multi-matrix support --- drivers/qwiic/qwiic_keyboard.c | 16 +++++++--------- .../planck/old_keymap_files/keymap_common.c | 2 +- quantum/keymap.h | 2 +- quantum/keymap_common.c | 8 +++++--- quantum/process_keycode/process_music.c | 13 +++++++------ quantum/quantum.c | 2 +- tests/layer_cache/test_layer_cache.cpp | 14 ++++++++------ tmk_core/common/action.c | 2 +- tmk_core/common/action.h | 4 ++-- tmk_core/common/action_layer.c | 14 +++++++------- tmk_core/common/action_layer.h | 10 +++++----- tmk_core/common/bootmagic.c | 2 +- tmk_core/common/keyboard.c | 3 ++- tmk_core/common/keyboard.h | 16 +++++++++++----- 14 files changed, 59 insertions(+), 49 deletions(-) diff --git a/drivers/qwiic/qwiic_keyboard.c b/drivers/qwiic/qwiic_keyboard.c index 8542a9f2b9f..8e3591fd9d0 100644 --- a/drivers/qwiic/qwiic_keyboard.c +++ b/drivers/qwiic/qwiic_keyboard.c @@ -80,7 +80,6 @@ void qwiic_keyboard_task(void) { #ifdef QMK_KEYS_PER_SCAN uint8_t keys_processed = 0; #endif - qwiic_keyboard_processing_slave = true; for (uint8_t r = 0; r < QWIIC_KEYBOARD_ROWS; r++) { matrix_row = qwiic_keyboard_matrix_message[r]; matrix_change = matrix_row ^ matrix_prev[r]; @@ -88,7 +87,8 @@ void qwiic_keyboard_task(void) { for (uint8_t c = 0; c < QWIIC_KEYBOARD_COLS; c++) { if (matrix_change & ((qwiic_matrix_t)1<. /* translates key to keycode */ -uint8_t keymap_key_to_keycode(uint8_t layer, keypos_t key) +uint8_t keymap_key_to_keycode(uint8_t layer, keymatrix_t key) { return pgm_read_byte(&keymaps[(layer)][(key.row)][(key.col)]); } diff --git a/quantum/keymap.h b/quantum/keymap.h index bfcb2f7cd51..734d128573c 100644 --- a/quantum/keymap.h +++ b/quantum/keymap.h @@ -44,7 +44,7 @@ along with this program. If not, see . #include "quantum_keycodes.h" // translates key to keycode -uint16_t keymap_key_to_keycode(uint8_t layer, keypos_t key); +uint16_t keymap_key_to_keycode(uint8_t layer, keymatrix_t key); // translates function id to action uint16_t keymap_function_id_to_action( uint16_t function_id ); diff --git a/quantum/keymap_common.c b/quantum/keymap_common.c index 9a412b66ade..d68001bb65d 100644 --- a/quantum/keymap_common.c +++ b/quantum/keymap_common.c @@ -38,7 +38,7 @@ extern keymap_config_t keymap_config; #include /* converts key to action */ -action_t action_for_key(uint8_t layer, keypos_t key) +action_t action_for_key(uint8_t layer, keymatrix_t key) { // 16bit keycodes - important uint16_t keycode = keymap_key_to_keycode(layer, key); @@ -184,10 +184,12 @@ void action_function(keyrecord_t *record, uint8_t id, uint8_t opt) // translates key to keycode __attribute__ ((weak)) -uint16_t keymap_key_to_keycode(uint8_t layer, keypos_t key) +uint16_t keymap_key_to_keycode(uint8_t layer, keymatrix_t key) { // Read entire word (16bits) - return pgm_read_word(&keymaps[(layer)][(key.row)][(key.col)]); + // The default implmention does not have multiple matrix support + // and therfore it ignores the matrix field of the key + return pgm_read_word(&keymaps[(layer)][(key.pos.row)][(key.pos.col)]); } // translates function id to action diff --git a/quantum/process_keycode/process_music.c b/quantum/process_keycode/process_music.c index 697aa237fac..fc6de4350a5 100644 --- a/quantum/process_keycode/process_music.c +++ b/quantum/process_keycode/process_music.c @@ -198,22 +198,23 @@ bool process_music(uint16_t keycode, keyrecord_t *record) { } uint8_t note = 36; + // Note: Multimatrix support is missing from this (it's probablly better to define it using keycodes) #ifdef MUSIC_MAP if (music_mode == MUSIC_MODE_CHROMATIC) { - note = music_starting_note + music_offset + 36 + music_map[record->event.key.row][record->event.key.col]; + note = music_starting_note + music_offset + 36 + music_map[record->event.key.pos.row][record->event.key.pos.col]; } else { - uint8_t position = music_map[record->event.key.row][record->event.key.col]; + uint8_t position = music_map[record->event.key.pos.row][record->event.key.pos.col]; note = music_starting_note + music_offset + 36 + SCALE[position % 12] + (position / 12)*12; } #else if (music_mode == MUSIC_MODE_CHROMATIC) - note = (music_starting_note + record->event.key.col + music_offset - 3)+12*(MATRIX_ROWS - record->event.key.row); + note = (music_starting_note + record->event.key.pos.col + music_offset - 3)+12*(MATRIX_ROWS - record->event.key.pos.row); else if (music_mode == MUSIC_MODE_GUITAR) - note = (music_starting_note + record->event.key.col + music_offset + 32)+5*(MATRIX_ROWS - record->event.key.row); + note = (music_starting_note + record->event.key.pos.col + music_offset + 32)+5*(MATRIX_ROWS - record->event.key.pos.row); else if (music_mode == MUSIC_MODE_VIOLIN) - note = (music_starting_note + record->event.key.col + music_offset + 32)+7*(MATRIX_ROWS - record->event.key.row); + note = (music_starting_note + record->event.key.pos.col + music_offset + 32)+7*(MATRIX_ROWS - record->event.key.pos.row); else if (music_mode == MUSIC_MODE_MAJOR) - note = (music_starting_note + SCALE[record->event.key.col + music_offset] - 3)+12*(MATRIX_ROWS - record->event.key.row); + note = (music_starting_note + SCALE[record->event.key.pos.col + music_offset] - 3)+12*(MATRIX_ROWS - record->event.key.pos.row); else note = music_starting_note; #endif diff --git a/quantum/quantum.c b/quantum/quantum.c index 331ed5634c1..086c1160b43 100644 --- a/quantum/quantum.c +++ b/quantum/quantum.c @@ -190,7 +190,7 @@ static bool grave_esc_was_shifted = false; bool process_record_quantum(keyrecord_t *record) { /* This gets the keycode from the key pressed */ - keypos_t key = record->event.key; + keymatrix_t key = record->event.key; uint16_t keycode; #if !defined(NO_ACTION_LAYER) && defined(PREVENT_STUCK_MODIFIERS) diff --git a/tests/layer_cache/test_layer_cache.cpp b/tests/layer_cache/test_layer_cache.cpp index 4aebe24b749..cc58cbbdba6 100644 --- a/tests/layer_cache/test_layer_cache.cpp +++ b/tests/layer_cache/test_layer_cache.cpp @@ -34,16 +34,18 @@ namespace uint8_t read_cache(uint8_t col, uint8_t row) { - keypos_t key; - key.col = col; - key.row = row; + keymatrix_t key; + key.pos.col = col; + key.pos.row = row; + key.matrix = 0; return read_source_layers_cache(key); } void write_cache(uint8_t col, uint8_t row, uint8_t value) { - keypos_t key; - key.col = col; - key.row = row; + keymatrix_t key; + key.pos.col = col; + key.pos.row = row; + key.matrix = 0; return update_source_layers_cache(key, value); } diff --git a/tmk_core/common/action.c b/tmk_core/common/action.c index f7c039f4579..cfc933fb280 100644 --- a/tmk_core/common/action.c +++ b/tmk_core/common/action.c @@ -892,7 +892,7 @@ void clear_keyboard_but_mods(void) * * FIXME: Needs documentation. */ -bool is_tap_key(keypos_t key) +bool is_tap_key(keymatrix_t key) { action_t action = layer_switch_get_action(key); diff --git a/tmk_core/common/action.h b/tmk_core/common/action.h index acc55c7d388..7b69c6c282d 100644 --- a/tmk_core/common/action.h +++ b/tmk_core/common/action.h @@ -50,7 +50,7 @@ typedef struct { void action_exec(keyevent_t event); /* action for key */ -action_t action_for_key(uint8_t layer, keypos_t key); +action_t action_for_key(uint8_t layer, keymatrix_t key); /* macro */ const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt); @@ -94,7 +94,7 @@ void unregister_mods(uint8_t mods); void clear_keyboard(void); void clear_keyboard_but_mods(void); void layer_switch(uint8_t new_layer); -bool is_tap_key(keypos_t key); +bool is_tap_key(keymatrix_t key); #ifndef NO_ACTION_TAPPING void process_record_tap_hint(keyrecord_t *record); diff --git a/tmk_core/common/action_layer.c b/tmk_core/common/action_layer.c index a1ead402c8e..6bcf3d935dc 100644 --- a/tmk_core/common/action_layer.c +++ b/tmk_core/common/action_layer.c @@ -223,9 +223,9 @@ void layer_debug(void) uint8_t source_layers_cache[(MATRIX_ROWS * MATRIX_COLS * MAX_LAYER_BITS + 7) / 8] = {0}; static const uint8_t layer_cache_mask = (1u << MAX_LAYER_BITS) - 1; -void update_source_layers_cache(keypos_t key, uint8_t layer) +void update_source_layers_cache(keymatrix_t key, uint8_t layer) { - const uint16_t key_number = key.col + (key.row * MATRIX_COLS); + const uint16_t key_number = key.pos.col + (key.pos.row * MATRIX_COLS); const uint32_t bit_number = key_number * MAX_LAYER_BITS; const uint16_t byte_number = bit_number / 8; if (byte_number >= sizeof(source_layers_cache)) { @@ -261,9 +261,9 @@ void update_source_layers_cache(keypos_t key, uint8_t layer) } } -uint8_t read_source_layers_cache(keypos_t key) +uint8_t read_source_layers_cache(keymatrix_t key) { - const uint16_t key_number = key.col + (key.row * MATRIX_COLS); + const uint16_t key_number = key.pos.col + (key.pos.row * MATRIX_COLS); const uint32_t bit_number = key_number * MAX_LAYER_BITS; const uint16_t byte_number = bit_number / 8; if (byte_number >= sizeof(source_layers_cache)) { @@ -296,7 +296,7 @@ uint8_t read_source_layers_cache(keypos_t key) * when the layer is switched after the down event but before the up * event as they may get stuck otherwise. */ -action_t store_or_get_action(bool pressed, keypos_t key) +action_t store_or_get_action(bool pressed, keymatrix_t key) { #if !defined(NO_ACTION_LAYER) && defined(PREVENT_STUCK_MODIFIERS) if (disable_action_cache) { @@ -323,7 +323,7 @@ action_t store_or_get_action(bool pressed, keypos_t key) * * FIXME: Needs docs */ -int8_t layer_switch_get_layer(keypos_t key) +int8_t layer_switch_get_layer(keymatrix_t key) { #ifndef NO_ACTION_LAYER action_t action; @@ -350,7 +350,7 @@ int8_t layer_switch_get_layer(keypos_t key) * * FIXME: Needs docs */ -action_t layer_switch_get_action(keypos_t key) +action_t layer_switch_get_action(keymatrix_t key) { return action_for_key(layer_switch_get_layer(key), key); } diff --git a/tmk_core/common/action_layer.h b/tmk_core/common/action_layer.h index 72a6bd8f684..8f47fb0c962 100644 --- a/tmk_core/common/action_layer.h +++ b/tmk_core/common/action_layer.h @@ -91,15 +91,15 @@ uint32_t layer_state_set_kb(uint32_t state); #if !defined(NO_ACTION_LAYER) && defined(PREVENT_STUCK_MODIFIERS) /* The number of bits needed to represent the layer number: log2(32). */ #define MAX_LAYER_BITS 5 -void update_source_layers_cache(keypos_t key, uint8_t layer); -uint8_t read_source_layers_cache(keypos_t key); +void update_source_layers_cache(keymatrix_t key, uint8_t layer); +uint8_t read_source_layers_cache(keymatrix_t key); #endif -action_t store_or_get_action(bool pressed, keypos_t key); +action_t store_or_get_action(bool pressed, keymatrix_t key); /* return the topmost non-transparent layer currently associated with key */ -int8_t layer_switch_get_layer(keypos_t key); +int8_t layer_switch_get_layer(keymatrix_t key); /* return action depending on current layer status */ -action_t layer_switch_get_action(keypos_t key); +action_t layer_switch_get_action(keymatrix_t key); #endif diff --git a/tmk_core/common/bootmagic.c b/tmk_core/common/bootmagic.c index 9f79fb8eedb..828769c3224 100644 --- a/tmk_core/common/bootmagic.c +++ b/tmk_core/common/bootmagic.c @@ -116,7 +116,7 @@ static bool scan_keycode(uint8_t keycode) matrix_row_t matrix_row = matrix_get_row(r); for (uint8_t c = 0; c < MATRIX_COLS; c++) { if (matrix_row & ((matrix_row_t)1<