USB
  multiple HID and one MSD on a -340

Post New Topic  Post A Reply
profile | register | preferences | faq | search

UBBFriend: Email This Page to Someone! next newest topic | next oldest topic
Author Topic:   multiple HID and one MSD on a -340
clauswk
New Member
posted January 24, 2008 03:06 PM     Click Here to See the Profile for clauswk   Click Here to Email clauswk     Edit/Delete Message
Greetings,

I am currently working on a project which must handle one USB HID mouse, one USB HID keyboard, one vendor specific HID interface and one Mass Storage Device.
I am using a C8051F340.
I have earlier implemented the mouse, the keyboard and the vendor HID interfaces, all interrupt driven, with success. (It passed the USB-IF test suite, AND works on the PC)

I did not use ReportIDs, instead I used different endpoints for the different interfaces.

Trying to implement the MSD on top of that gives me a lot of headache:
I am trying to use the same endpoint (EP1 in interrupt mode) for the three interfaces with reportIDs, and then use EP3 in bulk mode for the MSD.

I have trawled through all kind of application notes and the USB bibles with no luck.
Can anyone out there give me a couple of hints, what to do and what to avoid etc.

Thanks

------------------
Best regards,
Claus Knudsen

IP: Logged

Tsuneo
Member
posted January 24, 2008 11:25 PM     Click Here to See the Profile for Tsuneo   Click Here to Email Tsuneo     Edit/Delete Message
"I am currently working on a project which must handle one USB HID mouse, one USB HID keyboard, one vendor specific HID interface and one Mass Storage Device...
I am trying to use the same endpoint (EP1 in interrupt mode) for the three interfaces with reportIDs"

I recommend you this composite device configuration.
- Interface 0, EP2 IN/OUT, interrupt: vendor specific HID
- Interface 1, EP1 IN/OUT, interrupt: HID mouse + HID keyboard
- Interface 2, EP3 IN/OUT, bulk: Mass Storage, bulk-only transfer

The reasons are,
a) HID mouse + keyboard on single interface is an established technique.

b) Windows grab mouse and keyboard as system device. Direct access to these device instances from your host app is not allowed. When you add another collection (report ID) to this interface, the access to this collection may be refused by Windows.


The HID spec shows the outline for mouse + keyboard on single interface.
8.5 Report Example (HID1_11.pdf p57)

The combined report descriptor is made just by appending keyboard and mouse report descriptor. (revised the bug on report ID numbering on the example)

Collection (Application)        Keyboard
Report ID (01)
Input (Variable, Absolute) Modifier keys
Output (Variable, Absolute) LEDs
Input (Array, Absolute) Main keys
End Collection
Collection (Application) Mouse
Report ID (02)
Collection (Physical) Pointer
Input (Variable, Relative) X, Y
Input (Variable, Absolute) Button
End Collection
End Collection

On this combined interface, you cannot apply boot device.
(bInterfaceClass, bInterfaceSubclass, bInterfaceProtocol)
= (0x03, 0x00, 0x00) = (HID class, no subclass, no protocol)

The detailed report descriptor is as follows.
I just appended the keyboard and mouse report descriptor on the HID spec.
And inserted the Report ID fields.

Usage Page (Generic Desktop),
Usage (Keyboard),
Collection (Application),
Report ID (01),
Report Size (1),
Report Count (8),
Usage Page (Key Codes),
Usage Minimum (224),
Usage Maximum (231),
Logical Minimum (0),
Logical Maximum (1),
Input (Data, Variable, Absolute), ;Modifier byte
Report Count (1),
Report Size (8),
Input (Constant), ;Reserved byte
Report Count (5),
Report Size (1),
Usage Page (LEDs),
Usage Minimum (1),
Usage Maximum (5),
Output (Data, Variable, Absolute), ;LED report
Report Count (1),
Report Size (3),
Output (Constant), ;LED report padding
Report Count (6),
Report Size (8),
Logical Minimum (0),
Logical Maximum(255),
Usage Page (Key Codes),
Usage Minimum (0),
Usage Maximum (101),
Input (Data, Array),
End Collection

Usage Page (Generic Desktop),
Usage (Mouse),
Collection (Application),
Usage (Pointer),
Collection (Physical),
Report ID (02),
Report Count (3),
Report Size (1),
Usage Page (Buttons),
Usage Minimum (1),
Usage Maximum (3),
Logical Minimum (0),
Logical Maximum (1),
Input (Data, Variable, Absolute),
Report Count (1),
Report Size (5),
Input (Constant),
Report Size (8),
Report Count (2),
Usage Page (Generic Desktop),
Usage (X),
Usage (Y),
Logical Minimum (-127),
Logical Maximum (127),
Input (Data, Variable, Relative),
End Collection,
End Collection

Tsuneo

[This message has been edited by Tsuneo (edited January 24, 2008).]

IP: Logged

Patryk
Member
posted January 25, 2008 05:29 AM     Click Here to See the Profile for Patryk     Edit/Delete Message
Tsuneo:
"Windows grab mouse and keyboard as system device. Direct access to these device instances from your host app is not allowed."
WriteFile() and ReadFile() will fail, but HidD_SetFeature()/HidD_GetFeature() and HidD_GetInputReport()/HidD_SetOutputReport() works. Just need to use 0 for dwDesiredAccess and (FILE_SHARE_READ | FILE_SHARE_WRITE) for dwShareMode in a call to CreateFile().

IP: Logged

clauswk
New Member
posted January 25, 2008 01:57 PM     Click Here to See the Profile for clauswk   Click Here to Email clauswk     Edit/Delete Message
Thank you very much, Tsuneo, for your quick and, as always, precise and enlightening answer.

I just tried to implement a mouse and a keyboard to the HID Blinky example for the -340, and it just works excellent: The mouse is circling on the screen, and a test text is repeatedly written in my editor. And at the same time the LEDs are blinking in patterns controlled by the potmeter on the -340 DK.

Thanks,

------------------
Best regards,
Claus Knudsen

IP: Logged

Tsuneo
Member
posted January 25, 2008 05:45 PM     Click Here to See the Profile for Tsuneo   Click Here to Email Tsuneo     Edit/Delete Message
This topic on MSDN shows the way how Windows handle the combined report descriptor for keyboard and mouse.

Top-Level Collections
http://msdn2.microsoft.com/en-us/library/ms789908.aspx

Microsoft defines a top-level collection as a HID collection that is not nested within another collection. An unnested collection is always a top-level collection, regardless of its HID type. In particular, a top-level collection does not have to be an Application collection, as defined by the USB HID standard.

A report descriptor can include more than one top-level collection. The HID class driver enumerates the top-level collections of an input device and creates a physical device object (PDO) for each top-level collection. User-mode applications or kernel-mode drivers can access a top-level collection by opening its PDO and using the HIDClass support routines and the HID class driver IOCTLs.

Tsuneo

IP: Logged

Umetsu
New Member
posted March 26, 2009 06:42 AM     Click Here to See the Profile for Umetsu   Click Here to Email Umetsu     Edit/Delete Message
I'd like to USB composite device such as HID keyboard and mouse.

So, I tried it implementing the above Report-descriptor which is written by Mr. Tsuneo.

ReportID #1 = keyboard.
ReportID #2 = Mouse.

For keyboard, I can received two byte data vir EP0 OUT. ReportID=0x01 and 8bit of keyboard LED(combination of NumLock, ScrLock and so on).

Now where, I'd like to send key code(ex. key 'A' is 0x04) to PC.
So I prepared 8 bytes data - 1 byte modifier keys, 1 byte reserved 0x00, 6 bytes of key code(such as 0x04='A', 0x00, 0x00, 0x00, 0x00, 0x00) vir EP0 IN.

But, my PC can't receive anything...

I'd like to ask why this didn't work correctly.

Does the keyboard report ID needed to send key code to PC?
In case of this, 1+8 bytes data transmittion is needed? (Report ID, Modifier keys, 0x00 reserved, 6 key code)??


If any specification or source code sample are available, could you please tell me?

[This message has been edited by Umetsu (edited March 26, 2009).]

IP: Logged

ElectroLund
New Member
posted April 05, 2010 04:44 PM     Click Here to See the Profile for ElectroLund     Edit/Delete Message
Sorry to everyone for resurrecting a very old post! But I'm in the beginning stages of doing a similar exercise... making a HID-based USB device which is both mouse and keyboard.

I don't need other functions like storage.

Tsuneo, your post is most helpful. However, I have a problem with one area in your keyboard descriptor section. You listed a "Usage Maximum (101)". When I use the HID Descriptor Tool and open its keybrd.hid example, the USAGE_MAXIMUM has predefined values (like Keyboard RightAlt, etc.), none of which will allow me the value of 101.

Did you mean to put 101 in the Logical Maximum? The HID Descriptor Tool's default value for Logical Maximum was 101, which seems to be the number of keys.

IP: Logged

Tsuneo
Member
posted April 17, 2010 05:25 AM     Click Here to See the Profile for Tsuneo   Click Here to Email Tsuneo     Edit/Delete Message
> none of which will allow me the value of 101.

101 is in decimal. Choose this keycode,
0x65 Keyboard Application

Tsuneo

IP: Logged

ElectroLund
New Member
posted April 19, 2010 04:45 PM     Click Here to See the Profile for ElectroLund     Edit/Delete Message
Tsuneo, thanks for your reply! I am working with Freescale's JS16. Using your method of multiple reports, single interface, I am able to have both mouse and keyboard HID descriptors register on host PC correctly.

However, my data buffers now are not sent to the host PC. None of my mouse and keyboard inputs seem to get sent to the host. I assume there is some collision happening.

IP: Logged

Tsuneo
Member
posted April 19, 2010 05:26 PM     Click Here to See the Profile for Tsuneo   Click Here to Email Tsuneo     Edit/Delete Message
However, my data buffers now are not sent to the host PC. None of my mouse and keyboard inputs seem to get sent to the host.

Check the USB traffic using a hardware analyzer or software sniffer.
There are two possibility,

a) The device doesn't return any packet for interrupt IN transaction
- NAKing or timeout error

b) The device returns packets, but HID device driver drops them on the PC.

a) means
- The interrupt IN endpoint is not enabled on the firmware
OR
- The packet is not actually loaded to the endpoint

b) means the format of the input reports is wrong.
For above report descriptor with multiple TLCs (Top-Level Collections), the input report format is as follows

For keyboard,

offset (byte)
0 report ID (01)
1 modifier keys
2 padding
3 - 8 keycode array

For mouse,

offset (byte)
0 report ID (02)
1 buttons
2 X asis
3 Y axis


Software sniffers
SniffUSB (Open source)
http://www.pcausa.com/Utilities/UsbSnoop/default.htm

Usblyzer (commercial with free trial)
http://www.usblyzer.com/
etc.

> I am working with Freescale's JS16.

Then, continue on Freescale forum - 8-Bit Microcontrollers, if any.
http://forums.freescale.com/t5/8-Bit-Microcontrollers/bd-p/8BITCOMM
I have account on the Freescale forum, too, though I'm not active on the forum.

Tsuneo

IP: Logged

Tsuneo
Member
posted April 22, 2010 08:12 PM     Click Here to See the Profile for Tsuneo   Click Here to Email Tsuneo     Edit/Delete Message
This discussion with ElectroLund (irob) continues to this topic on Freescale forum,

DEMO9S08JS16 - hybrid USB peripheral?
http://forums.freescale.com/t5/8-Bit-Microcontrollers/DEMO9S08JS16-hybrid-USB-peripheral/td-p/53244

Tsuneo

[This message has been edited by Tsuneo (edited April 22, 2010).]

IP: Logged

All times are CT (US)

next newest topic | next oldest topic

Administrative Options: Close Topic | Archive/Move | Delete Topic
Post New Topic  Post A Reply
Hop to:

Contact Us | MCU User Forum

Have you seen our MCU Knowledge Base?


Ultimate Bulletin Board 5.47b