1
-
2
-
3
1
#include " Arduino.h"
4
2
#include < usbhub.h>
5
3
#include " wiring_constants.h"
6
4
#include " pgmstrings.h"
7
- // Satisfy IDE, which only needs to see the include statment in the ino.
8
- #ifdef dobogusinclude
9
- #include < spi4teensy3.h>
10
- #endif
5
+
6
+
7
+ // on a zero with debug port, use debug port
8
+ // #define SerialDebug Serial
9
+
10
+ // on a feather or non-debug Zero, use Serial1 (since USB is taken!)
11
+ #define SerialDebug Serial1
11
12
12
13
USBHost usb;
13
- // USBHub Hub1(&Usb);
14
- // USBHub Hub2(&Usb);
15
- // USBHub Hub3(&Usb);
16
- // USBHub Hub4(&Usb);
17
- // USBHub Hub5(&Usb);
18
- // USBHub Hub6(&Usb);
19
- // USBHub Hub7(&Usb);
20
14
21
15
uint32_t next_time;
22
16
@@ -33,39 +27,40 @@ void PrintAllAddresses(UsbDeviceDefinition *pdev)
33
27
{
34
28
UsbDeviceAddress adr;
35
29
adr.devAddress = pdev->address .devAddress ;
36
- SERIAL_PORT_MONITOR .print (" \r\n Addr:" );
37
- SERIAL_PORT_MONITOR .print (adr.devAddress , HEX);
38
- SERIAL_PORT_MONITOR .print (" (" );
39
- SERIAL_PORT_MONITOR .print (adr.bmHub , HEX);
40
- SERIAL_PORT_MONITOR .print (" ." );
41
- SERIAL_PORT_MONITOR .print (adr.bmParent , HEX);
42
- SERIAL_PORT_MONITOR .print (" ." );
43
- SERIAL_PORT_MONITOR .print (adr.bmAddress , HEX);
44
- SERIAL_PORT_MONITOR .println (" )" );
30
+ SerialDebug .print (" \r\n Addr:" );
31
+ SerialDebug .print (adr.devAddress , HEX);
32
+ SerialDebug .print (" (" );
33
+ SerialDebug .print (adr.bmHub , HEX);
34
+ SerialDebug .print (" ." );
35
+ SerialDebug .print (adr.bmParent , HEX);
36
+ SerialDebug .print (" ." );
37
+ SerialDebug .print (adr.bmAddress , HEX);
38
+ SerialDebug .println (" )" );
45
39
}
46
40
47
41
void PrintAddress (uint8_t addr)
48
42
{
49
43
UsbDeviceAddress adr;
50
44
adr.devAddress = addr;
51
- SERIAL_PORT_MONITOR .print (" \r\n ADDR:\t " );
52
- SERIAL_PORT_MONITOR .println (adr.devAddress ,HEX);
53
- SERIAL_PORT_MONITOR .print (" DEV:\t " );
54
- SERIAL_PORT_MONITOR .println (adr.bmAddress ,HEX);
55
- SERIAL_PORT_MONITOR .print (" PRNT:\t " );
56
- SERIAL_PORT_MONITOR .println (adr.bmParent ,HEX);
57
- SERIAL_PORT_MONITOR .print (" HUB:\t " );
58
- SERIAL_PORT_MONITOR .println (adr.bmHub ,HEX);
45
+ SerialDebug .print (" \r\n ADDR:\t " );
46
+ SerialDebug .println (adr.devAddress ,HEX);
47
+ SerialDebug .print (" DEV:\t " );
48
+ SerialDebug .println (adr.bmAddress ,HEX);
49
+ SerialDebug .print (" PRNT:\t " );
50
+ SerialDebug .println (adr.bmParent ,HEX);
51
+ SerialDebug .print (" HUB:\t " );
52
+ SerialDebug .println (adr.bmHub ,HEX);
59
53
}
60
54
61
55
void setup ()
62
56
{
63
- SERIAL_PORT_MONITOR .begin ( 115200 );
64
- while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection
65
- SERIAL_PORT_MONITOR .println (" Start USB Desc " );
57
+ Serial .begin (115200 );
58
+ SerialDebug. begin ( 115200 );
59
+ SerialDebug .println (" Starting USB Descriptor test " );
66
60
61
+ SerialDebug.println (" Initializing USB" );
67
62
if (usb.Init () == -1 )
68
- SERIAL_PORT_MONITOR .println (" OSC did not start." );
63
+ SerialDebug .println (" USBhost did not start." );
69
64
70
65
delay ( 20 );
71
66
@@ -85,7 +80,7 @@ void PrintDescriptors(uint8_t addr)
85
80
printProgStr (Gen_Error_str);
86
81
print_hex ( rcode, 8 );
87
82
}
88
- SERIAL_PORT_MONITOR .print (" \r\n " );
83
+ SerialDebug .print (" \r\n " );
89
84
90
85
for (int i=0 ; i<num_conf; i++)
91
86
{
@@ -95,15 +90,15 @@ void PrintDescriptors(uint8_t addr)
95
90
printProgStr (Gen_Error_str);
96
91
print_hex (rcode, 8 );
97
92
}
98
- SERIAL_PORT_MONITOR .println (" \r\n " );
93
+ SerialDebug .println (" \r\n " );
99
94
}
100
95
}
101
96
102
97
void PrintAllDescriptors (UsbDeviceDefinition *pdev)
103
98
{
104
- SERIAL_PORT_MONITOR .println (" \r\n " );
99
+ SerialDebug .println (" \r\n " );
105
100
print_hex (pdev->address .devAddress , 8 );
106
- SERIAL_PORT_MONITOR .println (" \r\n --" );
101
+ SerialDebug .println (" \r\n --" );
107
102
PrintDescriptors ( pdev->address .devAddress );
108
103
}
109
104
@@ -171,37 +166,37 @@ void printhubdescr(uint8_t *descrptr, uint8_t addr)
171
166
172
167
printProgStr (PSTR (" \r\n\r\n Hub Descriptor:\r\n " ));
173
168
printProgStr (PSTR (" bDescLength:\t\t " ));
174
- SERIAL_PORT_MONITOR .println (pHub->bDescLength , HEX);
169
+ SerialDebug .println (pHub->bDescLength , HEX);
175
170
176
171
printProgStr (PSTR (" bDescriptorType:\t " ));
177
- SERIAL_PORT_MONITOR .println (pHub->bDescriptorType , HEX);
172
+ SerialDebug .println (pHub->bDescriptorType , HEX);
178
173
179
174
printProgStr (PSTR (" bNbrPorts:\t\t " ));
180
- SERIAL_PORT_MONITOR .println (pHub->bNbrPorts , HEX);
175
+ SerialDebug .println (pHub->bNbrPorts , HEX);
181
176
182
177
printProgStr (PSTR (" LogPwrSwitchMode:\t " ));
183
- SERIAL_PORT_MONITOR .println (pHub->LogPwrSwitchMode , BIN);
178
+ SerialDebug .println (pHub->LogPwrSwitchMode , BIN);
184
179
185
180
printProgStr (PSTR (" CompoundDevice:\t\t " ));
186
- SERIAL_PORT_MONITOR .println (pHub->CompoundDevice , BIN);
181
+ SerialDebug .println (pHub->CompoundDevice , BIN);
187
182
188
183
printProgStr (PSTR (" OverCurrentProtectMode:\t " ));
189
- SERIAL_PORT_MONITOR .println (pHub->OverCurrentProtectMode , BIN);
184
+ SerialDebug .println (pHub->OverCurrentProtectMode , BIN);
190
185
191
186
printProgStr (PSTR (" TTThinkTime:\t\t " ));
192
- SERIAL_PORT_MONITOR .println (pHub->TTThinkTime , BIN);
187
+ SerialDebug .println (pHub->TTThinkTime , BIN);
193
188
194
189
printProgStr (PSTR (" PortIndicatorsSupported:" ));
195
- SERIAL_PORT_MONITOR .println (pHub->PortIndicatorsSupported , BIN);
190
+ SerialDebug .println (pHub->PortIndicatorsSupported , BIN);
196
191
197
192
printProgStr (PSTR (" Reserved:\t\t " ));
198
- SERIAL_PORT_MONITOR .println (pHub->Reserved , HEX);
193
+ SerialDebug .println (pHub->Reserved , HEX);
199
194
200
195
printProgStr (PSTR (" bPwrOn2PwrGood:\t\t " ));
201
- SERIAL_PORT_MONITOR .println (pHub->bPwrOn2PwrGood , HEX);
196
+ SerialDebug .println (pHub->bPwrOn2PwrGood , HEX);
202
197
203
198
printProgStr (PSTR (" bHubContrCurrent:\t " ));
204
- SERIAL_PORT_MONITOR .println (pHub->bHubContrCurrent , HEX);
199
+ SerialDebug .println (pHub->bHubContrCurrent , HEX);
205
200
206
201
for (uint8_t i=7 ; i<len; i++)
207
202
print_hex (descrptr[i], 8 );
@@ -271,7 +266,7 @@ void print_hex(int v, int num_places)
271
266
}
272
267
do {
273
268
digit = ((v >> (num_nibbles-1 ) * 4 )) & 0x0f ;
274
- SERIAL_PORT_MONITOR .print (digit, HEX);
269
+ SerialDebug .print (digit, HEX);
275
270
}
276
271
while (--num_nibbles);
277
272
}
@@ -329,7 +324,7 @@ void printHIDdescr( uint8_t* descr_ptr )
329
324
printProgStr (PSTR (" \r\n Numb Class Descriptor:\t " ));
330
325
print_hex ( ep_ptr->bNumDescriptors , 8 );
331
326
printProgStr (PSTR (" \r\n Descriptor Type:\t " ));
332
- if ( ep_ptr->bDescrType == 0x22 )
327
+ if ( ep_ptr->bDescrType == 0x22 )
333
328
printProgStr (PSTR (" REPORT DESCRIPTOR" ));
334
329
else
335
330
print_hex ( ep_ptr->bDescrType , 8 );
@@ -383,5 +378,4 @@ void printProgStr(const prog_char str[])
383
378
char c;
384
379
if (!str) return ;
385
380
while ((c = pgm_read_byte (str++)))
386
- SERIAL_PORT_MONITOR.print (c);
387
- }
381
+ SerialDebug.print (c);
0 commit comments