USB-Host - How to begin?

Status
Not open for further replies.

Frank B

Senior Member
Ok,

an easier question.

If I want to support a new USB device for the USBHost library - where do I start? Which are the first steps?
I've attached all info as Windows sees it.

My Program should not only support this stick, but similar others, too.

The file shows, that there are two child devices. I don't need the second - it seems to be for the inbuilt IR Receiver only. It seems to emulate a Keyboard - I don't need that feature.


I browsed through the library files - some are claiming at "interface level", some at "device level" - why that, and what should I choose? Do I need to know which endpoints it uses? I guess yes.. the Information seems to be somewhere in the descriptors. How do I find it?

I need to send some config values, and hope to get a (isochronous?) stream of data back at some point.

You see - I'm a noob when it comes to these things ;)
Hoping to get some hints here, that make the beginnings a bit easier...
 

Attachments

  • device.txt
    18.4 KB · Views: 126
@Frank B
Might be easier to know what device you are trying to connect to USB host.

When I was trying to add new devices I would start by turning debug on in USBHost, and the different .cpp files for the device - bluetooth, joystick, mouse, HID etc. and see what it gave me as well. You then need to add the pid/vid to list of supported devices so it would disovery it and then start playing.

USB hub is already supported but have to make sure you add:
Code:
USBHost myusb;
USBHub hub1(myusb);
USBHub hub2(myusb);
USBHub hub3(myusb);
USBHub hub4(myusb);
and of course look at the examples.

For me I can;t sort out the device you are adding from the device.txt file. But when I was adding a digitizer I know I was playing around with USBHost_t36 if it was a totally new device and then to be honest since I knew it was of a joystick type I got the usuage reports from there and then @KurtE and I developed a new driver for it.

If its a completely new device @KurtE might be better off giving more details.
 
Is this what you are trying to implement:
Code:
Child Device 2          : HID Infrared Remote Receiver
?

Be honest - I would plug it in with all the debug turned on and see what it recognizes and start from there.
 
It is a DVBT receiver.

Its think its good to have a more generic "howto". Later, i want to add the next device.. audio :)
 
Hi Frank,

It looks like this device is a HID (Human Interface Device) like mouse, some keyboard...

There is an example sketch under USBHost_t36 HIDDeviceInfo that is setup to dump a lot of data in the way that I would typically do using a linux box...
With Linux, I would do commands like (from the USBHost joystick thread) that I did for PS4...
Code:
pi@raspberrypi:~ $ sudo usbhid-dump   | grep -v : | xxd -r -p | hidrd-convert -o spec
Usage Page (Desktop),               ; Generic desktop controls (01h)
Usage (Gamepad),                    ; Gamepad (05h, application collection)
Collection (Application),
    Report ID (1),
    Usage (X),                      ; X (30h, dynamic value)
    Usage (Y),                      ; Y (31h, dynamic value)
    Usage (Z),                      ; Z (32h, dynamic value)
    Usage (Rz),                     ; Rz (35h, dynamic value)
    Logical Minimum (0),
    Logical Maximum (255),
    Report Size (8),
    Report Count (4),
    Input (Variable),
    Usage (Hat Switch),             ; Hat switch (39h, dynamic value)
    Logical Minimum (0),
    Logical Maximum (7),
    Physical Minimum (0),
    Physical Maximum (315),
    Unit (Degrees),
    Report Size (4),
    Report Count (1),
    Input (Variable, Null State),
    Unit,
    Usage Page (Button),            ; Button (09h)
    Usage Minimum (01h),
    Usage Maximum (0Eh),
    Logical Minimum (0),
    Logical Maximum (1),
    Report Size (1),
    Report Count (14),
    Input (Variable),
    Usage Page (FF00h),             ; FF00h, vendor-defined
    Usage (20h),
    Report Size (6),
    Report Count (1),
    Logical Minimum (0),
    Logical Maximum (127),
    Input (Variable),
    Usage Page (Desktop),           ; Generic desktop controls (01h)
    Usage (Rx),                     ; Rx (33h, dynamic value)
    Usage (Ry),                     ; Ry (34h, dynamic value)
    Logical Minimum (0),
    Logical Maximum (255),
    Report Size (8),
    Report Count (2),
    Input (Variable),
    Usage Page (FF00h),             ; FF00h, vendor-defined
    Usage (21h),
    Report Count (54),
    Input (Variable),
    Report ID (5),
    Usage (22h),
    Report Count (31),
    Output (Variable),
    Report ID (4),
    Usage (23h),
    Report Count (36),
    Feature (Variable),
    Report ID (2),
    Usage (24h),
    Report Count (36),
    Feature (Variable),
    Report ID (8),
    Usage (25h),
    Report Count (3),
    Feature (Variable),
    Report ID (16),
    Usage (26h),
    Report Count (4),
    Feature (Variable),
    Report ID (17),
    Usage (27h),
    Report Count (2),
    Feature (Variable),
    Report ID (18),
    Usage Page (FF02h),             ; FF02h, vendor-defined
    Usage (21h),
    Report Count (15),
    Feature (Variable),
    Report ID (19),
    Usage (22h),
    Report Count (22),
    Feature (Variable),
    Report ID (20),
    Usage Page (FF05h),             ; FF05h, vendor-defined
    Usage (20h),
    Report Count (16),
    Feature (Variable),
    Report ID (21),
    Usage (21h),
    Report Count (44),
    Feature (Variable),
    Usage Page (FF80h),             ; FF80h, vendor-defined
    Report ID (128),
    Usage (20h),
    Report Count (6),
    Feature (Variable),
    Report ID (129),
    Usage (21h),
    Report Count (6),
    Feature (Variable),
    Report ID (130),
    Usage (22h),
    Report Count (5),
    Feature (Variable),
    Report ID (131),
    Usage (23h),
    Report Count (1),
    Feature (Variable),
    Report ID (132),
    Usage (24h),
    Report Count (4),
    Feature (Variable),
    Report ID (133),
    Usage (25h),
    Report Count (6),
    Feature (Variable),
    Report ID (134),
    Usage (26h),
    Report Count (6),
    Feature (Variable),
    Report ID (135),
    Usage (27h),
    Report Count (35),
    Feature (Variable),
    Report ID (136),
    Usage (28h),
    Report Count (63),
    Feature (Variable),
    Report ID (137),
    Usage (29h),
    Report Count (2),
    Feature (Variable),
    Report ID (144),
    Usage (30h),
    Report Count (5),
    Feature (Variable),
    Report ID (145),
    Usage (31h),
    Report Count (3),
    Feature (Variable),
    Report ID (146),
    Usage (32h),
    Report Count (3),
    Feature (Variable),
    Report ID (147),
    Usage (33h),
    Report Count (12),
    Feature (Variable),
    Report ID (148),
    Usage (34h),
    Report Count (63),
    Feature (Variable),
    Report ID (160),
    Usage (40h),
    Report Count (6),
    Feature (Variable),
    Report ID (161),
    Usage (41h),
    Report Count (1),
    Feature (Variable),
    Report ID (162),
    Usage (42h),
    Report Count (1),
    Feature (Variable),
    Report ID (163),
    Usage (43h),
    Report Count (48),
    Feature (Variable),
    Report ID (164),
    Usage (44h),
    Report Count (13),
    Feature (Variable),
    Report ID (240),
    Usage (47h),
    Report Count (63),
    Feature (Variable),
    Report ID (241),
    Usage (48h),
    Report Count (63),
    Feature (Variable),
    Report ID (242),
    Usage (49h),
    Report Count (15),
    Feature (Variable),
    Report ID (167),
    Usage (4Ah),
    Report Count (1),
    Feature (Variable),
    Report ID (168),
    Usage (4Bh),
    Report Count (1),
    Feature (Variable),
    Report ID (169),
    Usage (4Ch),
    Report Count (8),
    Feature (Variable),
    Report ID (170),
    Usage (4Eh),
    Report Count (1),
    Feature (Variable),
    Report ID (171),
    Usage (4Fh),
    Report Count (57),
    Feature (Variable),
    Report ID (172),
    Usage (50h),
    Report Count (57),
    Feature (Variable),
    Report ID (173),
    Usage (51h),
    Report Count (11),
    Feature (Variable),
    Report ID (174),
    Usage (52h),
    Report Count (1),
    Feature (Variable),
    Report ID (175),
    Usage (53h),
    Report Count (2),
    Feature (Variable),
    Report ID (176),
    Usage (54h),
    Report Count (63),
    Feature (Variable),
    Report ID (224),
    Usage (57h),
    Report Count (2),
    Feature (Variable),
    Report ID (179),
    Usage (55h),
    Report Count (63),
    Feature (Variable),
    Report ID (180),
    Usage (55h),
    Report Count (63),
    Feature (Variable),
    Report ID (181),
    Usage (56h),
    Report Count (63),
    Feature (Variable),
    Report ID (208),
    Usage (58h),
    Report Count (63),
    Feature (Variable),
    Report ID (212),
    Usage (59h),
    Report Count (63),
    Feature (Variable),
End Collection
But somewhere in some of my posts were locations on where to find these utilities and the like...

Now assuming that the Hid Data comes back with something reasonable,

You can start off more or less with copy a simple HID device like Mouse. Although Mouse also supports the Bluetooth interface, but the two are pretty well separate.

Or depending on your actual device, look at the rawhid version, which actually bypasses most stuff.

But the HID stuff is pretty simple: in that once you have your device registered with HID, the Hid Parser objects when they see a new HID device, will a
call off to you and ask if you wish to claim a report:
Code:
hidclaim_t MouseController::claim_collection(USBHIDParser *driver, Device_t *dev, uint32_t topusage)
{
	// only claim Desktop/Mouse
	if ((topusage != 0x10002) && (topusage != 0x10001)) return CLAIM_NO;
	// only claim from one physical device
	if (mydevice != NULL && dev != mydevice) return CLAIM_NO;
	mydevice = dev;
	collections_claimed++;
	return CLAIM_REPORT;
}
If you claim the device, when it see data from that device for a report that you say you want, it parses the data by the HID descriptor, and for each field will call off to you with each field.
Actually starts of with a hid_input_begin to tell you it is starting processing of that packet, then for each field it will call off with hid_input_data and after the last data is parsed it will call you with
hid_input_end... Note: Some HID devices work to bypass some of this parsing...

But sometimes the most difficult part of this is the startup. That is some of these devices will need you to send them some special something to get started. Like some of them will need you to tell them that you want them to start sending them Report X... more on that later.
 
Yup, but the receivers with RTL2832 first (even if they have a "RTL2832" they have different additional chips but I think I can handle that when the communication is working.)
I can send you a link if you want. I'll use it as a SDR. There is a lib "libsdr" I want to port to the teensy.
 
Yup, but the receivers with RTL2832 first (even if they have a "RTL2832" they have different additional chips but I think I can handle that when the communication is working.)
I can send you a link if you want. I'll use it as a SDR. There is a lib "libsdr" I want to port to the teensy.

Yes please. Now I am curious which implies I am in trouble :)
 
Kurt, yes, RTL2832U & R820T looks good.
The dump i posted above is from a different one (has a different "tuner"-chip ) but I've oderd the one from the Amazon link I gave above that will arrive tomorrow.
However, they are pretty similar

Note that the windows software is outdated and DVB-T version 1 is, at least in Germany, switched off :) So, no point to use the original software (and do NOT install the driver - it will not work as a SDR with the original driver! you'll have to remove it, then..)
 
Kurt, yes, RTL2832U & R820T looks good.
The dump i posted above is from a different one (has a different "tuner"-chip ) but I've oderd the one from the Amazon link I gave above that will arrive tomorrow.
However, they are pretty similar

Just ordered the one Kurt posted as well - told you I am in trouble when I get curious.
 
LOL :)
Ok, if you want to use it for other things than FM you'll need different Antennas etc. , and for lower frequencies a little hack to the hardware is needed (Or a frequency shifter)
But FM works good without mods.

It spits out I/Q Data (no Audio - the I/Q need some processing to make Audio from it..) , so even when the Teensy driver parts runs, there is much to do... :) Maybe take a look at DD4WHs SDR thread :)
For Windows, try Airspy.
 
LOL :)
Ok, if you want to use it for other things than FM you'll need different Antennas etc. , and for lower frequencies a little hack to the hardware is needed (Or a frequency shifter)
But FM works good without mods.

It spits out I/Q Data (no Audio - the I/Q need some processing to make Audio from it..) , so even when the Teensy driver parts runs, there is much to do... :) Maybe take a look at DD4WHs SDR thread :)
For Windows, try Airspy.

At 24 pages, think that its going on the list of things to do :)
 
...Linux says, it is "usb-storage" (but it isn't)
Code:
frank@frank-lubuntu:~$ lsusb -v -t -d 1d19:
/:  Bus 02.Port 1: Dev 1, Class=root_hub, Driver=ohci-pci/12p, 12M
    |__ Port 1: Dev 2, If 0, Class=Human Interface Device, Driver=usbhid, 12M
/:  Bus 01.Port 1: Dev 1, Class=root_hub, Driver=ehci-pci/12p, 480M
    |__ Port 1: Dev 2, If 0, Class=Mass Storage, Driver=usb-storage, 480M
    |__ Port 2: Dev 3, If 0, Class=Vendor Specific Class, Driver=dvb_usb_rtl28xxu, 480M
    |__ Port 2: Dev 3, If 1, Class=Vendor Specific Class, Driver=, 480M

Edit, oops wrong device.
Seems to be this line only?
Code:
    |__ Port 2: Dev 3, If 0, Class=Vendor Specific Class, Driver=dvb_usb_rtl28xxu, 480M

usbhid-dump -d 1d19 | grep -v : | xxd -r -p | hidrd-convert -o spec | grep -v : | xxd -r -p | hidrd-convert -o spec

shows nothing.
 
Last edited:
The new Stick arrived sooner than I thought.
Attched the output from Usb Device Tree Viewer.

Interestingly, it does not show the IR Recceiver (but it must be there).
 

Attachments

  • device_820t.txt
    15.4 KB · Views: 120
Could this be it:
Code:
    ---------------------- Device Descriptor ----------------------
bLength                  : 0x12 (18 bytes)
bDescriptorType          : 0x01 (Device Descriptor)
bcdUSB                   : 0x200 (USB Version 2.00)
bDeviceClass             : 0x00 (defined by the interface descriptors)
bDeviceSubClass          : 0x00
bDeviceProtocol          : 0x00
bMaxPacketSize0          : 0x40 (64 bytes)
idVendor                 : 0x0BDA (Realtek Semiconductor Corp.)
idProduct                : 0x2838
bcdDevice                : 0x0100
iManufacturer            : 0x01 (String Descriptor 1)
 Language 0x0409         : "Realtek"
iProduct                 : 0x02 (String Descriptor 2)
 Language 0x0409         : [B]"RTL2838UHIDIR"[/B]
iSerialNumber            : 0x03 (String Descriptor 3)
 Language 0x0409         : "00000001"
bNumConfigurations       : 0x01 (1 Configuration)
Data (HexDump)           : 12 01 00 02 00 00 00 40 DA 0B 38 28 00 01 01 02   .......@..8(....
                           03 01                                             ..

Code:
       +++++++++++++++++ Device Information ++++++++++++++++++
Friendly Name            : RTL2838UHIDIR
[B]Device Description       : RTL2838UHIDIR[/B]
Device ID                : USB\VID_0BDA&PID_2838\00000001
Hardware IDs             : USB\VID_0BDA&PID_2838&REV_0100 USB\VID_0BDA&PID_2838
Driver KeyName           : {88bae032-5a81-49f0-bc3d-a4ff138216d6}\0001 (GUID_DEVCLASS_USBDEVICE)
Driver                   : \SystemRoot\System32\drivers\WinUsb.sys (Version: 10.0.19041.1  Date: 2019-12-07)
Driver Inf               : C:\WINDOWS\inf\oem23.inf
Legacy BusType           : PNPBus
Class                    : USBDevice
Class GUID               : {88bae032-5a81-49f0-bc3d-a4ff138216d6} (GUID_DEVCLASS_USBDEVICE)
Service                  : WinUSB
Enumerator               : USB
Location Info            : Port_#0004.Hub_#0004
Location IDs             : PCIROOT(0)#PCI(0801)#PCI(0004)#USBROOT(0)#USB(1)#USB(4), ACPI(_SB_)#ACPI(PCI0)#ACPI(GP17)#ACPI(XHC1)#ACPI(RHUB)#ACPI(PRT1)#USB(4)
Container ID             : {222e0e7c-ce5f-5afb-962a-44e96a1e19c7}
Manufacturer Info        : Realtek Semiconductor Corp.
Capabilities             : 0x14 (Removable, UniqueID)
Status                   : 0x0180600A (DN_DRIVER_LOADED, DN_STARTED, DN_DISABLEABLE, DN_REMOVABLE, DN_NT_ENUMERATOR, DN_NT_DRIVER)
Problem Code             : 0
HcDisableSelectiveSuspend: 0
EnableSelectiveSuspend   : 0
SelectiveSuspendEnabled  : 0
EnhancedPowerMgmtEnabled : 0
IdleInWorkingState       : 0
WakeFromSleepState       : 0
Power State              : D0 (supported: D0, D2, D3, wake from D0, wake from D2)

Did find this:
Code:
DVB-T/DAB USB dongle with Realtek RTL2832 chipset (sometimes badly named as RTL2838)
 
Interestingly, it does not show the IR Recceiver (but it must be there).
Oops missed this.

Don't see it. Maybe its looking at like a HID device. Its not showing device class?
 
Hi Frank,

Not sure the second one has HID or not...

But again maybe try plugging it into T3.6 or T4.x with one of the USBHost_t36 examples like I mentioned.
And at about line 62 in USBHost_t36.h uncomment the line: //#define USBHOST_PRINT_DEBUG
Build and see what all we print out about it.
 
Status
Not open for further replies.
Back
Top