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
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.
View all questions in Keil forum