Browse Source

A sample implementation of keymap-in-eeprom

keymap_in_eeprom
Kai Ryu 10 years ago
parent
commit
0f31162554

+ 1
- 0
doc/build.md View File

@@ -133,6 +133,7 @@ Optional. Note that ***comment out*** to disable them.
SLEEP_LED_ENABLE = yes # Breathing sleep LED during USB suspend
#NKRO_ENABLE = yes # USB Nkey Rollover - not yet supported in LUFA
#BACKLIGHT_ENABLE = yes # Enable keyboard backlight functionality
#KEYMAP_IN_EEPROM_ENABLE = yes # Read keymap from eeprom

### 3. Programmer
Optional. Set proper command for your controller, bootloader and programmer. This command can be used with `make program`. Not needed if you use `FLIP`, `dfu-programmer` or `Teensy Loader`.

+ 4
- 3
keyboard/gh60/Makefile View File

@@ -118,9 +118,10 @@ BOOTMAGIC_ENABLE = yes # Virtual DIP switch configuration(+1000)
MOUSEKEY_ENABLE = yes # Mouse keys(+4700)
EXTRAKEY_ENABLE = yes # Audio control and System control(+450)
CONSOLE_ENABLE = yes # Console for debug(+400)
COMMAND_ENABLE = yes # Commands for debug and configuration
#SLEEP_LED_ENABLE = yes # Breathing sleep LED during USB suspend
NKRO_ENABLE = yes # USB Nkey Rollover - not yet supported in LUFA
COMMAND_ENABLE = yes # Commands for debug and configuration
#SLEEP_LED_ENABLE = yes # Breathing sleep LED during USB suspend
NKRO_ENABLE = yes # USB Nkey Rollover
KEYMAP_IN_EEPROM_ENABLE = yes # Read keymap from eeprom


# Optimize size but this may cause error "relocation truncated to fit"

+ 4
- 15
keyboard/gh60/Makefile.pjrc View File

@@ -88,11 +88,12 @@ OPT_DEFS += -DBOOTLOADER_SIZE=4096
BOOTMAGIC_ENABLE = yes # Virtual DIP switch configuration(+1000)
MOUSEKEY_ENABLE = yes # Mouse keys(+5000)
EXTRAKEY_ENABLE = yes # Audio control and System control(+600)
CONSOLE_ENABLE = yes # Console for debug
COMMAND_ENABLE = yes # Commands for debug and configuration
SLEEP_LED_ENABLE = yes # Breathing sleep LED during USB suspend
CONSOLE_ENABLE = yes # Console for debug
COMMAND_ENABLE = yes # Commands for debug and configuration
#SLEEP_LED_ENABLE = yes # Breathing sleep LED during USB suspend
NKRO_ENABLE = yes # USB Nkey Rollover(+500)
#PS2_MOUSE_ENABLE = yes # PS/2 mouse(TrackPoint) support
KEYMAP_IN_EEPROM_ENABLE = yes # Read keymap from eeprom


# Search Path
@@ -102,15 +103,3 @@ VPATH += $(TOP_DIR)
include $(TOP_DIR)/protocol/pjrc.mk
include $(TOP_DIR)/common.mk
include $(TOP_DIR)/rules.mk

plain: OPT_DEFS += -DKEYMAP_PLAIN
plain: all

poker: OPT_DEFS += -DKEYMAP_POKER
poker: all

poker_set: OPT_DEFS += -DKEYMAP_POKER_SET
poker_set: all

poker_bit: OPT_DEFS += -DKEYMAP_POKER_BIT
poker_bit: all

+ 4
- 0
keyboard/gh60/config.h View File

@@ -31,6 +31,10 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#define MATRIX_ROWS 5
#define MATRIX_COLS 14

/* keymap in eeprom */
#define FN_ACTIONS_COUNT 32
#define KEYMAPS_COUNT 8

/* define if matrix has ghost */
//#define MATRIX_HAS_GHOST


+ 21
- 1
keyboard/gh60/keymap_common.c View File

@@ -20,11 +20,31 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
/* 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
}

/* translates Fn keycode to action */
action_t keymap_fn_to_action(uint8_t keycode)
{
return (action_t){ .code = pgm_read_word(&fn_actions[FN_INDEX(keycode)]) };
return (action_t) {
#ifndef KEYMAP_IN_EEPROM_ENABLE
.code = pgm_read_word(&fn_actions[FN_INDEX(keycode)])
#else
.code = eeconfig_read_keymap_fn_action(FN_INDEX(keycode))
#endif
};
}

#ifdef KEYMAP_IN_EEPROM_ENABLE
const uint8_t* keymaps_pointer(void) {
return (const uint8_t*)keymaps;
}

const uint16_t* fn_actions_pointer(void) {
return fn_actions;
}
#endif

+ 1
- 0
keyboard/gh60/keymap_common.h View File

@@ -28,6 +28,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "print.h"
#include "debug.h"
#include "keymap.h"
#include "keymap_in_eeprom.h"


extern const uint8_t keymaps[][MATRIX_ROWS][MATRIX_COLS];

+ 10
- 0
keyboard/gh60/keymap_poker.c View File

@@ -102,3 +102,13 @@ const uint16_t PROGMEM fn_actions[] = {
[7] = ACTION_DEFAULT_LAYER_SET(2), // set dvorak layout
[8] = ACTION_DEFAULT_LAYER_SET(3), // set workman layout
};

#ifdef KEYMAP_IN_EEPROM_ENABLE
uint16_t keys_count(void) {
return sizeof(keymaps) / sizeof(keymaps[0]) * MATRIX_ROWS * MATRIX_COLS;
}

uint16_t fn_actions_count(void) {
return sizeof(fn_actions) / sizeof(fn_actions[0]);
}
#endif