Advertisement
Guest User

Untitled

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