]> git.donarmstrong.com Git - kiibohd-controller.git/commitdiff
USB NKRO working for ARM!
authorJacob Alexander <haata@kiibohd.com>
Mon, 29 Sep 2014 00:24:52 +0000 (17:24 -0700)
committerJacob Alexander <haata@kiibohd.com>
Mon, 29 Sep 2014 00:24:52 +0000 (17:24 -0700)
- Setting NKRO mode as default (up to bios to disable)

Output/pjrcUSB/arm/usb_keyboard.c
Output/pjrcUSB/output_com.c

index 07ef394c2e157604b9439ccc2e66f4dba69c63eb..a5fc2559e4d1e1e814c6d78097c211b8178b384a 100644 (file)
@@ -76,6 +76,7 @@ void usb_keyboard_send()
        uint32_t wait_count = 0;
        usb_packet_t *tx_packet;
 
+       // Wait till ready
        while ( 1 )
        {
                if ( !usb_configuration )
@@ -83,12 +84,26 @@ void usb_keyboard_send()
                        erro_print("USB not configured...");
                        return;
                }
-               if ( usb_tx_packet_count(KEYBOARD_ENDPOINT) < TX_PACKET_LIMIT )
+
+               if ( USBKeys_Protocol == 0 ) // Boot Mode
+               {
+                       if ( usb_tx_packet_count( NKRO_KEYBOARD_ENDPOINT ) < TX_PACKET_LIMIT )
+                       {
+                               tx_packet = usb_malloc();
+                               if ( tx_packet )
+                                       break;
+                       }
+               }
+               else if ( USBKeys_Protocol == 1 ) // NKRO Mode
                {
-                       tx_packet = usb_malloc();
-                       if ( tx_packet )
-                               break;
+                       if ( usb_tx_packet_count( KEYBOARD_ENDPOINT ) < TX_PACKET_LIMIT )
+                       {
+                               tx_packet = usb_malloc();
+                               if ( tx_packet )
+                                       break;
+                       }
                }
+
                if ( ++wait_count > TX_TIMEOUT || transmit_previous_timeout )
                {
                        transmit_previous_timeout = 1;
@@ -98,15 +113,89 @@ void usb_keyboard_send()
                yield();
        }
 
-       // Boot Mode
-       *(tx_packet->buf) = USBKeys_Modifiers;
-       *(tx_packet->buf + 1) = 0;
-       memcpy( tx_packet->buf + 2, USBKeys_Keys, USB_BOOT_MAX_KEYS );
-       tx_packet->len = 8;
+       // Pointer to USB tx packet buffer
+       uint8_t *tx_buf = tx_packet->buf;
+
+       switch ( USBKeys_Protocol )
+       {
+       // Send boot keyboard interrupt packet(s)
+       case 0:
+               // Boot Mode
+               *tx_buf++ = USBKeys_Modifiers;
+               *tx_buf++ = 0;
+               memcpy( tx_buf, USBKeys_Keys, USB_BOOT_MAX_KEYS );
+               tx_packet->len = 8;
+
+               // Send USB Packet
+               usb_tx( KEYBOARD_ENDPOINT, tx_packet );
+               USBKeys_Changed = USBKeyChangeState_None;
+               break;
+
+       // Send NKRO keyboard interrupts packet(s)
+       case 1:
+               // Check modifiers
+               if ( USBKeys_Changed & USBKeyChangeState_Modifiers )
+               {
+                       *tx_buf++ = 0x01; // ID
+                       *tx_buf   = USBKeys_Modifiers;
+                       tx_packet->len = 2;
+
+                       // Send USB Packet
+                       usb_tx( NKRO_KEYBOARD_ENDPOINT, tx_packet );
+                       USBKeys_Changed &= ~USBKeyChangeState_Modifiers; // Mark sent
+               }
+               // Check main key section
+               else if ( USBKeys_Changed & USBKeyChangeState_MainKeys )
+               {
+                       *tx_buf++ = 0x03; // ID
+
+                       // 4-164 (first 20 bytes)
+                       memcpy( tx_buf, USBKeys_Keys, 20 );
+                       tx_packet->len = 21;
 
-       // Send USB Packet
-       usb_tx( KEYBOARD_ENDPOINT, tx_packet );
-       USBKeys_Changed = USBKeyChangeState_None;
+                       // Send USB Packet
+                       usb_tx( NKRO_KEYBOARD_ENDPOINT, tx_packet );
+                       USBKeys_Changed &= ~USBKeyChangeState_MainKeys; // Mark sent
+               }
+               // Check secondary key section
+               else if ( USBKeys_Changed & USBKeyChangeState_SecondaryKeys )
+               {
+                       *tx_buf++ = 0x04; // ID
+
+                       // 176-221 (last 6 bytes)
+                       memcpy( tx_buf, USBKeys_Keys + 20, 6 );
+                       tx_packet->len = 7;
+
+                       // Send USB Packet
+                       usb_tx( NKRO_KEYBOARD_ENDPOINT, tx_packet );
+                       USBKeys_Changed &= ~USBKeyChangeState_SecondaryKeys; // Mark sent
+               }
+               // Check system control keys
+               else if ( USBKeys_Changed & USBKeyChangeState_System )
+               {
+                       *tx_buf++ = 0x05; // 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++ = 0x06; // ID
+                       *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_Consumer; // Mark sent
+               }
+
+               break;
+       }
 
        return;
 }
index 6bc027591199cc593780af012e4e619f086a76fd..5b562e94e6cb2a07464e18da01681a0b1ec5e5f3 100644 (file)
@@ -106,7 +106,7 @@ volatile uint8_t  USBKeys_LEDs = 0;
 // Protocol setting from the host.
 // 0 - Boot Mode
 // 1 - NKRO Mode (Default, unless set by a BIOS or boot interface)
-volatile uint8_t  USBKeys_Protocol = 0;
+volatile uint8_t  USBKeys_Protocol = 1;
 
 // Indicate if USB should send update
 // OS only needs update if there has been a change in state