annotate Output/pjrcUSB/arm/usb_serial.h @ 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 66eccdd9ced5
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
117
5ffefdf89b37 Adding in USB module updates from Teensyduino 1.18rc2.
Jacob Alexander <haata@kiibohd.com>
parents: 104
diff changeset
1 /* Teensyduino Core Library
5ffefdf89b37 Adding in USB module updates from Teensyduino 1.18rc2.
Jacob Alexander <haata@kiibohd.com>
parents: 104
diff changeset
2 * http://www.pjrc.com/teensy/
5ffefdf89b37 Adding in USB module updates from Teensyduino 1.18rc2.
Jacob Alexander <haata@kiibohd.com>
parents: 104
diff changeset
3 * Copyright (c) 2013 PJRC.COM, LLC.
449
45feb80a2ad1 Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents: 341
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: 104
diff changeset
5 *
5ffefdf89b37 Adding in USB module updates from Teensyduino 1.18rc2.
Jacob Alexander <haata@kiibohd.com>
parents: 104
diff changeset
6 * Permission is hereby granted, free of charge, to any person obtaining
5ffefdf89b37 Adding in USB module updates from Teensyduino 1.18rc2.
Jacob Alexander <haata@kiibohd.com>
parents: 104
diff changeset
7 * a copy of this software and associated documentation files (the
5ffefdf89b37 Adding in USB module updates from Teensyduino 1.18rc2.
Jacob Alexander <haata@kiibohd.com>
parents: 104
diff changeset
8 * "Software"), to deal in the Software without restriction, including
5ffefdf89b37 Adding in USB module updates from Teensyduino 1.18rc2.
Jacob Alexander <haata@kiibohd.com>
parents: 104
diff changeset
9 * without limitation the rights to use, copy, modify, merge, publish,
5ffefdf89b37 Adding in USB module updates from Teensyduino 1.18rc2.
Jacob Alexander <haata@kiibohd.com>
parents: 104
diff changeset
10 * distribute, sublicense, and/or sell copies of the Software, and to
5ffefdf89b37 Adding in USB module updates from Teensyduino 1.18rc2.
Jacob Alexander <haata@kiibohd.com>
parents: 104
diff changeset
11 * permit persons to whom the Software is furnished to do so, subject to
5ffefdf89b37 Adding in USB module updates from Teensyduino 1.18rc2.
Jacob Alexander <haata@kiibohd.com>
parents: 104
diff changeset
12 * the following conditions:
5ffefdf89b37 Adding in USB module updates from Teensyduino 1.18rc2.
Jacob Alexander <haata@kiibohd.com>
parents: 104
diff changeset
13 *
170
85d74e5e1a95 More work on mk20dx128vlf5 port.
Jacob Alexander <haata@kiibohd.com>
parents: 117
diff changeset
14 * 1. The above copyright notice and this permission notice shall be
117
5ffefdf89b37 Adding in USB module updates from Teensyduino 1.18rc2.
Jacob Alexander <haata@kiibohd.com>
parents: 104
diff changeset
15 * included in all copies or substantial portions of the Software.
5ffefdf89b37 Adding in USB module updates from Teensyduino 1.18rc2.
Jacob Alexander <haata@kiibohd.com>
parents: 104
diff changeset
16 *
170
85d74e5e1a95 More work on mk20dx128vlf5 port.
Jacob Alexander <haata@kiibohd.com>
parents: 117
diff changeset
17 * 2. If the Software is incorporated into a build system that allows
117
5ffefdf89b37 Adding in USB module updates from Teensyduino 1.18rc2.
Jacob Alexander <haata@kiibohd.com>
parents: 104
diff changeset
18 * selection among a list of target devices, then similar target
5ffefdf89b37 Adding in USB module updates from Teensyduino 1.18rc2.
Jacob Alexander <haata@kiibohd.com>
parents: 104
diff changeset
19 * devices manufactured by PJRC.COM must be included in the list of
5ffefdf89b37 Adding in USB module updates from Teensyduino 1.18rc2.
Jacob Alexander <haata@kiibohd.com>
parents: 104
diff changeset
20 * target devices and selectable in the same manner.
5ffefdf89b37 Adding in USB module updates from Teensyduino 1.18rc2.
Jacob Alexander <haata@kiibohd.com>
parents: 104
diff changeset
21 *
5ffefdf89b37 Adding in USB module updates from Teensyduino 1.18rc2.
Jacob Alexander <haata@kiibohd.com>
parents: 104
diff changeset
22 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
5ffefdf89b37 Adding in USB module updates from Teensyduino 1.18rc2.
Jacob Alexander <haata@kiibohd.com>
parents: 104
diff changeset
23 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
5ffefdf89b37 Adding in USB module updates from Teensyduino 1.18rc2.
Jacob Alexander <haata@kiibohd.com>
parents: 104
diff changeset
24 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
5ffefdf89b37 Adding in USB module updates from Teensyduino 1.18rc2.
Jacob Alexander <haata@kiibohd.com>
parents: 104
diff changeset
25 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
5ffefdf89b37 Adding in USB module updates from Teensyduino 1.18rc2.
Jacob Alexander <haata@kiibohd.com>
parents: 104
diff changeset
26 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
5ffefdf89b37 Adding in USB module updates from Teensyduino 1.18rc2.
Jacob Alexander <haata@kiibohd.com>
parents: 104
diff changeset
27 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
5ffefdf89b37 Adding in USB module updates from Teensyduino 1.18rc2.
Jacob Alexander <haata@kiibohd.com>
parents: 104
diff changeset
28 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
5ffefdf89b37 Adding in USB module updates from Teensyduino 1.18rc2.
Jacob Alexander <haata@kiibohd.com>
parents: 104
diff changeset
29 * SOFTWARE.
5ffefdf89b37 Adding in USB module updates from Teensyduino 1.18rc2.
Jacob Alexander <haata@kiibohd.com>
parents: 104
diff changeset
30 */
5ffefdf89b37 Adding in USB module updates from Teensyduino 1.18rc2.
Jacob Alexander <haata@kiibohd.com>
parents: 104
diff changeset
31
341
66eccdd9ced5 Code cleanup
Jacob Alexander <haata@kiibohd.com>
parents: 231
diff changeset
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: 170
diff changeset
34 // ----- Includes -----
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 170
diff changeset
35
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 170
diff changeset
36 // Compiler Includes
104
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
37 #include <inttypes.h>
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
38
231
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 170
diff changeset
39
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 170
diff changeset
40
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 170
diff changeset
41 // ----- Defines -----
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 170
diff changeset
42
104
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
43 // Compatibility defines from AVR
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
44 #define PROGMEM
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
45 #define PGM_P const char *
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
46 #define PSTR(str) (str)
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
47
231
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 170
diff changeset
48 #define USB_SERIAL_DTR 0x01
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 170
diff changeset
49 #define USB_SERIAL_RTS 0x02
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: 170
diff changeset
51
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 170
diff changeset
52
449
45feb80a2ad1 Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents: 341
diff changeset
53 // ----- Structs -----
45feb80a2ad1 Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents: 341
diff changeset
54
45feb80a2ad1 Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents: 341
diff changeset
55 // See: Universal Serial Bus Class Definitions for Communication Devices 1.11 Table 50
45feb80a2ad1 Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents: 341
diff changeset
56 // dwDTERate - Baud Rate : 4 bytes
45feb80a2ad1 Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents: 341
diff changeset
57 // bCharFormat - Stop Bits : 1 byte
45feb80a2ad1 Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents: 341
diff changeset
58 // 0: 1 stop bit
45feb80a2ad1 Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents: 341
diff changeset
59 // 1: 1.5 stop bits
45feb80a2ad1 Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents: 341
diff changeset
60 // 2: 2 stop bits
45feb80a2ad1 Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents: 341
diff changeset
61 // bParityType - Parity : 1 byte
45feb80a2ad1 Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents: 341
diff changeset
62 // 0: None
45feb80a2ad1 Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents: 341
diff changeset
63 // 1: Odd
45feb80a2ad1 Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents: 341
diff changeset
64 // 2: Even
45feb80a2ad1 Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents: 341
diff changeset
65 // 3: Mark
45feb80a2ad1 Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents: 341
diff changeset
66 // 4: Space
45feb80a2ad1 Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents: 341
diff changeset
67 // bDataBits - Data Bits : 1 byte
45feb80a2ad1 Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents: 341
diff changeset
68 // (5,6,7,8 or 16)
45feb80a2ad1 Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents: 341
diff changeset
69 //
45feb80a2ad1 Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents: 341
diff changeset
70 // Struct is 7 bytes wide
45feb80a2ad1 Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents: 341
diff changeset
71 typedef struct USBCDCLineCoding {
45feb80a2ad1 Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents: 341
diff changeset
72 uint32_t dwDTERate; // Baud Rate
45feb80a2ad1 Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents: 341
diff changeset
73 uint8_t bCharFormat; // Stop Bits
45feb80a2ad1 Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents: 341
diff changeset
74 uint8_t bParityType; // Parity
45feb80a2ad1 Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents: 341
diff changeset
75 uint8_t bDataBits; // Data Bits
45feb80a2ad1 Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents: 341
diff changeset
76 } USBCDCLineCoding;
45feb80a2ad1 Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents: 341
diff changeset
77
45feb80a2ad1 Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents: 341
diff changeset
78
45feb80a2ad1 Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents: 341
diff changeset
79
231
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 170
diff changeset
80 // ----- Variables -----
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 170
diff changeset
81
449
45feb80a2ad1 Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents: 341
diff changeset
82 extern volatile USBCDCLineCoding usb_cdc_line_coding;
231
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 170
diff changeset
83
104
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
84 extern volatile uint8_t usb_cdc_line_rtsdtr;
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
85 extern volatile uint8_t usb_cdc_transmit_flush_timer;
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
86 extern volatile uint8_t usb_configuration;
e84738d174bc Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
87
231
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 170
diff changeset
88
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 170
diff changeset
89
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 170
diff changeset
90 // ----- Functions -----
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 170
diff changeset
91
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 170
diff changeset
92 int usb_serial_available();
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 170
diff changeset
93 int usb_serial_getchar();
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 170
diff changeset
94 int usb_serial_peekchar();
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 170
diff changeset
95 int usb_serial_putchar( uint8_t c );
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 170
diff changeset
96 int usb_serial_read( void *buffer, uint32_t size );
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 170
diff changeset
97 int usb_serial_write( const void *buffer, uint32_t size );
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 170
diff changeset
98
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 170
diff changeset
99 void usb_serial_flush_input();
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 170
diff changeset
100 void usb_serial_flush_output();
4afb170978e9 More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents: 170
diff changeset
101