Separate the keymap layout from the core firmware

This moves the layouts to the sketch directory, so that other sketches
can easily use a different keymap. In the process, not much had to be
changed, and a number of things still remain in the core that assume the
default keymap (such as the NUMPAD_KEYMAP thing in LEDControl.cpp), but
this is a first step.

The downside is that the keymap is no longer static, because that would
conflict with the extern declaration, and the NUMPAD_KEYMAP is a byte,
instead of a compile-time define.

Alltogether, the difference is small enough to be acceptable.

Signed-off-by: Gergely Nagy <algernon@madhouse-project.org>
pull/37/head
Gergely Nagy 8 years ago
parent f665f9acaf
commit 58f6b18076

@ -86,8 +86,8 @@ astyle:
find . -type f -name \*.h |xargs -n 1 astyle --style=google
generate-keymaps:
-rm src/generated/keymaps.h
cd layouts && ( find . -type f |xargs -n 1 -I % sh -c 'perl ../tools/generate_keymaps.pl < % >> ../src/generated/keymaps.h' )
-rm examples/KeyboardioFirmware/generated/keymaps.h
cd examples/KeyboardioFirmware/layouts && ( find . -type f | sort | xargs -n 1 -I % sh -c 'perl ../../../tools/generate_keymaps.pl < % >> ../generated/keymaps.h' )
dirs:
mkdir -p $(OUTPUT_PATH)

@ -1,15 +1,23 @@
// -*- mode: c++ -*-
// Copyright 2016 Keyboardio, inc. <jesse@keyboard.io>
// See "LICENSE" for license details
#define DEBUG_SERIAL false
#include "KeyboardioFirmware.h"
#include "generated/keymaps.h"
uint8_t primary_keymap = 0;
uint8_t temporary_keymap = 0;
#define KEYMAPS 3
#define NUMPAD_KEYMAP 2
#define KEYMAP_LIST KEYMAP_QWERTY KEYMAP_GENERIC_FN2 KEYMAP_NUMPAD
const Key keymaps[][ROWS][COLS] PROGMEM = { KEYMAP_LIST };
void setup() {
Keyboardio.setup();
Keyboardio.setup(KEYMAPS, NUMPAD_KEYMAP);
}

@ -1,10 +1,12 @@
#include "KeyboardioFirmware.h"
byte NUMPAD_KEYMAP = 0;
Keyboardio_::Keyboardio_(void) {
}
void
Keyboardio_::setup(void) {
Keyboardio_::setup(const byte keymap_count, const byte numpad_layer) {
event_handler_hook_add (handle_key_event_default);
wdt_disable();
delay(100);
@ -14,7 +16,8 @@ Keyboardio_::setup(void) {
KeyboardHardware.setup();
LEDControl.boot_animation();
temporary_keymap = primary_keymap = Storage.load_primary_keymap(KEYMAPS);
NUMPAD_KEYMAP = numpad_layer;
temporary_keymap = primary_keymap = Storage.load_primary_keymap(keymap_count);
}
custom_loop_t loopHooks[HOOK_MAX] = {NULL};

@ -22,7 +22,6 @@ void setup();
#include <avr/wdt.h>
#include "KeyboardConfig.h"
#include "generated/keymaps.h"
#include "key_events.h"
extern HARDWARE_IMPLEMENTATION KeyboardHardware;
@ -38,7 +37,7 @@ class Keyboardio_ {
public:
Keyboardio_(void);
void setup(void);
void setup(const byte keymap_count, const byte numpad_layer);
void loop(void);
};

@ -91,3 +91,5 @@ class LEDControl_ {
};
extern LEDControl_ LEDControl;
extern byte NUMPAD_KEYMAP;

@ -1,7 +1,5 @@
#include "key_events.h"
static const Key keymaps[KEYMAPS][ROWS][COLS] PROGMEM = { KEYMAP_LIST };
void handle_synthetic_key_event(Key mappedKey, uint8_t currentState, uint8_t previousState) {
if (mappedKey.flags & IS_MOUSE_KEY && !( mappedKey.rawKey & KEY_MOUSE_WARP) ) {
handle_mouse_key_event(mappedKey, currentState, previousState);

@ -7,12 +7,12 @@
#include "LEDControl.h"
#include "Storage.h"
#include "keymap_metadata.h"
#include "generated/keymaps.h"
#include "hooks.h"
//static const Key keymaps[KEYMAPS][ROWS][COLS];
extern uint8_t primary_keymap;
extern uint8_t temporary_keymap;
extern const Key keymaps[][ROWS][COLS];
// sending events to the computer
void handle_synthetic_key_event( Key mappedKey, uint8_t currentState, uint8_t previousState);

@ -2,6 +2,3 @@
#define COLS 16
#define ROWS 4
#define KEYMAPS 3
#define NUMPAD_KEYMAP 2
#define KEYMAP_LIST KEYMAP_QWERTY KEYMAP_GENERIC_FN2 KEYMAP_NUMPAD

Loading…
Cancel
Save