Significant speed improvement in key lookup code

Instead of storing the layer for each key, store the keycode, so that lookups
are considerably faster (one array lookup instead of two). This saves us almost
a full millisecond per scan cycle. Furthermore, inline `Layer_.lookup`, saving
us even more time.

Signed-off-by: Gergely Nagy <algernon@madhouse-project.org>
pull/159/head
Gergely Nagy 7 years ago
parent e3f1172244
commit f0c1c35e8f

@ -4,7 +4,7 @@ static uint8_t DefaultLayer;
static uint32_t LayerState;
uint8_t Layer_::highestLayer;
uint8_t Layer_::keyMap[ROWS][COLS];
Key Layer_::keyMap[ROWS][COLS];
Key(*Layer_::getKey)(uint8_t layer, byte row, byte col) = Layer.getKeyFromPROGMEM;
bool Layer_::repeat_first_press = false;
@ -89,19 +89,13 @@ Layer_::updateKeyCache(byte row, byte col) {
Key mappedKey = (*getKey)(layer, row, col);
if (mappedKey != Key_Transparent) {
keyMap[row][col] = layer;
keyMap[row][col] = mappedKey;
break;
}
}
}
}
Key Layer_::lookup(byte row, byte col) {
uint8_t layer = keyMap[row][col];
return (*getKey)(layer, row, col);
}
uint8_t Layer_::top(void) {
for (int8_t i = 31; i >= 0; i--) {
if (bitRead(LayerState, i))

@ -8,7 +8,9 @@ class Layer_ {
public:
Layer_(void);
static Key lookup(byte row, byte col);
static Key lookup(byte row, byte col) {
return keyMap[row][col];
};
static void on(uint8_t layer);
static void off(uint8_t layer);
static void move(uint8_t layer);
@ -36,7 +38,7 @@ class Layer_ {
private:
static uint8_t highestLayer;
static uint8_t keyMap[ROWS][COLS];
static Key keyMap[ROWS][COLS];
};
Key layer_getKey(uint8_t layer, uint8_t r, uint8_t c);

Loading…
Cancel
Save