USB support in Circle (specifically for non-HID devices) #481
-
Be gentle with me, I haven't been here very long ... I am trying to understand how USB device handlers are "connected" in Circle. I know a little about some parts of what is going on underneath, but not enough to help me understand it properly. I think the CUSBDeviceFactory::GetDevice does a lot of the heavy lifting. It is being called with the 'container' for the device, and a string name to identify the device. I see that there are known interfaces (such as 9-0-0, 9-0-2, 3-1-1 etc) which I think come from the device class, device subclass, and interface number, prefixed by "int"). Am I right in thinking that the vendor specific or unspecified (255 and 0) are never used for this? This would seem to make sense, as I can see in the source where the SMSC951x gets created. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 8 replies
-
The USB enumeration process is complex, so explaining this all would take much
time. I try to give a short summary.
On the lower layer the USB root port or a hub, if the device is connected to
it, detects a newly attached device. Then the root or hub port is enabled and
the device descriptor of the USB device (a small data structure) is read. It
contains the vendor and device ID of this device. This forms the vendor string
("venXXXX-XXXX") in Circle.
Then the configuration descriptor is read, which consists of the configuration
descriptor header itself and of (possibly) multiple interface and endpoint
descriptors in a row. These interface descriptor structures contain the device
class, subclass and protocol values, which form the interface string ("int-XX-
XX-XX") in Circle.
With these mentioned strings Circle enters the factory class for the function
drivers. It starts with the vendor string and continuous with the interface
strings. When the vendor string is found in the factory, a USB function driver
class is instantiated for this known device. Only when it is not found, the
USB interface descriptors will be scanned in this process. The further
initialization depends on the device class and is different. Normally the
endpoint descriptors are scanned by the function driver and an instance of
CUSBEndpoint is created for each endpoint, which is accessed by the driver.
You are right, USB interfaces with values of 255 ( vendor specific) in the
interface descriptor's device class/subclass/protocol fields are never detected
in the USB device factory. They must be detected using the vendor string.
|
Beta Was this translation helpful? Give feedback.
-
OK, I understand this part of the process, and have produced a stub driver for a device that has two endpoints (it is a display and touchscreen) for the single interface the device has. I found that I was consistently getting problems trying to iterate the endpoints with GetDescriptor inside my Configure function, as it showed an error, a problem with the configuration descriptor (always at the same address 0x19). When I added code to CUSBDevice to increment ucConfigIndex, as required for the NetChip,RealTek devices, this was resolved, and I was able to get the endpoints successfully. As far as I can determine, the device descriptor reports bNumConfigurations as 1. I would expect that asking for the default would be OK, but clearly not. I put some code into CUSBDevice to retrieve DeviceConfiguration for both index#0 and index#1, and there is an obvious difference, in that bNumConfigurations is 0x32 (50) in the first case, while in the second case it is 0x01 (1). I am confused as to why this would cause a problem, since as far as I can see, this member is never referred to directly. |
Beta Was this translation helpful? Give feedback.
Despite the oddities of the device, I have basic functionality now, as I am able to send data to the display (320x240 16-bit colour depth) and get touch information back. My next stage will be to present the touch side as a 'standard' device, then move on to the display side.
I aim to represent it as a framebuffer style device, as that would allow me to more easlity use the lvgl addon with it.
Again, many thanks for your assistance and patience!