Created
May 31, 2020 06:30
-
-
Save fredcallaway/78cc1caa392a4e45fe48a0d044273fa6 to your computer and use it in GitHub Desktop.
Fred's Model01-Firmware.ino that worked previously
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// -*- mode: c++ -*- | |
// Copyright 2016 Keyboardio, inc. <[email protected]> | |
// See "LICENSE" for license details | |
#ifndef BUILD_INFORMATION | |
#define BUILD_INFORMATION "locally built" | |
#endif | |
/** | |
* These #include directives pull in the Kaleidoscope firmware core, | |
* as well as the Kaleidoscope plugins we use in the Model 01's firmware | |
*/ | |
// The Kaleidoscope core | |
#include "Kaleidoscope.h" | |
// Support for macros | |
#include "Kaleidoscope-Macros.h" | |
// Support for controlling the keyboard's LEDs | |
#include "Kaleidoscope-LEDControl.h" | |
// Support for "Numpad" mode, which is mostly just the Numpad specific LED mode | |
#include "Kaleidoscope-NumPad.h" | |
// Support for an "LED off mode" | |
#include "LED-Off.h" | |
// Support for the "Boot greeting" effect, which pulses the 'LED' button for 10s | |
// when the keyboard is connected to a computer (or that computer is powered on) | |
#include "Kaleidoscope-LEDEffect-BootGreeting.h" | |
// Support for an LED mode that makes all the LEDs 'breathe' | |
#include "Kaleidoscope-LEDEffect-Breathe.h" | |
// Support for an LED mode that lights up the keys as you press them | |
#include "Kaleidoscope-LED-Stalker.h" | |
// Support for Keyboardio's internal keyboard testing mode | |
#include "Kaleidoscope-Model01-TestMode.h" | |
// Support for host power management (suspend & wakeup) | |
#include "Kaleidoscope-HostPowerManagement.h" | |
#include <Kaleidoscope-OneShot.h> | |
#include <Kaleidoscope-LED-ActiveModColor.h> | |
#include <Kaleidoscope-MagicCombo.h> | |
#include <Kaleidoscope-Qukeys.h> | |
#include <Kaleidoscope-EEPROM-Settings.h> | |
#include "Kaleidoscope-HostOS.h" | |
#include "Kaleidoscope/HostOS-select.h" | |
#include "Kaleidoscope-Unicode.h" | |
/** This 'enum' is a list of all the macros used by | |
the Model 01's firmware | |
* The names aren't particularly important. What is important is that each | |
* is unique. | |
* | |
* These are the names of your macros. They'll be used in two places. | |
* The first is in your keymap definitions. There, you'll use the syntax | |
* `M(MACRO_NAME)` to mark a specific keymap position as triggering `MACRO_NAME` | |
* | |
* The second usage is in the 'switch' statement in the `macroAction` function. | |
* That switch statement actually runs the code associated with a macro when | |
* a macro key is pressed. | |
*/ | |
enum { | |
MACRO_VERSION_INFO, | |
MACRO_ANY, | |
MACRO_OSM_HYPER, | |
U_ALPHA, | |
}; | |
static void unicode(uint32_t codepoint, uint8_t keyState) { | |
if (!keyToggledOn(keyState)) { | |
return; | |
} | |
Unicode.type(codepoint); | |
} | |
const macro_t *macroAction(uint8_t macroIndex, uint8_t keyState) { | |
switch (macroIndex) { | |
case MACRO_VERSION_INFO: | |
if (keyToggledOn(keyState)) { | |
Macros.type(PSTR("Keyboardio Model 01 - Kaleidoscope ")); | |
Macros.type(PSTR(BUILD_INFORMATION)); | |
} | |
break; | |
case MACRO_ANY: Macros.type(PSTR("A")); break; | |
case MACRO_OSM_HYPER: | |
OneShot.inject(OSM(LeftAlt), keyState); | |
OneShot.inject(OSM(LeftControl), keyState); | |
OneShot.inject(OSM(LeftGui), keyState); | |
break; | |
case U_ALPHA: unicode(0x2328, keyState); break; | |
} | |
return MACRO_NONE; | |
} | |
enum { QWERTY, NUMPAD, SLATE, FUNCTION }; // layers | |
/* This comment temporarily turns off astyle's indent enforcement | |
* so we can make the keymaps actually resemble the physical key layout better | |
*/ | |
// *INDENT-OFF* | |
#define HYPER LCTRL(Key_LeftAlt) | |
KEYMAPS( | |
[QWERTY] = KEYMAP_STACKED | |
(OSL(SLATE) , 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_Delete , | |
HYPER , Key_A , Key_S , Key_D , Key_F , Key_G , | |
Key_Tab , Key_Z , Key_X , Key_C , Key_V , Key_B , Key_F11 , | |
Key_LeftShift , Key_Backspace , Key_LeftControl, Key_LeftAlt, | |
Key_LeftGui , | |
M(U_ALPHA) , Key_6 , Key_7 , Key_8 , Key_9 , Key_0 , OSL(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 , | |
M(MACRO_OSM_HYPER) , Key_N , Key_M , Key_Comma , Key_Period , Key_Slash , Key_Minus , | |
Key_RightGui , Key_LeftAlt , Key_Spacebar , Key_RightShift , | |
ShiftToLayer(FUNCTION)) , | |
// [COLEMAK] = 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_LeftGui, Key_Backspace, Key_LeftControl, 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_RightGui, | |
// ShiftToLayer(FUNCTION)), | |
[NUMPAD] = KEYMAP_STACKED | |
(___, ___, ___, ___, ___, ___, ___, | |
___, ___, ___, ___, ___, ___, ___, | |
___, Key_KeypadDivide, Key_KeypadMultiply, Key_KeypadSubtract, Key_KeypadAdd, Key_Tab, | |
___, ___, ___, ___, ___, ___, ___, | |
___, ___, ___, ___, | |
___, | |
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, | |
___, ___, ___, ___, | |
___), | |
[SLATE] = KEYMAP_STACKED | |
(___, ___, ___, ___, ___, ___, ___, | |
___, ___, ___, ___, ___, ___, ___, | |
___, ___, ___, ___, ___, ___, | |
___, ___, ___, ___, ___, ___, ___, | |
___, ___, ___, ___, | |
___, | |
M(MACRO_VERSION_INFO), ___, Key_Keypad7, Key_Keypad8, Key_Keypad9, Key_KeypadSubtract, ___, | |
___, ___, Key_Keypad4, Key_Keypad5, Key_Keypad6, Key_KeypadAdd, ___, | |
___, Key_Keypad1, Key_Keypad2, Key_Keypad3, Key_Equals, ___, | |
___, ___, Key_Keypad0, Key_KeypadDot, Key_KeypadMultiply, Key_KeypadDivide, Key_Enter, | |
___, ___, ___, ___, | |
___), | |
[FUNCTION] = KEYMAP_STACKED | |
(___ , Key_F1 , Key_F2 , Key_F3 , Key_F4 , Key_F5 , XXX , | |
Key_Tab , Key_Pipe , Key_Backslash , Key_LeftBracket , Key_RightBracket , LSHIFT(Key_6) , LALT(Key_Delete) , | |
Key_PageUp , Key_Escape , Key_Enter , LSHIFT(Key_9) , LSHIFT(Key_0) , Key_Minus , | |
Key_PageDown , Key_Home , Key_End , Key_LeftCurlyBracket , Key_RightCurlyBracket , LSHIFT(Key_Minus) , ___ , | |
___ , LALT(Key_Backspace) , ___ , ___ , | |
___ , | |
Consumer_ScanPreviousTrack , Key_F6 , Key_F7 , Key_F8 , Key_F9 , Key_F10 , Key_F11 , | |
___ , ___ , Key_LeftArrow , Key_UpArrow , Key_RightArrow , Key_Tab , Key_Tab , | |
/* , */LGUI(Key_LeftArrow) , LALT(Key_LeftArrow) , Key_DownArrow , LALT(Key_RightArrow) , LGUI(Key_RightArrow) , ___ , | |
Key_PcApplication , Consumer_Mute , Consumer_VolumeDecrement , Consumer_VolumeIncrement , ___ , Key_Backslash , Key_Pipe , | |
___ , ___ , Key_Enter , ___ , | |
___) | |
) // KEYMAPS( | |
/* Re-enable astyle's indent enforcement */ | |
// *INDENT-ON* | |
/** macroAction dispatches keymap events that are tied to a macro | |
to that macro. It takes two uint8_t parameters. | |
The first is the macro being called (the entry in the 'enum' earlier in this file). | |
The second is the state of the keyswitch. You can use the keyswitch state to figure out | |
if the key has just been toggled on, is currently pressed or if it's just been released. | |
The 'switch' statement should have a 'case' for each entry of the macro enum. | |
Each 'case' statement should call out to a function to handle the macro in question. | |
*/ | |
static const kaleidoscope::MagicCombo::combo_t magic_combos[] PROGMEM = { | |
{R1C7, // left hand, | |
R0C8 //right hand | |
}, | |
{0, 0} | |
}; | |
// void magicComboActions(uint8_t combo_index, uint32_t left_hand, uint32_t right_hand) { | |
// switch (combo_index) { | |
// case 0: | |
// MACRODOWN(T(D)); | |
// break; | |
// } | |
// } | |
// These 'solid' color effect definitions define a rainbow of | |
// LED color modes calibrated to draw 500mA or less on the | |
// Keyboardio Model 01. | |
// static kaleidoscope::LEDSolidColor solidRed(160, 0, 0); | |
// static kaleidoscope::LEDSolidColor solidOrange(140, 70, 0); | |
// static kaleidoscope::LEDSolidColor solidYellow(130, 100, 0); | |
// static kaleidoscope::LEDSolidColor solidGreen(0, 160, 0); | |
// static kaleidoscope::LEDSolidColor solidBlue(0, 70, 130); | |
// static kaleidoscope::LEDSolidColor solidIndigo(0, 0, 170); | |
// static kaleidoscope::LEDSolidColor solidViolet(130, 0, 120); | |
/** toggleLedsOnSuspendResume toggles the LEDs off when the host goes to sleep, | |
* and turns them back on when it wakes up. | |
*/ | |
void toggleLedsOnSuspendResume(kaleidoscope::HostPowerManagement::Event event) { | |
switch (event) { | |
case kaleidoscope::HostPowerManagement::Suspend: | |
LEDControl.paused = true; | |
LEDControl.set_all_leds_to({0, 0, 0}); | |
LEDControl.syncLeds(); | |
break; | |
case kaleidoscope::HostPowerManagement::Resume: | |
LEDControl.paused = false; | |
LEDControl.refreshAll(); | |
break; | |
case kaleidoscope::HostPowerManagement::Sleep: | |
break; | |
} | |
} | |
/** hostPowerManagementEventHandler dispatches power management events (suspend, | |
* resume, and sleep) to other functions that perform action based on these | |
* events. | |
*/ | |
void hostPowerManagementEventHandler(kaleidoscope::HostPowerManagement::Event event) { | |
toggleLedsOnSuspendResume(event); | |
} | |
/** The 'setup' function is one of the two standard Arduino sketch functions. | |
* It's called when your keyboard first powers up. This is where you set up | |
* Kaleidoscope and any plugins. | |
*/ | |
void setup() { | |
// First, call Kaleidoscope's internal setup function | |
Kaleidoscope.setup(); | |
// Next, tell Kaleidoscope which plugins you want to use. | |
// The order can be important. For example, LED effects are | |
// added in the order they're listed here. | |
Kaleidoscope.use( | |
// The macros plugin adds support for macros | |
&Macros, | |
&OneShot, | |
&ActiveModColorEffect, | |
&MagicCombo, | |
&BootGreetingEffect, | |
&TestMode, | |
&LEDControl, | |
&LEDOff, | |
&LEDBreatheEffect, | |
&StalkerEffect, | |
&NumPad, | |
&Qukeys, | |
&EEPROMSettings, | |
&HostOS, | |
&Unicode, | |
// The HostPowerManagement plugin enables waking up the host from suspend, | |
// and allows us to turn LEDs off when it goes to sleep. | |
&HostPowerManagement | |
); | |
// While we hope to improve this in the future, the NumPad plugin | |
// needs to be explicitly told which keymap layer is your numpad layer | |
NumPad.numPadLayer = NUMPAD; | |
// The LED Stalker mode has a few effects. The one we like is | |
// called 'BlazingTrail'. For details on other options, | |
// see https://github.com/keyboardio/Kaleidoscope-LED-Stalker | |
StalkerEffect.variant = STALKER(BlazingTrail); | |
// We want the keyboard to be able to wake the host up from suspend. | |
HostPowerManagement.enableWakeup(); | |
// We want to make sure that the firmware starts with LED effects off | |
// This avoids over-taxing devices that don't have a lot of power to share | |
// with USB devices | |
LEDOff.activate(); | |
MagicCombo.magic_combos = magic_combos; | |
} | |
/** loop is the second of the standard Arduino sketch functions. | |
* As you might expect, it runs in a loop, never exiting. | |
* | |
* For Kaleidoscope-based keyboard firmware, you usually just want to | |
* call Kaleidoscope.loop(); and not do anything custom here. | |
*/ | |
void loop() { | |
Kaleidoscope.loop(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment