
Originally Posted by
ohoomens
Hi everyone!
From what I know it is possible to retrieve port numbers of devices which are connected to a USB hub. I couldnt find any information regarding the libraries capability of doing so - is this possible with the current lib version?
Thanks in advance!
This information can be found starting at line #83 in "USBHost_t36.h" in the USBHost_t36 library. The device_t struct is used as part of each claimed USB device with the information you are looking for. Paul explains it's usage there. An example of accessing this information can be found in "MassStorageDriver.cpp", "utility/msc.h" and an example of it's usage in "examples/storage/DriveInfo.ino".
Code:
// Show USB drive information for the selected USB drive.
void printDriveInfo(USBDrive &drive) {
// Print USB drive information.
Serial.printf(F(" connected: %d\n"), drive.msDriveInfo.connected);
Serial.printf(F(" initialized: %d\n"), drive.msDriveInfo.initialized);
Serial.printf(F(" USB Vendor ID: %4.4x\n"), drive.msDriveInfo.idVendor);
Serial.printf(F(" USB Product ID: %4.4x\n"), drive.msDriveInfo.idProduct);
Serial.printf(F(" HUB Number: %d\n"), drive.msDriveInfo.hubNumber);
Serial.printf(F(" HUB Port: %d\n"), drive.msDriveInfo.hubPort);
Serial.printf(F(" Device Address: %d\n"), drive.msDriveInfo.deviceAddress);
Serial.printf(F("Removable Device: "));
if(drive.msDriveInfo.inquiry.Removable == 1) {
Serial.printf(F("YES\n"));
} else {
Serial.printf(F("NO\n"));
}
Serial.printf(F(" VendorID: %8.8s\n"), drive.msDriveInfo.inquiry.VendorID);
Serial.printf(F(" ProductID: %16.16s\n"), drive.msDriveInfo.inquiry.ProductID);
Serial.printf(F(" RevisionID: %4.4s\n"), drive.msDriveInfo.inquiry.RevisionID);
Serial.printf(F(" Version: %d\n"), drive.msDriveInfo.inquiry.Version);
Serial.printf(F(" Sector Count: %ld\n"), drive.msDriveInfo.capacity.Blocks);
Serial.printf(F(" Sector size: %ld\n"), drive.msDriveInfo.capacity.BlockSize);
uint64_t drivesize = drive.msDriveInfo.capacity.Blocks;
drivesize *= drive.msDriveInfo.capacity.BlockSize;
Serial.print(F(" Disk Capacity: "));
Serial.print(drivesize);
Serial.println(" Bytes");
drive.printPartionTable(Serial);
Serial.println();
}
In "msc.h" is the struct:
Code:
// MSC Drive status/info struct
typedef struct {
bool connected; // Device is connected
bool initialized; // Device is initialized
bool mounted; // Device is mounted
const char * drvName;
uint32_t bufferSize;
uint8_t hubNumber;
uint8_t hubPort;
uint8_t deviceAddress;
uint16_t idVendor;
uint16_t idProduct;
msSCSICapacity_t capacity;
msInquiryResponse_t inquiry;
} __attribute__((packed)) msDriveInfo_t;
And in "MassStorageDriver.cpp" in the claim function:
Code:
idVendor = dev->idVendor;
idProduct = dev->idProduct;
hubNumber = dev->hub_address;
deviceAddress = dev->address;
hubPort = dev->hub_port; // Used for device ID with multiple drives.
and in the mscInit function:
Code:
// Retrieve drive information.
msDriveInfo.initialized = true;
msDriveInfo.hubNumber = getHubNumber(); // Which HUB.
msDriveInfo.hubPort = getHubPort(); // Which HUB port.
msDriveInfo.deviceAddress = getDeviceAddress(); // Device addreess.
Maybe this will help you get started with getting this information for your usage.