mirror of
https://github.com/qmk/qmk_firmware.git
synced 2025-07-10 18:01:33 +00:00
Enable dynamic keymap
This commit is contained in:
parent
5dc171218c
commit
00c9ef9216
@ -36,4 +36,28 @@
|
|||||||
/* Locking resynchronize hack */
|
/* Locking resynchronize hack */
|
||||||
#define LOCKING_RESYNC_ENABLE
|
#define LOCKING_RESYNC_ENABLE
|
||||||
|
|
||||||
|
// Dynamic keyboard support {
|
||||||
|
#define DYNAMIC_KEYMAP_LAYER_COUNT 4
|
||||||
|
|
||||||
|
// EEPROM usage
|
||||||
|
#define EEPROM_SIZE 1024
|
||||||
|
|
||||||
|
// TODO: refactor with new user EEPROM code (coming soon)
|
||||||
|
#define EEPROM_MAGIC 0x76EC
|
||||||
|
#define EEPROM_MAGIC_ADDR 64
|
||||||
|
// Bump this every time we change what we store
|
||||||
|
// This will automatically reset the EEPROM with defaults
|
||||||
|
// and avoid loading invalid data from the EEPROM
|
||||||
|
#define EEPROM_VERSION 0x01
|
||||||
|
#define EEPROM_VERSION_ADDR (EEPROM_MAGIC_ADDR + 2)
|
||||||
|
|
||||||
|
// Dynamic keymap starts after EEPROM version
|
||||||
|
#define DYNAMIC_KEYMAP_EEPROM_ADDR (EEPROM_VERSION_ADDR + 1)
|
||||||
|
#define DYNAMIC_KEYMAP_EEPROM_SIZE (DYNAMIC_KEYMAP_LAYER_COUNT * MATRIX_ROWS * MATRIX_COLS * 2)
|
||||||
|
// Dynamic macro starts after dynamic keymaps
|
||||||
|
#define DYNAMIC_KEYMAP_MACRO_EEPROM_ADDR (DYNAMIC_KEYMAP_EEPROM_ADDR + DYNAMIC_KEYMAP_EEPROM_SIZE)
|
||||||
|
#define DYNAMIC_KEYMAP_MACRO_EEPROM_SIZE (EEPROM_SIZE - DYNAMIC_KEYMAP_MACRO_EEPROM_ADDR)
|
||||||
|
#define DYNAMIC_KEYMAP_MACRO_COUNT 16
|
||||||
|
// } Dynamic keyboard support
|
||||||
|
|
||||||
#endif // CONFIG_H
|
#endif // CONFIG_H
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
#include QMK_KEYBOARD_H
|
#include QMK_KEYBOARD_H
|
||||||
|
|
||||||
const uint16_t PROGMEM keymaps[MATRIX_LAYERS][MATRIX_ROWS][MATRIX_COLS] = {
|
const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
|
||||||
[0] = LAYOUT(
|
[0] = LAYOUT(
|
||||||
RGB_TOG, RGB_RMOD, RGB_MOD, RGB_HUD, RGB_HUI, RGB_SAD, RGB_SAI, RGB_VAD, RGB_VAI, RGB_M_P, RESET,
|
RGB_TOG, RGB_RMOD, RGB_MOD, RGB_HUD, RGB_HUI, RGB_SAD, RGB_SAI, RGB_VAD, RGB_VAI, RGB_M_P, RESET,
|
||||||
KC_ESC, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0
|
KC_ESC, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0
|
||||||
|
@ -1,19 +1,33 @@
|
|||||||
#include "launch_test.h"
|
#include "dynamic_keymap.h"
|
||||||
#include "raw_hid.h"
|
#include "raw_hid.h"
|
||||||
|
#include "tmk_core/common/eeprom.h"
|
||||||
|
|
||||||
void keyboard_post_init_user(void) {
|
#include "launch_test.h"
|
||||||
// Customise these values to desired behaviour
|
|
||||||
debug_enable=true;
|
enum Command {
|
||||||
debug_matrix=true;
|
// Get keyboard map index
|
||||||
debug_keyboard=true;
|
CMD_KEYMAP_GET = 9,
|
||||||
//debug_mouse=true;
|
// Set keyboard map index
|
||||||
}
|
CMD_KEYMAP_SET = 10,
|
||||||
|
};
|
||||||
|
|
||||||
static bool keymap_get(uint8_t layer, uint8_t output, uint8_t input, uint16_t *value) {
|
static bool keymap_get(uint8_t layer, uint8_t output, uint8_t input, uint16_t *value) {
|
||||||
if (layer < MATRIX_LAYERS) {
|
if (layer < dynamic_keymap_get_layer_count()) {
|
||||||
if (output < MATRIX_ROWS) {
|
if (output < MATRIX_ROWS) {
|
||||||
if (input < MATRIX_COLS) {
|
if (input < MATRIX_COLS) {
|
||||||
*value = keymap_key_to_keycode(layer, (keypos_t){.row = output, .col = input});
|
*value = dynamic_keymap_get_keycode(layer, output, input);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool keymap_set(uint8_t layer, uint8_t output, uint8_t input, uint16_t value) {
|
||||||
|
if (layer < dynamic_keymap_get_layer_count()) {
|
||||||
|
if (output < MATRIX_ROWS) {
|
||||||
|
if (input < MATRIX_COLS) {
|
||||||
|
dynamic_keymap_set_keycode(layer, output, input, value);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -26,7 +40,7 @@ void raw_hid_receive(uint8_t *data, uint8_t length) {
|
|||||||
data[1] = 1;
|
data[1] = 1;
|
||||||
|
|
||||||
switch (data[0]) {
|
switch (data[0]) {
|
||||||
case 9: // KEYMAP_GET
|
case CMD_KEYMAP_GET:
|
||||||
{
|
{
|
||||||
uint16_t value = 0;
|
uint16_t value = 0;
|
||||||
if (keymap_get(data[2], data[3], data[4], &value)) {
|
if (keymap_get(data[2], data[3], data[4], &value)) {
|
||||||
@ -36,7 +50,34 @@ void raw_hid_receive(uint8_t *data, uint8_t length) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case CMD_KEYMAP_SET:
|
||||||
|
{
|
||||||
|
uint16_t value =
|
||||||
|
((uint16_t)data[5]) |
|
||||||
|
(((uint16_t)data[6]) << 8);
|
||||||
|
if (keymap_set(data[2], data[3], data[4], value)) {
|
||||||
|
data[1] = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
raw_hid_send(data, length);
|
raw_hid_send(data, length);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool eeprom_is_valid(void) {
|
||||||
|
return (eeprom_read_word(((void*)EEPROM_MAGIC_ADDR)) == EEPROM_MAGIC &&
|
||||||
|
eeprom_read_byte(((void*)EEPROM_VERSION_ADDR)) == EEPROM_VERSION);
|
||||||
|
}
|
||||||
|
|
||||||
|
void eeprom_set_valid(bool valid) {
|
||||||
|
eeprom_update_word(((void*)EEPROM_MAGIC_ADDR), valid ? EEPROM_MAGIC : 0xFFFF);
|
||||||
|
eeprom_update_byte(((void*)EEPROM_VERSION_ADDR), valid ? EEPROM_VERSION : 0xFF);
|
||||||
|
}
|
||||||
|
|
||||||
|
void matrix_init_kb(void) {
|
||||||
|
if (!eeprom_is_valid()) {
|
||||||
|
dynamic_keymap_reset();
|
||||||
|
dynamic_keymap_macro_reset();
|
||||||
|
eeprom_set_valid(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -3,9 +3,6 @@
|
|||||||
|
|
||||||
#include "quantum.h"
|
#include "quantum.h"
|
||||||
|
|
||||||
//TODO: determine this automatically
|
|
||||||
#define MATRIX_LAYERS 1
|
|
||||||
|
|
||||||
#define ___ KC_NO
|
#define ___ KC_NO
|
||||||
|
|
||||||
#define LAYOUT( \
|
#define LAYOUT( \
|
||||||
|
@ -22,6 +22,7 @@ MOUSEKEY_ENABLE = no # Mouse keys(+4700)
|
|||||||
EXTRAKEY_ENABLE = no # Audio control and System control(+450)
|
EXTRAKEY_ENABLE = no # Audio control and System control(+450)
|
||||||
CONSOLE_ENABLE = no # Console for debug(+400)
|
CONSOLE_ENABLE = no # Console for debug(+400)
|
||||||
COMMAND_ENABLE = no # Commands for debug and configuration
|
COMMAND_ENABLE = no # Commands for debug and configuration
|
||||||
|
DYNAMIC_KEYMAP_ENABLE = yes # Reconfigurable keyboard without flashing firmware
|
||||||
NKRO_ENABLE = yes # USB Nkey Rollover - if this doesn't work, see here: https://github.com/tmk/tmk_keyboard/wiki/FAQ#nkro-doesnt-work
|
NKRO_ENABLE = yes # USB Nkey Rollover - if this doesn't work, see here: https://github.com/tmk/tmk_keyboard/wiki/FAQ#nkro-doesnt-work
|
||||||
RAW_ENABLE = yes # Enable RAW HID commands (used by keyboard configurator)
|
RAW_ENABLE = yes # Enable RAW HID commands (used by keyboard configurator)
|
||||||
RGBLIGHT_ENABLE = yes
|
RGBLIGHT_ENABLE = yes # Support for RGB backlight
|
||||||
|
Loading…
Reference in New Issue
Block a user