From cbbb45c13f3de5ec28f62b6cd4a8b77143026500 Mon Sep 17 00:00:00 2001 From: Nick Brassel Date: Fri, 30 Sep 2022 03:25:55 +1000 Subject: Start moving towards introspection-based data retrieval (#18441) --- quantum/dynamic_keymap.c | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) (limited to 'quantum/dynamic_keymap.c') diff --git a/quantum/dynamic_keymap.c b/quantum/dynamic_keymap.c index 01be9806e4..e9529ed14e 100644 --- a/quantum/dynamic_keymap.c +++ b/quantum/dynamic_keymap.c @@ -153,7 +153,7 @@ void dynamic_keymap_reset(void) { for (int row = 0; row < MATRIX_ROWS; row++) { for (int column = 0; column < MATRIX_COLS; column++) { if (layer < keymap_layer_count()) { - dynamic_keymap_set_keycode(layer, row, column, pgm_read_word(&keymaps[layer][row][column])); + dynamic_keymap_set_keycode(layer, row, column, keycode_at_keymap_location_raw(layer, row, column)); } else { dynamic_keymap_set_keycode(layer, row, column, KC_TRANSPARENT); } @@ -162,8 +162,8 @@ void dynamic_keymap_reset(void) { #ifdef ENCODER_MAP_ENABLE for (int encoder = 0; encoder < NUM_ENCODERS; encoder++) { if (layer < encodermap_layer_count()) { - dynamic_keymap_set_encoder(layer, encoder, true, pgm_read_word(&encoder_map[layer][encoder][0])); - dynamic_keymap_set_encoder(layer, encoder, false, pgm_read_word(&encoder_map[layer][encoder][1])); + dynamic_keymap_set_encoder(layer, encoder, true, keycode_at_encodermap_location_raw(layer, encoder, true)); + dynamic_keymap_set_encoder(layer, encoder, false, keycode_at_encodermap_location_raw(layer, encoder, false)); } else { dynamic_keymap_set_encoder(layer, encoder, true, KC_TRANSPARENT); dynamic_keymap_set_encoder(layer, encoder, false, KC_TRANSPARENT); @@ -201,20 +201,21 @@ void dynamic_keymap_set_buffer(uint16_t offset, uint16_t size, uint8_t *data) { } } -// This overrides the one in quantum/keymap_common.c -uint16_t keymap_key_to_keycode(uint8_t layer, keypos_t key) { - if (layer < DYNAMIC_KEYMAP_LAYER_COUNT && key.row < MATRIX_ROWS && key.col < MATRIX_COLS) { - return dynamic_keymap_get_keycode(layer, key.row, key.col); +uint16_t keycode_at_keymap_location(uint8_t layer_num, uint8_t row, uint8_t column) { + if (layer_num < DYNAMIC_KEYMAP_LAYER_COUNT && row < MATRIX_ROWS && column < MATRIX_COLS) { + return dynamic_keymap_get_keycode(layer_num, row, column); } + return KC_NO; +} + #ifdef ENCODER_MAP_ENABLE - else if (layer < DYNAMIC_KEYMAP_LAYER_COUNT && key.row == KEYLOC_ENCODER_CW && key.col < NUM_ENCODERS) { - return dynamic_keymap_get_encoder(layer, key.col, true); - } else if (layer < DYNAMIC_KEYMAP_LAYER_COUNT && key.row == KEYLOC_ENCODER_CCW && key.col < NUM_ENCODERS) { - return dynamic_keymap_get_encoder(layer, key.col, false); +uint16_t keycode_at_encodermap_location(uint8_t layer_num, uint8_t encoder_idx, bool clockwise) { + if (layer_num < DYNAMIC_KEYMAP_LAYER_COUNT && encoder_idx < NUM_ENCODERS) { + return dynamic_keymap_get_encoder(layer_num, encoder_idx, clockwise); } -#endif // ENCODER_MAP_ENABLE return KC_NO; } +#endif // ENCODER_MAP_ENABLE uint8_t dynamic_keymap_macro_get_count(void) { return DYNAMIC_KEYMAP_MACRO_COUNT; -- cgit v1.2.3 From 91b1e8a3e563addc1492cabc78466c8142edcf91 Mon Sep 17 00:00:00 2001 From: Nick Brassel Date: Thu, 27 Oct 2022 18:29:26 +1100 Subject: Allow overriding of dynamic keymap start address. (#18867) --- quantum/dynamic_keymap.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'quantum/dynamic_keymap.c') diff --git a/quantum/dynamic_keymap.c b/quantum/dynamic_keymap.c index e9529ed14e..d800bbab84 100644 --- a/quantum/dynamic_keymap.c +++ b/quantum/dynamic_keymap.c @@ -24,7 +24,9 @@ # include "via.h" // for VIA_EEPROM_CONFIG_END # define DYNAMIC_KEYMAP_EEPROM_START (VIA_EEPROM_CONFIG_END) #else -# define DYNAMIC_KEYMAP_EEPROM_START (EECONFIG_SIZE) +# ifndef DYNAMIC_KEYMAP_EEPROM_START +# define DYNAMIC_KEYMAP_EEPROM_START (EECONFIG_SIZE) +# endif #endif #ifdef ENCODER_ENABLE -- cgit v1.2.3 From f82e90bdeaab1b2ec5c96716731f0a4c63193de9 Mon Sep 17 00:00:00 2001 From: Nick Brassel Date: Sat, 5 Nov 2022 06:20:11 +1100 Subject: Formalise keyboard- and user-specific EEPROM blocks (#18874) * Formalise keyboard and user eeconfig datablocks. * Add debounce helper that checks a condition and issues post-write function invocation. * Naming. --- quantum/dynamic_keymap.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'quantum/dynamic_keymap.c') diff --git a/quantum/dynamic_keymap.c b/quantum/dynamic_keymap.c index d800bbab84..e9529ed14e 100644 --- a/quantum/dynamic_keymap.c +++ b/quantum/dynamic_keymap.c @@ -24,9 +24,7 @@ # include "via.h" // for VIA_EEPROM_CONFIG_END # define DYNAMIC_KEYMAP_EEPROM_START (VIA_EEPROM_CONFIG_END) #else -# ifndef DYNAMIC_KEYMAP_EEPROM_START -# define DYNAMIC_KEYMAP_EEPROM_START (EECONFIG_SIZE) -# endif +# define DYNAMIC_KEYMAP_EEPROM_START (EECONFIG_SIZE) #endif #ifdef ENCODER_ENABLE -- cgit v1.2.3 From bc6f8dc8b0822e5e03893eacffa42a7badb4c2fa Mon Sep 17 00:00:00 2001 From: Wilba Date: Thu, 10 Nov 2022 07:46:44 +1100 Subject: VIA V3 - The Custom UI Update (#18222) --- quantum/dynamic_keymap.c | 56 ++++++++++++++++++++++++++++++++++++------------ 1 file changed, 42 insertions(+), 14 deletions(-) (limited to 'quantum/dynamic_keymap.c') diff --git a/quantum/dynamic_keymap.c b/quantum/dynamic_keymap.c index e9529ed14e..c406be4585 100644 --- a/quantum/dynamic_keymap.c +++ b/quantum/dynamic_keymap.c @@ -279,9 +279,8 @@ void dynamic_keymap_macro_send(uint8_t id) { p = (void *)(DYNAMIC_KEYMAP_MACRO_EEPROM_ADDR); void *end = (void *)(DYNAMIC_KEYMAP_MACRO_EEPROM_ADDR + DYNAMIC_KEYMAP_MACRO_EEPROM_SIZE); while (id > 0) { - // If we are past the end of the buffer, then the buffer - // contents are garbage, i.e. there were not DYNAMIC_KEYMAP_MACRO_COUNT - // nulls in the buffer. + // If we are past the end of the buffer, then there is + // no Nth macro in the buffer. if (p == end) { return; } @@ -291,9 +290,8 @@ void dynamic_keymap_macro_send(uint8_t id) { ++p; } - // Send the macro string one or three chars at a time - // by making temporary 1 or 3 char strings - char data[4] = {0, 0, 0, 0}; + // Send the macro string by making a temporary string. + char data[8] = {0}; // We already checked there was a null at the end of // the buffer, so this cannot go past the end while (1) { @@ -303,14 +301,44 @@ void dynamic_keymap_macro_send(uint8_t id) { if (data[0] == 0) { break; } - // If the char is magic (tap, down, up), - // add the next char (key to use) and send a 3 char string. - if (data[0] == SS_TAP_CODE || data[0] == SS_DOWN_CODE || data[0] == SS_UP_CODE) { - data[1] = data[0]; - data[0] = SS_QMK_PREFIX; - data[2] = eeprom_read_byte(p++); - if (data[2] == 0) { - break; + if (data[0] == SS_QMK_PREFIX) { + // Get the code + data[1] = eeprom_read_byte(p++); + // Unexpected null, abort. + if (data[1] == 0) { + return; + } + if (data[1] == SS_TAP_CODE || data[1] == SS_DOWN_CODE || data[1] == SS_UP_CODE) { + // Get the keycode + data[2] = eeprom_read_byte(p++); + // Unexpected null, abort. + if (data[2] == 0) { + return; + } + // Null terminate + data[3] = 0; + } else if (data[1] == SS_DELAY_CODE) { + // Get the number and '|' + // At most this is 4 digits plus '|' + uint8_t i = 2; + while (1) { + data[i] = eeprom_read_byte(p++); + // Unexpected null, abort + if (data[i] == 0) { + return; + } + // Found '|', send it + if (data[i] == '|') { + data[i + 1] = 0; + break; + } + // If haven't found '|' by i==6 then + // number too big, abort + if (i == 6) { + return; + } + ++i; + } } } send_string_with_delay(data, DYNAMIC_KEYMAP_MACRO_DELAY); -- cgit v1.2.3