|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <Arduino.h>
|
|
|
|
|
|
|
|
#define HARDWARE_IMPLEMENTATION Model01
|
|
|
|
#include "Kaleidoscope-HIDAdaptor-KeyboardioHID.h"
|
|
|
|
#include "KeyboardioScanner.h"
|
|
|
|
|
|
|
|
#include "macro_helpers.h"
|
|
|
|
|
|
|
|
#define COLS 16
|
|
|
|
#define ROWS 4
|
|
|
|
|
|
|
|
#define CRGB(r,g,b) (cRGB){b, g, r}
|
|
|
|
|
|
|
|
class Model01 {
|
|
|
|
public:
|
|
|
|
Model01(void);
|
|
|
|
void syncLeds(void);
|
|
|
|
void setCrgbAt(byte row, byte col, cRGB color);
|
|
|
|
void setCrgbAt(uint8_t i, cRGB crgb);
|
|
|
|
cRGB getCrgbAt(uint8_t i);
|
|
|
|
uint8_t getLedIndex(byte row, byte col);
|
|
|
|
|
|
|
|
void scanMatrix(void);
|
|
|
|
void readMatrix(void);
|
|
|
|
void actOnMatrixScan(void);
|
|
|
|
void setup();
|
|
|
|
void rebootBootloader();
|
|
|
|
|
|
|
|
|
|
|
|
/** Detaching from / attaching to the host.
|
|
|
|
*
|
|
|
|
* These two functions should detach the device from (or attach it to) the
|
|
|
|
* host, preferably without rebooting the device. Their purpose is to allow
|
|
|
|
* one to do some configuration inbetween, so the re-attach happens with
|
|
|
|
* different properties. The device remains powered between these operations,
|
|
|
|
* only the connection to the host gets severed.
|
|
|
|
*/
|
|
|
|
void detachFromHost();
|
|
|
|
void attachToHost();
|
|
|
|
|
|
|
|
/* These public functions are things supported by the Model 01, but
|
|
|
|
* aren't necessarily part of the Kaleidoscope API
|
|
|
|
*/
|
|
|
|
void enableHighPowerLeds(void);
|
|
|
|
void enableScannerPower(void);
|
|
|
|
void setKeyscanInterval(uint8_t interval);
|
|
|
|
boolean ledPowerFault(void);
|
|
|
|
|
|
|
|
/* Key masking
|
|
|
|
* -----------
|
|
|
|
*
|
|
|
|
* There are situations when one wants to ignore key events for a while, and
|
|
|
|
* mask them out. These functions help do that. In isolation, they do nothing,
|
|
|
|
* plugins and the core firmware is expected to make use of these.
|
|
|
|
*
|
|
|
|
* See `handleKeyswitchEvent` in the Kaleidoscope sources for a use-case.
|
|
|
|
*/
|
|
|
|
void maskKey(byte row, byte col);
|
|
|
|
void unMaskKey(byte row, byte col);
|
|
|
|
bool isKeyMasked(byte row, byte col);
|
|
|
|
void maskHeldKeys(void);
|
|
|
|
|
|
|
|
/** Key switch state
|
|
|
|
*
|
|
|
|
* These two methods return the state of the keyswitch at any given position,
|
|
|
|
* regardless of which half they are on. This is a hardware-agnostic access to
|
|
|
|
* the key switch states.
|
|
|
|
*
|
|
|
|
* The first variant requires a row and a column, the second an index, as
|
|
|
|
* returned by `KEY_INDEX`.
|
|
|
|
*/
|
|
|
|
uint8_t getKeyswitchStateAtPosition(byte row, byte col);
|
|
|
|
uint8_t getKeyswitchStateAtPosition(uint8_t keyIndex);
|
|
|
|
|
|
|
|
keydata_t leftHandState;
|
|
|
|
keydata_t rightHandState;
|
|
|
|
keydata_t previousLeftHandState;
|
|
|
|
keydata_t previousRightHandState;
|
|
|
|
|
|
|
|
private:
|
actOnMatrixScan: Optimize the idle case
When there are no state changes, and no keys pressed on a row, instead of
iterating through a byte bit-by-bit, just fire idle events without checking the
bits. In all other cases, do the bit-walking like we did before.
The reason this is useful is because bit-walking is costly, and slow. If we can
avoid that, we win quite a lot of performance. Since rows being idle is the most
common case on a keyboard, this is a huge net win. Even in the worst case, where
no rows are idle, this is just one byte comparison and a branch slower than our
previous implementation.
As part of this optimization, `actOnHalfRow` was lifted out into its own
function, to reduce code duplication.
Many thanks to @gedankenexperimenter for the original idea!
Signed-off-by: Gergely Nagy <algernon@keyboard.io>
7 years ago
|
|
|
static void actOnHalfRow(byte row, byte colState, byte colPrevState, byte startPos);
|
|
|
|
|
|
|
|
static bool isLEDChanged;
|
|
|
|
static KeyboardioScanner leftHand;
|
|
|
|
static KeyboardioScanner rightHand;
|
|
|
|
|
|
|
|
static keydata_t leftHandMask;
|
|
|
|
static keydata_t rightHandMask;
|
|
|
|
};
|
|
|
|
|
|
|
|
#ifndef DOXYGEN_SHOULD_SKIP_THIS
|
|
|
|
|
|
|
|
#define R0C0 KEY_INDEX(0, 0)
|
|
|
|
#define R0C1 KEY_INDEX(0, 1)
|
|
|
|
#define R0C2 KEY_INDEX(0, 2)
|
|
|
|
#define R0C3 KEY_INDEX(0, 3)
|
|
|
|
#define R0C4 KEY_INDEX(0, 4)
|
|
|
|
#define R0C5 KEY_INDEX(0, 5)
|
|
|
|
#define R0C6 KEY_INDEX(0, 6)
|
|
|
|
#define R0C7 KEY_INDEX(0, 7)
|
|
|
|
#define R1C0 KEY_INDEX(1, 0)
|
|
|
|
#define R1C1 KEY_INDEX(1, 1)
|
|
|
|
#define R1C2 KEY_INDEX(1, 2)
|
|
|
|
#define R1C3 KEY_INDEX(1, 3)
|
|
|
|
#define R1C4 KEY_INDEX(1, 4)
|
|
|
|
#define R1C5 KEY_INDEX(1, 5)
|
|
|
|
#define R1C6 KEY_INDEX(1, 6)
|
|
|
|
#define R1C7 KEY_INDEX(1, 7)
|
|
|
|
#define R2C0 KEY_INDEX(2, 0)
|
|
|
|
#define R2C1 KEY_INDEX(2, 1)
|
|
|
|
#define R2C2 KEY_INDEX(2, 2)
|
|
|
|
#define R2C3 KEY_INDEX(2, 3)
|
|
|
|
#define R2C4 KEY_INDEX(2, 4)
|
|
|
|
#define R2C5 KEY_INDEX(2, 5)
|
|
|
|
#define R2C6 KEY_INDEX(2, 6)
|
|
|
|
#define R2C7 KEY_INDEX(2, 7)
|
|
|
|
#define R3C0 KEY_INDEX(3, 0)
|
|
|
|
#define R3C1 KEY_INDEX(3, 1)
|
|
|
|
#define R3C2 KEY_INDEX(3, 2)
|
|
|
|
#define R3C3 KEY_INDEX(3, 3)
|
|
|
|
#define R3C4 KEY_INDEX(3, 4)
|
|
|
|
#define R3C5 KEY_INDEX(3, 5)
|
|
|
|
#define R3C6 KEY_INDEX(3, 6)
|
|
|
|
#define R3C7 KEY_INDEX(3, 7)
|
|
|
|
|
|
|
|
#define R0C8 KEY_INDEX(0, 8)
|
|
|
|
#define R0C9 KEY_INDEX(0, 9)
|
|
|
|
#define R0C10 KEY_INDEX(0, 10)
|
|
|
|
#define R0C11 KEY_INDEX(0, 11)
|
|
|
|
#define R0C12 KEY_INDEX(0, 12)
|
|
|
|
#define R0C13 KEY_INDEX(0, 13)
|
|
|
|
#define R0C14 KEY_INDEX(0, 15)
|
|
|
|
#define R0C15 KEY_INDEX(0, 16)
|
|
|
|
#define R1C8 KEY_INDEX(1, 8)
|
|
|
|
#define R1C9 KEY_INDEX(1, 9)
|
|
|
|
#define R1C10 KEY_INDEX(1, 10)
|
|
|
|
#define R1C11 KEY_INDEX(1, 11)
|
|
|
|
#define R1C12 KEY_INDEX(1, 12)
|
|
|
|
#define R1C13 KEY_INDEX(1, 13)
|
|
|
|
#define R1C14 KEY_INDEX(1, 14)
|
|
|
|
#define R1C15 KEY_INDEX(1, 15)
|
|
|
|
#define R2C8 KEY_INDEX(2, 8)
|
|
|
|
#define R2C9 KEY_INDEX(2, 9)
|
|
|
|
#define R2C10 KEY_INDEX(2, 10)
|
|
|
|
#define R2C11 KEY_INDEX(2, 11)
|
|
|
|
#define R2C12 KEY_INDEX(2, 12)
|
|
|
|
#define R2C13 KEY_INDEX(2, 13)
|
|
|
|
#define R2C14 KEY_INDEX(2, 14)
|
|
|
|
#define R2C15 KEY_INDEX(2, 15)
|
|
|
|
#define R3C8 KEY_INDEX(3, 8)
|
|
|
|
#define R3C9 KEY_INDEX(3, 9)
|
|
|
|
#define R3C10 KEY_INDEX(3, 10)
|
|
|
|
#define R3C11 KEY_INDEX(3, 11)
|
|
|
|
#define R3C12 KEY_INDEX(3, 12)
|
|
|
|
#define R3C13 KEY_INDEX(3, 13)
|
|
|
|
#define R3C14 KEY_INDEX(3, 14)
|
|
|
|
#define R3C15 KEY_INDEX(3, 15)
|
|
|
|
|
|
|
|
|
|
|
|
#define LED_COUNT 64
|
|
|
|
|
|
|
|
|
|
|
|
#define LED_PGDN 0
|
|
|
|
#define LED_PGUP 1
|
|
|
|
#define LED_BACKTICK 2
|
|
|
|
#define LED_PROG 3
|
|
|
|
#define LED_1 4
|
|
|
|
#define LED_Q 5
|
|
|
|
#define LED_A 6
|
|
|
|
#define LED_Z 7
|
|
|
|
#define LED_X 8
|
|
|
|
#define LED_S 9
|
|
|
|
#define LED_W 10
|
|
|
|
#define LED_2 11
|
|
|
|
#define LED_3 12
|
|
|
|
#define LED_E 13
|
|
|
|
#define LED_D 14
|
|
|
|
#define LED_C 15
|
|
|
|
#define LED_V 16
|
|
|
|
#define LED_F 17
|
|
|
|
#define LED_R 18
|
|
|
|
#define LED_4 19
|
|
|
|
#define LED_5 20
|
|
|
|
#define LED_T 21
|
|
|
|
#define LED_G 22
|
|
|
|
#define LED_B 23
|
|
|
|
#define LED_ESC 24
|
|
|
|
#define LED_TAB 25
|
|
|
|
#define LED_LED 26
|
|
|
|
#define LED_L_CTRL 27
|
|
|
|
#define LED_BKSP 28
|
|
|
|
#define LED_CMD 29
|
|
|
|
#define LED_L_SHIFT 30
|
|
|
|
#define LED_L_FN 31
|
|
|
|
#define LED_R_FN 32
|
|
|
|
#define LED_R_SHIFT 33
|
|
|
|
#define LED_ALT 34
|
|
|
|
#define LED_SPACE 35
|
|
|
|
#define LED_R_CTRL 36
|
|
|
|
#define LED_ANY 37
|
|
|
|
#define LED_RETURN 38
|
|
|
|
#define LED_BUTTERFLY 39
|
|
|
|
#define LED_N 40
|
|
|
|
#define LED_H 41
|
|
|
|
#define LED_Y 42
|
|
|
|
#define LED_6 43
|
|
|
|
#define LED_7 44
|
|
|
|
#define LED_U 45
|
|
|
|
#define LED_J 46
|
|
|
|
#define LED_M 47
|
|
|
|
#define LED_COMMA 48
|
|
|
|
#define LED_K 49
|
|
|
|
#define LED_I 50
|
|
|
|
#define LED_8 51
|
|
|
|
#define LED_9 52
|
|
|
|
#define LED_O 53
|
|
|
|
#define LED_L 54
|
|
|
|
#define LED_PERIOD 55
|
|
|
|
#define LED_SLASH 56
|
|
|
|
#define LED_SEMICOLON 57
|
|
|
|
#define LED_P 58
|
|
|
|
#define LED_0 59
|
|
|
|
#define LED_NUM 60
|
|
|
|
#define LED_EQUALS 61
|
|
|
|
#define LED_APOSTROPHE 62
|
|
|
|
#define LED_MINUS 63
|
|
|
|
|
|
|
|
#endif /* DOXYGEN_SHOULD_SKIP_THIS */
|
|
|
|
|
|
|
|
|
|
|
|
#define KEYMAP_STACKED( \
|
|
|
|
r0c0, r0c1, r0c2, r0c3, r0c4, r0c5, r0c6, \
|
|
|
|
r1c0, r1c1, r1c2, r1c3, r1c4, r1c5, r1c6, \
|
|
|
|
r2c0, r2c1, r2c2, r2c3, r2c4, r2c5, \
|
|
|
|
r3c0, r3c1, r3c2, r3c3, r3c4, r3c5, r2c6, \
|
|
|
|
r0c7, r1c7, r2c7, r3c7, \
|
|
|
|
r3c6, \
|
|
|
|
\
|
|
|
|
r0c9, r0c10, r0c11, r0c12, r0c13, r0c14, r0c15, \
|
|
|
|
r1c9, r1c10, r1c11, r1c12, r1c13, r1c14, r1c15, \
|
|
|
|
r2c10, r2c11, r2c12, r2c13, r2c14, r2c15, \
|
|
|
|
r2c9, r3c10, r3c11, r3c12, r3c13, r3c14, r3c15, \
|
|
|
|
r3c8, r2c8, r1c8, r0c8, \
|
|
|
|
r3c9, ...) \
|
|
|
|
{ \
|
|
|
|
{r0c0, r0c1, r0c2, r0c3, r0c4, r0c5, r0c6, r0c7, r0c8, r0c9, r0c10, r0c11, r0c12, r0c13, r0c14, r0c15}, \
|
|
|
|
{r1c0, r1c1, r1c2, r1c3, r1c4, r1c5, r1c6, r1c7, r1c8, r1c9, r1c10, r1c11, r1c12, r1c13, r1c14, r1c15}, \
|
|
|
|
{r2c0, r2c1, r2c2, r2c3, r2c4, r2c5, r2c6, r2c7, r2c8, r2c9, r2c10, r2c11, r2c12, r2c13, r2c14, r2c15}, \
|
|
|
|
{r3c0, r3c1, r3c2, r3c3, r3c4, r3c5, r3c6, r3c7, r3c8, r3c9, r3c10, r3c11, r3c12, r3c13, r3c14, RESTRICT_ARGS_COUNT((r3c15), 64, KEYMAP_STACKED, ##__VA_ARGS__)}, \
|
|
|
|
}
|
|
|
|
|
|
|
|
#define KEYMAP( \
|
|
|
|
r0c0, r0c1, r0c2, r0c3, r0c4, r0c5, r0c6, r0c9, r0c10, r0c11, r0c12, r0c13, r0c14, r0c15, \
|
|
|
|
r1c0, r1c1, r1c2, r1c3, r1c4, r1c5, r1c6, r1c9, r1c10, r1c11, r1c12, r1c13, r1c14, r1c15, \
|
|
|
|
r2c0, r2c1, r2c2, r2c3, r2c4, r2c5, r2c10, r2c11, r2c12, r2c13, r2c14, r2c15, \
|
|
|
|
r3c0, r3c1, r3c2, r3c3, r3c4, r3c5, r2c6, r2c9, r3c10, r3c11, r3c12, r3c13, r3c14, r3c15, \
|
|
|
|
r0c7, r1c7, r2c7, r3c7, r3c8, r2c8, r1c8, r0c8, \
|
|
|
|
r3c6, r3c9, ...) \
|
|
|
|
{ \
|
|
|
|
{r0c0, r0c1, r0c2, r0c3, r0c4, r0c5, r0c6, r0c7, r0c8, r0c9, r0c10, r0c11, r0c12, r0c13, r0c14, r0c15}, \
|
|
|
|
{r1c0, r1c1, r1c2, r1c3, r1c4, r1c5, r1c6, r1c7, r1c8, r1c9, r1c10, r1c11, r1c12, r1c13, r1c14, r1c15}, \
|
|
|
|
{r2c0, r2c1, r2c2, r2c3, r2c4, r2c5, r2c6, r2c7, r2c8, r2c9, r2c10, r2c11, r2c12, r2c13, r2c14, r2c15}, \
|
|
|
|
{r3c0, r3c1, r3c2, r3c3, r3c4, r3c5, r3c6, r3c7, r3c8, r3c9, r3c10, r3c11, r3c12, r3c13, r3c14, RESTRICT_ARGS_COUNT((r3c15), 64, KEYMAP, ##__VA_ARGS__)}, \
|
|
|
|
}
|