comparison 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
comparison
equal deleted inserted replaced
367:8a6c2d410ad9 368:06a54d582bf8
50 #define TX_PACKET_LIMIT 4 50 #define TX_PACKET_LIMIT 4
51 51
52 // When the PC isn't listening, how long do we wait before discarding data? 52 // When the PC isn't listening, how long do we wait before discarding data?
53 #define TX_TIMEOUT_MSEC 50 53 #define TX_TIMEOUT_MSEC 50
54 54
55 #if F_CPU == 96000000 55 #if F_CPU == 168000000
56 #define TX_TIMEOUT (TX_TIMEOUT_MSEC * 1100)
57 #elif F_CPU == 144000000
58 #define TX_TIMEOUT (TX_TIMEOUT_MSEC * 932)
59 #elif F_CPU == 120000000
60 #define TX_TIMEOUT (TX_TIMEOUT_MSEC * 764)
61 #elif F_CPU == 96000000
56 #define TX_TIMEOUT (TX_TIMEOUT_MSEC * 596) 62 #define TX_TIMEOUT (TX_TIMEOUT_MSEC * 596)
57 #elif F_CPU == 72000000 63 #elif F_CPU == 72000000
58 #define TX_TIMEOUT (TX_TIMEOUT_MSEC * 512) // XXX Correct? 64 #define TX_TIMEOUT (TX_TIMEOUT_MSEC * 512)
59 #elif F_CPU == 48000000 65 #elif F_CPU == 48000000
60 #define TX_TIMEOUT (TX_TIMEOUT_MSEC * 428) 66 #define TX_TIMEOUT (TX_TIMEOUT_MSEC * 428)
61 #elif F_CPU == 24000000 67 #elif F_CPU == 24000000
62 #define TX_TIMEOUT (TX_TIMEOUT_MSEC * 262) 68 #define TX_TIMEOUT (TX_TIMEOUT_MSEC * 262)
63 #endif 69 #endif
87 return; 93 return;
88 } 94 }
89 95
90 if ( USBKeys_Protocol == 0 ) // Boot Mode 96 if ( USBKeys_Protocol == 0 ) // Boot Mode
91 { 97 {
92 if ( usb_tx_packet_count( NKRO_KEYBOARD_ENDPOINT ) < TX_PACKET_LIMIT ) 98 if ( usb_tx_packet_count( KEYBOARD_ENDPOINT ) < TX_PACKET_LIMIT )
93 { 99 {
94 tx_packet = usb_malloc(); 100 tx_packet = usb_malloc();
95 if ( tx_packet ) 101 if ( tx_packet )
96 break; 102 break;
97 } 103 }
98 } 104 }
99 else if ( USBKeys_Protocol == 1 ) // NKRO Mode 105 else if ( USBKeys_Protocol == 1 ) // NKRO Mode
100 { 106 {
101 if ( usb_tx_packet_count( KEYBOARD_ENDPOINT ) < TX_PACKET_LIMIT ) 107 if ( usb_tx_packet_count( NKRO_KEYBOARD_ENDPOINT ) < TX_PACKET_LIMIT )
102 { 108 {
103 tx_packet = usb_malloc(); 109 tx_packet = usb_malloc();
104 if ( tx_packet ) 110 if ( tx_packet )
105 break; 111 break;
106 } 112 }
107 } 113 }
114 else if ( USBKeys_Changed &
115 ( USBKeyChangeState_System | USBKeyChangeState_Consumer )
116 )
117 {
118 if ( usb_tx_packet_count( SYS_CTRL_ENDPOINT ) < TX_PACKET_LIMIT )
119 {
120 tx_packet = usb_malloc();
121 if ( tx_packet )
122 break;
123 }
124 }
108 125
109 if ( ++wait_count > TX_TIMEOUT || transmit_previous_timeout ) 126 if ( ++wait_count > TX_TIMEOUT || transmit_previous_timeout )
110 { 127 {
111 transmit_previous_timeout = 1; 128 transmit_previous_timeout = 1;
112 warn_print("USB Transmit Timeout..."); 129 warn_print("USB Transmit Timeout...");
115 yield(); 132 yield();
116 } 133 }
117 134
118 // Pointer to USB tx packet buffer 135 // Pointer to USB tx packet buffer
119 uint8_t *tx_buf = tx_packet->buf; 136 uint8_t *tx_buf = tx_packet->buf;
137
138 // Check system control keys
139 if ( USBKeys_Changed & USBKeyChangeState_System )
140 {
141 if ( Output_DebugMode )
142 {
143 print("SysCtrl[");
144 printHex_op( USBKeys_SysCtrl, 2 );
145 print( "] " NL );
146 }
147
148 *tx_buf++ = 0x02; // ID
149 *tx_buf = USBKeys_SysCtrl;
150 tx_packet->len = 2;
151
152 // Send USB Packet
153 usb_tx( SYS_CTRL_ENDPOINT, tx_packet );
154 USBKeys_Changed &= ~USBKeyChangeState_System; // Mark sent
155 return;
156 }
157
158 // Check consumer control keys
159 if ( USBKeys_Changed & USBKeyChangeState_Consumer )
160 {
161 if ( Output_DebugMode )
162 {
163 print("ConsCtrl[");
164 printHex_op( USBKeys_ConsCtrl, 2 );
165 print( "] " NL );
166 }
167
168 *tx_buf++ = 0x03; // ID
169 *tx_buf++ = (uint8_t)(USBKeys_ConsCtrl & 0x00FF);
170 *tx_buf = (uint8_t)(USBKeys_ConsCtrl >> 8);
171 tx_packet->len = 3;
172
173 // Send USB Packet
174 usb_tx( SYS_CTRL_ENDPOINT, tx_packet );
175 USBKeys_Changed &= ~USBKeyChangeState_Consumer; // Mark sent
176 return;
177 }
120 178
121 switch ( USBKeys_Protocol ) 179 switch ( USBKeys_Protocol )
122 { 180 {
123 // Send boot keyboard interrupt packet(s) 181 // Send boot keyboard interrupt packet(s)
124 case 0: 182 case 0:
155 if ( Output_DebugMode ) 213 if ( Output_DebugMode )
156 { 214 {
157 dbug_msg("NKRO USB: "); 215 dbug_msg("NKRO USB: ");
158 } 216 }
159 217
160 // Check system control keys
161 if ( USBKeys_Changed & USBKeyChangeState_System )
162 {
163 if ( Output_DebugMode )
164 {
165 print("SysCtrl[");
166 printHex_op( USBKeys_SysCtrl, 2 );
167 print( "] " NL );
168 }
169
170 *tx_buf++ = 0x02; // ID
171 *tx_buf = USBKeys_SysCtrl;
172 tx_packet->len = 2;
173
174 // Send USB Packet
175 usb_tx( NKRO_KEYBOARD_ENDPOINT, tx_packet );
176 USBKeys_Changed &= ~USBKeyChangeState_System; // Mark sent
177 }
178
179 // Check consumer control keys
180 if ( USBKeys_Changed & USBKeyChangeState_Consumer )
181 {
182 if ( Output_DebugMode )
183 {
184 print("ConsCtrl[");
185 printHex_op( USBKeys_ConsCtrl, 2 );
186 print( "] " NL );
187 }
188
189 *tx_buf++ = 0x03; // ID
190 *tx_buf++ = (uint8_t)(USBKeys_ConsCtrl & 0x00FF);
191 *tx_buf = (uint8_t)(USBKeys_ConsCtrl >> 8);
192 tx_packet->len = 3;
193
194 // Send USB Packet
195 usb_tx( NKRO_KEYBOARD_ENDPOINT, tx_packet );
196 USBKeys_Changed &= ~USBKeyChangeState_Consumer; // Mark sent
197 }
198
199 // Standard HID Keyboard 218 // Standard HID Keyboard
200 if ( USBKeys_Changed ) 219 if ( USBKeys_Changed )
201 { 220 {
202 // USB NKRO Debug output 221 // USB NKRO Debug output
203 if ( Output_DebugMode ) 222 if ( Output_DebugMode )