Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed FastIO FastPWM USBDevice
Diff: USBJoystick/USBJoystick.cpp
- Revision:
- 40:cc0d9814522b
- Parent:
- 39:b3815a1c3802
- Child:
- 47:df7a88cd249c
--- a/USBJoystick/USBJoystick.cpp Mon Jan 11 21:08:36 2016 +0000 +++ b/USBJoystick/USBJoystick.cpp Wed Feb 03 22:57:25 2016 +0000 @@ -47,8 +47,9 @@ // Fill the report according to the Joystick Descriptor #define put(idx, val) (report.data[idx] = (val) & 0xff, report.data[(idx)+1] = ((val) >> 8) & 0xff) +#define putl(idx, val) (put(idx, val), put((idx)+2, (val) >> 16)) put(0, _status); - put(2, 0); // second byte of status isn't used in normal reports + put(2, 0); // second word of status - zero in high bit identifies as normal joystick report put(4, _buttonsLo); put(6, _buttonsHi); put(8, _x); @@ -119,7 +120,28 @@ return sendTO(&report, 100); } -bool USBJoystick::reportConfig(int numOutputs, int unitNo, int plungerZero, int plungerMax) +bool USBJoystick::reportID() +{ + HID_REPORT report; + + // initially fill the report with zeros + memset(report.data, 0, sizeof(report.data)); + + // Set the special status bits to indicate that it's an ID report + uint16_t s = 0x9000; + put(0, s); + + // write the 80-bit ID + put(2, SIM->UIDMH); + putl(4, SIM->UIDML); + putl(8, SIM->UIDL); + + // send the report + report.length = reportLen; + return sendTO(&report, 100); +} + +bool USBJoystick::reportConfig(int numOutputs, int unitNo, int plungerZero, int plungerMax, bool configured) { HID_REPORT report; @@ -140,6 +162,10 @@ put(6, plungerZero); put(8, plungerMax); + // write the status bits: + // 0x01 -> configuration loaded + report.data[10] = (configured ? 0x01 : 0x00); + // send the report report.length = reportLen; return sendTO(&report, 100);