Created
October 19, 2017 07:30
-
-
Save indirect/d5f3ab1f82d3a74c085c73c2b76f74a7 to your computer and use it in GitHub Desktop.
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 keys that move the mouse | |
#include "Kaleidoscope-MouseKeys.h" | |
// Support for macros | |
#include "Kaleidoscope-Macros.h" | |
// Support for controlling the keyboard's LEDs | |
#include "Kaleidoscope-LEDControl.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 LED modes that set all LEDs to a single color | |
#include "Kaleidoscope-LEDEffect-SolidColor.h" | |
// Support for LED modes that pulse the keyboard's LED in a rainbow pattern | |
#include "Kaleidoscope-LEDEffect-Rainbow.h" | |
// Support for an LED mode that lights up the keys as you press them | |
#include "Kaleidoscope-LED-Stalker.h" | |
// Support for lighting up active mod keys | |
#include "Kaleidoscope-LED-ActiveModColor.h" | |
// Support for tap or hold on a single button | |
#include "Kaleidoscope-DualUse.h" | |
// Support for tapping modifiers to use them on the next key | |
#include "Kaleidoscope-OneShot.h" | |
// Support for Esc to cancel pending oneshots | |
#include "Kaleidoscope-Escape-OneShot.h" | |
#define Key_Bang LSHIFT(Key_1) | |
#define Key_At LSHIFT(Key_2) | |
#define Key_Hash LSHIFT(Key_3) | |
#define Key_Dollar LSHIFT(Key_4) | |
#define Key_Percent LSHIFT(Key_5) | |
#define Key_Caret LSHIFT(Key_6) | |
#define Key_And LSHIFT(Key_7) | |
#define Key_Star LSHIFT(Key_8) | |
#define Key_Lparen LSHIFT(Key_9) | |
#define Key_Rparen LSHIFT(Key_0) | |
#define Key_Meh LALT(LCTRL(Key_LeftGui)) | |
#define Key_Hyper LALT(LCTRL(LGUI(Key_LeftShift))) | |
/** 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, | |
}; | |
/** The Model 01'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/key_defs_keyboard.h | |
* https://github.com/keyboardio/Kaleidoscope/blob/master/src/key_defs_consumerctl.h | |
* https://github.com/keyboardio/Kaleidoscope/blob/master/src/key_defs_sysctl.h | |
* https://github.com/keyboardio/Kaleidoscope/blob/master/src/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. | |
* the special nature of the PROG key | |
* keeping NUM and FN consistent and accessible on all layers | |
* | |
* | |
* The "keymaps" data structure is a list of the keymaps compiled into the firmware. | |
* The order of keymaps in the list is important, as the ShiftToLayer(#) and LockLayer(#) | |
* macros switch to key layers based on this list. | |
* | |
* | |
* 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. | |
*/ | |
/** | |
* Layers are "0-indexed" -- That is the first one is layer 0. The second one is layer 1. | |
* The third one is layer 2. | |
* This 'enum' lets us use names like QWERTY, FUNCTION, and NUMPAD in place of | |
* the numbers 0, 1 and 2. | |
*/ | |
enum { DVORAK, FUNCTION, NUM, META }; // 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* | |
const Key keymaps[][ROWS][COLS] PROGMEM = { | |
[DVORAK] = 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, | |
/* OSM(LeftControl), Key_Backspace, OSM(LeftGui), OSM(LeftShift), */ | |
Key_LeftControl, Key_Backspace, Key_LeftGui, Key_LeftShift, | |
ShiftToLayer(FUNCTION), | |
Key_Hyper, Key_6, Key_7, Key_8, Key_9, Key_0, LockLayer(NUM), | |
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, | |
ShiftToLayer(NUM), Key_B, Key_M, Key_W, Key_V, Key_Z, Key_Equals, | |
/* OSM(RightShift), OSM(LeftAlt), Key_Spacebar, OSM(RightControl), */ | |
Key_RightShift, Key_LeftAlt, Key_Spacebar, Key_RightControl, | |
ShiftToLayer(FUNCTION)), | |
[FUNCTION] = KEYMAP_STACKED | |
(___, Key_F1, Key_F2, Key_F3, Key_F4, Key_F5, XXX, | |
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, Key_Mute, Consumer_VolumeDecrement, Consumer_VolumeIncrement, ___, Key_Backslash, Key_Pipe, | |
___, ___, Key_Enter, ___, | |
___), | |
[NUM] = KEYMAP_STACKED | |
(___, ___, ___, ___, ___, ___, ___, | |
___, ___, ___, ___, ___, ___, ___, | |
___, Key_1, Key_2, Key_3, Key_4, Key_5, | |
___, Key_6, Key_7, Key_8, Key_9, Key_0, ___, | |
___, ___, ___, ___, | |
___, | |
___, ___, ___, ___, ___, ___, ___, | |
___, ___, ___, ___, ___, ___, ___, | |
Key_Bang, Key_At, Key_Hash, Key_Dollar, Key_Percent, ___, | |
___, Key_Caret, Key_And, Key_Star, Key_Lparen, Key_Rparen, ___, | |
___, ___, ___, ___, | |
___) | |
}; | |
/* Re-enable astyle's indent enforcement */ | |
// *INDENT-ON* | |
/** versionInfoMacro handles the 'firmware version info' macro | |
* When a key bound to the macro is pressed, this macro | |
* prints out the firmware build information as virtual keystrokes | |
*/ | |
static void versionInfoMacro(uint8_t keyState) { | |
if (keyToggledOn(keyState)) { | |
Macros.type(PSTR("Keyboardio Model 01 - Kaleidoscope ")); | |
Macros.type(PSTR(BUILD_INFORMATION)); | |
} | |
} | |
/** 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. | |
*/ | |
const macro_t *macroAction(uint8_t macroIndex, uint8_t keyState) { | |
switch (macroIndex) { | |
case MACRO_VERSION_INFO: | |
versionInfoMacro(keyState); | |
break; | |
} | |
return MACRO_NONE; | |
} | |
// 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); | |
/** 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 boot greeting effect pulses the LED button for 10 seconds after the keyboard is first connected | |
&BootGreetingEffect, | |
&LEDControl, | |
&LEDOff, | |
&StalkerEffect, | |
&LEDRainbowWaveEffect, | |
&solidRed, &solidOrange, &solidYellow, &solidGreen, &solidBlue, &solidIndigo, &solidViolet, | |
&Macros, | |
&MouseKeys, | |
&DualUse, | |
&OneShot, | |
&EscapeOneShot, | |
&ActiveModColorEffect, | |
NULL | |
); | |
// We set the brightness of the rainbow effects to 150 (on a scale of 0-255) | |
// This draws more than 500mA, but looks much nicer than a dimmer effect | |
LEDRainbowWaveEffect.brightness(150); | |
// 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 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(); | |
} | |
/** 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