312 lines
11 KiB
C++
312 lines
11 KiB
C++
// -*- mode: c++ -*-
|
|
// Copyright 2016 Keyboardio, inc. <jesse@keyboard.io>
|
|
// See "LICENSE" for license details
|
|
|
|
#ifndef BUILD_INFORMATION
|
|
#define BUILD_INFORMATION "locally built on " __DATE__ " at " __TIME__
|
|
#endif
|
|
|
|
|
|
#include "Kaleidoscope.h"
|
|
#include "Kaleidoscope-EEPROM-Settings.h"
|
|
#include "Kaleidoscope-EEPROM-Keymap.h"
|
|
#include "Kaleidoscope-FocusSerial.h"
|
|
#include "Kaleidoscope-MouseKeys.h"
|
|
#include "Kaleidoscope-Macros.h"
|
|
#include "Kaleidoscope-LEDControl.h"
|
|
#include "Kaleidoscope-NumPad.h"
|
|
#include "Kaleidoscope-LEDEffect-BootGreeting.h"
|
|
#include "Kaleidoscope-LEDEffect-SolidColor.h"
|
|
#include "Kaleidoscope-LEDEffect-Breathe.h"
|
|
#include "Kaleidoscope-LEDEffect-Chase.h"
|
|
#include "Kaleidoscope-LEDEffect-Rainbow.h"
|
|
#include "Kaleidoscope-LED-Stalker.h"
|
|
#include "Kaleidoscope-LED-AlphaSquare.h"
|
|
#include "Kaleidoscope-LED-Palette-Theme.h"
|
|
#include "Kaleidoscope-Colormap.h"
|
|
#include "Kaleidoscope-HardwareTestMode.h"
|
|
#include "Kaleidoscope-HostPowerManagement.h"
|
|
#include "Kaleidoscope-MagicCombo.h"
|
|
#include "Kaleidoscope-USB-Quirks.h"
|
|
|
|
enum {
|
|
MACRO_VERSION_INFO,
|
|
MACRO_ANY,
|
|
};
|
|
|
|
|
|
/** The Model 100's key layouts are defined as 'keymaps'. By default, there are three
|
|
* keymaps: The standard QWERTY keymap, the "Function layer" keymap and the "Numpad"
|
|
* keymap.
|
|
*
|
|
* Each keymap is defined as a list using the 'KEYMAP_STACKED' macro, built
|
|
* of first the left hand's layout, followed by the right hand's layout.
|
|
*
|
|
* Keymaps typically consist mostly of `Key_` definitions. There are many, many keys
|
|
* defined as part of the USB HID Keyboard specification. You can find the names
|
|
* (if not yet the explanations) for all the standard `Key_` defintions offered by
|
|
* Kaleidoscope in these files:
|
|
* https://github.com/keyboardio/Kaleidoscope/blob/master/src/kaleidoscope/key_defs/keyboard.h
|
|
* https://github.com/keyboardio/Kaleidoscope/blob/master/src/kaleidoscope/key_defs/consumerctl.h
|
|
* https://github.com/keyboardio/Kaleidoscope/blob/master/src/kaleidoscope/key_defs/sysctl.h
|
|
* https://github.com/keyboardio/Kaleidoscope/blob/master/src/kaleidoscope/key_defs/keymaps.h
|
|
*
|
|
* Additional things that should be documented here include
|
|
* using ___ to let keypresses fall through to the previously active layer
|
|
* using XXX to mark a keyswitch as 'blocked' on this layer
|
|
* using ShiftToLayer() and LockLayer() keys to change the active keymap.
|
|
* keeping NUM and FN consistent and accessible on all layers
|
|
*
|
|
* A key defined as 'ShiftToLayer(FUNCTION)' will switch to FUNCTION while held.
|
|
* Similarly, a key defined as 'LockLayer(NUMPAD)' will switch to NUMPAD when tapped.
|
|
*/
|
|
|
|
enum {
|
|
PRIMARY,
|
|
NUMPAD,
|
|
FUNCTION,
|
|
};
|
|
|
|
|
|
#define PRIMARY_KEYMAP_QWERTY
|
|
|
|
|
|
/* This comment temporarily turns off astyle's indent enforcement
|
|
* so we can make the keymaps actually resemble the physical key layout better
|
|
*/
|
|
// clang-format off
|
|
|
|
KEYMAPS(
|
|
|
|
#if defined (PRIMARY_KEYMAP_QWERTY)
|
|
[PRIMARY] = KEYMAP_STACKED
|
|
(___, Key_1, Key_2, Key_3, Key_4, Key_5, Key_LEDEffectNext,
|
|
Key_Backtick, Key_Q, Key_W, Key_E, Key_R, Key_T, Key_Tab,
|
|
Key_PageUp, Key_A, Key_S, Key_D, Key_F, Key_G,
|
|
Key_PageDown, Key_Z, Key_X, Key_C, Key_V, Key_B, Key_Escape,
|
|
Key_LeftControl, Key_Backspace, Key_LeftGui, Key_LeftShift,
|
|
ShiftToLayer(FUNCTION),
|
|
|
|
M(MACRO_ANY), Key_6, Key_7, Key_8, Key_9, Key_0, LockLayer(NUMPAD),
|
|
Key_Enter, Key_Y, Key_U, Key_I, Key_O, Key_P, Key_Equals,
|
|
Key_H, Key_J, Key_K, Key_L, Key_Semicolon, Key_Quote,
|
|
Key_RightAlt, Key_N, Key_M, Key_Comma, Key_Period, Key_Slash, Key_Minus,
|
|
Key_RightShift, Key_LeftAlt, Key_Spacebar, Key_RightControl,
|
|
ShiftToLayer(FUNCTION)),
|
|
|
|
#elif defined (PRIMARY_KEYMAP_DVORAK)
|
|
|
|
[PRIMARY] = KEYMAP_STACKED
|
|
(___, Key_1, Key_2, Key_3, Key_4, Key_5, Key_LEDEffectNext,
|
|
Key_Backtick, Key_Quote, Key_Comma, Key_Period, Key_P, Key_Y, Key_Tab,
|
|
Key_PageUp, Key_A, Key_O, Key_E, Key_U, Key_I,
|
|
Key_PageDown, Key_Semicolon, Key_Q, Key_J, Key_K, Key_X, Key_Escape,
|
|
Key_LeftControl, Key_Backspace, Key_LeftGui, Key_LeftShift,
|
|
ShiftToLayer(FUNCTION),
|
|
|
|
M(MACRO_ANY), Key_6, Key_7, Key_8, Key_9, Key_0, LockLayer(NUMPAD),
|
|
Key_Enter, Key_F, Key_G, Key_C, Key_R, Key_L, Key_Slash,
|
|
Key_D, Key_H, Key_T, Key_N, Key_S, Key_Minus,
|
|
Key_RightAlt, Key_B, Key_M, Key_W, Key_V, Key_Z, Key_Equals,
|
|
Key_RightShift, Key_LeftAlt, Key_Spacebar, Key_RightControl,
|
|
ShiftToLayer(FUNCTION)),
|
|
|
|
#elif defined (PRIMARY_KEYMAP_COLEMAK)
|
|
|
|
[PRIMARY] = KEYMAP_STACKED
|
|
(___, Key_1, Key_2, Key_3, Key_4, Key_5, Key_LEDEffectNext,
|
|
Key_Backtick, Key_Q, Key_W, Key_F, Key_P, Key_G, Key_Tab,
|
|
Key_PageUp, Key_A, Key_R, Key_S, Key_T, Key_D,
|
|
Key_PageDown, Key_Z, Key_X, Key_C, Key_V, Key_B, Key_Escape,
|
|
Key_LeftControl, Key_Backspace, Key_LeftGui, Key_LeftShift,
|
|
ShiftToLayer(FUNCTION),
|
|
|
|
M(MACRO_ANY), Key_6, Key_7, Key_8, Key_9, Key_0, LockLayer(NUMPAD),
|
|
Key_Enter, Key_J, Key_L, Key_U, Key_Y, Key_Semicolon, Key_Equals,
|
|
Key_H, Key_N, Key_E, Key_I, Key_O, Key_Quote,
|
|
Key_RightAlt, Key_K, Key_M, Key_Comma, Key_Period, Key_Slash, Key_Minus,
|
|
Key_RightShift, Key_LeftAlt, Key_Spacebar, Key_RightControl,
|
|
ShiftToLayer(FUNCTION)),
|
|
|
|
#elif defined (PRIMARY_KEYMAP_CUSTOM)
|
|
// Edit this keymap to make a custom layout
|
|
[PRIMARY] = KEYMAP_STACKED
|
|
(___, Key_1, Key_2, Key_3, Key_4, Key_5, Key_LEDEffectNext,
|
|
Key_Backtick, Key_Q, Key_W, Key_E, Key_R, Key_T, Key_Tab,
|
|
Key_PageUp, Key_A, Key_S, Key_D, Key_F, Key_G,
|
|
Key_PageDown, Key_Z, Key_X, Key_C, Key_V, Key_B, Key_Escape,
|
|
Key_LeftControl, Key_Backspace, Key_LeftGui, Key_LeftShift,
|
|
ShiftToLayer(FUNCTION),
|
|
|
|
M(MACRO_ANY), Key_6, Key_7, Key_8, Key_9, Key_0, LockLayer(NUMPAD),
|
|
Key_Enter, Key_Y, Key_U, Key_I, Key_O, Key_P, Key_Equals,
|
|
Key_H, Key_J, Key_K, Key_L, Key_Semicolon, Key_Quote,
|
|
Key_RightAlt, Key_N, Key_M, Key_Comma, Key_Period, Key_Slash, Key_Minus,
|
|
Key_RightShift, Key_LeftAlt, Key_Spacebar, Key_RightControl,
|
|
ShiftToLayer(FUNCTION)),
|
|
|
|
#else
|
|
|
|
#error "No default keymap defined. You should make sure that you have a line like '#define PRIMARY_KEYMAP_QWERTY' in your sketch"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
[NUMPAD] = KEYMAP_STACKED
|
|
(___, ___, ___, ___, ___, ___, ___,
|
|
___, ___, ___, ___, ___, ___, ___,
|
|
___, ___, ___, ___, ___, ___,
|
|
___, ___, ___, ___, ___, ___, ___,
|
|
___, ___, ___, ___,
|
|
___,
|
|
|
|
M(MACRO_VERSION_INFO), ___, Key_7, Key_8, Key_9, Key_KeypadSubtract, ___,
|
|
___, ___, Key_4, Key_5, Key_6, Key_KeypadAdd, ___,
|
|
___, Key_1, Key_2, Key_3, Key_Equals, ___,
|
|
___, ___, Key_0, Key_Period, Key_KeypadMultiply, Key_KeypadDivide, Key_Enter,
|
|
___, ___, ___, ___,
|
|
___),
|
|
|
|
[FUNCTION] = KEYMAP_STACKED
|
|
(___, Key_F1, Key_F2, Key_F3, Key_F4, Key_F5, Key_CapsLock,
|
|
Key_Tab, ___, Key_mouseUp, ___, Key_mouseBtnR, Key_mouseWarpEnd, Key_mouseWarpNE,
|
|
Key_Home, Key_mouseL, Key_mouseDn, Key_mouseR, Key_mouseBtnL, Key_mouseWarpNW,
|
|
Key_End, Key_PrintScreen, Key_Insert, ___, Key_mouseBtnM, Key_mouseWarpSW, Key_mouseWarpSE,
|
|
___, Key_Delete, ___, ___,
|
|
___,
|
|
|
|
Consumer_ScanPreviousTrack, Key_F6, Key_F7, Key_F8, Key_F9, Key_F10, Key_F11,
|
|
Consumer_PlaySlashPause, Consumer_ScanNextTrack, Key_LeftCurlyBracket, Key_RightCurlyBracket, Key_LeftBracket, Key_RightBracket, Key_F12,
|
|
Key_LeftArrow, Key_DownArrow, Key_UpArrow, Key_RightArrow, ___, ___,
|
|
Key_PcApplication, Consumer_Mute, Consumer_VolumeDecrement, Consumer_VolumeIncrement, ___, Key_Backslash, Key_Pipe,
|
|
___, ___, Key_Enter, ___,
|
|
___)
|
|
) // KEYMAPS(
|
|
|
|
/* Re-enable astyle's indent enforcement */
|
|
// clang-format on
|
|
|
|
static void versionInfoMacro(uint8_t key_state) {
|
|
if (keyToggledOn(key_state)) {
|
|
Macros.type(PSTR("Keyboardio Model 100 - Kaleidoscope "));
|
|
Macros.type(PSTR(BUILD_INFORMATION));
|
|
}
|
|
}
|
|
|
|
static void anyKeyMacro(KeyEvent &event) {
|
|
if (keyToggledOn(event.state)) {
|
|
event.key.setKeyCode(Key_A.getKeyCode() + (uint8_t)(millis() % 36));
|
|
event.key.setFlags(0);
|
|
}
|
|
}
|
|
|
|
const macro_t *macroAction(uint8_t macro_id, KeyEvent &event) {
|
|
switch (macro_id) {
|
|
|
|
case MACRO_VERSION_INFO:
|
|
versionInfoMacro(event.state);
|
|
break;
|
|
|
|
case MACRO_ANY:
|
|
anyKeyMacro(event);
|
|
break;
|
|
}
|
|
return MACRO_NONE;
|
|
}
|
|
|
|
|
|
static kaleidoscope::plugin::LEDSolidColor solidRed(160, 0, 0);
|
|
static kaleidoscope::plugin::LEDSolidColor solidOrange(140, 70, 0);
|
|
static kaleidoscope::plugin::LEDSolidColor solidYellow(130, 100, 0);
|
|
static kaleidoscope::plugin::LEDSolidColor solidGreen(0, 160, 0);
|
|
static kaleidoscope::plugin::LEDSolidColor solidBlue(0, 70, 130);
|
|
static kaleidoscope::plugin::LEDSolidColor solidIndigo(0, 0, 170);
|
|
static kaleidoscope::plugin::LEDSolidColor solidViolet(130, 0, 120);
|
|
|
|
void toggleLedsOnSuspendResume(kaleidoscope::plugin::HostPowerManagement::Event event) {
|
|
switch (event) {
|
|
case kaleidoscope::plugin::HostPowerManagement::Suspend:
|
|
LEDControl.disable();
|
|
break;
|
|
case kaleidoscope::plugin::HostPowerManagement::Resume:
|
|
LEDControl.enable();
|
|
break;
|
|
case kaleidoscope::plugin::HostPowerManagement::Sleep:
|
|
break;
|
|
}
|
|
}
|
|
|
|
void hostPowerManagementEventHandler(kaleidoscope::plugin::HostPowerManagement::Event event) {
|
|
toggleLedsOnSuspendResume(event);
|
|
}
|
|
|
|
enum {
|
|
COMBO_TOGGLE_NKRO_MODE,
|
|
COMBO_ENTER_TEST_MODE
|
|
};
|
|
|
|
static void toggleKeyboardProtocol(uint8_t combo_index) {
|
|
USBQuirks.toggleKeyboardProtocol();
|
|
}
|
|
|
|
static void enterHardwareTestMode(uint8_t combo_index) {
|
|
HardwareTestMode.runTests();
|
|
}
|
|
|
|
USE_MAGIC_COMBOS({.action = toggleKeyboardProtocol,
|
|
// Left Fn + Esc + Shift
|
|
.keys = {R3C6, R2C6, R3C7}},
|
|
{.action = enterHardwareTestMode,
|
|
// Left Fn + Prog + LED
|
|
.keys = {R3C6, R0C0, R0C6}});
|
|
|
|
KALEIDOSCOPE_INIT_PLUGINS(
|
|
EEPROMSettings,
|
|
EEPROMKeymap,
|
|
Focus,
|
|
FocusSettingsCommand,
|
|
FocusEEPROMCommand,
|
|
BootGreetingEffect,
|
|
HardwareTestMode,
|
|
LEDControl,
|
|
LEDOff,
|
|
LEDRainbowEffect,
|
|
LEDRainbowWaveEffect,
|
|
LEDChaseEffect,
|
|
solidRed,
|
|
solidOrange,
|
|
solidYellow,
|
|
solidGreen,
|
|
solidBlue,
|
|
solidIndigo,
|
|
solidViolet,
|
|
LEDBreatheEffect,
|
|
AlphaSquareEffect,
|
|
StalkerEffect,
|
|
LEDPaletteTheme,
|
|
ColormapEffect,
|
|
NumPad,
|
|
Macros,
|
|
MouseKeys,
|
|
HostPowerManagement,
|
|
MagicCombo,
|
|
USBQuirks);
|
|
|
|
void setup() {
|
|
Kaleidoscope.setup();
|
|
NumPad.numPadLayer = NUMPAD;
|
|
AlphaSquare.color = CRGB(255, 0, 0);
|
|
LEDRainbowEffect.brightness(255);
|
|
LEDRainbowWaveEffect.brightness(255);
|
|
HardwareTestMode.setActionKey(R3C6);
|
|
StalkerEffect.variant = STALKER(BlazingTrail);
|
|
LEDOff.activate();
|
|
EEPROMKeymap.setup(5);
|
|
ColormapEffect.max_layers(5);
|
|
}
|
|
|
|
void loop() {
|
|
Kaleidoscope.loop();
|
|
}
|