Advertisement
Guest User

Untitled

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