Mercurial > louis > kiibohd-controller
annotate Output/pjrcUSB/arm/usb_dev.h @ 447:56237ba5da6f
Adding auto-restart support whenever USB gets into an odd state
- Somewhat aggresive, may cause restarts if the keyboard/OS hasn't fully intialized the keyboard
- Added GET_IDLE handling and correct usage of SET_IDLE
- Initial implementation of idle send, commented out as it causes issues on Mac OSX for sleeping
(keyboard has been working without it)
- MacOSX seems to have some sort of data corruption on the USB link, not sure why (other OSs have no issues)
- Cleaned up some code
- Added a longer sleep after the resume sequence to prevent possible issues sending keys too soon
(may need to be increased more)
Ipad support now seems flaky, though Mac, Windows seems solid.
Init sequence on Linux seems slow, even though there are no errors.
author | Jacob Alexander <haata@kiibohd.com> |
---|---|
date | Fri, 27 May 2016 01:21:57 -0700 |
parents | 23a1868b4ac2 |
children | 45feb80a2ad1 |
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. |
447
56237ba5da6f
Adding auto-restart support whenever USB gets into an odd state
Jacob Alexander <haata@kiibohd.com>
parents:
420
diff
changeset
|
4 * Modifications by Jacob Alexander 2014-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 * |
231
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
177
diff
changeset
|
14 * 1. The above copyright notice and this permission notice shall be |
117
5ffefdf89b37
Adding in USB module updates from Teensyduino 1.18rc2.
Jacob Alexander <haata@kiibohd.com>
parents:
109
diff
changeset
|
15 * included in all copies or substantial portions of the Software. |
5ffefdf89b37
Adding in USB module updates from Teensyduino 1.18rc2.
Jacob Alexander <haata@kiibohd.com>
parents:
109
diff
changeset
|
16 * |
231
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
177
diff
changeset
|
17 * 2. If the Software is incorporated into a build system that allows |
117
5ffefdf89b37
Adding in USB module updates from Teensyduino 1.18rc2.
Jacob Alexander <haata@kiibohd.com>
parents:
109
diff
changeset
|
18 * selection among a list of target devices, then similar target |
5ffefdf89b37
Adding in USB module updates from Teensyduino 1.18rc2.
Jacob Alexander <haata@kiibohd.com>
parents:
109
diff
changeset
|
19 * devices manufactured by PJRC.COM must be included in the list of |
5ffefdf89b37
Adding in USB module updates from Teensyduino 1.18rc2.
Jacob Alexander <haata@kiibohd.com>
parents:
109
diff
changeset
|
20 * target devices and selectable in the same manner. |
5ffefdf89b37
Adding in USB module updates from Teensyduino 1.18rc2.
Jacob Alexander <haata@kiibohd.com>
parents:
109
diff
changeset
|
21 * |
5ffefdf89b37
Adding in USB module updates from Teensyduino 1.18rc2.
Jacob Alexander <haata@kiibohd.com>
parents:
109
diff
changeset
|
22 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
5ffefdf89b37
Adding in USB module updates from Teensyduino 1.18rc2.
Jacob Alexander <haata@kiibohd.com>
parents:
109
diff
changeset
|
23 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
5ffefdf89b37
Adding in USB module updates from Teensyduino 1.18rc2.
Jacob Alexander <haata@kiibohd.com>
parents:
109
diff
changeset
|
24 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
5ffefdf89b37
Adding in USB module updates from Teensyduino 1.18rc2.
Jacob Alexander <haata@kiibohd.com>
parents:
109
diff
changeset
|
25 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS |
5ffefdf89b37
Adding in USB module updates from Teensyduino 1.18rc2.
Jacob Alexander <haata@kiibohd.com>
parents:
109
diff
changeset
|
26 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN |
5ffefdf89b37
Adding in USB module updates from Teensyduino 1.18rc2.
Jacob Alexander <haata@kiibohd.com>
parents:
109
diff
changeset
|
27 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
5ffefdf89b37
Adding in USB module updates from Teensyduino 1.18rc2.
Jacob Alexander <haata@kiibohd.com>
parents:
109
diff
changeset
|
28 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
5ffefdf89b37
Adding in USB module updates from Teensyduino 1.18rc2.
Jacob Alexander <haata@kiibohd.com>
parents:
109
diff
changeset
|
29 * SOFTWARE. |
5ffefdf89b37
Adding in USB module updates from Teensyduino 1.18rc2.
Jacob Alexander <haata@kiibohd.com>
parents:
109
diff
changeset
|
30 */ |
5ffefdf89b37
Adding in USB module updates from Teensyduino 1.18rc2.
Jacob Alexander <haata@kiibohd.com>
parents:
109
diff
changeset
|
31 |
341 | 32 #pragma once |
104
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
33 |
231
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
177
diff
changeset
|
34 // ----- Includes ----- |
104
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
35 |
231
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
177
diff
changeset
|
36 // Local Includes |
104
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
37 #include "usb_mem.h" |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
38 #include "usb_desc.h" |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
39 |
231
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
177
diff
changeset
|
40 |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
177
diff
changeset
|
41 |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
177
diff
changeset
|
42 // ----- Defines ----- |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
177
diff
changeset
|
43 |
177
3420e018ffbc
Adding McHCK flash reload function and some cleanup.
Jacob Alexander <haata@kiibohd.com>
parents:
175
diff
changeset
|
44 #define usb_device_software_reset() SOFTWARE_RESET() |
3420e018ffbc
Adding McHCK flash reload function and some cleanup.
Jacob Alexander <haata@kiibohd.com>
parents:
175
diff
changeset
|
45 |
231
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
177
diff
changeset
|
46 |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
177
diff
changeset
|
47 |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
177
diff
changeset
|
48 // ----- Variables ----- |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
177
diff
changeset
|
49 |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
177
diff
changeset
|
50 extern volatile uint8_t usb_configuration; |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
177
diff
changeset
|
51 |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
177
diff
changeset
|
52 extern uint16_t usb_rx_byte_count_data[NUM_ENDPOINTS]; |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
177
diff
changeset
|
53 |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
177
diff
changeset
|
54 extern volatile uint8_t usb_cdc_line_coding[7]; |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
177
diff
changeset
|
55 extern volatile uint8_t usb_cdc_line_rtsdtr; |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
177
diff
changeset
|
56 extern volatile uint8_t usb_cdc_transmit_flush_timer; |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
177
diff
changeset
|
57 |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
177
diff
changeset
|
58 |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
177
diff
changeset
|
59 |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
177
diff
changeset
|
60 // ----- Functions ----- |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
177
diff
changeset
|
61 |
177
3420e018ffbc
Adding McHCK flash reload function and some cleanup.
Jacob Alexander <haata@kiibohd.com>
parents:
175
diff
changeset
|
62 uint8_t usb_configured(); // is the USB port configured |
275
d5bf41d7f7ef
Initial code for USB cable detection
Jacob Alexander <haata@kiibohd.com>
parents:
231
diff
changeset
|
63 uint8_t usb_init(); // Returns 1 on success, 0 if no cable is attached |
447
56237ba5da6f
Adding auto-restart support whenever USB gets into an odd state
Jacob Alexander <haata@kiibohd.com>
parents:
420
diff
changeset
|
64 void usb_reinit(); // Force restart USB interface, simulates disconnect |
177
3420e018ffbc
Adding McHCK flash reload function and some cleanup.
Jacob Alexander <haata@kiibohd.com>
parents:
175
diff
changeset
|
65 |
175 | 66 void usb_isr(); |
177
3420e018ffbc
Adding McHCK flash reload function and some cleanup.
Jacob Alexander <haata@kiibohd.com>
parents:
175
diff
changeset
|
67 void usb_tx( uint32_t endpoint, usb_packet_t *packet ); |
3420e018ffbc
Adding McHCK flash reload function and some cleanup.
Jacob Alexander <haata@kiibohd.com>
parents:
175
diff
changeset
|
68 void usb_tx_isr( uint32_t endpoint, usb_packet_t *packet ); |
3420e018ffbc
Adding McHCK flash reload function and some cleanup.
Jacob Alexander <haata@kiibohd.com>
parents:
175
diff
changeset
|
69 |
3420e018ffbc
Adding McHCK flash reload function and some cleanup.
Jacob Alexander <haata@kiibohd.com>
parents:
175
diff
changeset
|
70 uint32_t usb_tx_byte_count( uint32_t endpoint ); |
3420e018ffbc
Adding McHCK flash reload function and some cleanup.
Jacob Alexander <haata@kiibohd.com>
parents:
175
diff
changeset
|
71 uint32_t usb_tx_packet_count( uint32_t endpoint ); |
3420e018ffbc
Adding McHCK flash reload function and some cleanup.
Jacob Alexander <haata@kiibohd.com>
parents:
175
diff
changeset
|
72 |
3420e018ffbc
Adding McHCK flash reload function and some cleanup.
Jacob Alexander <haata@kiibohd.com>
parents:
175
diff
changeset
|
73 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
|
74 |
117
5ffefdf89b37
Adding in USB module updates from Teensyduino 1.18rc2.
Jacob Alexander <haata@kiibohd.com>
parents:
109
diff
changeset
|
75 static inline uint32_t usb_rx_byte_count(uint32_t endpoint) __attribute__((always_inline)); |
5ffefdf89b37
Adding in USB module updates from Teensyduino 1.18rc2.
Jacob Alexander <haata@kiibohd.com>
parents:
109
diff
changeset
|
76 static inline uint32_t usb_rx_byte_count(uint32_t endpoint) |
5ffefdf89b37
Adding in USB module updates from Teensyduino 1.18rc2.
Jacob Alexander <haata@kiibohd.com>
parents:
109
diff
changeset
|
77 { |
326
05a09eda53fb
Inital Remote Wakeup Support
Rowan Decker <Smasher816@gmail.com>
parents:
275
diff
changeset
|
78 endpoint--; |
05a09eda53fb
Inital Remote Wakeup Support
Rowan Decker <Smasher816@gmail.com>
parents:
275
diff
changeset
|
79 if ( endpoint >= NUM_ENDPOINTS ) |
231
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
177
diff
changeset
|
80 return 0; |
326
05a09eda53fb
Inital Remote Wakeup Support
Rowan Decker <Smasher816@gmail.com>
parents:
275
diff
changeset
|
81 return usb_rx_byte_count_data[ endpoint ]; |
117
5ffefdf89b37
Adding in USB module updates from Teensyduino 1.18rc2.
Jacob Alexander <haata@kiibohd.com>
parents:
109
diff
changeset
|
82 } |
5ffefdf89b37
Adding in USB module updates from Teensyduino 1.18rc2.
Jacob Alexander <haata@kiibohd.com>
parents:
109
diff
changeset
|
83 |
231
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
177
diff
changeset
|
84 void usb_device_reload(); |
420
23a1868b4ac2
Adding dynamic USB power support
Jacob Alexander <haata@kiibohd.com>
parents:
346
diff
changeset
|
85 void usb_device_check(); |
104
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
86 |
231
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
177
diff
changeset
|
87 extern void usb_serial_flush_callback(); |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
177
diff
changeset
|
88 |