Add keymap cache to speedup keycode responding
This commit is contained in:
parent
27238c9023
commit
1605365a5a
@ -14,17 +14,34 @@ GNU General Public License for more details.
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
//#include <stdbool.h>
|
||||
#include <avr/pgmspace.h>
|
||||
#include "keymap.h"
|
||||
#include "keymap_in_eeprom.h"
|
||||
#include "keymap_common.h"
|
||||
|
||||
static uint8_t keymaps_cache[KEYMAPS_COUNT][MATRIX_ROWS][MATRIX_COLS];
|
||||
|
||||
void keymaps_cache_init(void)
|
||||
{
|
||||
for (uint8_t layer = 0; layer < KEYMAPS_COUNT; layer++) {
|
||||
for (uint8_t row = 0; row < MATRIX_ROWS; row++) {
|
||||
for (uint8_t col = 0; col < MATRIX_COLS; col++) {
|
||||
#ifndef KEYMAP_IN_EEPROM_ENABLE
|
||||
keymaps_cache[layer][row][col] = pgm_read_byte(&keymaps[layer][row][col]);
|
||||
#else
|
||||
keymaps_cache[layer][row][col] = eeconfig_read_keymap_key(layer, row, col);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* translates key to keycode */
|
||||
uint8_t keymap_key_to_keycode(uint8_t layer, key_t key)
|
||||
{
|
||||
#ifndef KEYMAP_IN_EEPROM_ENABLE
|
||||
return pgm_read_byte(&keymaps[(layer)][(key.row)][(key.col)]);
|
||||
#else
|
||||
return eeconfig_read_keymap_key(layer, key.row, key.col);
|
||||
#endif
|
||||
return keymaps_cache[layer][key.row][key.col];
|
||||
}
|
||||
|
||||
/* translates Fn keycode to action */
|
||||
|
@ -19,22 +19,12 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#define KEYMAP_COMMON_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include <avr/pgmspace.h>
|
||||
#include "keycode.h"
|
||||
#include "action.h"
|
||||
#include "action_macro.h"
|
||||
#include "report.h"
|
||||
#include "host.h"
|
||||
#include "print.h"
|
||||
#include "debug.h"
|
||||
#include "keymap.h"
|
||||
#include "keymap_in_eeprom.h"
|
||||
|
||||
|
||||
extern const uint8_t keymaps[][MATRIX_ROWS][MATRIX_COLS];
|
||||
extern const uint16_t fn_actions[];
|
||||
|
||||
void keymaps_cache_init(void);
|
||||
|
||||
/* TentaPad keymap definition macro
|
||||
*/
|
||||
#define KEYMAP( \
|
||||
|
@ -15,6 +15,11 @@ You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <avr/pgmspace.h>
|
||||
#include "keycode.h"
|
||||
#include "action_layer.h"
|
||||
#include "eeconfig.h"
|
||||
#include "backlight.h"
|
||||
#include "keymap_common.h"
|
||||
|
||||
enum function_id {
|
||||
@ -24,7 +29,7 @@ enum function_id {
|
||||
};
|
||||
|
||||
enum {
|
||||
CONFIG_LAYER = 31,
|
||||
CONFIG_LAYER = 8,
|
||||
};
|
||||
|
||||
// Default
|
||||
@ -89,6 +94,7 @@ void action_function(keyrecord_t *record, uint8_t id, uint8_t opt)
|
||||
if (record->event.pressed) {
|
||||
if (config_mode) {
|
||||
default_layer_set(1UL<<layer);
|
||||
eeconfig_write_default_layer(1UL<<layer);
|
||||
layer = (layer + 1) % 6;
|
||||
}
|
||||
}
|
||||
@ -97,7 +103,7 @@ void action_function(keyrecord_t *record, uint8_t id, uint8_t opt)
|
||||
if (record->event.pressed) {
|
||||
if (config_mode) {
|
||||
backlight_level(backlight);
|
||||
backlight = (backlight + 1) % BACKLIGHT_LEVEL;
|
||||
backlight = (backlight + 1) % (BACKLIGHT_LEVELS + 1);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
Reference in New Issue
Block a user