Advertisement
ghoetker

Keyboardio firmware

Aug 20th, 2019
142
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // -*- mode: c++ -*-
  2. // Copyright 2016 Keyboardio, inc. <jesse@keyboard.io>
  3. // See "LICENSE" for license details
  4.  
  5. #ifndef BUILD_INFORMATION
  6. #define BUILD_INFORMATION "locally built"
  7. #endif
  8.  
  9.  
  10. /**
  11.  * These #include directives pull in the Kaleidoscope firmware core,
  12.  * as well as the Kaleidoscope plugins we use in the Model 01's firmware
  13.  */
  14.  
  15.  
  16. // The Kaleidoscope core
  17. #include "Kaleidoscope.h"
  18.  
  19. // Support for storing the keymap in EEPROM
  20. #include "Kaleidoscope-EEPROM-Settings.h"
  21. #include "Kaleidoscope-EEPROM-Keymap.h"
  22.  
  23. // Support for communicating with the host via a simple Serial protocol
  24. #include "Kaleidoscope-FocusSerial.h"
  25.  
  26. // Support for keys that move the mouse
  27. #include "Kaleidoscope-MouseKeys.h"
  28.  
  29. // Support for macros
  30. #include "Kaleidoscope-Macros.h"
  31.  
  32. // Support for controlling the keyboard's LEDs
  33. #include "Kaleidoscope-LEDControl.h"
  34.  
  35. // Support for "Numpad" mode, which is mostly just the Numpad specific LED mode
  36. #include "Kaleidoscope-NumPad.h"
  37.  
  38. // Support for the "Boot greeting" effect, which pulses the 'LED' button for 10s
  39. // when the keyboard is connected to a computer (or that computer is powered on)
  40. #include "Kaleidoscope-LEDEffect-BootGreeting.h"
  41.  
  42. // Support for LED modes that set all LEDs to a single color
  43. #include "Kaleidoscope-LEDEffect-SolidColor.h"
  44.  
  45. // Support for an LED mode that makes all the LEDs 'breathe'
  46. #include "Kaleidoscope-LEDEffect-Breathe.h"
  47.  
  48. // Support for an LED mode that makes a red pixel chase a blue pixel across the keyboard
  49. #include "Kaleidoscope-LEDEffect-Chase.h"
  50.  
  51. // Support for LED modes that pulse the keyboard's LED in a rainbow pattern
  52. #include "Kaleidoscope-LEDEffect-Rainbow.h"
  53.  
  54. // Support for an LED mode that lights up the keys as you press them
  55. #include "Kaleidoscope-LED-Stalker.h"
  56.  
  57. // Support for an LED mode that prints the keys you press in letters 4px high
  58. #include "Kaleidoscope-LED-AlphaSquare.h"
  59.  
  60. // Support for shared palettes for other plugins, like Colormap below
  61. #include "Kaleidoscope-LED-Palette-Theme.h"
  62.  
  63. // Support for an LED mode that lets one configure per-layer color maps
  64. #include "Kaleidoscope-Colormap.h"
  65.  
  66. // Support for Keyboardio's internal keyboard testing mode
  67. #include "Kaleidoscope-HardwareTestMode.h"
  68.  
  69. // Support for host power management (suspend & wakeup)
  70. #include "Kaleidoscope-HostPowerManagement.h"
  71.  
  72. // Support for magic combos (key chords that trigger an action)
  73. #include "Kaleidoscope-MagicCombo.h"
  74.  
  75. // Support for USB quirks, like changing the key state report protocol
  76. #include "Kaleidoscope-USB-Quirks.h"
  77.  
  78. // Plugins added by Glenn
  79. #include <Kaleidoscope-LED-Fire.h>
  80. #include <Kaleidoscope-LED-Wavepool.h>
  81. #include <Kaleidoscope-LEDEffect-Rainbow.h>
  82. #include <Kaleidoscope-LEDEffect-DigitalRain.h>
  83.  
  84.  
  85. /** This 'enum' is a list of all the macros used by the Model 01's firmware
  86.   * The names aren't particularly important. What is important is that each
  87.   * is unique.
  88.   *
  89.   * These are the names of your macros. They'll be used in two places.
  90.   * The first is in your keymap definitions. There, you'll use the syntax
  91.   * `M(MACRO_NAME)` to mark a specific keymap position as triggering `MACRO_NAME`
  92.   *
  93.   * The second usage is in the 'switch' statement in the `macroAction` function.
  94.   * That switch statement actually runs the code associated with a macro when
  95.   * a macro key is pressed.
  96.   */
  97.  
  98. enum { MACRO_VERSION_INFO,
  99.        MACRO_ANY
  100.      };
  101.  
  102.  
  103.  
  104. /** The Model 01's key layouts are defined as 'keymaps'. By default, there are three
  105.   * keymaps: The standard QWERTY keymap, the "Function layer" keymap and the "Numpad"
  106.   * keymap.
  107.   *
  108.   * Each keymap is defined as a list using the 'KEYMAP_STACKED' macro, built
  109.   * of first the left hand's layout, followed by the right hand's layout.
  110.   *
  111.   * Keymaps typically consist mostly of `Key_` definitions. There are many, many keys
  112.   * defined as part of the USB HID Keyboard specification. You can find the names
  113.   * (if not yet the explanations) for all the standard `Key_` defintions offered by
  114.   * Kaleidoscope in these files:
  115.   *    https://github.com/keyboardio/Kaleidoscope/blob/master/src/key_defs_keyboard.h
  116.   *    https://github.com/keyboardio/Kaleidoscope/blob/master/src/key_defs_consumerctl.h
  117.   *    https://github.com/keyboardio/Kaleidoscope/blob/master/src/key_defs_sysctl.h
  118.   *    https://github.com/keyboardio/Kaleidoscope/blob/master/src/key_defs_keymaps.h
  119.   *
  120.   * Additional things that should be documented here include
  121.   *   using ___ to let keypresses fall through to the previously active layer
  122.   *   using XXX to mark a keyswitch as 'blocked' on this layer
  123.   *   using ShiftToLayer() and LockLayer() keys to change the active keymap.
  124.   *   keeping NUM and FN consistent and accessible on all layers
  125.   *
  126.   * The PROG key is special, since it is how you indicate to the board that you
  127.   * want to flash the firmware. However, it can be remapped to a regular key.
  128.   * When the keyboard boots, it first looks to see whether the PROG key is held
  129.   * down; if it is, it simply awaits further flashing instructions. If it is
  130.   * not, it continues loading the rest of the firmware and the keyboard
  131.   * functions normally, with whatever binding you have set to PROG. More detail
  132.   * here: https://community.keyboard.io/t/how-the-prog-key-gets-you-into-the-bootloader/506/8
  133.   *
  134.   * The "keymaps" data structure is a list of the keymaps compiled into the firmware.
  135.   * The order of keymaps in the list is important, as the ShiftToLayer(#) and LockLayer(#)
  136.   * macros switch to key layers based on this list.
  137.   *
  138.   *
  139.  
  140.   * A key defined as 'ShiftToLayer(FUNCTION)' will switch to FUNCTION while held.
  141.   * Similarly, a key defined as 'LockLayer(NUMPAD)' will switch to NUMPAD when tapped.
  142.   */
  143.  
  144. /**
  145.   * Layers are "0-indexed" -- That is the first one is layer 0. The second one is layer 1.
  146.   * The third one is layer 2.
  147.   * This 'enum' lets us use names like QWERTY, FUNCTION, and NUMPAD in place of
  148.   * the numbers 0, 1 and 2.
  149.   *
  150.   */
  151.  
  152. enum { PRIMARY, NUMPAD, FUNCTION }; // layers
  153.  
  154.  
  155. /**
  156.   * To change your keyboard's layout from QWERTY to DVORAK or COLEMAK, comment out the line
  157.   *
  158.   * #define PRIMARY_KEYMAP_QWERTY
  159.   *
  160.   * by changing it to
  161.   *
  162.   * // #define PRIMARY_KEYMAP_QWERTY
  163.   *
  164.   * Then uncomment the line corresponding to the layout you want to use.
  165.   *
  166.   */
  167.  
  168. #define PRIMARY_KEYMAP_QWERTY
  169. // #define PRIMARY_KEYMAP_COLEMAK
  170. // #define PRIMARY_KEYMAP_DVORAK
  171. // #define PRIMARY_KEYMAP_CUSTOM
  172.  
  173.  
  174.  
  175. /* This comment temporarily turns off astyle's indent enforcement
  176.  *   so we can make the keymaps actually resemble the physical key layout better
  177.  */
  178. // *INDENT-OFF*
  179.  
  180. KEYMAPS(
  181.  
  182. #if defined (PRIMARY_KEYMAP_QWERTY)
  183.   [PRIMARY] = KEYMAP_STACKED
  184.   (___,          Key_1, Key_2, Key_3, Key_4, Key_5, Key_LEDEffectNext,
  185.    Key_Backtick, Key_Q, Key_W, Key_E, Key_R, Key_T, Key_Tab,
  186.    Key_PageUp,   Key_A, Key_S, Key_D, Key_F, Key_G,
  187.    Key_PageDown, Key_Z, Key_X, Key_C, Key_V, Key_B, Key_Escape,
  188.    Key_LeftControl, Key_Backspace, Key_LeftGui, Key_LeftShift,
  189.    ShiftToLayer(FUNCTION),
  190.  
  191.    M(MACRO_ANY),  Key_6, Key_7, Key_8,     Key_9,         Key_0,         LockLayer(NUMPAD),
  192.    Key_Enter,     Key_Y, Key_U, Key_I,     Key_O,         Key_P,         Key_Equals,
  193.                   Key_H, Key_J, Key_K,     Key_L,         Key_Semicolon, Key_Quote,
  194.    Key_RightAlt,  Key_N, Key_M, Key_Comma, Key_Period,    Key_Slash,     Key_Minus,
  195.    Key_RightShift, Key_LeftAlt, Key_Spacebar, Key_RightControl,
  196.    ShiftToLayer(FUNCTION)),
  197.  
  198. #elif defined (PRIMARY_KEYMAP_DVORAK)
  199.  
  200.   [PRIMARY] = KEYMAP_STACKED
  201.   (___,          Key_1,         Key_2,     Key_3,      Key_4, Key_5, Key_LEDEffectNext,
  202.    Key_Backtick, Key_Quote,     Key_Comma, Key_Period, Key_P, Key_Y, Key_Tab,
  203.    Key_PageUp,   Key_A,         Key_O,     Key_E,      Key_U, Key_I,
  204.    Key_PageDown, Key_Semicolon, Key_Q,     Key_J,      Key_K, Key_X, Key_Escape,
  205.    Key_LeftControl, Key_Backspace, Key_LeftGui, Key_LeftShift,
  206.    ShiftToLayer(FUNCTION),
  207.  
  208.    M(MACRO_ANY),   Key_6, Key_7, Key_8, Key_9, Key_0, LockLayer(NUMPAD),
  209.    Key_Enter,      Key_F, Key_G, Key_C, Key_R, Key_L, Key_Slash,
  210.                    Key_D, Key_H, Key_T, Key_N, Key_S, Key_Minus,
  211.    Key_RightAlt,   Key_B, Key_M, Key_W, Key_V, Key_Z, Key_Equals,
  212.    Key_RightShift, Key_LeftAlt, Key_Spacebar, Key_RightControl,
  213.    ShiftToLayer(FUNCTION)),
  214.  
  215. #elif defined (PRIMARY_KEYMAP_COLEMAK)
  216.  
  217.   [PRIMARY] = KEYMAP_STACKED
  218.   (___,          Key_1, Key_2, Key_3, Key_4, Key_5, Key_LEDEffectNext,
  219.    Key_Backtick, Key_Q, Key_W, Key_F, Key_P, Key_G, Key_Tab,
  220.    Key_PageUp,   Key_A, Key_R, Key_S, Key_T, Key_D,
  221.    Key_PageDown, Key_Z, Key_X, Key_C, Key_V, Key_B, Key_Escape,
  222.    Key_LeftControl, Key_Backspace, Key_LeftGui, Key_LeftShift,
  223.    ShiftToLayer(FUNCTION),
  224.  
  225.    M(MACRO_ANY),  Key_6, Key_7, Key_8,     Key_9,         Key_0,         LockLayer(NUMPAD),
  226.    Key_Enter,     Key_J, Key_L, Key_U,     Key_Y,         Key_Semicolon, Key_Equals,
  227.                   Key_H, Key_N, Key_E,     Key_I,         Key_O,         Key_Quote,
  228.    Key_RightAlt,  Key_K, Key_M, Key_Comma, Key_Period,    Key_Slash,     Key_Minus,
  229.    Key_RightShift, Key_LeftAlt, Key_Spacebar, Key_RightControl,
  230.    ShiftToLayer(FUNCTION)),
  231.  
  232. #elif defined (PRIMARY_KEYMAP_CUSTOM)
  233.   // Edit this keymap to make a custom layout
  234.   [PRIMARY] = KEYMAP_STACKED
  235.   (___,          Key_1, Key_2, Key_3, Key_4, Key_5, Key_LEDEffectNext,
  236.    Key_Backtick, Key_Q, Key_W, Key_E, Key_R, Key_T, Key_Tab,
  237.    Key_PageUp,   Key_A, Key_S, Key_D, Key_F, Key_G,
  238.    Key_PageDown, Key_Z, Key_X, Key_C, Key_V, Key_B, Key_Escape,
  239.    Key_LeftControl, Key_Backspace, Key_LeftGui, Key_LeftShift,
  240.    ShiftToLayer(FUNCTION),
  241.  
  242.    M(MACRO_ANY),  Key_6, Key_7, Key_8,     Key_9,         Key_0,         LockLayer(NUMPAD),
  243.    Key_Enter,     Key_Y, Key_U, Key_I,     Key_O,         Key_P,         Key_Equals,
  244.                   Key_H, Key_J, Key_K,     Key_L,         Key_Semicolon, Key_Quote,
  245.    Key_RightAlt,  Key_N, Key_M, Key_Comma, Key_Period,    Key_Slash,     Key_Minus,
  246.    Key_RightShift, Key_LeftAlt, Key_Spacebar, Key_RightControl,
  247.    ShiftToLayer(FUNCTION)),
  248.  
  249. #else
  250.  
  251. #error "No default keymap defined. You should make sure that you have a line like '#define PRIMARY_KEYMAP_QWERTY' in your sketch"
  252.  
  253. #endif
  254.  
  255.  
  256.  
  257.   [NUMPAD] =  KEYMAP_STACKED
  258.   (___, ___, ___, ___, ___, ___, ___,
  259.    ___, ___, ___, ___, ___, ___, ___,
  260.    ___, ___, ___, ___, ___, ___,
  261.    ___, ___, ___, ___, ___, ___, ___,
  262.    ___, ___, ___, ___,
  263.    ___,
  264.  
  265.    M(MACRO_VERSION_INFO),  ___, Key_7, Key_8,      Key_9,              Key_KeypadSubtract, ___,
  266.    ___,                    ___, Key_4, Key_5,      Key_6,              Key_KeypadAdd,      ___,
  267.                            ___, Key_1, Key_2,      Key_3,              Key_Equals,         ___,
  268.    ___,                    ___, Key_0, Key_Period, Key_KeypadMultiply, Key_KeypadDivide,   Key_Enter,
  269.    ___, ___, ___, ___,
  270.    ___),
  271.  
  272.   [FUNCTION] =  KEYMAP_STACKED
  273.   (___,      Key_F1,           Key_F2,      Key_F3,     Key_F4,        Key_F5,           Key_CapsLock,
  274.    Key_Tab,  ___,              Key_mouseUp, ___,        Key_mouseBtnR, Key_mouseWarpEnd, Key_mouseWarpNE,
  275.    Key_Home, Key_mouseL,       Key_mouseDn, Key_mouseR, Key_mouseBtnL, Key_mouseWarpNW,
  276.    Key_End,  Key_PrintScreen,  Key_Insert,  ___,        Key_mouseBtnM, Key_mouseWarpSW,  Key_mouseWarpSE,
  277.    ___, Key_Delete, ___, ___,
  278.    ___,
  279.  
  280.    Consumer_ScanPreviousTrack, Key_F6,                 Key_F7,                   Key_F8,                   Key_F9,          Key_F10,          Key_F11,
  281.    Consumer_PlaySlashPause,    Consumer_ScanNextTrack, Key_LeftCurlyBracket,     Key_RightCurlyBracket,    Key_LeftBracket, Key_RightBracket, Key_F12,
  282.                                Key_LeftArrow,          Key_DownArrow,            Key_UpArrow,              Key_RightArrow,  ___,              ___,
  283.    Key_PcApplication,          Consumer_Mute,          Consumer_VolumeDecrement, Consumer_VolumeIncrement, ___,             Key_Backslash,    Key_Pipe,
  284.    ___, ___, Key_Enter, ___,
  285.    ___)
  286. ) // KEYMAPS(
  287.  
  288. /* Re-enable astyle's indent enforcement */
  289. // *INDENT-ON*
  290.  
  291. /** versionInfoMacro handles the 'firmware version info' macro
  292.  *  When a key bound to the macro is pressed, this macro
  293.  *  prints out the firmware build information as virtual keystrokes
  294.  */
  295.  
  296. static void versionInfoMacro(uint8_t keyState) {
  297.   if (keyToggledOn(keyState)) {
  298.     Macros.type(PSTR("Keyboardio Model 01 - Kaleidoscope "));
  299.     Macros.type(PSTR(BUILD_INFORMATION));
  300.   }
  301. }
  302.  
  303. /** anyKeyMacro is used to provide the functionality of the 'Any' key.
  304.  *
  305.  * When the 'any key' macro is toggled on, a random alphanumeric key is
  306.  * selected. While the key is held, the function generates a synthetic
  307.  * keypress event repeating that randomly selected key.
  308.  *
  309.  */
  310.  
  311. static void anyKeyMacro(uint8_t keyState) {
  312.   static Key lastKey;
  313.   bool toggledOn = false;
  314.   if (keyToggledOn(keyState)) {
  315.     lastKey.keyCode = Key_A.keyCode + (uint8_t)(millis() % 36);
  316.     toggledOn = true;
  317.   }
  318.  
  319.   if (keyIsPressed(keyState))
  320.     kaleidoscope::hid::pressKey(lastKey, toggledOn);
  321. }
  322.  
  323.  
  324. /** macroAction dispatches keymap events that are tied to a macro
  325.     to that macro. It takes two uint8_t parameters.
  326.  
  327.     The first is the macro being called (the entry in the 'enum' earlier in this file).
  328.     The second is the state of the keyswitch. You can use the keyswitch state to figure out
  329.     if the key has just been toggled on, is currently pressed or if it's just been released.
  330.  
  331.     The 'switch' statement should have a 'case' for each entry of the macro enum.
  332.     Each 'case' statement should call out to a function to handle the macro in question.
  333.  
  334.  */
  335.  
  336. const macro_t *macroAction(uint8_t macroIndex, uint8_t keyState) {
  337.   switch (macroIndex) {
  338.  
  339.   case MACRO_VERSION_INFO:
  340.     versionInfoMacro(keyState);
  341.     break;
  342.  
  343.   case MACRO_ANY:
  344.     anyKeyMacro(keyState);
  345.     break;
  346.   }
  347.   return MACRO_NONE;
  348. }
  349.  
  350.  
  351.  
  352. // These 'solid' color effect definitions define a rainbow of
  353. // LED color modes calibrated to draw 500mA or less on the
  354. // Keyboardio Model 01.
  355.  
  356.  
  357. static kaleidoscope::plugin::LEDSolidColor solidRed(160, 0, 0);
  358. static kaleidoscope::plugin::LEDSolidColor solidOrange(140, 70, 0);
  359. static kaleidoscope::plugin::LEDSolidColor solidYellow(130, 100, 0);
  360. static kaleidoscope::plugin::LEDSolidColor solidGreen(0, 160, 0);
  361. static kaleidoscope::plugin::LEDSolidColor solidBlue(0, 70, 130);
  362. static kaleidoscope::plugin::LEDSolidColor solidIndigo(0, 0, 170);
  363. static kaleidoscope::plugin::LEDSolidColor solidViolet(130, 0, 120);
  364.  
  365. /** toggleLedsOnSuspendResume toggles the LEDs off when the host goes to sleep,
  366.  * and turns them back on when it wakes up.
  367.  */
  368. void toggleLedsOnSuspendResume(kaleidoscope::plugin::HostPowerManagement::Event event) {
  369.   switch (event) {
  370.   case kaleidoscope::plugin::HostPowerManagement::Suspend:
  371.     LEDControl.set_all_leds_to({0, 0, 0});
  372.     LEDControl.syncLeds();
  373.     LEDControl.paused = true;
  374.     break;
  375.   case kaleidoscope::plugin::HostPowerManagement::Resume:
  376.     LEDControl.paused = false;
  377.     LEDControl.refreshAll();
  378.     break;
  379.   case kaleidoscope::plugin::HostPowerManagement::Sleep:
  380.     break;
  381.   }
  382. }
  383.  
  384. /** hostPowerManagementEventHandler dispatches power management events (suspend,
  385.  * resume, and sleep) to other functions that perform action based on these
  386.  * events.
  387.  */
  388. void hostPowerManagementEventHandler(kaleidoscope::plugin::HostPowerManagement::Event event) {
  389.   toggleLedsOnSuspendResume(event);
  390. }
  391.  
  392. /** This 'enum' is a list of all the magic combos used by the Model 01's
  393.  * firmware The names aren't particularly important. What is important is that
  394.  * each is unique.
  395.  *
  396.  * These are the names of your magic combos. They will be used by the
  397.  * `USE_MAGIC_COMBOS` call below.
  398.  */
  399. enum {
  400.   // Toggle between Boot (6-key rollover; for BIOSes and early boot) and NKRO
  401.   // mode.
  402.   COMBO_TOGGLE_NKRO_MODE,
  403.   // Enter test mode
  404.   COMBO_ENTER_TEST_MODE
  405. };
  406.  
  407. /** Wrappers, to be used by MagicCombo. **/
  408.  
  409. /**
  410.  * This simply toggles the keyboard protocol via USBQuirks, and wraps it within
  411.  * a function with an unused argument, to match what MagicCombo expects.
  412.  */
  413. static void toggleKeyboardProtocol(uint8_t combo_index) {
  414.   USBQuirks.toggleKeyboardProtocol();
  415. }
  416.  
  417. /**
  418.  *  This enters the hardware test mode
  419.  */
  420. static void enterHardwareTestMode(uint8_t combo_index) {
  421.   HardwareTestMode.runTests();
  422. }
  423.  
  424.  
  425. /** Magic combo list, a list of key combo and action pairs the firmware should
  426.  * recognise.
  427.  */
  428. USE_MAGIC_COMBOS({.action = toggleKeyboardProtocol,
  429.                   // Left Fn + Esc + Shift
  430.                   .keys = { R3C6, R2C6, R3C7 }
  431. }, {
  432.   .action = enterHardwareTestMode,
  433.   // Left Fn + Prog + LED
  434.   .keys = { R3C6, R0C0, R0C6 }
  435. });
  436.  
  437.  
  438. // First, tell Kaleidoscope which plugins you want to use.
  439. // The order can be important. For example, LED effects are
  440. // added in the order they're listed here.
  441. KALEIDOSCOPE_INIT_PLUGINS(
  442.   // The EEPROMSettings & EEPROMKeymap plugins make it possible to have an
  443.   // editable keymap in EEPROM.
  444.   EEPROMSettings,
  445.   EEPROMKeymap,
  446.  
  447.   // Focus allows bi-directional communication with the host, and is the
  448.   // interface through which the keymap in EEPROM can be edited.
  449.   Focus,
  450.  
  451.   // FocusSettingsCommand adds a few Focus commands, intended to aid in
  452.   // changing some settings of the keyboard, such as the default layer (via the
  453.   // `settings.defaultLayer` command)
  454.   FocusSettingsCommand,
  455.  
  456.   // FocusEEPROMCommand adds a set of Focus commands, which are very helpful in
  457.   // both debugging, and in backing up one's EEPROM contents.
  458.   FocusEEPROMCommand,
  459.  
  460.   // The boot greeting effect pulses the LED button for 10 seconds after the
  461.   // keyboard is first connected
  462.   BootGreetingEffect,
  463.  
  464.   // The hardware test mode, which can be invoked by tapping Prog, LED and the
  465.   // left Fn button at the same time.
  466.   HardwareTestMode,
  467.  
  468.   // LEDControl provides support for other LED modes
  469.   LEDControl,
  470.  
  471.   // We start with the LED effect that turns off all the LEDs.
  472.   LEDOff,
  473.  
  474.   // The rainbow effect changes the color of all of the keyboard's keys at the same time
  475.   // running through all the colors of the rainbow.
  476.   LEDRainbowEffect,
  477.  
  478.   // The rainbow wave effect lights up your keyboard with all the colors of a rainbow
  479.   // and slowly moves the rainbow across your keyboard
  480.   LEDRainbowWaveEffect,
  481.  
  482.   // The chase effect follows the adventure of a blue pixel which chases a red pixel across
  483.   // your keyboard. Spoiler: the blue pixel never catches the red pixel
  484.   LEDChaseEffect,
  485.  
  486.   // These static effects turn your keyboard's LEDs a variety of colors
  487.   solidRed, solidOrange, solidYellow, solidGreen, solidBlue, solidIndigo, solidViolet,
  488.  
  489.   // The breathe effect slowly pulses all of the LEDs on your keyboard
  490.   LEDBreatheEffect,
  491.  
  492.   // The AlphaSquare effect prints each character you type, using your
  493.   // keyboard's LEDs as a display
  494.   AlphaSquareEffect,
  495.  
  496.   // The stalker effect lights up the keys you've pressed recently
  497.   StalkerEffect,
  498.  
  499.   // The LED Palette Theme plugin provides a shared palette for other plugins,
  500.   // like Colormap below
  501.   LEDPaletteTheme,
  502.  
  503.   // The Colormap effect makes it possible to set up per-layer colormaps
  504.   ColormapEffect,
  505.  
  506.   // The numpad plugin is responsible for lighting up the 'numpad' mode
  507.   // with a custom LED effect
  508.   NumPad,
  509.  
  510.   // The macros plugin adds support for macros
  511.   Macros,
  512.  
  513.   // The MouseKeys plugin lets you add keys to your keymap which move the mouse.
  514.   MouseKeys,
  515.  
  516.   // The HostPowerManagement plugin allows us to turn LEDs off when then host
  517.   // goes to sleep, and resume them when it wakes up.
  518.   HostPowerManagement,
  519.  
  520.   // The MagicCombo plugin lets you use key combinations to trigger custom
  521.   // actions - a bit like Macros, but triggered by pressing multiple keys at the
  522.   // same time.
  523.  MagicCombo,
  524.  
  525.   // The USBQuirks plugin lets you do some things with USB that we aren't
  526.   // comfortable - or able - to do automatically, but can be useful
  527.   // nevertheless. Such as toggling the key report protocol between Boot (used
  528.   // by BIOSes) and Report (NKRO).
  529.   USBQuirks,
  530.  
  531. // Plugins added by Glenn
  532. FireEffect,
  533. WavepoolEffect,
  534. LEDRainbowEffect, LEDRainbowWaveEffect,
  535. LEDDigitalRainEffect
  536.  
  537. );
  538.  
  539. /** The 'setup' function is one of the two standard Arduino sketch functions.
  540.  * It's called when your keyboard first powers up. This is where you set up
  541.  * Kaleidoscope and any plugins.
  542.  */
  543. void setup() {
  544.   // First, call Kaleidoscope's internal setup function
  545.   Kaleidoscope.setup();
  546.  
  547.   // While we hope to improve this in the future, the NumPad plugin
  548.   // needs to be explicitly told which keymap layer is your numpad layer
  549.   NumPad.numPadLayer = NUMPAD;
  550.  
  551.   // We configure the AlphaSquare effect to use RED letters
  552.   AlphaSquare.color = CRGB(255, 0, 0);
  553.  
  554.   // We set the brightness of the rainbow effects to 150 (on a scale of 0-255)
  555.   // This draws more than 500mA, but looks much nicer than a dimmer effect
  556.   LEDRainbowEffect.brightness(150);
  557.   LEDRainbowWaveEffect.brightness(150);
  558.  
  559.   // Set the action key the test mode should listen for to Left Fn
  560.   HardwareTestMode.setActionKey(R3C6);
  561.  
  562.   // The LED Stalker mode has a few effects. The one we like is called
  563.   // 'BlazingTrail'. For details on other options, see
  564.   // https://github.com/keyboardio/Kaleidoscope/blob/master/doc/plugin/LED-Stalker.md
  565.   StalkerEffect.variant = STALKER(BlazingTrail);
  566.  
  567.   // We want to make sure that the firmware starts with LED effects off
  568.   // This avoids over-taxing devices that don't have a lot of power to share
  569.   // with USB devices
  570.   LEDOff.activate();
  571.  
  572.   // To make the keymap editable without flashing new firmware, we store
  573.   // additional layers in EEPROM. For now, we reserve space for five layers. If
  574.   // one wants to use these layers, just set the default layer to one in EEPROM,
  575.   // by using the `settings.defaultLayer` Focus command, or by using the
  576.   // `keymap.onlyCustom` command to use EEPROM layers only.
  577.   EEPROMKeymap.setup(5);
  578.  
  579.   // We need to tell the Colormap plugin how many layers we want to have custom
  580.   // maps for. To make things simple, we set it to five layers, which is how
  581.   // many editable layers we have (see above).
  582.   ColormapEffect.max_layers(5);
  583.  
  584.   // Plugins added by Glenn
  585.   FireEffect.activate();
  586.  
  587.   WavepoolEffect.idle_timeout = 5000;  // 5 seconds
  588.   WavepoolEffect.activate();
  589.  
  590.   LEDRainbowEffect.brightness(150);
  591.   LEDRainbowWaveEffect.brightness(150);
  592.   LEDRainbowWaveEffect.update_delay(50);
  593.  
  594.   LEDDigitalRainEffect.DROP_TICKS = 22; // Make the rain fall faster
  595.  
  596. }
  597.  
  598. /** loop is the second of the standard Arduino sketch functions.
  599.   * As you might expect, it runs in a loop, never exiting.
  600.   *
  601.   * For Kaleidoscope-based keyboard firmware, you usually just want to
  602.   * call Kaleidoscope.loop(); and not do anything custom here.
  603.   */
  604.  
  605. void loop() {
  606.   Kaleidoscope.loop();
  607. }
Advertisement
RAW Paste Data Copied
Advertisement