]> git.donarmstrong.com Git - kiibohd-controller.git/blobdiff - Output/pjrcUSB/arm/usb_keyboard.c
Fixing NKRO on Windows 8.1
[kiibohd-controller.git] / Output / pjrcUSB / arm / usb_keyboard.c
index 722ae8dccf1a957ce5c5f27d5aeaa62cad8ee522..24c60bf5fa422a2e22f978bf05f24093c6e436ef 100644 (file)
@@ -133,91 +133,63 @@ void usb_keyboard_send()
 
        // Send NKRO keyboard interrupts packet(s)
        case 1:
-               // Check modifiers
-               if ( USBKeys_Changed & USBKeyChangeState_Modifiers )
+               // Check system control keys
+               if ( USBKeys_Changed & USBKeyChangeState_System )
                {
-                       *tx_buf++ = 0x01; // ID
-                       *tx_buf   = USBKeys_Modifiers;
+                       *tx_buf++ = 0x02; // ID
+                       *tx_buf   = USBKeys_SysCtrl;
                        tx_packet->len = 2;
 
                        // Send USB Packet
                        usb_tx( NKRO_KEYBOARD_ENDPOINT, tx_packet );
-                       USBKeys_Changed &= ~USBKeyChangeState_Modifiers; // Mark sent
+                       USBKeys_Changed &= ~USBKeyChangeState_System; // Mark sent
                }
-               // Check main key section
-               else if ( USBKeys_Changed & USBKeyChangeState_MainKeys )
+
+               // Check consumer control keys
+               if ( USBKeys_Changed & USBKeyChangeState_Consumer )
                {
                        *tx_buf++ = 0x03; // ID
-
-                       // 4-49 (first 6 bytes)
-                       memcpy( tx_buf, USBKeys_Keys, 6 );
-                       tx_packet->len = 7;
+                       *tx_buf++ = (uint8_t)(USBKeys_ConsCtrl & 0x00FF);
+                       *tx_buf   = (uint8_t)(USBKeys_ConsCtrl >> 8);
+                       tx_packet->len = 3;
 
                        // Send USB Packet
                        usb_tx( NKRO_KEYBOARD_ENDPOINT, tx_packet );
-                       USBKeys_Changed &= ~USBKeyChangeState_MainKeys; // Mark sent
+                       USBKeys_Changed &= ~USBKeyChangeState_Consumer; // Mark sent
                }
-               // Check secondary key section
-               else if ( USBKeys_Changed & USBKeyChangeState_SecondaryKeys )
+
+               // Standard HID Keyboard
+               if ( USBKeys_Changed )
                {
-                       *tx_buf++ = 0x04; // ID
+                       tx_packet->len = 0;
+
+                       // Modifiers
+                       *tx_buf++ = 0x01; // ID
+                       *tx_buf++ = USBKeys_Modifiers;
+                       tx_packet->len += 2;
+
+                       // 4-49 (first 6 bytes)
+                       memcpy( tx_buf, USBKeys_Keys, 6 );
+                       tx_buf += 6;
+                       tx_packet->len += 6;
 
                        // 51-155 (Middle 14 bytes)
                        memcpy( tx_buf, USBKeys_Keys + 6, 14 );
-                       tx_packet->len = 15;
-
-                       // Send USB Packet
-                       usb_tx( NKRO_KEYBOARD_ENDPOINT, tx_packet );
-                       USBKeys_Changed &= ~USBKeyChangeState_SecondaryKeys; // Mark sent
-               }
-               // Check tertiary key section
-               else if ( USBKeys_Changed & USBKeyChangeState_TertiaryKeys )
-               {
-                       *tx_buf++ = 0x05; // ID
+                       tx_buf += 14;
+                       tx_packet->len += 14;
 
                        // 157-164 (Next byte)
                        memcpy( tx_buf, USBKeys_Keys + 20, 1 );
-                       tx_packet->len = 2;
-
-                       // Send USB Packet
-                       usb_tx( NKRO_KEYBOARD_ENDPOINT, tx_packet );
-                       USBKeys_Changed &= ~USBKeyChangeState_TertiaryKeys; // Mark sent
-               }
-               // Check quartiary key section
-               else if ( USBKeys_Changed & USBKeyChangeState_QuartiaryKeys )
-               {
-                       *tx_buf++ = 0x06; // ID
+                       tx_buf += 1;
+                       tx_packet->len += 1;
 
                        // 176-221 (last 6 bytes)
                        memcpy( tx_buf, USBKeys_Keys + 21, 6 );
-                       tx_packet->len = 7;
-
-                       // Send USB Packet
-                       usb_tx( NKRO_KEYBOARD_ENDPOINT, tx_packet );
-                       USBKeys_Changed &= ~USBKeyChangeState_QuartiaryKeys; // Mark sent
-               }
-               // Check system control keys
-               else if ( USBKeys_Changed & USBKeyChangeState_System )
-               {
-                       *tx_buf++ = 0x07; // ID
-                       *tx_buf   = USBKeys_SysCtrl;
-                       tx_packet->len = 2;
-
-                       // Send USB Packet
-                       usb_tx( NKRO_KEYBOARD_ENDPOINT, tx_packet );
-                       USBKeys_Changed &= ~USBKeyChangeState_System; // Mark sent
-               }
-               // Check consumer control keys
-               else if ( USBKeys_Changed & USBKeyChangeState_Consumer )
-               {
-                       *tx_buf++ = 0x08; // ID
-                       *tx_buf++ = (uint8_t)(USBKeys_ConsCtrl & 0x00FF);
-                       *tx_buf   = (uint8_t)(USBKeys_ConsCtrl >> 8);
-                       tx_packet->len = 3;
+                       tx_packet->len += 6;
 
                        // Send USB Packet
                        usb_tx( NKRO_KEYBOARD_ENDPOINT, tx_packet );
-                       USBKeys_Changed &= ~USBKeyChangeState_Consumer; // Mark sent
+                       USBKeys_Changed = USBKeyChangeState_None; // Mark sent
                }
 
                break;