Merge branch 'master' of ssh://github.com/keyboardio/KeyboardioFirmware

pull/45/head
Jesse Vincent 8 years ago
commit 2c6dc72da3

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

@ -1,15 +1,23 @@
// -*- mode: c++ -*-
// Copyright 2016 Keyboardio, inc. <jesse@keyboard.io> // Copyright 2016 Keyboardio, inc. <jesse@keyboard.io>
// See "LICENSE" for license details // See "LICENSE" for license details
#define DEBUG_SERIAL false #define DEBUG_SERIAL false
#include "KeyboardioFirmware.h" #include "KeyboardioFirmware.h"
#include "generated/keymaps.h"
uint8_t primary_keymap = 0; uint8_t primary_keymap = 0;
uint8_t temporary_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() { void setup() {
Keyboardio.setup(); Keyboardio.setup(KEYMAPS, NUMPAD_KEYMAP);
} }

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

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

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

@ -117,12 +117,12 @@ void Model01::act_on_matrix_scan() {
uint8_t keynum = (row*8)+(col); uint8_t keynum = (row*8)+(col);
handle_key_event(row, 7-col, handle_key_event(Key_NoKey, row, 7-col,
bitRead(leftHandState.all, keynum), bitRead(leftHandState.all, keynum),
bitRead(previousLeftHandState.all, keynum) bitRead(previousLeftHandState.all, keynum)
); );
handle_key_event(row, (15- col), handle_key_event(Key_NoKey, row, (15- col),
bitRead(rightHandState.all, keynum), bitRead(rightHandState.all, keynum),
bitRead(previousRightHandState.all, keynum) bitRead(previousRightHandState.all, keynum)
); );

@ -48,7 +48,7 @@ class Model01 {
}; };
#define SCANBIT(row,col) (1 << (row * 8 + (7 - col))) #define SCANBIT(row,col) ((uint32_t)1 << (row * 8 + (7 - col)))
#define R0C0 SCANBIT(0, 0) #define R0C0 SCANBIT(0, 0)
#define R0C1 SCANBIT(0, 1) #define R0C1 SCANBIT(0, 1)

@ -61,7 +61,7 @@ void TestMode_::TestMatrix () {
void TestMode_::setup() { void TestMode_::setup() {
eventHandlers[0] = handle_key_event_test; eventHandlers[0] = handle_key_event_test;
} }
bool handle_key_event_test(byte row, byte col, uint8_t currentState, uint8_t previousState) { bool handle_key_event_test(Key mappedKey, byte row, byte col, uint8_t currentState, uint8_t previousState) {
Serial.write(row); Serial.write(row);
} }

@ -15,4 +15,4 @@ class TestMode_ {
extern TestMode_ TestMode; extern TestMode_ TestMode;
bool handle_key_event_test(byte row, byte col, uint8_t currentState, uint8_t previousState); bool handle_key_event_test(Key mappedKey, byte row, byte col, uint8_t currentState, uint8_t previousState);

@ -1,10 +1,11 @@
#pragma once #pragma once
#include <Arduino.h> #include <Arduino.h>
#include "key_defs.h"
#define HOOK_MAX 64 #define HOOK_MAX 64
typedef bool (*custom_handler_t)(byte row, byte col, uint8_t currentState, uint8_t previousState); typedef bool (*custom_handler_t)(Key mappedKey, byte row, byte col, uint8_t currentState, uint8_t previousState);
extern custom_handler_t eventHandlers[HOOK_MAX]; extern custom_handler_t eventHandlers[HOOK_MAX];
void event_handler_hook_add (custom_handler_t hook); void event_handler_hook_add (custom_handler_t hook);

@ -1,7 +1,5 @@
#include "key_events.h" #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) { void handle_synthetic_key_event(Key mappedKey, uint8_t currentState, uint8_t previousState) {
if (mappedKey.flags & IS_MOUSE_KEY && !( mappedKey.rawKey & KEY_MOUSE_WARP) ) { if (mappedKey.flags & IS_MOUSE_KEY && !( mappedKey.rawKey & KEY_MOUSE_WARP) ) {
handle_mouse_key_event(mappedKey, currentState, previousState); handle_mouse_key_event(mappedKey, currentState, previousState);
@ -51,19 +49,21 @@ Key lookup_key(byte keymap, byte row, byte col) {
return mappedKey; return mappedKey;
} }
void handle_key_event(byte row, byte col, uint8_t currentState, uint8_t previousState) { void handle_key_event(Key mappedKey, byte row, byte col, uint8_t currentState, uint8_t previousState) {
for (byte i = 0; eventHandlers[i] != NULL && i < HOOK_MAX; i++) { for (byte i = 0; eventHandlers[i] != NULL && i < HOOK_MAX; i++) {
custom_handler_t handler = eventHandlers[i]; custom_handler_t handler = eventHandlers[i];
if ((*handler)(row, col, currentState, previousState)) if ((*handler)(mappedKey, row, col, currentState, previousState))
return; return;
} }
} }
bool handle_key_event_default(byte row, byte col, uint8_t currentState, uint8_t previousState) { bool handle_key_event_default(Key mappedKey, byte row, byte col, uint8_t currentState, uint8_t previousState) {
//for every newly pressed button, figure out what logical key it is and send a key down event //for every newly pressed button, figure out what logical key it is and send a key down event
// for every newly released button, figure out what logical key it is and send a key up event // for every newly released button, figure out what logical key it is and send a key up event
Key mappedKey = lookup_key(temporary_keymap, row, col); if (mappedKey.raw == Key_NoKey.raw) {
mappedKey = lookup_key(temporary_keymap, row, col);
}
Key baseKey = lookup_key(primary_keymap, row, col); Key baseKey = lookup_key(primary_keymap, row, col);
if ((baseKey.flags & SWITCH_TO_KEYMAP if ((baseKey.flags & SWITCH_TO_KEYMAP

@ -7,19 +7,47 @@
#include "LEDControl.h" #include "LEDControl.h"
#include "Storage.h" #include "Storage.h"
#include "keymap_metadata.h" #include "keymap_metadata.h"
#include "generated/keymaps.h"
#include "hooks.h" #include "hooks.h"
//static const Key keymaps[KEYMAPS][ROWS][COLS]; //static const Key keymaps[KEYMAPS][ROWS][COLS];
extern uint8_t primary_keymap; extern uint8_t primary_keymap;
extern uint8_t temporary_keymap; extern uint8_t temporary_keymap;
extern const Key keymaps[][ROWS][COLS];
// sending events to the computer // sending events to the computer
/* The event handling starts with the Scanner calling handle_key_event() for
* every key in the matrix, and it is the task of this method to figure out what
* to do, it is the main entry point.
*
* This function will iterate through an array of handler functions, and stop as
* soon as one of them signals that the event has been handled. To make it
* possible to inject synthetic events, one can call handle_key_event from
* within a custom handler (making the event handling recursive), with a
* different keycode.
*
* This is useful for example for one-shot modifiers, where we would like to
* temporarily disable the one-shot functionality, and have them work as a
* normal modifier instead. In this case, the keymap would contain a key with
* OSM flags set, and the event handler would remove the OSM flags, and let the
* system handle the key as it would have, without the OSM flags. So we simply
* clear the flags, and call handle_key_event again, with the modifier keycode
* as the first argument. This way, we could insert an event, and have the whole
* chain re-process it, instead of registering the keycode ourselves with HID
* ourselves. Injecting allows any and all custom handlers to have a chance,
* too.
*
* For this reason, the handle_key_event receives four arguments: the mapped key
* (or Key_NoKey if we do not want to override what is in the keymap), the row
* and column of the key, so we can look up the code for it, and the current and
* previous state of the key, so we can determine what the event is.
*/
void handle_key_event(Key mappedKey, byte row, byte col, uint8_t currentState, uint8_t previousState);
// Internal use
void handle_synthetic_key_event( Key mappedKey, uint8_t currentState, uint8_t previousState); void handle_synthetic_key_event( Key mappedKey, uint8_t currentState, uint8_t previousState);
void handle_key_event(byte row, byte col, uint8_t currentState, uint8_t previousState);
void press_key(Key mappedKey); void press_key(Key mappedKey);
void handle_keymap_key_event(Key keymapEntry, uint8_t currentState, uint8_t previousState); void handle_keymap_key_event(Key keymapEntry, uint8_t currentState, uint8_t previousState);
void handle_mouse_key_event(Key mappedKey, uint8_t currentState, uint8_t previousState); void handle_mouse_key_event(Key mappedKey, uint8_t currentState, uint8_t previousState);
bool handle_key_event_default(byte row, byte col, uint8_t currentState, uint8_t previousState); bool handle_key_event_default(Key mappedKey, byte row, byte col, uint8_t currentState, uint8_t previousState);
Key lookup_key(byte keymap, byte row, byte col); Key lookup_key(byte keymap, byte row, byte col);

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

Loading…
Cancel
Save