Hello, I'm using the DEMO9S08JS16 and going through the labs now. Pretty nice little micro.
There is included a lab and source code for turning the micro into a USB mouse and another for USB keyboard, using the HID standard.
My question is, could it be possible to use both at the same time with HID, such that some buttons would be mouse control and others keyboard keys? Anyone tried this?
已解决! 转到解答。
Increase the wMaxPacketSize for the interrupt IN endpoint into 9.
It is assigned HID_INT_IN_EP_SIZE macro
Hid.h#define HID_INT_IN_EP_SIZE 9
Where did you change?
On the trace, the device still returns the input report without any report ID.
Revise your code so that you see this report format on the trace.
For keyboard,offset (byte) 0 report ID (01) 1 modifier keys 2 padding 3 - 8 keycode arrayFor mouse,offset (byte) 0 report ID (02) 1 buttons 2 X asis 3 Y axis
You run USBlyzer and SnifUsb (usbsnoop) at the same time.
It causes the trace complicated.
Tsuneo
My goal here is to make a composite HID device, a mouse & keyboard, using the MC9S08JS16. My platform for testing is the DEMO9S08JM board with JS16 module plugged in.
I started with the demo kit's example HID keyboard and mouse projects. Nice software, but by no means non-trivial! From what I've read elsewhere, the best approach would be to make a single endpoint with two interfaces. I've begun this, but would appreciate anyone's input. I've attached the project so far, which is far from compiling.
(UPDATE)
I now have both mouse and keyboard HID descriptors concatenated into one HID_RPT, by using 2 report IDs. See here for more info. However, data buffers are no longer sent to the host PC, and I'm not sure why.
Attached is the updated software.
I have recently discovered that the added ReportID lines in the descriptors (Usb_Descriptors.c) are what causes the data buffers to disappear.
As a simple test, I took the keyboard-only HID sample code, added the ReportID line. The host will continue to register this device correctly as a HID keyboard. But none of the data buffers will make it to the host (pressing keys results in nothing to the PC).
So the data buffer routines must need some more work to handle the added ReportIDs
Are you the same one who posted to SiLabs USB forum about multiple TLCs (Top-Level Collections) of keyboard and mouse?
http://www.cygnal.org/ubb/Forum9/HTML/001496.html
irob wrote:As a simple test, I took the keyboard-only HID sample code, added the ReportID line. The host will continue to register this device correctly as a HID keyboard.
After changing the report descriptor, delete (uninstall) the device once on the device manager, or USBDeview, unless the VID/PID of the device is also changed. And then, the device is recognized as both of keyboard and mouse.
http://www.nirsoft.net/utils/usb_devices_view.html
irob wrote:
So the data buffer routines must need some more work to handle the added ReportIDs
You are right.
As I wrote on above SiLabs post, each input report has to be preceded by the report ID.
Tsuneo
Tsuneo, I have prepended the report ID (0x01 or 0x02 for my keyboard or mouse) into the function HID_Transfer_Rpt() which is in hid.c.
Unfortunately, the host PC is still not seeing data. I also tried prepending the ReportID keyword code of 0x85, thinking maybe that was required.
HC08 is big endian and the PC is little endian. I thought maybe I should reverse the position of the Report ID in my data buffer. Tried that, still didn't work. Hmm.
Monitor USB traffic using a hardware USB analyzer or software sniffer.
Is the host reads out the input report from the interrupt IN endpoint?
For software sniffers,
If BulkOrInterrupt request is held in pending, the firmware doesn't put the report to the endpoint correctly.
If the request fails, the endpoint is not initialized well.
If the request success, but the host app doesn't see the report, the report format (usually report length, or report ID) is wrong.
Software sniffers
SniffUsb (open source) http://www.pcausa.com/Utilities/UsbSnoop/default.htm
USBlyzer (with free trial) http://www.usblyzer.com/
HHD USB monitor (with free trial) http://www.hhdsoftware.com/Downloads/usb-monitor.html
Tsuneo
Tsuneo, you've been a big help. I took your advice and am running USBlyzer now. It is showing me some interesting things. For one, I see that the the Input Report length is still only 8 bytes, though I've increased the buffer size in software to 9 bytes (to include the ReportID). USBlyzer shows a buffer length of 9, but an Input Report of only 8. See below...
Capture List
START | 0001 | 14:39:14.049 | ||||||||||
URB | 0002 | 14:39:16.034 | Bulk or Interrupt Transfer | 9 bytes buffer | in | 01:00:81 | 892EB878h | usbsnoop | 89381BB0h | |||
URB | 0003 | 14:39:16.034 | Bulk or Interrupt Transfer | 9 bytes buffer | in | 01:00:81 | 892436C0h | USBPDO-8 | 89381BB0h | |||
URB | 0004 | 14:39:16.143 | Bulk or Interrupt Transfer | 9 bytes buffer | in | 01:00:81 | 892EB878h | usbsnoop | 89480B80h | |||
URB | 0005 | 14:39:16.143 | Bulk or Interrupt Transfer | 9 bytes buffer | in | 01:00:81 | 892436C0h | USBPDO-8 | 89480B80h | |||
URB | 0006-0003 | 14:39:18.768 | Bulk or Interrupt Transfer | Input Report len:8 | 00 00 4F 00 00 00 00 00 | in | 01:00:81 | 892436C0h | USBPDO-8 | 89381BB0h | Success (Success) | |
URB | 0007-0002 | 14:39:18.768 | Bulk or Interrupt Transfer | Input Report len:8 | 00 00 4F 00 00 00 00 00 | in | 01:00:81 | 892EB878h | usbsnoop | 89381BB0h | Success (Success) | |
URB | 0008 | 14:39:18.768 | Bulk or Interrupt Transfer | 9 bytes buffer | in | 01:00:81 | 892EB878h | usbsnoop | 89381BB0h | |||
URB | 0009 | 14:39:18.768 | Bulk or Interrupt Transfer | 9 bytes buffer | in | 01:00:81 | 892436C0h | USBPDO-8 | 89381BB0h | |||
URB | 0010-0005 | 14:39:18.846 | Bulk or Interrupt Transfer | Input Report len:8 | 00 00 00 00 00 00 00 00 | in | 01:00:81 | 892436C0h | USBPDO-8 | 89480B80h | Success (Success) | |
URB | 0011-0004 | 14:39:18.846 | Bulk or Interrupt Transfer | Input Report len:8 | 00 00 00 00 00 00 00 00 | in | 01:00:81 | 892EB878h | usbsnoop | 89480B80h | Success (Success) | |
URB | 0012 | 14:39:18.846 | Bulk or Interrupt Transfer | 9 bytes buffer | in | 01:00:81 | 892EB878h | usbsnoop | 89480B80h | |||
URB | 0013 | 14:39:18.846 | Bulk or Interrupt Transfer | 9 bytes buffer | in | 01:00:81 | 892436C0h | USBPDO-8 | 89480B80h | |||
URB | 0014-0009 | 14:39:27.205 | Bulk or Interrupt Transfer | Input Report len:8 | 00 00 58 00 00 00 00 00 | in | 01:00:81 | 892436C0h | USBPDO-8 | 89381BB0h | Success (Success) | |
URB | 0015-0008 | 14:39:27.205 | Bulk or Interrupt Transfer | Input Report len:8 | 00 00 58 00 00 00 00 00 | in | 01:00:81 | 892EB878h | usbsnoop | 89381BB0h | Success (Success) | |
URB | 0016 | 14:39:27.205 | Bulk or Interrupt Transfer | 9 bytes buffer | in | 01:00:81 | 892EB878h | usbsnoop | 89381BB0h | |||
URB | 0017 | 14:39:27.205 | Bulk or Interrupt Transfer | 9 bytes buffer | in | 01:00:81 | 892436C0h | USBPDO-8 | 89381BB0h | |||
URB | 0018-0013 | 14:39:27.299 | Bulk or Interrupt Transfer | Input Report len:8 | 00 00 00 00 00 00 00 00 | in | 01:00:81 | 892436C0h | USBPDO-8 | 89480B80h | Success (Success) | |
URB | 0019-0012 | 14:39:27.299 | Bulk or Interrupt Transfer | Input Report len:8 | 00 00 00 00 00 00 00 00 | in | 01:00:81 | 892EB878h | usbsnoop | 89480B80h | Success (Success) | |
URB | 0020 | 14:39:27.299 | Bulk or Interrupt Transfer | 9 bytes buffer | in | 01:00:81 | 892EB878h | usbsnoop | 89480B80h | |||
URB | 0021 | 14:39:27.299 | Bulk or Interrupt Transfer | 9 bytes buffer | in | 01:00:81 | 892436C0h | USBPDO-8 | 89480B80h |
Increase the wMaxPacketSize for the interrupt IN endpoint into 9.
It is assigned HID_INT_IN_EP_SIZE macro
Hid.h#define HID_INT_IN_EP_SIZE 9
Where did you change?
On the trace, the device still returns the input report without any report ID.
Revise your code so that you see this report format on the trace.
For keyboard,offset (byte) 0 report ID (01) 1 modifier keys 2 padding 3 - 8 keycode arrayFor mouse,offset (byte) 0 report ID (02) 1 buttons 2 X asis 3 Y axis
You run USBlyzer and SnifUsb (usbsnoop) at the same time.
It causes the trace complicated.
Tsuneo
This is another problem from above one.
You are enabling boot keyboard on the interface descriptor.
But it is not supported on your code at all.
/* Interface Descriptor */ { sizeof(USB_INTF_DSC), /* Size of this descriptor in bytes */ DSC_INTF, /* INTERFACE descriptor type */ 0, /* Interface Number */ 0, /* Alternate Setting Number */ 2, /* Number of endpoints in this intf */ HID_INTF, /* Class code */ BOOT_INTF_SUBCLASS, /* Subclass code */ <--------// keyboard: HID_PROTOCOL_KEYBOAD, /* Protocol code */ <--------// mouse:// HID_PROTOCOL_MOUSE, /* Protocol code */ 0 /* Interface string index */ },
1) hid.c handles Get_Protocol and Set_Protocol requests properly, but Current_Active_Protocol is not initialized to report protocol (1) anywhere. Add the initialization to Init_EP_For_HID(), which is called from Set_Configuration handler.
#define HID_PROTOCOL_BOOT 0#define HID_PROTOCOL_REPORT 1void Init_EP_For_HID(void){ ... ... // <-------- add this line Current_Active_Protocol = HID_PROTOCOL_REPORT; // set to default report protocol return;}
2) While Current_Active_Protocol is boot protocol (0), return this "standard" keyboard report. No mouse report is sent to host.
offset (byte) 0 modifier keys 1 padding 2 - 7 keycode array
When Current_Active_Protocol is report protocol (1), both of keyboard and mouse reports are sent back in turn, as described above.
Tsuneo
I appreciate the work you did for this, and decided to give it a try.
I tried building the zipped code that you posted. I had to fix two errors before it built. HID_RPT_SIZE in hid.h was 63, and needed to be 119 to accomodate the additional mouse stuff. Also in hid.c the definition of HID_Transfer_Rpt was the old definition with two parameters. After fixing these and building it, It doesn't allow me to send keystrokes. I haven't gotten into debugging it yet. But I'm suspicious, since the code that you posted doesn't build, might it be missing some other changes?
Thanks again for your efforts.
Akalaka, did you download the zip in my latest message? Check it out, because I thought I had fixed all the errors you're describing.
Unfortunately, after a certain amount of time, use posters are no longer able to edit our messages or delete old attachments.
Let me know if the zip file from my ver last post works for you.
The sources you previously posted are identical. My problem was with some code that didn't take into account the additional offset on Rpt_Buf. My target is not the eval board, so I had to adapt it to make it work. It's now working fine. Again, many thanks for your efforts!
Tsuneo, yes, it's me! Very clever of you to track me down. What I found was that I didn't need to delete the device from the Device Manager. MS Windows found both mouse and keyboard when I inserted onto its USB bus.
However, it's the data buffers that aren't working right now. Thanks for your help regarding the report IDs. I will see about preceding the data buffer output routines with the report ID.