mirror of
https://github.com/felis/USB_Host_Shield_2.0.git
synced 2024-03-22 11:31:26 +01:00
Fixed formatting
No new code added
This commit is contained in:
parent
5053e8dfae
commit
cbea36f76f
2 changed files with 192 additions and 192 deletions
|
@ -21,31 +21,31 @@ uint32_t next_time;
|
||||||
|
|
||||||
void PrintAllAddresses(UsbDevice *pdev)
|
void PrintAllAddresses(UsbDevice *pdev)
|
||||||
{
|
{
|
||||||
UsbDeviceAddress adr;
|
UsbDeviceAddress adr;
|
||||||
adr.devAddress = pdev->address.devAddress;
|
adr.devAddress = pdev->address.devAddress;
|
||||||
Serial.print("\r\nAddr:");
|
Serial.print("\r\nAddr:");
|
||||||
Serial.print(adr.devAddress, HEX);
|
Serial.print(adr.devAddress, HEX);
|
||||||
Serial.print("(");
|
Serial.print("(");
|
||||||
Serial.print(adr.bmHub, HEX);
|
Serial.print(adr.bmHub, HEX);
|
||||||
Serial.print(".");
|
Serial.print(".");
|
||||||
Serial.print(adr.bmParent, HEX);
|
Serial.print(adr.bmParent, HEX);
|
||||||
Serial.print(".");
|
Serial.print(".");
|
||||||
Serial.print(adr.bmAddress, HEX);
|
Serial.print(adr.bmAddress, HEX);
|
||||||
Serial.println(")");
|
Serial.println(")");
|
||||||
}
|
}
|
||||||
|
|
||||||
void PrintAddress(uint8_t addr)
|
void PrintAddress(uint8_t addr)
|
||||||
{
|
{
|
||||||
UsbDeviceAddress adr;
|
UsbDeviceAddress adr;
|
||||||
adr.devAddress = addr;
|
adr.devAddress = addr;
|
||||||
Serial.print("\r\nADDR:\t");
|
Serial.print("\r\nADDR:\t");
|
||||||
Serial.println(adr.devAddress,HEX);
|
Serial.println(adr.devAddress, HEX);
|
||||||
Serial.print("DEV:\t");
|
Serial.print("DEV:\t");
|
||||||
Serial.println(adr.bmAddress,HEX);
|
Serial.println(adr.bmAddress, HEX);
|
||||||
Serial.print("PRNT:\t");
|
Serial.print("PRNT:\t");
|
||||||
Serial.println(adr.bmParent,HEX);
|
Serial.println(adr.bmParent, HEX);
|
||||||
Serial.print("HUB:\t");
|
Serial.print("HUB:\t");
|
||||||
Serial.println(adr.bmHub,HEX);
|
Serial.println(adr.bmHub, HEX);
|
||||||
}
|
}
|
||||||
|
|
||||||
void setup()
|
void setup()
|
||||||
|
@ -57,7 +57,7 @@ void setup()
|
||||||
Serial.println("Start");
|
Serial.println("Start");
|
||||||
|
|
||||||
if (Usb.Init() == -1)
|
if (Usb.Init() == -1)
|
||||||
Serial.println("OSC did not start.");
|
Serial.println("OSC did not start.");
|
||||||
|
|
||||||
delay( 200 );
|
delay( 200 );
|
||||||
|
|
||||||
|
@ -68,49 +68,49 @@ byte getdevdescr( byte addr, byte &num_conf );
|
||||||
|
|
||||||
void PrintDescriptors(uint8_t addr)
|
void PrintDescriptors(uint8_t addr)
|
||||||
{
|
{
|
||||||
uint8_t rcode = 0;
|
uint8_t rcode = 0;
|
||||||
byte num_conf = 0;
|
byte num_conf = 0;
|
||||||
|
|
||||||
rcode = getdevdescr( (byte)addr, num_conf );
|
rcode = getdevdescr( (byte)addr, num_conf );
|
||||||
if( rcode )
|
if ( rcode )
|
||||||
|
{
|
||||||
|
printProgStr(Gen_Error_str);
|
||||||
|
print_hex( rcode, 8 );
|
||||||
|
}
|
||||||
|
Serial.print("\r\n");
|
||||||
|
|
||||||
|
for (int i = 0; i < num_conf; i++)
|
||||||
|
{
|
||||||
|
rcode = getconfdescr( addr, i ); // get configuration descriptor
|
||||||
|
if ( rcode )
|
||||||
{
|
{
|
||||||
printProgStr(Gen_Error_str);
|
printProgStr(Gen_Error_str);
|
||||||
print_hex( rcode, 8 );
|
print_hex(rcode, 8);
|
||||||
}
|
|
||||||
Serial.print("\r\n");
|
|
||||||
|
|
||||||
for (int i=0; i<num_conf; i++)
|
|
||||||
{
|
|
||||||
rcode = getconfdescr( addr, i ); // get configuration descriptor
|
|
||||||
if( rcode )
|
|
||||||
{
|
|
||||||
printProgStr(Gen_Error_str);
|
|
||||||
print_hex(rcode, 8);
|
|
||||||
}
|
|
||||||
Serial.println("\r\n");
|
|
||||||
}
|
}
|
||||||
|
Serial.println("\r\n");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void PrintAllDescriptors(UsbDevice *pdev)
|
void PrintAllDescriptors(UsbDevice *pdev)
|
||||||
{
|
{
|
||||||
Serial.println("\r\n");
|
Serial.println("\r\n");
|
||||||
print_hex(pdev->address.devAddress, 8);
|
print_hex(pdev->address.devAddress, 8);
|
||||||
Serial.println("\r\n--");
|
Serial.println("\r\n--");
|
||||||
PrintDescriptors( pdev->address.devAddress );
|
PrintDescriptors( pdev->address.devAddress );
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop()
|
void loop()
|
||||||
{
|
{
|
||||||
Usb.Task();
|
Usb.Task();
|
||||||
|
|
||||||
if( Usb.getUsbTaskState() == USB_STATE_RUNNING )
|
if ( Usb.getUsbTaskState() == USB_STATE_RUNNING )
|
||||||
{
|
{
|
||||||
//if (millis() >= next_time)
|
//if (millis() >= next_time)
|
||||||
{
|
{
|
||||||
Usb.ForEachUsbDevice(&PrintAllDescriptors);
|
Usb.ForEachUsbDevice(&PrintAllDescriptors);
|
||||||
Usb.ForEachUsbDevice(&PrintAllAddresses);
|
Usb.ForEachUsbDevice(&PrintAllAddresses);
|
||||||
|
|
||||||
while( 1 ); //stop
|
while ( 1 ); //stop
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -120,8 +120,8 @@ byte getdevdescr( byte addr, byte &num_conf )
|
||||||
USB_DEVICE_DESCRIPTOR buf;
|
USB_DEVICE_DESCRIPTOR buf;
|
||||||
byte rcode;
|
byte rcode;
|
||||||
rcode = Usb.getDevDescr( addr, 0, 0x12, ( uint8_t *)&buf );
|
rcode = Usb.getDevDescr( addr, 0, 0x12, ( uint8_t *)&buf );
|
||||||
if( rcode ) {
|
if ( rcode ) {
|
||||||
return( rcode );
|
return ( rcode );
|
||||||
}
|
}
|
||||||
printProgStr(Dev_Header_str);
|
printProgStr(Dev_Header_str);
|
||||||
printProgStr(Dev_Length_str);
|
printProgStr(Dev_Length_str);
|
||||||
|
@ -153,53 +153,53 @@ byte getdevdescr( byte addr, byte &num_conf )
|
||||||
printProgStr(Dev_Nconf_str);
|
printProgStr(Dev_Nconf_str);
|
||||||
print_hex( buf.bNumConfigurations, 8 );
|
print_hex( buf.bNumConfigurations, 8 );
|
||||||
num_conf = buf.bNumConfigurations;
|
num_conf = buf.bNumConfigurations;
|
||||||
return( 0 );
|
return ( 0 );
|
||||||
}
|
}
|
||||||
|
|
||||||
void printhubdescr(uint8_t *descrptr, uint8_t addr)
|
void printhubdescr(uint8_t *descrptr, uint8_t addr)
|
||||||
{
|
{
|
||||||
HubDescriptor *pHub = (HubDescriptor*) descrptr;
|
HubDescriptor *pHub = (HubDescriptor*) descrptr;
|
||||||
uint8_t len = *((uint8_t*)descrptr);
|
uint8_t len = *((uint8_t*)descrptr);
|
||||||
|
|
||||||
printProgStr(PSTR("\r\n\r\nHub Descriptor:\r\n"));
|
printProgStr(PSTR("\r\n\r\nHub Descriptor:\r\n"));
|
||||||
printProgStr(PSTR("bDescLength:\t\t"));
|
printProgStr(PSTR("bDescLength:\t\t"));
|
||||||
Serial.println(pHub->bDescLength, HEX);
|
Serial.println(pHub->bDescLength, HEX);
|
||||||
|
|
||||||
printProgStr(PSTR("bDescriptorType:\t"));
|
printProgStr(PSTR("bDescriptorType:\t"));
|
||||||
Serial.println(pHub->bDescriptorType, HEX);
|
Serial.println(pHub->bDescriptorType, HEX);
|
||||||
|
|
||||||
printProgStr(PSTR("bNbrPorts:\t\t"));
|
printProgStr(PSTR("bNbrPorts:\t\t"));
|
||||||
Serial.println(pHub->bNbrPorts, HEX);
|
Serial.println(pHub->bNbrPorts, HEX);
|
||||||
|
|
||||||
printProgStr(PSTR("LogPwrSwitchMode:\t"));
|
printProgStr(PSTR("LogPwrSwitchMode:\t"));
|
||||||
Serial.println(pHub->LogPwrSwitchMode, BIN);
|
Serial.println(pHub->LogPwrSwitchMode, BIN);
|
||||||
|
|
||||||
printProgStr(PSTR("CompoundDevice:\t\t"));
|
printProgStr(PSTR("CompoundDevice:\t\t"));
|
||||||
Serial.println(pHub->CompoundDevice, BIN);
|
Serial.println(pHub->CompoundDevice, BIN);
|
||||||
|
|
||||||
printProgStr(PSTR("OverCurrentProtectMode:\t"));
|
printProgStr(PSTR("OverCurrentProtectMode:\t"));
|
||||||
Serial.println(pHub->OverCurrentProtectMode, BIN);
|
Serial.println(pHub->OverCurrentProtectMode, BIN);
|
||||||
|
|
||||||
printProgStr(PSTR("TTThinkTime:\t\t"));
|
printProgStr(PSTR("TTThinkTime:\t\t"));
|
||||||
Serial.println(pHub->TTThinkTime, BIN);
|
Serial.println(pHub->TTThinkTime, BIN);
|
||||||
|
|
||||||
printProgStr(PSTR("PortIndicatorsSupported:"));
|
printProgStr(PSTR("PortIndicatorsSupported:"));
|
||||||
Serial.println(pHub->PortIndicatorsSupported, BIN);
|
Serial.println(pHub->PortIndicatorsSupported, BIN);
|
||||||
|
|
||||||
printProgStr(PSTR("Reserved:\t\t"));
|
printProgStr(PSTR("Reserved:\t\t"));
|
||||||
Serial.println(pHub->Reserved, HEX);
|
Serial.println(pHub->Reserved, HEX);
|
||||||
|
|
||||||
printProgStr(PSTR("bPwrOn2PwrGood:\t\t"));
|
printProgStr(PSTR("bPwrOn2PwrGood:\t\t"));
|
||||||
Serial.println(pHub->bPwrOn2PwrGood, HEX);
|
Serial.println(pHub->bPwrOn2PwrGood, HEX);
|
||||||
|
|
||||||
printProgStr(PSTR("bHubContrCurrent:\t"));
|
printProgStr(PSTR("bHubContrCurrent:\t"));
|
||||||
Serial.println(pHub->bHubContrCurrent, HEX);
|
Serial.println(pHub->bHubContrCurrent, HEX);
|
||||||
|
|
||||||
for (uint8_t i=7; i<len; i++)
|
for (uint8_t i = 7; i < len; i++)
|
||||||
print_hex(descrptr[i], 8);
|
print_hex(descrptr[i], 8);
|
||||||
|
|
||||||
//for (uint8_t i=1; i<=pHub->bNbrPorts; i++)
|
//for (uint8_t i=1; i<=pHub->bNbrPorts; i++)
|
||||||
// PrintHubPortStatus(&Usb, addr, i, 1);
|
// PrintHubPortStatus(&Usb, addr, i, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
byte getconfdescr( byte addr, byte conf )
|
byte getconfdescr( byte addr, byte conf )
|
||||||
|
@ -213,22 +213,22 @@ byte getconfdescr( byte addr, byte conf )
|
||||||
rcode = Usb.getConfDescr( addr, 0, 4, conf, buf ); //get total length
|
rcode = Usb.getConfDescr( addr, 0, 4, conf, buf ); //get total length
|
||||||
LOBYTE( total_length ) = buf[ 2 ];
|
LOBYTE( total_length ) = buf[ 2 ];
|
||||||
HIBYTE( total_length ) = buf[ 3 ];
|
HIBYTE( total_length ) = buf[ 3 ];
|
||||||
if( total_length > 256 ) { //check if total length is larger than buffer
|
if ( total_length > 256 ) { //check if total length is larger than buffer
|
||||||
printProgStr(Conf_Trunc_str);
|
printProgStr(Conf_Trunc_str);
|
||||||
total_length = 256;
|
total_length = 256;
|
||||||
}
|
}
|
||||||
rcode = Usb.getConfDescr( addr, 0, total_length, conf, buf ); //get the whole descriptor
|
rcode = Usb.getConfDescr( addr, 0, total_length, conf, buf ); //get the whole descriptor
|
||||||
while( buf_ptr < buf + total_length ) { //parsing descriptors
|
while ( buf_ptr < buf + total_length ) { //parsing descriptors
|
||||||
descr_length = *( buf_ptr );
|
descr_length = *( buf_ptr );
|
||||||
descr_type = *( buf_ptr + 1 );
|
descr_type = *( buf_ptr + 1 );
|
||||||
switch( descr_type ) {
|
switch ( descr_type ) {
|
||||||
case( USB_DESCRIPTOR_CONFIGURATION ):
|
case ( USB_DESCRIPTOR_CONFIGURATION ):
|
||||||
printconfdescr( buf_ptr );
|
printconfdescr( buf_ptr );
|
||||||
break;
|
break;
|
||||||
case( USB_DESCRIPTOR_INTERFACE ):
|
case ( USB_DESCRIPTOR_INTERFACE ):
|
||||||
printintfdescr( buf_ptr );
|
printintfdescr( buf_ptr );
|
||||||
break;
|
break;
|
||||||
case( USB_DESCRIPTOR_ENDPOINT ):
|
case ( USB_DESCRIPTOR_ENDPOINT ):
|
||||||
printepdescr( buf_ptr );
|
printepdescr( buf_ptr );
|
||||||
break;
|
break;
|
||||||
case 0x29:
|
case 0x29:
|
||||||
|
@ -237,7 +237,7 @@ byte getconfdescr( byte addr, byte conf )
|
||||||
default:
|
default:
|
||||||
printunkdescr( buf_ptr );
|
printunkdescr( buf_ptr );
|
||||||
break;
|
break;
|
||||||
}//switch( descr_type
|
}//switch( descr_type
|
||||||
buf_ptr = ( buf_ptr + descr_length ); //advance buffer pointer
|
buf_ptr = ( buf_ptr + descr_length ); //advance buffer pointer
|
||||||
}//while( buf_ptr <=...
|
}//while( buf_ptr <=...
|
||||||
return ( rcode );
|
return ( rcode );
|
||||||
|
@ -247,9 +247,9 @@ byte getconfdescr( byte addr, byte conf )
|
||||||
// source: http://www.phanderson.com/arduino/arduino_display.html
|
// source: http://www.phanderson.com/arduino/arduino_display.html
|
||||||
void print_hex(int v, int num_places)
|
void print_hex(int v, int num_places)
|
||||||
{
|
{
|
||||||
int mask=0, n, num_nibbles, digit;
|
int mask = 0, n, num_nibbles, digit;
|
||||||
|
|
||||||
for (n=1; n<=num_places; n++) {
|
for (n = 1; n <= num_places; n++) {
|
||||||
mask = (mask << 1) | 0x0001;
|
mask = (mask << 1) | 0x0001;
|
||||||
}
|
}
|
||||||
v = v & mask; // truncate v to specified number of places
|
v = v & mask; // truncate v to specified number of places
|
||||||
|
@ -259,15 +259,15 @@ void print_hex(int v, int num_places)
|
||||||
++num_nibbles;
|
++num_nibbles;
|
||||||
}
|
}
|
||||||
do {
|
do {
|
||||||
digit = ((v >> (num_nibbles-1) * 4)) & 0x0f;
|
digit = ((v >> (num_nibbles - 1) * 4)) & 0x0f;
|
||||||
Serial.print(digit, HEX);
|
Serial.print(digit, HEX);
|
||||||
}
|
}
|
||||||
while(--num_nibbles);
|
while (--num_nibbles);
|
||||||
}
|
}
|
||||||
/* function to print configuration descriptor */
|
/* function to print configuration descriptor */
|
||||||
void printconfdescr( uint8_t* descr_ptr )
|
void printconfdescr( uint8_t* descr_ptr )
|
||||||
{
|
{
|
||||||
USB_CONFIGURATION_DESCRIPTOR* conf_ptr = ( USB_CONFIGURATION_DESCRIPTOR* )descr_ptr;
|
USB_CONFIGURATION_DESCRIPTOR* conf_ptr = ( USB_CONFIGURATION_DESCRIPTOR* )descr_ptr;
|
||||||
printProgStr(Conf_Header_str);
|
printProgStr(Conf_Header_str);
|
||||||
printProgStr(Conf_Totlen_str);
|
printProgStr(Conf_Totlen_str);
|
||||||
print_hex( conf_ptr->wTotalLength, 16 );
|
print_hex( conf_ptr->wTotalLength, 16 );
|
||||||
|
@ -286,7 +286,7 @@ void printconfdescr( uint8_t* descr_ptr )
|
||||||
/* function to print interface descriptor */
|
/* function to print interface descriptor */
|
||||||
void printintfdescr( uint8_t* descr_ptr )
|
void printintfdescr( uint8_t* descr_ptr )
|
||||||
{
|
{
|
||||||
USB_INTERFACE_DESCRIPTOR* intf_ptr = ( USB_INTERFACE_DESCRIPTOR* )descr_ptr;
|
USB_INTERFACE_DESCRIPTOR* intf_ptr = ( USB_INTERFACE_DESCRIPTOR* )descr_ptr;
|
||||||
printProgStr(Int_Header_str);
|
printProgStr(Int_Header_str);
|
||||||
printProgStr(Int_Number_str);
|
printProgStr(Int_Number_str);
|
||||||
print_hex( intf_ptr->bInterfaceNumber, 8 );
|
print_hex( intf_ptr->bInterfaceNumber, 8 );
|
||||||
|
@ -307,7 +307,7 @@ void printintfdescr( uint8_t* descr_ptr )
|
||||||
/* function to print endpoint descriptor */
|
/* function to print endpoint descriptor */
|
||||||
void printepdescr( uint8_t* descr_ptr )
|
void printepdescr( uint8_t* descr_ptr )
|
||||||
{
|
{
|
||||||
USB_ENDPOINT_DESCRIPTOR* ep_ptr = ( USB_ENDPOINT_DESCRIPTOR* )descr_ptr;
|
USB_ENDPOINT_DESCRIPTOR* ep_ptr = ( USB_ENDPOINT_DESCRIPTOR* )descr_ptr;
|
||||||
printProgStr(End_Header_str);
|
printProgStr(End_Header_str);
|
||||||
printProgStr(End_Address_str);
|
printProgStr(End_Address_str);
|
||||||
print_hex( ep_ptr->bEndpointAddress, 8 );
|
print_hex( ep_ptr->bEndpointAddress, 8 );
|
||||||
|
@ -332,7 +332,7 @@ void printunkdescr( uint8_t* descr_ptr )
|
||||||
print_hex( *(descr_ptr + 1 ), 8 );
|
print_hex( *(descr_ptr + 1 ), 8 );
|
||||||
printProgStr(Unk_Contents_str);
|
printProgStr(Unk_Contents_str);
|
||||||
descr_ptr += 2;
|
descr_ptr += 2;
|
||||||
for( i = 0; i < length; i++ ) {
|
for ( i = 0; i < length; i++ ) {
|
||||||
print_hex( *descr_ptr, 8 );
|
print_hex( *descr_ptr, 8 );
|
||||||
descr_ptr++;
|
descr_ptr++;
|
||||||
}
|
}
|
||||||
|
@ -343,7 +343,7 @@ void printunkdescr( uint8_t* descr_ptr )
|
||||||
void printProgStr(const char* str)
|
void printProgStr(const char* str)
|
||||||
{
|
{
|
||||||
char c;
|
char c;
|
||||||
if(!str) return;
|
if (!str) return;
|
||||||
while((c = pgm_read_byte(str++)))
|
while ((c = pgm_read_byte(str++)))
|
||||||
Serial.print(c);
|
Serial.print(c);
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,31 +17,31 @@ uint32_t next_time;
|
||||||
|
|
||||||
void PrintAllAddresses(UsbDevice *pdev)
|
void PrintAllAddresses(UsbDevice *pdev)
|
||||||
{
|
{
|
||||||
UsbDeviceAddress adr;
|
UsbDeviceAddress adr;
|
||||||
adr.devAddress = pdev->address.devAddress;
|
adr.devAddress = pdev->address.devAddress;
|
||||||
Serial.print("\r\nAddr:");
|
Serial.print("\r\nAddr:");
|
||||||
Serial.print(adr.devAddress, HEX);
|
Serial.print(adr.devAddress, HEX);
|
||||||
Serial.print("(");
|
Serial.print("(");
|
||||||
Serial.print(adr.bmHub, HEX);
|
Serial.print(adr.bmHub, HEX);
|
||||||
Serial.print(".");
|
Serial.print(".");
|
||||||
Serial.print(adr.bmParent, HEX);
|
Serial.print(adr.bmParent, HEX);
|
||||||
Serial.print(".");
|
Serial.print(".");
|
||||||
Serial.print(adr.bmAddress, HEX);
|
Serial.print(adr.bmAddress, HEX);
|
||||||
Serial.println(")");
|
Serial.println(")");
|
||||||
}
|
}
|
||||||
|
|
||||||
void PrintAddress(uint8_t addr)
|
void PrintAddress(uint8_t addr)
|
||||||
{
|
{
|
||||||
UsbDeviceAddress adr;
|
UsbDeviceAddress adr;
|
||||||
adr.devAddress = addr;
|
adr.devAddress = addr;
|
||||||
Serial.print("\r\nADDR:\t");
|
Serial.print("\r\nADDR:\t");
|
||||||
Serial.println(adr.devAddress,HEX);
|
Serial.println(adr.devAddress, HEX);
|
||||||
Serial.print("DEV:\t");
|
Serial.print("DEV:\t");
|
||||||
Serial.println(adr.bmAddress,HEX);
|
Serial.println(adr.bmAddress, HEX);
|
||||||
Serial.print("PRNT:\t");
|
Serial.print("PRNT:\t");
|
||||||
Serial.println(adr.bmParent,HEX);
|
Serial.println(adr.bmParent, HEX);
|
||||||
Serial.print("HUB:\t");
|
Serial.print("HUB:\t");
|
||||||
Serial.println(adr.bmHub,HEX);
|
Serial.println(adr.bmHub, HEX);
|
||||||
}
|
}
|
||||||
|
|
||||||
void setup()
|
void setup()
|
||||||
|
@ -53,7 +53,7 @@ void setup()
|
||||||
Serial.println("Start");
|
Serial.println("Start");
|
||||||
|
|
||||||
if (Usb.Init() == -1)
|
if (Usb.Init() == -1)
|
||||||
Serial.println("OSC did not start.");
|
Serial.println("OSC did not start.");
|
||||||
|
|
||||||
delay( 200 );
|
delay( 200 );
|
||||||
|
|
||||||
|
@ -64,49 +64,49 @@ byte getdevdescr( byte addr, byte &num_conf );
|
||||||
|
|
||||||
void PrintDescriptors(uint8_t addr)
|
void PrintDescriptors(uint8_t addr)
|
||||||
{
|
{
|
||||||
uint8_t rcode = 0;
|
uint8_t rcode = 0;
|
||||||
byte num_conf = 0;
|
byte num_conf = 0;
|
||||||
|
|
||||||
rcode = getdevdescr( (byte)addr, num_conf );
|
rcode = getdevdescr( (byte)addr, num_conf );
|
||||||
if( rcode )
|
if ( rcode )
|
||||||
|
{
|
||||||
|
printProgStr(Gen_Error_str);
|
||||||
|
print_hex( rcode, 8 );
|
||||||
|
}
|
||||||
|
Serial.print("\r\n");
|
||||||
|
|
||||||
|
for (int i = 0; i < num_conf; i++)
|
||||||
|
{
|
||||||
|
rcode = getconfdescr( addr, i ); // get configuration descriptor
|
||||||
|
if ( rcode )
|
||||||
{
|
{
|
||||||
printProgStr(Gen_Error_str);
|
printProgStr(Gen_Error_str);
|
||||||
print_hex( rcode, 8 );
|
print_hex(rcode, 8);
|
||||||
}
|
|
||||||
Serial.print("\r\n");
|
|
||||||
|
|
||||||
for (int i=0; i<num_conf; i++)
|
|
||||||
{
|
|
||||||
rcode = getconfdescr( addr, i ); // get configuration descriptor
|
|
||||||
if( rcode )
|
|
||||||
{
|
|
||||||
printProgStr(Gen_Error_str);
|
|
||||||
print_hex(rcode, 8);
|
|
||||||
}
|
|
||||||
Serial.println("\r\n");
|
|
||||||
}
|
}
|
||||||
|
Serial.println("\r\n");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void PrintAllDescriptors(UsbDevice *pdev)
|
void PrintAllDescriptors(UsbDevice *pdev)
|
||||||
{
|
{
|
||||||
Serial.println("\r\n");
|
Serial.println("\r\n");
|
||||||
print_hex(pdev->address.devAddress, 8);
|
print_hex(pdev->address.devAddress, 8);
|
||||||
Serial.println("\r\n--");
|
Serial.println("\r\n--");
|
||||||
PrintDescriptors( pdev->address.devAddress );
|
PrintDescriptors( pdev->address.devAddress );
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop()
|
void loop()
|
||||||
{
|
{
|
||||||
Usb.Task();
|
Usb.Task();
|
||||||
|
|
||||||
if( Usb.getUsbTaskState() == USB_STATE_RUNNING )
|
if ( Usb.getUsbTaskState() == USB_STATE_RUNNING )
|
||||||
{
|
{
|
||||||
if ((millis() - next_time) >= 0L)
|
if ((millis() - next_time) >= 0L)
|
||||||
{
|
{
|
||||||
Usb.ForEachUsbDevice(&PrintAllDescriptors);
|
Usb.ForEachUsbDevice(&PrintAllDescriptors);
|
||||||
Usb.ForEachUsbDevice(&PrintAllAddresses);
|
Usb.ForEachUsbDevice(&PrintAllAddresses);
|
||||||
|
|
||||||
while( 1 ); //stop
|
while ( 1 ); //stop
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -116,8 +116,8 @@ byte getdevdescr( byte addr, byte &num_conf )
|
||||||
USB_DEVICE_DESCRIPTOR buf;
|
USB_DEVICE_DESCRIPTOR buf;
|
||||||
byte rcode;
|
byte rcode;
|
||||||
rcode = Usb.getDevDescr( addr, 0, 0x12, ( uint8_t *)&buf );
|
rcode = Usb.getDevDescr( addr, 0, 0x12, ( uint8_t *)&buf );
|
||||||
if( rcode ) {
|
if ( rcode ) {
|
||||||
return( rcode );
|
return ( rcode );
|
||||||
}
|
}
|
||||||
printProgStr(Dev_Header_str);
|
printProgStr(Dev_Header_str);
|
||||||
printProgStr(Dev_Length_str);
|
printProgStr(Dev_Length_str);
|
||||||
|
@ -149,53 +149,53 @@ byte getdevdescr( byte addr, byte &num_conf )
|
||||||
printProgStr(Dev_Nconf_str);
|
printProgStr(Dev_Nconf_str);
|
||||||
print_hex( buf.bNumConfigurations, 8 );
|
print_hex( buf.bNumConfigurations, 8 );
|
||||||
num_conf = buf.bNumConfigurations;
|
num_conf = buf.bNumConfigurations;
|
||||||
return( 0 );
|
return ( 0 );
|
||||||
}
|
}
|
||||||
|
|
||||||
void printhubdescr(uint8_t *descrptr, uint8_t addr)
|
void printhubdescr(uint8_t *descrptr, uint8_t addr)
|
||||||
{
|
{
|
||||||
HubDescriptor *pHub = (HubDescriptor*) descrptr;
|
HubDescriptor *pHub = (HubDescriptor*) descrptr;
|
||||||
uint8_t len = *((uint8_t*)descrptr);
|
uint8_t len = *((uint8_t*)descrptr);
|
||||||
|
|
||||||
printProgStr(PSTR("\r\n\r\nHub Descriptor:\r\n"));
|
printProgStr(PSTR("\r\n\r\nHub Descriptor:\r\n"));
|
||||||
printProgStr(PSTR("bDescLength:\t\t"));
|
printProgStr(PSTR("bDescLength:\t\t"));
|
||||||
Serial.println(pHub->bDescLength, HEX);
|
Serial.println(pHub->bDescLength, HEX);
|
||||||
|
|
||||||
printProgStr(PSTR("bDescriptorType:\t"));
|
printProgStr(PSTR("bDescriptorType:\t"));
|
||||||
Serial.println(pHub->bDescriptorType, HEX);
|
Serial.println(pHub->bDescriptorType, HEX);
|
||||||
|
|
||||||
printProgStr(PSTR("bNbrPorts:\t\t"));
|
printProgStr(PSTR("bNbrPorts:\t\t"));
|
||||||
Serial.println(pHub->bNbrPorts, HEX);
|
Serial.println(pHub->bNbrPorts, HEX);
|
||||||
|
|
||||||
printProgStr(PSTR("LogPwrSwitchMode:\t"));
|
printProgStr(PSTR("LogPwrSwitchMode:\t"));
|
||||||
Serial.println(pHub->LogPwrSwitchMode, BIN);
|
Serial.println(pHub->LogPwrSwitchMode, BIN);
|
||||||
|
|
||||||
printProgStr(PSTR("CompoundDevice:\t\t"));
|
printProgStr(PSTR("CompoundDevice:\t\t"));
|
||||||
Serial.println(pHub->CompoundDevice, BIN);
|
Serial.println(pHub->CompoundDevice, BIN);
|
||||||
|
|
||||||
printProgStr(PSTR("OverCurrentProtectMode:\t"));
|
printProgStr(PSTR("OverCurrentProtectMode:\t"));
|
||||||
Serial.println(pHub->OverCurrentProtectMode, BIN);
|
Serial.println(pHub->OverCurrentProtectMode, BIN);
|
||||||
|
|
||||||
printProgStr(PSTR("TTThinkTime:\t\t"));
|
printProgStr(PSTR("TTThinkTime:\t\t"));
|
||||||
Serial.println(pHub->TTThinkTime, BIN);
|
Serial.println(pHub->TTThinkTime, BIN);
|
||||||
|
|
||||||
printProgStr(PSTR("PortIndicatorsSupported:"));
|
printProgStr(PSTR("PortIndicatorsSupported:"));
|
||||||
Serial.println(pHub->PortIndicatorsSupported, BIN);
|
Serial.println(pHub->PortIndicatorsSupported, BIN);
|
||||||
|
|
||||||
printProgStr(PSTR("Reserved:\t\t"));
|
printProgStr(PSTR("Reserved:\t\t"));
|
||||||
Serial.println(pHub->Reserved, HEX);
|
Serial.println(pHub->Reserved, HEX);
|
||||||
|
|
||||||
printProgStr(PSTR("bPwrOn2PwrGood:\t\t"));
|
printProgStr(PSTR("bPwrOn2PwrGood:\t\t"));
|
||||||
Serial.println(pHub->bPwrOn2PwrGood, HEX);
|
Serial.println(pHub->bPwrOn2PwrGood, HEX);
|
||||||
|
|
||||||
printProgStr(PSTR("bHubContrCurrent:\t"));
|
printProgStr(PSTR("bHubContrCurrent:\t"));
|
||||||
Serial.println(pHub->bHubContrCurrent, HEX);
|
Serial.println(pHub->bHubContrCurrent, HEX);
|
||||||
|
|
||||||
for (uint8_t i=7; i<len; i++)
|
for (uint8_t i = 7; i < len; i++)
|
||||||
print_hex(descrptr[i], 8);
|
print_hex(descrptr[i], 8);
|
||||||
|
|
||||||
//for (uint8_t i=1; i<=pHub->bNbrPorts; i++)
|
//for (uint8_t i=1; i<=pHub->bNbrPorts; i++)
|
||||||
// PrintHubPortStatus(&Usb, addr, i, 1);
|
// PrintHubPortStatus(&Usb, addr, i, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
byte getconfdescr( byte addr, byte conf )
|
byte getconfdescr( byte addr, byte conf )
|
||||||
|
@ -209,22 +209,22 @@ byte getconfdescr( byte addr, byte conf )
|
||||||
rcode = Usb.getConfDescr( addr, 0, 4, conf, buf ); //get total length
|
rcode = Usb.getConfDescr( addr, 0, 4, conf, buf ); //get total length
|
||||||
LOBYTE( total_length ) = buf[ 2 ];
|
LOBYTE( total_length ) = buf[ 2 ];
|
||||||
HIBYTE( total_length ) = buf[ 3 ];
|
HIBYTE( total_length ) = buf[ 3 ];
|
||||||
if( total_length > 256 ) { //check if total length is larger than buffer
|
if ( total_length > 256 ) { //check if total length is larger than buffer
|
||||||
printProgStr(Conf_Trunc_str);
|
printProgStr(Conf_Trunc_str);
|
||||||
total_length = 256;
|
total_length = 256;
|
||||||
}
|
}
|
||||||
rcode = Usb.getConfDescr( addr, 0, total_length, conf, buf ); //get the whole descriptor
|
rcode = Usb.getConfDescr( addr, 0, total_length, conf, buf ); //get the whole descriptor
|
||||||
while( buf_ptr < buf + total_length ) { //parsing descriptors
|
while ( buf_ptr < buf + total_length ) { //parsing descriptors
|
||||||
descr_length = *( buf_ptr );
|
descr_length = *( buf_ptr );
|
||||||
descr_type = *( buf_ptr + 1 );
|
descr_type = *( buf_ptr + 1 );
|
||||||
switch( descr_type ) {
|
switch ( descr_type ) {
|
||||||
case( USB_DESCRIPTOR_CONFIGURATION ):
|
case ( USB_DESCRIPTOR_CONFIGURATION ):
|
||||||
printconfdescr( buf_ptr );
|
printconfdescr( buf_ptr );
|
||||||
break;
|
break;
|
||||||
case( USB_DESCRIPTOR_INTERFACE ):
|
case ( USB_DESCRIPTOR_INTERFACE ):
|
||||||
printintfdescr( buf_ptr );
|
printintfdescr( buf_ptr );
|
||||||
break;
|
break;
|
||||||
case( USB_DESCRIPTOR_ENDPOINT ):
|
case ( USB_DESCRIPTOR_ENDPOINT ):
|
||||||
printepdescr( buf_ptr );
|
printepdescr( buf_ptr );
|
||||||
break;
|
break;
|
||||||
case 0x29:
|
case 0x29:
|
||||||
|
@ -233,7 +233,7 @@ byte getconfdescr( byte addr, byte conf )
|
||||||
default:
|
default:
|
||||||
printunkdescr( buf_ptr );
|
printunkdescr( buf_ptr );
|
||||||
break;
|
break;
|
||||||
}//switch( descr_type
|
}//switch( descr_type
|
||||||
buf_ptr = ( buf_ptr + descr_length ); //advance buffer pointer
|
buf_ptr = ( buf_ptr + descr_length ); //advance buffer pointer
|
||||||
}//while( buf_ptr <=...
|
}//while( buf_ptr <=...
|
||||||
return ( rcode );
|
return ( rcode );
|
||||||
|
@ -243,9 +243,9 @@ byte getconfdescr( byte addr, byte conf )
|
||||||
// source: http://www.phanderson.com/arduino/arduino_display.html
|
// source: http://www.phanderson.com/arduino/arduino_display.html
|
||||||
void print_hex(int v, int num_places)
|
void print_hex(int v, int num_places)
|
||||||
{
|
{
|
||||||
int mask=0, n, num_nibbles, digit;
|
int mask = 0, n, num_nibbles, digit;
|
||||||
|
|
||||||
for (n=1; n<=num_places; n++) {
|
for (n = 1; n <= num_places; n++) {
|
||||||
mask = (mask << 1) | 0x0001;
|
mask = (mask << 1) | 0x0001;
|
||||||
}
|
}
|
||||||
v = v & mask; // truncate v to specified number of places
|
v = v & mask; // truncate v to specified number of places
|
||||||
|
@ -255,15 +255,15 @@ void print_hex(int v, int num_places)
|
||||||
++num_nibbles;
|
++num_nibbles;
|
||||||
}
|
}
|
||||||
do {
|
do {
|
||||||
digit = ((v >> (num_nibbles-1) * 4)) & 0x0f;
|
digit = ((v >> (num_nibbles - 1) * 4)) & 0x0f;
|
||||||
Serial.print(digit, HEX);
|
Serial.print(digit, HEX);
|
||||||
}
|
}
|
||||||
while(--num_nibbles);
|
while (--num_nibbles);
|
||||||
}
|
}
|
||||||
/* function to print configuration descriptor */
|
/* function to print configuration descriptor */
|
||||||
void printconfdescr( uint8_t* descr_ptr )
|
void printconfdescr( uint8_t* descr_ptr )
|
||||||
{
|
{
|
||||||
USB_CONFIGURATION_DESCRIPTOR* conf_ptr = ( USB_CONFIGURATION_DESCRIPTOR* )descr_ptr;
|
USB_CONFIGURATION_DESCRIPTOR* conf_ptr = ( USB_CONFIGURATION_DESCRIPTOR* )descr_ptr;
|
||||||
printProgStr(Conf_Header_str);
|
printProgStr(Conf_Header_str);
|
||||||
printProgStr(Conf_Totlen_str);
|
printProgStr(Conf_Totlen_str);
|
||||||
print_hex( conf_ptr->wTotalLength, 16 );
|
print_hex( conf_ptr->wTotalLength, 16 );
|
||||||
|
@ -282,7 +282,7 @@ void printconfdescr( uint8_t* descr_ptr )
|
||||||
/* function to print interface descriptor */
|
/* function to print interface descriptor */
|
||||||
void printintfdescr( uint8_t* descr_ptr )
|
void printintfdescr( uint8_t* descr_ptr )
|
||||||
{
|
{
|
||||||
USB_INTERFACE_DESCRIPTOR* intf_ptr = ( USB_INTERFACE_DESCRIPTOR* )descr_ptr;
|
USB_INTERFACE_DESCRIPTOR* intf_ptr = ( USB_INTERFACE_DESCRIPTOR* )descr_ptr;
|
||||||
printProgStr(Int_Header_str);
|
printProgStr(Int_Header_str);
|
||||||
printProgStr(Int_Number_str);
|
printProgStr(Int_Number_str);
|
||||||
print_hex( intf_ptr->bInterfaceNumber, 8 );
|
print_hex( intf_ptr->bInterfaceNumber, 8 );
|
||||||
|
@ -303,7 +303,7 @@ void printintfdescr( uint8_t* descr_ptr )
|
||||||
/* function to print endpoint descriptor */
|
/* function to print endpoint descriptor */
|
||||||
void printepdescr( uint8_t* descr_ptr )
|
void printepdescr( uint8_t* descr_ptr )
|
||||||
{
|
{
|
||||||
USB_ENDPOINT_DESCRIPTOR* ep_ptr = ( USB_ENDPOINT_DESCRIPTOR* )descr_ptr;
|
USB_ENDPOINT_DESCRIPTOR* ep_ptr = ( USB_ENDPOINT_DESCRIPTOR* )descr_ptr;
|
||||||
printProgStr(End_Header_str);
|
printProgStr(End_Header_str);
|
||||||
printProgStr(End_Address_str);
|
printProgStr(End_Address_str);
|
||||||
print_hex( ep_ptr->bEndpointAddress, 8 );
|
print_hex( ep_ptr->bEndpointAddress, 8 );
|
||||||
|
@ -328,7 +328,7 @@ void printunkdescr( uint8_t* descr_ptr )
|
||||||
print_hex( *(descr_ptr + 1 ), 8 );
|
print_hex( *(descr_ptr + 1 ), 8 );
|
||||||
printProgStr(Unk_Contents_str);
|
printProgStr(Unk_Contents_str);
|
||||||
descr_ptr += 2;
|
descr_ptr += 2;
|
||||||
for( i = 0; i < length; i++ ) {
|
for ( i = 0; i < length; i++ ) {
|
||||||
print_hex( *descr_ptr, 8 );
|
print_hex( *descr_ptr, 8 );
|
||||||
descr_ptr++;
|
descr_ptr++;
|
||||||
}
|
}
|
||||||
|
@ -339,7 +339,7 @@ void printunkdescr( uint8_t* descr_ptr )
|
||||||
void printProgStr(const char* str)
|
void printProgStr(const char* str)
|
||||||
{
|
{
|
||||||
char c;
|
char c;
|
||||||
if(!str) return;
|
if (!str) return;
|
||||||
while((c = pgm_read_byte(str++)))
|
while ((c = pgm_read_byte(str++)))
|
||||||
Serial.print(c);
|
Serial.print(c);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue