Hi all,
Thanks for your contineous support from this site.
I want to detect my board as HID mouse when plugged to USB port of PC. For that I guess I need to write HID mouse driver.
I am using LPC2148 controller. Can i gett some reference code for it?
Thanks & Regards, Kamal
> Can i gett some reference code for it?
Implementation of keyboard and mouse is a good exercise for USB starters to learn Class implementation, because HID spec documents on keyboard and mouse well.
HID spec v1.11 www.usb.org/.../HID1_11.pdf - Appendix E: Example USB Descriptors for HID Class Devices (p66) - Appendix B.2 Protocol 2 (Mouse) (p61)
Starting with a HID example which fits to your compiler,
- LPC2148 USB HID (Human Interface Device) Example - MDK-ARM http://www.keil.com/download/docs/306.asp
- LPCUSB - GNU ARM (YAGARTO, etc) sourceforge.net/.../
Modification of 40-50 lines of its source code (including 26 lines of report descriptor) makes your board a mouse.
If you want to learn on USB, I'll guide you.
Tsuneo
Tsuneo,
I'm soon going to be looking at USB on ARM.
Thank you so much for those links - Some very good bedtime reading :)
Hi Tsuneo,
Thanks for those documents.
I tried both the ways...
1. Changed all the descriptor tables as mentioned in the HID1_1.pdf like:
const U8 HID_ReportDescriptor[] = { 0x05,0x01, 0x09,0x02, 0xA1,0x01, 0x09,0x01, 0xA1,0x00, 0x05,0x09, 0x19,0x01, 0x29,0x03, 0x15,0x00, 0x25,0x01, 0x95,0x03, 0x75,0x01, 0x81,0x02, 0x95,0x01, 0x75,0x05, 0x81,0x01, 0x05,0x01, 0x09,0x30, 0x09,0x31, 0x15,0x81, 0x25,0x7F, 0x75,0x08, 0x95,0x02, 0x81,0x06, 0xC0, 0xC0 }; const U16 HID_ReportDescSize = sizeof(HID_ReportDescriptor); /* USB Standard Device Descriptor */ const U8 USB_DeviceDescriptor[] = { 0x12, 0x01, WBVAL(0x100), 0x00, 0x00, 0x00, 0x08, WBVAL(0xFFFF), WBVAL(0x0001), WBVAL(0x0100), 0x04, 0x0E, 0x30, 0x01 }; /* USB Configuration Descriptor */ /* All Descriptors (Configuration, Interface, Endpoint, Class, Vendor) */ const U8 USB_ConfigDescriptor[] = { /* Configuration 1 */ 0x09, 0x02, WBVAL(0x003), 0x02, 0x01, 0x00, 0xA0, 0x32, /* Interface 0, Alternate Setting 0, HID Class */ 0x09, 0x04, 0x01, 0x00, 0x01, 0x03, 0x01, 0x02, 0x00, /* HID Class Descriptor */ /* HID_DESC_OFFSET = 0x0012 */ 0x09, 0x21, WBVAL(0x101), 0x00, 0x01, 0x22, 0x32, /* Endpoint, HID Interrupt In */ 0x07, 0x05, 0x82, 0x03, WBVAL(0x0008), 0x0A, /* Terminator */ 0 /* bLength */ };
2. I kept the the other descriptor as it is and changed only Report, Interface, HID, Endpoint descriptor. String Descriptor remains the same. Both the ways windows could not detect the board as HID Mouse.
Am I missing something?
One more question, How should i send the mouse data to pc ? What should be its format?
I made the Report Descriptor in readable format now:-)
const U8 HID_ReportDescriptor[] = { HID_UsagePage(HID_USAGE_PAGE_GENERIC), HID_Usage(HID_USAGE_GENERIC_MOUSE), HID_Collection (HID_Application), HID_Usage (HID_USAGE_GENERIC_POINTER), HID_Collection (HID_Physical), HID_ReportCount (3), HID_ReportSize (1), HID_UsagePage (HID_USAGE_PAGE_BUTTON), HID_UsageMin (1), HID_UsageMax (3), HID_LogicalMin (0), HID_LogicalMax (1), HID_Input (HID_Data | HID_Variable | HID_Absolute), HID_ReportCount (1), HID_ReportSize (5), HID_Input (HID_Constant), HID_ReportSize (8), HID_ReportCount (2), HID_UsagePage(HID_USAGE_PAGE_GENERIC), HID_Usage(HID_USAGE_GENERIC_X), HID_Usage(HID_USAGE_GENERIC_Y), HID_LogicalMin(0x81), HID_LogicalMax (0x7F), HID_Input (HID_Data | HID_Variable | HID_Relative), HID_EndCollection, HID_EndCollection };
As the USB mouse protocol requires 3 bytes of Data (Button, X Displacement, Y Displacement), I declared U8 InReport as
U8 InReport[3] = {0};
void GetInReport (void) function does nothing (Code stubing will be done later)
I feel by doing so, it should work but....:-( It is still not working...
Are there any other changes i need to take care ?
Thanks & Regards, Kamal Joshi
Are you working on Keil HID example?
Then, you don't need to swap entire descriptors. Replace just the report descriptor.
I see some errors on the config descriptor set in above post, for example, wTotalLength field. But it's pain to examine the figures without any comment for the fields. I recomend you to recover the original descriptors from the example.
For other change,
demo.c BYTE InReport[3]; /* HID Input Report - 3 bytes for mouse */ /* * Get HID Input Report -> InReport */ void GetInReport (void) { // // Fill InReport[] // // InReport[0] mouse buttons, bit 0: left, bit 1: right, bit2: middle // InReport[1] X axis relative movement // InReport[2] Y axis relative movement // }
Hello guys,
I am a first timer with USB and like many others, VERY CONFUSED.
To start with, i have downloaded the example code for USBHID for LPC2368 and it is not working, leading to more confusion but most of them are conceptual and here are a few of them :
1. How will the code call the functions usbcore.c ?
2. How will the code initialize the descriptors and endpoints ?
Any help will be greatly appreciated.
Thanks. Nitin
Don't you think you should start with a new thread, instead of hijacking someone elses?
Yes, I should have.
Apologies for that.
Can you please tell me how to start a new one ?
Thanks.
Got it ..
Please Help Tsuneo !
Sorry for posting here again.
Dear Tsuneo,
I have an example code (made from this link:sourceforge.net/.../) which makes LPC2148 to be a USB joystick device, it's working good. Now I want to make LPC2148 to become a USB keyboard device, running on Keil MCB2140 board, I changed the report desciptor following HID 1.1 pdf, but the host PC still detects it as a HID-compliant game controller??
Here is my report descriptor: static UNS_8 abReportDesc[] = { HID_UsagePage(HID_USAGE_PAGE_GENERIC), HID_Usage(HID_USAGE_GENERIC_KEYBOARD), HID_Collection(HID_Application), HID_UsagePage(HID_USAGE_PAGE_KEYBOARD), HID_UsageMin(224), HID_UsageMax(231), HID_LogicalMin(0), HID_LogicalMax(1), HID_ReportSize(1), HID_ReportCount(8), HID_Input(HID_Data | HID_Variable | HID_Absolute), HID_ReportCount(1), HID_ReportSize(8), HID_Input(HID_Constant), HID_ReportCount(8), HID_ReportSize(1), HID_UsagePage(HID_USAGE_PAGE_LED), HID_UsageMin(1), HID_UsageMax(8), HID_Output(HID_Data | HID_Variable | HID_Absolute), HID_UsagePage(HID_USAGE_PAGE_KEYBOARD), HID_UsageMin(0), HID_UsageMax(101), HID_LogicalMin(0), HID_LogicalMax(101), HID_ReportSize(8), HID_ReportCount(6), HID_Input(HID_Data | HID_Array), HID_EndCollection, };
Please take a look and give me some advices! Thanks for your time! Tuong Nguyen
Sorry, I repost my report descriptor:
static UNS_8 abReportDesc[] = { HID_UsagePage(HID_USAGE_PAGE_GENERIC), HID_Usage(HID_USAGE_GENERIC_KEYBOARD), HID_Collection(HID_Application), HID_UsagePage(HID_USAGE_PAGE_KEYBOARD), HID_UsageMin(224), HID_UsageMax(231), HID_LogicalMin(0), HID_LogicalMax(1), HID_ReportSize(1), HID_ReportCount(8), HID_Input(HID_Data | HID_Variable | HID_Absolute), HID_ReportCount(1), HID_ReportSize(8), HID_Input(HID_Constant), HID_ReportCount(8), HID_ReportSize(1), HID_UsagePage(HID_USAGE_PAGE_LED), HID_UsageMin(1), HID_UsageMax(8), HID_Output(HID_Data | HID_Variable | HID_Absolute), HID_UsagePage(HID_USAGE_PAGE_KEYBOARD), HID_UsageMin(0), HID_UsageMax(101), HID_LogicalMin(0), HID_LogicalMax(101), HID_ReportSize(8), HID_ReportCount(6), HID_Input(HID_Data | HID_Array), HID_EndCollection, };
Tuong,
> I changed the report desciptor following HID 1.1 pdf, but the host PC still detects it as a HID-compliant game controller??
Delete (uninstall) the device instance (game controller) once using USBDeview.
Windows keep records of device configuration on the registry. When the device configuration change, Windows often fail to refresh the record. Deleting the device instance trashes the record on the registry.
USBDeview lists up all USB device instances, regardless of current connection.
USBDeview www.nirsoft.net/.../usb_devices_view.html
OR
You are able to show up all registered devices in Device Manager. 1) Copy these two lines to a blank text file, and rename the file to DevManager.bat
set devmgr_show_nonpresent_devices=1 start devmgmt.msc
2) Double click DevManager.bat, and Device Manager comes up. Under 'View' menu, select 'Show hidden devices'
Thanks so much for your guidance! I have my PC detects MCB2140 as a USB keyboard and play arround with 2 bytes report in, one for modify keys one for array keys. But I still have one stupid question, need your help!!
Actually, in HID1_11.pdf, there is a report example for a standard keyboard, which the report data is 8 bytes format(1 modify keys, 1 reserve, 6 for array keys). And I see that Windows only has the maximum number of combined keys is 3 or 4, ex: CTRL+ALT+DEL, so I wonder why the standard keyboard has the report in data format is 8, is it redundant??
Please help me clear! Tuong Nguyen
I don't know if this is relevant to USB but a key press in Windows can use any number of modifiers.
CTRL+ALT+DEL is just the single key DEL with CTRL and ALT as modifiers.
But the next issue is that a keyboard can handle n-key rollover, in which it keeps track of n concurrently pressed characters, and then reports the key releases first when you do release any of the n pressed keys.
So in a game, you may press one key to move forward, while pressing another to slide sideways, while pressing a third key to fire a weapon and potentially a fourth key to aim through a sniper scope. For a gamer, it is important to select a good keyboard that supports a large "n", so it is able to keep track of many concurrently pressed keys.