Mercurial > louis > kiibohd-controller
annotate Output/pjrcUSB/avr/usb_keyboard_serial.c @ 229:b78806c7f9f4
Fixing descriptor bugs
- Missing device qualifier descriptor
- Missing USB Debug descriptor (used by lsusb)
author | Jacob Alexander <haata@kiibohd.com> |
---|---|
date | Sun, 28 Sep 2014 16:42:43 -0700 |
parents | b4e7a712cc15 |
children | d494b74d5242 |
rev | line source |
---|---|
123
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1 /* USB Keyboard and CDC Serial Device for Teensy USB Development Board |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
2 * Copyright (c) 2009 PJRC.COM, LLC |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
3 * Modifications by Jacob Alexander (2011-2014) |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
4 * |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
5 * Permission is hereby granted, free of charge, to any person obtaining a copy |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
6 * of this software and associated documentation files (the "Software"), to deal |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
7 * in the Software without restriction, including without limitation the rights |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
8 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
9 * copies of the Software, and to permit persons to whom the Software is |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
10 * furnished to do so, subject to the following conditions: |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
11 * |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
12 * The above copyright notice and this permission notice shall be included in |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
13 * all copies or substantial portions of the Software. |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
14 * |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
18 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
21 * THE SOFTWARE. |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
22 */ |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
23 |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
24 |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
25 // Local Includes |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
26 #include "usb_keyboard_serial.h" |
212
2794931a4d30
DPH controller now working with macros/layers
Jacob Alexander <haata@kiibohd.com>
parents:
177
diff
changeset
|
27 #include <print.h> |
123
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
28 |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
29 |
165
0d992d26114f
Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents:
123
diff
changeset
|
30 // ----- Variables ----- |
123
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
31 |
165
0d992d26114f
Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents:
123
diff
changeset
|
32 // zero when we are not configured, non-zero when enumerated |
0d992d26114f
Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents:
123
diff
changeset
|
33 static volatile uint8_t usb_configuration = 0; |
123
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
34 |
165
0d992d26114f
Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents:
123
diff
changeset
|
35 // the time remaining before we transmit any partially full |
0d992d26114f
Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents:
123
diff
changeset
|
36 // packet, or send a zero length packet. |
0d992d26114f
Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents:
123
diff
changeset
|
37 static volatile uint8_t transmit_flush_timer = 0; |
0d992d26114f
Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents:
123
diff
changeset
|
38 static uint8_t transmit_previous_timeout = 0; |
123
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
39 |
165
0d992d26114f
Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents:
123
diff
changeset
|
40 // serial port settings (baud rate, control signals, etc) set |
0d992d26114f
Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents:
123
diff
changeset
|
41 // by the PC. These are ignored, but kept in RAM. |
0d992d26114f
Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents:
123
diff
changeset
|
42 static uint8_t cdc_line_coding[7] = {0x00, 0xE1, 0x00, 0x00, 0x00, 0x00, 0x08}; |
0d992d26114f
Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents:
123
diff
changeset
|
43 static uint8_t cdc_line_rtsdtr = 0; |
123
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
44 |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
45 |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
46 |
165
0d992d26114f
Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents:
123
diff
changeset
|
47 // ----- USB Keyboard Functions ----- |
123
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
48 |
165
0d992d26114f
Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents:
123
diff
changeset
|
49 // Sends normal keyboard out to host |
0d992d26114f
Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents:
123
diff
changeset
|
50 // NOTE: Make sure to match the descriptor |
0d992d26114f
Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents:
123
diff
changeset
|
51 void usb_keyboard_toHost() |
0d992d26114f
Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents:
123
diff
changeset
|
52 { |
0d992d26114f
Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents:
123
diff
changeset
|
53 uint8_t i; |
123
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
54 |
165
0d992d26114f
Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents:
123
diff
changeset
|
55 // Modifiers |
0d992d26114f
Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents:
123
diff
changeset
|
56 UEDATX = USBKeys_Modifiers; |
123
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
57 |
223
fc3b9cb190cc
Adding NKRO support to AVR/DPH.
Jacob Alexander <haata@kiibohd.com>
parents:
212
diff
changeset
|
58 // Reserved Byte |
fc3b9cb190cc
Adding NKRO support to AVR/DPH.
Jacob Alexander <haata@kiibohd.com>
parents:
212
diff
changeset
|
59 UEDATX = 0x00; |
212
2794931a4d30
DPH controller now working with macros/layers
Jacob Alexander <haata@kiibohd.com>
parents:
177
diff
changeset
|
60 |
223
fc3b9cb190cc
Adding NKRO support to AVR/DPH.
Jacob Alexander <haata@kiibohd.com>
parents:
212
diff
changeset
|
61 // Normal Keys, only supports 6 in Boot mode |
165
0d992d26114f
Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents:
123
diff
changeset
|
62 for ( i = 0; i < 6; i++) |
0d992d26114f
Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents:
123
diff
changeset
|
63 { |
223
fc3b9cb190cc
Adding NKRO support to AVR/DPH.
Jacob Alexander <haata@kiibohd.com>
parents:
212
diff
changeset
|
64 UEDATX = USBKeys_Keys[i]; |
165
0d992d26114f
Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents:
123
diff
changeset
|
65 } |
223
fc3b9cb190cc
Adding NKRO support to AVR/DPH.
Jacob Alexander <haata@kiibohd.com>
parents:
212
diff
changeset
|
66 UEINTX = 0x00; |
123
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
67 } |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
68 |
223
fc3b9cb190cc
Adding NKRO support to AVR/DPH.
Jacob Alexander <haata@kiibohd.com>
parents:
212
diff
changeset
|
69 // send the contents of USBKeys_Keys and USBKeys_Modifiers |
fc3b9cb190cc
Adding NKRO support to AVR/DPH.
Jacob Alexander <haata@kiibohd.com>
parents:
212
diff
changeset
|
70 inline void usb_keyboard_send() |
123
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
71 { |
165
0d992d26114f
Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents:
123
diff
changeset
|
72 uint8_t intr_state, timeout; |
123
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
73 |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
74 intr_state = SREG; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
75 timeout = UDFNUML + 50; |
165
0d992d26114f
Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents:
123
diff
changeset
|
76 |
0d992d26114f
Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents:
123
diff
changeset
|
77 // Ready to transmit keypresses? |
0d992d26114f
Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents:
123
diff
changeset
|
78 do |
0d992d26114f
Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents:
123
diff
changeset
|
79 { |
123
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
80 SREG = intr_state; |
165
0d992d26114f
Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents:
123
diff
changeset
|
81 |
0d992d26114f
Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents:
123
diff
changeset
|
82 // has the USB gone offline? or exceeded timeout? |
0d992d26114f
Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents:
123
diff
changeset
|
83 if ( !usb_configuration || UDFNUML == timeout ) |
223
fc3b9cb190cc
Adding NKRO support to AVR/DPH.
Jacob Alexander <haata@kiibohd.com>
parents:
212
diff
changeset
|
84 { |
fc3b9cb190cc
Adding NKRO support to AVR/DPH.
Jacob Alexander <haata@kiibohd.com>
parents:
212
diff
changeset
|
85 erro_print("USB Offline? Timeout?"); |
fc3b9cb190cc
Adding NKRO support to AVR/DPH.
Jacob Alexander <haata@kiibohd.com>
parents:
212
diff
changeset
|
86 return; |
fc3b9cb190cc
Adding NKRO support to AVR/DPH.
Jacob Alexander <haata@kiibohd.com>
parents:
212
diff
changeset
|
87 } |
165
0d992d26114f
Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents:
123
diff
changeset
|
88 |
123
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
89 // get ready to try checking again |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
90 intr_state = SREG; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
91 cli(); |
165
0d992d26114f
Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents:
123
diff
changeset
|
92 |
0d992d26114f
Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents:
123
diff
changeset
|
93 // If not using Boot protocol, send NKRO |
223
fc3b9cb190cc
Adding NKRO support to AVR/DPH.
Jacob Alexander <haata@kiibohd.com>
parents:
212
diff
changeset
|
94 UENUM = USBKeys_Protocol ? KEYBOARD_NKRO_ENDPOINT : KEYBOARD_ENDPOINT; |
165
0d992d26114f
Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents:
123
diff
changeset
|
95 } while ( !( UEINTX & (1 << RWAL) ) ); |
0d992d26114f
Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents:
123
diff
changeset
|
96 |
223
fc3b9cb190cc
Adding NKRO support to AVR/DPH.
Jacob Alexander <haata@kiibohd.com>
parents:
212
diff
changeset
|
97 switch ( USBKeys_Protocol ) |
fc3b9cb190cc
Adding NKRO support to AVR/DPH.
Jacob Alexander <haata@kiibohd.com>
parents:
212
diff
changeset
|
98 { |
fc3b9cb190cc
Adding NKRO support to AVR/DPH.
Jacob Alexander <haata@kiibohd.com>
parents:
212
diff
changeset
|
99 // Send boot keyboard interrupt packet(s) |
fc3b9cb190cc
Adding NKRO support to AVR/DPH.
Jacob Alexander <haata@kiibohd.com>
parents:
212
diff
changeset
|
100 case 0: |
fc3b9cb190cc
Adding NKRO support to AVR/DPH.
Jacob Alexander <haata@kiibohd.com>
parents:
212
diff
changeset
|
101 usb_keyboard_toHost(); |
224
138e5ca7f8e4
Preparing ARM for USB NKRO
Jacob Alexander <haata@kiibohd.com>
parents:
223
diff
changeset
|
102 USBKeys_Changed = USBKeyChangeState_None; |
223
fc3b9cb190cc
Adding NKRO support to AVR/DPH.
Jacob Alexander <haata@kiibohd.com>
parents:
212
diff
changeset
|
103 break; |
fc3b9cb190cc
Adding NKRO support to AVR/DPH.
Jacob Alexander <haata@kiibohd.com>
parents:
212
diff
changeset
|
104 |
fc3b9cb190cc
Adding NKRO support to AVR/DPH.
Jacob Alexander <haata@kiibohd.com>
parents:
212
diff
changeset
|
105 // Send NKRO keyboard interrupts packet(s) |
fc3b9cb190cc
Adding NKRO support to AVR/DPH.
Jacob Alexander <haata@kiibohd.com>
parents:
212
diff
changeset
|
106 case 1: |
fc3b9cb190cc
Adding NKRO support to AVR/DPH.
Jacob Alexander <haata@kiibohd.com>
parents:
212
diff
changeset
|
107 // Check modifiers |
fc3b9cb190cc
Adding NKRO support to AVR/DPH.
Jacob Alexander <haata@kiibohd.com>
parents:
212
diff
changeset
|
108 if ( USBKeys_Changed & USBKeyChangeState_Modifiers ) |
fc3b9cb190cc
Adding NKRO support to AVR/DPH.
Jacob Alexander <haata@kiibohd.com>
parents:
212
diff
changeset
|
109 { |
fc3b9cb190cc
Adding NKRO support to AVR/DPH.
Jacob Alexander <haata@kiibohd.com>
parents:
212
diff
changeset
|
110 UEDATX = 0x01; // ID |
fc3b9cb190cc
Adding NKRO support to AVR/DPH.
Jacob Alexander <haata@kiibohd.com>
parents:
212
diff
changeset
|
111 UEDATX = USBKeys_Modifiers; |
fc3b9cb190cc
Adding NKRO support to AVR/DPH.
Jacob Alexander <haata@kiibohd.com>
parents:
212
diff
changeset
|
112 UEINTX = 0; // Finished with ID |
fc3b9cb190cc
Adding NKRO support to AVR/DPH.
Jacob Alexander <haata@kiibohd.com>
parents:
212
diff
changeset
|
113 |
fc3b9cb190cc
Adding NKRO support to AVR/DPH.
Jacob Alexander <haata@kiibohd.com>
parents:
212
diff
changeset
|
114 USBKeys_Changed &= ~USBKeyChangeState_Modifiers; // Mark sent |
fc3b9cb190cc
Adding NKRO support to AVR/DPH.
Jacob Alexander <haata@kiibohd.com>
parents:
212
diff
changeset
|
115 } |
fc3b9cb190cc
Adding NKRO support to AVR/DPH.
Jacob Alexander <haata@kiibohd.com>
parents:
212
diff
changeset
|
116 // Check main key section |
fc3b9cb190cc
Adding NKRO support to AVR/DPH.
Jacob Alexander <haata@kiibohd.com>
parents:
212
diff
changeset
|
117 else if ( USBKeys_Changed & USBKeyChangeState_MainKeys ) |
fc3b9cb190cc
Adding NKRO support to AVR/DPH.
Jacob Alexander <haata@kiibohd.com>
parents:
212
diff
changeset
|
118 { |
fc3b9cb190cc
Adding NKRO support to AVR/DPH.
Jacob Alexander <haata@kiibohd.com>
parents:
212
diff
changeset
|
119 UEDATX = 0x03; // ID |
fc3b9cb190cc
Adding NKRO support to AVR/DPH.
Jacob Alexander <haata@kiibohd.com>
parents:
212
diff
changeset
|
120 |
fc3b9cb190cc
Adding NKRO support to AVR/DPH.
Jacob Alexander <haata@kiibohd.com>
parents:
212
diff
changeset
|
121 // 4-164 (first 20 bytes) |
fc3b9cb190cc
Adding NKRO support to AVR/DPH.
Jacob Alexander <haata@kiibohd.com>
parents:
212
diff
changeset
|
122 for ( uint8_t byte = 0; byte < 20; byte++ ) |
fc3b9cb190cc
Adding NKRO support to AVR/DPH.
Jacob Alexander <haata@kiibohd.com>
parents:
212
diff
changeset
|
123 UEDATX = USBKeys_Keys[ byte ]; |
fc3b9cb190cc
Adding NKRO support to AVR/DPH.
Jacob Alexander <haata@kiibohd.com>
parents:
212
diff
changeset
|
124 |
fc3b9cb190cc
Adding NKRO support to AVR/DPH.
Jacob Alexander <haata@kiibohd.com>
parents:
212
diff
changeset
|
125 UEINTX = 0; // Finished with ID |
fc3b9cb190cc
Adding NKRO support to AVR/DPH.
Jacob Alexander <haata@kiibohd.com>
parents:
212
diff
changeset
|
126 |
fc3b9cb190cc
Adding NKRO support to AVR/DPH.
Jacob Alexander <haata@kiibohd.com>
parents:
212
diff
changeset
|
127 USBKeys_Changed &= ~USBKeyChangeState_MainKeys; // Mark sent |
fc3b9cb190cc
Adding NKRO support to AVR/DPH.
Jacob Alexander <haata@kiibohd.com>
parents:
212
diff
changeset
|
128 } |
fc3b9cb190cc
Adding NKRO support to AVR/DPH.
Jacob Alexander <haata@kiibohd.com>
parents:
212
diff
changeset
|
129 // Check secondary key section |
fc3b9cb190cc
Adding NKRO support to AVR/DPH.
Jacob Alexander <haata@kiibohd.com>
parents:
212
diff
changeset
|
130 else if ( USBKeys_Changed & USBKeyChangeState_SecondaryKeys ) |
fc3b9cb190cc
Adding NKRO support to AVR/DPH.
Jacob Alexander <haata@kiibohd.com>
parents:
212
diff
changeset
|
131 { |
fc3b9cb190cc
Adding NKRO support to AVR/DPH.
Jacob Alexander <haata@kiibohd.com>
parents:
212
diff
changeset
|
132 UEDATX = 0x04; // ID |
fc3b9cb190cc
Adding NKRO support to AVR/DPH.
Jacob Alexander <haata@kiibohd.com>
parents:
212
diff
changeset
|
133 |
fc3b9cb190cc
Adding NKRO support to AVR/DPH.
Jacob Alexander <haata@kiibohd.com>
parents:
212
diff
changeset
|
134 // 176-221 (last 6 bytes) |
fc3b9cb190cc
Adding NKRO support to AVR/DPH.
Jacob Alexander <haata@kiibohd.com>
parents:
212
diff
changeset
|
135 for ( uint8_t byte = 20; byte < 26; byte++ ) |
fc3b9cb190cc
Adding NKRO support to AVR/DPH.
Jacob Alexander <haata@kiibohd.com>
parents:
212
diff
changeset
|
136 UEDATX = USBKeys_Keys[ byte ]; |
fc3b9cb190cc
Adding NKRO support to AVR/DPH.
Jacob Alexander <haata@kiibohd.com>
parents:
212
diff
changeset
|
137 |
fc3b9cb190cc
Adding NKRO support to AVR/DPH.
Jacob Alexander <haata@kiibohd.com>
parents:
212
diff
changeset
|
138 UEINTX = 0; // Finished with ID |
fc3b9cb190cc
Adding NKRO support to AVR/DPH.
Jacob Alexander <haata@kiibohd.com>
parents:
212
diff
changeset
|
139 |
fc3b9cb190cc
Adding NKRO support to AVR/DPH.
Jacob Alexander <haata@kiibohd.com>
parents:
212
diff
changeset
|
140 USBKeys_Changed &= ~USBKeyChangeState_SecondaryKeys; // Mark sent |
fc3b9cb190cc
Adding NKRO support to AVR/DPH.
Jacob Alexander <haata@kiibohd.com>
parents:
212
diff
changeset
|
141 } |
fc3b9cb190cc
Adding NKRO support to AVR/DPH.
Jacob Alexander <haata@kiibohd.com>
parents:
212
diff
changeset
|
142 // Check system control keys |
fc3b9cb190cc
Adding NKRO support to AVR/DPH.
Jacob Alexander <haata@kiibohd.com>
parents:
212
diff
changeset
|
143 else if ( USBKeys_Changed & USBKeyChangeState_System ) |
fc3b9cb190cc
Adding NKRO support to AVR/DPH.
Jacob Alexander <haata@kiibohd.com>
parents:
212
diff
changeset
|
144 { |
fc3b9cb190cc
Adding NKRO support to AVR/DPH.
Jacob Alexander <haata@kiibohd.com>
parents:
212
diff
changeset
|
145 UEDATX = 0x05; // ID |
fc3b9cb190cc
Adding NKRO support to AVR/DPH.
Jacob Alexander <haata@kiibohd.com>
parents:
212
diff
changeset
|
146 UEDATX = USBKeys_SysCtrl; |
fc3b9cb190cc
Adding NKRO support to AVR/DPH.
Jacob Alexander <haata@kiibohd.com>
parents:
212
diff
changeset
|
147 UEINTX = 0; // Finished with ID |
fc3b9cb190cc
Adding NKRO support to AVR/DPH.
Jacob Alexander <haata@kiibohd.com>
parents:
212
diff
changeset
|
148 |
fc3b9cb190cc
Adding NKRO support to AVR/DPH.
Jacob Alexander <haata@kiibohd.com>
parents:
212
diff
changeset
|
149 USBKeys_Changed &= ~USBKeyChangeState_System; // Mark sent |
fc3b9cb190cc
Adding NKRO support to AVR/DPH.
Jacob Alexander <haata@kiibohd.com>
parents:
212
diff
changeset
|
150 } |
fc3b9cb190cc
Adding NKRO support to AVR/DPH.
Jacob Alexander <haata@kiibohd.com>
parents:
212
diff
changeset
|
151 // Check consumer control keys |
fc3b9cb190cc
Adding NKRO support to AVR/DPH.
Jacob Alexander <haata@kiibohd.com>
parents:
212
diff
changeset
|
152 else if ( USBKeys_Changed & USBKeyChangeState_Consumer ) |
fc3b9cb190cc
Adding NKRO support to AVR/DPH.
Jacob Alexander <haata@kiibohd.com>
parents:
212
diff
changeset
|
153 { |
fc3b9cb190cc
Adding NKRO support to AVR/DPH.
Jacob Alexander <haata@kiibohd.com>
parents:
212
diff
changeset
|
154 UEDATX = 0x06; // ID |
fc3b9cb190cc
Adding NKRO support to AVR/DPH.
Jacob Alexander <haata@kiibohd.com>
parents:
212
diff
changeset
|
155 UEDATX = (uint8_t)(USBKeys_ConsCtrl & 0x00FF); |
fc3b9cb190cc
Adding NKRO support to AVR/DPH.
Jacob Alexander <haata@kiibohd.com>
parents:
212
diff
changeset
|
156 UEDATX = (uint8_t)(USBKeys_ConsCtrl >> 8); |
fc3b9cb190cc
Adding NKRO support to AVR/DPH.
Jacob Alexander <haata@kiibohd.com>
parents:
212
diff
changeset
|
157 UEINTX = 0; // Finished with ID |
fc3b9cb190cc
Adding NKRO support to AVR/DPH.
Jacob Alexander <haata@kiibohd.com>
parents:
212
diff
changeset
|
158 |
fc3b9cb190cc
Adding NKRO support to AVR/DPH.
Jacob Alexander <haata@kiibohd.com>
parents:
212
diff
changeset
|
159 USBKeys_Changed &= ~USBKeyChangeState_Consumer; // Mark sent |
fc3b9cb190cc
Adding NKRO support to AVR/DPH.
Jacob Alexander <haata@kiibohd.com>
parents:
212
diff
changeset
|
160 } |
fc3b9cb190cc
Adding NKRO support to AVR/DPH.
Jacob Alexander <haata@kiibohd.com>
parents:
212
diff
changeset
|
161 |
fc3b9cb190cc
Adding NKRO support to AVR/DPH.
Jacob Alexander <haata@kiibohd.com>
parents:
212
diff
changeset
|
162 break; |
fc3b9cb190cc
Adding NKRO support to AVR/DPH.
Jacob Alexander <haata@kiibohd.com>
parents:
212
diff
changeset
|
163 } |
165
0d992d26114f
Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents:
123
diff
changeset
|
164 |
123
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
165 USBKeys_Idle_Count = 0; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
166 SREG = intr_state; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
167 } |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
168 |
165
0d992d26114f
Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents:
123
diff
changeset
|
169 |
0d992d26114f
Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents:
123
diff
changeset
|
170 |
0d992d26114f
Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents:
123
diff
changeset
|
171 // ----- USB Virtual Serial Port (CDC) Functions ----- |
0d992d26114f
Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents:
123
diff
changeset
|
172 |
123
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
173 // get the next character, or -1 if nothing received |
225 | 174 int16_t usb_serial_getchar() |
123
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
175 { |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
176 uint8_t c, intr_state; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
177 |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
178 // interrupts are disabled so these functions can be |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
179 // used from the main program or interrupt context, |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
180 // even both in the same program! |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
181 intr_state = SREG; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
182 cli(); |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
183 if (!usb_configuration) { |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
184 SREG = intr_state; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
185 return -1; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
186 } |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
187 UENUM = CDC_RX_ENDPOINT; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
188 retry: |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
189 c = UEINTX; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
190 if (!(c & (1<<RWAL))) { |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
191 // no data in buffer |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
192 if (c & (1<<RXOUTI)) { |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
193 UEINTX = 0x6B; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
194 goto retry; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
195 } |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
196 SREG = intr_state; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
197 return -2; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
198 } |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
199 // take one byte out of the buffer |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
200 c = UEDATX; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
201 // if buffer completely used, release it |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
202 if (!(UEINTX & (1<<RWAL))) UEINTX = 0x6B; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
203 SREG = intr_state; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
204 return c; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
205 } |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
206 |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
207 // number of bytes available in the receive buffer |
225 | 208 uint8_t usb_serial_available() |
123
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
209 { |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
210 uint8_t n=0, i, intr_state; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
211 |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
212 intr_state = SREG; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
213 cli(); |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
214 if (usb_configuration) { |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
215 UENUM = CDC_RX_ENDPOINT; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
216 n = UEBCLX; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
217 if (!n) { |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
218 i = UEINTX; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
219 if (i & (1<<RXOUTI) && !(i & (1<<RWAL))) UEINTX = 0x6B; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
220 } |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
221 } |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
222 SREG = intr_state; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
223 return n; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
224 } |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
225 |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
226 // discard any buffered input |
225 | 227 void usb_serial_flush_input() |
123
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
228 { |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
229 uint8_t intr_state; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
230 |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
231 if (usb_configuration) { |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
232 intr_state = SREG; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
233 cli(); |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
234 UENUM = CDC_RX_ENDPOINT; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
235 while ((UEINTX & (1<<RWAL))) { |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
236 UEINTX = 0x6B; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
237 } |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
238 SREG = intr_state; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
239 } |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
240 } |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
241 |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
242 // transmit a character. 0 returned on success, -1 on error |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
243 int8_t usb_serial_putchar(uint8_t c) |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
244 { |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
245 uint8_t timeout, intr_state; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
246 |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
247 // if we're not online (enumerated and configured), error |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
248 if (!usb_configuration) return -1; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
249 // interrupts are disabled so these functions can be |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
250 // used from the main program or interrupt context, |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
251 // even both in the same program! |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
252 intr_state = SREG; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
253 cli(); |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
254 UENUM = CDC_TX_ENDPOINT; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
255 // if we gave up due to timeout before, don't wait again |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
256 if (transmit_previous_timeout) { |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
257 if (!(UEINTX & (1<<RWAL))) { |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
258 SREG = intr_state; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
259 return -1; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
260 } |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
261 transmit_previous_timeout = 0; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
262 } |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
263 // wait for the FIFO to be ready to accept data |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
264 timeout = UDFNUML + TRANSMIT_TIMEOUT; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
265 while (1) { |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
266 // are we ready to transmit? |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
267 if (UEINTX & (1<<RWAL)) break; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
268 SREG = intr_state; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
269 // have we waited too long? This happens if the user |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
270 // is not running an application that is listening |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
271 if (UDFNUML == timeout) { |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
272 transmit_previous_timeout = 1; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
273 return -1; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
274 } |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
275 // has the USB gone offline? |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
276 if (!usb_configuration) return -1; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
277 // get ready to try checking again |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
278 intr_state = SREG; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
279 cli(); |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
280 UENUM = CDC_TX_ENDPOINT; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
281 } |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
282 // actually write the byte into the FIFO |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
283 UEDATX = c; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
284 // if this completed a packet, transmit it now! |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
285 if (!(UEINTX & (1<<RWAL))) UEINTX = 0x3A; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
286 transmit_flush_timer = TRANSMIT_FLUSH_TIMEOUT; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
287 SREG = intr_state; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
288 return 0; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
289 } |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
290 |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
291 |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
292 // transmit a character, but do not wait if the buffer is full, |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
293 // 0 returned on success, -1 on buffer full or error |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
294 int8_t usb_serial_putchar_nowait(uint8_t c) |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
295 { |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
296 uint8_t intr_state; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
297 |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
298 if (!usb_configuration) return -1; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
299 intr_state = SREG; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
300 cli(); |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
301 UENUM = CDC_TX_ENDPOINT; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
302 if (!(UEINTX & (1<<RWAL))) { |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
303 // buffer is full |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
304 SREG = intr_state; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
305 return -2; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
306 } |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
307 // actually write the byte into the FIFO |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
308 UEDATX = c; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
309 // if this completed a packet, transmit it now! |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
310 if (!(UEINTX & (1<<RWAL))) UEINTX = 0x3A; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
311 transmit_flush_timer = TRANSMIT_FLUSH_TIMEOUT; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
312 SREG = intr_state; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
313 return 0; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
314 } |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
315 |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
316 // transmit a buffer. |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
317 // 0 returned on success, -1 on error |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
318 // This function is optimized for speed! Each call takes approx 6.1 us overhead |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
319 // plus 0.25 us per byte. 12 Mbit/sec USB has 8.67 us per-packet overhead and |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
320 // takes 0.67 us per byte. If called with 64 byte packet-size blocks, this function |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
321 // can transmit at full USB speed using 43% CPU time. The maximum theoretical speed |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
322 // is 19 packets per USB frame, or 1216 kbytes/sec. However, bulk endpoints have the |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
323 // lowest priority, so any other USB devices will likely reduce the speed. Speed |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
324 // can also be limited by how quickly the PC-based software reads data, as the host |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
325 // controller in the PC will not allocate bandwitdh without a pending read request. |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
326 // (thanks to Victor Suarez for testing and feedback and initial code) |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
327 |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
328 int8_t usb_serial_write(const char *buffer, uint16_t size) |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
329 { |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
330 uint8_t timeout, intr_state, write_size; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
331 |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
332 // if we're not online (enumerated and configured), error |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
333 if (!usb_configuration) return -1; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
334 // interrupts are disabled so these functions can be |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
335 // used from the main program or interrupt context, |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
336 // even both in the same program! |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
337 intr_state = SREG; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
338 cli(); |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
339 UENUM = CDC_TX_ENDPOINT; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
340 // if we gave up due to timeout before, don't wait again |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
341 /* |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
342 if (transmit_previous_timeout) { |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
343 if (!(UEINTX & (1<<RWAL))) { |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
344 SREG = intr_state; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
345 return -2; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
346 } |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
347 transmit_previous_timeout = 0; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
348 } |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
349 */ |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
350 // each iteration of this loop transmits a packet |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
351 while (size) { |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
352 // wait for the FIFO to be ready to accept data |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
353 timeout = UDFNUML + TRANSMIT_TIMEOUT; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
354 while (1) { |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
355 // are we ready to transmit? |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
356 if (UEINTX & (1<<RWAL)) break; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
357 SREG = intr_state; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
358 // have we waited too long? This happens if the user |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
359 // is not running an application that is listening |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
360 if (UDFNUML == timeout) { |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
361 transmit_previous_timeout = 1; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
362 return -3; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
363 } |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
364 // has the USB gone offline? |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
365 if (!usb_configuration) return -4; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
366 // get ready to try checking again |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
367 intr_state = SREG; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
368 cli(); |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
369 UENUM = CDC_TX_ENDPOINT; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
370 } |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
371 |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
372 // compute how many bytes will fit into the next packet |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
373 write_size = CDC_TX_SIZE - UEBCLX; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
374 if (write_size > size) write_size = size; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
375 size -= write_size; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
376 |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
377 // write the packet |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
378 switch (write_size) { |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
379 #if (CDC_TX_SIZE == 64) |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
380 case 64: UEDATX = *buffer++; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
381 case 63: UEDATX = *buffer++; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
382 case 62: UEDATX = *buffer++; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
383 case 61: UEDATX = *buffer++; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
384 case 60: UEDATX = *buffer++; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
385 case 59: UEDATX = *buffer++; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
386 case 58: UEDATX = *buffer++; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
387 case 57: UEDATX = *buffer++; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
388 case 56: UEDATX = *buffer++; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
389 case 55: UEDATX = *buffer++; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
390 case 54: UEDATX = *buffer++; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
391 case 53: UEDATX = *buffer++; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
392 case 52: UEDATX = *buffer++; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
393 case 51: UEDATX = *buffer++; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
394 case 50: UEDATX = *buffer++; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
395 case 49: UEDATX = *buffer++; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
396 case 48: UEDATX = *buffer++; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
397 case 47: UEDATX = *buffer++; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
398 case 46: UEDATX = *buffer++; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
399 case 45: UEDATX = *buffer++; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
400 case 44: UEDATX = *buffer++; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
401 case 43: UEDATX = *buffer++; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
402 case 42: UEDATX = *buffer++; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
403 case 41: UEDATX = *buffer++; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
404 case 40: UEDATX = *buffer++; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
405 case 39: UEDATX = *buffer++; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
406 case 38: UEDATX = *buffer++; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
407 case 37: UEDATX = *buffer++; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
408 case 36: UEDATX = *buffer++; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
409 case 35: UEDATX = *buffer++; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
410 case 34: UEDATX = *buffer++; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
411 case 33: UEDATX = *buffer++; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
412 #endif |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
413 #if (CDC_TX_SIZE >= 32) |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
414 case 32: UEDATX = *buffer++; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
415 case 31: UEDATX = *buffer++; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
416 case 30: UEDATX = *buffer++; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
417 case 29: UEDATX = *buffer++; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
418 case 28: UEDATX = *buffer++; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
419 case 27: UEDATX = *buffer++; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
420 case 26: UEDATX = *buffer++; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
421 case 25: UEDATX = *buffer++; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
422 case 24: UEDATX = *buffer++; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
423 case 23: UEDATX = *buffer++; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
424 case 22: UEDATX = *buffer++; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
425 case 21: UEDATX = *buffer++; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
426 case 20: UEDATX = *buffer++; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
427 case 19: UEDATX = *buffer++; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
428 case 18: UEDATX = *buffer++; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
429 case 17: UEDATX = *buffer++; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
430 #endif |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
431 #if (CDC_TX_SIZE >= 16) |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
432 case 16: UEDATX = *buffer++; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
433 case 15: UEDATX = *buffer++; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
434 case 14: UEDATX = *buffer++; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
435 case 13: UEDATX = *buffer++; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
436 case 12: UEDATX = *buffer++; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
437 case 11: UEDATX = *buffer++; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
438 case 10: UEDATX = *buffer++; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
439 case 9: UEDATX = *buffer++; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
440 #endif |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
441 case 8: UEDATX = *buffer++; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
442 case 7: UEDATX = *buffer++; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
443 case 6: UEDATX = *buffer++; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
444 case 5: UEDATX = *buffer++; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
445 case 4: UEDATX = *buffer++; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
446 case 3: UEDATX = *buffer++; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
447 case 2: UEDATX = *buffer++; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
448 default: |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
449 case 1: UEDATX = *buffer++; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
450 case 0: break; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
451 } |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
452 // if this completed a packet, transmit it now! |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
453 if (!(UEINTX & (1<<RWAL))) UEINTX = 0x3A; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
454 transmit_flush_timer = TRANSMIT_FLUSH_TIMEOUT; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
455 SREG = intr_state; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
456 } |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
457 return 0; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
458 } |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
459 |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
460 // immediately transmit any buffered output. |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
461 // This doesn't actually transmit the data - that is impossible! |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
462 // USB devices only transmit when the host allows, so the best |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
463 // we can do is release the FIFO buffer for when the host wants it |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
464 void usb_serial_flush_output(void) |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
465 { |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
466 uint8_t intr_state; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
467 |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
468 intr_state = SREG; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
469 cli(); |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
470 if (transmit_flush_timer) { |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
471 UENUM = CDC_TX_ENDPOINT; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
472 UEINTX = 0x3A; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
473 transmit_flush_timer = 0; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
474 } |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
475 SREG = intr_state; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
476 } |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
477 |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
478 // functions to read the various async serial settings. These |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
479 // aren't actually used by USB at all (communication is always |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
480 // at full USB speed), but they are set by the host so we can |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
481 // set them properly if we're converting the USB to a real serial |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
482 // communication |
225 | 483 uint32_t usb_serial_get_baud() |
123
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
484 { |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
485 uint32_t *baud = (uint32_t*)cdc_line_coding; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
486 return *baud; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
487 } |
225 | 488 uint8_t usb_serial_get_stopbits() |
123
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
489 { |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
490 return cdc_line_coding[4]; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
491 } |
225 | 492 uint8_t usb_serial_get_paritytype() |
123
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
493 { |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
494 return cdc_line_coding[5]; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
495 } |
225 | 496 uint8_t usb_serial_get_numbits() |
123
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
497 { |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
498 return cdc_line_coding[6]; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
499 } |
225 | 500 uint8_t usb_serial_get_control() |
123
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
501 { |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
502 return cdc_line_rtsdtr; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
503 } |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
504 |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
505 // write the control signals, DCD, DSR, RI, etc |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
506 // There is no CTS signal. If software on the host has transmitted |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
507 // data to you but you haven't been calling the getchar function, |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
508 // it remains buffered (either here or on the host) and can not be |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
509 // lost because you weren't listening at the right time, like it |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
510 // would in real serial communication. |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
511 int8_t usb_serial_set_control(uint8_t signals) |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
512 { |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
513 uint8_t intr_state; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
514 |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
515 intr_state = SREG; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
516 cli(); |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
517 if (!usb_configuration) { |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
518 // we're not enumerated/configured |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
519 SREG = intr_state; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
520 return -1; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
521 } |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
522 |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
523 UENUM = CDC_ACM_ENDPOINT; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
524 if (!(UEINTX & (1<<RWAL))) { |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
525 // unable to write |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
526 // TODO; should this try to abort the previously |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
527 // buffered message?? |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
528 SREG = intr_state; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
529 return -1; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
530 } |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
531 UEDATX = 0xA1; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
532 UEDATX = 0x20; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
533 UEDATX = 0; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
534 UEDATX = 0; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
535 UEDATX = 0; // 0 seems to work nicely. what if this is 1?? |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
536 UEDATX = 0; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
537 UEDATX = 1; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
538 UEDATX = 0; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
539 UEDATX = signals; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
540 UEINTX = 0x3A; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
541 SREG = intr_state; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
542 return 0; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
543 } |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
544 |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
545 |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
546 |
165
0d992d26114f
Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents:
123
diff
changeset
|
547 // ----- General USB Functions ----- |
0d992d26114f
Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents:
123
diff
changeset
|
548 |
0d992d26114f
Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents:
123
diff
changeset
|
549 // Set the avr into firmware reload mode |
177
3420e018ffbc
Adding McHCK flash reload function and some cleanup.
Jacob Alexander <haata@kiibohd.com>
parents:
165
diff
changeset
|
550 void usb_device_reload() |
165
0d992d26114f
Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents:
123
diff
changeset
|
551 { |
0d992d26114f
Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents:
123
diff
changeset
|
552 cli(); |
0d992d26114f
Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents:
123
diff
changeset
|
553 // Disable watchdog, if enabled |
0d992d26114f
Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents:
123
diff
changeset
|
554 // Disable all peripherals |
0d992d26114f
Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents:
123
diff
changeset
|
555 |
0d992d26114f
Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents:
123
diff
changeset
|
556 UDCON = 1; |
0d992d26114f
Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents:
123
diff
changeset
|
557 USBCON = (1 << FRZCLK); // Disable USB |
0d992d26114f
Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents:
123
diff
changeset
|
558 UCSR1B = 0; |
0d992d26114f
Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents:
123
diff
changeset
|
559 _delay_ms( 5 ); |
0d992d26114f
Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents:
123
diff
changeset
|
560 |
0d992d26114f
Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents:
123
diff
changeset
|
561 #if defined(__AVR_AT90USB162__) // Teensy 1.0 |
0d992d26114f
Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents:
123
diff
changeset
|
562 EIMSK = 0; PCICR = 0; SPCR = 0; ACSR = 0; EECR = 0; |
0d992d26114f
Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents:
123
diff
changeset
|
563 TIMSK0 = 0; TIMSK1 = 0; UCSR1B = 0; |
0d992d26114f
Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents:
123
diff
changeset
|
564 DDRB = 0; DDRC = 0; DDRD = 0; |
0d992d26114f
Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents:
123
diff
changeset
|
565 PORTB = 0; PORTC = 0; PORTD = 0; |
0d992d26114f
Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents:
123
diff
changeset
|
566 asm volatile("jmp 0x3E00"); |
0d992d26114f
Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents:
123
diff
changeset
|
567 #elif defined(__AVR_ATmega32U4__) // Teensy 2.0 |
0d992d26114f
Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents:
123
diff
changeset
|
568 EIMSK = 0; PCICR = 0; SPCR = 0; ACSR = 0; EECR = 0; ADCSRA = 0; |
0d992d26114f
Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents:
123
diff
changeset
|
569 TIMSK0 = 0; TIMSK1 = 0; TIMSK3 = 0; TIMSK4 = 0; UCSR1B = 0; TWCR = 0; |
0d992d26114f
Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents:
123
diff
changeset
|
570 DDRB = 0; DDRC = 0; DDRD = 0; DDRE = 0; DDRF = 0; TWCR = 0; |
0d992d26114f
Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents:
123
diff
changeset
|
571 PORTB = 0; PORTC = 0; PORTD = 0; PORTE = 0; PORTF = 0; |
0d992d26114f
Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents:
123
diff
changeset
|
572 asm volatile("jmp 0x7E00"); |
0d992d26114f
Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents:
123
diff
changeset
|
573 #elif defined(__AVR_AT90USB646__) // Teensy++ 1.0 |
0d992d26114f
Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents:
123
diff
changeset
|
574 EIMSK = 0; PCICR = 0; SPCR = 0; ACSR = 0; EECR = 0; ADCSRA = 0; |
0d992d26114f
Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents:
123
diff
changeset
|
575 TIMSK0 = 0; TIMSK1 = 0; TIMSK2 = 0; TIMSK3 = 0; UCSR1B = 0; TWCR = 0; |
0d992d26114f
Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents:
123
diff
changeset
|
576 DDRA = 0; DDRB = 0; DDRC = 0; DDRD = 0; DDRE = 0; DDRF = 0; |
0d992d26114f
Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents:
123
diff
changeset
|
577 PORTA = 0; PORTB = 0; PORTC = 0; PORTD = 0; PORTE = 0; PORTF = 0; |
0d992d26114f
Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents:
123
diff
changeset
|
578 asm volatile("jmp 0xFC00"); |
0d992d26114f
Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents:
123
diff
changeset
|
579 #elif defined(__AVR_AT90USB1286__) // Teensy++ 2.0 |
0d992d26114f
Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents:
123
diff
changeset
|
580 EIMSK = 0; PCICR = 0; SPCR = 0; ACSR = 0; EECR = 0; ADCSRA = 0; |
0d992d26114f
Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents:
123
diff
changeset
|
581 TIMSK0 = 0; TIMSK1 = 0; TIMSK2 = 0; TIMSK3 = 0; UCSR1B = 0; TWCR = 0; |
0d992d26114f
Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents:
123
diff
changeset
|
582 DDRA = 0; DDRB = 0; DDRC = 0; DDRD = 0; DDRE = 0; DDRF = 0; |
0d992d26114f
Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents:
123
diff
changeset
|
583 PORTA = 0; PORTB = 0; PORTC = 0; PORTD = 0; PORTE = 0; PORTF = 0; |
0d992d26114f
Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents:
123
diff
changeset
|
584 asm volatile("jmp 0x1FC00"); |
0d992d26114f
Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents:
123
diff
changeset
|
585 #endif |
0d992d26114f
Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents:
123
diff
changeset
|
586 } |
123
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
587 |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
588 |
165
0d992d26114f
Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents:
123
diff
changeset
|
589 // WDT Setup for software reset the chip |
225 | 590 void wdt_init() |
165
0d992d26114f
Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents:
123
diff
changeset
|
591 { |
0d992d26114f
Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents:
123
diff
changeset
|
592 MCUSR = 0; |
0d992d26114f
Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents:
123
diff
changeset
|
593 wdt_disable(); |
0d992d26114f
Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents:
123
diff
changeset
|
594 } |
0d992d26114f
Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents:
123
diff
changeset
|
595 |
0d992d26114f
Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents:
123
diff
changeset
|
596 |
0d992d26114f
Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents:
123
diff
changeset
|
597 // initialize USB |
225 | 598 void usb_init() |
165
0d992d26114f
Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents:
123
diff
changeset
|
599 { |
0d992d26114f
Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents:
123
diff
changeset
|
600 HW_CONFIG(); |
0d992d26114f
Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents:
123
diff
changeset
|
601 USB_FREEZE(); // enable USB |
0d992d26114f
Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents:
123
diff
changeset
|
602 PLL_CONFIG(); // config PLL |
0d992d26114f
Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents:
123
diff
changeset
|
603 while (!(PLLCSR & (1<<PLOCK))) ; // wait for PLL lock |
0d992d26114f
Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents:
123
diff
changeset
|
604 USB_CONFIG(); // start USB clock |
0d992d26114f
Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents:
123
diff
changeset
|
605 UDCON = 0; // enable attach resistor |
0d992d26114f
Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents:
123
diff
changeset
|
606 usb_configuration = 0; |
0d992d26114f
Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents:
123
diff
changeset
|
607 UDIEN = (1<<EORSTE) | (1<<SOFE); |
0d992d26114f
Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents:
123
diff
changeset
|
608 sei(); |
0d992d26114f
Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents:
123
diff
changeset
|
609 |
0d992d26114f
Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents:
123
diff
changeset
|
610 // Disable watchdog timer after possible software reset |
0d992d26114f
Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents:
123
diff
changeset
|
611 //wdt_init(); // XXX Not working...seems to be ok without this, not sure though |
0d992d26114f
Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents:
123
diff
changeset
|
612 } |
0d992d26114f
Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents:
123
diff
changeset
|
613 |
0d992d26114f
Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents:
123
diff
changeset
|
614 // return 0 if the USB is not configured, or the configuration |
0d992d26114f
Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents:
123
diff
changeset
|
615 // number selected by the HOST |
0d992d26114f
Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents:
123
diff
changeset
|
616 uint8_t usb_configured() |
0d992d26114f
Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents:
123
diff
changeset
|
617 { |
0d992d26114f
Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents:
123
diff
changeset
|
618 return usb_configuration; |
0d992d26114f
Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents:
123
diff
changeset
|
619 } |
123
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
620 |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
621 // USB Device Interrupt - handle all device-level events |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
622 // the transmit buffer flushing is triggered by the start of frame |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
623 // |
165
0d992d26114f
Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents:
123
diff
changeset
|
624 ISR( USB_GEN_vect ) |
123
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
625 { |
165
0d992d26114f
Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents:
123
diff
changeset
|
626 uint8_t intbits, t_cdc; |
123
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
627 |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
628 intbits = UDINT; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
629 UDINT = 0; |
165
0d992d26114f
Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents:
123
diff
changeset
|
630 if ( intbits & (1 << EORSTI) ) |
0d992d26114f
Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents:
123
diff
changeset
|
631 { |
123
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
632 UENUM = 0; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
633 UECONX = 1; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
634 UECFG0X = EP_TYPE_CONTROL; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
635 UECFG1X = EP_SIZE(ENDPOINT0_SIZE) | EP_SINGLE_BUFFER; |
165
0d992d26114f
Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents:
123
diff
changeset
|
636 UEIENX = (1 << RXSTPE); |
123
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
637 usb_configuration = 0; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
638 cdc_line_rtsdtr = 0; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
639 } |
165
0d992d26114f
Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents:
123
diff
changeset
|
640 if ( (intbits & (1 << SOFI)) && usb_configuration ) |
0d992d26114f
Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents:
123
diff
changeset
|
641 { |
123
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
642 t_cdc = transmit_flush_timer; |
165
0d992d26114f
Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents:
123
diff
changeset
|
643 if ( t_cdc ) |
0d992d26114f
Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents:
123
diff
changeset
|
644 { |
123
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
645 transmit_flush_timer = --t_cdc; |
165
0d992d26114f
Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents:
123
diff
changeset
|
646 if ( !t_cdc ) |
0d992d26114f
Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents:
123
diff
changeset
|
647 { |
123
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
648 UENUM = CDC_TX_ENDPOINT; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
649 UEINTX = 0x3A; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
650 } |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
651 } |
165
0d992d26114f
Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents:
123
diff
changeset
|
652 static uint8_t div4 = 0; |
0d992d26114f
Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents:
123
diff
changeset
|
653 if ( USBKeys_Idle_Config && (++div4 & 3) == 0 ) |
0d992d26114f
Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents:
123
diff
changeset
|
654 { |
0d992d26114f
Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents:
123
diff
changeset
|
655 USBKeys_Idle_Count++; |
0d992d26114f
Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents:
123
diff
changeset
|
656 if ( USBKeys_Idle_Count == USBKeys_Idle_Config ) |
0d992d26114f
Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents:
123
diff
changeset
|
657 { |
0d992d26114f
Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents:
123
diff
changeset
|
658 // XXX TODO Is this even used? If so, when? -Jacob |
0d992d26114f
Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents:
123
diff
changeset
|
659 // From hasu's code, this section looks like it could fix the Mac SET_IDLE problem |
0d992d26114f
Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents:
123
diff
changeset
|
660 // Send normal keyboard interrupt packet(s) |
223
fc3b9cb190cc
Adding NKRO support to AVR/DPH.
Jacob Alexander <haata@kiibohd.com>
parents:
212
diff
changeset
|
661 switch ( USBKeys_Protocol ) |
fc3b9cb190cc
Adding NKRO support to AVR/DPH.
Jacob Alexander <haata@kiibohd.com>
parents:
212
diff
changeset
|
662 { |
fc3b9cb190cc
Adding NKRO support to AVR/DPH.
Jacob Alexander <haata@kiibohd.com>
parents:
212
diff
changeset
|
663 // Send boot keyboard interrupt packet(s) |
fc3b9cb190cc
Adding NKRO support to AVR/DPH.
Jacob Alexander <haata@kiibohd.com>
parents:
212
diff
changeset
|
664 case 0: usb_keyboard_toHost(); break; |
fc3b9cb190cc
Adding NKRO support to AVR/DPH.
Jacob Alexander <haata@kiibohd.com>
parents:
212
diff
changeset
|
665 // Send NKRO keyboard interrupts packet(s) |
fc3b9cb190cc
Adding NKRO support to AVR/DPH.
Jacob Alexander <haata@kiibohd.com>
parents:
212
diff
changeset
|
666 //case 1: usb_nkrokeyboard_toHost(); break; // XXX Not valid anymore |
fc3b9cb190cc
Adding NKRO support to AVR/DPH.
Jacob Alexander <haata@kiibohd.com>
parents:
212
diff
changeset
|
667 } |
212
2794931a4d30
DPH controller now working with macros/layers
Jacob Alexander <haata@kiibohd.com>
parents:
177
diff
changeset
|
668 print("IDLE"); |
123
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
669 } |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
670 } |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
671 } |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
672 } |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
673 |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
674 |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
675 |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
676 // Misc functions to wait for ready and send/receive packets |
225 | 677 static inline void usb_wait_in_ready() |
123
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
678 { |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
679 while (!(UEINTX & (1<<TXINI))) ; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
680 } |
225 | 681 static inline void usb_send_in() |
123
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
682 { |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
683 UEINTX = ~(1<<TXINI); |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
684 } |
225 | 685 static inline void usb_wait_receive_out() |
123
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
686 { |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
687 while (!(UEINTX & (1<<RXOUTI))) ; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
688 } |
225 | 689 static inline void usb_ack_out() |
123
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
690 { |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
691 UEINTX = ~(1<<RXOUTI); |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
692 } |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
693 |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
694 |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
695 |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
696 // USB Endpoint Interrupt - endpoint 0 is handled here. The |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
697 // other endpoints are manipulated by the user-callable |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
698 // functions, and the start-of-frame interrupt. |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
699 // |
225 | 700 ISR( USB_COM_vect ) |
123
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
701 { |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
702 uint8_t intbits; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
703 const uint8_t *list; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
704 const uint8_t *cfg; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
705 uint8_t i, n, len, en; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
706 uint8_t *p; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
707 uint8_t bmRequestType; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
708 uint8_t bRequest; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
709 uint16_t wValue; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
710 uint16_t wIndex; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
711 uint16_t wLength; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
712 uint16_t desc_val; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
713 const uint8_t *desc_addr; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
714 uint8_t desc_length; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
715 |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
716 UENUM = 0; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
717 intbits = UEINTX; |
223
fc3b9cb190cc
Adding NKRO support to AVR/DPH.
Jacob Alexander <haata@kiibohd.com>
parents:
212
diff
changeset
|
718 if (intbits & (1<<RXSTPI)) |
fc3b9cb190cc
Adding NKRO support to AVR/DPH.
Jacob Alexander <haata@kiibohd.com>
parents:
212
diff
changeset
|
719 { |
123
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
720 bmRequestType = UEDATX; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
721 bRequest = UEDATX; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
722 wValue = UEDATX; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
723 wValue |= (UEDATX << 8); |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
724 wIndex = UEDATX; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
725 wIndex |= (UEDATX << 8); |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
726 wLength = UEDATX; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
727 wLength |= (UEDATX << 8); |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
728 UEINTX = ~((1<<RXSTPI) | (1<<RXOUTI) | (1<<TXINI)); |
165
0d992d26114f
Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents:
123
diff
changeset
|
729 |
0d992d26114f
Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents:
123
diff
changeset
|
730 if ( bRequest == GET_DESCRIPTOR ) |
0d992d26114f
Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents:
123
diff
changeset
|
731 { |
123
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
732 list = (const uint8_t *)descriptor_list; |
165
0d992d26114f
Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents:
123
diff
changeset
|
733 for ( i = 0; ; i++ ) |
0d992d26114f
Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents:
123
diff
changeset
|
734 { |
0d992d26114f
Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents:
123
diff
changeset
|
735 if ( i >= NUM_DESC_LIST ) |
0d992d26114f
Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents:
123
diff
changeset
|
736 { |
0d992d26114f
Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents:
123
diff
changeset
|
737 UECONX = (1 << STALLRQ) | (1 << EPEN); //stall |
123
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
738 return; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
739 } |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
740 desc_val = pgm_read_word(list); |
165
0d992d26114f
Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents:
123
diff
changeset
|
741 if ( desc_val != wValue ) |
0d992d26114f
Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents:
123
diff
changeset
|
742 { |
0d992d26114f
Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents:
123
diff
changeset
|
743 list += sizeof( struct descriptor_list_struct ); |
123
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
744 continue; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
745 } |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
746 list += 2; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
747 desc_val = pgm_read_word(list); |
165
0d992d26114f
Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents:
123
diff
changeset
|
748 if ( desc_val != wIndex ) |
0d992d26114f
Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents:
123
diff
changeset
|
749 { |
0d992d26114f
Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents:
123
diff
changeset
|
750 list += sizeof(struct descriptor_list_struct) - 2; |
123
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
751 continue; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
752 } |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
753 list += 2; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
754 desc_addr = (const uint8_t *)pgm_read_word(list); |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
755 list += 2; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
756 desc_length = pgm_read_byte(list); |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
757 break; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
758 } |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
759 len = (wLength < 256) ? wLength : 255; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
760 if (len > desc_length) len = desc_length; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
761 do { |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
762 // wait for host ready for IN packet |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
763 do { |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
764 i = UEINTX; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
765 } while (!(i & ((1<<TXINI)|(1<<RXOUTI)))); |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
766 if (i & (1<<RXOUTI)) return; // abort |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
767 // send IN packet |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
768 n = len < ENDPOINT0_SIZE ? len : ENDPOINT0_SIZE; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
769 for (i = n; i; i--) { |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
770 UEDATX = pgm_read_byte(desc_addr++); |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
771 } |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
772 len -= n; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
773 usb_send_in(); |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
774 } while (len || n == ENDPOINT0_SIZE); |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
775 return; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
776 } |
165
0d992d26114f
Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents:
123
diff
changeset
|
777 |
123
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
778 if (bRequest == SET_ADDRESS) { |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
779 usb_send_in(); |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
780 usb_wait_in_ready(); |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
781 UDADDR = wValue | (1<<ADDEN); |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
782 return; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
783 } |
165
0d992d26114f
Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents:
123
diff
changeset
|
784 |
0d992d26114f
Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents:
123
diff
changeset
|
785 if ( bRequest == SET_CONFIGURATION && bmRequestType == 0 ) |
0d992d26114f
Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents:
123
diff
changeset
|
786 { |
123
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
787 usb_configuration = wValue; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
788 cdc_line_rtsdtr = 0; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
789 transmit_flush_timer = 0; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
790 usb_send_in(); |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
791 cfg = endpoint_config_table; |
165
0d992d26114f
Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents:
123
diff
changeset
|
792 // Setup each of the 6 additional endpoints (0th already configured) |
0d992d26114f
Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents:
123
diff
changeset
|
793 for ( i = 1; i < 6; i++ ) |
0d992d26114f
Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents:
123
diff
changeset
|
794 { |
123
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
795 UENUM = i; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
796 en = pgm_read_byte(cfg++); |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
797 UECONX = en; |
165
0d992d26114f
Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents:
123
diff
changeset
|
798 if (en) |
0d992d26114f
Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents:
123
diff
changeset
|
799 { |
123
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
800 UECFG0X = pgm_read_byte(cfg++); |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
801 UECFG1X = pgm_read_byte(cfg++); |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
802 } |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
803 } |
165
0d992d26114f
Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents:
123
diff
changeset
|
804 UERST = 0x7E; |
123
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
805 UERST = 0; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
806 return; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
807 } |
165
0d992d26114f
Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents:
123
diff
changeset
|
808 |
123
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
809 if (bRequest == GET_CONFIGURATION && bmRequestType == 0x80) { |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
810 usb_wait_in_ready(); |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
811 UEDATX = usb_configuration; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
812 usb_send_in(); |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
813 return; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
814 } |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
815 |
223
fc3b9cb190cc
Adding NKRO support to AVR/DPH.
Jacob Alexander <haata@kiibohd.com>
parents:
212
diff
changeset
|
816 if ( ( wIndex == KEYBOARD_INTERFACE && USBKeys_Protocol == 0 ) |
fc3b9cb190cc
Adding NKRO support to AVR/DPH.
Jacob Alexander <haata@kiibohd.com>
parents:
212
diff
changeset
|
817 || ( wIndex == KEYBOARD_NKRO_INTERFACE && USBKeys_Protocol == 1 ) ) |
165
0d992d26114f
Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents:
123
diff
changeset
|
818 { |
0d992d26114f
Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents:
123
diff
changeset
|
819 if ( bmRequestType == 0xA1) |
0d992d26114f
Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents:
123
diff
changeset
|
820 { |
0d992d26114f
Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents:
123
diff
changeset
|
821 if ( bRequest == HID_GET_REPORT ) |
0d992d26114f
Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents:
123
diff
changeset
|
822 { |
0d992d26114f
Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents:
123
diff
changeset
|
823 usb_wait_in_ready(); |
0d992d26114f
Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents:
123
diff
changeset
|
824 |
0d992d26114f
Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents:
123
diff
changeset
|
825 // Send normal keyboard interrupt packet(s) |
223
fc3b9cb190cc
Adding NKRO support to AVR/DPH.
Jacob Alexander <haata@kiibohd.com>
parents:
212
diff
changeset
|
826 switch ( USBKeys_Protocol ) |
fc3b9cb190cc
Adding NKRO support to AVR/DPH.
Jacob Alexander <haata@kiibohd.com>
parents:
212
diff
changeset
|
827 { |
fc3b9cb190cc
Adding NKRO support to AVR/DPH.
Jacob Alexander <haata@kiibohd.com>
parents:
212
diff
changeset
|
828 // Send boot keyboard interrupt packet(s) |
fc3b9cb190cc
Adding NKRO support to AVR/DPH.
Jacob Alexander <haata@kiibohd.com>
parents:
212
diff
changeset
|
829 case 0: usb_keyboard_toHost(); break; |
fc3b9cb190cc
Adding NKRO support to AVR/DPH.
Jacob Alexander <haata@kiibohd.com>
parents:
212
diff
changeset
|
830 // Send NKRO keyboard interrupts packet(s) |
fc3b9cb190cc
Adding NKRO support to AVR/DPH.
Jacob Alexander <haata@kiibohd.com>
parents:
212
diff
changeset
|
831 //case 1: usb_nkrokeyboard_toHost(); break; // XXX Not valid anymore |
fc3b9cb190cc
Adding NKRO support to AVR/DPH.
Jacob Alexander <haata@kiibohd.com>
parents:
212
diff
changeset
|
832 } |
165
0d992d26114f
Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents:
123
diff
changeset
|
833 |
0d992d26114f
Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents:
123
diff
changeset
|
834 usb_send_in(); |
0d992d26114f
Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents:
123
diff
changeset
|
835 return; |
0d992d26114f
Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents:
123
diff
changeset
|
836 } |
0d992d26114f
Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents:
123
diff
changeset
|
837 if ( bRequest == HID_GET_IDLE ) |
0d992d26114f
Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents:
123
diff
changeset
|
838 { |
0d992d26114f
Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents:
123
diff
changeset
|
839 usb_wait_in_ready(); |
0d992d26114f
Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents:
123
diff
changeset
|
840 UEDATX = USBKeys_Idle_Config; |
0d992d26114f
Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents:
123
diff
changeset
|
841 usb_send_in(); |
0d992d26114f
Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents:
123
diff
changeset
|
842 return; |
0d992d26114f
Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents:
123
diff
changeset
|
843 } |
0d992d26114f
Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents:
123
diff
changeset
|
844 if ( bRequest == HID_GET_PROTOCOL ) |
0d992d26114f
Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents:
123
diff
changeset
|
845 { |
0d992d26114f
Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents:
123
diff
changeset
|
846 usb_wait_in_ready(); |
0d992d26114f
Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents:
123
diff
changeset
|
847 UEDATX = USBKeys_Protocol; |
0d992d26114f
Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents:
123
diff
changeset
|
848 usb_send_in(); |
0d992d26114f
Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents:
123
diff
changeset
|
849 return; |
0d992d26114f
Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents:
123
diff
changeset
|
850 } |
0d992d26114f
Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents:
123
diff
changeset
|
851 } |
0d992d26114f
Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents:
123
diff
changeset
|
852 if ( bmRequestType == 0x21 ) |
0d992d26114f
Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents:
123
diff
changeset
|
853 { |
0d992d26114f
Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents:
123
diff
changeset
|
854 if ( bRequest == HID_SET_REPORT ) |
0d992d26114f
Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents:
123
diff
changeset
|
855 { |
0d992d26114f
Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents:
123
diff
changeset
|
856 usb_wait_receive_out(); |
0d992d26114f
Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents:
123
diff
changeset
|
857 USBKeys_LEDs = UEDATX; |
0d992d26114f
Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents:
123
diff
changeset
|
858 usb_ack_out(); |
0d992d26114f
Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents:
123
diff
changeset
|
859 usb_send_in(); |
0d992d26114f
Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents:
123
diff
changeset
|
860 return; |
0d992d26114f
Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents:
123
diff
changeset
|
861 } |
0d992d26114f
Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents:
123
diff
changeset
|
862 if ( bRequest == HID_SET_IDLE ) |
0d992d26114f
Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents:
123
diff
changeset
|
863 { |
223
fc3b9cb190cc
Adding NKRO support to AVR/DPH.
Jacob Alexander <haata@kiibohd.com>
parents:
212
diff
changeset
|
864 usb_wait_in_ready(); |
165
0d992d26114f
Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents:
123
diff
changeset
|
865 USBKeys_Idle_Config = (wValue >> 8); |
0d992d26114f
Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents:
123
diff
changeset
|
866 USBKeys_Idle_Count = 0; |
0d992d26114f
Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents:
123
diff
changeset
|
867 usb_send_in(); |
229 | 868 //print("HID IDLE"); |
165
0d992d26114f
Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents:
123
diff
changeset
|
869 return; |
0d992d26114f
Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents:
123
diff
changeset
|
870 } |
0d992d26114f
Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents:
123
diff
changeset
|
871 if ( bRequest == HID_SET_PROTOCOL ) |
0d992d26114f
Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents:
123
diff
changeset
|
872 { |
223
fc3b9cb190cc
Adding NKRO support to AVR/DPH.
Jacob Alexander <haata@kiibohd.com>
parents:
212
diff
changeset
|
873 usb_wait_in_ready(); |
165
0d992d26114f
Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents:
123
diff
changeset
|
874 USBKeys_Protocol = wValue; // 0 - Boot Mode, 1 - NKRO Mode |
0d992d26114f
Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents:
123
diff
changeset
|
875 usb_send_in(); |
229 | 876 //print("HID SET"); |
165
0d992d26114f
Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents:
123
diff
changeset
|
877 return; |
0d992d26114f
Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents:
123
diff
changeset
|
878 } |
0d992d26114f
Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents:
123
diff
changeset
|
879 } |
0d992d26114f
Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents:
123
diff
changeset
|
880 } |
0d992d26114f
Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents:
123
diff
changeset
|
881 |
123
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
882 if (bRequest == CDC_GET_LINE_CODING && bmRequestType == 0xA1) { |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
883 usb_wait_in_ready(); |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
884 p = cdc_line_coding; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
885 for (i=0; i<7; i++) { |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
886 UEDATX = *p++; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
887 } |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
888 usb_send_in(); |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
889 return; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
890 } |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
891 |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
892 if (bRequest == CDC_SET_LINE_CODING && bmRequestType == 0x21) { |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
893 usb_wait_receive_out(); |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
894 p = cdc_line_coding; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
895 for (i=0; i<7; i++) { |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
896 *p++ = UEDATX; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
897 } |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
898 usb_ack_out(); |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
899 usb_send_in(); |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
900 return; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
901 } |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
902 |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
903 if (bRequest == CDC_SET_CONTROL_LINE_STATE && bmRequestType == 0x21) { |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
904 cdc_line_rtsdtr = wValue; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
905 usb_wait_in_ready(); |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
906 usb_send_in(); |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
907 return; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
908 } |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
909 |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
910 if (bRequest == GET_STATUS) { |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
911 usb_wait_in_ready(); |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
912 i = 0; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
913 if (bmRequestType == 0x82) { |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
914 UENUM = wIndex; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
915 if (UECONX & (1<<STALLRQ)) i = 1; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
916 UENUM = 0; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
917 } |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
918 UEDATX = i; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
919 UEDATX = 0; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
920 usb_send_in(); |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
921 return; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
922 } |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
923 |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
924 if ((bRequest == CLEAR_FEATURE || bRequest == SET_FEATURE) |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
925 && bmRequestType == 0x02 && wValue == 0) { |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
926 i = wIndex & 0x7F; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
927 if (i >= 1 && i <= MAX_ENDPOINT) { |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
928 usb_send_in(); |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
929 UENUM = i; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
930 if (bRequest == SET_FEATURE) { |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
931 UECONX = (1<<STALLRQ)|(1<<EPEN); |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
932 } else { |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
933 UECONX = (1<<STALLRQC)|(1<<RSTDT)|(1<<EPEN); |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
934 UERST = (1 << i); |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
935 UERST = 0; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
936 } |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
937 return; |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
938 } |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
939 } |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
940 } |
165
0d992d26114f
Preparing from initial AVR USB NKRO support.
Jacob Alexander <haata@kiibohd.com>
parents:
123
diff
changeset
|
941 UECONX = (1 << STALLRQ) | (1 << EPEN); // stall |
123
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
942 } |
0c5d1fe99302
Adding CLI and CDC Serial support for Teensy 2.0 and Teensy 2.0++
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
943 |