Mercurial > louis > kiibohd-controller
annotate Output/pjrcUSB/arm/usb_serial.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 | 9ac304aa1ab5 |
children |
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:
334
diff
changeset
|
4 * Modified 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:
118
diff
changeset
|
14 * 1. The above copyright notice and this permission notice shall be |
117
5ffefdf89b37
Adding in USB module updates from Teensyduino 1.18rc2.
Jacob Alexander <haata@kiibohd.com>
parents:
104
diff
changeset
|
15 * included in all copies or substantial portions of the Software. |
5ffefdf89b37
Adding in USB module updates from Teensyduino 1.18rc2.
Jacob Alexander <haata@kiibohd.com>
parents:
104
diff
changeset
|
16 * |
170
85d74e5e1a95
More work on mk20dx128vlf5 port.
Jacob Alexander <haata@kiibohd.com>
parents:
118
diff
changeset
|
17 * 2. If the Software is incorporated into a build system that allows |
117
5ffefdf89b37
Adding in USB module updates from Teensyduino 1.18rc2.
Jacob Alexander <haata@kiibohd.com>
parents:
104
diff
changeset
|
18 * selection among a list of target devices, then similar target |
5ffefdf89b37
Adding in USB module updates from Teensyduino 1.18rc2.
Jacob Alexander <haata@kiibohd.com>
parents:
104
diff
changeset
|
19 * devices manufactured by PJRC.COM must be included in the list of |
5ffefdf89b37
Adding in USB module updates from Teensyduino 1.18rc2.
Jacob Alexander <haata@kiibohd.com>
parents:
104
diff
changeset
|
20 * target devices and selectable in the same manner. |
5ffefdf89b37
Adding in USB module updates from Teensyduino 1.18rc2.
Jacob Alexander <haata@kiibohd.com>
parents:
104
diff
changeset
|
21 * |
5ffefdf89b37
Adding in USB module updates from Teensyduino 1.18rc2.
Jacob Alexander <haata@kiibohd.com>
parents:
104
diff
changeset
|
22 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
5ffefdf89b37
Adding in USB module updates from Teensyduino 1.18rc2.
Jacob Alexander <haata@kiibohd.com>
parents:
104
diff
changeset
|
23 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
5ffefdf89b37
Adding in USB module updates from Teensyduino 1.18rc2.
Jacob Alexander <haata@kiibohd.com>
parents:
104
diff
changeset
|
24 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
5ffefdf89b37
Adding in USB module updates from Teensyduino 1.18rc2.
Jacob Alexander <haata@kiibohd.com>
parents:
104
diff
changeset
|
25 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS |
5ffefdf89b37
Adding in USB module updates from Teensyduino 1.18rc2.
Jacob Alexander <haata@kiibohd.com>
parents:
104
diff
changeset
|
26 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN |
5ffefdf89b37
Adding in USB module updates from Teensyduino 1.18rc2.
Jacob Alexander <haata@kiibohd.com>
parents:
104
diff
changeset
|
27 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
5ffefdf89b37
Adding in USB module updates from Teensyduino 1.18rc2.
Jacob Alexander <haata@kiibohd.com>
parents:
104
diff
changeset
|
28 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
5ffefdf89b37
Adding in USB module updates from Teensyduino 1.18rc2.
Jacob Alexander <haata@kiibohd.com>
parents:
104
diff
changeset
|
29 * SOFTWARE. |
5ffefdf89b37
Adding in USB module updates from Teensyduino 1.18rc2.
Jacob Alexander <haata@kiibohd.com>
parents:
104
diff
changeset
|
30 */ |
5ffefdf89b37
Adding in USB module updates from Teensyduino 1.18rc2.
Jacob Alexander <haata@kiibohd.com>
parents:
104
diff
changeset
|
31 |
449
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
334
diff
changeset
|
32 #include <kll_defs.h> |
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
334
diff
changeset
|
33 #if enableVirtualSerialPort_define == 1 |
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
334
diff
changeset
|
34 |
231
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
170
diff
changeset
|
35 // ----- Includes ----- |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
170
diff
changeset
|
36 |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
170
diff
changeset
|
37 // Compiler Includes |
117
5ffefdf89b37
Adding in USB module updates from Teensyduino 1.18rc2.
Jacob Alexander <haata@kiibohd.com>
parents:
104
diff
changeset
|
38 #include <string.h> // For memcpy |
104
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:
170
diff
changeset
|
40 // Project Includes |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
170
diff
changeset
|
41 #include <Lib/OutputLib.h> |
104
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
42 |
231
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
170
diff
changeset
|
43 // Local Includes |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
170
diff
changeset
|
44 #include "usb_dev.h" |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
170
diff
changeset
|
45 #include "usb_serial.h" |
104
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
46 |
231
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
170
diff
changeset
|
47 |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
170
diff
changeset
|
48 |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
170
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 |
308 | 51 #define TRANSMIT_FLUSH_TIMEOUT 5 /* in milliseconds */ |
104
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
52 |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
53 // Maximum number of transmit packets to queue so we don't starve other endpoints for memory |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
54 #define TX_PACKET_LIMIT 8 |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
55 |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
56 // When the PC isn't listening, how long do we wait before discarding data? If this is |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
57 // too short, we risk losing data during the stalls that are common with ordinary desktop |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
58 // software. If it's too long, we stall the user's program when no software is running. |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
59 #define TX_TIMEOUT_MSEC 70 |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
60 |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
61 #if F_CPU == 96000000 |
334
9ac304aa1ab5
Adding initial dfu-upload code and debugging for Bootloader.
Jacob Alexander <haata@kiibohd.com>
parents:
308
diff
changeset
|
62 #define TX_TIMEOUT (TX_TIMEOUT_MSEC * 596) |
9ac304aa1ab5
Adding initial dfu-upload code and debugging for Bootloader.
Jacob Alexander <haata@kiibohd.com>
parents:
308
diff
changeset
|
63 #elif F_CPU == 72000000 |
9ac304aa1ab5
Adding initial dfu-upload code and debugging for Bootloader.
Jacob Alexander <haata@kiibohd.com>
parents:
308
diff
changeset
|
64 #define TX_TIMEOUT (TX_TIMEOUT_MSEC * 512) // XXX Correct? |
104
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
65 #elif F_CPU == 48000000 |
334
9ac304aa1ab5
Adding initial dfu-upload code and debugging for Bootloader.
Jacob Alexander <haata@kiibohd.com>
parents:
308
diff
changeset
|
66 #define TX_TIMEOUT (TX_TIMEOUT_MSEC * 428) |
104
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
67 #elif F_CPU == 24000000 |
334
9ac304aa1ab5
Adding initial dfu-upload code and debugging for Bootloader.
Jacob Alexander <haata@kiibohd.com>
parents:
308
diff
changeset
|
68 #define TX_TIMEOUT (TX_TIMEOUT_MSEC * 262) |
104
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
69 #endif |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
70 |
231
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
170
diff
changeset
|
71 |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
170
diff
changeset
|
72 |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
170
diff
changeset
|
73 // ----- Variables ----- |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
170
diff
changeset
|
74 |
449
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
334
diff
changeset
|
75 // Serial port settings (baud rate, control signals, etc) set by the host |
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
334
diff
changeset
|
76 // These are *ignored*, except to return back to the host if requested |
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
334
diff
changeset
|
77 volatile USBCDCLineCoding usb_cdc_line_coding = { |
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
334
diff
changeset
|
78 115200, |
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
334
diff
changeset
|
79 0, |
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
334
diff
changeset
|
80 0, |
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
334
diff
changeset
|
81 8, |
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
334
diff
changeset
|
82 }; |
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
334
diff
changeset
|
83 |
231
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
170
diff
changeset
|
84 volatile uint8_t usb_cdc_line_rtsdtr = 0; |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
170
diff
changeset
|
85 volatile uint8_t usb_cdc_transmit_flush_timer = 0; |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
170
diff
changeset
|
86 |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
170
diff
changeset
|
87 static usb_packet_t *rx_packet = NULL; |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
170
diff
changeset
|
88 static usb_packet_t *tx_packet = NULL; |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
170
diff
changeset
|
89 static volatile uint8_t tx_noautoflush = 0; |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
170
diff
changeset
|
90 |
104
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
91 // When we've suffered the transmit timeout, don't wait again until the computer |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
92 // begins accepting data. If no software is running to receive, we'll just discard |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
93 // data as rapidly as Serial.print() can generate it, until there's something to |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
94 // actually receive it. |
231
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
170
diff
changeset
|
95 static uint8_t transmit_previous_timeout = 0; |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
170
diff
changeset
|
96 |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
170
diff
changeset
|
97 |
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 // ----- Functions ----- |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
170
diff
changeset
|
100 |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
170
diff
changeset
|
101 // get the next character, or -1 if nothing received |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
170
diff
changeset
|
102 int usb_serial_getchar() |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
170
diff
changeset
|
103 { |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
170
diff
changeset
|
104 unsigned int i; |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
170
diff
changeset
|
105 int c; |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
170
diff
changeset
|
106 |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
170
diff
changeset
|
107 if ( !rx_packet ) |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
170
diff
changeset
|
108 { |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
170
diff
changeset
|
109 if ( !usb_configuration ) |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
170
diff
changeset
|
110 return -1; |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
170
diff
changeset
|
111 rx_packet = usb_rx( CDC_RX_ENDPOINT ); |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
170
diff
changeset
|
112 if ( !rx_packet ) |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
170
diff
changeset
|
113 return -1; |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
170
diff
changeset
|
114 } |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
170
diff
changeset
|
115 i = rx_packet->index; |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
170
diff
changeset
|
116 c = rx_packet->buf[i++]; |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
170
diff
changeset
|
117 if ( i >= rx_packet->len ) |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
170
diff
changeset
|
118 { |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
170
diff
changeset
|
119 usb_free( rx_packet ); |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
170
diff
changeset
|
120 rx_packet = NULL; |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
170
diff
changeset
|
121 } |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
170
diff
changeset
|
122 else |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
170
diff
changeset
|
123 { |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
170
diff
changeset
|
124 rx_packet->index = i; |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
170
diff
changeset
|
125 } |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
170
diff
changeset
|
126 return c; |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
170
diff
changeset
|
127 } |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
170
diff
changeset
|
128 |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
170
diff
changeset
|
129 // peek at the next character, or -1 if nothing received |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
170
diff
changeset
|
130 int usb_serial_peekchar() |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
170
diff
changeset
|
131 { |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
170
diff
changeset
|
132 if ( !rx_packet ) |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
170
diff
changeset
|
133 { |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
170
diff
changeset
|
134 if ( !usb_configuration ) |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
170
diff
changeset
|
135 return -1; |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
170
diff
changeset
|
136 rx_packet = usb_rx( CDC_RX_ENDPOINT ); |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
170
diff
changeset
|
137 if ( !rx_packet ) |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
170
diff
changeset
|
138 return -1; |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
170
diff
changeset
|
139 } |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
170
diff
changeset
|
140 if ( !rx_packet ) |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
170
diff
changeset
|
141 return -1; |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
170
diff
changeset
|
142 return rx_packet->buf[ rx_packet->index ]; |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
170
diff
changeset
|
143 } |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
170
diff
changeset
|
144 |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
170
diff
changeset
|
145 // number of bytes available in the receive buffer |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
170
diff
changeset
|
146 int usb_serial_available() |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
170
diff
changeset
|
147 { |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
170
diff
changeset
|
148 int count = usb_rx_byte_count( CDC_RX_ENDPOINT ); |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
170
diff
changeset
|
149 if ( rx_packet ) |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
170
diff
changeset
|
150 count += rx_packet->len - rx_packet->index; |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
170
diff
changeset
|
151 return count; |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
170
diff
changeset
|
152 } |
104
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
153 |
231
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
170
diff
changeset
|
154 // read a block of bytes to a buffer |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
170
diff
changeset
|
155 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
|
156 { |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
170
diff
changeset
|
157 uint8_t *p = (uint8_t *)buffer; |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
170
diff
changeset
|
158 uint32_t qty, count=0; |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
170
diff
changeset
|
159 |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
170
diff
changeset
|
160 while ( size ) |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
170
diff
changeset
|
161 { |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
170
diff
changeset
|
162 if ( !usb_configuration ) |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
170
diff
changeset
|
163 break; |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
170
diff
changeset
|
164 if ( !rx_packet ) |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
170
diff
changeset
|
165 { |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
170
diff
changeset
|
166 rx: |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
170
diff
changeset
|
167 rx_packet = usb_rx(CDC_RX_ENDPOINT); |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
170
diff
changeset
|
168 if ( !rx_packet ) |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
170
diff
changeset
|
169 break; |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
170
diff
changeset
|
170 if ( rx_packet->len == 0 ) |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
170
diff
changeset
|
171 { |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
170
diff
changeset
|
172 usb_free(rx_packet); |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
170
diff
changeset
|
173 goto rx; |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
170
diff
changeset
|
174 } |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
170
diff
changeset
|
175 } |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
170
diff
changeset
|
176 qty = rx_packet->len - rx_packet->index; |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
170
diff
changeset
|
177 if ( qty > size ) |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
170
diff
changeset
|
178 qty = size; |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
170
diff
changeset
|
179 memcpy( p, rx_packet->buf + rx_packet->index, qty ); |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
170
diff
changeset
|
180 p += qty; |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
170
diff
changeset
|
181 count += qty; |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
170
diff
changeset
|
182 size -= qty; |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
170
diff
changeset
|
183 rx_packet->index += qty; |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
170
diff
changeset
|
184 if ( rx_packet->index >= rx_packet->len ) |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
170
diff
changeset
|
185 { |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
170
diff
changeset
|
186 usb_free( rx_packet ); |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
170
diff
changeset
|
187 rx_packet = NULL; |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
170
diff
changeset
|
188 } |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
170
diff
changeset
|
189 } |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
170
diff
changeset
|
190 return count; |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
170
diff
changeset
|
191 } |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
170
diff
changeset
|
192 |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
170
diff
changeset
|
193 // discard any buffered input |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
170
diff
changeset
|
194 void usb_serial_flush_input() |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
170
diff
changeset
|
195 { |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
170
diff
changeset
|
196 usb_packet_t *rx; |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
170
diff
changeset
|
197 |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
170
diff
changeset
|
198 if ( !usb_configuration ) |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
170
diff
changeset
|
199 return; |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
170
diff
changeset
|
200 if ( rx_packet ) |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
170
diff
changeset
|
201 { |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
170
diff
changeset
|
202 usb_free( rx_packet ); |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
170
diff
changeset
|
203 rx_packet = NULL; |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
170
diff
changeset
|
204 } |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
170
diff
changeset
|
205 while (1) |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
170
diff
changeset
|
206 { |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
170
diff
changeset
|
207 rx = usb_rx( CDC_RX_ENDPOINT ); |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
170
diff
changeset
|
208 if ( !rx ) |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
170
diff
changeset
|
209 break; |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
170
diff
changeset
|
210 usb_free( rx ); |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
170
diff
changeset
|
211 } |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
170
diff
changeset
|
212 } |
104
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
213 |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
214 // transmit a character. 0 returned on success, -1 on error |
231
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
170
diff
changeset
|
215 int usb_serial_putchar( uint8_t c ) |
104
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
216 { |
231
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
170
diff
changeset
|
217 return usb_serial_write( &c, 1 ); |
104
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
218 } |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
219 |
231
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
170
diff
changeset
|
220 int usb_serial_write( const void *buffer, uint32_t size ) |
104
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
221 { |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
222 uint32_t len; |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
223 uint32_t wait_count; |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
224 const uint8_t *src = (const uint8_t *)buffer; |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
225 uint8_t *dest; |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
226 |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
227 tx_noautoflush = 1; |
231
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
170
diff
changeset
|
228 while ( size > 0 ) |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
170
diff
changeset
|
229 { |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
170
diff
changeset
|
230 if ( !tx_packet ) |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
170
diff
changeset
|
231 { |
104
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
232 wait_count = 0; |
231
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
170
diff
changeset
|
233 while ( 1 ) |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
170
diff
changeset
|
234 { |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
170
diff
changeset
|
235 if ( !usb_configuration ) |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
170
diff
changeset
|
236 { |
104
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
237 tx_noautoflush = 0; |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
238 return -1; |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
239 } |
231
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
170
diff
changeset
|
240 if ( usb_tx_packet_count( CDC_TX_ENDPOINT ) < TX_PACKET_LIMIT ) |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
170
diff
changeset
|
241 { |
104
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
242 tx_noautoflush = 1; |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
243 tx_packet = usb_malloc(); |
231
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
170
diff
changeset
|
244 if ( tx_packet ) |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
170
diff
changeset
|
245 break; |
104
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
246 tx_noautoflush = 0; |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
247 } |
231
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
170
diff
changeset
|
248 if ( ++wait_count > TX_TIMEOUT || transmit_previous_timeout ) |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
170
diff
changeset
|
249 { |
104
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
250 transmit_previous_timeout = 1; |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
251 return -1; |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
252 } |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
253 yield(); |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
254 } |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
255 } |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
256 transmit_previous_timeout = 0; |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
257 len = CDC_TX_SIZE - tx_packet->index; |
231
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
170
diff
changeset
|
258 if ( len > size ) |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
170
diff
changeset
|
259 len = size; |
104
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
260 dest = tx_packet->buf + tx_packet->index; |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
261 tx_packet->index += len; |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
262 size -= len; |
231
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
170
diff
changeset
|
263 while ( len-- > 0 ) |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
170
diff
changeset
|
264 *dest++ = *src++; |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
170
diff
changeset
|
265 if ( tx_packet->index >= CDC_TX_SIZE ) |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
170
diff
changeset
|
266 { |
104
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
267 tx_packet->len = CDC_TX_SIZE; |
231
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
170
diff
changeset
|
268 usb_tx( CDC_TX_ENDPOINT, tx_packet ); |
104
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
269 tx_packet = NULL; |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
270 } |
117
5ffefdf89b37
Adding in USB module updates from Teensyduino 1.18rc2.
Jacob Alexander <haata@kiibohd.com>
parents:
104
diff
changeset
|
271 usb_cdc_transmit_flush_timer = TRANSMIT_FLUSH_TIMEOUT; |
104
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
272 } |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
273 tx_noautoflush = 0; |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
274 return 0; |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
275 } |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
276 |
231
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
170
diff
changeset
|
277 void usb_serial_flush_output() |
104
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
278 { |
231
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
170
diff
changeset
|
279 if ( !usb_configuration ) |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
170
diff
changeset
|
280 return; |
117
5ffefdf89b37
Adding in USB module updates from Teensyduino 1.18rc2.
Jacob Alexander <haata@kiibohd.com>
parents:
104
diff
changeset
|
281 tx_noautoflush = 1; |
231
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
170
diff
changeset
|
282 if ( tx_packet ) |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
170
diff
changeset
|
283 { |
104
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
284 usb_cdc_transmit_flush_timer = 0; |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
285 tx_packet->len = tx_packet->index; |
231
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
170
diff
changeset
|
286 usb_tx( CDC_TX_ENDPOINT, tx_packet ); |
104
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
287 tx_packet = NULL; |
231
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
170
diff
changeset
|
288 } |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
170
diff
changeset
|
289 else |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
170
diff
changeset
|
290 { |
117
5ffefdf89b37
Adding in USB module updates from Teensyduino 1.18rc2.
Jacob Alexander <haata@kiibohd.com>
parents:
104
diff
changeset
|
291 usb_packet_t *tx = usb_malloc(); |
231
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
170
diff
changeset
|
292 if ( tx ) |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
170
diff
changeset
|
293 { |
117
5ffefdf89b37
Adding in USB module updates from Teensyduino 1.18rc2.
Jacob Alexander <haata@kiibohd.com>
parents:
104
diff
changeset
|
294 usb_cdc_transmit_flush_timer = 0; |
231
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
170
diff
changeset
|
295 usb_tx( CDC_TX_ENDPOINT, tx ); |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
170
diff
changeset
|
296 } |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
170
diff
changeset
|
297 else |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
170
diff
changeset
|
298 { |
117
5ffefdf89b37
Adding in USB module updates from Teensyduino 1.18rc2.
Jacob Alexander <haata@kiibohd.com>
parents:
104
diff
changeset
|
299 usb_cdc_transmit_flush_timer = 1; |
5ffefdf89b37
Adding in USB module updates from Teensyduino 1.18rc2.
Jacob Alexander <haata@kiibohd.com>
parents:
104
diff
changeset
|
300 } |
104
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
301 } |
117
5ffefdf89b37
Adding in USB module updates from Teensyduino 1.18rc2.
Jacob Alexander <haata@kiibohd.com>
parents:
104
diff
changeset
|
302 tx_noautoflush = 0; |
104
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
303 } |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
304 |
231
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
170
diff
changeset
|
305 void usb_serial_flush_callback() |
104
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
306 { |
231
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
170
diff
changeset
|
307 if ( tx_noautoflush ) |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
170
diff
changeset
|
308 return; |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
170
diff
changeset
|
309 if ( tx_packet ) |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
170
diff
changeset
|
310 { |
117
5ffefdf89b37
Adding in USB module updates from Teensyduino 1.18rc2.
Jacob Alexander <haata@kiibohd.com>
parents:
104
diff
changeset
|
311 tx_packet->len = tx_packet->index; |
231
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
170
diff
changeset
|
312 usb_tx( CDC_TX_ENDPOINT, tx_packet ); |
117
5ffefdf89b37
Adding in USB module updates from Teensyduino 1.18rc2.
Jacob Alexander <haata@kiibohd.com>
parents:
104
diff
changeset
|
313 tx_packet = NULL; |
5ffefdf89b37
Adding in USB module updates from Teensyduino 1.18rc2.
Jacob Alexander <haata@kiibohd.com>
parents:
104
diff
changeset
|
314 } else { |
5ffefdf89b37
Adding in USB module updates from Teensyduino 1.18rc2.
Jacob Alexander <haata@kiibohd.com>
parents:
104
diff
changeset
|
315 usb_packet_t *tx = usb_malloc(); |
231
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
170
diff
changeset
|
316 if ( tx ) |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
170
diff
changeset
|
317 { |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
170
diff
changeset
|
318 usb_tx( CDC_TX_ENDPOINT, tx ); |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
170
diff
changeset
|
319 } |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
170
diff
changeset
|
320 else |
4afb170978e9
More preparation for NKRO USB for arm
Jacob Alexander <haata@kiibohd.com>
parents:
170
diff
changeset
|
321 { |
117
5ffefdf89b37
Adding in USB module updates from Teensyduino 1.18rc2.
Jacob Alexander <haata@kiibohd.com>
parents:
104
diff
changeset
|
322 usb_cdc_transmit_flush_timer = 1; |
5ffefdf89b37
Adding in USB module updates from Teensyduino 1.18rc2.
Jacob Alexander <haata@kiibohd.com>
parents:
104
diff
changeset
|
323 } |
5ffefdf89b37
Adding in USB module updates from Teensyduino 1.18rc2.
Jacob Alexander <haata@kiibohd.com>
parents:
104
diff
changeset
|
324 } |
104
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
325 } |
e84738d174bc
Moving USB to Output in preparation for additional Output types.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
326 |
449
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
334
diff
changeset
|
327 #endif |
45feb80a2ad1
Major USB update, fixes most (if not all) known issues
Jacob Alexander <haata@kiibohd.com>
parents:
334
diff
changeset
|
328 |