annotate Output/pjrcUSB/arm/usb_dev.c @ 447:56237ba5da6f

Adding auto-restart support whenever USB gets into an odd state - Somewhat aggresive, may cause restarts if the keyboard/OS hasn't fully intialized the keyboard - Added GET_IDLE handling and correct usage of SET_IDLE - Initial implementation of idle send, commented out as it causes issues on Mac OSX for sleeping (keyboard has been working without it) - MacOSX seems to have some sort of data corruption on the USB link, not sure why (other OSs have no issues) - Cleaned up some code - Added a longer sleep after the resume sequence to prevent possible issues sending keys too soon (may need to be increased more) Ipad support now seems flaky, though Mac, Windows seems solid. Init sequence on Linux seems slow, even though there are no errors.
author Jacob Alexander <haata@kiibohd.com>
date Fri, 27 May 2016 01:21:57 -0700
parents 68e19d7c953e
children 45feb80a2ad1
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
117
5ffefdf89b37 Adding in USB module updates from Teensyduino 1.18rc2.
Jacob Alexander <haata@kiibohd.com>
parents: 109
diff changeset
1 /* Teensyduino Core Library
5ffefdf89b37 Adding in USB module updates from Teensyduino 1.18rc2.
Jacob Alexander <haata@kiibohd.com>
parents: 109
diff changeset
2 * http://www.pjrc.com/teensy/
5ffefdf89b37 Adding in USB module updates from Teensyduino 1.18rc2.
Jacob Alexander <haata@kiibohd.com>
parents: 109
diff changeset
3 * Copyright (c) 2013 PJRC.COM, LLC.
420
23a1868b4ac2 Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents: 385
diff changeset
4 * Modifications by Jacob Alexander (2013-2016)
117
5ffefdf89b37 Adding in USB module updates from Teensyduino 1.18rc2.
Jacob Alexander <haata@kiibohd.com>
parents: 109
diff changeset
5 *
5ffefdf89b37 Adding in USB module updates from Teensyduino 1.18rc2.
Jacob Alexander <haata@kiibohd.com>
parents: 109
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: 109
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: 109
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: 109
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: 109
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: 109
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: 109
diff changeset
12 * the following conditions:
5ffefdf89b37 Adding in USB module updates from Teensyduino 1.18rc2.
Jacob Alexander <haata@kiibohd.com>
parents: 109
diff changeset
13 *
175
c70f641581b5 McHCK USB WORKS!!
Jacob Alexander <haata@kiibohd.com>
parents: 171
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: 109
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: 109
diff changeset
16 *
175
c70f641581b5 McHCK USB WORKS!!
Jacob Alexander <haata@kiibohd.com>
parents: 171
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: 109
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: 109
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: 109
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: 109
diff changeset
21 *
5ffefdf89b37 Adding in USB module updates from Teensyduino 1.18rc2.
Jacob Alexander <haata@kiibohd.com>
parents: 109
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: 109
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: 109
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: 109
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: 109
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: 109
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: 109
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: 109
diff changeset
29 * SOFTWARE.
5ffefdf89b37 Adding in USB module updates from Teensyduino 1.18rc2.
Jacob Alexander <haata@kiibohd.com>
parents: 109
diff changeset
30 */
5ffefdf89b37 Adding in USB module updates from Teensyduino 1.18rc2.
Jacob Alexander <haata@kiibohd.com>
parents: 109
diff changeset
31
231
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
32 // ----- Includes -----
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
33
175
c70f641581b5 McHCK USB WORKS!!
Jacob Alexander <haata@kiibohd.com>
parents: 171
diff changeset
34 // Project Includes
118
b61ca96b7c24 File and macro modifications for supporting Teensy 3.1
Jacob Alexander <haata@kiibohd.com>
parents: 117
diff changeset
35 #include <Lib/OutputLib.h>
175
c70f641581b5 McHCK USB WORKS!!
Jacob Alexander <haata@kiibohd.com>
parents: 171
diff changeset
36 #include <print.h>
370
39e338a6733d Fixing default ErgoDox layout and adding FlashMode button
Jacob Alexander <haata@kiibohd.com>
parents: 368
diff changeset
37 #include <kll_defs.h>
175
c70f641581b5 McHCK USB WORKS!!
Jacob Alexander <haata@kiibohd.com>
parents: 171
diff changeset
38
c70f641581b5 McHCK USB WORKS!!
Jacob Alexander <haata@kiibohd.com>
parents: 171
diff changeset
39 // Local Includes
104
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
40 #include "usb_dev.h"
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
41 #include "usb_mem.h"
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
42
231
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
43
104
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
44
231
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
45 // ----- Defines -----
104
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
46
231
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
47 // DEBUG Mode
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
48 // XXX - Only use when using usbMuxUart Module
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
49 // Delay causes issues initializing more than 1 hid device (i.e. NKRO keyboard)
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
50 //#define UART_DEBUG 1
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
51 // Debug Unknown USB requests, usually what you want to debug USB issues
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
52 //#define UART_DEBUG_UNKNOWN 1
117
5ffefdf89b37 Adding in USB module updates from Teensyduino 1.18rc2.
Jacob Alexander <haata@kiibohd.com>
parents: 109
diff changeset
53
5ffefdf89b37 Adding in USB module updates from Teensyduino 1.18rc2.
Jacob Alexander <haata@kiibohd.com>
parents: 109
diff changeset
54
326
05a09eda53fb Inital Remote Wakeup Support
Rowan Decker <Smasher816@gmail.com>
parents: 302
diff changeset
55 #define TX_STATE_BOTH_FREE_EVEN_FIRST 0
05a09eda53fb Inital Remote Wakeup Support
Rowan Decker <Smasher816@gmail.com>
parents: 302
diff changeset
56 #define TX_STATE_BOTH_FREE_ODD_FIRST 1
05a09eda53fb Inital Remote Wakeup Support
Rowan Decker <Smasher816@gmail.com>
parents: 302
diff changeset
57 #define TX_STATE_EVEN_FREE 2
05a09eda53fb Inital Remote Wakeup Support
Rowan Decker <Smasher816@gmail.com>
parents: 302
diff changeset
58 #define TX_STATE_ODD_FREE 3
05a09eda53fb Inital Remote Wakeup Support
Rowan Decker <Smasher816@gmail.com>
parents: 302
diff changeset
59 #define TX_STATE_NONE_FREE_EVEN_FIRST 4
05a09eda53fb Inital Remote Wakeup Support
Rowan Decker <Smasher816@gmail.com>
parents: 302
diff changeset
60 #define TX_STATE_NONE_FREE_ODD_FIRST 5
104
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
61
326
05a09eda53fb Inital Remote Wakeup Support
Rowan Decker <Smasher816@gmail.com>
parents: 302
diff changeset
62 #define BDT_OWN 0x80
05a09eda53fb Inital Remote Wakeup Support
Rowan Decker <Smasher816@gmail.com>
parents: 302
diff changeset
63 #define BDT_DATA1 0x40
05a09eda53fb Inital Remote Wakeup Support
Rowan Decker <Smasher816@gmail.com>
parents: 302
diff changeset
64 #define BDT_DATA0 0x00
05a09eda53fb Inital Remote Wakeup Support
Rowan Decker <Smasher816@gmail.com>
parents: 302
diff changeset
65 #define BDT_DTS 0x08
05a09eda53fb Inital Remote Wakeup Support
Rowan Decker <Smasher816@gmail.com>
parents: 302
diff changeset
66 #define BDT_STALL 0x04
104
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
67
231
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
68 #define TX 1
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
69 #define RX 0
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
70 #define ODD 1
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
71 #define EVEN 0
104
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
72 #define DATA0 0
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
73 #define DATA1 1
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
74
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
75
326
05a09eda53fb Inital Remote Wakeup Support
Rowan Decker <Smasher816@gmail.com>
parents: 302
diff changeset
76 #define GET_STATUS 0
05a09eda53fb Inital Remote Wakeup Support
Rowan Decker <Smasher816@gmail.com>
parents: 302
diff changeset
77 #define CLEAR_FEATURE 1
05a09eda53fb Inital Remote Wakeup Support
Rowan Decker <Smasher816@gmail.com>
parents: 302
diff changeset
78 #define SET_FEATURE 3
05a09eda53fb Inital Remote Wakeup Support
Rowan Decker <Smasher816@gmail.com>
parents: 302
diff changeset
79 #define SET_ADDRESS 5
05a09eda53fb Inital Remote Wakeup Support
Rowan Decker <Smasher816@gmail.com>
parents: 302
diff changeset
80 #define GET_DESCRIPTOR 6
05a09eda53fb Inital Remote Wakeup Support
Rowan Decker <Smasher816@gmail.com>
parents: 302
diff changeset
81 #define SET_DESCRIPTOR 7
05a09eda53fb Inital Remote Wakeup Support
Rowan Decker <Smasher816@gmail.com>
parents: 302
diff changeset
82 #define GET_CONFIGURATION 8
05a09eda53fb Inital Remote Wakeup Support
Rowan Decker <Smasher816@gmail.com>
parents: 302
diff changeset
83 #define SET_CONFIGURATION 9
05a09eda53fb Inital Remote Wakeup Support
Rowan Decker <Smasher816@gmail.com>
parents: 302
diff changeset
84 #define GET_INTERFACE 10
05a09eda53fb Inital Remote Wakeup Support
Rowan Decker <Smasher816@gmail.com>
parents: 302
diff changeset
85 #define SET_INTERFACE 11
05a09eda53fb Inital Remote Wakeup Support
Rowan Decker <Smasher816@gmail.com>
parents: 302
diff changeset
86 #define SYNCH_FRAME 12
104
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
87
326
05a09eda53fb Inital Remote Wakeup Support
Rowan Decker <Smasher816@gmail.com>
parents: 302
diff changeset
88 #define TX_STATE_BOTH_FREE_EVEN_FIRST 0
05a09eda53fb Inital Remote Wakeup Support
Rowan Decker <Smasher816@gmail.com>
parents: 302
diff changeset
89 #define TX_STATE_BOTH_FREE_ODD_FIRST 1
05a09eda53fb Inital Remote Wakeup Support
Rowan Decker <Smasher816@gmail.com>
parents: 302
diff changeset
90 #define TX_STATE_EVEN_FREE 2
05a09eda53fb Inital Remote Wakeup Support
Rowan Decker <Smasher816@gmail.com>
parents: 302
diff changeset
91 #define TX_STATE_ODD_FREE 3
05a09eda53fb Inital Remote Wakeup Support
Rowan Decker <Smasher816@gmail.com>
parents: 302
diff changeset
92 #define TX_STATE_NONE_FREE 4
231
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
93
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
94
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
95
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
96
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
97
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
98 // ----- Macros -----
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
99
326
05a09eda53fb Inital Remote Wakeup Support
Rowan Decker <Smasher816@gmail.com>
parents: 302
diff changeset
100 #define BDT_PID(n) (((n) >> 2) & 15)
231
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
101
326
05a09eda53fb Inital Remote Wakeup Support
Rowan Decker <Smasher816@gmail.com>
parents: 302
diff changeset
102 #define BDT_DESC(count, data) (BDT_OWN | BDT_DTS \
231
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
103 | ((data) ? BDT_DATA1 : BDT_DATA0) \
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
104 | ((count) << 16))
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
105
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
106 #define index(endpoint, tx, odd) (((endpoint) << 2) | ((tx) << 1) | (odd))
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
107 #define stat2bufferdescriptor(stat) (table + ((stat) >> 2))
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
108
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
109
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
110
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
111 // ----- Structs -----
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
112
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
113 // buffer descriptor table
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
114
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
115 typedef struct {
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
116 uint32_t desc;
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
117 void * addr;
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
118 } bdt_t;
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
119
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
120 static union {
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
121 struct {
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
122 union {
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
123 struct {
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
124 uint8_t bmRequestType;
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
125 uint8_t bRequest;
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
126 };
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
127 uint16_t wRequestAndType;
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
128 };
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
129 uint16_t wValue;
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
130 uint16_t wIndex;
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
131 uint16_t wLength;
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
132 };
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
133 struct {
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
134 uint32_t word1;
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
135 uint32_t word2;
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
136 };
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
137 } setup;
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
138
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
139
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
140
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
141 // ----- Variables -----
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
142
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
143 __attribute__ ((section(".usbdescriptortable"), used))
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
144 static bdt_t table[ (NUM_ENDPOINTS + 1) * 4 ];
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
145
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
146 static usb_packet_t *rx_first [ NUM_ENDPOINTS ];
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
147 static usb_packet_t *rx_last [ NUM_ENDPOINTS ];
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
148 static usb_packet_t *tx_first [ NUM_ENDPOINTS ];
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
149 static usb_packet_t *tx_last [ NUM_ENDPOINTS ];
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
150 uint16_t usb_rx_byte_count_data[ NUM_ENDPOINTS ];
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
151
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
152 static uint8_t tx_state[NUM_ENDPOINTS];
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
153
104
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
154 // SETUP always uses a DATA0 PID for the data field of the SETUP transaction.
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
155 // transactions in the data phase start with DATA1 and toggle (figure 8-12, USB1.1)
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
156 // Status stage uses a DATA1 PID.
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
157
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
158 static uint8_t ep0_rx0_buf[EP0_SIZE] __attribute__ ((aligned (4)));
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
159 static uint8_t ep0_rx1_buf[EP0_SIZE] __attribute__ ((aligned (4)));
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
160 static const uint8_t *ep0_tx_ptr = NULL;
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
161 static uint16_t ep0_tx_len;
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
162 static uint8_t ep0_tx_bdt_bank = 0;
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
163 static uint8_t ep0_tx_data_toggle = 0;
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
164 uint8_t usb_rx_memory_needed = 0;
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
165
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
166 volatile uint8_t usb_configuration = 0;
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
167 volatile uint8_t usb_reboot_timer = 0;
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
168
231
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
169 static uint8_t reply_buffer[8];
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
170
420
23a1868b4ac2 Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents: 385
diff changeset
171 static uint8_t power_neg_delay;
23a1868b4ac2 Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents: 385
diff changeset
172 static uint32_t power_neg_time;
23a1868b4ac2 Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents: 385
diff changeset
173
439
68e19d7c953e Adding proper remote wake-up support
Jacob Alexander <haata@kiibohd.com>
parents: 438
diff changeset
174 static uint8_t usb_dev_sleep = 0;
68e19d7c953e Adding proper remote wake-up support
Jacob Alexander <haata@kiibohd.com>
parents: 438
diff changeset
175
231
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
176
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
177
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
178 // ----- Functions -----
104
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
179
175
c70f641581b5 McHCK USB WORKS!!
Jacob Alexander <haata@kiibohd.com>
parents: 171
diff changeset
180 static void endpoint0_stall()
104
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
181 {
368
06a54d582bf8 FIxing Media Keys and general USB compatibilty
Jacob Alexander <haata@kiibohd.com>
parents: 347
diff changeset
182 #ifdef UART_DEBUG_UNKNOWN
06a54d582bf8 FIxing Media Keys and general USB compatibilty
Jacob Alexander <haata@kiibohd.com>
parents: 347
diff changeset
183 print("STALL" NL );
06a54d582bf8 FIxing Media Keys and general USB compatibilty
Jacob Alexander <haata@kiibohd.com>
parents: 347
diff changeset
184 #endif
104
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
185 USB0_ENDPT0 = USB_ENDPT_EPSTALL | USB_ENDPT_EPRXEN | USB_ENDPT_EPTXEN | USB_ENDPT_EPHSHK;
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
186 }
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
187
231
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
188 static void endpoint0_transmit( const void *data, uint32_t len )
104
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
189 {
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
190 table[index(0, TX, ep0_tx_bdt_bank)].addr = (void *)data;
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
191 table[index(0, TX, ep0_tx_bdt_bank)].desc = BDT_DESC(len, ep0_tx_data_toggle);
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
192 ep0_tx_data_toggle ^= 1;
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
193 ep0_tx_bdt_bank ^= 1;
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
194 }
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
195
447
56237ba5da6f Adding auto-restart support whenever USB gets into an odd state
Jacob Alexander <haata@kiibohd.com>
parents: 439
diff changeset
196 void usb_reinit()
56237ba5da6f Adding auto-restart support whenever USB gets into an odd state
Jacob Alexander <haata@kiibohd.com>
parents: 439
diff changeset
197 {
56237ba5da6f Adding auto-restart support whenever USB gets into an odd state
Jacob Alexander <haata@kiibohd.com>
parents: 439
diff changeset
198 power_neg_delay = 0;
56237ba5da6f Adding auto-restart support whenever USB gets into an odd state
Jacob Alexander <haata@kiibohd.com>
parents: 439
diff changeset
199 usb_configuration = 0; // Clear USB configuration if we have one
56237ba5da6f Adding auto-restart support whenever USB gets into an odd state
Jacob Alexander <haata@kiibohd.com>
parents: 439
diff changeset
200 USB0_CONTROL = 0; // Disable D+ Pullup to simulate disconnect
56237ba5da6f Adding auto-restart support whenever USB gets into an odd state
Jacob Alexander <haata@kiibohd.com>
parents: 439
diff changeset
201 delay(10); // Delay is necessary to simulate disconnect
56237ba5da6f Adding auto-restart support whenever USB gets into an odd state
Jacob Alexander <haata@kiibohd.com>
parents: 439
diff changeset
202 usb_init();
56237ba5da6f Adding auto-restart support whenever USB gets into an odd state
Jacob Alexander <haata@kiibohd.com>
parents: 439
diff changeset
203 }
56237ba5da6f Adding auto-restart support whenever USB gets into an odd state
Jacob Alexander <haata@kiibohd.com>
parents: 439
diff changeset
204
420
23a1868b4ac2 Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents: 385
diff changeset
205 // Used to check any USB state changes that may not have a proper interrupt
23a1868b4ac2 Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents: 385
diff changeset
206 // Called once per scan loop, should take minimal processing time or it may affect other modules
23a1868b4ac2 Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents: 385
diff changeset
207 void usb_device_check()
23a1868b4ac2 Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents: 385
diff changeset
208 {
23a1868b4ac2 Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents: 385
diff changeset
209 // Check to see if we're still waiting for the next USB request after Get Configuration Descriptor
23a1868b4ac2 Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents: 385
diff changeset
210 // If still waiting, restart the USB initialization with a lower power requirement
23a1868b4ac2 Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents: 385
diff changeset
211 if ( power_neg_delay )
23a1868b4ac2 Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents: 385
diff changeset
212 {
23a1868b4ac2 Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents: 385
diff changeset
213 // Check if 100 ms has elapsed
23a1868b4ac2 Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents: 385
diff changeset
214 if ( systick_millis_count - power_neg_time > 100 )
23a1868b4ac2 Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents: 385
diff changeset
215 {
23a1868b4ac2 Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents: 385
diff changeset
216 // Update bMaxPower
23a1868b4ac2 Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents: 385
diff changeset
217 // The value set is in increments of 2 mA
23a1868b4ac2 Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents: 385
diff changeset
218 // So 50 * 2 mA = 100 mA
23a1868b4ac2 Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents: 385
diff changeset
219 // XXX Currently only transitions to 100 mA
23a1868b4ac2 Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents: 385
diff changeset
220 // It may be possible to transition down again to 20 mA
23a1868b4ac2 Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents: 385
diff changeset
221 *usb_bMaxPower = 50;
23a1868b4ac2 Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents: 385
diff changeset
222
23a1868b4ac2 Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents: 385
diff changeset
223 // Re-initialize USB
447
56237ba5da6f Adding auto-restart support whenever USB gets into an odd state
Jacob Alexander <haata@kiibohd.com>
parents: 439
diff changeset
224 usb_reinit();
420
23a1868b4ac2 Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents: 385
diff changeset
225 }
23a1868b4ac2 Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents: 385
diff changeset
226 }
23a1868b4ac2 Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents: 385
diff changeset
227 }
23a1868b4ac2 Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents: 385
diff changeset
228
175
c70f641581b5 McHCK USB WORKS!!
Jacob Alexander <haata@kiibohd.com>
parents: 171
diff changeset
229 static void usb_setup()
104
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
230 {
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
231 const uint8_t *data = NULL;
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
232 uint32_t datalen = 0;
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
233 const usb_descriptor_list_t *list;
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
234 uint32_t size;
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
235 volatile uint8_t *reg;
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
236 uint8_t epconf;
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
237 const uint8_t *cfg;
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
238 int i;
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
239
420
23a1868b4ac2 Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents: 385
diff changeset
240 // If another request is made, disable the power negotiation check
23a1868b4ac2 Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents: 385
diff changeset
241 // See GET_DESCRIPTOR - Configuration
23a1868b4ac2 Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents: 385
diff changeset
242 if ( power_neg_delay )
23a1868b4ac2 Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents: 385
diff changeset
243 {
23a1868b4ac2 Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents: 385
diff changeset
244 power_neg_delay = 0;
23a1868b4ac2 Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents: 385
diff changeset
245 }
23a1868b4ac2 Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents: 385
diff changeset
246
231
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
247 switch ( setup.wRequestAndType )
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
248 {
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
249 case 0x0500: // SET_ADDRESS
368
06a54d582bf8 FIxing Media Keys and general USB compatibilty
Jacob Alexander <haata@kiibohd.com>
parents: 347
diff changeset
250 goto send;
06a54d582bf8 FIxing Media Keys and general USB compatibilty
Jacob Alexander <haata@kiibohd.com>
parents: 347
diff changeset
251
231
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
252 case 0x0900: // SET_CONFIGURATION
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
253 #ifdef UART_DEBUG
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
254 print("CONFIGURE - ");
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
255 #endif
104
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
256 usb_configuration = setup.wValue;
347
136e47478441 UARTConnect enumeration working!
Jacob Alexander <haata@kiibohd.com>
parents: 346
diff changeset
257 Output_Available = usb_configuration;
104
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
258 reg = &USB0_ENDPT1;
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
259 cfg = usb_endpoint_config_table;
420
23a1868b4ac2 Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents: 385
diff changeset
260
23a1868b4ac2 Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents: 385
diff changeset
261 // Now configured so we can utilize bMaxPower now
23a1868b4ac2 Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents: 385
diff changeset
262 Output_update_usb_current( *usb_bMaxPower * 2 );
23a1868b4ac2 Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents: 385
diff changeset
263
104
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
264 // clear all BDT entries, free any allocated memory...
231
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
265 for ( i = 4; i < ( NUM_ENDPOINTS + 1) * 4; i++ )
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
266 {
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
267 if ( table[i].desc & BDT_OWN )
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
268 {
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
269 usb_free( (usb_packet_t *)((uint8_t *)(table[ i ].addr) - 8) );
117
5ffefdf89b37 Adding in USB module updates from Teensyduino 1.18rc2.
Jacob Alexander <haata@kiibohd.com>
parents: 109
diff changeset
270 }
5ffefdf89b37 Adding in USB module updates from Teensyduino 1.18rc2.
Jacob Alexander <haata@kiibohd.com>
parents: 109
diff changeset
271 }
5ffefdf89b37 Adding in USB module updates from Teensyduino 1.18rc2.
Jacob Alexander <haata@kiibohd.com>
parents: 109
diff changeset
272 // free all queued packets
231
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
273 for ( i = 0; i < NUM_ENDPOINTS; i++ )
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
274 {
117
5ffefdf89b37 Adding in USB module updates from Teensyduino 1.18rc2.
Jacob Alexander <haata@kiibohd.com>
parents: 109
diff changeset
275 usb_packet_t *p, *n;
5ffefdf89b37 Adding in USB module updates from Teensyduino 1.18rc2.
Jacob Alexander <haata@kiibohd.com>
parents: 109
diff changeset
276 p = rx_first[i];
231
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
277 while ( p )
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
278 {
117
5ffefdf89b37 Adding in USB module updates from Teensyduino 1.18rc2.
Jacob Alexander <haata@kiibohd.com>
parents: 109
diff changeset
279 n = p->next;
5ffefdf89b37 Adding in USB module updates from Teensyduino 1.18rc2.
Jacob Alexander <haata@kiibohd.com>
parents: 109
diff changeset
280 usb_free(p);
5ffefdf89b37 Adding in USB module updates from Teensyduino 1.18rc2.
Jacob Alexander <haata@kiibohd.com>
parents: 109
diff changeset
281 p = n;
5ffefdf89b37 Adding in USB module updates from Teensyduino 1.18rc2.
Jacob Alexander <haata@kiibohd.com>
parents: 109
diff changeset
282 }
250
afe96322d0c5 Code formatting cleanup.
Jacob Alexander <haata@kiibohd.com>
parents: 231
diff changeset
283 rx_first[ i ] = NULL;
afe96322d0c5 Code formatting cleanup.
Jacob Alexander <haata@kiibohd.com>
parents: 231
diff changeset
284 rx_last[ i ] = NULL;
117
5ffefdf89b37 Adding in USB module updates from Teensyduino 1.18rc2.
Jacob Alexander <haata@kiibohd.com>
parents: 109
diff changeset
285 p = tx_first[i];
231
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
286 while (p)
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
287 {
117
5ffefdf89b37 Adding in USB module updates from Teensyduino 1.18rc2.
Jacob Alexander <haata@kiibohd.com>
parents: 109
diff changeset
288 n = p->next;
5ffefdf89b37 Adding in USB module updates from Teensyduino 1.18rc2.
Jacob Alexander <haata@kiibohd.com>
parents: 109
diff changeset
289 usb_free(p);
5ffefdf89b37 Adding in USB module updates from Teensyduino 1.18rc2.
Jacob Alexander <haata@kiibohd.com>
parents: 109
diff changeset
290 p = n;
5ffefdf89b37 Adding in USB module updates from Teensyduino 1.18rc2.
Jacob Alexander <haata@kiibohd.com>
parents: 109
diff changeset
291 }
250
afe96322d0c5 Code formatting cleanup.
Jacob Alexander <haata@kiibohd.com>
parents: 231
diff changeset
292 tx_first[ i ] = NULL;
afe96322d0c5 Code formatting cleanup.
Jacob Alexander <haata@kiibohd.com>
parents: 231
diff changeset
293 tx_last[ i ] = NULL;
117
5ffefdf89b37 Adding in USB module updates from Teensyduino 1.18rc2.
Jacob Alexander <haata@kiibohd.com>
parents: 109
diff changeset
294 usb_rx_byte_count_data[i] = 0;
231
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
295
250
afe96322d0c5 Code formatting cleanup.
Jacob Alexander <haata@kiibohd.com>
parents: 231
diff changeset
296 switch ( tx_state[ i ] )
afe96322d0c5 Code formatting cleanup.
Jacob Alexander <haata@kiibohd.com>
parents: 231
diff changeset
297 {
231
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
298 case TX_STATE_EVEN_FREE:
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
299 case TX_STATE_NONE_FREE_EVEN_FIRST:
250
afe96322d0c5 Code formatting cleanup.
Jacob Alexander <haata@kiibohd.com>
parents: 231
diff changeset
300 tx_state[ i ] = TX_STATE_BOTH_FREE_EVEN_FIRST;
117
5ffefdf89b37 Adding in USB module updates from Teensyduino 1.18rc2.
Jacob Alexander <haata@kiibohd.com>
parents: 109
diff changeset
301 break;
231
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
302 case TX_STATE_ODD_FREE:
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
303 case TX_STATE_NONE_FREE_ODD_FIRST:
250
afe96322d0c5 Code formatting cleanup.
Jacob Alexander <haata@kiibohd.com>
parents: 231
diff changeset
304 tx_state[ i ] = TX_STATE_BOTH_FREE_ODD_FIRST;
117
5ffefdf89b37 Adding in USB module updates from Teensyduino 1.18rc2.
Jacob Alexander <haata@kiibohd.com>
parents: 109
diff changeset
305 break;
231
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
306 default:
117
5ffefdf89b37 Adding in USB module updates from Teensyduino 1.18rc2.
Jacob Alexander <haata@kiibohd.com>
parents: 109
diff changeset
307 break;
104
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
308 }
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
309 }
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
310 usb_rx_memory_needed = 0;
231
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
311 for ( i = 1; i <= NUM_ENDPOINTS; i++ )
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
312 {
104
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
313 epconf = *cfg++;
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
314 *reg = epconf;
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
315 reg += 4;
231
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
316 if ( epconf & USB_ENDPT_EPRXEN )
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
317 {
104
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
318 usb_packet_t *p;
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
319 p = usb_malloc();
231
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
320 if ( p )
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
321 {
250
afe96322d0c5 Code formatting cleanup.
Jacob Alexander <haata@kiibohd.com>
parents: 231
diff changeset
322 table[ index( i, RX, EVEN ) ].addr = p->buf;
afe96322d0c5 Code formatting cleanup.
Jacob Alexander <haata@kiibohd.com>
parents: 231
diff changeset
323 table[ index( i, RX, EVEN ) ].desc = BDT_DESC( 64, 0 );
231
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
324 }
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
325 else
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
326 {
250
afe96322d0c5 Code formatting cleanup.
Jacob Alexander <haata@kiibohd.com>
parents: 231
diff changeset
327 table[ index( i, RX, EVEN ) ].desc = 0;
104
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
328 usb_rx_memory_needed++;
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
329 }
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
330 p = usb_malloc();
231
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
331 if ( p )
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
332 {
250
afe96322d0c5 Code formatting cleanup.
Jacob Alexander <haata@kiibohd.com>
parents: 231
diff changeset
333 table[ index( i, RX, ODD ) ].addr = p->buf;
afe96322d0c5 Code formatting cleanup.
Jacob Alexander <haata@kiibohd.com>
parents: 231
diff changeset
334 table[ index( i, RX, ODD ) ].desc = BDT_DESC( 64, 1 );
231
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
335 }
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
336 else
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
337 {
250
afe96322d0c5 Code formatting cleanup.
Jacob Alexander <haata@kiibohd.com>
parents: 231
diff changeset
338 table[ index( i, RX, ODD ) ].desc = 0;
104
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
339 usb_rx_memory_needed++;
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
340 }
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
341 }
250
afe96322d0c5 Code formatting cleanup.
Jacob Alexander <haata@kiibohd.com>
parents: 231
diff changeset
342 table[ index( i, TX, EVEN ) ].desc = 0;
afe96322d0c5 Code formatting cleanup.
Jacob Alexander <haata@kiibohd.com>
parents: 231
diff changeset
343 table[ index( i, TX, ODD ) ].desc = 0;
104
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
344 }
368
06a54d582bf8 FIxing Media Keys and general USB compatibilty
Jacob Alexander <haata@kiibohd.com>
parents: 347
diff changeset
345 goto send;
06a54d582bf8 FIxing Media Keys and general USB compatibilty
Jacob Alexander <haata@kiibohd.com>
parents: 347
diff changeset
346
231
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
347 case 0x0880: // GET_CONFIGURATION
104
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
348 reply_buffer[0] = usb_configuration;
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
349 datalen = 1;
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
350 data = reply_buffer;
368
06a54d582bf8 FIxing Media Keys and general USB compatibilty
Jacob Alexander <haata@kiibohd.com>
parents: 347
diff changeset
351 goto send;
06a54d582bf8 FIxing Media Keys and general USB compatibilty
Jacob Alexander <haata@kiibohd.com>
parents: 347
diff changeset
352
231
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
353 case 0x0080: // GET_STATUS (device)
346
1beec5f17e64 Revert "Merge pull request #27 from smasher816/wakeup-devel"
Jacob Alexander <haata@kiibohd.com>
parents: 327
diff changeset
354 reply_buffer[0] = 0;
104
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
355 reply_buffer[1] = 0;
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
356 datalen = 2;
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
357 data = reply_buffer;
368
06a54d582bf8 FIxing Media Keys and general USB compatibilty
Jacob Alexander <haata@kiibohd.com>
parents: 347
diff changeset
358 goto send;
06a54d582bf8 FIxing Media Keys and general USB compatibilty
Jacob Alexander <haata@kiibohd.com>
parents: 347
diff changeset
359
231
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
360 case 0x0082: // GET_STATUS (endpoint)
302
ac842066568a Adding additional case statements for SET_FEATURE and CLEAR_FEATURE
Jacob Alexander <haata@kiibohd.com>
parents: 301
diff changeset
361 if ( setup.wIndex > NUM_ENDPOINTS )
231
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
362 {
104
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
363 // TODO: do we need to handle IN vs OUT here?
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
364 endpoint0_stall();
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
365 return;
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
366 }
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
367 reply_buffer[0] = 0;
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
368 reply_buffer[1] = 0;
231
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
369 if ( *(uint8_t *)(&USB0_ENDPT0 + setup.wIndex * 4) & 0x02 )
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
370 reply_buffer[0] = 1;
104
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
371 data = reply_buffer;
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
372 datalen = 2;
368
06a54d582bf8 FIxing Media Keys and general USB compatibilty
Jacob Alexander <haata@kiibohd.com>
parents: 347
diff changeset
373 goto send;
06a54d582bf8 FIxing Media Keys and general USB compatibilty
Jacob Alexander <haata@kiibohd.com>
parents: 347
diff changeset
374
302
ac842066568a Adding additional case statements for SET_FEATURE and CLEAR_FEATURE
Jacob Alexander <haata@kiibohd.com>
parents: 301
diff changeset
375 case 0x0100: // CLEAR_FEATURE (device)
420
23a1868b4ac2 Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents: 385
diff changeset
376 switch ( setup.wValue )
23a1868b4ac2 Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents: 385
diff changeset
377 {
23a1868b4ac2 Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents: 385
diff changeset
378 // CLEAR_FEATURE(DEVICE_REMOTE_WAKEUP)
23a1868b4ac2 Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents: 385
diff changeset
379 // See SET_FEATURE(DEVICE_REMOTE_WAKEUP) for details
23a1868b4ac2 Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents: 385
diff changeset
380 case 0x1:
23a1868b4ac2 Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents: 385
diff changeset
381 goto send;
23a1868b4ac2 Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents: 385
diff changeset
382 }
23a1868b4ac2 Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents: 385
diff changeset
383
23a1868b4ac2 Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents: 385
diff changeset
384 warn_msg("SET_FEATURE - Device wValue(");
23a1868b4ac2 Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents: 385
diff changeset
385 printHex( setup.wValue );
23a1868b4ac2 Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents: 385
diff changeset
386 print( ")" NL );
23a1868b4ac2 Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents: 385
diff changeset
387 endpoint0_stall();
23a1868b4ac2 Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents: 385
diff changeset
388 return;
23a1868b4ac2 Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents: 385
diff changeset
389
302
ac842066568a Adding additional case statements for SET_FEATURE and CLEAR_FEATURE
Jacob Alexander <haata@kiibohd.com>
parents: 301
diff changeset
390 case 0x0101: // CLEAR_FEATURE (interface)
ac842066568a Adding additional case statements for SET_FEATURE and CLEAR_FEATURE
Jacob Alexander <haata@kiibohd.com>
parents: 301
diff changeset
391 // TODO: Currently ignoring, perhaps useful? -HaaTa
420
23a1868b4ac2 Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents: 385
diff changeset
392 warn_msg("CLEAR_FEATURE - Interface wValue(");
23a1868b4ac2 Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents: 385
diff changeset
393 printHex( setup.wValue );
23a1868b4ac2 Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents: 385
diff changeset
394 print(") wIndex(");
23a1868b4ac2 Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents: 385
diff changeset
395 printHex( setup.wIndex );
23a1868b4ac2 Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents: 385
diff changeset
396 print( ")" NL );
302
ac842066568a Adding additional case statements for SET_FEATURE and CLEAR_FEATURE
Jacob Alexander <haata@kiibohd.com>
parents: 301
diff changeset
397 endpoint0_stall();
ac842066568a Adding additional case statements for SET_FEATURE and CLEAR_FEATURE
Jacob Alexander <haata@kiibohd.com>
parents: 301
diff changeset
398 return;
368
06a54d582bf8 FIxing Media Keys and general USB compatibilty
Jacob Alexander <haata@kiibohd.com>
parents: 347
diff changeset
399
381
fbe55b27dc02 Cleaning up CLEAR_FEATURE (endpoint)
Jacob Alexander <haata@kiibohd.com>
parents: 376
diff changeset
400 case 0x0102: // CLEAR_FEATURE (endpoint)
104
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
401 i = setup.wIndex & 0x7F;
231
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
402 if ( i > NUM_ENDPOINTS || setup.wValue != 0 )
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
403 {
104
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
404 endpoint0_stall();
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
405 return;
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
406 }
381
fbe55b27dc02 Cleaning up CLEAR_FEATURE (endpoint)
Jacob Alexander <haata@kiibohd.com>
parents: 376
diff changeset
407 (*(uint8_t *)(&USB0_ENDPT0 + setup.wIndex * 4)) &= ~0x02;
104
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
408 // TODO: do we need to clear the data toggle here?
381
fbe55b27dc02 Cleaning up CLEAR_FEATURE (endpoint)
Jacob Alexander <haata@kiibohd.com>
parents: 376
diff changeset
409 goto send;
368
06a54d582bf8 FIxing Media Keys and general USB compatibilty
Jacob Alexander <haata@kiibohd.com>
parents: 347
diff changeset
410
302
ac842066568a Adding additional case statements for SET_FEATURE and CLEAR_FEATURE
Jacob Alexander <haata@kiibohd.com>
parents: 301
diff changeset
411 case 0x0300: // SET_FEATURE (device)
420
23a1868b4ac2 Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents: 385
diff changeset
412 switch ( setup.wValue )
23a1868b4ac2 Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents: 385
diff changeset
413 {
23a1868b4ac2 Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents: 385
diff changeset
414 // SET_FEATURE(DEVICE_REMOTE_WAKEUP)
23a1868b4ac2 Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents: 385
diff changeset
415 // XXX: Only used to confirm Remote Wake
23a1868b4ac2 Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents: 385
diff changeset
416 // Used on Mac OSX and Windows not on Linux
23a1868b4ac2 Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents: 385
diff changeset
417 // Good post on the behaviour:
23a1868b4ac2 Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents: 385
diff changeset
418 // http://community.silabs.com/t5/8-bit-MCU/Remote-wakeup-HID/m-p/74957#M30802
23a1868b4ac2 Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents: 385
diff changeset
419 case 0x1:
23a1868b4ac2 Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents: 385
diff changeset
420 goto send;
23a1868b4ac2 Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents: 385
diff changeset
421 }
23a1868b4ac2 Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents: 385
diff changeset
422
23a1868b4ac2 Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents: 385
diff changeset
423 warn_msg("SET_FEATURE - Device wValue(");
23a1868b4ac2 Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents: 385
diff changeset
424 printHex( setup.wValue );
23a1868b4ac2 Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents: 385
diff changeset
425 print( ")" NL );
23a1868b4ac2 Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents: 385
diff changeset
426 endpoint0_stall();
23a1868b4ac2 Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents: 385
diff changeset
427 return;
23a1868b4ac2 Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents: 385
diff changeset
428
302
ac842066568a Adding additional case statements for SET_FEATURE and CLEAR_FEATURE
Jacob Alexander <haata@kiibohd.com>
parents: 301
diff changeset
429 case 0x0301: // SET_FEATURE (interface)
ac842066568a Adding additional case statements for SET_FEATURE and CLEAR_FEATURE
Jacob Alexander <haata@kiibohd.com>
parents: 301
diff changeset
430 // TODO: Currently ignoring, perhaps useful? -HaaTa
420
23a1868b4ac2 Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents: 385
diff changeset
431 warn_msg("SET_FEATURE - Interface wValue(");
23a1868b4ac2 Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents: 385
diff changeset
432 printHex( setup.wValue );
23a1868b4ac2 Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents: 385
diff changeset
433 print(") wIndex(");
23a1868b4ac2 Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents: 385
diff changeset
434 printHex( setup.wIndex );
23a1868b4ac2 Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents: 385
diff changeset
435 print( ")" NL );
302
ac842066568a Adding additional case statements for SET_FEATURE and CLEAR_FEATURE
Jacob Alexander <haata@kiibohd.com>
parents: 301
diff changeset
436 endpoint0_stall();
ac842066568a Adding additional case statements for SET_FEATURE and CLEAR_FEATURE
Jacob Alexander <haata@kiibohd.com>
parents: 301
diff changeset
437 return;
368
06a54d582bf8 FIxing Media Keys and general USB compatibilty
Jacob Alexander <haata@kiibohd.com>
parents: 347
diff changeset
438
231
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
439 case 0x0302: // SET_FEATURE (endpoint)
104
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
440 i = setup.wIndex & 0x7F;
231
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
441 if ( i > NUM_ENDPOINTS || setup.wValue != 0 )
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
442 {
104
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
443 // TODO: do we need to handle IN vs OUT here?
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
444 endpoint0_stall();
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
445 return;
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
446 }
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
447 (*(uint8_t *)(&USB0_ENDPT0 + setup.wIndex * 4)) |= 0x02;
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
448 // TODO: do we need to clear the data toggle here?
368
06a54d582bf8 FIxing Media Keys and general USB compatibilty
Jacob Alexander <haata@kiibohd.com>
parents: 347
diff changeset
449 goto send;
06a54d582bf8 FIxing Media Keys and general USB compatibilty
Jacob Alexander <haata@kiibohd.com>
parents: 347
diff changeset
450
231
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
451 case 0x0680: // GET_DESCRIPTOR
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
452 case 0x0681:
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
453 #ifdef UART_DEBUG
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
454 print("desc:");
250
afe96322d0c5 Code formatting cleanup.
Jacob Alexander <haata@kiibohd.com>
parents: 231
diff changeset
455 printHex( setup.wValue );
afe96322d0c5 Code formatting cleanup.
Jacob Alexander <haata@kiibohd.com>
parents: 231
diff changeset
456 print( NL );
231
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
457 #endif
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
458 for ( list = usb_descriptor_list; 1; list++ )
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
459 {
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
460 if ( list->addr == NULL )
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
461 break;
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
462 if ( setup.wValue == list->wValue && setup.wIndex == list->wIndex )
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
463 {
104
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
464 data = list->addr;
231
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
465 if ( (setup.wValue >> 8) == 3 )
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
466 {
117
5ffefdf89b37 Adding in USB module updates from Teensyduino 1.18rc2.
Jacob Alexander <haata@kiibohd.com>
parents: 109
diff changeset
467 // for string descriptors, use the descriptor's
5ffefdf89b37 Adding in USB module updates from Teensyduino 1.18rc2.
Jacob Alexander <haata@kiibohd.com>
parents: 109
diff changeset
468 // length field, allowing runtime configured
5ffefdf89b37 Adding in USB module updates from Teensyduino 1.18rc2.
Jacob Alexander <haata@kiibohd.com>
parents: 109
diff changeset
469 // length.
5ffefdf89b37 Adding in USB module updates from Teensyduino 1.18rc2.
Jacob Alexander <haata@kiibohd.com>
parents: 109
diff changeset
470 datalen = *(list->addr);
231
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
471 }
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
472 else
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
473 {
117
5ffefdf89b37 Adding in USB module updates from Teensyduino 1.18rc2.
Jacob Alexander <haata@kiibohd.com>
parents: 109
diff changeset
474 datalen = list->length;
5ffefdf89b37 Adding in USB module updates from Teensyduino 1.18rc2.
Jacob Alexander <haata@kiibohd.com>
parents: 109
diff changeset
475 }
420
23a1868b4ac2 Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents: 385
diff changeset
476
23a1868b4ac2 Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents: 385
diff changeset
477 // XXX Power negotiation hack -HaaTa
23a1868b4ac2 Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents: 385
diff changeset
478 // Some devices such as the Apple Ipad do not support bMaxPower greater than 100 mA
23a1868b4ac2 Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents: 385
diff changeset
479 // However, there is no provision in the basic USB 2.0 stack for power negotiation
23a1868b4ac2 Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents: 385
diff changeset
480 // To get around this:
23a1868b4ac2 Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents: 385
diff changeset
481 // * Attempt to set bMaxPower to 500 mA first
23a1868b4ac2 Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents: 385
diff changeset
482 // * If more than 100 ms passes since retrieving a Get Configuration Descriptor
23a1868b4ac2 Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents: 385
diff changeset
483 // (Descriptor with bMaxPower in it)
23a1868b4ac2 Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents: 385
diff changeset
484 // * Change usb_bMaxPower to 50 (100 mA)
23a1868b4ac2 Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents: 385
diff changeset
485 // * Restart the USB init process
23a1868b4ac2 Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents: 385
diff changeset
486 // According to notes online, it says that some Apple devices can only do 20 mA
23a1868b4ac2 Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents: 385
diff changeset
487 // However, in my testing this hasn't been the case
23a1868b4ac2 Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents: 385
diff changeset
488 // (you can also draw as much current as you want if you just lie in the descriptor :P)
23a1868b4ac2 Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents: 385
diff changeset
489 // If this becomes an issue we can use this hack a second time to negotiate down to 20 mA
23a1868b4ac2 Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents: 385
diff changeset
490 // (which should be fine for just the mcu)
23a1868b4ac2 Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents: 385
diff changeset
491 if ( setup.wValue == 0x0200 && setup.wIndex == 0x0 )
23a1868b4ac2 Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents: 385
diff changeset
492 {
23a1868b4ac2 Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents: 385
diff changeset
493 power_neg_delay = 1;
23a1868b4ac2 Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents: 385
diff changeset
494 power_neg_time = systick_millis_count;
23a1868b4ac2 Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents: 385
diff changeset
495 }
23a1868b4ac2 Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents: 385
diff changeset
496
231
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
497 #if UART_DEBUG
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
498 print("Desc found, ");
250
afe96322d0c5 Code formatting cleanup.
Jacob Alexander <haata@kiibohd.com>
parents: 231
diff changeset
499 printHex32( (uint32_t)data );
231
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
500 print(",");
250
afe96322d0c5 Code formatting cleanup.
Jacob Alexander <haata@kiibohd.com>
parents: 231
diff changeset
501 printHex( datalen );
231
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
502 print(",");
250
afe96322d0c5 Code formatting cleanup.
Jacob Alexander <haata@kiibohd.com>
parents: 231
diff changeset
503 printHex_op( data[0], 2 );
afe96322d0c5 Code formatting cleanup.
Jacob Alexander <haata@kiibohd.com>
parents: 231
diff changeset
504 printHex_op( data[1], 2 );
afe96322d0c5 Code formatting cleanup.
Jacob Alexander <haata@kiibohd.com>
parents: 231
diff changeset
505 printHex_op( data[2], 2 );
afe96322d0c5 Code formatting cleanup.
Jacob Alexander <haata@kiibohd.com>
parents: 231
diff changeset
506 printHex_op( data[3], 2 );
afe96322d0c5 Code formatting cleanup.
Jacob Alexander <haata@kiibohd.com>
parents: 231
diff changeset
507 printHex_op( data[4], 2 );
afe96322d0c5 Code formatting cleanup.
Jacob Alexander <haata@kiibohd.com>
parents: 231
diff changeset
508 printHex_op( data[5], 2 );
afe96322d0c5 Code formatting cleanup.
Jacob Alexander <haata@kiibohd.com>
parents: 231
diff changeset
509 print( NL );
231
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
510 #endif
104
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
511 goto send;
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
512 }
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
513 }
231
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
514 #ifdef UART_DEBUG
250
afe96322d0c5 Code formatting cleanup.
Jacob Alexander <haata@kiibohd.com>
parents: 231
diff changeset
515 print( "desc: not found" NL );
231
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
516 #endif
104
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
517 endpoint0_stall();
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
518 return;
231
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
519
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
520 case 0x2221: // CDC_SET_CONTROL_LINE_STATE
104
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
521 usb_cdc_line_rtsdtr = setup.wValue;
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
522 //serial_print("set control line state\n");
368
06a54d582bf8 FIxing Media Keys and general USB compatibilty
Jacob Alexander <haata@kiibohd.com>
parents: 347
diff changeset
523 goto send;
231
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
524
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
525 case 0x21A1: // CDC_GET_LINE_CODING
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
526 data = (uint8_t*)usb_cdc_line_coding;
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
527 datalen = sizeof( usb_cdc_line_coding );
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
528 goto send;
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
529
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
530 case 0x2021: // CDC_SET_LINE_CODING
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
531 // XXX Needed?
104
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
532 //serial_print("set coding, waiting...\n");
368
06a54d582bf8 FIxing Media Keys and general USB compatibilty
Jacob Alexander <haata@kiibohd.com>
parents: 347
diff changeset
533 return;
231
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
534
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
535 case 0x0921: // HID SET_REPORT
383
801e7628d977 Fixing long-standing SET_REPORT bug
Jacob Alexander <haata@kiibohd.com>
parents: 381
diff changeset
536 // Interface
801e7628d977 Fixing long-standing SET_REPORT bug
Jacob Alexander <haata@kiibohd.com>
parents: 381
diff changeset
537 switch ( setup.wIndex & 0xFF )
801e7628d977 Fixing long-standing SET_REPORT bug
Jacob Alexander <haata@kiibohd.com>
parents: 381
diff changeset
538 {
801e7628d977 Fixing long-standing SET_REPORT bug
Jacob Alexander <haata@kiibohd.com>
parents: 381
diff changeset
539 // Keyboard Interface
801e7628d977 Fixing long-standing SET_REPORT bug
Jacob Alexander <haata@kiibohd.com>
parents: 381
diff changeset
540 case KEYBOARD_INTERFACE:
801e7628d977 Fixing long-standing SET_REPORT bug
Jacob Alexander <haata@kiibohd.com>
parents: 381
diff changeset
541 break;
801e7628d977 Fixing long-standing SET_REPORT bug
Jacob Alexander <haata@kiibohd.com>
parents: 381
diff changeset
542 // NKRO Keyboard Interface
801e7628d977 Fixing long-standing SET_REPORT bug
Jacob Alexander <haata@kiibohd.com>
parents: 381
diff changeset
543 case NKRO_KEYBOARD_INTERFACE:
801e7628d977 Fixing long-standing SET_REPORT bug
Jacob Alexander <haata@kiibohd.com>
parents: 381
diff changeset
544 break;
801e7628d977 Fixing long-standing SET_REPORT bug
Jacob Alexander <haata@kiibohd.com>
parents: 381
diff changeset
545 default:
801e7628d977 Fixing long-standing SET_REPORT bug
Jacob Alexander <haata@kiibohd.com>
parents: 381
diff changeset
546 warn_msg("Unknown interface - ");
801e7628d977 Fixing long-standing SET_REPORT bug
Jacob Alexander <haata@kiibohd.com>
parents: 381
diff changeset
547 printHex( setup.wIndex );
801e7628d977 Fixing long-standing SET_REPORT bug
Jacob Alexander <haata@kiibohd.com>
parents: 381
diff changeset
548 print( NL );
801e7628d977 Fixing long-standing SET_REPORT bug
Jacob Alexander <haata@kiibohd.com>
parents: 381
diff changeset
549 endpoint0_stall();
801e7628d977 Fixing long-standing SET_REPORT bug
Jacob Alexander <haata@kiibohd.com>
parents: 381
diff changeset
550 break;
801e7628d977 Fixing long-standing SET_REPORT bug
Jacob Alexander <haata@kiibohd.com>
parents: 381
diff changeset
551 }
368
06a54d582bf8 FIxing Media Keys and general USB compatibilty
Jacob Alexander <haata@kiibohd.com>
parents: 347
diff changeset
552
447
56237ba5da6f Adding auto-restart support whenever USB gets into an odd state
Jacob Alexander <haata@kiibohd.com>
parents: 439
diff changeset
553 goto send;
104
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
554
231
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
555 case 0x01A1: // HID GET_REPORT
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
556 #ifdef UART_DEBUG
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
557 print("GET_REPORT - ");
368
06a54d582bf8 FIxing Media Keys and general USB compatibilty
Jacob Alexander <haata@kiibohd.com>
parents: 347
diff changeset
558 printHex( setup.wIndex );
231
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
559 print(NL);
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
560 #endif
368
06a54d582bf8 FIxing Media Keys and general USB compatibilty
Jacob Alexander <haata@kiibohd.com>
parents: 347
diff changeset
561 // Search through descriptors returning necessary info
06a54d582bf8 FIxing Media Keys and general USB compatibilty
Jacob Alexander <haata@kiibohd.com>
parents: 347
diff changeset
562 for ( list = usb_descriptor_list; 1; list++ )
06a54d582bf8 FIxing Media Keys and general USB compatibilty
Jacob Alexander <haata@kiibohd.com>
parents: 347
diff changeset
563 {
06a54d582bf8 FIxing Media Keys and general USB compatibilty
Jacob Alexander <haata@kiibohd.com>
parents: 347
diff changeset
564 if ( list->addr == NULL )
06a54d582bf8 FIxing Media Keys and general USB compatibilty
Jacob Alexander <haata@kiibohd.com>
parents: 347
diff changeset
565 break;
06a54d582bf8 FIxing Media Keys and general USB compatibilty
Jacob Alexander <haata@kiibohd.com>
parents: 347
diff changeset
566 if ( list->wValue != 0x2200 )
06a54d582bf8 FIxing Media Keys and general USB compatibilty
Jacob Alexander <haata@kiibohd.com>
parents: 347
diff changeset
567 continue;
06a54d582bf8 FIxing Media Keys and general USB compatibilty
Jacob Alexander <haata@kiibohd.com>
parents: 347
diff changeset
568 if ( setup.wIndex == list->wIndex )
06a54d582bf8 FIxing Media Keys and general USB compatibilty
Jacob Alexander <haata@kiibohd.com>
parents: 347
diff changeset
569 {
06a54d582bf8 FIxing Media Keys and general USB compatibilty
Jacob Alexander <haata@kiibohd.com>
parents: 347
diff changeset
570 data = list->addr;
06a54d582bf8 FIxing Media Keys and general USB compatibilty
Jacob Alexander <haata@kiibohd.com>
parents: 347
diff changeset
571 datalen = list->length;
06a54d582bf8 FIxing Media Keys and general USB compatibilty
Jacob Alexander <haata@kiibohd.com>
parents: 347
diff changeset
572 goto send;
06a54d582bf8 FIxing Media Keys and general USB compatibilty
Jacob Alexander <haata@kiibohd.com>
parents: 347
diff changeset
573 }
06a54d582bf8 FIxing Media Keys and general USB compatibilty
Jacob Alexander <haata@kiibohd.com>
parents: 347
diff changeset
574 }
06a54d582bf8 FIxing Media Keys and general USB compatibilty
Jacob Alexander <haata@kiibohd.com>
parents: 347
diff changeset
575 endpoint0_stall();
06a54d582bf8 FIxing Media Keys and general USB compatibilty
Jacob Alexander <haata@kiibohd.com>
parents: 347
diff changeset
576 return;
231
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
577
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
578 case 0x0A21: // HID SET_IDLE
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
579 #ifdef UART_DEBUG
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
580 print("SET_IDLE - ");
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
581 printHex( setup.wValue );
447
56237ba5da6f Adding auto-restart support whenever USB gets into an odd state
Jacob Alexander <haata@kiibohd.com>
parents: 439
diff changeset
582 print(" - ");
56237ba5da6f Adding auto-restart support whenever USB gets into an odd state
Jacob Alexander <haata@kiibohd.com>
parents: 439
diff changeset
583 printHex( setup.wValue >> 8 );
231
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
584 print(NL);
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
585 #endif
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
586 USBKeys_Idle_Config = (setup.wValue >> 8);
447
56237ba5da6f Adding auto-restart support whenever USB gets into an odd state
Jacob Alexander <haata@kiibohd.com>
parents: 439
diff changeset
587 USBKeys_Idle_Expiry = 0;
368
06a54d582bf8 FIxing Media Keys and general USB compatibilty
Jacob Alexander <haata@kiibohd.com>
parents: 347
diff changeset
588 goto send;
231
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
589
447
56237ba5da6f Adding auto-restart support whenever USB gets into an odd state
Jacob Alexander <haata@kiibohd.com>
parents: 439
diff changeset
590 case 0x02A1: // HID GET_IDLE
56237ba5da6f Adding auto-restart support whenever USB gets into an odd state
Jacob Alexander <haata@kiibohd.com>
parents: 439
diff changeset
591 #ifdef UART_DEBUG
56237ba5da6f Adding auto-restart support whenever USB gets into an odd state
Jacob Alexander <haata@kiibohd.com>
parents: 439
diff changeset
592 print("SET_IDLE - ");
56237ba5da6f Adding auto-restart support whenever USB gets into an odd state
Jacob Alexander <haata@kiibohd.com>
parents: 439
diff changeset
593 printHex( setup.wValue );
56237ba5da6f Adding auto-restart support whenever USB gets into an odd state
Jacob Alexander <haata@kiibohd.com>
parents: 439
diff changeset
594 print(" - ");
56237ba5da6f Adding auto-restart support whenever USB gets into an odd state
Jacob Alexander <haata@kiibohd.com>
parents: 439
diff changeset
595 printHex( USBKeys_Idle_Config );
56237ba5da6f Adding auto-restart support whenever USB gets into an odd state
Jacob Alexander <haata@kiibohd.com>
parents: 439
diff changeset
596 print(NL);
56237ba5da6f Adding auto-restart support whenever USB gets into an odd state
Jacob Alexander <haata@kiibohd.com>
parents: 439
diff changeset
597 #endif
56237ba5da6f Adding auto-restart support whenever USB gets into an odd state
Jacob Alexander <haata@kiibohd.com>
parents: 439
diff changeset
598 reply_buffer[0] = USBKeys_Idle_Config;
56237ba5da6f Adding auto-restart support whenever USB gets into an odd state
Jacob Alexander <haata@kiibohd.com>
parents: 439
diff changeset
599 datalen = 1;
56237ba5da6f Adding auto-restart support whenever USB gets into an odd state
Jacob Alexander <haata@kiibohd.com>
parents: 439
diff changeset
600 goto send;
56237ba5da6f Adding auto-restart support whenever USB gets into an odd state
Jacob Alexander <haata@kiibohd.com>
parents: 439
diff changeset
601
56237ba5da6f Adding auto-restart support whenever USB gets into an odd state
Jacob Alexander <haata@kiibohd.com>
parents: 439
diff changeset
602
231
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
603 case 0x0B21: // HID SET_PROTOCOL
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
604 #ifdef UART_DEBUG
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
605 print("SET_PROTOCOL - ");
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
606 printHex( setup.wValue );
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
607 print(" - ");
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
608 printHex( setup.wValue & 0xFF );
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
609 print(NL);
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
610 #endif
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
611 USBKeys_Protocol = setup.wValue & 0xFF; // 0 - Boot Mode, 1 - NKRO Mode
368
06a54d582bf8 FIxing Media Keys and general USB compatibilty
Jacob Alexander <haata@kiibohd.com>
parents: 347
diff changeset
612 goto send;
231
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
613
438
f10c2dad7f55 Adding missing GET_PROTOCOL handling
Jacob Alexander <haata@kiibohd.com>
parents: 420
diff changeset
614 case 0x03A1: /// HID GET_PROTOCOL
f10c2dad7f55 Adding missing GET_PROTOCOL handling
Jacob Alexander <haata@kiibohd.com>
parents: 420
diff changeset
615 #ifdef UART_DEBUG
f10c2dad7f55 Adding missing GET_PROTOCOL handling
Jacob Alexander <haata@kiibohd.com>
parents: 420
diff changeset
616 print("GET_PROTOCOL - ");
f10c2dad7f55 Adding missing GET_PROTOCOL handling
Jacob Alexander <haata@kiibohd.com>
parents: 420
diff changeset
617 printHex( setup.wValue );
f10c2dad7f55 Adding missing GET_PROTOCOL handling
Jacob Alexander <haata@kiibohd.com>
parents: 420
diff changeset
618 print(" - ");
f10c2dad7f55 Adding missing GET_PROTOCOL handling
Jacob Alexander <haata@kiibohd.com>
parents: 420
diff changeset
619 printHex( USBKeys_Protocol );
f10c2dad7f55 Adding missing GET_PROTOCOL handling
Jacob Alexander <haata@kiibohd.com>
parents: 420
diff changeset
620 print(NL);
f10c2dad7f55 Adding missing GET_PROTOCOL handling
Jacob Alexander <haata@kiibohd.com>
parents: 420
diff changeset
621 #endif
f10c2dad7f55 Adding missing GET_PROTOCOL handling
Jacob Alexander <haata@kiibohd.com>
parents: 420
diff changeset
622 reply_buffer[0] = USBKeys_Protocol;
f10c2dad7f55 Adding missing GET_PROTOCOL handling
Jacob Alexander <haata@kiibohd.com>
parents: 420
diff changeset
623 datalen = 1;
f10c2dad7f55 Adding missing GET_PROTOCOL handling
Jacob Alexander <haata@kiibohd.com>
parents: 420
diff changeset
624 goto send;
f10c2dad7f55 Adding missing GET_PROTOCOL handling
Jacob Alexander <haata@kiibohd.com>
parents: 420
diff changeset
625
231
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
626 // case 0xC940:
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
627 default:
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
628 #ifdef UART_DEBUG_UNKNOWN
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
629 print("UNKNOWN");
438
f10c2dad7f55 Adding missing GET_PROTOCOL handling
Jacob Alexander <haata@kiibohd.com>
parents: 420
diff changeset
630 print(NL);
231
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
631 #endif
104
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
632 endpoint0_stall();
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
633 return;
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
634 }
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
635
231
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
636 send:
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
637 #ifdef UART_DEBUG
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
638 print("setup send ");
368
06a54d582bf8 FIxing Media Keys and general USB compatibilty
Jacob Alexander <haata@kiibohd.com>
parents: 347
diff changeset
639 printHex32( (uint32_t)data );
231
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
640 print(",");
368
06a54d582bf8 FIxing Media Keys and general USB compatibilty
Jacob Alexander <haata@kiibohd.com>
parents: 347
diff changeset
641 for ( uint8_t c = 0; c < datalen; c++ )
06a54d582bf8 FIxing Media Keys and general USB compatibilty
Jacob Alexander <haata@kiibohd.com>
parents: 347
diff changeset
642 {
06a54d582bf8 FIxing Media Keys and general USB compatibilty
Jacob Alexander <haata@kiibohd.com>
parents: 347
diff changeset
643 printHex( data[c] );
06a54d582bf8 FIxing Media Keys and general USB compatibilty
Jacob Alexander <haata@kiibohd.com>
parents: 347
diff changeset
644 print(" ");
06a54d582bf8 FIxing Media Keys and general USB compatibilty
Jacob Alexander <haata@kiibohd.com>
parents: 347
diff changeset
645 }
06a54d582bf8 FIxing Media Keys and general USB compatibilty
Jacob Alexander <haata@kiibohd.com>
parents: 347
diff changeset
646 print(",");
06a54d582bf8 FIxing Media Keys and general USB compatibilty
Jacob Alexander <haata@kiibohd.com>
parents: 347
diff changeset
647 printHex( datalen );
06a54d582bf8 FIxing Media Keys and general USB compatibilty
Jacob Alexander <haata@kiibohd.com>
parents: 347
diff changeset
648 print( NL );
231
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
649 #endif
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
650
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
651 if ( datalen > setup.wLength )
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
652 datalen = setup.wLength;
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
653
104
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
654 size = datalen;
231
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
655 if ( size > EP0_SIZE )
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
656 size = EP0_SIZE;
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
657
104
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
658 endpoint0_transmit(data, size);
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
659 data += size;
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
660 datalen -= size;
231
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
661
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
662 // See if transmit has finished
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
663 if ( datalen == 0 && size < EP0_SIZE )
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
664 return;
104
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
665
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
666 size = datalen;
231
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
667 if ( size > EP0_SIZE )
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
668 size = EP0_SIZE;
104
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
669 endpoint0_transmit(data, size);
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
670 data += size;
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
671 datalen -= size;
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
672
231
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
673 // See if transmit has finished
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
674 if ( datalen == 0 && size < EP0_SIZE )
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
675 return;
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
676
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
677 // Save rest of transfer for later? XXX
104
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
678 ep0_tx_ptr = data;
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
679 ep0_tx_len = datalen;
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
680 }
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
681
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
682
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
683 //A bulk endpoint's toggle sequence is initialized to DATA0 when the endpoint
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
684 //experiences any configuration event (configuration events are explained in
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
685 //Sections 9.1.1.5 and 9.4.5).
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
686
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
687 //Configuring a device or changing an alternate setting causes all of the status
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
688 //and configuration values associated with endpoints in the affected interfaces
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
689 //to be set to their default values. This includes setting the data toggle of
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
690 //any endpoint using data toggles to the value DATA0.
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
691
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
692 //For endpoints using data toggle, regardless of whether an endpoint has the
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
693 //Halt feature set, a ClearFeature(ENDPOINT_HALT) request always results in the
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
694 //data toggle being reinitialized to DATA0.
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
695
231
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
696 static void usb_control( uint32_t stat )
104
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
697 {
231
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
698 #ifdef UART_DEBUG
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
699 print("CONTROL - ");
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
700 #endif
104
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
701 bdt_t *b;
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
702 uint32_t pid, size;
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
703 uint8_t *buf;
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
704 const uint8_t *data;
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
705
231
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
706 b = stat2bufferdescriptor( stat );
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
707 pid = BDT_PID( b->desc );
104
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
708 buf = b->addr;
231
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
709 #ifdef UART_DEBUG
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
710 print("pid:");
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
711 printHex(pid);
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
712 print(", count:");
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
713 printHex32(b->desc);
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
714 print(" - ");
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
715 #endif
104
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
716
231
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
717 switch (pid)
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
718 {
104
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
719 case 0x0D: // Setup received from host
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
720 //serial_print("PID=Setup\n");
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
721 //if (count != 8) ; // panic?
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
722 // grab the 8 byte setup info
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
723 setup.word1 = *(uint32_t *)(buf);
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
724 setup.word2 = *(uint32_t *)(buf + 4);
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
725
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
726 // give the buffer back
231
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
727 b->desc = BDT_DESC( EP0_SIZE, DATA1 );
104
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
728 //table[index(0, RX, EVEN)].desc = BDT_DESC(EP0_SIZE, 1);
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
729 //table[index(0, RX, ODD)].desc = BDT_DESC(EP0_SIZE, 1);
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
730
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
731 // clear any leftover pending IN transactions
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
732 ep0_tx_ptr = NULL;
231
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
733 if ( ep0_tx_data_toggle )
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
734 {
104
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
735 }
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
736 //if (table[index(0, TX, EVEN)].desc & 0x80) {
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
737 //serial_print("leftover tx even\n");
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
738 //}
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
739 //if (table[index(0, TX, ODD)].desc & 0x80) {
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
740 //serial_print("leftover tx odd\n");
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
741 //}
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
742 table[index(0, TX, EVEN)].desc = 0;
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
743 table[index(0, TX, ODD)].desc = 0;
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
744 // first IN after Setup is always DATA1
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
745 ep0_tx_data_toggle = 1;
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
746
231
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
747 #ifdef UART_DEBUG_UNKNOWN
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
748 print("bmRequestType:");
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
749 printHex(setup.bmRequestType);
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
750 print(", bRequest:");
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
751 printHex(setup.bRequest);
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
752 print(", wValue:");
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
753 printHex(setup.wValue);
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
754 print(", wIndex:");
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
755 printHex(setup.wIndex);
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
756 print(", len:");
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
757 printHex(setup.wLength);
383
801e7628d977 Fixing long-standing SET_REPORT bug
Jacob Alexander <haata@kiibohd.com>
parents: 381
diff changeset
758 print(" -- ");
801e7628d977 Fixing long-standing SET_REPORT bug
Jacob Alexander <haata@kiibohd.com>
parents: 381
diff changeset
759 printHex32(setup.word1);
801e7628d977 Fixing long-standing SET_REPORT bug
Jacob Alexander <haata@kiibohd.com>
parents: 381
diff changeset
760 print(" ");
801e7628d977 Fixing long-standing SET_REPORT bug
Jacob Alexander <haata@kiibohd.com>
parents: 381
diff changeset
761 printHex32(setup.word2);
231
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
762 print(NL);
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
763 #endif
104
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
764 // actually "do" the setup request
117
5ffefdf89b37 Adding in USB module updates from Teensyduino 1.18rc2.
Jacob Alexander <haata@kiibohd.com>
parents: 109
diff changeset
765 usb_setup();
104
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
766 // unfreeze the USB, now that we're ready
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
767 USB0_CTL = USB_CTL_USBENSOFEN; // clear TXSUSPENDTOKENBUSY bit
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
768 break;
368
06a54d582bf8 FIxing Media Keys and general USB compatibilty
Jacob Alexander <haata@kiibohd.com>
parents: 347
diff changeset
769
104
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
770 case 0x01: // OUT transaction received from host
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
771 case 0x02:
383
801e7628d977 Fixing long-standing SET_REPORT bug
Jacob Alexander <haata@kiibohd.com>
parents: 381
diff changeset
772 #ifdef UART_DEBUG_UNKNOWN
801e7628d977 Fixing long-standing SET_REPORT bug
Jacob Alexander <haata@kiibohd.com>
parents: 381
diff changeset
773 print("PID=OUT wRequestAndType:");
801e7628d977 Fixing long-standing SET_REPORT bug
Jacob Alexander <haata@kiibohd.com>
parents: 381
diff changeset
774 printHex(setup.wRequestAndType);
801e7628d977 Fixing long-standing SET_REPORT bug
Jacob Alexander <haata@kiibohd.com>
parents: 381
diff changeset
775 print(", wValue:");
801e7628d977 Fixing long-standing SET_REPORT bug
Jacob Alexander <haata@kiibohd.com>
parents: 381
diff changeset
776 printHex(setup.wValue);
801e7628d977 Fixing long-standing SET_REPORT bug
Jacob Alexander <haata@kiibohd.com>
parents: 381
diff changeset
777 print(", wIndex:");
801e7628d977 Fixing long-standing SET_REPORT bug
Jacob Alexander <haata@kiibohd.com>
parents: 381
diff changeset
778 printHex(setup.wIndex);
801e7628d977 Fixing long-standing SET_REPORT bug
Jacob Alexander <haata@kiibohd.com>
parents: 381
diff changeset
779 print(", len:");
801e7628d977 Fixing long-standing SET_REPORT bug
Jacob Alexander <haata@kiibohd.com>
parents: 381
diff changeset
780 printHex(setup.wLength);
801e7628d977 Fixing long-standing SET_REPORT bug
Jacob Alexander <haata@kiibohd.com>
parents: 381
diff changeset
781 print(" -- ");
801e7628d977 Fixing long-standing SET_REPORT bug
Jacob Alexander <haata@kiibohd.com>
parents: 381
diff changeset
782 printHex32(setup.word1);
801e7628d977 Fixing long-standing SET_REPORT bug
Jacob Alexander <haata@kiibohd.com>
parents: 381
diff changeset
783 print(" ");
801e7628d977 Fixing long-standing SET_REPORT bug
Jacob Alexander <haata@kiibohd.com>
parents: 381
diff changeset
784 printHex32(setup.word2);
801e7628d977 Fixing long-standing SET_REPORT bug
Jacob Alexander <haata@kiibohd.com>
parents: 381
diff changeset
785 print(NL);
231
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
786 #endif
383
801e7628d977 Fixing long-standing SET_REPORT bug
Jacob Alexander <haata@kiibohd.com>
parents: 381
diff changeset
787
231
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
788 // CDC Interface
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
789 if ( setup.wRequestAndType == 0x2021 /*CDC_SET_LINE_CODING*/ )
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
790 {
104
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
791 int i;
117
5ffefdf89b37 Adding in USB module updates from Teensyduino 1.18rc2.
Jacob Alexander <haata@kiibohd.com>
parents: 109
diff changeset
792 uint8_t *dst = (uint8_t *)usb_cdc_line_coding;
104
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
793 //serial_print("set line coding ");
231
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
794 for ( i = 0; i < 7; i++ )
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
795 {
104
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
796 //serial_phex(*buf);
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
797 *dst++ = *buf++;
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
798 }
117
5ffefdf89b37 Adding in USB module updates from Teensyduino 1.18rc2.
Jacob Alexander <haata@kiibohd.com>
parents: 109
diff changeset
799 //serial_phex32(usb_cdc_line_coding[0]);
104
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
800 //serial_print("\n");
231
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
801 if ( usb_cdc_line_coding[0] == 134 )
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
802 usb_reboot_timer = 15;
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
803 endpoint0_transmit( NULL, 0 );
104
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
804 }
231
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
805
383
801e7628d977 Fixing long-standing SET_REPORT bug
Jacob Alexander <haata@kiibohd.com>
parents: 381
diff changeset
806 // Keyboard SET_REPORT
801e7628d977 Fixing long-standing SET_REPORT bug
Jacob Alexander <haata@kiibohd.com>
parents: 381
diff changeset
807 if ( setup.wRequestAndType == 0x921 && setup.wValue & 0x200 )
231
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
808 {
383
801e7628d977 Fixing long-standing SET_REPORT bug
Jacob Alexander <haata@kiibohd.com>
parents: 381
diff changeset
809 // Interface
801e7628d977 Fixing long-standing SET_REPORT bug
Jacob Alexander <haata@kiibohd.com>
parents: 381
diff changeset
810 switch ( setup.wIndex & 0xFF )
801e7628d977 Fixing long-standing SET_REPORT bug
Jacob Alexander <haata@kiibohd.com>
parents: 381
diff changeset
811 {
801e7628d977 Fixing long-standing SET_REPORT bug
Jacob Alexander <haata@kiibohd.com>
parents: 381
diff changeset
812 // Keyboard Interface
801e7628d977 Fixing long-standing SET_REPORT bug
Jacob Alexander <haata@kiibohd.com>
parents: 381
diff changeset
813 case KEYBOARD_INTERFACE:
801e7628d977 Fixing long-standing SET_REPORT bug
Jacob Alexander <haata@kiibohd.com>
parents: 381
diff changeset
814 USBKeys_LEDs = buf[0];
801e7628d977 Fixing long-standing SET_REPORT bug
Jacob Alexander <haata@kiibohd.com>
parents: 381
diff changeset
815 endpoint0_transmit( NULL, 0 );
801e7628d977 Fixing long-standing SET_REPORT bug
Jacob Alexander <haata@kiibohd.com>
parents: 381
diff changeset
816 break;
801e7628d977 Fixing long-standing SET_REPORT bug
Jacob Alexander <haata@kiibohd.com>
parents: 381
diff changeset
817 // NKRO Keyboard Interface
801e7628d977 Fixing long-standing SET_REPORT bug
Jacob Alexander <haata@kiibohd.com>
parents: 381
diff changeset
818 case NKRO_KEYBOARD_INTERFACE:
801e7628d977 Fixing long-standing SET_REPORT bug
Jacob Alexander <haata@kiibohd.com>
parents: 381
diff changeset
819 // Only use 2nd byte, first byte is the report id
801e7628d977 Fixing long-standing SET_REPORT bug
Jacob Alexander <haata@kiibohd.com>
parents: 381
diff changeset
820 USBKeys_LEDs = buf[1];
801e7628d977 Fixing long-standing SET_REPORT bug
Jacob Alexander <haata@kiibohd.com>
parents: 381
diff changeset
821 endpoint0_transmit( NULL, 0 );
801e7628d977 Fixing long-standing SET_REPORT bug
Jacob Alexander <haata@kiibohd.com>
parents: 381
diff changeset
822 break;
801e7628d977 Fixing long-standing SET_REPORT bug
Jacob Alexander <haata@kiibohd.com>
parents: 381
diff changeset
823 default:
801e7628d977 Fixing long-standing SET_REPORT bug
Jacob Alexander <haata@kiibohd.com>
parents: 381
diff changeset
824 warn_msg("Unknown interface - ");
801e7628d977 Fixing long-standing SET_REPORT bug
Jacob Alexander <haata@kiibohd.com>
parents: 381
diff changeset
825 printHex( setup.wIndex );
801e7628d977 Fixing long-standing SET_REPORT bug
Jacob Alexander <haata@kiibohd.com>
parents: 381
diff changeset
826 print( NL );
801e7628d977 Fixing long-standing SET_REPORT bug
Jacob Alexander <haata@kiibohd.com>
parents: 381
diff changeset
827 break;
801e7628d977 Fixing long-standing SET_REPORT bug
Jacob Alexander <haata@kiibohd.com>
parents: 381
diff changeset
828 }
801e7628d977 Fixing long-standing SET_REPORT bug
Jacob Alexander <haata@kiibohd.com>
parents: 381
diff changeset
829
801e7628d977 Fixing long-standing SET_REPORT bug
Jacob Alexander <haata@kiibohd.com>
parents: 381
diff changeset
830 #ifdef UART_DEBUG
801e7628d977 Fixing long-standing SET_REPORT bug
Jacob Alexander <haata@kiibohd.com>
parents: 381
diff changeset
831 for ( size_t len = 0; len < setup.wLength; len++ )
801e7628d977 Fixing long-standing SET_REPORT bug
Jacob Alexander <haata@kiibohd.com>
parents: 381
diff changeset
832 {
801e7628d977 Fixing long-standing SET_REPORT bug
Jacob Alexander <haata@kiibohd.com>
parents: 381
diff changeset
833 printHex( buf[ len ] );
801e7628d977 Fixing long-standing SET_REPORT bug
Jacob Alexander <haata@kiibohd.com>
parents: 381
diff changeset
834 print(" ");
801e7628d977 Fixing long-standing SET_REPORT bug
Jacob Alexander <haata@kiibohd.com>
parents: 381
diff changeset
835 }
801e7628d977 Fixing long-standing SET_REPORT bug
Jacob Alexander <haata@kiibohd.com>
parents: 381
diff changeset
836 print( NL );
801e7628d977 Fixing long-standing SET_REPORT bug
Jacob Alexander <haata@kiibohd.com>
parents: 381
diff changeset
837 #endif
231
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
838 }
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
839
104
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
840 // give the buffer back
231
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
841 b->desc = BDT_DESC( EP0_SIZE, DATA1 );
104
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
842 break;
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
843
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
844 case 0x09: // IN transaction completed to host
231
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
845 #ifdef UART_DEBUG
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
846 print("PID=IN:");
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
847 printHex(stat);
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
848 print(NL);
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
849 #endif
104
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
850
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
851 // send remaining data, if any...
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
852 data = ep0_tx_ptr;
231
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
853 if ( data )
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
854 {
104
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
855 size = ep0_tx_len;
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
856 if (size > EP0_SIZE) size = EP0_SIZE;
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
857 endpoint0_transmit(data, size);
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
858 data += size;
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
859 ep0_tx_len -= size;
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
860 ep0_tx_ptr = (ep0_tx_len > 0 || size == EP0_SIZE) ? data : NULL;
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
861 }
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
862
231
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
863 if ( setup.bRequest == 5 && setup.bmRequestType == 0 )
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
864 {
104
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
865 setup.bRequest = 0;
231
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
866 #ifdef UART_DEBUG
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
867 print("set address: ");
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
868 printHex(setup.wValue);
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
869 print(NL);
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
870 #endif
104
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
871 USB0_ADDR = setup.wValue;
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
872 }
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
873
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
874 break;
368
06a54d582bf8 FIxing Media Keys and general USB compatibilty
Jacob Alexander <haata@kiibohd.com>
parents: 347
diff changeset
875
231
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
876 default:
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
877 #ifdef UART_DEBUG
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
878 print("PID=unknown:");
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
879 printHex(pid);
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
880 print(NL);
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
881 #endif
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
882 break;
104
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
883 }
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
884 USB0_CTL = USB_CTL_USBENSOFEN; // clear TXSUSPENDTOKENBUSY bit
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
885 }
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
886
231
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
887 usb_packet_t *usb_rx( uint32_t endpoint )
104
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
888 {
175
c70f641581b5 McHCK USB WORKS!!
Jacob Alexander <haata@kiibohd.com>
parents: 171
diff changeset
889 //print("USB RX");
104
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
890 usb_packet_t *ret;
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
891 endpoint--;
231
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
892 if ( endpoint >= NUM_ENDPOINTS )
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
893 return NULL;
104
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
894 __disable_irq();
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
895 ret = rx_first[endpoint];
231
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
896 if ( ret )
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
897 rx_first[ endpoint ] = ret->next;
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
898 usb_rx_byte_count_data[ endpoint ] -= ret->len;
104
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
899 __enable_irq();
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
900 //serial_print("rx, epidx=");
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
901 //serial_phex(endpoint);
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
902 //serial_print(", packet=");
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
903 //serial_phex32(ret);
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
904 //serial_print("\n");
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
905 return ret;
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
906 }
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
907
231
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
908 static uint32_t usb_queue_byte_count( const usb_packet_t *p )
104
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
909 {
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
910 uint32_t count=0;
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
911
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
912 __disable_irq();
231
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
913 for ( ; p; p = p->next )
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
914 {
104
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
915 count += p->len;
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
916 }
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
917 __enable_irq();
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
918 return count;
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
919 }
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
920
231
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
921 uint32_t usb_tx_byte_count( uint32_t endpoint )
104
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
922 {
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
923 endpoint--;
231
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
924 if ( endpoint >= NUM_ENDPOINTS )
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
925 return 0;
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
926 return usb_queue_byte_count( tx_first[ endpoint ] );
104
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
927 }
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
928
231
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
929 uint32_t usb_tx_packet_count( uint32_t endpoint )
104
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
930 {
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
931 const usb_packet_t *p;
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
932 uint32_t count=0;
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
933
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
934 endpoint--;
231
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
935 if ( endpoint >= NUM_ENDPOINTS )
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
936 return 0;
104
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
937 __disable_irq();
231
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
938 for ( p = tx_first[ endpoint ]; p; p = p->next )
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
939 count++;
104
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
940 __enable_irq();
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
941 return count;
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
942 }
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
943
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
944
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
945 // Called from usb_free, but only when usb_rx_memory_needed > 0, indicating
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
946 // receive endpoints are starving for memory. The intention is to give
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
947 // endpoints needing receive memory priority over the user's code, which is
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
948 // likely calling usb_malloc to obtain memory for transmitting. When the
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
949 // user is creating data very quickly, their consumption could starve reception
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
950 // without this prioritization. The packet buffer (input) is assigned to the
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
951 // first endpoint needing memory.
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
952 //
231
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
953 void usb_rx_memory( usb_packet_t *packet )
104
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
954 {
175
c70f641581b5 McHCK USB WORKS!!
Jacob Alexander <haata@kiibohd.com>
parents: 171
diff changeset
955 //print("USB RX MEMORY");
104
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
956 unsigned int i;
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
957 const uint8_t *cfg;
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
958
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
959 cfg = usb_endpoint_config_table;
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
960 //serial_print("rx_mem:");
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
961 __disable_irq();
250
afe96322d0c5 Code formatting cleanup.
Jacob Alexander <haata@kiibohd.com>
parents: 231
diff changeset
962 for ( i = 1; i <= NUM_ENDPOINTS; i++ )
afe96322d0c5 Code formatting cleanup.
Jacob Alexander <haata@kiibohd.com>
parents: 231
diff changeset
963 {
afe96322d0c5 Code formatting cleanup.
Jacob Alexander <haata@kiibohd.com>
parents: 231
diff changeset
964 if ( *cfg++ & USB_ENDPT_EPRXEN )
afe96322d0c5 Code formatting cleanup.
Jacob Alexander <haata@kiibohd.com>
parents: 231
diff changeset
965 {
231
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
966 if ( table[ index( i, RX, EVEN ) ].desc == 0 )
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
967 {
250
afe96322d0c5 Code formatting cleanup.
Jacob Alexander <haata@kiibohd.com>
parents: 231
diff changeset
968 table[ index( i, RX, EVEN ) ].addr = packet->buf;
afe96322d0c5 Code formatting cleanup.
Jacob Alexander <haata@kiibohd.com>
parents: 231
diff changeset
969 table[ index( i, RX, EVEN ) ].desc = BDT_DESC( 64, 0 );
104
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
970 usb_rx_memory_needed--;
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
971 __enable_irq();
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
972 //serial_phex(i);
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
973 //serial_print(",even\n");
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
974 return;
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
975 }
231
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
976 if ( table[ index( i, RX, ODD ) ].desc == 0 )
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
977 {
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
978 table[ index( i, RX, ODD ) ].addr = packet->buf;
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
979 table[ index( i, RX, ODD ) ].desc = BDT_DESC( 64, 1 );
104
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
980 usb_rx_memory_needed--;
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
981 __enable_irq();
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
982 //serial_phex(i);
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
983 //serial_print(",odd\n");
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
984 return;
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
985 }
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
986 }
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
987 }
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
988 __enable_irq();
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
989 // we should never reach this point. If we get here, it means
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
990 // usb_rx_memory_needed was set greater than zero, but no memory
175
c70f641581b5 McHCK USB WORKS!!
Jacob Alexander <haata@kiibohd.com>
parents: 171
diff changeset
991 // was actually needed.
104
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
992 usb_rx_memory_needed = 0;
231
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
993 usb_free( packet );
104
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
994 return;
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
995 }
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
996
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
997 //#define index(endpoint, tx, odd) (((endpoint) << 2) | ((tx) << 1) | (odd))
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
998 //#define stat2bufferdescriptor(stat) (table + ((stat) >> 2))
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
999
231
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
1000 void usb_tx( uint32_t endpoint, usb_packet_t *packet )
104
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
1001 {
447
56237ba5da6f Adding auto-restart support whenever USB gets into an odd state
Jacob Alexander <haata@kiibohd.com>
parents: 439
diff changeset
1002 // Update expiry counter
56237ba5da6f Adding auto-restart support whenever USB gets into an odd state
Jacob Alexander <haata@kiibohd.com>
parents: 439
diff changeset
1003 USBKeys_Idle_Expiry = systick_millis_count;
56237ba5da6f Adding auto-restart support whenever USB gets into an odd state
Jacob Alexander <haata@kiibohd.com>
parents: 439
diff changeset
1004
439
68e19d7c953e Adding proper remote wake-up support
Jacob Alexander <haata@kiibohd.com>
parents: 438
diff changeset
1005 // If we have been sleeping, try to wake up host
68e19d7c953e Adding proper remote wake-up support
Jacob Alexander <haata@kiibohd.com>
parents: 438
diff changeset
1006 if ( usb_dev_sleep )
68e19d7c953e Adding proper remote wake-up support
Jacob Alexander <haata@kiibohd.com>
parents: 438
diff changeset
1007 {
68e19d7c953e Adding proper remote wake-up support
Jacob Alexander <haata@kiibohd.com>
parents: 438
diff changeset
1008 // Force wake-up for 10 ms
68e19d7c953e Adding proper remote wake-up support
Jacob Alexander <haata@kiibohd.com>
parents: 438
diff changeset
1009 // According to the USB Spec a device must hold resume for at least 1 ms but no more than 15 ms
68e19d7c953e Adding proper remote wake-up support
Jacob Alexander <haata@kiibohd.com>
parents: 438
diff changeset
1010 USB0_CTL |= USB_CTL_RESUME;
68e19d7c953e Adding proper remote wake-up support
Jacob Alexander <haata@kiibohd.com>
parents: 438
diff changeset
1011 delay(10);
68e19d7c953e Adding proper remote wake-up support
Jacob Alexander <haata@kiibohd.com>
parents: 438
diff changeset
1012 USB0_CTL &= ~(USB_CTL_RESUME);
447
56237ba5da6f Adding auto-restart support whenever USB gets into an odd state
Jacob Alexander <haata@kiibohd.com>
parents: 439
diff changeset
1013 delay(50); // Wait for at least 50 ms to make sure the bus is clear
56237ba5da6f Adding auto-restart support whenever USB gets into an odd state
Jacob Alexander <haata@kiibohd.com>
parents: 439
diff changeset
1014 usb_dev_sleep = 0; // Make sure we don't call this again, may crash system
439
68e19d7c953e Adding proper remote wake-up support
Jacob Alexander <haata@kiibohd.com>
parents: 438
diff changeset
1015 }
68e19d7c953e Adding proper remote wake-up support
Jacob Alexander <haata@kiibohd.com>
parents: 438
diff changeset
1016
420
23a1868b4ac2 Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents: 385
diff changeset
1017 // Since we are transmitting data, USB will be brought out of sleep/suspend
23a1868b4ac2 Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents: 385
diff changeset
1018 // if it's in that state
23a1868b4ac2 Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents: 385
diff changeset
1019 // Use the currently set descriptor value
23a1868b4ac2 Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents: 385
diff changeset
1020 Output_update_usb_current( *usb_bMaxPower * 2 );
23a1868b4ac2 Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents: 385
diff changeset
1021
231
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
1022 bdt_t *b = &table[ index( endpoint, TX, EVEN ) ];
104
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
1023 uint8_t next;
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
1024
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
1025 endpoint--;
231
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
1026 if ( endpoint >= NUM_ENDPOINTS )
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
1027 return;
104
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
1028 __disable_irq();
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
1029 //serial_print("txstate=");
231
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
1030 //serial_phex(tx_state[ endpoint ]);
104
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
1031 //serial_print("\n");
231
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
1032 switch ( tx_state[ endpoint ] )
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
1033 {
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
1034 case TX_STATE_BOTH_FREE_EVEN_FIRST:
104
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
1035 next = TX_STATE_ODD_FREE;
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
1036 break;
231
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
1037 case TX_STATE_BOTH_FREE_ODD_FIRST:
104
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
1038 b++;
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
1039 next = TX_STATE_EVEN_FREE;
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
1040 break;
231
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
1041 case TX_STATE_EVEN_FREE:
117
5ffefdf89b37 Adding in USB module updates from Teensyduino 1.18rc2.
Jacob Alexander <haata@kiibohd.com>
parents: 109
diff changeset
1042 next = TX_STATE_NONE_FREE_ODD_FIRST;
104
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
1043 break;
231
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
1044 case TX_STATE_ODD_FREE:
104
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
1045 b++;
117
5ffefdf89b37 Adding in USB module updates from Teensyduino 1.18rc2.
Jacob Alexander <haata@kiibohd.com>
parents: 109
diff changeset
1046 next = TX_STATE_NONE_FREE_EVEN_FIRST;
104
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
1047 break;
231
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
1048 default:
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
1049 if (tx_first[ endpoint ] == NULL)
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
1050 {
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
1051 tx_first[ endpoint ] = packet;
104
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
1052 }
231
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
1053 else
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
1054 {
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
1055 tx_last[ endpoint ]->next = packet;
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
1056 }
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
1057 tx_last[ endpoint ] = packet;
104
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
1058 __enable_irq();
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
1059 return;
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
1060 }
231
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
1061
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
1062 tx_state[ endpoint ] = next;
104
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
1063 b->addr = packet->buf;
231
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
1064 b->desc = BDT_DESC( packet->len, ((uint32_t)b & 8) ? DATA1 : DATA0 );
104
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
1065 __enable_irq();
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
1066 }
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
1067
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
1068
109
2c1a9e6ae70e Added more CLI commands.
Jacob Alexander <haata@kiibohd.com>
parents: 104
diff changeset
1069 void usb_device_reload()
2c1a9e6ae70e Added more CLI commands.
Jacob Alexander <haata@kiibohd.com>
parents: 104
diff changeset
1070 {
177
3420e018ffbc Adding McHCK flash reload function and some cleanup.
Jacob Alexander <haata@kiibohd.com>
parents: 175
diff changeset
1071 // MCHCK
347
136e47478441 UARTConnect enumeration working!
Jacob Alexander <haata@kiibohd.com>
parents: 346
diff changeset
1072 // Kiibohd mk20dx256vlh7
385
d8f61e15aca1 Adding jump to bootloader key
Jacob Alexander <haata@kiibohd.com>
parents: 383
diff changeset
1073 #if defined(_mk20dx128vlf5_) || defined(_mk20dx256vlh7_)
347
136e47478441 UARTConnect enumeration working!
Jacob Alexander <haata@kiibohd.com>
parents: 346
diff changeset
1074 // Copies variable into the VBAT register, must be identical to the variable in the bootloader to jump to the bootloader flash mode
136e47478441 UARTConnect enumeration working!
Jacob Alexander <haata@kiibohd.com>
parents: 346
diff changeset
1075 for ( int pos = 0; pos < sizeof(sys_reset_to_loader_magic); pos++ )
136e47478441 UARTConnect enumeration working!
Jacob Alexander <haata@kiibohd.com>
parents: 346
diff changeset
1076 (&VBAT)[ pos ] = sys_reset_to_loader_magic[ pos ];
136e47478441 UARTConnect enumeration working!
Jacob Alexander <haata@kiibohd.com>
parents: 346
diff changeset
1077 SOFTWARE_RESET();
136e47478441 UARTConnect enumeration working!
Jacob Alexander <haata@kiibohd.com>
parents: 346
diff changeset
1078
177
3420e018ffbc Adding McHCK flash reload function and some cleanup.
Jacob Alexander <haata@kiibohd.com>
parents: 175
diff changeset
1079 // Teensy 3.0 and 3.1
3420e018ffbc Adding McHCK flash reload function and some cleanup.
Jacob Alexander <haata@kiibohd.com>
parents: 175
diff changeset
1080 #else
109
2c1a9e6ae70e Added more CLI commands.
Jacob Alexander <haata@kiibohd.com>
parents: 104
diff changeset
1081 asm volatile("bkpt");
177
3420e018ffbc Adding McHCK flash reload function and some cleanup.
Jacob Alexander <haata@kiibohd.com>
parents: 175
diff changeset
1082 #endif
109
2c1a9e6ae70e Added more CLI commands.
Jacob Alexander <haata@kiibohd.com>
parents: 104
diff changeset
1083 }
104
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
1084
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
1085
175
c70f641581b5 McHCK USB WORKS!!
Jacob Alexander <haata@kiibohd.com>
parents: 171
diff changeset
1086 void usb_isr()
104
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
1087 {
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
1088 uint8_t status, stat, t;
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
1089
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
1090 //serial_print("isr");
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
1091 //status = USB0_ISTAT;
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
1092 //serial_phex(status);
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
1093 //serial_print("\n");
250
afe96322d0c5 Code formatting cleanup.
Jacob Alexander <haata@kiibohd.com>
parents: 231
diff changeset
1094 restart:
104
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
1095 status = USB0_ISTAT;
175
c70f641581b5 McHCK USB WORKS!!
Jacob Alexander <haata@kiibohd.com>
parents: 171
diff changeset
1096 /*
c70f641581b5 McHCK USB WORKS!!
Jacob Alexander <haata@kiibohd.com>
parents: 171
diff changeset
1097 print("USB ISR STATUS: ");
c70f641581b5 McHCK USB WORKS!!
Jacob Alexander <haata@kiibohd.com>
parents: 171
diff changeset
1098 printHex( status );
c70f641581b5 McHCK USB WORKS!!
Jacob Alexander <haata@kiibohd.com>
parents: 171
diff changeset
1099 print( NL );
c70f641581b5 McHCK USB WORKS!!
Jacob Alexander <haata@kiibohd.com>
parents: 171
diff changeset
1100 */
104
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
1101
231
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
1102 if ( (status & USB_INTEN_SOFTOKEN /* 04 */ ) )
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
1103 {
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
1104 if ( usb_configuration )
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
1105 {
104
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
1106 t = usb_reboot_timer;
231
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
1107 if ( t )
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
1108 {
104
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
1109 usb_reboot_timer = --t;
231
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
1110 if ( !t )
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
1111 usb_device_reload();
104
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
1112 }
231
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
1113
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
1114 // CDC Interface
104
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
1115 t = usb_cdc_transmit_flush_timer;
231
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
1116 if ( t )
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
1117 {
104
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
1118 usb_cdc_transmit_flush_timer = --t;
231
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
1119 if ( t == 0 )
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
1120 usb_serial_flush_callback();
104
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
1121 }
231
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
1122
104
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
1123 }
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
1124 USB0_ISTAT = USB_INTEN_SOFTOKEN;
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
1125 }
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
1126
231
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
1127 if ( (status & USB_ISTAT_TOKDNE /* 08 */ ) )
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
1128 {
104
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
1129 uint8_t endpoint;
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
1130 stat = USB0_STAT;
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
1131 //serial_print("token: ep=");
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
1132 //serial_phex(stat >> 4);
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
1133 //serial_print(stat & 0x08 ? ",tx" : ",rx");
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
1134 //serial_print(stat & 0x04 ? ",odd\n" : ",even\n");
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
1135 endpoint = stat >> 4;
231
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
1136 if ( endpoint == 0 )
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
1137 {
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
1138 usb_control( stat );
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
1139 }
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
1140 else
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
1141 {
104
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
1142 bdt_t *b = stat2bufferdescriptor(stat);
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
1143 usb_packet_t *packet = (usb_packet_t *)((uint8_t *)(b->addr) - 8);
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
1144 #if 0
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
1145 serial_print("ep:");
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
1146 serial_phex(endpoint);
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
1147 serial_print(", pid:");
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
1148 serial_phex(BDT_PID(b->desc));
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
1149 serial_print(((uint32_t)b & 8) ? ", odd" : ", even");
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
1150 serial_print(", count:");
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
1151 serial_phex(b->desc >> 16);
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
1152 serial_print("\n");
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
1153 #endif
326
05a09eda53fb Inital Remote Wakeup Support
Rowan Decker <Smasher816@gmail.com>
parents: 302
diff changeset
1154 endpoint--; // endpoint is index to zero-based arrays
104
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
1155
231
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
1156 if ( stat & 0x08 )
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
1157 { // transmit
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
1158 usb_free( packet );
250
afe96322d0c5 Code formatting cleanup.
Jacob Alexander <haata@kiibohd.com>
parents: 231
diff changeset
1159 packet = tx_first[ endpoint ];
231
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
1160 if ( packet )
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
1161 {
104
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
1162 //serial_print("tx packet\n");
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
1163 tx_first[endpoint] = packet->next;
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
1164 b->addr = packet->buf;
231
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
1165 switch ( tx_state[ endpoint ] )
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
1166 {
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
1167 case TX_STATE_BOTH_FREE_EVEN_FIRST:
250
afe96322d0c5 Code formatting cleanup.
Jacob Alexander <haata@kiibohd.com>
parents: 231
diff changeset
1168 tx_state[ endpoint ] = TX_STATE_ODD_FREE;
104
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
1169 break;
231
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
1170 case TX_STATE_BOTH_FREE_ODD_FIRST:
250
afe96322d0c5 Code formatting cleanup.
Jacob Alexander <haata@kiibohd.com>
parents: 231
diff changeset
1171 tx_state[ endpoint ] = TX_STATE_EVEN_FREE;
104
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
1172 break;
231
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
1173 case TX_STATE_EVEN_FREE:
250
afe96322d0c5 Code formatting cleanup.
Jacob Alexander <haata@kiibohd.com>
parents: 231
diff changeset
1174 tx_state[ endpoint ] = TX_STATE_NONE_FREE_ODD_FIRST;
117
5ffefdf89b37 Adding in USB module updates from Teensyduino 1.18rc2.
Jacob Alexander <haata@kiibohd.com>
parents: 109
diff changeset
1175 break;
231
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
1176 case TX_STATE_ODD_FREE:
250
afe96322d0c5 Code formatting cleanup.
Jacob Alexander <haata@kiibohd.com>
parents: 231
diff changeset
1177 tx_state[ endpoint ] = TX_STATE_NONE_FREE_EVEN_FIRST;
117
5ffefdf89b37 Adding in USB module updates from Teensyduino 1.18rc2.
Jacob Alexander <haata@kiibohd.com>
parents: 109
diff changeset
1178 break;
231
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
1179 default:
104
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
1180 break;
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
1181 }
250
afe96322d0c5 Code formatting cleanup.
Jacob Alexander <haata@kiibohd.com>
parents: 231
diff changeset
1182 b->desc = BDT_DESC( packet->len, ((uint32_t)b & 8) ? DATA1 : DATA0 );
104
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
1183 } else {
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
1184 //serial_print("tx no packet\n");
231
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
1185 switch ( tx_state[ endpoint ] )
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
1186 {
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
1187 case TX_STATE_BOTH_FREE_EVEN_FIRST:
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
1188 case TX_STATE_BOTH_FREE_ODD_FIRST:
104
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
1189 break;
231
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
1190 case TX_STATE_EVEN_FREE:
250
afe96322d0c5 Code formatting cleanup.
Jacob Alexander <haata@kiibohd.com>
parents: 231
diff changeset
1191 tx_state[ endpoint ] = TX_STATE_BOTH_FREE_EVEN_FIRST;
104
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
1192 break;
231
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
1193 case TX_STATE_ODD_FREE:
250
afe96322d0c5 Code formatting cleanup.
Jacob Alexander <haata@kiibohd.com>
parents: 231
diff changeset
1194 tx_state[ endpoint ] = TX_STATE_BOTH_FREE_ODD_FIRST;
104
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
1195 break;
231
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
1196 default:
250
afe96322d0c5 Code formatting cleanup.
Jacob Alexander <haata@kiibohd.com>
parents: 231
diff changeset
1197 tx_state[ endpoint ] = ((uint32_t)b & 8)
376
47f89f1bfdb7 Prep for mouse support
Jacob Alexander <haata@kiibohd.com>
parents: 370
diff changeset
1198 ? TX_STATE_ODD_FREE
47f89f1bfdb7 Prep for mouse support
Jacob Alexander <haata@kiibohd.com>
parents: 370
diff changeset
1199 : TX_STATE_EVEN_FREE;
104
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
1200 break;
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
1201 }
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
1202 }
231
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
1203 }
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
1204 else
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
1205 { // receive
104
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
1206 packet->len = b->desc >> 16;
250
afe96322d0c5 Code formatting cleanup.
Jacob Alexander <haata@kiibohd.com>
parents: 231
diff changeset
1207 if ( packet->len > 0 )
afe96322d0c5 Code formatting cleanup.
Jacob Alexander <haata@kiibohd.com>
parents: 231
diff changeset
1208 {
117
5ffefdf89b37 Adding in USB module updates from Teensyduino 1.18rc2.
Jacob Alexander <haata@kiibohd.com>
parents: 109
diff changeset
1209 packet->index = 0;
5ffefdf89b37 Adding in USB module updates from Teensyduino 1.18rc2.
Jacob Alexander <haata@kiibohd.com>
parents: 109
diff changeset
1210 packet->next = NULL;
250
afe96322d0c5 Code formatting cleanup.
Jacob Alexander <haata@kiibohd.com>
parents: 231
diff changeset
1211 if ( rx_first[ endpoint ] == NULL )
231
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
1212 {
117
5ffefdf89b37 Adding in USB module updates from Teensyduino 1.18rc2.
Jacob Alexander <haata@kiibohd.com>
parents: 109
diff changeset
1213 //serial_print("rx 1st, epidx=");
5ffefdf89b37 Adding in USB module updates from Teensyduino 1.18rc2.
Jacob Alexander <haata@kiibohd.com>
parents: 109
diff changeset
1214 //serial_phex(endpoint);
5ffefdf89b37 Adding in USB module updates from Teensyduino 1.18rc2.
Jacob Alexander <haata@kiibohd.com>
parents: 109
diff changeset
1215 //serial_print(", packet=");
5ffefdf89b37 Adding in USB module updates from Teensyduino 1.18rc2.
Jacob Alexander <haata@kiibohd.com>
parents: 109
diff changeset
1216 //serial_phex32((uint32_t)packet);
5ffefdf89b37 Adding in USB module updates from Teensyduino 1.18rc2.
Jacob Alexander <haata@kiibohd.com>
parents: 109
diff changeset
1217 //serial_print("\n");
250
afe96322d0c5 Code formatting cleanup.
Jacob Alexander <haata@kiibohd.com>
parents: 231
diff changeset
1218 rx_first[ endpoint ] = packet;
231
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
1219 }
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
1220 else
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
1221 {
117
5ffefdf89b37 Adding in USB module updates from Teensyduino 1.18rc2.
Jacob Alexander <haata@kiibohd.com>
parents: 109
diff changeset
1222 //serial_print("rx Nth, epidx=");
5ffefdf89b37 Adding in USB module updates from Teensyduino 1.18rc2.
Jacob Alexander <haata@kiibohd.com>
parents: 109
diff changeset
1223 //serial_phex(endpoint);
5ffefdf89b37 Adding in USB module updates from Teensyduino 1.18rc2.
Jacob Alexander <haata@kiibohd.com>
parents: 109
diff changeset
1224 //serial_print(", packet=");
5ffefdf89b37 Adding in USB module updates from Teensyduino 1.18rc2.
Jacob Alexander <haata@kiibohd.com>
parents: 109
diff changeset
1225 //serial_phex32((uint32_t)packet);
5ffefdf89b37 Adding in USB module updates from Teensyduino 1.18rc2.
Jacob Alexander <haata@kiibohd.com>
parents: 109
diff changeset
1226 //serial_print("\n");
250
afe96322d0c5 Code formatting cleanup.
Jacob Alexander <haata@kiibohd.com>
parents: 231
diff changeset
1227 rx_last[ endpoint ]->next = packet;
117
5ffefdf89b37 Adding in USB module updates from Teensyduino 1.18rc2.
Jacob Alexander <haata@kiibohd.com>
parents: 109
diff changeset
1228 }
250
afe96322d0c5 Code formatting cleanup.
Jacob Alexander <haata@kiibohd.com>
parents: 231
diff changeset
1229 rx_last[ endpoint ] = packet;
afe96322d0c5 Code formatting cleanup.
Jacob Alexander <haata@kiibohd.com>
parents: 231
diff changeset
1230 usb_rx_byte_count_data[ endpoint ] += packet->len;
117
5ffefdf89b37 Adding in USB module updates from Teensyduino 1.18rc2.
Jacob Alexander <haata@kiibohd.com>
parents: 109
diff changeset
1231 // TODO: implement a per-endpoint maximum # of allocated packets
5ffefdf89b37 Adding in USB module updates from Teensyduino 1.18rc2.
Jacob Alexander <haata@kiibohd.com>
parents: 109
diff changeset
1232 // so a flood of incoming data on 1 endpoint doesn't starve
5ffefdf89b37 Adding in USB module updates from Teensyduino 1.18rc2.
Jacob Alexander <haata@kiibohd.com>
parents: 109
diff changeset
1233 // the others if the user isn't reading it regularly
5ffefdf89b37 Adding in USB module updates from Teensyduino 1.18rc2.
Jacob Alexander <haata@kiibohd.com>
parents: 109
diff changeset
1234 packet = usb_malloc();
231
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
1235 if ( packet )
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
1236 {
117
5ffefdf89b37 Adding in USB module updates from Teensyduino 1.18rc2.
Jacob Alexander <haata@kiibohd.com>
parents: 109
diff changeset
1237 b->addr = packet->buf;
250
afe96322d0c5 Code formatting cleanup.
Jacob Alexander <haata@kiibohd.com>
parents: 231
diff changeset
1238 b->desc = BDT_DESC( 64, ((uint32_t)b & 8) ? DATA1 : DATA0 );
231
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
1239 }
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
1240 else
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
1241 {
117
5ffefdf89b37 Adding in USB module updates from Teensyduino 1.18rc2.
Jacob Alexander <haata@kiibohd.com>
parents: 109
diff changeset
1242 //serial_print("starving ");
5ffefdf89b37 Adding in USB module updates from Teensyduino 1.18rc2.
Jacob Alexander <haata@kiibohd.com>
parents: 109
diff changeset
1243 //serial_phex(endpoint + 1);
5ffefdf89b37 Adding in USB module updates from Teensyduino 1.18rc2.
Jacob Alexander <haata@kiibohd.com>
parents: 109
diff changeset
1244 //serial_print(((uint32_t)b & 8) ? ",odd\n" : ",even\n");
5ffefdf89b37 Adding in USB module updates from Teensyduino 1.18rc2.
Jacob Alexander <haata@kiibohd.com>
parents: 109
diff changeset
1245 b->desc = 0;
5ffefdf89b37 Adding in USB module updates from Teensyduino 1.18rc2.
Jacob Alexander <haata@kiibohd.com>
parents: 109
diff changeset
1246 usb_rx_memory_needed++;
5ffefdf89b37 Adding in USB module updates from Teensyduino 1.18rc2.
Jacob Alexander <haata@kiibohd.com>
parents: 109
diff changeset
1247 }
231
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
1248 }
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
1249 else
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
1250 {
250
afe96322d0c5 Code formatting cleanup.
Jacob Alexander <haata@kiibohd.com>
parents: 231
diff changeset
1251 b->desc = BDT_DESC( 64, ((uint32_t)b & 8) ? DATA1 : DATA0 );
104
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
1252 }
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
1253 }
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
1254
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
1255
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
1256
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
1257
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
1258 }
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
1259 USB0_ISTAT = USB_ISTAT_TOKDNE;
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
1260 goto restart;
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
1261 }
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
1262
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
1263
231
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
1264 if ( status & USB_ISTAT_USBRST /* 01 */ )
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
1265 {
104
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
1266 //serial_print("reset\n");
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
1267
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
1268 // initialize BDT toggle bits
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
1269 USB0_CTL = USB_CTL_ODDRST;
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
1270 ep0_tx_bdt_bank = 0;
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
1271
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
1272 // set up buffers to receive Setup and OUT packets
250
afe96322d0c5 Code formatting cleanup.
Jacob Alexander <haata@kiibohd.com>
parents: 231
diff changeset
1273 table[index( 0, RX, EVEN ) ].desc = BDT_DESC( EP0_SIZE, 0 );
afe96322d0c5 Code formatting cleanup.
Jacob Alexander <haata@kiibohd.com>
parents: 231
diff changeset
1274 table[index( 0, RX, EVEN ) ].addr = ep0_rx0_buf;
afe96322d0c5 Code formatting cleanup.
Jacob Alexander <haata@kiibohd.com>
parents: 231
diff changeset
1275 table[index( 0, RX, ODD ) ].desc = BDT_DESC( EP0_SIZE, 0 );
afe96322d0c5 Code formatting cleanup.
Jacob Alexander <haata@kiibohd.com>
parents: 231
diff changeset
1276 table[index( 0, RX, ODD ) ].addr = ep0_rx1_buf;
afe96322d0c5 Code formatting cleanup.
Jacob Alexander <haata@kiibohd.com>
parents: 231
diff changeset
1277 table[index( 0, TX, EVEN ) ].desc = 0;
afe96322d0c5 Code formatting cleanup.
Jacob Alexander <haata@kiibohd.com>
parents: 231
diff changeset
1278 table[index( 0, TX, ODD ) ].desc = 0;
170
85d74e5e1a95 More work on mk20dx128vlf5 port.
Jacob Alexander <haata@kiibohd.com>
parents: 118
diff changeset
1279
104
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
1280 // activate endpoint 0
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
1281 USB0_ENDPT0 = USB_ENDPT_EPRXEN | USB_ENDPT_EPTXEN | USB_ENDPT_EPHSHK;
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
1282
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
1283 // clear all ending interrupts
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
1284 USB0_ERRSTAT = 0xFF;
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
1285 USB0_ISTAT = 0xFF;
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
1286
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
1287 // set the address to zero during enumeration
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
1288 USB0_ADDR = 0;
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
1289
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
1290 // enable other interrupts
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
1291 USB0_ERREN = 0xFF;
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
1292 USB0_INTEN = USB_INTEN_TOKDNEEN |
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
1293 USB_INTEN_SOFTOKEN |
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
1294 USB_INTEN_STALLEN |
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
1295 USB_INTEN_ERROREN |
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
1296 USB_INTEN_USBRSTEN |
439
68e19d7c953e Adding proper remote wake-up support
Jacob Alexander <haata@kiibohd.com>
parents: 438
diff changeset
1297 USB_INTEN_RESUMEEN |
104
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
1298 USB_INTEN_SLEEPEN;
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
1299
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
1300 // is this necessary?
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
1301 USB0_CTL = USB_CTL_USBENSOFEN;
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
1302 return;
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
1303 }
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
1304
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
1305
231
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
1306 if ( (status & USB_ISTAT_STALL /* 80 */ ) )
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
1307 {
104
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
1308 //serial_print("stall:\n");
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
1309 USB0_ENDPT0 = USB_ENDPT_EPRXEN | USB_ENDPT_EPTXEN | USB_ENDPT_EPHSHK;
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
1310 USB0_ISTAT = USB_ISTAT_STALL;
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
1311 }
231
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
1312 if ( (status & USB_ISTAT_ERROR /* 02 */ ) )
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
1313 {
104
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
1314 uint8_t err = USB0_ERRSTAT;
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
1315 USB0_ERRSTAT = err;
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
1316 //serial_print("err:");
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
1317 //serial_phex(err);
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
1318 //serial_print("\n");
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
1319 USB0_ISTAT = USB_ISTAT_ERROR;
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
1320 }
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
1321
420
23a1868b4ac2 Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents: 385
diff changeset
1322 // USB Host signalling device to enter 'sleep' state
23a1868b4ac2 Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents: 385
diff changeset
1323 // The USB Module triggers this interrupt when it detects the bus has been idle for 3 ms
231
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
1324 if ( (status & USB_ISTAT_SLEEP /* 10 */ ) )
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
1325 {
439
68e19d7c953e Adding proper remote wake-up support
Jacob Alexander <haata@kiibohd.com>
parents: 438
diff changeset
1326 //info_print("Host has requested USB sleep/suspend state");
420
23a1868b4ac2 Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents: 385
diff changeset
1327 Output_update_usb_current( 100 ); // Set to 100 mA
439
68e19d7c953e Adding proper remote wake-up support
Jacob Alexander <haata@kiibohd.com>
parents: 438
diff changeset
1328 usb_dev_sleep = 1;
68e19d7c953e Adding proper remote wake-up support
Jacob Alexander <haata@kiibohd.com>
parents: 438
diff changeset
1329 USB0_ISTAT |= USB_ISTAT_SLEEP;
68e19d7c953e Adding proper remote wake-up support
Jacob Alexander <haata@kiibohd.com>
parents: 438
diff changeset
1330 }
68e19d7c953e Adding proper remote wake-up support
Jacob Alexander <haata@kiibohd.com>
parents: 438
diff changeset
1331
68e19d7c953e Adding proper remote wake-up support
Jacob Alexander <haata@kiibohd.com>
parents: 438
diff changeset
1332 // On USB Resume, unset the usb_dev_sleep so we don't keep sending resume signals
68e19d7c953e Adding proper remote wake-up support
Jacob Alexander <haata@kiibohd.com>
parents: 438
diff changeset
1333 if ( (status & USB_ISTAT_RESUME /* 20 */ ) )
68e19d7c953e Adding proper remote wake-up support
Jacob Alexander <haata@kiibohd.com>
parents: 438
diff changeset
1334 {
68e19d7c953e Adding proper remote wake-up support
Jacob Alexander <haata@kiibohd.com>
parents: 438
diff changeset
1335 //info_print("Host has woken-up/resumed from sleep/suspend state");
68e19d7c953e Adding proper remote wake-up support
Jacob Alexander <haata@kiibohd.com>
parents: 438
diff changeset
1336 Output_update_usb_current( *usb_bMaxPower * 2 );
68e19d7c953e Adding proper remote wake-up support
Jacob Alexander <haata@kiibohd.com>
parents: 438
diff changeset
1337 usb_dev_sleep = 0;
68e19d7c953e Adding proper remote wake-up support
Jacob Alexander <haata@kiibohd.com>
parents: 438
diff changeset
1338 USB0_ISTAT |= USB_ISTAT_RESUME;
104
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
1339 }
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
1340 }
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
1341
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
1342
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
1343
275
d5bf41d7f7ef Initial code for USB cable detection
Jacob Alexander <haata@kiibohd.com>
parents: 251
diff changeset
1344 uint8_t usb_init()
104
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
1345 {
231
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
1346 #ifdef UART_DEBUG
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
1347 print("USB INIT"NL);
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
1348 #endif
104
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
1349
175
c70f641581b5 McHCK USB WORKS!!
Jacob Alexander <haata@kiibohd.com>
parents: 171
diff changeset
1350 // Clear out endpoints table
c70f641581b5 McHCK USB WORKS!!
Jacob Alexander <haata@kiibohd.com>
parents: 171
diff changeset
1351 for ( int i = 0; i <= NUM_ENDPOINTS * 4; i++ )
c70f641581b5 McHCK USB WORKS!!
Jacob Alexander <haata@kiibohd.com>
parents: 171
diff changeset
1352 {
104
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
1353 table[i].desc = 0;
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
1354 table[i].addr = 0;
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
1355 }
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
1356
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
1357 // this basically follows the flowchart in the Kinetis
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
1358 // Quick Reference User Guide, Rev. 1, 03/2012, page 141
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
1359
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
1360 // assume 48 MHz clock already running
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
1361 // SIM - enable clock
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
1362 SIM_SCGC4 |= SIM_SCGC4_USBOTG;
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
1363
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
1364 // reset USB module
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
1365 USB0_USBTRC0 = USB_USBTRC_USBRESET;
175
c70f641581b5 McHCK USB WORKS!!
Jacob Alexander <haata@kiibohd.com>
parents: 171
diff changeset
1366 while ( (USB0_USBTRC0 & USB_USBTRC_USBRESET) != 0 ); // wait for reset to end
104
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
1367
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
1368 // set desc table base addr
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
1369 USB0_BDTPAGE1 = ((uint32_t)table) >> 8;
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
1370 USB0_BDTPAGE2 = ((uint32_t)table) >> 16;
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
1371 USB0_BDTPAGE3 = ((uint32_t)table) >> 24;
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
1372
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
1373 // clear all ISR flags
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
1374 USB0_ISTAT = 0xFF;
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
1375 USB0_ERRSTAT = 0xFF;
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
1376 USB0_OTGISTAT = 0xFF;
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
1377
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
1378 USB0_USBTRC0 |= 0x40; // undocumented bit
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
1379
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
1380 // enable USB
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
1381 USB0_CTL = USB_CTL_USBENSOFEN;
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
1382 USB0_USBCTRL = 0;
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
1383
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
1384 // enable reset interrupt
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
1385 USB0_INTEN = USB_INTEN_USBRSTEN;
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
1386
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
1387 // enable interrupt in NVIC...
175
c70f641581b5 McHCK USB WORKS!!
Jacob Alexander <haata@kiibohd.com>
parents: 171
diff changeset
1388 NVIC_SET_PRIORITY( IRQ_USBOTG, 112 );
c70f641581b5 McHCK USB WORKS!!
Jacob Alexander <haata@kiibohd.com>
parents: 171
diff changeset
1389 NVIC_ENABLE_IRQ( IRQ_USBOTG );
104
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
1390
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
1391 // enable d+ pullup
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
1392 USB0_CONTROL = USB_CONTROL_DPPULLUPNONOTG;
275
d5bf41d7f7ef Initial code for USB cable detection
Jacob Alexander <haata@kiibohd.com>
parents: 251
diff changeset
1393
420
23a1868b4ac2 Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents: 385
diff changeset
1394 // Do not check for power negotiation delay until Get Configuration Descriptor
23a1868b4ac2 Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents: 385
diff changeset
1395 power_neg_delay = 0;
23a1868b4ac2 Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents: 385
diff changeset
1396
439
68e19d7c953e Adding proper remote wake-up support
Jacob Alexander <haata@kiibohd.com>
parents: 438
diff changeset
1397 // During initialization host isn't sleeping
68e19d7c953e Adding proper remote wake-up support
Jacob Alexander <haata@kiibohd.com>
parents: 438
diff changeset
1398 usb_dev_sleep = 0;
68e19d7c953e Adding proper remote wake-up support
Jacob Alexander <haata@kiibohd.com>
parents: 438
diff changeset
1399
275
d5bf41d7f7ef Initial code for USB cable detection
Jacob Alexander <haata@kiibohd.com>
parents: 251
diff changeset
1400 return 1;
104
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
1401 }
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
1402
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
1403 // return 0 if the USB is not configured, or the configuration
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
1404 // number selected by the HOST
175
c70f641581b5 McHCK USB WORKS!!
Jacob Alexander <haata@kiibohd.com>
parents: 171
diff changeset
1405 uint8_t usb_configured()
104
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
1406 {
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
1407 return usb_configuration;
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
1408 }
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
1409