diff --git a/README.md b/README.md index 6596dc33..a01de8c6 100644 --- a/README.md +++ b/README.md @@ -151,6 +151,7 @@ To avoid configuring accidentally additive salt key `KC_SPACE` also needs to be - Disable Gui(`Left Gui`) - Swap Grave and Escape(`Grave`) - Swap BackSlash and BackSpace(`Back Slash`) +- Enable NKRO on boot(`N`) #### Default Layer - Set Default Layer to 0(`0`) diff --git a/common/bootmagic.c b/common/bootmagic.c index 1668ee49..7649a197 100644 --- a/common/bootmagic.c +++ b/common/bootmagic.c @@ -5,6 +5,7 @@ #include "bootloader.h" #include "debug.h" #include "keymap.h" +#include "host.h" #include "action_layer.h" #include "eeconfig.h" #include "keymap_in_eeprom.h" @@ -81,8 +82,15 @@ void bootmagic(void) if (bootmagic_scan_keycode(BOOTMAGIC_KEY_SWAP_BACKSLASH_BACKSPACE)) { keymap_config.swap_backslash_backspace = !keymap_config.swap_backslash_backspace; } + if (bootmagic_scan_keycode(BOOTMAGIC_HOST_NKRO)) { + keymap_config.nkro = !keymap_config.nkro; + } eeconfig_write_keymap(keymap_config.raw); +#ifdef NKRO_ENABLE + keyboard_nkro = keymap_config.nkro; +#endif + /* default layer */ uint8_t default_layer = 0; if (bootmagic_scan_keycode(BOOTMAGIC_KEY_DEFAULT_LAYER_0)) { default_layer |= (1<<0); } diff --git a/common/bootmagic.h b/common/bootmagic.h index 7c192239..8f6618f4 100644 --- a/common/bootmagic.h +++ b/common/bootmagic.h @@ -60,6 +60,9 @@ #ifndef BOOTMAGIC_KEY_SWAP_BACKSLASH_BACKSPACE #define BOOTMAGIC_KEY_SWAP_BACKSLASH_BACKSPACE KC_BSLASH #endif +#ifndef BOOTMAGIC_HOST_NKRO +#define BOOTMAGIC_HOST_NKRO KC_N +#endif /* diff --git a/common/command.c b/common/command.c index d2f8eb83..2c65f0da 100644 --- a/common/command.c +++ b/common/command.c @@ -151,6 +151,7 @@ static void print_eeconfig(void) print(".no_gui: "); print_dec(kc.no_gui); print("\n"); print(".swap_grave_esc: "); print_dec(kc.swap_grave_esc); print("\n"); print(".swap_backslash_backspace: "); print_dec(kc.swap_backslash_backspace); print("\n"); + print(".nkro: "); print_dec(kc.nkro); print("\n"); #ifdef BACKLIGHT_ENABLE backlight_config_t bc; diff --git a/common/eeconfig.h b/common/eeconfig.h index e1b5ae28..3cd1a174 100644 --- a/common/eeconfig.h +++ b/common/eeconfig.h @@ -47,6 +47,7 @@ along with this program. If not, see . #define EECONFIG_KEYMAP_NO_GUI (1<<4) #define EECONFIG_KEYMAP_SWAP_GRAVE_ESC (1<<5) #define EECONFIG_KEYMAP_SWAP_BACKSLASH_BACKSPACE (1<<6) +#define EECONFIG_KEYMAP_NKRO (1<<7) bool eeconfig_is_enabled(void); diff --git a/common/keymap.h b/common/keymap.h index bf32aced..4c3019a3 100644 --- a/common/keymap.h +++ b/common/keymap.h @@ -35,7 +35,7 @@ typedef union { bool no_gui:1; bool swap_grave_esc:1; bool swap_backslash_backspace:1; - bool reserved:1; + bool nkro:1; }; } keymap_config_t; keymap_config_t keymap_config; diff --git a/doc/build.md b/doc/build.md index c7522e4d..438ce153 100644 --- a/doc/build.md +++ b/doc/build.md @@ -5,23 +5,22 @@ Build Firmware and Program Controller Download and Install -------------------- ### 1. Install Tools -First, you need tools to build firmware and program your controller. I assume you are on Windows here. -1. **Toolchain** Install [WinAVR][winavr]. This is old but works well for this purpose. `WinAVR` is a tool set to build firmware including C compiler(gcc) and make commands. You can use [CrossPack][crosspack] instead if you are on Mac. +1. **Toolchain** On Windows install [MHV AVR Tools][mhv] for AVR GCC compiler and [Cygwin][cygwin](or [MinGW][mingw]) for shell terminal. On Mac you can use [CrossPack][crosspack]. On Linux you can install AVR GCC with your favorite package manager. -2. **Programmer** Install [Atmel FLIP][flip]. `FLIP` is a tool to program(load) firmware into AVR controller via DFU bootloader. AVR USB chips including ATmega32U4 has DFU bootloader by factory default. You can also use [dfu-programmer][dfu-prog] instead if you are on Mac or Linux. +2. **Programmer** On Windows install [Atmel FLIP][flip]. On Mac and Linux install [dfu-programmer][dfu-prog]. -3. **Driver** At first time you start DFU bootloader on Chip 'Found New Hardware Wizard' will come up on Windows. If you install device driver properly you can find chip name like 'ATmega32U4' under 'LibUSB-Win32 Devices' tree on 'Device Manager'. If not you shall need to update its driver on 'Device Manager'. You will find the driver in `FLIP` install directory like: C:\Program Files (x86)\Atmel\Flip 3.4.5\usb\. If you use `dfu-programmer` install its driver. +3. **Driver** On Windows you start DFU bootloader on the chip first time you will see 'Found New Hardware Wizard' to install driver. If you install device driver properly you can find chip name like 'ATmega32U4' under 'LibUSB-Win32 Devices' tree on 'Device Manager'. If not you shall need to update its driver on 'Device Manager'. You will find the driver in `FLIP` install directory like: C:\Program Files (x86)\Atmel\Flip 3.4.5\usb\. In case of `dfu-programmer` use its driver. If you use PJRC Teensy you don't need step 2 and 3 above, just get [Teensy loader][teensy-loader]. ### 2. Download source -You can find firmware source at github: +You can find firmware source at github: - -If you are familiar with `Git` tools you are recommended to use it but you can also download zip archive from: +If you are familiar with `Git` tools you are recommended to use it but you can also download zip archive from: - @@ -29,7 +28,7 @@ If you are familiar with `Git` tools you are recommended to use it but you can a Build firmware -------------- ### 1. Open terminal -Open terminal window to get access to commands. You can use `cmd` in Windows or `Terminal.app` on Mac OSX. In Windows press `Windows` key and `R` then enter `cmd` in 'Run command' dialog showing up. +Open terminal window to get access to commands. Use Cygwin(or MingGW) `shell terminal` in Windows or `Terminal.app` on Mac OSX. In Windows press `Windows` key and `R` then enter `cmd` in 'Run command' dialog showing up. ### 2. Change directory Move to project directory in the firmware source. @@ -100,6 +99,9 @@ You may want to use other programmer like `avrdude` with AVRISPmkII, Arduino or $ make -f Makefile. program +[cygwin]: https://www.cygwin.com/ +[mingw]: http://www.mingw.org/ +[mhv]: https://infernoembedded.com/products/avr-tools [winavr]: http://winavr.sourceforge.net/ [crosspack]: http://www.obdev.at/products/crosspack/index.html [flip]: http://www.atmel.com/tools/FLIP.aspx @@ -116,14 +118,18 @@ Makefile Options #MCU = at90usb1286 # Teensy++ 2.0 F_CPU = 16000000 +Set your MCU and its clock in Hz. + # Boot Section Size in *bytes* # Teensy halfKay 512 # Atmel DFU loader 4096 # LUFA bootloader 4096 OPT_DEFS += -DBOOTLOADER_SIZE=4096 +If you are using PJRC Teensy use `512` for `BOOTLOADER_SIZE`, otherwise use `4096` unless you are sure. + ### 2. Features -Optional. Note that ***comment out*** to disable them. +Optional. Note that ***comment out*** with `#` to disable them. BOOTMAGIC_ENABLE = yes # Virtual DIP switch configuration(+1000) MOUSEKEY_ENABLE = yes # Mouse keys(+4700) @@ -153,7 +159,7 @@ Config.h Options ---------------- ### 1. Magic command key combination - #define IS_COMMAND() (keyboard_report->mods == (MOD_BIT(KB_LSHIFT) | MOD_BIT(KB_RSHIFT))) + #define IS_COMMAND() (keyboard_report->mods == (MOD_BIT(KB_LSHIFT) | MOD_BIT(KB_RSHIFT))) ### 2. Mechanical Locking Support for CapsLock diff --git a/protocol/adb.c b/protocol/adb.c index a4783f36..f57afac9 100644 --- a/protocol/adb.c +++ b/protocol/adb.c @@ -128,6 +128,10 @@ uint16_t adb_host_kbd_recv(void) attention(); send_byte(0x2C); // Addr:Keyboard(0010), Cmd:Talk(11), Register0(00) place_bit0(); // Stopbit(0) + if (!wait_data_hi(500)) { // Service Request(310us Adjustable Keyboard): just ignored + sei(); + return -30; // something wrong + } if (!wait_data_lo(500)) { // Tlt/Stop to Start(140-260us) sei(); return 0; // No data to send diff --git a/protocol/lufa/lufa.c b/protocol/lufa/lufa.c index d60aecc3..16a602df 100644 --- a/protocol/lufa/lufa.c +++ b/protocol/lufa/lufa.c @@ -272,7 +272,9 @@ void EVENT_USB_Device_ControlRequest(void) // Interface switch (USB_ControlRequest.wIndex) { case KEYBOARD_INTERFACE: +#ifdef NKRO_ENABLE case NKRO_INTERFACE: +#endif Endpoint_ClearSETUP(); while (!(Endpoint_IsOUTReceived())) { diff --git a/protocol/ps2_mouse.c b/protocol/ps2_mouse.c index 4702f12c..c3e8b3c1 100644 --- a/protocol/ps2_mouse.c +++ b/protocol/ps2_mouse.c @@ -82,9 +82,14 @@ void ps2_mouse_task(void) mouse_report.x = ps2_host_recv_response(); mouse_report.y = ps2_host_recv_response(); } else { - if (!debug_mouse) print("ps2_mouse: fail to get mouse packet\n"); + if (debug_mouse) print("ps2_mouse: fail to get mouse packet\n"); return; } + xprintf("%ud ", timer_read()); + print("ps2_mouse raw: ["); + phex(mouse_report.buttons); print("|"); + print_hex8((uint8_t)mouse_report.x); print(" "); + print_hex8((uint8_t)mouse_report.y); print("]\n"); /* if mouse moves or buttons state changes */ if (mouse_report.x || mouse_report.y ||