Mercurial > louis > kiibohd-controller
annotate Output/pjrcUSB/arm/usb_keyboard.c @ 326:05a09eda53fb
Inital Remote Wakeup Support
Not working yet...
author | Rowan Decker <Smasher816@gmail.com> |
---|---|
date | Sun, 08 Mar 2015 22:35:55 -0700 |
parents | e946656696f2 |
children | 9ac304aa1ab5 |
rev | line source |
---|---|
117
5ffefdf89b37
Adding in USB module updates from Teensyduino 1.18rc2.
Jacob Alexander <haata@kiibohd.com>
parents:
104
diff
changeset
|
1 /* Teensyduino Core Library |
5ffefdf89b37
Adding in USB module updates from Teensyduino 1.18rc2.
Jacob Alexander <haata@kiibohd.com>
parents:
104
diff
changeset
|
2 * http://www.pjrc.com/teensy/ |
5ffefdf89b37
Adding in USB module updates from Teensyduino 1.18rc2.
Jacob Alexander <haata@kiibohd.com>
parents:
104
diff
changeset
|
3 * Copyright (c) 2013 PJRC.COM, LLC. |
285
1495b4504a59
Adding outputDebug command
Jacob Alexander <haata@kiibohd.com>
parents:
251
diff
changeset
|
4 * Modifications by Jacob Alexander 2013-2015 |
117
5ffefdf89b37
Adding in USB module updates from Teensyduino 1.18rc2.
Jacob Alexander <haata@kiibohd.com>
parents:
104
diff
changeset
|
5 * |
5ffefdf89b37
Adding in USB module updates from Teensyduino 1.18rc2.
Jacob Alexander <haata@kiibohd.com>
parents:
104
diff
changeset
|
6 * Permission is hereby granted, free of charge, to any person obtaining |
5ffefdf89b37
Adding in USB module updates from Teensyduino 1.18rc2.
Jacob Alexander <haata@kiibohd.com>
parents:
104
diff
changeset
|
7 * a copy of this software and associated documentation files (the |
5ffefdf89b37
Adding in USB module updates from Teensyduino 1.18rc2.
Jacob Alexander <haata@kiibohd.com>
parents:
104
diff
changeset
|
8 * "Software"), to deal in the Software without restriction, including |
5ffefdf89b37
Adding in USB module updates from Teensyduino 1.18rc2.
Jacob Alexander <haata@kiibohd.com>
parents:
104
diff
changeset
|
9 * without limitation the rights to use, copy, modify, merge, publish, |
5ffefdf89b37
Adding in USB module updates from Teensyduino 1.18rc2.
Jacob Alexander <haata@kiibohd.com>
parents:
104
diff
changeset
|
10 * distribute, sublicense, and/or sell copies of the Software, and to |
5ffefdf89b37
Adding in USB module updates from Teensyduino 1.18rc2.
Jacob Alexander <haata@kiibohd.com>
parents:
104
diff
changeset
|
11 * permit persons to whom the Software is furnished to do so, subject to |
5ffefdf89b37
Adding in USB module updates from Teensyduino 1.18rc2.
Jacob Alexander <haata@kiibohd.com>
parents:
104
diff
changeset
|
12 * the following conditions: |
5ffefdf89b37
Adding in USB module updates from Teensyduino 1.18rc2.
Jacob Alexander <haata@kiibohd.com>
parents:
104
diff
changeset
|
13 * |
224
138e5ca7f8e4
Preparing ARM for USB NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
118
diff
changeset
|
14 * 1. The above copyright notice and this permission notice shall be |
117
5ffefdf89b37
Adding in USB module updates from Teensyduino 1.18rc2.
Jacob Alexander <haata@kiibohd.com>
parents:
104
diff
changeset
|
15 * included in all copies or substantial portions of the Software. |
5ffefdf89b37
Adding in USB module updates from Teensyduino 1.18rc2.
Jacob Alexander <haata@kiibohd.com>
parents:
104
diff
changeset
|
16 * |
224
138e5ca7f8e4
Preparing ARM for USB NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
118
diff
changeset
|
17 * 2. If the Software is incorporated into a build system that allows |
117
5ffefdf89b37
Adding in USB module updates from Teensyduino 1.18rc2.
Jacob Alexander <haata@kiibohd.com>
parents:
104
diff
changeset
|
18 * selection among a list of target devices, then similar target |
5ffefdf89b37
Adding in USB module updates from Teensyduino 1.18rc2.
Jacob Alexander <haata@kiibohd.com>
parents:
104
diff
changeset
|
19 * devices manufactured by PJRC.COM must be included in the list of |
5ffefdf89b37
Adding in USB module updates from Teensyduino 1.18rc2.
Jacob Alexander <haata@kiibohd.com>
parents:
104
diff
changeset
|
20 * target devices and selectable in the same manner. |
5ffefdf89b37
Adding in USB module updates from Teensyduino 1.18rc2.
Jacob Alexander <haata@kiibohd.com>
parents:
104
diff
changeset
|
21 * |
5ffefdf89b37
Adding in USB module updates from Teensyduino 1.18rc2.
Jacob Alexander <haata@kiibohd.com>
parents:
104
diff
changeset
|
22 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
5ffefdf89b37
Adding in USB module updates from Teensyduino 1.18rc2.
Jacob Alexander <haata@kiibohd.com>
parents:
104
diff
changeset
|
23 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
5ffefdf89b37
Adding in USB module updates from Teensyduino 1.18rc2.
Jacob Alexander <haata@kiibohd.com>
parents:
104
diff
changeset
|
24 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
5ffefdf89b37
Adding in USB module updates from Teensyduino 1.18rc2.
Jacob Alexander <haata@kiibohd.com>
parents:
104
diff
changeset
|
25 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS |
5ffefdf89b37
Adding in USB module updates from Teensyduino 1.18rc2.
Jacob Alexander <haata@kiibohd.com>
parents:
104
diff
changeset
|
26 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN |
5ffefdf89b37
Adding in USB module updates from Teensyduino 1.18rc2.
Jacob Alexander <haata@kiibohd.com>
parents:
104
diff
changeset
|
27 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
5ffefdf89b37
Adding in USB module updates from Teensyduino 1.18rc2.
Jacob Alexander <haata@kiibohd.com>
parents:
104
diff
changeset
|
28 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
5ffefdf89b37
Adding in USB module updates from Teensyduino 1.18rc2.
Jacob Alexander <haata@kiibohd.com>
parents:
104
diff
changeset
|
29 * SOFTWARE. |
5ffefdf89b37
Adding in USB module updates from Teensyduino 1.18rc2.
Jacob Alexander <haata@kiibohd.com>
parents:
104
diff
changeset
|
30 */ |
5ffefdf89b37
Adding in USB module updates from Teensyduino 1.18rc2.
Jacob Alexander <haata@kiibohd.com>
parents:
104
diff
changeset
|
31 |
224
138e5ca7f8e4
Preparing ARM for USB NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
118
diff
changeset
|
32 // ----- Includes ----- |
138e5ca7f8e4
Preparing ARM for USB NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
118
diff
changeset
|
33 |
138e5ca7f8e4
Preparing ARM for USB NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
118
diff
changeset
|
34 // Compiler Includes |
138e5ca7f8e4
Preparing ARM for USB NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
118
diff
changeset
|
35 #include <string.h> // for memcpy() |
138e5ca7f8e4
Preparing ARM for USB NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
118
diff
changeset
|
36 |
138e5ca7f8e4
Preparing ARM for USB NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
118
diff
changeset
|
37 // Project Includes |
138e5ca7f8e4
Preparing ARM for USB NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
118
diff
changeset
|
38 #include <Lib/OutputLib.h> |
138e5ca7f8e4
Preparing ARM for USB NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
118
diff
changeset
|
39 #include <print.h> |
138e5ca7f8e4
Preparing ARM for USB NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
118
diff
changeset
|
40 |
138e5ca7f8e4
Preparing ARM for USB NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
118
diff
changeset
|
41 // Local Includes |
104
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
42 #include "usb_dev.h" |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
43 #include "usb_keyboard.h" |
224
138e5ca7f8e4
Preparing ARM for USB NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
118
diff
changeset
|
44 |
104
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
45 |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
46 |
224
138e5ca7f8e4
Preparing ARM for USB NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
118
diff
changeset
|
47 // ----- Defines ----- |
138e5ca7f8e4
Preparing ARM for USB NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
118
diff
changeset
|
48 |
104
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
49 // Maximum number of transmit packets to queue so we don't starve other endpoints for memory |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
50 #define TX_PACKET_LIMIT 4 |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
51 |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
52 // When the PC isn't listening, how long do we wait before discarding data? |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
53 #define TX_TIMEOUT_MSEC 50 |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
54 |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
55 #if F_CPU == 96000000 |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
56 #define TX_TIMEOUT (TX_TIMEOUT_MSEC * 596) |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
57 #elif F_CPU == 48000000 |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
58 #define TX_TIMEOUT (TX_TIMEOUT_MSEC * 428) |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
59 #elif F_CPU == 24000000 |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
60 #define TX_TIMEOUT (TX_TIMEOUT_MSEC * 262) |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
61 #endif |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
62 |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
63 |
224
138e5ca7f8e4
Preparing ARM for USB NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
118
diff
changeset
|
64 |
138e5ca7f8e4
Preparing ARM for USB NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
118
diff
changeset
|
65 // ----- Variables ----- |
138e5ca7f8e4
Preparing ARM for USB NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
118
diff
changeset
|
66 |
138e5ca7f8e4
Preparing ARM for USB NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
118
diff
changeset
|
67 static uint8_t transmit_previous_timeout = 0; |
138e5ca7f8e4
Preparing ARM for USB NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
118
diff
changeset
|
68 |
138e5ca7f8e4
Preparing ARM for USB NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
118
diff
changeset
|
69 |
138e5ca7f8e4
Preparing ARM for USB NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
118
diff
changeset
|
70 |
138e5ca7f8e4
Preparing ARM for USB NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
118
diff
changeset
|
71 // ----- Functions ----- |
138e5ca7f8e4
Preparing ARM for USB NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
118
diff
changeset
|
72 |
104
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
73 // send the contents of keyboard_keys and keyboard_modifier_keys |
224
138e5ca7f8e4
Preparing ARM for USB NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
118
diff
changeset
|
74 void usb_keyboard_send() |
104
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
75 { |
224
138e5ca7f8e4
Preparing ARM for USB NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
118
diff
changeset
|
76 uint32_t wait_count = 0; |
104
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
77 usb_packet_t *tx_packet; |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
78 |
326
05a09eda53fb
Inital Remote Wakeup Support
Rowan Decker <Smasher816@gmail.com>
parents:
292
diff
changeset
|
79 if (remote_wakeup_enabled) { |
05a09eda53fb
Inital Remote Wakeup Support
Rowan Decker <Smasher816@gmail.com>
parents:
292
diff
changeset
|
80 USB0_CTL |= USB_CTL_RESUME; |
05a09eda53fb
Inital Remote Wakeup Support
Rowan Decker <Smasher816@gmail.com>
parents:
292
diff
changeset
|
81 _delay_ms(5); //wait 1 to 15ms |
05a09eda53fb
Inital Remote Wakeup Support
Rowan Decker <Smasher816@gmail.com>
parents:
292
diff
changeset
|
82 USB0_CTL &= ~USB_CTL_RESUME; |
05a09eda53fb
Inital Remote Wakeup Support
Rowan Decker <Smasher816@gmail.com>
parents:
292
diff
changeset
|
83 _delay_ms(5); |
05a09eda53fb
Inital Remote Wakeup Support
Rowan Decker <Smasher816@gmail.com>
parents:
292
diff
changeset
|
84 } |
05a09eda53fb
Inital Remote Wakeup Support
Rowan Decker <Smasher816@gmail.com>
parents:
292
diff
changeset
|
85 |
232
9a3c9f6f4866
USB NKRO working for ARM!
Jacob Alexander <haata@kiibohd.com>
parents:
224
diff
changeset
|
86 // Wait till ready |
224
138e5ca7f8e4
Preparing ARM for USB NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
118
diff
changeset
|
87 while ( 1 ) |
138e5ca7f8e4
Preparing ARM for USB NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
118
diff
changeset
|
88 { |
138e5ca7f8e4
Preparing ARM for USB NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
118
diff
changeset
|
89 if ( !usb_configuration ) |
138e5ca7f8e4
Preparing ARM for USB NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
118
diff
changeset
|
90 { |
138e5ca7f8e4
Preparing ARM for USB NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
118
diff
changeset
|
91 erro_print("USB not configured..."); |
138e5ca7f8e4
Preparing ARM for USB NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
118
diff
changeset
|
92 return; |
104
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
93 } |
232
9a3c9f6f4866
USB NKRO working for ARM!
Jacob Alexander <haata@kiibohd.com>
parents:
224
diff
changeset
|
94 |
9a3c9f6f4866
USB NKRO working for ARM!
Jacob Alexander <haata@kiibohd.com>
parents:
224
diff
changeset
|
95 if ( USBKeys_Protocol == 0 ) // Boot Mode |
224
138e5ca7f8e4
Preparing ARM for USB NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
118
diff
changeset
|
96 { |
232
9a3c9f6f4866
USB NKRO working for ARM!
Jacob Alexander <haata@kiibohd.com>
parents:
224
diff
changeset
|
97 if ( usb_tx_packet_count( NKRO_KEYBOARD_ENDPOINT ) < TX_PACKET_LIMIT ) |
9a3c9f6f4866
USB NKRO working for ARM!
Jacob Alexander <haata@kiibohd.com>
parents:
224
diff
changeset
|
98 { |
9a3c9f6f4866
USB NKRO working for ARM!
Jacob Alexander <haata@kiibohd.com>
parents:
224
diff
changeset
|
99 tx_packet = usb_malloc(); |
9a3c9f6f4866
USB NKRO working for ARM!
Jacob Alexander <haata@kiibohd.com>
parents:
224
diff
changeset
|
100 if ( tx_packet ) |
9a3c9f6f4866
USB NKRO working for ARM!
Jacob Alexander <haata@kiibohd.com>
parents:
224
diff
changeset
|
101 break; |
9a3c9f6f4866
USB NKRO working for ARM!
Jacob Alexander <haata@kiibohd.com>
parents:
224
diff
changeset
|
102 } |
104
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
103 } |
232
9a3c9f6f4866
USB NKRO working for ARM!
Jacob Alexander <haata@kiibohd.com>
parents:
224
diff
changeset
|
104 else if ( USBKeys_Protocol == 1 ) // NKRO Mode |
9a3c9f6f4866
USB NKRO working for ARM!
Jacob Alexander <haata@kiibohd.com>
parents:
224
diff
changeset
|
105 { |
9a3c9f6f4866
USB NKRO working for ARM!
Jacob Alexander <haata@kiibohd.com>
parents:
224
diff
changeset
|
106 if ( usb_tx_packet_count( KEYBOARD_ENDPOINT ) < TX_PACKET_LIMIT ) |
9a3c9f6f4866
USB NKRO working for ARM!
Jacob Alexander <haata@kiibohd.com>
parents:
224
diff
changeset
|
107 { |
9a3c9f6f4866
USB NKRO working for ARM!
Jacob Alexander <haata@kiibohd.com>
parents:
224
diff
changeset
|
108 tx_packet = usb_malloc(); |
9a3c9f6f4866
USB NKRO working for ARM!
Jacob Alexander <haata@kiibohd.com>
parents:
224
diff
changeset
|
109 if ( tx_packet ) |
9a3c9f6f4866
USB NKRO working for ARM!
Jacob Alexander <haata@kiibohd.com>
parents:
224
diff
changeset
|
110 break; |
9a3c9f6f4866
USB NKRO working for ARM!
Jacob Alexander <haata@kiibohd.com>
parents:
224
diff
changeset
|
111 } |
9a3c9f6f4866
USB NKRO working for ARM!
Jacob Alexander <haata@kiibohd.com>
parents:
224
diff
changeset
|
112 } |
9a3c9f6f4866
USB NKRO working for ARM!
Jacob Alexander <haata@kiibohd.com>
parents:
224
diff
changeset
|
113 |
224
138e5ca7f8e4
Preparing ARM for USB NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
118
diff
changeset
|
114 if ( ++wait_count > TX_TIMEOUT || transmit_previous_timeout ) |
138e5ca7f8e4
Preparing ARM for USB NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
118
diff
changeset
|
115 { |
104
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
116 transmit_previous_timeout = 1; |
224
138e5ca7f8e4
Preparing ARM for USB NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
118
diff
changeset
|
117 warn_print("USB Transmit Timeout..."); |
138e5ca7f8e4
Preparing ARM for USB NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
118
diff
changeset
|
118 return; |
104
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
119 } |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
120 yield(); |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
121 } |
224
138e5ca7f8e4
Preparing ARM for USB NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
118
diff
changeset
|
122 |
232
9a3c9f6f4866
USB NKRO working for ARM!
Jacob Alexander <haata@kiibohd.com>
parents:
224
diff
changeset
|
123 // Pointer to USB tx packet buffer |
9a3c9f6f4866
USB NKRO working for ARM!
Jacob Alexander <haata@kiibohd.com>
parents:
224
diff
changeset
|
124 uint8_t *tx_buf = tx_packet->buf; |
9a3c9f6f4866
USB NKRO working for ARM!
Jacob Alexander <haata@kiibohd.com>
parents:
224
diff
changeset
|
125 |
9a3c9f6f4866
USB NKRO working for ARM!
Jacob Alexander <haata@kiibohd.com>
parents:
224
diff
changeset
|
126 switch ( USBKeys_Protocol ) |
9a3c9f6f4866
USB NKRO working for ARM!
Jacob Alexander <haata@kiibohd.com>
parents:
224
diff
changeset
|
127 { |
9a3c9f6f4866
USB NKRO working for ARM!
Jacob Alexander <haata@kiibohd.com>
parents:
224
diff
changeset
|
128 // Send boot keyboard interrupt packet(s) |
9a3c9f6f4866
USB NKRO working for ARM!
Jacob Alexander <haata@kiibohd.com>
parents:
224
diff
changeset
|
129 case 0: |
285
1495b4504a59
Adding outputDebug command
Jacob Alexander <haata@kiibohd.com>
parents:
251
diff
changeset
|
130 // USB Boot Mode debug output |
1495b4504a59
Adding outputDebug command
Jacob Alexander <haata@kiibohd.com>
parents:
251
diff
changeset
|
131 if ( Output_DebugMode ) |
1495b4504a59
Adding outputDebug command
Jacob Alexander <haata@kiibohd.com>
parents:
251
diff
changeset
|
132 { |
1495b4504a59
Adding outputDebug command
Jacob Alexander <haata@kiibohd.com>
parents:
251
diff
changeset
|
133 dbug_msg("Boot USB: "); |
1495b4504a59
Adding outputDebug command
Jacob Alexander <haata@kiibohd.com>
parents:
251
diff
changeset
|
134 printHex_op( USBKeys_Modifiers, 2 ); |
1495b4504a59
Adding outputDebug command
Jacob Alexander <haata@kiibohd.com>
parents:
251
diff
changeset
|
135 print(" "); |
1495b4504a59
Adding outputDebug command
Jacob Alexander <haata@kiibohd.com>
parents:
251
diff
changeset
|
136 printHex( 0 ); |
1495b4504a59
Adding outputDebug command
Jacob Alexander <haata@kiibohd.com>
parents:
251
diff
changeset
|
137 print(" "); |
1495b4504a59
Adding outputDebug command
Jacob Alexander <haata@kiibohd.com>
parents:
251
diff
changeset
|
138 printHex_op( USBKeys_Keys[0], 2 ); |
1495b4504a59
Adding outputDebug command
Jacob Alexander <haata@kiibohd.com>
parents:
251
diff
changeset
|
139 printHex_op( USBKeys_Keys[1], 2 ); |
1495b4504a59
Adding outputDebug command
Jacob Alexander <haata@kiibohd.com>
parents:
251
diff
changeset
|
140 printHex_op( USBKeys_Keys[2], 2 ); |
1495b4504a59
Adding outputDebug command
Jacob Alexander <haata@kiibohd.com>
parents:
251
diff
changeset
|
141 printHex_op( USBKeys_Keys[3], 2 ); |
1495b4504a59
Adding outputDebug command
Jacob Alexander <haata@kiibohd.com>
parents:
251
diff
changeset
|
142 printHex_op( USBKeys_Keys[4], 2 ); |
1495b4504a59
Adding outputDebug command
Jacob Alexander <haata@kiibohd.com>
parents:
251
diff
changeset
|
143 printHex_op( USBKeys_Keys[5], 2 ); |
1495b4504a59
Adding outputDebug command
Jacob Alexander <haata@kiibohd.com>
parents:
251
diff
changeset
|
144 print( NL ); |
1495b4504a59
Adding outputDebug command
Jacob Alexander <haata@kiibohd.com>
parents:
251
diff
changeset
|
145 } |
1495b4504a59
Adding outputDebug command
Jacob Alexander <haata@kiibohd.com>
parents:
251
diff
changeset
|
146 |
232
9a3c9f6f4866
USB NKRO working for ARM!
Jacob Alexander <haata@kiibohd.com>
parents:
224
diff
changeset
|
147 // Boot Mode |
9a3c9f6f4866
USB NKRO working for ARM!
Jacob Alexander <haata@kiibohd.com>
parents:
224
diff
changeset
|
148 *tx_buf++ = USBKeys_Modifiers; |
9a3c9f6f4866
USB NKRO working for ARM!
Jacob Alexander <haata@kiibohd.com>
parents:
224
diff
changeset
|
149 *tx_buf++ = 0; |
9a3c9f6f4866
USB NKRO working for ARM!
Jacob Alexander <haata@kiibohd.com>
parents:
224
diff
changeset
|
150 memcpy( tx_buf, USBKeys_Keys, USB_BOOT_MAX_KEYS ); |
9a3c9f6f4866
USB NKRO working for ARM!
Jacob Alexander <haata@kiibohd.com>
parents:
224
diff
changeset
|
151 tx_packet->len = 8; |
9a3c9f6f4866
USB NKRO working for ARM!
Jacob Alexander <haata@kiibohd.com>
parents:
224
diff
changeset
|
152 |
9a3c9f6f4866
USB NKRO working for ARM!
Jacob Alexander <haata@kiibohd.com>
parents:
224
diff
changeset
|
153 // Send USB Packet |
9a3c9f6f4866
USB NKRO working for ARM!
Jacob Alexander <haata@kiibohd.com>
parents:
224
diff
changeset
|
154 usb_tx( KEYBOARD_ENDPOINT, tx_packet ); |
9a3c9f6f4866
USB NKRO working for ARM!
Jacob Alexander <haata@kiibohd.com>
parents:
224
diff
changeset
|
155 USBKeys_Changed = USBKeyChangeState_None; |
9a3c9f6f4866
USB NKRO working for ARM!
Jacob Alexander <haata@kiibohd.com>
parents:
224
diff
changeset
|
156 break; |
9a3c9f6f4866
USB NKRO working for ARM!
Jacob Alexander <haata@kiibohd.com>
parents:
224
diff
changeset
|
157 |
9a3c9f6f4866
USB NKRO working for ARM!
Jacob Alexander <haata@kiibohd.com>
parents:
224
diff
changeset
|
158 // Send NKRO keyboard interrupts packet(s) |
9a3c9f6f4866
USB NKRO working for ARM!
Jacob Alexander <haata@kiibohd.com>
parents:
224
diff
changeset
|
159 case 1: |
285
1495b4504a59
Adding outputDebug command
Jacob Alexander <haata@kiibohd.com>
parents:
251
diff
changeset
|
160 if ( Output_DebugMode ) |
1495b4504a59
Adding outputDebug command
Jacob Alexander <haata@kiibohd.com>
parents:
251
diff
changeset
|
161 { |
1495b4504a59
Adding outputDebug command
Jacob Alexander <haata@kiibohd.com>
parents:
251
diff
changeset
|
162 dbug_msg("NKRO USB: "); |
1495b4504a59
Adding outputDebug command
Jacob Alexander <haata@kiibohd.com>
parents:
251
diff
changeset
|
163 } |
1495b4504a59
Adding outputDebug command
Jacob Alexander <haata@kiibohd.com>
parents:
251
diff
changeset
|
164 |
251
d3ac199593d6
Fixing NKRO on Windows 8.1
Jacob Alexander <haata@kiibohd.com>
parents:
248
diff
changeset
|
165 // Check system control keys |
d3ac199593d6
Fixing NKRO on Windows 8.1
Jacob Alexander <haata@kiibohd.com>
parents:
248
diff
changeset
|
166 if ( USBKeys_Changed & USBKeyChangeState_System ) |
232
9a3c9f6f4866
USB NKRO working for ARM!
Jacob Alexander <haata@kiibohd.com>
parents:
224
diff
changeset
|
167 { |
285
1495b4504a59
Adding outputDebug command
Jacob Alexander <haata@kiibohd.com>
parents:
251
diff
changeset
|
168 if ( Output_DebugMode ) |
1495b4504a59
Adding outputDebug command
Jacob Alexander <haata@kiibohd.com>
parents:
251
diff
changeset
|
169 { |
1495b4504a59
Adding outputDebug command
Jacob Alexander <haata@kiibohd.com>
parents:
251
diff
changeset
|
170 print("SysCtrl["); |
1495b4504a59
Adding outputDebug command
Jacob Alexander <haata@kiibohd.com>
parents:
251
diff
changeset
|
171 printHex_op( USBKeys_SysCtrl, 2 ); |
292
e946656696f2
Adding missing NL's for Cons and Sys Control debug
Jacob Alexander <haata@kiibohd.com>
parents:
285
diff
changeset
|
172 print( "] " NL ); |
285
1495b4504a59
Adding outputDebug command
Jacob Alexander <haata@kiibohd.com>
parents:
251
diff
changeset
|
173 } |
1495b4504a59
Adding outputDebug command
Jacob Alexander <haata@kiibohd.com>
parents:
251
diff
changeset
|
174 |
251
d3ac199593d6
Fixing NKRO on Windows 8.1
Jacob Alexander <haata@kiibohd.com>
parents:
248
diff
changeset
|
175 *tx_buf++ = 0x02; // ID |
232
9a3c9f6f4866
USB NKRO working for ARM!
Jacob Alexander <haata@kiibohd.com>
parents:
224
diff
changeset
|
176 *tx_buf = USBKeys_SysCtrl; |
9a3c9f6f4866
USB NKRO working for ARM!
Jacob Alexander <haata@kiibohd.com>
parents:
224
diff
changeset
|
177 tx_packet->len = 2; |
9a3c9f6f4866
USB NKRO working for ARM!
Jacob Alexander <haata@kiibohd.com>
parents:
224
diff
changeset
|
178 |
9a3c9f6f4866
USB NKRO working for ARM!
Jacob Alexander <haata@kiibohd.com>
parents:
224
diff
changeset
|
179 // Send USB Packet |
9a3c9f6f4866
USB NKRO working for ARM!
Jacob Alexander <haata@kiibohd.com>
parents:
224
diff
changeset
|
180 usb_tx( NKRO_KEYBOARD_ENDPOINT, tx_packet ); |
9a3c9f6f4866
USB NKRO working for ARM!
Jacob Alexander <haata@kiibohd.com>
parents:
224
diff
changeset
|
181 USBKeys_Changed &= ~USBKeyChangeState_System; // Mark sent |
9a3c9f6f4866
USB NKRO working for ARM!
Jacob Alexander <haata@kiibohd.com>
parents:
224
diff
changeset
|
182 } |
251
d3ac199593d6
Fixing NKRO on Windows 8.1
Jacob Alexander <haata@kiibohd.com>
parents:
248
diff
changeset
|
183 |
232
9a3c9f6f4866
USB NKRO working for ARM!
Jacob Alexander <haata@kiibohd.com>
parents:
224
diff
changeset
|
184 // Check consumer control keys |
251
d3ac199593d6
Fixing NKRO on Windows 8.1
Jacob Alexander <haata@kiibohd.com>
parents:
248
diff
changeset
|
185 if ( USBKeys_Changed & USBKeyChangeState_Consumer ) |
232
9a3c9f6f4866
USB NKRO working for ARM!
Jacob Alexander <haata@kiibohd.com>
parents:
224
diff
changeset
|
186 { |
285
1495b4504a59
Adding outputDebug command
Jacob Alexander <haata@kiibohd.com>
parents:
251
diff
changeset
|
187 if ( Output_DebugMode ) |
1495b4504a59
Adding outputDebug command
Jacob Alexander <haata@kiibohd.com>
parents:
251
diff
changeset
|
188 { |
1495b4504a59
Adding outputDebug command
Jacob Alexander <haata@kiibohd.com>
parents:
251
diff
changeset
|
189 print("ConsCtrl["); |
1495b4504a59
Adding outputDebug command
Jacob Alexander <haata@kiibohd.com>
parents:
251
diff
changeset
|
190 printHex_op( USBKeys_ConsCtrl, 2 ); |
292
e946656696f2
Adding missing NL's for Cons and Sys Control debug
Jacob Alexander <haata@kiibohd.com>
parents:
285
diff
changeset
|
191 print( "] " NL ); |
285
1495b4504a59
Adding outputDebug command
Jacob Alexander <haata@kiibohd.com>
parents:
251
diff
changeset
|
192 } |
1495b4504a59
Adding outputDebug command
Jacob Alexander <haata@kiibohd.com>
parents:
251
diff
changeset
|
193 |
251
d3ac199593d6
Fixing NKRO on Windows 8.1
Jacob Alexander <haata@kiibohd.com>
parents:
248
diff
changeset
|
194 *tx_buf++ = 0x03; // ID |
232
9a3c9f6f4866
USB NKRO working for ARM!
Jacob Alexander <haata@kiibohd.com>
parents:
224
diff
changeset
|
195 *tx_buf++ = (uint8_t)(USBKeys_ConsCtrl & 0x00FF); |
9a3c9f6f4866
USB NKRO working for ARM!
Jacob Alexander <haata@kiibohd.com>
parents:
224
diff
changeset
|
196 *tx_buf = (uint8_t)(USBKeys_ConsCtrl >> 8); |
9a3c9f6f4866
USB NKRO working for ARM!
Jacob Alexander <haata@kiibohd.com>
parents:
224
diff
changeset
|
197 tx_packet->len = 3; |
9a3c9f6f4866
USB NKRO working for ARM!
Jacob Alexander <haata@kiibohd.com>
parents:
224
diff
changeset
|
198 |
9a3c9f6f4866
USB NKRO working for ARM!
Jacob Alexander <haata@kiibohd.com>
parents:
224
diff
changeset
|
199 // Send USB Packet |
9a3c9f6f4866
USB NKRO working for ARM!
Jacob Alexander <haata@kiibohd.com>
parents:
224
diff
changeset
|
200 usb_tx( NKRO_KEYBOARD_ENDPOINT, tx_packet ); |
9a3c9f6f4866
USB NKRO working for ARM!
Jacob Alexander <haata@kiibohd.com>
parents:
224
diff
changeset
|
201 USBKeys_Changed &= ~USBKeyChangeState_Consumer; // Mark sent |
9a3c9f6f4866
USB NKRO working for ARM!
Jacob Alexander <haata@kiibohd.com>
parents:
224
diff
changeset
|
202 } |
9a3c9f6f4866
USB NKRO working for ARM!
Jacob Alexander <haata@kiibohd.com>
parents:
224
diff
changeset
|
203 |
251
d3ac199593d6
Fixing NKRO on Windows 8.1
Jacob Alexander <haata@kiibohd.com>
parents:
248
diff
changeset
|
204 // Standard HID Keyboard |
d3ac199593d6
Fixing NKRO on Windows 8.1
Jacob Alexander <haata@kiibohd.com>
parents:
248
diff
changeset
|
205 if ( USBKeys_Changed ) |
d3ac199593d6
Fixing NKRO on Windows 8.1
Jacob Alexander <haata@kiibohd.com>
parents:
248
diff
changeset
|
206 { |
285
1495b4504a59
Adding outputDebug command
Jacob Alexander <haata@kiibohd.com>
parents:
251
diff
changeset
|
207 // USB NKRO Debug output |
1495b4504a59
Adding outputDebug command
Jacob Alexander <haata@kiibohd.com>
parents:
251
diff
changeset
|
208 if ( Output_DebugMode ) |
1495b4504a59
Adding outputDebug command
Jacob Alexander <haata@kiibohd.com>
parents:
251
diff
changeset
|
209 { |
1495b4504a59
Adding outputDebug command
Jacob Alexander <haata@kiibohd.com>
parents:
251
diff
changeset
|
210 printHex_op( USBKeys_Modifiers, 2 ); |
1495b4504a59
Adding outputDebug command
Jacob Alexander <haata@kiibohd.com>
parents:
251
diff
changeset
|
211 print(" "); |
1495b4504a59
Adding outputDebug command
Jacob Alexander <haata@kiibohd.com>
parents:
251
diff
changeset
|
212 for ( uint8_t c = 0; c < 6; c++ ) |
1495b4504a59
Adding outputDebug command
Jacob Alexander <haata@kiibohd.com>
parents:
251
diff
changeset
|
213 printHex_op( USBKeys_Keys[ c ], 2 ); |
1495b4504a59
Adding outputDebug command
Jacob Alexander <haata@kiibohd.com>
parents:
251
diff
changeset
|
214 print(" "); |
1495b4504a59
Adding outputDebug command
Jacob Alexander <haata@kiibohd.com>
parents:
251
diff
changeset
|
215 for ( uint8_t c = 6; c < 20; c++ ) |
1495b4504a59
Adding outputDebug command
Jacob Alexander <haata@kiibohd.com>
parents:
251
diff
changeset
|
216 printHex_op( USBKeys_Keys[ c ], 2 ); |
1495b4504a59
Adding outputDebug command
Jacob Alexander <haata@kiibohd.com>
parents:
251
diff
changeset
|
217 print(" "); |
1495b4504a59
Adding outputDebug command
Jacob Alexander <haata@kiibohd.com>
parents:
251
diff
changeset
|
218 printHex_op( USBKeys_Keys[20], 2 ); |
1495b4504a59
Adding outputDebug command
Jacob Alexander <haata@kiibohd.com>
parents:
251
diff
changeset
|
219 print(" "); |
1495b4504a59
Adding outputDebug command
Jacob Alexander <haata@kiibohd.com>
parents:
251
diff
changeset
|
220 for ( uint8_t c = 21; c < 27; c++ ) |
1495b4504a59
Adding outputDebug command
Jacob Alexander <haata@kiibohd.com>
parents:
251
diff
changeset
|
221 printHex_op( USBKeys_Keys[ c ], 2 ); |
1495b4504a59
Adding outputDebug command
Jacob Alexander <haata@kiibohd.com>
parents:
251
diff
changeset
|
222 print( NL ); |
1495b4504a59
Adding outputDebug command
Jacob Alexander <haata@kiibohd.com>
parents:
251
diff
changeset
|
223 } |
1495b4504a59
Adding outputDebug command
Jacob Alexander <haata@kiibohd.com>
parents:
251
diff
changeset
|
224 |
251
d3ac199593d6
Fixing NKRO on Windows 8.1
Jacob Alexander <haata@kiibohd.com>
parents:
248
diff
changeset
|
225 tx_packet->len = 0; |
d3ac199593d6
Fixing NKRO on Windows 8.1
Jacob Alexander <haata@kiibohd.com>
parents:
248
diff
changeset
|
226 |
d3ac199593d6
Fixing NKRO on Windows 8.1
Jacob Alexander <haata@kiibohd.com>
parents:
248
diff
changeset
|
227 // Modifiers |
d3ac199593d6
Fixing NKRO on Windows 8.1
Jacob Alexander <haata@kiibohd.com>
parents:
248
diff
changeset
|
228 *tx_buf++ = 0x01; // ID |
d3ac199593d6
Fixing NKRO on Windows 8.1
Jacob Alexander <haata@kiibohd.com>
parents:
248
diff
changeset
|
229 *tx_buf++ = USBKeys_Modifiers; |
d3ac199593d6
Fixing NKRO on Windows 8.1
Jacob Alexander <haata@kiibohd.com>
parents:
248
diff
changeset
|
230 tx_packet->len += 2; |
d3ac199593d6
Fixing NKRO on Windows 8.1
Jacob Alexander <haata@kiibohd.com>
parents:
248
diff
changeset
|
231 |
d3ac199593d6
Fixing NKRO on Windows 8.1
Jacob Alexander <haata@kiibohd.com>
parents:
248
diff
changeset
|
232 // 4-49 (first 6 bytes) |
d3ac199593d6
Fixing NKRO on Windows 8.1
Jacob Alexander <haata@kiibohd.com>
parents:
248
diff
changeset
|
233 memcpy( tx_buf, USBKeys_Keys, 6 ); |
d3ac199593d6
Fixing NKRO on Windows 8.1
Jacob Alexander <haata@kiibohd.com>
parents:
248
diff
changeset
|
234 tx_buf += 6; |
d3ac199593d6
Fixing NKRO on Windows 8.1
Jacob Alexander <haata@kiibohd.com>
parents:
248
diff
changeset
|
235 tx_packet->len += 6; |
d3ac199593d6
Fixing NKRO on Windows 8.1
Jacob Alexander <haata@kiibohd.com>
parents:
248
diff
changeset
|
236 |
d3ac199593d6
Fixing NKRO on Windows 8.1
Jacob Alexander <haata@kiibohd.com>
parents:
248
diff
changeset
|
237 // 51-155 (Middle 14 bytes) |
d3ac199593d6
Fixing NKRO on Windows 8.1
Jacob Alexander <haata@kiibohd.com>
parents:
248
diff
changeset
|
238 memcpy( tx_buf, USBKeys_Keys + 6, 14 ); |
d3ac199593d6
Fixing NKRO on Windows 8.1
Jacob Alexander <haata@kiibohd.com>
parents:
248
diff
changeset
|
239 tx_buf += 14; |
d3ac199593d6
Fixing NKRO on Windows 8.1
Jacob Alexander <haata@kiibohd.com>
parents:
248
diff
changeset
|
240 tx_packet->len += 14; |
d3ac199593d6
Fixing NKRO on Windows 8.1
Jacob Alexander <haata@kiibohd.com>
parents:
248
diff
changeset
|
241 |
d3ac199593d6
Fixing NKRO on Windows 8.1
Jacob Alexander <haata@kiibohd.com>
parents:
248
diff
changeset
|
242 // 157-164 (Next byte) |
d3ac199593d6
Fixing NKRO on Windows 8.1
Jacob Alexander <haata@kiibohd.com>
parents:
248
diff
changeset
|
243 memcpy( tx_buf, USBKeys_Keys + 20, 1 ); |
d3ac199593d6
Fixing NKRO on Windows 8.1
Jacob Alexander <haata@kiibohd.com>
parents:
248
diff
changeset
|
244 tx_buf += 1; |
d3ac199593d6
Fixing NKRO on Windows 8.1
Jacob Alexander <haata@kiibohd.com>
parents:
248
diff
changeset
|
245 tx_packet->len += 1; |
d3ac199593d6
Fixing NKRO on Windows 8.1
Jacob Alexander <haata@kiibohd.com>
parents:
248
diff
changeset
|
246 |
d3ac199593d6
Fixing NKRO on Windows 8.1
Jacob Alexander <haata@kiibohd.com>
parents:
248
diff
changeset
|
247 // 176-221 (last 6 bytes) |
d3ac199593d6
Fixing NKRO on Windows 8.1
Jacob Alexander <haata@kiibohd.com>
parents:
248
diff
changeset
|
248 memcpy( tx_buf, USBKeys_Keys + 21, 6 ); |
d3ac199593d6
Fixing NKRO on Windows 8.1
Jacob Alexander <haata@kiibohd.com>
parents:
248
diff
changeset
|
249 tx_packet->len += 6; |
d3ac199593d6
Fixing NKRO on Windows 8.1
Jacob Alexander <haata@kiibohd.com>
parents:
248
diff
changeset
|
250 |
d3ac199593d6
Fixing NKRO on Windows 8.1
Jacob Alexander <haata@kiibohd.com>
parents:
248
diff
changeset
|
251 // Send USB Packet |
d3ac199593d6
Fixing NKRO on Windows 8.1
Jacob Alexander <haata@kiibohd.com>
parents:
248
diff
changeset
|
252 usb_tx( NKRO_KEYBOARD_ENDPOINT, tx_packet ); |
d3ac199593d6
Fixing NKRO on Windows 8.1
Jacob Alexander <haata@kiibohd.com>
parents:
248
diff
changeset
|
253 USBKeys_Changed = USBKeyChangeState_None; // Mark sent |
d3ac199593d6
Fixing NKRO on Windows 8.1
Jacob Alexander <haata@kiibohd.com>
parents:
248
diff
changeset
|
254 } |
d3ac199593d6
Fixing NKRO on Windows 8.1
Jacob Alexander <haata@kiibohd.com>
parents:
248
diff
changeset
|
255 |
232
9a3c9f6f4866
USB NKRO working for ARM!
Jacob Alexander <haata@kiibohd.com>
parents:
224
diff
changeset
|
256 break; |
9a3c9f6f4866
USB NKRO working for ARM!
Jacob Alexander <haata@kiibohd.com>
parents:
224
diff
changeset
|
257 } |
224
138e5ca7f8e4
Preparing ARM for USB NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
118
diff
changeset
|
258 |
138e5ca7f8e4
Preparing ARM for USB NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
118
diff
changeset
|
259 return; |
104
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
260 } |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
261 |