From 33bcc999b9b1beeb9418a9ff3907dc15b44ea47f Mon Sep 17 00:00:00 2001 From: Gergely Nagy Date: Fri, 8 Jun 2018 13:13:04 +0200 Subject: Add a way to toggle between Boot and NKRO mode manually Make use of the MagicCombo and USB-Quirks plugins in order to allow one to toggle between Boot and NKRO mode of the keyboard, simply by pressing Left Fn + Shift + Esc. Signed-off-by: Gergely Nagy --- Model01-Firmware.ino | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 62 insertions(+), 1 deletion(-) (limited to 'Model01-Firmware.ino') diff --git a/Model01-Firmware.ino b/Model01-Firmware.ino index eeef307..12c3b0a 100644 --- a/Model01-Firmware.ino +++ b/Model01-Firmware.ino @@ -59,6 +59,11 @@ // Support for host power management (suspend & wakeup) #include "Kaleidoscope-HostPowerManagement.h" +// Support for magic combos (key chrods that trigger an action) +#include "Kaleidoscope-MagicCombo.h" + +// Support for USB quirks, like changing the key state report protocol +#include "Kaleidoscope-USB-Quirks.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 @@ -279,6 +284,49 @@ void hostPowerManagementEventHandler(kaleidoscope::HostPowerManagement::Event ev toggleLedsOnSuspendResume(event); } +/** This 'enum' is a list of all the magic combos 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 magic combos. They'll be used in two places. + * + * The first is in the magic combo list, that pairs a name (or index, really) + * with keys. + * + * The second is in the 'switch' statement in the 'magicComboActions' function. + * That switch statement actually runs the code associated with the combo, when + * the combo is recognised. + */ +enum { COMBO_PROTOCOL_TOGGLE }; + +// Key combinations we want special actions for, to be used with the MagicCombo +// plugin. +static const kaleidoscope::MagicCombo::combo_t magic_combos[] PROGMEM = { + [COMBO_PROTOCOL_TOGGLE] = { + R3C6 | R2C6 | R3C7, // Left Fn + Esc + Shift + 0 + }, + {0, 0} // End-of-list marker. +}; + +/** magicComboActions dispatches combo events the MagicCombo plugin recognises. + + The first argument is the index of the combination, the next two are the + left- and right-hand states, as bit maps. For most cases, the index is + enough to decide how to handle the combination. + + The 'switch' statement should have a 'case' for each entry of the combo + enum. Each 'case' statement should call out to a function to handle the + combination in question. +*/ +void magicComboActions(uint8_t combo_index, uint32_t left_hand, uint32_t right_hand) { + switch (combo_index) { + case COMBO_PROTOCOL_TOGGLE: + USBQuirks.toggleKeyboardProtocol(); + break; + } +} + // First, 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. @@ -332,7 +380,16 @@ KALEIDOSCOPE_INIT_PLUGINS( // The HostPowerManagement plugin allows us to turn LEDs off when then host // goes to sleep, and resume them when it wakes up. - HostPowerManagement + HostPowerManagement, + + // The MagicCombo plugin lets you use key combinations to trigger custom + // actions - a bit like Macros, but use multiple keys instead of one. + MagicCombo, + + // The USBQuriks plugin lets you do some quirky business with USB, such as + // toggling the key report protocol between Boot (used by BIOSes) and Report + // (NKRO). + USBQuirks ); /** The 'setup' function is one of the two standard Arduino sketch functions. @@ -360,6 +417,10 @@ void setup() { // see https://github.com/keyboardio/Kaleidoscope-LED-Stalker StalkerEffect.variant = STALKER(BlazingTrail); + // For the MagicCombo plugin to work, we need to tell it what combos we care + // about. + MagicCombo.magic_combos = magic_combos; + // 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 -- cgit v1.2.3 From 583d5429cd1ed65956a96af8630d733bfd88b072 Mon Sep 17 00:00:00 2001 From: Gergely Nagy Date: Sat, 9 Jun 2018 13:13:46 +0200 Subject: Updated to use the new MagicCombo APIs Signed-off-by: Gergely Nagy --- Model01-Firmware.ino | 50 ++++++++++++-------------------------------------- 1 file changed, 12 insertions(+), 38 deletions(-) (limited to 'Model01-Firmware.ino') diff --git a/Model01-Firmware.ino b/Model01-Firmware.ino index 12c3b0a..f04ade8 100644 --- a/Model01-Firmware.ino +++ b/Model01-Firmware.ino @@ -288,45 +288,23 @@ void hostPowerManagementEventHandler(kaleidoscope::HostPowerManagement::Event ev * firmware The names aren't particularly important. What is important is that * each is unique. * - * These are the names of your magic combos. They'll be used in two places. - * - * The first is in the magic combo list, that pairs a name (or index, really) - * with keys. - * - * The second is in the 'switch' statement in the 'magicComboActions' function. - * That switch statement actually runs the code associated with the combo, when - * the combo is recognised. + * These are the names of your magic combos. They will be used by the + * `USE_MAGIC_COMBOS` call below. */ enum { COMBO_PROTOCOL_TOGGLE }; -// Key combinations we want special actions for, to be used with the MagicCombo -// plugin. -static const kaleidoscope::MagicCombo::combo_t magic_combos[] PROGMEM = { - [COMBO_PROTOCOL_TOGGLE] = { - R3C6 | R2C6 | R3C7, // Left Fn + Esc + Shift - 0 - }, - {0, 0} // End-of-list marker. -}; - -/** magicComboActions dispatches combo events the MagicCombo plugin recognises. - - The first argument is the index of the combination, the next two are the - left- and right-hand states, as bit maps. For most cases, the index is - enough to decide how to handle the combination. - - The 'switch' statement should have a 'case' for each entry of the combo - enum. Each 'case' statement should call out to a function to handle the - combination in question. -*/ -void magicComboActions(uint8_t combo_index, uint32_t left_hand, uint32_t right_hand) { - switch (combo_index) { - case COMBO_PROTOCOL_TOGGLE: - USBQuirks.toggleKeyboardProtocol(); - break; - } +static void toggleKeyboardProtocol(uint8_t combo_index) { + USBQuirks.toggleKeyboardProtocol(); } +/** Magic combo list, a list of key combo and action pairs the firmware should + * recognise. + */ +USE_MAGIC_COMBOS([COMBO_PROTOCOL_TOGGLE] = {.action = toggleKeyboardProtocol, + // Left Fn + Esc + Shift + .keys = { R3C6, R2C6, R3C7 } + }); + // First, 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. @@ -417,10 +395,6 @@ void setup() { // see https://github.com/keyboardio/Kaleidoscope-LED-Stalker StalkerEffect.variant = STALKER(BlazingTrail); - // For the MagicCombo plugin to work, we need to tell it what combos we care - // about. - MagicCombo.magic_combos = magic_combos; - // 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 -- cgit v1.2.3 From 1e6c2c702c98a087fdfc01c12cef705c6ba693af Mon Sep 17 00:00:00 2001 From: Gergely Nagy Date: Sun, 1 Jul 2018 23:06:11 +0200 Subject: Documentation fixups Fixed up some of the USBQuirks and MagicCombo-related documentation, based on feedback from @obra. Signed-off-by: Gergely Nagy --- Model01-Firmware.ino | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) (limited to 'Model01-Firmware.ino') diff --git a/Model01-Firmware.ino b/Model01-Firmware.ino index f04ade8..cca405c 100644 --- a/Model01-Firmware.ino +++ b/Model01-Firmware.ino @@ -291,7 +291,11 @@ void hostPowerManagementEventHandler(kaleidoscope::HostPowerManagement::Event ev * These are the names of your magic combos. They will be used by the * `USE_MAGIC_COMBOS` call below. */ -enum { COMBO_PROTOCOL_TOGGLE }; +enum { + // Toggle between Boot (6-key rollover; for BIOSes and early boot) and NKRO + // mode. + COMBO_TOGGLE_NKRO_MODE +}; static void toggleKeyboardProtocol(uint8_t combo_index) { USBQuirks.toggleKeyboardProtocol(); @@ -300,10 +304,10 @@ static void toggleKeyboardProtocol(uint8_t combo_index) { /** Magic combo list, a list of key combo and action pairs the firmware should * recognise. */ -USE_MAGIC_COMBOS([COMBO_PROTOCOL_TOGGLE] = {.action = toggleKeyboardProtocol, - // Left Fn + Esc + Shift - .keys = { R3C6, R2C6, R3C7 } - }); +USE_MAGIC_COMBOS([COMBO_TOGGLE_NKRO_MODE] = {.action = toggleKeyboardProtocol, + // Left Fn + Esc + Shift + .keys = { R3C6, R2C6, R3C7 } + }); // First, tell Kaleidoscope which plugins you want to use. // The order can be important. For example, LED effects are @@ -361,12 +365,14 @@ KALEIDOSCOPE_INIT_PLUGINS( HostPowerManagement, // The MagicCombo plugin lets you use key combinations to trigger custom - // actions - a bit like Macros, but use multiple keys instead of one. + // actions - a bit like Macros, but triggered by pressing multiple keys at the + // same time. MagicCombo, - // The USBQuriks plugin lets you do some quirky business with USB, such as - // toggling the key report protocol between Boot (used by BIOSes) and Report - // (NKRO). + // The USBQuirks plugin lets you do some things with USB that we aren't + // comfortable - or able - to do automatically, but can be useful + // nevertheless. Such as toggling the key report protocol between Boot (used + // by BIOSes) and Report (NKRO). USBQuirks ); -- cgit v1.2.3 From d9c5d7022f04d1362939de615910df8f9e18c2a8 Mon Sep 17 00:00:00 2001 From: Gergely Nagy Date: Mon, 2 Jul 2018 23:44:32 +0200 Subject: Don't use an enum for MagicCombo. Since we use a dedicated function for the single magic combo we have, using an enum in this case is just more confusing than if we didn't. For this reason, drop the use of enum, and just specify the array directly. Thanks @obra for the suggestion! Signed-off-by: Gergely Nagy --- Model01-Firmware.ino | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'Model01-Firmware.ino') diff --git a/Model01-Firmware.ino b/Model01-Firmware.ino index cca405c..bc45ee3 100644 --- a/Model01-Firmware.ino +++ b/Model01-Firmware.ino @@ -297,6 +297,10 @@ enum { COMBO_TOGGLE_NKRO_MODE }; +/** A tiny wrapper, to be used by MagicCombo. + * This simply toggles the keyboard protocol via USBQuirks, and wraps it within + * a function with an unused argument, to match what MagicCombo expects. + */ static void toggleKeyboardProtocol(uint8_t combo_index) { USBQuirks.toggleKeyboardProtocol(); } @@ -304,10 +308,10 @@ static void toggleKeyboardProtocol(uint8_t combo_index) { /** Magic combo list, a list of key combo and action pairs the firmware should * recognise. */ -USE_MAGIC_COMBOS([COMBO_TOGGLE_NKRO_MODE] = {.action = toggleKeyboardProtocol, - // Left Fn + Esc + Shift - .keys = { R3C6, R2C6, R3C7 } - }); +USE_MAGIC_COMBOS({.action = toggleKeyboardProtocol, + // Left Fn + Esc + Shift + .keys = { R3C6, R2C6, R3C7 } + }); // First, tell Kaleidoscope which plugins you want to use. // The order can be important. For example, LED effects are -- cgit v1.2.3