Mercurial > louis > kiibohd-controller
annotate Output/pjrcUSB/arm/usb_dev.c @ 449:45feb80a2ad1
Major USB update, fixes most (if not all) known issues
USB - General
- Refactored descriptors
- Enabled/Disable USB endpoints
- Added debug flags for special features
- Code cleanup
- Interface count calculation based off of enabled endpoints
- Delayed wTotalLength calculation to simplify descriptor offsets
- Re-ordered endpoints and interfaces
- Added more debug output
- Added usbInitTime to show how long keyboard initialization took
(Useful when debugging bad init sequences)
- Added function for usb_resume() which takes care of the resume sequence
* Resume is now only called if packets are starting to timeout
USB - Special Options
- Added enableDeviceRestartOnUSBTimeout
* A last resort hammer for bad USB Chipsets/OSs, don't use if you can help it
* Disabled
- Added enableUSBResume
* Enables host resume wake-up signalling, required to wake a computer from sleep
* Enabled
- Added enableUSBLowPowerNegotiation
* Enables power negotiation hack
* Required to use firmware with an IPad and other hard-limit low-power USB hosts
* Hasn't been tested with the recent changes
* Disabled
- Added enableUSBSuspend
* Enables power down events on host USB bus suspend
* Enabled
USB - Keyboard
- Attempted to cleanup HID SET_REPORT
* Works much better
* Still has an issue under Linux which generates *a lot* of NAKs (initializes quickly regardless)
+ Not present on other keyboards
+ SETUP -> OUT -> IN : This sequence is the problem
+ Specifically during the OUT phase
- Enabled
USB - CDC Virtual Serial Port
- Code cleanup
- Added convenience struct USBCDCLineCoding for easier debugging
- Attempted to cleanup CDC_SET_LING_CODING
* Works much better
* Still has an issue under Linux which generates *a lot* of NAKs (initializes quickly regardless)
+ SETUP -> OUT -> IN : This sequence is the problem
+ Specifically during the OUT phase
+ Likely the same issues as HID SET_REPORT
- Enabled
USB - Mouse
- Enabled
USB - Joystick
- Disabled
USB - RawIO
- Initial code, API not used yet
- Disabled
DFU
- Updated load script, now faster
author | Jacob Alexander <haata@kiibohd.com> |
---|---|
date | Tue, 31 May 2016 00:19:45 -0700 |
parents | 56237ba5da6f |
children |
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 | 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 | 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 | 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 | 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 | 38 |
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 |
449
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
43 #if enableVirtualSerialPort_define == 1 |
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
44 #include "usb_serial.h" |
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
45 #endif |
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
46 |
231
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
47 |
104
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
48 |
231
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
49 // ----- Defines ----- |
104
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
50 |
231
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
51 // DEBUG Mode |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
52 // XXX - Only use when using usbMuxUart Module |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
53 // 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
|
54 //#define UART_DEBUG 1 |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
55 // 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
|
56 //#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
|
57 |
5ffefdf89b37
Adding in USB module updates from Teensyduino 1.18rc2.
Jacob Alexander <haata@kiibohd.com>
parents:
109
diff
changeset
|
58 |
326
05a09eda53fb
Inital Remote Wakeup Support
Rowan Decker <Smasher816@gmail.com>
parents:
302
diff
changeset
|
59 #define TX_STATE_BOTH_FREE_EVEN_FIRST 0 |
05a09eda53fb
Inital Remote Wakeup Support
Rowan Decker <Smasher816@gmail.com>
parents:
302
diff
changeset
|
60 #define TX_STATE_BOTH_FREE_ODD_FIRST 1 |
05a09eda53fb
Inital Remote Wakeup Support
Rowan Decker <Smasher816@gmail.com>
parents:
302
diff
changeset
|
61 #define TX_STATE_EVEN_FREE 2 |
05a09eda53fb
Inital Remote Wakeup Support
Rowan Decker <Smasher816@gmail.com>
parents:
302
diff
changeset
|
62 #define TX_STATE_ODD_FREE 3 |
05a09eda53fb
Inital Remote Wakeup Support
Rowan Decker <Smasher816@gmail.com>
parents:
302
diff
changeset
|
63 #define TX_STATE_NONE_FREE_EVEN_FIRST 4 |
05a09eda53fb
Inital Remote Wakeup Support
Rowan Decker <Smasher816@gmail.com>
parents:
302
diff
changeset
|
64 #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
|
65 |
326
05a09eda53fb
Inital Remote Wakeup Support
Rowan Decker <Smasher816@gmail.com>
parents:
302
diff
changeset
|
66 #define BDT_OWN 0x80 |
05a09eda53fb
Inital Remote Wakeup Support
Rowan Decker <Smasher816@gmail.com>
parents:
302
diff
changeset
|
67 #define BDT_DATA1 0x40 |
05a09eda53fb
Inital Remote Wakeup Support
Rowan Decker <Smasher816@gmail.com>
parents:
302
diff
changeset
|
68 #define BDT_DATA0 0x00 |
05a09eda53fb
Inital Remote Wakeup Support
Rowan Decker <Smasher816@gmail.com>
parents:
302
diff
changeset
|
69 #define BDT_DTS 0x08 |
05a09eda53fb
Inital Remote Wakeup Support
Rowan Decker <Smasher816@gmail.com>
parents:
302
diff
changeset
|
70 #define BDT_STALL 0x04 |
104
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
71 |
231
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
72 #define TX 1 |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
73 #define RX 0 |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
74 #define ODD 1 |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
75 #define EVEN 0 |
104
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
76 #define DATA0 0 |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
77 #define DATA1 1 |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
78 |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
79 |
326
05a09eda53fb
Inital Remote Wakeup Support
Rowan Decker <Smasher816@gmail.com>
parents:
302
diff
changeset
|
80 #define GET_STATUS 0 |
05a09eda53fb
Inital Remote Wakeup Support
Rowan Decker <Smasher816@gmail.com>
parents:
302
diff
changeset
|
81 #define CLEAR_FEATURE 1 |
05a09eda53fb
Inital Remote Wakeup Support
Rowan Decker <Smasher816@gmail.com>
parents:
302
diff
changeset
|
82 #define SET_FEATURE 3 |
05a09eda53fb
Inital Remote Wakeup Support
Rowan Decker <Smasher816@gmail.com>
parents:
302
diff
changeset
|
83 #define SET_ADDRESS 5 |
05a09eda53fb
Inital Remote Wakeup Support
Rowan Decker <Smasher816@gmail.com>
parents:
302
diff
changeset
|
84 #define GET_DESCRIPTOR 6 |
05a09eda53fb
Inital Remote Wakeup Support
Rowan Decker <Smasher816@gmail.com>
parents:
302
diff
changeset
|
85 #define SET_DESCRIPTOR 7 |
05a09eda53fb
Inital Remote Wakeup Support
Rowan Decker <Smasher816@gmail.com>
parents:
302
diff
changeset
|
86 #define GET_CONFIGURATION 8 |
05a09eda53fb
Inital Remote Wakeup Support
Rowan Decker <Smasher816@gmail.com>
parents:
302
diff
changeset
|
87 #define SET_CONFIGURATION 9 |
05a09eda53fb
Inital Remote Wakeup Support
Rowan Decker <Smasher816@gmail.com>
parents:
302
diff
changeset
|
88 #define GET_INTERFACE 10 |
05a09eda53fb
Inital Remote Wakeup Support
Rowan Decker <Smasher816@gmail.com>
parents:
302
diff
changeset
|
89 #define SET_INTERFACE 11 |
05a09eda53fb
Inital Remote Wakeup Support
Rowan Decker <Smasher816@gmail.com>
parents:
302
diff
changeset
|
90 #define SYNCH_FRAME 12 |
104
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
91 |
326
05a09eda53fb
Inital Remote Wakeup Support
Rowan Decker <Smasher816@gmail.com>
parents:
302
diff
changeset
|
92 #define TX_STATE_BOTH_FREE_EVEN_FIRST 0 |
05a09eda53fb
Inital Remote Wakeup Support
Rowan Decker <Smasher816@gmail.com>
parents:
302
diff
changeset
|
93 #define TX_STATE_BOTH_FREE_ODD_FIRST 1 |
05a09eda53fb
Inital Remote Wakeup Support
Rowan Decker <Smasher816@gmail.com>
parents:
302
diff
changeset
|
94 #define TX_STATE_EVEN_FREE 2 |
05a09eda53fb
Inital Remote Wakeup Support
Rowan Decker <Smasher816@gmail.com>
parents:
302
diff
changeset
|
95 #define TX_STATE_ODD_FREE 3 |
05a09eda53fb
Inital Remote Wakeup Support
Rowan Decker <Smasher816@gmail.com>
parents:
302
diff
changeset
|
96 #define TX_STATE_NONE_FREE 4 |
231
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 |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
99 |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
100 |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
101 |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
102 // ----- Macros ----- |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
103 |
326
05a09eda53fb
Inital Remote Wakeup Support
Rowan Decker <Smasher816@gmail.com>
parents:
302
diff
changeset
|
104 #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
|
105 |
326
05a09eda53fb
Inital Remote Wakeup Support
Rowan Decker <Smasher816@gmail.com>
parents:
302
diff
changeset
|
106 #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
|
107 | ((data) ? BDT_DATA1 : BDT_DATA0) \ |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
108 | ((count) << 16)) |
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 #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
|
111 #define stat2bufferdescriptor(stat) (table + ((stat) >> 2)) |
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 |
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 // ----- Structs ----- |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
116 |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
117 // buffer descriptor table |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
118 |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
119 typedef struct { |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
120 uint32_t desc; |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
121 void * addr; |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
122 } bdt_t; |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
123 |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
124 static union { |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
125 struct { |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
126 union { |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
127 struct { |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
128 uint8_t bmRequestType; |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
129 uint8_t bRequest; |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
130 }; |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
131 uint16_t wRequestAndType; |
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 uint16_t wValue; |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
134 uint16_t wIndex; |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
135 uint16_t wLength; |
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 struct { |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
138 uint32_t word1; |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
139 uint32_t word2; |
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 } setup; |
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 |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
144 |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
145 // ----- Variables ----- |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
146 |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
147 __attribute__ ((section(".usbdescriptortable"), used)) |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
148 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
|
149 |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
150 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
|
151 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
|
152 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
|
153 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
|
154 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
|
155 |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
156 static uint8_t tx_state[NUM_ENDPOINTS]; |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
157 |
104
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
158 // 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
|
159 // 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
|
160 // 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
|
161 |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
162 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
|
163 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
|
164 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
|
165 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
|
166 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
|
167 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
|
168 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
|
169 |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
170 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
|
171 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
|
172 |
231
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
173 static uint8_t reply_buffer[8]; |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
174 |
420
23a1868b4ac2
Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents:
385
diff
changeset
|
175 static uint8_t power_neg_delay; |
23a1868b4ac2
Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents:
385
diff
changeset
|
176 static uint32_t power_neg_time; |
23a1868b4ac2
Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents:
385
diff
changeset
|
177 |
439
68e19d7c953e
Adding proper remote wake-up support
Jacob Alexander <haata@kiibohd.com>
parents:
438
diff
changeset
|
178 static uint8_t usb_dev_sleep = 0; |
68e19d7c953e
Adding proper remote wake-up support
Jacob Alexander <haata@kiibohd.com>
parents:
438
diff
changeset
|
179 |
231
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
180 |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
181 |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
182 // ----- Functions ----- |
104
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
183 |
175 | 184 static void endpoint0_stall() |
104
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
185 { |
368
06a54d582bf8
FIxing Media Keys and general USB compatibilty
Jacob Alexander <haata@kiibohd.com>
parents:
347
diff
changeset
|
186 #ifdef UART_DEBUG_UNKNOWN |
449
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
187 print("STALL : "); |
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
188 printInt32( systick_millis_count - USBInit_TimeStart ); |
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
189 print(" ms"); |
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
190 print(NL); |
368
06a54d582bf8
FIxing Media Keys and general USB compatibilty
Jacob Alexander <haata@kiibohd.com>
parents:
347
diff
changeset
|
191 #endif |
104
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
192 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
|
193 } |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
194 |
231
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
195 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
|
196 { |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
197 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
|
198 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
|
199 ep0_tx_data_toggle ^= 1; |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
200 ep0_tx_bdt_bank ^= 1; |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
201 } |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
202 |
447
56237ba5da6f
Adding auto-restart support whenever USB gets into an odd state
Jacob Alexander <haata@kiibohd.com>
parents:
439
diff
changeset
|
203 void usb_reinit() |
56237ba5da6f
Adding auto-restart support whenever USB gets into an odd state
Jacob Alexander <haata@kiibohd.com>
parents:
439
diff
changeset
|
204 { |
56237ba5da6f
Adding auto-restart support whenever USB gets into an odd state
Jacob Alexander <haata@kiibohd.com>
parents:
439
diff
changeset
|
205 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
|
206 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
|
207 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
|
208 usb_init(); |
56237ba5da6f
Adding auto-restart support whenever USB gets into an odd state
Jacob Alexander <haata@kiibohd.com>
parents:
439
diff
changeset
|
209 } |
56237ba5da6f
Adding auto-restart support whenever USB gets into an odd state
Jacob Alexander <haata@kiibohd.com>
parents:
439
diff
changeset
|
210 |
420
23a1868b4ac2
Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents:
385
diff
changeset
|
211 // 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
|
212 // 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
|
213 void usb_device_check() |
23a1868b4ac2
Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents:
385
diff
changeset
|
214 { |
23a1868b4ac2
Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents:
385
diff
changeset
|
215 // 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
|
216 // 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
|
217 if ( power_neg_delay ) |
23a1868b4ac2
Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents:
385
diff
changeset
|
218 { |
23a1868b4ac2
Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents:
385
diff
changeset
|
219 // Check if 100 ms has elapsed |
23a1868b4ac2
Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents:
385
diff
changeset
|
220 if ( systick_millis_count - power_neg_time > 100 ) |
23a1868b4ac2
Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents:
385
diff
changeset
|
221 { |
449
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
222 power_neg_delay = 0; |
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
223 |
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
224 // USB Low Power Negotiation |
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
225 #if enableUSBLowPowerNegotiation_define == 1 |
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
226 // Check to see if bMaxPower has already be lowered |
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
227 // This generally points to a USB bug (host or device?) |
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
228 if ( *usb_bMaxPower == 50 ) |
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
229 { |
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
230 warn_msg("Power negotiation delay detected again, likely a system/device USB bug"); |
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
231 return; |
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
232 } |
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
233 |
420
23a1868b4ac2
Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents:
385
diff
changeset
|
234 // Update bMaxPower |
23a1868b4ac2
Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents:
385
diff
changeset
|
235 // The value set is in increments of 2 mA |
23a1868b4ac2
Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents:
385
diff
changeset
|
236 // So 50 * 2 mA = 100 mA |
23a1868b4ac2
Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents:
385
diff
changeset
|
237 // XXX Currently only transitions to 100 mA |
23a1868b4ac2
Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents:
385
diff
changeset
|
238 // 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
|
239 *usb_bMaxPower = 50; |
23a1868b4ac2
Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents:
385
diff
changeset
|
240 |
23a1868b4ac2
Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents:
385
diff
changeset
|
241 // 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
|
242 usb_reinit(); |
449
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
243 #else |
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
244 warn_msg("USB Low Power Negotation Disabled, condition detected."); |
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
245 #endif |
420
23a1868b4ac2
Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents:
385
diff
changeset
|
246 } |
23a1868b4ac2
Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents:
385
diff
changeset
|
247 } |
23a1868b4ac2
Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents:
385
diff
changeset
|
248 } |
23a1868b4ac2
Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents:
385
diff
changeset
|
249 |
175 | 250 static void usb_setup() |
104
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
251 { |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
252 const uint8_t *data = NULL; |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
253 uint32_t datalen = 0; |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
254 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
|
255 uint32_t size; |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
256 volatile uint8_t *reg; |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
257 uint8_t epconf; |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
258 const uint8_t *cfg; |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
259 int i; |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
260 |
449
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
261 // Reset USB Init timer |
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
262 USBInit_TimeEnd = systick_millis_count; |
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
263 USBInit_Ticks++; |
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
264 |
420
23a1868b4ac2
Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents:
385
diff
changeset
|
265 // 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
|
266 // See GET_DESCRIPTOR - Configuration |
23a1868b4ac2
Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents:
385
diff
changeset
|
267 if ( power_neg_delay ) |
23a1868b4ac2
Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents:
385
diff
changeset
|
268 { |
23a1868b4ac2
Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents:
385
diff
changeset
|
269 power_neg_delay = 0; |
23a1868b4ac2
Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents:
385
diff
changeset
|
270 } |
23a1868b4ac2
Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents:
385
diff
changeset
|
271 |
231
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
272 switch ( setup.wRequestAndType ) |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
273 { |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
274 case 0x0500: // SET_ADDRESS |
368
06a54d582bf8
FIxing Media Keys and general USB compatibilty
Jacob Alexander <haata@kiibohd.com>
parents:
347
diff
changeset
|
275 goto send; |
06a54d582bf8
FIxing Media Keys and general USB compatibilty
Jacob Alexander <haata@kiibohd.com>
parents:
347
diff
changeset
|
276 |
231
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
277 case 0x0900: // SET_CONFIGURATION |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
278 #ifdef UART_DEBUG |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
279 print("CONFIGURE - "); |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
280 #endif |
104
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
281 usb_configuration = setup.wValue; |
347
136e47478441
UARTConnect enumeration working!
Jacob Alexander <haata@kiibohd.com>
parents:
346
diff
changeset
|
282 Output_Available = usb_configuration; |
104
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
283 reg = &USB0_ENDPT1; |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
284 cfg = usb_endpoint_config_table; |
420
23a1868b4ac2
Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents:
385
diff
changeset
|
285 |
23a1868b4ac2
Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents:
385
diff
changeset
|
286 // Now configured so we can utilize bMaxPower now |
23a1868b4ac2
Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents:
385
diff
changeset
|
287 Output_update_usb_current( *usb_bMaxPower * 2 ); |
23a1868b4ac2
Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents:
385
diff
changeset
|
288 |
104
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
289 // 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
|
290 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
|
291 { |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
292 if ( table[i].desc & BDT_OWN ) |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
293 { |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
294 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
|
295 } |
5ffefdf89b37
Adding in USB module updates from Teensyduino 1.18rc2.
Jacob Alexander <haata@kiibohd.com>
parents:
109
diff
changeset
|
296 } |
5ffefdf89b37
Adding in USB module updates from Teensyduino 1.18rc2.
Jacob Alexander <haata@kiibohd.com>
parents:
109
diff
changeset
|
297 // free all queued packets |
231
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
298 for ( i = 0; i < NUM_ENDPOINTS; i++ ) |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
299 { |
117
5ffefdf89b37
Adding in USB module updates from Teensyduino 1.18rc2.
Jacob Alexander <haata@kiibohd.com>
parents:
109
diff
changeset
|
300 usb_packet_t *p, *n; |
5ffefdf89b37
Adding in USB module updates from Teensyduino 1.18rc2.
Jacob Alexander <haata@kiibohd.com>
parents:
109
diff
changeset
|
301 p = rx_first[i]; |
231
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
302 while ( p ) |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
303 { |
117
5ffefdf89b37
Adding in USB module updates from Teensyduino 1.18rc2.
Jacob Alexander <haata@kiibohd.com>
parents:
109
diff
changeset
|
304 n = p->next; |
5ffefdf89b37
Adding in USB module updates from Teensyduino 1.18rc2.
Jacob Alexander <haata@kiibohd.com>
parents:
109
diff
changeset
|
305 usb_free(p); |
5ffefdf89b37
Adding in USB module updates from Teensyduino 1.18rc2.
Jacob Alexander <haata@kiibohd.com>
parents:
109
diff
changeset
|
306 p = n; |
5ffefdf89b37
Adding in USB module updates from Teensyduino 1.18rc2.
Jacob Alexander <haata@kiibohd.com>
parents:
109
diff
changeset
|
307 } |
250
afe96322d0c5
Code formatting cleanup.
Jacob Alexander <haata@kiibohd.com>
parents:
231
diff
changeset
|
308 rx_first[ i ] = NULL; |
afe96322d0c5
Code formatting cleanup.
Jacob Alexander <haata@kiibohd.com>
parents:
231
diff
changeset
|
309 rx_last[ i ] = NULL; |
117
5ffefdf89b37
Adding in USB module updates from Teensyduino 1.18rc2.
Jacob Alexander <haata@kiibohd.com>
parents:
109
diff
changeset
|
310 p = tx_first[i]; |
231
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
311 while (p) |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
312 { |
117
5ffefdf89b37
Adding in USB module updates from Teensyduino 1.18rc2.
Jacob Alexander <haata@kiibohd.com>
parents:
109
diff
changeset
|
313 n = p->next; |
5ffefdf89b37
Adding in USB module updates from Teensyduino 1.18rc2.
Jacob Alexander <haata@kiibohd.com>
parents:
109
diff
changeset
|
314 usb_free(p); |
5ffefdf89b37
Adding in USB module updates from Teensyduino 1.18rc2.
Jacob Alexander <haata@kiibohd.com>
parents:
109
diff
changeset
|
315 p = n; |
5ffefdf89b37
Adding in USB module updates from Teensyduino 1.18rc2.
Jacob Alexander <haata@kiibohd.com>
parents:
109
diff
changeset
|
316 } |
250
afe96322d0c5
Code formatting cleanup.
Jacob Alexander <haata@kiibohd.com>
parents:
231
diff
changeset
|
317 tx_first[ i ] = NULL; |
afe96322d0c5
Code formatting cleanup.
Jacob Alexander <haata@kiibohd.com>
parents:
231
diff
changeset
|
318 tx_last[ i ] = NULL; |
117
5ffefdf89b37
Adding in USB module updates from Teensyduino 1.18rc2.
Jacob Alexander <haata@kiibohd.com>
parents:
109
diff
changeset
|
319 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
|
320 |
250
afe96322d0c5
Code formatting cleanup.
Jacob Alexander <haata@kiibohd.com>
parents:
231
diff
changeset
|
321 switch ( tx_state[ i ] ) |
afe96322d0c5
Code formatting cleanup.
Jacob Alexander <haata@kiibohd.com>
parents:
231
diff
changeset
|
322 { |
231
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
323 case TX_STATE_EVEN_FREE: |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
324 case TX_STATE_NONE_FREE_EVEN_FIRST: |
250
afe96322d0c5
Code formatting cleanup.
Jacob Alexander <haata@kiibohd.com>
parents:
231
diff
changeset
|
325 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
|
326 break; |
231
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
327 case TX_STATE_ODD_FREE: |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
328 case TX_STATE_NONE_FREE_ODD_FIRST: |
250
afe96322d0c5
Code formatting cleanup.
Jacob Alexander <haata@kiibohd.com>
parents:
231
diff
changeset
|
329 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
|
330 break; |
231
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
331 default: |
117
5ffefdf89b37
Adding in USB module updates from Teensyduino 1.18rc2.
Jacob Alexander <haata@kiibohd.com>
parents:
109
diff
changeset
|
332 break; |
104
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
333 } |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
334 } |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
335 usb_rx_memory_needed = 0; |
231
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
336 for ( i = 1; i <= NUM_ENDPOINTS; i++ ) |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
337 { |
104
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
338 epconf = *cfg++; |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
339 *reg = epconf; |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
340 reg += 4; |
231
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
341 if ( epconf & USB_ENDPT_EPRXEN ) |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
342 { |
104
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
343 usb_packet_t *p; |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
344 p = usb_malloc(); |
231
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
345 if ( p ) |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
346 { |
250
afe96322d0c5
Code formatting cleanup.
Jacob Alexander <haata@kiibohd.com>
parents:
231
diff
changeset
|
347 table[ index( i, RX, EVEN ) ].addr = p->buf; |
afe96322d0c5
Code formatting cleanup.
Jacob Alexander <haata@kiibohd.com>
parents:
231
diff
changeset
|
348 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
|
349 } |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
350 else |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
351 { |
250
afe96322d0c5
Code formatting cleanup.
Jacob Alexander <haata@kiibohd.com>
parents:
231
diff
changeset
|
352 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
|
353 usb_rx_memory_needed++; |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
354 } |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
355 p = usb_malloc(); |
231
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
356 if ( p ) |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
357 { |
250
afe96322d0c5
Code formatting cleanup.
Jacob Alexander <haata@kiibohd.com>
parents:
231
diff
changeset
|
358 table[ index( i, RX, ODD ) ].addr = p->buf; |
afe96322d0c5
Code formatting cleanup.
Jacob Alexander <haata@kiibohd.com>
parents:
231
diff
changeset
|
359 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
|
360 } |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
361 else |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
362 { |
250
afe96322d0c5
Code formatting cleanup.
Jacob Alexander <haata@kiibohd.com>
parents:
231
diff
changeset
|
363 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
|
364 usb_rx_memory_needed++; |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
365 } |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
366 } |
250
afe96322d0c5
Code formatting cleanup.
Jacob Alexander <haata@kiibohd.com>
parents:
231
diff
changeset
|
367 table[ index( i, TX, EVEN ) ].desc = 0; |
afe96322d0c5
Code formatting cleanup.
Jacob Alexander <haata@kiibohd.com>
parents:
231
diff
changeset
|
368 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
|
369 } |
368
06a54d582bf8
FIxing Media Keys and general USB compatibilty
Jacob Alexander <haata@kiibohd.com>
parents:
347
diff
changeset
|
370 goto send; |
06a54d582bf8
FIxing Media Keys and general USB compatibilty
Jacob Alexander <haata@kiibohd.com>
parents:
347
diff
changeset
|
371 |
231
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
372 case 0x0880: // GET_CONFIGURATION |
104
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
373 reply_buffer[0] = usb_configuration; |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
374 datalen = 1; |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
375 data = reply_buffer; |
368
06a54d582bf8
FIxing Media Keys and general USB compatibilty
Jacob Alexander <haata@kiibohd.com>
parents:
347
diff
changeset
|
376 goto send; |
06a54d582bf8
FIxing Media Keys and general USB compatibilty
Jacob Alexander <haata@kiibohd.com>
parents:
347
diff
changeset
|
377 |
231
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
378 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
|
379 reply_buffer[0] = 0; |
104
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
380 reply_buffer[1] = 0; |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
381 datalen = 2; |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
382 data = reply_buffer; |
368
06a54d582bf8
FIxing Media Keys and general USB compatibilty
Jacob Alexander <haata@kiibohd.com>
parents:
347
diff
changeset
|
383 goto send; |
06a54d582bf8
FIxing Media Keys and general USB compatibilty
Jacob Alexander <haata@kiibohd.com>
parents:
347
diff
changeset
|
384 |
231
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
385 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
|
386 if ( setup.wIndex > NUM_ENDPOINTS ) |
231
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
387 { |
104
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
388 // 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
|
389 endpoint0_stall(); |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
390 return; |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
391 } |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
392 reply_buffer[0] = 0; |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
393 reply_buffer[1] = 0; |
231
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
394 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
|
395 reply_buffer[0] = 1; |
104
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
396 data = reply_buffer; |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
397 datalen = 2; |
368
06a54d582bf8
FIxing Media Keys and general USB compatibilty
Jacob Alexander <haata@kiibohd.com>
parents:
347
diff
changeset
|
398 goto send; |
06a54d582bf8
FIxing Media Keys and general USB compatibilty
Jacob Alexander <haata@kiibohd.com>
parents:
347
diff
changeset
|
399 |
302
ac842066568a
Adding additional case statements for SET_FEATURE and CLEAR_FEATURE
Jacob Alexander <haata@kiibohd.com>
parents:
301
diff
changeset
|
400 case 0x0100: // CLEAR_FEATURE (device) |
420
23a1868b4ac2
Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents:
385
diff
changeset
|
401 switch ( setup.wValue ) |
23a1868b4ac2
Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents:
385
diff
changeset
|
402 { |
23a1868b4ac2
Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents:
385
diff
changeset
|
403 // CLEAR_FEATURE(DEVICE_REMOTE_WAKEUP) |
23a1868b4ac2
Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents:
385
diff
changeset
|
404 // See SET_FEATURE(DEVICE_REMOTE_WAKEUP) for details |
23a1868b4ac2
Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents:
385
diff
changeset
|
405 case 0x1: |
23a1868b4ac2
Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents:
385
diff
changeset
|
406 goto send; |
23a1868b4ac2
Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents:
385
diff
changeset
|
407 } |
23a1868b4ac2
Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents:
385
diff
changeset
|
408 |
23a1868b4ac2
Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents:
385
diff
changeset
|
409 warn_msg("SET_FEATURE - Device wValue("); |
23a1868b4ac2
Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents:
385
diff
changeset
|
410 printHex( setup.wValue ); |
23a1868b4ac2
Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents:
385
diff
changeset
|
411 print( ")" NL ); |
23a1868b4ac2
Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents:
385
diff
changeset
|
412 endpoint0_stall(); |
23a1868b4ac2
Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents:
385
diff
changeset
|
413 return; |
23a1868b4ac2
Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents:
385
diff
changeset
|
414 |
302
ac842066568a
Adding additional case statements for SET_FEATURE and CLEAR_FEATURE
Jacob Alexander <haata@kiibohd.com>
parents:
301
diff
changeset
|
415 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
|
416 // TODO: Currently ignoring, perhaps useful? -HaaTa |
420
23a1868b4ac2
Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents:
385
diff
changeset
|
417 warn_msg("CLEAR_FEATURE - Interface wValue("); |
23a1868b4ac2
Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents:
385
diff
changeset
|
418 printHex( setup.wValue ); |
23a1868b4ac2
Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents:
385
diff
changeset
|
419 print(") wIndex("); |
23a1868b4ac2
Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents:
385
diff
changeset
|
420 printHex( setup.wIndex ); |
23a1868b4ac2
Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents:
385
diff
changeset
|
421 print( ")" NL ); |
302
ac842066568a
Adding additional case statements for SET_FEATURE and CLEAR_FEATURE
Jacob Alexander <haata@kiibohd.com>
parents:
301
diff
changeset
|
422 endpoint0_stall(); |
ac842066568a
Adding additional case statements for SET_FEATURE and CLEAR_FEATURE
Jacob Alexander <haata@kiibohd.com>
parents:
301
diff
changeset
|
423 return; |
368
06a54d582bf8
FIxing Media Keys and general USB compatibilty
Jacob Alexander <haata@kiibohd.com>
parents:
347
diff
changeset
|
424 |
381
fbe55b27dc02
Cleaning up CLEAR_FEATURE (endpoint)
Jacob Alexander <haata@kiibohd.com>
parents:
376
diff
changeset
|
425 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
|
426 i = setup.wIndex & 0x7F; |
231
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
427 if ( i > NUM_ENDPOINTS || setup.wValue != 0 ) |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
428 { |
104
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
429 endpoint0_stall(); |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
430 return; |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
431 } |
381
fbe55b27dc02
Cleaning up CLEAR_FEATURE (endpoint)
Jacob Alexander <haata@kiibohd.com>
parents:
376
diff
changeset
|
432 (*(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
|
433 // 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
|
434 goto send; |
368
06a54d582bf8
FIxing Media Keys and general USB compatibilty
Jacob Alexander <haata@kiibohd.com>
parents:
347
diff
changeset
|
435 |
302
ac842066568a
Adding additional case statements for SET_FEATURE and CLEAR_FEATURE
Jacob Alexander <haata@kiibohd.com>
parents:
301
diff
changeset
|
436 case 0x0300: // SET_FEATURE (device) |
420
23a1868b4ac2
Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents:
385
diff
changeset
|
437 switch ( setup.wValue ) |
23a1868b4ac2
Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents:
385
diff
changeset
|
438 { |
23a1868b4ac2
Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents:
385
diff
changeset
|
439 // SET_FEATURE(DEVICE_REMOTE_WAKEUP) |
23a1868b4ac2
Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents:
385
diff
changeset
|
440 // XXX: Only used to confirm Remote Wake |
23a1868b4ac2
Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents:
385
diff
changeset
|
441 // Used on Mac OSX and Windows not on Linux |
23a1868b4ac2
Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents:
385
diff
changeset
|
442 // Good post on the behaviour: |
23a1868b4ac2
Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents:
385
diff
changeset
|
443 // 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
|
444 case 0x1: |
23a1868b4ac2
Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents:
385
diff
changeset
|
445 goto send; |
23a1868b4ac2
Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents:
385
diff
changeset
|
446 } |
23a1868b4ac2
Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents:
385
diff
changeset
|
447 |
23a1868b4ac2
Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents:
385
diff
changeset
|
448 warn_msg("SET_FEATURE - Device wValue("); |
23a1868b4ac2
Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents:
385
diff
changeset
|
449 printHex( setup.wValue ); |
23a1868b4ac2
Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents:
385
diff
changeset
|
450 print( ")" NL ); |
23a1868b4ac2
Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents:
385
diff
changeset
|
451 endpoint0_stall(); |
23a1868b4ac2
Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents:
385
diff
changeset
|
452 return; |
23a1868b4ac2
Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents:
385
diff
changeset
|
453 |
302
ac842066568a
Adding additional case statements for SET_FEATURE and CLEAR_FEATURE
Jacob Alexander <haata@kiibohd.com>
parents:
301
diff
changeset
|
454 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
|
455 // TODO: Currently ignoring, perhaps useful? -HaaTa |
420
23a1868b4ac2
Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents:
385
diff
changeset
|
456 warn_msg("SET_FEATURE - Interface wValue("); |
23a1868b4ac2
Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents:
385
diff
changeset
|
457 printHex( setup.wValue ); |
23a1868b4ac2
Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents:
385
diff
changeset
|
458 print(") wIndex("); |
23a1868b4ac2
Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents:
385
diff
changeset
|
459 printHex( setup.wIndex ); |
23a1868b4ac2
Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents:
385
diff
changeset
|
460 print( ")" NL ); |
302
ac842066568a
Adding additional case statements for SET_FEATURE and CLEAR_FEATURE
Jacob Alexander <haata@kiibohd.com>
parents:
301
diff
changeset
|
461 endpoint0_stall(); |
ac842066568a
Adding additional case statements for SET_FEATURE and CLEAR_FEATURE
Jacob Alexander <haata@kiibohd.com>
parents:
301
diff
changeset
|
462 return; |
368
06a54d582bf8
FIxing Media Keys and general USB compatibilty
Jacob Alexander <haata@kiibohd.com>
parents:
347
diff
changeset
|
463 |
231
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
464 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
|
465 i = setup.wIndex & 0x7F; |
231
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
466 if ( i > NUM_ENDPOINTS || setup.wValue != 0 ) |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
467 { |
104
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
468 // 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
|
469 endpoint0_stall(); |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
470 return; |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
471 } |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
472 (*(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
|
473 // 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
|
474 goto send; |
06a54d582bf8
FIxing Media Keys and general USB compatibilty
Jacob Alexander <haata@kiibohd.com>
parents:
347
diff
changeset
|
475 |
231
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
476 case 0x0680: // GET_DESCRIPTOR |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
477 case 0x0681: |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
478 #ifdef UART_DEBUG |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
479 print("desc:"); |
250
afe96322d0c5
Code formatting cleanup.
Jacob Alexander <haata@kiibohd.com>
parents:
231
diff
changeset
|
480 printHex( setup.wValue ); |
afe96322d0c5
Code formatting cleanup.
Jacob Alexander <haata@kiibohd.com>
parents:
231
diff
changeset
|
481 print( NL ); |
231
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
482 #endif |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
483 for ( list = usb_descriptor_list; 1; list++ ) |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
484 { |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
485 if ( list->addr == NULL ) |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
486 break; |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
487 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
|
488 { |
104
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
489 data = list->addr; |
231
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
490 if ( (setup.wValue >> 8) == 3 ) |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
491 { |
117
5ffefdf89b37
Adding in USB module updates from Teensyduino 1.18rc2.
Jacob Alexander <haata@kiibohd.com>
parents:
109
diff
changeset
|
492 // 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
|
493 // length field, allowing runtime configured |
5ffefdf89b37
Adding in USB module updates from Teensyduino 1.18rc2.
Jacob Alexander <haata@kiibohd.com>
parents:
109
diff
changeset
|
494 // length. |
5ffefdf89b37
Adding in USB module updates from Teensyduino 1.18rc2.
Jacob Alexander <haata@kiibohd.com>
parents:
109
diff
changeset
|
495 datalen = *(list->addr); |
231
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
496 } |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
497 else |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
498 { |
117
5ffefdf89b37
Adding in USB module updates from Teensyduino 1.18rc2.
Jacob Alexander <haata@kiibohd.com>
parents:
109
diff
changeset
|
499 datalen = list->length; |
5ffefdf89b37
Adding in USB module updates from Teensyduino 1.18rc2.
Jacob Alexander <haata@kiibohd.com>
parents:
109
diff
changeset
|
500 } |
420
23a1868b4ac2
Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents:
385
diff
changeset
|
501 |
23a1868b4ac2
Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents:
385
diff
changeset
|
502 // XXX Power negotiation hack -HaaTa |
23a1868b4ac2
Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents:
385
diff
changeset
|
503 // 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
|
504 // 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
|
505 // To get around this: |
23a1868b4ac2
Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents:
385
diff
changeset
|
506 // * Attempt to set bMaxPower to 500 mA first |
23a1868b4ac2
Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents:
385
diff
changeset
|
507 // * 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
|
508 // (Descriptor with bMaxPower in it) |
23a1868b4ac2
Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents:
385
diff
changeset
|
509 // * Change usb_bMaxPower to 50 (100 mA) |
23a1868b4ac2
Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents:
385
diff
changeset
|
510 // * Restart the USB init process |
23a1868b4ac2
Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents:
385
diff
changeset
|
511 // 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
|
512 // 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
|
513 // (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
|
514 // 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
|
515 // (which should be fine for just the mcu) |
23a1868b4ac2
Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents:
385
diff
changeset
|
516 if ( setup.wValue == 0x0200 && setup.wIndex == 0x0 ) |
23a1868b4ac2
Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents:
385
diff
changeset
|
517 { |
23a1868b4ac2
Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents:
385
diff
changeset
|
518 power_neg_delay = 1; |
23a1868b4ac2
Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents:
385
diff
changeset
|
519 power_neg_time = systick_millis_count; |
23a1868b4ac2
Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents:
385
diff
changeset
|
520 } |
23a1868b4ac2
Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents:
385
diff
changeset
|
521 |
231
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
522 #if UART_DEBUG |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
523 print("Desc found, "); |
250
afe96322d0c5
Code formatting cleanup.
Jacob Alexander <haata@kiibohd.com>
parents:
231
diff
changeset
|
524 printHex32( (uint32_t)data ); |
231
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
525 print(","); |
250
afe96322d0c5
Code formatting cleanup.
Jacob Alexander <haata@kiibohd.com>
parents:
231
diff
changeset
|
526 printHex( datalen ); |
231
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
527 print(","); |
250
afe96322d0c5
Code formatting cleanup.
Jacob Alexander <haata@kiibohd.com>
parents:
231
diff
changeset
|
528 printHex_op( data[0], 2 ); |
afe96322d0c5
Code formatting cleanup.
Jacob Alexander <haata@kiibohd.com>
parents:
231
diff
changeset
|
529 printHex_op( data[1], 2 ); |
afe96322d0c5
Code formatting cleanup.
Jacob Alexander <haata@kiibohd.com>
parents:
231
diff
changeset
|
530 printHex_op( data[2], 2 ); |
afe96322d0c5
Code formatting cleanup.
Jacob Alexander <haata@kiibohd.com>
parents:
231
diff
changeset
|
531 printHex_op( data[3], 2 ); |
afe96322d0c5
Code formatting cleanup.
Jacob Alexander <haata@kiibohd.com>
parents:
231
diff
changeset
|
532 printHex_op( data[4], 2 ); |
afe96322d0c5
Code formatting cleanup.
Jacob Alexander <haata@kiibohd.com>
parents:
231
diff
changeset
|
533 printHex_op( data[5], 2 ); |
afe96322d0c5
Code formatting cleanup.
Jacob Alexander <haata@kiibohd.com>
parents:
231
diff
changeset
|
534 print( NL ); |
231
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
535 #endif |
104
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
536 goto send; |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
537 } |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
538 } |
231
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
539 #ifdef UART_DEBUG |
250
afe96322d0c5
Code formatting cleanup.
Jacob Alexander <haata@kiibohd.com>
parents:
231
diff
changeset
|
540 print( "desc: not found" NL ); |
231
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
541 #endif |
104
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
542 endpoint0_stall(); |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
543 return; |
231
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
544 |
449
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
545 #if enableVirtualSerialPort_define == 1 |
231
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
546 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
|
547 usb_cdc_line_rtsdtr = setup.wValue; |
449
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
548 //info_print("set control line state"); |
368
06a54d582bf8
FIxing Media Keys and general USB compatibilty
Jacob Alexander <haata@kiibohd.com>
parents:
347
diff
changeset
|
549 goto send; |
231
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
550 |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
551 case 0x21A1: // CDC_GET_LINE_CODING |
449
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
552 data = (uint8_t*)&usb_cdc_line_coding; |
231
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
553 datalen = sizeof( usb_cdc_line_coding ); |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
554 goto send; |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
555 |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
556 case 0x2021: // CDC_SET_LINE_CODING |
449
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
557 // ZLP Reply |
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
558 // Settings are applied in PID=OUT |
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
559 goto send; |
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
560 #endif |
231
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
561 |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
562 case 0x0921: // HID SET_REPORT |
449
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
563 // ZLP Reply |
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
564 // Settings are applied in PID=OUT |
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
565 |
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
566 #ifdef UART_DEBUG |
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
567 print("report_type("); |
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
568 printHex( setup.wValue >> 8 ); |
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
569 print(")report_id("); |
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
570 printHex( setup.wValue & 0xFF ); |
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
571 print(")interface("); |
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
572 printHex( setup.wIndex ); |
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
573 print(")len("); |
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
574 printHex( setup.wLength ); |
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
575 print(")"); |
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
576 print( NL ); |
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
577 #endif |
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
578 |
383
801e7628d977
Fixing long-standing SET_REPORT bug
Jacob Alexander <haata@kiibohd.com>
parents:
381
diff
changeset
|
579 // Interface |
801e7628d977
Fixing long-standing SET_REPORT bug
Jacob Alexander <haata@kiibohd.com>
parents:
381
diff
changeset
|
580 switch ( setup.wIndex & 0xFF ) |
801e7628d977
Fixing long-standing SET_REPORT bug
Jacob Alexander <haata@kiibohd.com>
parents:
381
diff
changeset
|
581 { |
801e7628d977
Fixing long-standing SET_REPORT bug
Jacob Alexander <haata@kiibohd.com>
parents:
381
diff
changeset
|
582 // Keyboard Interface |
801e7628d977
Fixing long-standing SET_REPORT bug
Jacob Alexander <haata@kiibohd.com>
parents:
381
diff
changeset
|
583 case KEYBOARD_INTERFACE: |
801e7628d977
Fixing long-standing SET_REPORT bug
Jacob Alexander <haata@kiibohd.com>
parents:
381
diff
changeset
|
584 break; |
801e7628d977
Fixing long-standing SET_REPORT bug
Jacob Alexander <haata@kiibohd.com>
parents:
381
diff
changeset
|
585 // NKRO Keyboard Interface |
801e7628d977
Fixing long-standing SET_REPORT bug
Jacob Alexander <haata@kiibohd.com>
parents:
381
diff
changeset
|
586 case NKRO_KEYBOARD_INTERFACE: |
801e7628d977
Fixing long-standing SET_REPORT bug
Jacob Alexander <haata@kiibohd.com>
parents:
381
diff
changeset
|
587 break; |
801e7628d977
Fixing long-standing SET_REPORT bug
Jacob Alexander <haata@kiibohd.com>
parents:
381
diff
changeset
|
588 default: |
801e7628d977
Fixing long-standing SET_REPORT bug
Jacob Alexander <haata@kiibohd.com>
parents:
381
diff
changeset
|
589 warn_msg("Unknown interface - "); |
801e7628d977
Fixing long-standing SET_REPORT bug
Jacob Alexander <haata@kiibohd.com>
parents:
381
diff
changeset
|
590 printHex( setup.wIndex ); |
801e7628d977
Fixing long-standing SET_REPORT bug
Jacob Alexander <haata@kiibohd.com>
parents:
381
diff
changeset
|
591 print( NL ); |
801e7628d977
Fixing long-standing SET_REPORT bug
Jacob Alexander <haata@kiibohd.com>
parents:
381
diff
changeset
|
592 endpoint0_stall(); |
449
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
593 return; |
383
801e7628d977
Fixing long-standing SET_REPORT bug
Jacob Alexander <haata@kiibohd.com>
parents:
381
diff
changeset
|
594 } |
368
06a54d582bf8
FIxing Media Keys and general USB compatibilty
Jacob Alexander <haata@kiibohd.com>
parents:
347
diff
changeset
|
595 |
447
56237ba5da6f
Adding auto-restart support whenever USB gets into an odd state
Jacob Alexander <haata@kiibohd.com>
parents:
439
diff
changeset
|
596 goto send; |
104
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
597 |
231
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
598 case 0x01A1: // HID GET_REPORT |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
599 #ifdef UART_DEBUG |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
600 print("GET_REPORT - "); |
368
06a54d582bf8
FIxing Media Keys and general USB compatibilty
Jacob Alexander <haata@kiibohd.com>
parents:
347
diff
changeset
|
601 printHex( setup.wIndex ); |
231
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
602 print(NL); |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
603 #endif |
368
06a54d582bf8
FIxing Media Keys and general USB compatibilty
Jacob Alexander <haata@kiibohd.com>
parents:
347
diff
changeset
|
604 // Search through descriptors returning necessary info |
06a54d582bf8
FIxing Media Keys and general USB compatibilty
Jacob Alexander <haata@kiibohd.com>
parents:
347
diff
changeset
|
605 for ( list = usb_descriptor_list; 1; list++ ) |
06a54d582bf8
FIxing Media Keys and general USB compatibilty
Jacob Alexander <haata@kiibohd.com>
parents:
347
diff
changeset
|
606 { |
06a54d582bf8
FIxing Media Keys and general USB compatibilty
Jacob Alexander <haata@kiibohd.com>
parents:
347
diff
changeset
|
607 if ( list->addr == NULL ) |
06a54d582bf8
FIxing Media Keys and general USB compatibilty
Jacob Alexander <haata@kiibohd.com>
parents:
347
diff
changeset
|
608 break; |
06a54d582bf8
FIxing Media Keys and general USB compatibilty
Jacob Alexander <haata@kiibohd.com>
parents:
347
diff
changeset
|
609 if ( list->wValue != 0x2200 ) |
06a54d582bf8
FIxing Media Keys and general USB compatibilty
Jacob Alexander <haata@kiibohd.com>
parents:
347
diff
changeset
|
610 continue; |
06a54d582bf8
FIxing Media Keys and general USB compatibilty
Jacob Alexander <haata@kiibohd.com>
parents:
347
diff
changeset
|
611 if ( setup.wIndex == list->wIndex ) |
06a54d582bf8
FIxing Media Keys and general USB compatibilty
Jacob Alexander <haata@kiibohd.com>
parents:
347
diff
changeset
|
612 { |
06a54d582bf8
FIxing Media Keys and general USB compatibilty
Jacob Alexander <haata@kiibohd.com>
parents:
347
diff
changeset
|
613 data = list->addr; |
06a54d582bf8
FIxing Media Keys and general USB compatibilty
Jacob Alexander <haata@kiibohd.com>
parents:
347
diff
changeset
|
614 datalen = list->length; |
06a54d582bf8
FIxing Media Keys and general USB compatibilty
Jacob Alexander <haata@kiibohd.com>
parents:
347
diff
changeset
|
615 goto send; |
06a54d582bf8
FIxing Media Keys and general USB compatibilty
Jacob Alexander <haata@kiibohd.com>
parents:
347
diff
changeset
|
616 } |
449
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
617 } |
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
618 endpoint0_stall(); |
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
619 return; |
231
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
620 |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
621 case 0x0A21: // HID SET_IDLE |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
622 #ifdef UART_DEBUG |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
623 print("SET_IDLE - "); |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
624 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
|
625 print(" - "); |
56237ba5da6f
Adding auto-restart support whenever USB gets into an odd state
Jacob Alexander <haata@kiibohd.com>
parents:
439
diff
changeset
|
626 printHex( setup.wValue >> 8 ); |
231
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
627 print(NL); |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
628 #endif |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
629 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
|
630 USBKeys_Idle_Expiry = 0; |
368
06a54d582bf8
FIxing Media Keys and general USB compatibilty
Jacob Alexander <haata@kiibohd.com>
parents:
347
diff
changeset
|
631 goto send; |
231
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
632 |
447
56237ba5da6f
Adding auto-restart support whenever USB gets into an odd state
Jacob Alexander <haata@kiibohd.com>
parents:
439
diff
changeset
|
633 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
|
634 #ifdef UART_DEBUG |
56237ba5da6f
Adding auto-restart support whenever USB gets into an odd state
Jacob Alexander <haata@kiibohd.com>
parents:
439
diff
changeset
|
635 print("SET_IDLE - "); |
56237ba5da6f
Adding auto-restart support whenever USB gets into an odd state
Jacob Alexander <haata@kiibohd.com>
parents:
439
diff
changeset
|
636 printHex( setup.wValue ); |
56237ba5da6f
Adding auto-restart support whenever USB gets into an odd state
Jacob Alexander <haata@kiibohd.com>
parents:
439
diff
changeset
|
637 print(" - "); |
56237ba5da6f
Adding auto-restart support whenever USB gets into an odd state
Jacob Alexander <haata@kiibohd.com>
parents:
439
diff
changeset
|
638 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
|
639 print(NL); |
56237ba5da6f
Adding auto-restart support whenever USB gets into an odd state
Jacob Alexander <haata@kiibohd.com>
parents:
439
diff
changeset
|
640 #endif |
56237ba5da6f
Adding auto-restart support whenever USB gets into an odd state
Jacob Alexander <haata@kiibohd.com>
parents:
439
diff
changeset
|
641 reply_buffer[0] = USBKeys_Idle_Config; |
449
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
642 data = reply_buffer; |
447
56237ba5da6f
Adding auto-restart support whenever USB gets into an odd state
Jacob Alexander <haata@kiibohd.com>
parents:
439
diff
changeset
|
643 datalen = 1; |
56237ba5da6f
Adding auto-restart support whenever USB gets into an odd state
Jacob Alexander <haata@kiibohd.com>
parents:
439
diff
changeset
|
644 goto send; |
56237ba5da6f
Adding auto-restart support whenever USB gets into an odd state
Jacob Alexander <haata@kiibohd.com>
parents:
439
diff
changeset
|
645 |
56237ba5da6f
Adding auto-restart support whenever USB gets into an odd state
Jacob Alexander <haata@kiibohd.com>
parents:
439
diff
changeset
|
646 |
231
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
647 case 0x0B21: // HID SET_PROTOCOL |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
648 #ifdef UART_DEBUG |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
649 print("SET_PROTOCOL - "); |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
650 printHex( setup.wValue ); |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
651 print(" - "); |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
652 printHex( setup.wValue & 0xFF ); |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
653 print(NL); |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
654 #endif |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
655 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
|
656 goto send; |
231
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
657 |
438
f10c2dad7f55
Adding missing GET_PROTOCOL handling
Jacob Alexander <haata@kiibohd.com>
parents:
420
diff
changeset
|
658 case 0x03A1: /// HID GET_PROTOCOL |
f10c2dad7f55
Adding missing GET_PROTOCOL handling
Jacob Alexander <haata@kiibohd.com>
parents:
420
diff
changeset
|
659 #ifdef UART_DEBUG |
f10c2dad7f55
Adding missing GET_PROTOCOL handling
Jacob Alexander <haata@kiibohd.com>
parents:
420
diff
changeset
|
660 print("GET_PROTOCOL - "); |
f10c2dad7f55
Adding missing GET_PROTOCOL handling
Jacob Alexander <haata@kiibohd.com>
parents:
420
diff
changeset
|
661 printHex( setup.wValue ); |
f10c2dad7f55
Adding missing GET_PROTOCOL handling
Jacob Alexander <haata@kiibohd.com>
parents:
420
diff
changeset
|
662 print(" - "); |
f10c2dad7f55
Adding missing GET_PROTOCOL handling
Jacob Alexander <haata@kiibohd.com>
parents:
420
diff
changeset
|
663 printHex( USBKeys_Protocol ); |
f10c2dad7f55
Adding missing GET_PROTOCOL handling
Jacob Alexander <haata@kiibohd.com>
parents:
420
diff
changeset
|
664 print(NL); |
f10c2dad7f55
Adding missing GET_PROTOCOL handling
Jacob Alexander <haata@kiibohd.com>
parents:
420
diff
changeset
|
665 #endif |
f10c2dad7f55
Adding missing GET_PROTOCOL handling
Jacob Alexander <haata@kiibohd.com>
parents:
420
diff
changeset
|
666 reply_buffer[0] = USBKeys_Protocol; |
449
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
667 data = reply_buffer; |
438
f10c2dad7f55
Adding missing GET_PROTOCOL handling
Jacob Alexander <haata@kiibohd.com>
parents:
420
diff
changeset
|
668 datalen = 1; |
f10c2dad7f55
Adding missing GET_PROTOCOL handling
Jacob Alexander <haata@kiibohd.com>
parents:
420
diff
changeset
|
669 goto send; |
f10c2dad7f55
Adding missing GET_PROTOCOL handling
Jacob Alexander <haata@kiibohd.com>
parents:
420
diff
changeset
|
670 |
231
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
671 // case 0xC940: |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
672 default: |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
673 #ifdef UART_DEBUG_UNKNOWN |
449
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
674 print("UNKNOWN: "); |
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
675 printInt32( systick_millis_count - USBInit_TimeStart ); |
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
676 print(" ms"); |
438
f10c2dad7f55
Adding missing GET_PROTOCOL handling
Jacob Alexander <haata@kiibohd.com>
parents:
420
diff
changeset
|
677 print(NL); |
231
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
678 #endif |
104
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
679 endpoint0_stall(); |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
680 return; |
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 |
231
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
683 send: |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
684 #ifdef UART_DEBUG |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
685 print("setup send "); |
368
06a54d582bf8
FIxing Media Keys and general USB compatibilty
Jacob Alexander <haata@kiibohd.com>
parents:
347
diff
changeset
|
686 printHex32( (uint32_t)data ); |
231
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
687 print(","); |
368
06a54d582bf8
FIxing Media Keys and general USB compatibilty
Jacob Alexander <haata@kiibohd.com>
parents:
347
diff
changeset
|
688 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
|
689 { |
06a54d582bf8
FIxing Media Keys and general USB compatibilty
Jacob Alexander <haata@kiibohd.com>
parents:
347
diff
changeset
|
690 printHex( data[c] ); |
06a54d582bf8
FIxing Media Keys and general USB compatibilty
Jacob Alexander <haata@kiibohd.com>
parents:
347
diff
changeset
|
691 print(" "); |
06a54d582bf8
FIxing Media Keys and general USB compatibilty
Jacob Alexander <haata@kiibohd.com>
parents:
347
diff
changeset
|
692 } |
06a54d582bf8
FIxing Media Keys and general USB compatibilty
Jacob Alexander <haata@kiibohd.com>
parents:
347
diff
changeset
|
693 print(","); |
06a54d582bf8
FIxing Media Keys and general USB compatibilty
Jacob Alexander <haata@kiibohd.com>
parents:
347
diff
changeset
|
694 printHex( datalen ); |
06a54d582bf8
FIxing Media Keys and general USB compatibilty
Jacob Alexander <haata@kiibohd.com>
parents:
347
diff
changeset
|
695 print( NL ); |
231
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
696 #endif |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
697 |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
698 if ( datalen > setup.wLength ) |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
699 datalen = setup.wLength; |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
700 |
104
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
701 size = datalen; |
231
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
702 if ( size > EP0_SIZE ) |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
703 size = EP0_SIZE; |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
704 |
449
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
705 endpoint0_transmit( data, size ); |
104
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
706 data += size; |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
707 datalen -= size; |
231
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
708 |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
709 // See if transmit has finished |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
710 if ( datalen == 0 && size < EP0_SIZE ) |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
711 return; |
104
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
712 |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
713 size = datalen; |
231
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
714 if ( size > EP0_SIZE ) |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
715 size = EP0_SIZE; |
449
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
716 endpoint0_transmit( data, size ); |
104
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
717 data += size; |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
718 datalen -= size; |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
719 |
231
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
720 // See if transmit has finished |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
721 if ( datalen == 0 && size < EP0_SIZE ) |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
722 return; |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
723 |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
724 // 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
|
725 ep0_tx_ptr = data; |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
726 ep0_tx_len = datalen; |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
727 } |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
728 |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
729 |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
730 //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
|
731 //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
|
732 //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
|
733 |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
734 //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
|
735 //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
|
736 //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
|
737 //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
|
738 |
449
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
739 // For endpoints using data toggle, regardless of whether an endpoint has the |
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
740 // Halt feature set, a ClearFeature(ENDPOINT_HALT) request always results in the |
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
741 // data toggle being reinitialized to DATA0. |
104
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
742 |
231
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
743 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
|
744 { |
231
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
745 #ifdef UART_DEBUG |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
746 print("CONTROL - "); |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
747 #endif |
104
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
748 bdt_t *b; |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
749 uint32_t pid, size; |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
750 uint8_t *buf; |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
751 const uint8_t *data; |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
752 |
231
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
753 b = stat2bufferdescriptor( stat ); |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
754 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
|
755 buf = b->addr; |
231
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
756 #ifdef UART_DEBUG |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
757 print("pid:"); |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
758 printHex(pid); |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
759 print(", count:"); |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
760 printHex32(b->desc); |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
761 print(" - "); |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
762 #endif |
104
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
763 |
449
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
764 switch ( pid ) |
231
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
765 { |
104
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
766 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
|
767 // 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
|
768 setup.word1 = *(uint32_t *)(buf); |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
769 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
|
770 |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
771 // give the buffer back |
231
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
772 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
|
773 //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
|
774 //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
|
775 |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
776 // 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
|
777 ep0_tx_ptr = NULL; |
231
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
778 if ( ep0_tx_data_toggle ) |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
779 { |
104
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
780 } |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
781 //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
|
782 //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
|
783 //} |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
784 //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
|
785 //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
|
786 //} |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
787 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
|
788 table[index(0, TX, ODD)].desc = 0; |
449
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
789 |
104
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
790 // 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
|
791 ep0_tx_data_toggle = 1; |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
792 |
231
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
793 #ifdef UART_DEBUG_UNKNOWN |
449
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
794 printHex( stat ); |
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
795 print(" PID=SETUP wRequestAndType:"); |
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
796 printHex(setup.wRequestAndType); |
231
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
797 print(", wValue:"); |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
798 printHex(setup.wValue); |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
799 print(", wIndex:"); |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
800 printHex(setup.wIndex); |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
801 print(", len:"); |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
802 printHex(setup.wLength); |
383
801e7628d977
Fixing long-standing SET_REPORT bug
Jacob Alexander <haata@kiibohd.com>
parents:
381
diff
changeset
|
803 print(" -- "); |
801e7628d977
Fixing long-standing SET_REPORT bug
Jacob Alexander <haata@kiibohd.com>
parents:
381
diff
changeset
|
804 printHex32(setup.word1); |
801e7628d977
Fixing long-standing SET_REPORT bug
Jacob Alexander <haata@kiibohd.com>
parents:
381
diff
changeset
|
805 print(" "); |
801e7628d977
Fixing long-standing SET_REPORT bug
Jacob Alexander <haata@kiibohd.com>
parents:
381
diff
changeset
|
806 printHex32(setup.word2); |
449
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
807 print(": "); |
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
808 printInt32( systick_millis_count - USBInit_TimeStart ); |
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
809 print(" ms"); |
231
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
810 print(NL); |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
811 #endif |
449
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
812 |
104
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
813 // 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
|
814 usb_setup(); |
104
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
815 // 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
|
816 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
|
817 break; |
368
06a54d582bf8
FIxing Media Keys and general USB compatibilty
Jacob Alexander <haata@kiibohd.com>
parents:
347
diff
changeset
|
818 |
104
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
819 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
|
820 case 0x02: |
383
801e7628d977
Fixing long-standing SET_REPORT bug
Jacob Alexander <haata@kiibohd.com>
parents:
381
diff
changeset
|
821 #ifdef UART_DEBUG_UNKNOWN |
449
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
822 printHex( stat ); |
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
823 print(" PID=OUT wRequestAndType:"); |
383
801e7628d977
Fixing long-standing SET_REPORT bug
Jacob Alexander <haata@kiibohd.com>
parents:
381
diff
changeset
|
824 printHex(setup.wRequestAndType); |
801e7628d977
Fixing long-standing SET_REPORT bug
Jacob Alexander <haata@kiibohd.com>
parents:
381
diff
changeset
|
825 print(", wValue:"); |
801e7628d977
Fixing long-standing SET_REPORT bug
Jacob Alexander <haata@kiibohd.com>
parents:
381
diff
changeset
|
826 printHex(setup.wValue); |
801e7628d977
Fixing long-standing SET_REPORT bug
Jacob Alexander <haata@kiibohd.com>
parents:
381
diff
changeset
|
827 print(", wIndex:"); |
801e7628d977
Fixing long-standing SET_REPORT bug
Jacob Alexander <haata@kiibohd.com>
parents:
381
diff
changeset
|
828 printHex(setup.wIndex); |
801e7628d977
Fixing long-standing SET_REPORT bug
Jacob Alexander <haata@kiibohd.com>
parents:
381
diff
changeset
|
829 print(", len:"); |
801e7628d977
Fixing long-standing SET_REPORT bug
Jacob Alexander <haata@kiibohd.com>
parents:
381
diff
changeset
|
830 printHex(setup.wLength); |
801e7628d977
Fixing long-standing SET_REPORT bug
Jacob Alexander <haata@kiibohd.com>
parents:
381
diff
changeset
|
831 print(" -- "); |
801e7628d977
Fixing long-standing SET_REPORT bug
Jacob Alexander <haata@kiibohd.com>
parents:
381
diff
changeset
|
832 printHex32(setup.word1); |
801e7628d977
Fixing long-standing SET_REPORT bug
Jacob Alexander <haata@kiibohd.com>
parents:
381
diff
changeset
|
833 print(" "); |
801e7628d977
Fixing long-standing SET_REPORT bug
Jacob Alexander <haata@kiibohd.com>
parents:
381
diff
changeset
|
834 printHex32(setup.word2); |
449
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
835 print(": "); |
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
836 printInt32( systick_millis_count - USBInit_TimeStart ); |
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
837 print(" ms"); |
383
801e7628d977
Fixing long-standing SET_REPORT bug
Jacob Alexander <haata@kiibohd.com>
parents:
381
diff
changeset
|
838 print(NL); |
231
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
839 #endif |
383
801e7628d977
Fixing long-standing SET_REPORT bug
Jacob Alexander <haata@kiibohd.com>
parents:
381
diff
changeset
|
840 |
231
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
841 // CDC Interface |
449
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
842 #if enableVirtualSerialPort_define == 1 |
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
843 // CDC_SET_LINE_CODING - PID=OUT |
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
844 // XXX - Getting lots of NAKs in Linux |
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
845 if ( setup.wRequestAndType == 0x2021 ) |
231
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
846 { |
449
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
847 // Copy over new line coding |
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
848 memcpy( (void*)&usb_cdc_line_coding, buf, 7 ); |
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
849 |
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
850 #ifdef UART_DEBUG |
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
851 // - Unused, but for the readers info - |
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
852 print("dwDTERate("); |
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
853 printInt32( usb_cdc_line_coding.dwDTERate ); |
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
854 print(")bCharFormat("); |
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
855 printHex( usb_cdc_line_coding.bCharFormat ); |
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
856 print(")bParityType("); |
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
857 printHex( usb_cdc_line_coding.bParityType ); |
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
858 print(")bDataBits("); |
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
859 printHex( usb_cdc_line_coding.bDataBits ); |
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
860 print(")"); |
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
861 print( NL ); |
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
862 #endif |
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
863 |
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
864 // XXX ZLP causes timeout/delay, why? -HaaTa |
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
865 //endpoint0_transmit( NULL, 0 ); |
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
866 } |
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
867 #endif |
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
868 |
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
869 // Keyboard HID SET_REPORT - PID=OUT |
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
870 #if enableKeyboard_define == 1 |
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
871 // XXX - Getting lots of NAKs in Linux |
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
872 if ( setup.wRequestAndType == 0x0921 && setup.wValue & 0x200 ) |
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
873 { |
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
874 #ifdef UART_DEBUG |
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
875 print("report_type("); |
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
876 printHex( setup.wValue >> 8 ); |
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
877 print(")report_id("); |
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
878 printHex( setup.wValue & 0xFF ); |
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
879 print(")interface("); |
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
880 printHex( setup.wIndex ); |
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
881 print(")len("); |
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
882 printHex( setup.wLength ); |
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
883 print(")["); |
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
884 |
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
885 for ( size_t len = 0; len < setup.wLength; len++ ) |
231
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
886 { |
449
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
887 printHex( buf[ len ] ); |
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
888 print(" "); |
104
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
889 } |
449
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
890 print("]"); |
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
891 print( NL ); |
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
892 #endif |
231
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
893 |
383
801e7628d977
Fixing long-standing SET_REPORT bug
Jacob Alexander <haata@kiibohd.com>
parents:
381
diff
changeset
|
894 // Interface |
801e7628d977
Fixing long-standing SET_REPORT bug
Jacob Alexander <haata@kiibohd.com>
parents:
381
diff
changeset
|
895 switch ( setup.wIndex & 0xFF ) |
801e7628d977
Fixing long-standing SET_REPORT bug
Jacob Alexander <haata@kiibohd.com>
parents:
381
diff
changeset
|
896 { |
801e7628d977
Fixing long-standing SET_REPORT bug
Jacob Alexander <haata@kiibohd.com>
parents:
381
diff
changeset
|
897 // Keyboard Interface |
801e7628d977
Fixing long-standing SET_REPORT bug
Jacob Alexander <haata@kiibohd.com>
parents:
381
diff
changeset
|
898 case KEYBOARD_INTERFACE: |
801e7628d977
Fixing long-standing SET_REPORT bug
Jacob Alexander <haata@kiibohd.com>
parents:
381
diff
changeset
|
899 USBKeys_LEDs = buf[0]; |
801e7628d977
Fixing long-standing SET_REPORT bug
Jacob Alexander <haata@kiibohd.com>
parents:
381
diff
changeset
|
900 break; |
801e7628d977
Fixing long-standing SET_REPORT bug
Jacob Alexander <haata@kiibohd.com>
parents:
381
diff
changeset
|
901 // NKRO Keyboard Interface |
801e7628d977
Fixing long-standing SET_REPORT bug
Jacob Alexander <haata@kiibohd.com>
parents:
381
diff
changeset
|
902 case NKRO_KEYBOARD_INTERFACE: |
449
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
903 // Already set with the control sequence |
383
801e7628d977
Fixing long-standing SET_REPORT bug
Jacob Alexander <haata@kiibohd.com>
parents:
381
diff
changeset
|
904 // 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
|
905 USBKeys_LEDs = buf[1]; |
801e7628d977
Fixing long-standing SET_REPORT bug
Jacob Alexander <haata@kiibohd.com>
parents:
381
diff
changeset
|
906 break; |
801e7628d977
Fixing long-standing SET_REPORT bug
Jacob Alexander <haata@kiibohd.com>
parents:
381
diff
changeset
|
907 default: |
801e7628d977
Fixing long-standing SET_REPORT bug
Jacob Alexander <haata@kiibohd.com>
parents:
381
diff
changeset
|
908 warn_msg("Unknown interface - "); |
801e7628d977
Fixing long-standing SET_REPORT bug
Jacob Alexander <haata@kiibohd.com>
parents:
381
diff
changeset
|
909 printHex( setup.wIndex ); |
801e7628d977
Fixing long-standing SET_REPORT bug
Jacob Alexander <haata@kiibohd.com>
parents:
381
diff
changeset
|
910 print( NL ); |
801e7628d977
Fixing long-standing SET_REPORT bug
Jacob Alexander <haata@kiibohd.com>
parents:
381
diff
changeset
|
911 break; |
801e7628d977
Fixing long-standing SET_REPORT bug
Jacob Alexander <haata@kiibohd.com>
parents:
381
diff
changeset
|
912 } |
801e7628d977
Fixing long-standing SET_REPORT bug
Jacob Alexander <haata@kiibohd.com>
parents:
381
diff
changeset
|
913 |
449
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
914 // XXX ZLP causes timeout/delay, why? -HaaTa |
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
915 //endpoint0_transmit( NULL, 0 ); |
231
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
916 } |
449
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
917 #endif |
231
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
918 |
104
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
919 // give the buffer back |
231
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
920 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
|
921 break; |
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 case 0x09: // IN transaction completed to host |
449
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
924 data = ep0_tx_ptr; |
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
925 |
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
926 #ifdef UART_DEBUG_UNKNOWN |
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
927 printHex( stat ); |
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
928 print(" PID=IN wRequestAndType:"); |
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
929 printHex(setup.wRequestAndType); |
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
930 print(", wValue:"); |
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
931 printHex(setup.wValue); |
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
932 print(", wIndex:"); |
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
933 printHex(setup.wIndex); |
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
934 print(", len:"); |
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
935 printHex(setup.wLength); |
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
936 print(" -- "); |
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
937 printHex32(setup.word1); |
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
938 print(" "); |
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
939 printHex32(setup.word2); |
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
940 print(": "); |
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
941 printInt32( systick_millis_count - USBInit_TimeStart ); |
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
942 print(" ms"); |
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
943 if ( data ) print(" DATA "); |
231
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
944 print(NL); |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
945 #endif |
104
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
946 |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
947 // send remaining data, if any... |
231
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
948 if ( data ) |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
949 { |
104
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
950 size = ep0_tx_len; |
449
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
951 if (size > EP0_SIZE) |
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
952 { |
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
953 size = EP0_SIZE; |
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
954 } |
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
955 endpoint0_transmit( data, size ); |
104
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
956 data += size; |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
957 ep0_tx_len -= size; |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
958 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
|
959 } |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
960 |
231
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
961 if ( setup.bRequest == 5 && setup.bmRequestType == 0 ) |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
962 { |
104
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
963 setup.bRequest = 0; |
231
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
964 #ifdef UART_DEBUG |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
965 print("set address: "); |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
966 printHex(setup.wValue); |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
967 print(NL); |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
968 #endif |
104
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
969 USB0_ADDR = setup.wValue; |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
970 } |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
971 |
449
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
972 // CDC_SET_LINE_CODING - PID=IN |
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
973 #if enableVirtualSerialPort_define == 1 |
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
974 if ( setup.wRequestAndType == 0x2021 ) |
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
975 { |
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
976 // XXX ZLP causes timeout/delay, why? -HaaTa |
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
977 //endpoint0_transmit( NULL, 0 ); |
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
978 } |
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
979 #endif |
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
980 |
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
981 // Keyboard HID SET_REPORT - PID=IN |
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
982 #if enableKeyboard_define == 1 |
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
983 // XXX - Getting lots of NAKs in Linux |
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
984 if ( setup.wRequestAndType == 0x0921 && setup.wValue & 0x200 ) |
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
985 { |
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
986 // XXX ZLP causes timeout/delay, why? -HaaTa |
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
987 //endpoint0_transmit( NULL, 0 ); |
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
988 } |
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
989 #endif |
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
990 |
104
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
991 break; |
368
06a54d582bf8
FIxing Media Keys and general USB compatibilty
Jacob Alexander <haata@kiibohd.com>
parents:
347
diff
changeset
|
992 |
231
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
993 default: |
449
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
994 #ifdef UART_DEBUG_UNKNOWN |
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
995 print("PID=unknown: "); |
231
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
996 printHex(pid); |
449
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
997 print(": "); |
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
998 printInt32( systick_millis_count - USBInit_TimeStart ); |
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
999 print(" ms"); |
231
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
1000 print(NL); |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
1001 #endif |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
1002 break; |
104
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1003 } |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1004 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
|
1005 } |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1006 |
231
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
1007 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
|
1008 { |
175 | 1009 //print("USB RX"); |
104
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1010 usb_packet_t *ret; |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1011 endpoint--; |
449
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
1012 |
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
1013 // Make sure this is a valid endpoint |
231
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
1014 if ( endpoint >= NUM_ENDPOINTS ) |
449
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
1015 { |
231
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
1016 return NULL; |
449
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
1017 } |
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
1018 |
104
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1019 __disable_irq(); |
449
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
1020 |
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
1021 // Receive packet, check pointer |
104
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1022 ret = rx_first[endpoint]; |
231
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
1023 if ( ret ) |
449
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
1024 { |
231
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
1025 rx_first[ endpoint ] = ret->next; |
449
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
1026 usb_rx_byte_count_data[ endpoint ] -= ret->len; |
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
1027 } |
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
1028 |
104
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1029 __enable_irq(); |
449
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
1030 |
104
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1031 //serial_print("rx, epidx="); |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1032 //serial_phex(endpoint); |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1033 //serial_print(", packet="); |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1034 //serial_phex32(ret); |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1035 //serial_print("\n"); |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1036 return ret; |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1037 } |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1038 |
231
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
1039 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
|
1040 { |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1041 uint32_t count=0; |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1042 |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1043 __disable_irq(); |
231
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
1044 for ( ; p; p = p->next ) |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
1045 { |
104
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1046 count += p->len; |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1047 } |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1048 __enable_irq(); |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1049 return count; |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1050 } |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1051 |
231
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
1052 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
|
1053 { |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1054 endpoint--; |
231
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
1055 if ( endpoint >= NUM_ENDPOINTS ) |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
1056 return 0; |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
1057 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
|
1058 } |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1059 |
231
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
1060 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
|
1061 { |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1062 const usb_packet_t *p; |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1063 uint32_t count=0; |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1064 |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1065 endpoint--; |
231
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
1066 if ( endpoint >= NUM_ENDPOINTS ) |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
1067 return 0; |
104
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1068 __disable_irq(); |
231
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
1069 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
|
1070 count++; |
104
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1071 __enable_irq(); |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1072 return count; |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1073 } |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1074 |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1075 |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1076 // 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
|
1077 // 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
|
1078 // 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
|
1079 // 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
|
1080 // 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
|
1081 // 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
|
1082 // first endpoint needing memory. |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1083 // |
231
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
1084 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
|
1085 { |
175 | 1086 //print("USB RX MEMORY"); |
104
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1087 unsigned int i; |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1088 const uint8_t *cfg; |
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 cfg = usb_endpoint_config_table; |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1091 //serial_print("rx_mem:"); |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1092 __disable_irq(); |
250
afe96322d0c5
Code formatting cleanup.
Jacob Alexander <haata@kiibohd.com>
parents:
231
diff
changeset
|
1093 for ( i = 1; i <= NUM_ENDPOINTS; i++ ) |
afe96322d0c5
Code formatting cleanup.
Jacob Alexander <haata@kiibohd.com>
parents:
231
diff
changeset
|
1094 { |
afe96322d0c5
Code formatting cleanup.
Jacob Alexander <haata@kiibohd.com>
parents:
231
diff
changeset
|
1095 if ( *cfg++ & USB_ENDPT_EPRXEN ) |
afe96322d0c5
Code formatting cleanup.
Jacob Alexander <haata@kiibohd.com>
parents:
231
diff
changeset
|
1096 { |
231
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
1097 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
|
1098 { |
250
afe96322d0c5
Code formatting cleanup.
Jacob Alexander <haata@kiibohd.com>
parents:
231
diff
changeset
|
1099 table[ index( i, RX, EVEN ) ].addr = packet->buf; |
afe96322d0c5
Code formatting cleanup.
Jacob Alexander <haata@kiibohd.com>
parents:
231
diff
changeset
|
1100 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
|
1101 usb_rx_memory_needed--; |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1102 __enable_irq(); |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1103 //serial_phex(i); |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1104 //serial_print(",even\n"); |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1105 return; |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1106 } |
231
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
1107 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
|
1108 { |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
1109 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
|
1110 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
|
1111 usb_rx_memory_needed--; |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1112 __enable_irq(); |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1113 //serial_phex(i); |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1114 //serial_print(",odd\n"); |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1115 return; |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1116 } |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1117 } |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1118 } |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1119 __enable_irq(); |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1120 // 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
|
1121 // usb_rx_memory_needed was set greater than zero, but no memory |
175 | 1122 // was actually needed. |
104
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1123 usb_rx_memory_needed = 0; |
231
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
1124 usb_free( packet ); |
104
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1125 return; |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1126 } |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1127 |
449
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
1128 // Call whenever there's an action that may wake the host device |
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
1129 void usb_resume() |
104
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1130 { |
439
68e19d7c953e
Adding proper remote wake-up support
Jacob Alexander <haata@kiibohd.com>
parents:
438
diff
changeset
|
1131 // If we have been sleeping, try to wake up host |
449
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
1132 if ( usb_dev_sleep && usb_configured() ) |
439
68e19d7c953e
Adding proper remote wake-up support
Jacob Alexander <haata@kiibohd.com>
parents:
438
diff
changeset
|
1133 { |
449
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
1134 #if enableUSBResume_define == 1 |
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
1135 #if enableVirtualSerialPort_define != 1 |
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
1136 info_print("Attempting to resume the host"); |
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
1137 #endif |
439
68e19d7c953e
Adding proper remote wake-up support
Jacob Alexander <haata@kiibohd.com>
parents:
438
diff
changeset
|
1138 // Force wake-up for 10 ms |
68e19d7c953e
Adding proper remote wake-up support
Jacob Alexander <haata@kiibohd.com>
parents:
438
diff
changeset
|
1139 // 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
|
1140 USB0_CTL |= USB_CTL_RESUME; |
68e19d7c953e
Adding proper remote wake-up support
Jacob Alexander <haata@kiibohd.com>
parents:
438
diff
changeset
|
1141 delay(10); |
68e19d7c953e
Adding proper remote wake-up support
Jacob Alexander <haata@kiibohd.com>
parents:
438
diff
changeset
|
1142 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
|
1143 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
|
1144 usb_dev_sleep = 0; // Make sure we don't call this again, may crash system |
449
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
1145 #else |
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
1146 warn_print("Host Resume Disabled"); |
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
1147 #endif |
439
68e19d7c953e
Adding proper remote wake-up support
Jacob Alexander <haata@kiibohd.com>
parents:
438
diff
changeset
|
1148 } |
68e19d7c953e
Adding proper remote wake-up support
Jacob Alexander <haata@kiibohd.com>
parents:
438
diff
changeset
|
1149 |
449
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
1150 } |
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
1151 |
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
1152 void usb_tx( uint32_t endpoint, usb_packet_t *packet ) |
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
1153 { |
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
1154 // Update expiry counter |
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
1155 USBKeys_Idle_Expiry = systick_millis_count; |
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
1156 |
420
23a1868b4ac2
Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents:
385
diff
changeset
|
1157 // 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
|
1158 // if it's in that state |
23a1868b4ac2
Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents:
385
diff
changeset
|
1159 // Use the currently set descriptor value |
23a1868b4ac2
Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents:
385
diff
changeset
|
1160 Output_update_usb_current( *usb_bMaxPower * 2 ); |
23a1868b4ac2
Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents:
385
diff
changeset
|
1161 |
231
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
1162 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
|
1163 uint8_t next; |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1164 |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1165 endpoint--; |
231
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
1166 if ( endpoint >= NUM_ENDPOINTS ) |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
1167 return; |
104
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1168 __disable_irq(); |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1169 //serial_print("txstate="); |
231
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
1170 //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
|
1171 //serial_print("\n"); |
231
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
1172 switch ( tx_state[ endpoint ] ) |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
1173 { |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
1174 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
|
1175 next = TX_STATE_ODD_FREE; |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1176 break; |
231
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
1177 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
|
1178 b++; |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1179 next = TX_STATE_EVEN_FREE; |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1180 break; |
231
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
1181 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
|
1182 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
|
1183 break; |
231
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
1184 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
|
1185 b++; |
117
5ffefdf89b37
Adding in USB module updates from Teensyduino 1.18rc2.
Jacob Alexander <haata@kiibohd.com>
parents:
109
diff
changeset
|
1186 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
|
1187 break; |
231
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
1188 default: |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
1189 if (tx_first[ endpoint ] == NULL) |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
1190 { |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
1191 tx_first[ endpoint ] = packet; |
104
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1192 } |
231
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
1193 else |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
1194 { |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
1195 tx_last[ endpoint ]->next = packet; |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
1196 } |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
1197 tx_last[ endpoint ] = packet; |
104
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1198 __enable_irq(); |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1199 return; |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1200 } |
231
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
1201 |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
1202 tx_state[ endpoint ] = next; |
104
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1203 b->addr = packet->buf; |
231
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
1204 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
|
1205 __enable_irq(); |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1206 } |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1207 |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1208 |
109
2c1a9e6ae70e
Added more CLI commands.
Jacob Alexander <haata@kiibohd.com>
parents:
104
diff
changeset
|
1209 void usb_device_reload() |
2c1a9e6ae70e
Added more CLI commands.
Jacob Alexander <haata@kiibohd.com>
parents:
104
diff
changeset
|
1210 { |
177
3420e018ffbc
Adding McHCK flash reload function and some cleanup.
Jacob Alexander <haata@kiibohd.com>
parents:
175
diff
changeset
|
1211 // MCHCK |
347
136e47478441
UARTConnect enumeration working!
Jacob Alexander <haata@kiibohd.com>
parents:
346
diff
changeset
|
1212 // Kiibohd mk20dx256vlh7 |
385
d8f61e15aca1
Adding jump to bootloader key
Jacob Alexander <haata@kiibohd.com>
parents:
383
diff
changeset
|
1213 #if defined(_mk20dx128vlf5_) || defined(_mk20dx256vlh7_) |
347
136e47478441
UARTConnect enumeration working!
Jacob Alexander <haata@kiibohd.com>
parents:
346
diff
changeset
|
1214 // 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
|
1215 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
|
1216 (&VBAT)[ pos ] = sys_reset_to_loader_magic[ pos ]; |
136e47478441
UARTConnect enumeration working!
Jacob Alexander <haata@kiibohd.com>
parents:
346
diff
changeset
|
1217 SOFTWARE_RESET(); |
136e47478441
UARTConnect enumeration working!
Jacob Alexander <haata@kiibohd.com>
parents:
346
diff
changeset
|
1218 |
177
3420e018ffbc
Adding McHCK flash reload function and some cleanup.
Jacob Alexander <haata@kiibohd.com>
parents:
175
diff
changeset
|
1219 // Teensy 3.0 and 3.1 |
3420e018ffbc
Adding McHCK flash reload function and some cleanup.
Jacob Alexander <haata@kiibohd.com>
parents:
175
diff
changeset
|
1220 #else |
109
2c1a9e6ae70e
Added more CLI commands.
Jacob Alexander <haata@kiibohd.com>
parents:
104
diff
changeset
|
1221 asm volatile("bkpt"); |
177
3420e018ffbc
Adding McHCK flash reload function and some cleanup.
Jacob Alexander <haata@kiibohd.com>
parents:
175
diff
changeset
|
1222 #endif |
109
2c1a9e6ae70e
Added more CLI commands.
Jacob Alexander <haata@kiibohd.com>
parents:
104
diff
changeset
|
1223 } |
104
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1224 |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1225 |
175 | 1226 void usb_isr() |
104
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1227 { |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1228 uint8_t status, stat, t; |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1229 |
250
afe96322d0c5
Code formatting cleanup.
Jacob Alexander <haata@kiibohd.com>
parents:
231
diff
changeset
|
1230 restart: |
104
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1231 status = USB0_ISTAT; |
175 | 1232 /* |
449
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
1233 print(" ISR("); |
175 | 1234 printHex( status ); |
449
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
1235 print(") "); |
175 | 1236 */ |
104
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1237 |
231
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
1238 if ( (status & USB_INTEN_SOFTOKEN /* 04 */ ) ) |
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 if ( usb_configuration ) |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
1241 { |
104
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1242 t = usb_reboot_timer; |
231
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
1243 if ( t ) |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
1244 { |
104
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1245 usb_reboot_timer = --t; |
231
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
1246 if ( !t ) |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
1247 usb_device_reload(); |
104
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1248 } |
231
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
1249 |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
1250 // CDC Interface |
449
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
1251 #if enableVirtualSerialPort_define == 1 |
104
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1252 t = usb_cdc_transmit_flush_timer; |
231
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
1253 if ( t ) |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
1254 { |
104
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1255 usb_cdc_transmit_flush_timer = --t; |
231
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
1256 if ( t == 0 ) |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
1257 usb_serial_flush_callback(); |
104
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1258 } |
449
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
1259 #endif |
231
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
1260 |
104
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 USB0_ISTAT = USB_INTEN_SOFTOKEN; |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1263 } |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1264 |
231
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
1265 if ( (status & USB_ISTAT_TOKDNE /* 08 */ ) ) |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
1266 { |
104
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1267 uint8_t endpoint; |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1268 stat = USB0_STAT; |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1269 //serial_print("token: ep="); |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1270 //serial_phex(stat >> 4); |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1271 //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
|
1272 //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
|
1273 endpoint = stat >> 4; |
231
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
1274 if ( endpoint == 0 ) |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
1275 { |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
1276 usb_control( stat ); |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
1277 } |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
1278 else |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
1279 { |
104
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1280 bdt_t *b = stat2bufferdescriptor(stat); |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1281 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
|
1282 #if 0 |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1283 serial_print("ep:"); |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1284 serial_phex(endpoint); |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1285 serial_print(", pid:"); |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1286 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
|
1287 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
|
1288 serial_print(", count:"); |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1289 serial_phex(b->desc >> 16); |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1290 serial_print("\n"); |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1291 #endif |
326
05a09eda53fb
Inital Remote Wakeup Support
Rowan Decker <Smasher816@gmail.com>
parents:
302
diff
changeset
|
1292 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
|
1293 |
231
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
1294 if ( stat & 0x08 ) |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
1295 { // transmit |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
1296 usb_free( packet ); |
250
afe96322d0c5
Code formatting cleanup.
Jacob Alexander <haata@kiibohd.com>
parents:
231
diff
changeset
|
1297 packet = tx_first[ endpoint ]; |
231
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
1298 if ( packet ) |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
1299 { |
104
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1300 //serial_print("tx packet\n"); |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1301 tx_first[endpoint] = packet->next; |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1302 b->addr = packet->buf; |
231
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
1303 switch ( tx_state[ endpoint ] ) |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
1304 { |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
1305 case TX_STATE_BOTH_FREE_EVEN_FIRST: |
250
afe96322d0c5
Code formatting cleanup.
Jacob Alexander <haata@kiibohd.com>
parents:
231
diff
changeset
|
1306 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
|
1307 break; |
231
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
1308 case TX_STATE_BOTH_FREE_ODD_FIRST: |
250
afe96322d0c5
Code formatting cleanup.
Jacob Alexander <haata@kiibohd.com>
parents:
231
diff
changeset
|
1309 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
|
1310 break; |
231
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
1311 case TX_STATE_EVEN_FREE: |
250
afe96322d0c5
Code formatting cleanup.
Jacob Alexander <haata@kiibohd.com>
parents:
231
diff
changeset
|
1312 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
|
1313 break; |
231
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
1314 case TX_STATE_ODD_FREE: |
250
afe96322d0c5
Code formatting cleanup.
Jacob Alexander <haata@kiibohd.com>
parents:
231
diff
changeset
|
1315 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
|
1316 break; |
231
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
1317 default: |
104
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1318 break; |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1319 } |
250
afe96322d0c5
Code formatting cleanup.
Jacob Alexander <haata@kiibohd.com>
parents:
231
diff
changeset
|
1320 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
|
1321 } else { |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1322 //serial_print("tx no packet\n"); |
231
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
1323 switch ( tx_state[ endpoint ] ) |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
1324 { |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
1325 case TX_STATE_BOTH_FREE_EVEN_FIRST: |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
1326 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
|
1327 break; |
231
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
1328 case TX_STATE_EVEN_FREE: |
250
afe96322d0c5
Code formatting cleanup.
Jacob Alexander <haata@kiibohd.com>
parents:
231
diff
changeset
|
1329 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
|
1330 break; |
231
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
1331 case TX_STATE_ODD_FREE: |
250
afe96322d0c5
Code formatting cleanup.
Jacob Alexander <haata@kiibohd.com>
parents:
231
diff
changeset
|
1332 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
|
1333 break; |
231
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
1334 default: |
250
afe96322d0c5
Code formatting cleanup.
Jacob Alexander <haata@kiibohd.com>
parents:
231
diff
changeset
|
1335 tx_state[ endpoint ] = ((uint32_t)b & 8) |
376 | 1336 ? TX_STATE_ODD_FREE |
1337 : TX_STATE_EVEN_FREE; | |
104
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1338 break; |
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 } |
231
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
1341 } |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
1342 else |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
1343 { // receive |
104
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1344 packet->len = b->desc >> 16; |
250
afe96322d0c5
Code formatting cleanup.
Jacob Alexander <haata@kiibohd.com>
parents:
231
diff
changeset
|
1345 if ( packet->len > 0 ) |
afe96322d0c5
Code formatting cleanup.
Jacob Alexander <haata@kiibohd.com>
parents:
231
diff
changeset
|
1346 { |
117
5ffefdf89b37
Adding in USB module updates from Teensyduino 1.18rc2.
Jacob Alexander <haata@kiibohd.com>
parents:
109
diff
changeset
|
1347 packet->index = 0; |
5ffefdf89b37
Adding in USB module updates from Teensyduino 1.18rc2.
Jacob Alexander <haata@kiibohd.com>
parents:
109
diff
changeset
|
1348 packet->next = NULL; |
250
afe96322d0c5
Code formatting cleanup.
Jacob Alexander <haata@kiibohd.com>
parents:
231
diff
changeset
|
1349 if ( rx_first[ endpoint ] == NULL ) |
231
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
1350 { |
117
5ffefdf89b37
Adding in USB module updates from Teensyduino 1.18rc2.
Jacob Alexander <haata@kiibohd.com>
parents:
109
diff
changeset
|
1351 //serial_print("rx 1st, epidx="); |
5ffefdf89b37
Adding in USB module updates from Teensyduino 1.18rc2.
Jacob Alexander <haata@kiibohd.com>
parents:
109
diff
changeset
|
1352 //serial_phex(endpoint); |
5ffefdf89b37
Adding in USB module updates from Teensyduino 1.18rc2.
Jacob Alexander <haata@kiibohd.com>
parents:
109
diff
changeset
|
1353 //serial_print(", packet="); |
5ffefdf89b37
Adding in USB module updates from Teensyduino 1.18rc2.
Jacob Alexander <haata@kiibohd.com>
parents:
109
diff
changeset
|
1354 //serial_phex32((uint32_t)packet); |
5ffefdf89b37
Adding in USB module updates from Teensyduino 1.18rc2.
Jacob Alexander <haata@kiibohd.com>
parents:
109
diff
changeset
|
1355 //serial_print("\n"); |
250
afe96322d0c5
Code formatting cleanup.
Jacob Alexander <haata@kiibohd.com>
parents:
231
diff
changeset
|
1356 rx_first[ endpoint ] = packet; |
231
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
1357 } |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
1358 else |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
1359 { |
117
5ffefdf89b37
Adding in USB module updates from Teensyduino 1.18rc2.
Jacob Alexander <haata@kiibohd.com>
parents:
109
diff
changeset
|
1360 //serial_print("rx Nth, epidx="); |
5ffefdf89b37
Adding in USB module updates from Teensyduino 1.18rc2.
Jacob Alexander <haata@kiibohd.com>
parents:
109
diff
changeset
|
1361 //serial_phex(endpoint); |
5ffefdf89b37
Adding in USB module updates from Teensyduino 1.18rc2.
Jacob Alexander <haata@kiibohd.com>
parents:
109
diff
changeset
|
1362 //serial_print(", packet="); |
5ffefdf89b37
Adding in USB module updates from Teensyduino 1.18rc2.
Jacob Alexander <haata@kiibohd.com>
parents:
109
diff
changeset
|
1363 //serial_phex32((uint32_t)packet); |
5ffefdf89b37
Adding in USB module updates from Teensyduino 1.18rc2.
Jacob Alexander <haata@kiibohd.com>
parents:
109
diff
changeset
|
1364 //serial_print("\n"); |
250
afe96322d0c5
Code formatting cleanup.
Jacob Alexander <haata@kiibohd.com>
parents:
231
diff
changeset
|
1365 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
|
1366 } |
250
afe96322d0c5
Code formatting cleanup.
Jacob Alexander <haata@kiibohd.com>
parents:
231
diff
changeset
|
1367 rx_last[ endpoint ] = packet; |
afe96322d0c5
Code formatting cleanup.
Jacob Alexander <haata@kiibohd.com>
parents:
231
diff
changeset
|
1368 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
|
1369 // 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
|
1370 // 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
|
1371 // 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
|
1372 packet = usb_malloc(); |
231
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
1373 if ( packet ) |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
1374 { |
117
5ffefdf89b37
Adding in USB module updates from Teensyduino 1.18rc2.
Jacob Alexander <haata@kiibohd.com>
parents:
109
diff
changeset
|
1375 b->addr = packet->buf; |
250
afe96322d0c5
Code formatting cleanup.
Jacob Alexander <haata@kiibohd.com>
parents:
231
diff
changeset
|
1376 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
|
1377 } |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
1378 else |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
1379 { |
117
5ffefdf89b37
Adding in USB module updates from Teensyduino 1.18rc2.
Jacob Alexander <haata@kiibohd.com>
parents:
109
diff
changeset
|
1380 //serial_print("starving "); |
5ffefdf89b37
Adding in USB module updates from Teensyduino 1.18rc2.
Jacob Alexander <haata@kiibohd.com>
parents:
109
diff
changeset
|
1381 //serial_phex(endpoint + 1); |
5ffefdf89b37
Adding in USB module updates from Teensyduino 1.18rc2.
Jacob Alexander <haata@kiibohd.com>
parents:
109
diff
changeset
|
1382 //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
|
1383 b->desc = 0; |
5ffefdf89b37
Adding in USB module updates from Teensyduino 1.18rc2.
Jacob Alexander <haata@kiibohd.com>
parents:
109
diff
changeset
|
1384 usb_rx_memory_needed++; |
5ffefdf89b37
Adding in USB module updates from Teensyduino 1.18rc2.
Jacob Alexander <haata@kiibohd.com>
parents:
109
diff
changeset
|
1385 } |
231
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
1386 } |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
1387 else |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
1388 { |
250
afe96322d0c5
Code formatting cleanup.
Jacob Alexander <haata@kiibohd.com>
parents:
231
diff
changeset
|
1389 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
|
1390 } |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1391 } |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1392 |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1393 |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1394 |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1395 |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1396 } |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1397 USB0_ISTAT = USB_ISTAT_TOKDNE; |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1398 goto restart; |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1399 } |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1400 |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1401 |
231
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
1402 if ( status & USB_ISTAT_USBRST /* 01 */ ) |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
1403 { |
104
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1404 //serial_print("reset\n"); |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1405 |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1406 // initialize BDT toggle bits |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1407 USB0_CTL = USB_CTL_ODDRST; |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1408 ep0_tx_bdt_bank = 0; |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1409 |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1410 // set up buffers to receive Setup and OUT packets |
250
afe96322d0c5
Code formatting cleanup.
Jacob Alexander <haata@kiibohd.com>
parents:
231
diff
changeset
|
1411 table[index( 0, RX, EVEN ) ].desc = BDT_DESC( EP0_SIZE, 0 ); |
afe96322d0c5
Code formatting cleanup.
Jacob Alexander <haata@kiibohd.com>
parents:
231
diff
changeset
|
1412 table[index( 0, RX, EVEN ) ].addr = ep0_rx0_buf; |
afe96322d0c5
Code formatting cleanup.
Jacob Alexander <haata@kiibohd.com>
parents:
231
diff
changeset
|
1413 table[index( 0, RX, ODD ) ].desc = BDT_DESC( EP0_SIZE, 0 ); |
afe96322d0c5
Code formatting cleanup.
Jacob Alexander <haata@kiibohd.com>
parents:
231
diff
changeset
|
1414 table[index( 0, RX, ODD ) ].addr = ep0_rx1_buf; |
afe96322d0c5
Code formatting cleanup.
Jacob Alexander <haata@kiibohd.com>
parents:
231
diff
changeset
|
1415 table[index( 0, TX, EVEN ) ].desc = 0; |
afe96322d0c5
Code formatting cleanup.
Jacob Alexander <haata@kiibohd.com>
parents:
231
diff
changeset
|
1416 table[index( 0, TX, ODD ) ].desc = 0; |
170
85d74e5e1a95
More work on mk20dx128vlf5 port.
Jacob Alexander <haata@kiibohd.com>
parents:
118
diff
changeset
|
1417 |
104
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1418 // activate endpoint 0 |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1419 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
|
1420 |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1421 // clear all ending interrupts |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1422 USB0_ERRSTAT = 0xFF; |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1423 USB0_ISTAT = 0xFF; |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1424 |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1425 // 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
|
1426 USB0_ADDR = 0; |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1427 |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1428 // enable other interrupts |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1429 USB0_ERREN = 0xFF; |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1430 USB0_INTEN = USB_INTEN_TOKDNEEN | |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1431 USB_INTEN_SOFTOKEN | |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1432 USB_INTEN_STALLEN | |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1433 USB_INTEN_ERROREN | |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1434 USB_INTEN_USBRSTEN | |
439
68e19d7c953e
Adding proper remote wake-up support
Jacob Alexander <haata@kiibohd.com>
parents:
438
diff
changeset
|
1435 USB_INTEN_RESUMEEN | |
104
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1436 USB_INTEN_SLEEPEN; |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1437 |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1438 // is this necessary? |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1439 USB0_CTL = USB_CTL_USBENSOFEN; |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1440 return; |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1441 } |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1442 |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1443 |
231
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
1444 if ( (status & USB_ISTAT_STALL /* 80 */ ) ) |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
1445 { |
104
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1446 //serial_print("stall:\n"); |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1447 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
|
1448 USB0_ISTAT = USB_ISTAT_STALL; |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1449 } |
231
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
1450 if ( (status & USB_ISTAT_ERROR /* 02 */ ) ) |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
1451 { |
104
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1452 uint8_t err = USB0_ERRSTAT; |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1453 USB0_ERRSTAT = err; |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1454 //serial_print("err:"); |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1455 //serial_phex(err); |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1456 //serial_print("\n"); |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1457 USB0_ISTAT = USB_ISTAT_ERROR; |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1458 } |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1459 |
420
23a1868b4ac2
Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents:
385
diff
changeset
|
1460 // USB Host signalling device to enter 'sleep' state |
23a1868b4ac2
Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents:
385
diff
changeset
|
1461 // 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
|
1462 if ( (status & USB_ISTAT_SLEEP /* 10 */ ) ) |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
1463 { |
449
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
1464 #if enableUSBSuspend_define == 1 |
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
1465 // Can cause issues with the virtual serial port |
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
1466 #if enableVirtualSerialPort_define != 1 |
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
1467 info_print("Host has requested USB sleep/suspend state"); |
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
1468 #endif |
420
23a1868b4ac2
Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents:
385
diff
changeset
|
1469 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
|
1470 usb_dev_sleep = 1; |
449
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
1471 #else |
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
1472 info_print("USB Suspend Detected - Firmware USB Suspend Disabled"); |
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
1473 #endif |
439
68e19d7c953e
Adding proper remote wake-up support
Jacob Alexander <haata@kiibohd.com>
parents:
438
diff
changeset
|
1474 USB0_ISTAT |= USB_ISTAT_SLEEP; |
68e19d7c953e
Adding proper remote wake-up support
Jacob Alexander <haata@kiibohd.com>
parents:
438
diff
changeset
|
1475 } |
68e19d7c953e
Adding proper remote wake-up support
Jacob Alexander <haata@kiibohd.com>
parents:
438
diff
changeset
|
1476 |
68e19d7c953e
Adding proper remote wake-up support
Jacob Alexander <haata@kiibohd.com>
parents:
438
diff
changeset
|
1477 // 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
|
1478 if ( (status & USB_ISTAT_RESUME /* 20 */ ) ) |
68e19d7c953e
Adding proper remote wake-up support
Jacob Alexander <haata@kiibohd.com>
parents:
438
diff
changeset
|
1479 { |
449
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
1480 // Can cause issues with the virtual serial port |
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
1481 #if enableVirtualSerialPort_define != 1 |
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
1482 info_print("Host has woken-up/resumed from sleep/suspend state"); |
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
1483 #endif |
439
68e19d7c953e
Adding proper remote wake-up support
Jacob Alexander <haata@kiibohd.com>
parents:
438
diff
changeset
|
1484 Output_update_usb_current( *usb_bMaxPower * 2 ); |
68e19d7c953e
Adding proper remote wake-up support
Jacob Alexander <haata@kiibohd.com>
parents:
438
diff
changeset
|
1485 usb_dev_sleep = 0; |
68e19d7c953e
Adding proper remote wake-up support
Jacob Alexander <haata@kiibohd.com>
parents:
438
diff
changeset
|
1486 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
|
1487 } |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1488 } |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1489 |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1490 |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1491 |
275
d5bf41d7f7ef
Initial code for USB cable detection
Jacob Alexander <haata@kiibohd.com>
parents:
251
diff
changeset
|
1492 uint8_t usb_init() |
104
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1493 { |
231
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
1494 #ifdef UART_DEBUG |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
1495 print("USB INIT"NL); |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
192
diff
changeset
|
1496 #endif |
104
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1497 |
449
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
1498 USBInit_TimeStart = systick_millis_count; |
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
1499 USBInit_Ticks = 0; |
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
1500 |
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
1501 // XXX Set wTotalLength here instead of using defines |
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
1502 // Simplifies defines considerably |
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
1503 usb_set_config_descriptor_size(); |
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
447
diff
changeset
|
1504 |
175 | 1505 // Clear out endpoints table |
1506 for ( int i = 0; i <= NUM_ENDPOINTS * 4; i++ ) | |
1507 { | |
104
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1508 table[i].desc = 0; |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1509 table[i].addr = 0; |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1510 } |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1511 |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1512 // 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
|
1513 // 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
|
1514 |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1515 // 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
|
1516 // SIM - enable clock |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1517 SIM_SCGC4 |= SIM_SCGC4_USBOTG; |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1518 |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1519 // reset USB module |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1520 USB0_USBTRC0 = USB_USBTRC_USBRESET; |
175 | 1521 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
|
1522 |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1523 // set desc table base addr |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1524 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
|
1525 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
|
1526 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
|
1527 |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1528 // clear all ISR flags |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1529 USB0_ISTAT = 0xFF; |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1530 USB0_ERRSTAT = 0xFF; |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1531 USB0_OTGISTAT = 0xFF; |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1532 |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1533 USB0_USBTRC0 |= 0x40; // undocumented bit |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1534 |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1535 // enable USB |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1536 USB0_CTL = USB_CTL_USBENSOFEN; |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1537 USB0_USBCTRL = 0; |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1538 |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1539 // enable reset interrupt |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1540 USB0_INTEN = USB_INTEN_USBRSTEN; |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1541 |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1542 // enable interrupt in NVIC... |
175 | 1543 NVIC_SET_PRIORITY( IRQ_USBOTG, 112 ); |
1544 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
|
1545 |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1546 // enable d+ pullup |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1547 USB0_CONTROL = USB_CONTROL_DPPULLUPNONOTG; |
275
d5bf41d7f7ef
Initial code for USB cable detection
Jacob Alexander <haata@kiibohd.com>
parents:
251
diff
changeset
|
1548 |
420
23a1868b4ac2
Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents:
385
diff
changeset
|
1549 // 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
|
1550 power_neg_delay = 0; |
23a1868b4ac2
Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents:
385
diff
changeset
|
1551 |
439
68e19d7c953e
Adding proper remote wake-up support
Jacob Alexander <haata@kiibohd.com>
parents:
438
diff
changeset
|
1552 // During initialization host isn't sleeping |
68e19d7c953e
Adding proper remote wake-up support
Jacob Alexander <haata@kiibohd.com>
parents:
438
diff
changeset
|
1553 usb_dev_sleep = 0; |
68e19d7c953e
Adding proper remote wake-up support
Jacob Alexander <haata@kiibohd.com>
parents:
438
diff
changeset
|
1554 |
275
d5bf41d7f7ef
Initial code for USB cable detection
Jacob Alexander <haata@kiibohd.com>
parents:
251
diff
changeset
|
1555 return 1; |
104
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1556 } |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1557 |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1558 // 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
|
1559 // number selected by the HOST |
175 | 1560 uint8_t usb_configured() |
104
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1561 { |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1562 return usb_configuration; |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1563 } |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1564 |