diff Output/pjrcUSB/arm/usb_keyboard.c @ 368:06a54d582bf8

FIxing Media Keys and general USB compatibilty - Media keys tested working on Linux/Windows/Mac (use Consumer control) - Fixed enumeration delays - Fixed virtual serial port configuration issues - Fixed GET_REPORT and SET_REPORT - Added intial descriptors and endpoints for Mouse and Joystick devices - Split out the consumer and system control endpoint - Added more fault debugging messages - Added interface names to endpoints (visible in Windows Device Manager) - Added KLL define for keyboard locale
author Jacob Alexander <haata@kiibohd.com>
date Wed, 19 Aug 2015 00:01:15 -0700
parents 1beec5f17e64
children 68e19d7c953e
line wrap: on
line diff
--- a/Output/pjrcUSB/arm/usb_keyboard.c	Tue Aug 18 10:46:55 2015 -0700
+++ b/Output/pjrcUSB/arm/usb_keyboard.c	Wed Aug 19 00:01:15 2015 -0700
@@ -52,10 +52,16 @@
 // When the PC isn't listening, how long do we wait before discarding data?
 #define TX_TIMEOUT_MSEC 50
 
-#if F_CPU == 96000000
+#if F_CPU == 168000000
+	#define TX_TIMEOUT (TX_TIMEOUT_MSEC * 1100)
+#elif F_CPU == 144000000
+	#define TX_TIMEOUT (TX_TIMEOUT_MSEC * 932)
+#elif F_CPU == 120000000
+	#define TX_TIMEOUT (TX_TIMEOUT_MSEC * 764)
+#elif F_CPU == 96000000
 	#define TX_TIMEOUT (TX_TIMEOUT_MSEC * 596)
 #elif F_CPU == 72000000
-	#define TX_TIMEOUT (TX_TIMEOUT_MSEC * 512) // XXX Correct?
+	#define TX_TIMEOUT (TX_TIMEOUT_MSEC * 512)
 #elif F_CPU == 48000000
 	#define TX_TIMEOUT (TX_TIMEOUT_MSEC * 428)
 #elif F_CPU == 24000000
@@ -89,7 +95,7 @@
 
 		if ( USBKeys_Protocol == 0 ) // Boot Mode
 		{
-			if ( usb_tx_packet_count( NKRO_KEYBOARD_ENDPOINT ) < TX_PACKET_LIMIT )
+			if ( usb_tx_packet_count( KEYBOARD_ENDPOINT ) < TX_PACKET_LIMIT )
 			{
 				tx_packet = usb_malloc();
 				if ( tx_packet )
@@ -98,7 +104,18 @@
 		}
 		else if ( USBKeys_Protocol == 1 ) // NKRO Mode
 		{
-			if ( usb_tx_packet_count( KEYBOARD_ENDPOINT ) < TX_PACKET_LIMIT )
+			if ( usb_tx_packet_count( NKRO_KEYBOARD_ENDPOINT ) < TX_PACKET_LIMIT )
+			{
+				tx_packet = usb_malloc();
+				if ( tx_packet )
+					break;
+			}
+		}
+		else if ( USBKeys_Changed &
+			( USBKeyChangeState_System | USBKeyChangeState_Consumer )
+		)
+		{
+			if ( usb_tx_packet_count( SYS_CTRL_ENDPOINT ) < TX_PACKET_LIMIT )
 			{
 				tx_packet = usb_malloc();
 				if ( tx_packet )
@@ -118,6 +135,47 @@
 	// Pointer to USB tx packet buffer
 	uint8_t *tx_buf = tx_packet->buf;
 
+	// Check system control keys
+	if ( USBKeys_Changed & USBKeyChangeState_System )
+	{
+		if ( Output_DebugMode )
+		{
+			print("SysCtrl[");
+			printHex_op( USBKeys_SysCtrl, 2 );
+			print( "] " NL );
+		}
+
+		*tx_buf++ = 0x02; // ID
+		*tx_buf   = USBKeys_SysCtrl;
+		tx_packet->len = 2;
+
+		// Send USB Packet
+		usb_tx( SYS_CTRL_ENDPOINT, tx_packet );
+		USBKeys_Changed &= ~USBKeyChangeState_System; // Mark sent
+		return;
+	}
+
+	// Check consumer control keys
+	if ( USBKeys_Changed & USBKeyChangeState_Consumer )
+	{
+		if ( Output_DebugMode )
+		{
+			print("ConsCtrl[");
+			printHex_op( USBKeys_ConsCtrl, 2 );
+			print( "] " NL );
+		}
+
+		*tx_buf++ = 0x03; // ID
+		*tx_buf++ = (uint8_t)(USBKeys_ConsCtrl & 0x00FF);
+		*tx_buf   = (uint8_t)(USBKeys_ConsCtrl >> 8);
+		tx_packet->len = 3;
+
+		// Send USB Packet
+		usb_tx( SYS_CTRL_ENDPOINT, tx_packet );
+		USBKeys_Changed &= ~USBKeyChangeState_Consumer; // Mark sent
+		return;
+	}
+
 	switch ( USBKeys_Protocol )
 	{
 	// Send boot keyboard interrupt packet(s)
@@ -157,45 +215,6 @@
 			dbug_msg("NKRO USB: ");
 		}
 
-		// Check system control keys
-		if ( USBKeys_Changed & USBKeyChangeState_System )
-		{
-			if ( Output_DebugMode )
-			{
-				print("SysCtrl[");
-				printHex_op( USBKeys_SysCtrl, 2 );
-				print( "] " NL );
-			}
-
-			*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_System; // Mark sent
-		}
-
-		// Check consumer control keys
-		if ( USBKeys_Changed & USBKeyChangeState_Consumer )
-		{
-			if ( Output_DebugMode )
-			{
-				print("ConsCtrl[");
-				printHex_op( USBKeys_ConsCtrl, 2 );
-				print( "] " NL );
-			}
-
-			*tx_buf++ = 0x03; // 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
-		}
-
 		// Standard HID Keyboard
 		if ( USBKeys_Changed )
 		{