Skip to content

Instantly share code, notes, and snippets.

@avtolstoy
Created December 7, 2017 13:22
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save avtolstoy/8a5c0f78693cc6d1843d19040adaff52 to your computer and use it in GitHub Desktop.
Save avtolstoy/8a5c0f78693cc6d1843d19040adaff52 to your computer and use it in GitHub Desktop.
diff --git a/platform/MCU/STM32F2xx/SPARK_Firmware_Driver/inc/usbd_mhid.h b/platform/MCU/STM32F2xx/SPARK_Firmware_Driver/inc/usbd_mhid.h
index af483adc6..ca707fffc 100644
--- a/platform/MCU/STM32F2xx/SPARK_Firmware_Driver/inc/usbd_mhid.h
+++ b/platform/MCU/STM32F2xx/SPARK_Firmware_Driver/inc/usbd_mhid.h
@@ -6,7 +6,7 @@
#define USBD_MHID_CONFIG_DESC_SIZE 32
#define USBD_MHID_DESC_SIZE 9
-#define USBD_MHID_REPORT_DESC_SIZE 178
+#define USBD_MHID_REPORT_DESC_SIZE 45
#define USBD_MHID_DIGITIZER_REPORT_DESC_SIZE 65
diff --git a/platform/MCU/STM32F2xx/SPARK_Firmware_Driver/src/usbd_mhid.c b/platform/MCU/STM32F2xx/SPARK_Firmware_Driver/src/usbd_mhid.c
index de9806131..932cc8dd2 100644
--- a/platform/MCU/STM32F2xx/SPARK_Firmware_Driver/src/usbd_mhid.c
+++ b/platform/MCU/STM32F2xx/SPARK_Firmware_Driver/src/usbd_mhid.c
@@ -97,47 +97,43 @@ static const uint8_t USBD_MHID_CfgDesc[USBD_MHID_CONFIG_DESC_SIZE] =
__ALIGN_BEGIN static const uint8_t USBD_MHID_DefaultReportDesc[USBD_MHID_REPORT_DESC_SIZE] __ALIGN_END =
{
- 0x05, 0x01, // USAGE_PAGE (Generic Desktop)
- 0x09, 0x02, // USAGE (Mouse)
- 0xa1, 0x01, // COLLECTION (Application)
- 0x85, 0x01, // REPORT_ID (1)
- 0x09, 0x01, // USAGE (Pointer)
- 0xa1, 0x00, // COLLECTION (Physical)
- 0x05, 0x09, // USAGE_PAGE (Button)
- 0x19, 0x01, // USAGE_MINIMUM (Button 1)
- 0x29, 0x03, // USAGE_MAXIMUM (Button 3)
- 0x15, 0x00, // LOGICAL_MINIMUM (0)
- 0x25, 0x01, // LOGICAL_MAXIMUM (1)
- 0x95, 0x03, // REPORT_COUNT (3)
- 0x75, 0x01, // REPORT_SIZE (1)
- 0x81, 0x02, // INPUT (Data,Var,Abs)
- 0x95, 0x01, // REPORT_COUNT (1)
- 0x75, 0x05, // REPORT_SIZE (5)
- 0x81, 0x03, // INPUT (Cnst,Var,Abs)
- 0x05, 0x01, // USAGE_PAGE (Generic Desktop)
- 0x09, 0x30, // USAGE (X)
- 0x09, 0x31, // USAGE (Y)
- // 0x36, 0x01, 0x80, // PHYSICAL_MINIMUM (-32767)
- // 0x46, 0xff, 0x7f, // PHYSICAL_MAXIMUM (32767)
- 0x16, 0x01, 0x80, // LOGICAL_MINIMUM (-32767)
- 0x26, 0xff, 0x7f, // LOGICAL_MAXIMUM (32767)
+ // 0x05, 0x01, // USAGE_PAGE (Generic Desktop)
+ // 0x09, 0x02, // USAGE (Mouse)
+ // 0xa1, 0x01, // COLLECTION (Application)
+ // 0x85, 0x01, // REPORT_ID (1)
+ // 0x09, 0x01, // USAGE (Pointer)
+ // 0xa1, 0x00, // COLLECTION (Physical)
+ // 0x05, 0x09, // USAGE_PAGE (Button)
+ // 0x19, 0x01, // USAGE_MINIMUM (Button 1)
+ // 0x29, 0x03, // USAGE_MAXIMUM (Button 3)
+ // 0x15, 0x00, // LOGICAL_MINIMUM (0)
+ // 0x25, 0x01, // LOGICAL_MAXIMUM (1)
+ // 0x95, 0x03, // REPORT_COUNT (3)
+ // 0x75, 0x01, // REPORT_SIZE (1)
+ // 0x81, 0x02, // INPUT (Data,Var,Abs)
+ // 0x95, 0x01, // REPORT_COUNT (1)
+ // 0x75, 0x05, // REPORT_SIZE (5)
+ // 0x81, 0x03, // INPUT (Cnst,Var,Abs)
+ // 0x05, 0x01, // USAGE_PAGE (Generic Desktop)
+ // 0x09, 0x30, // USAGE (X)
+ // 0x09, 0x31, // USAGE (Y)
+ // 0x16, 0x01, 0x80, // LOGICAL_MINIMUM (-32767)
+ // 0x26, 0xff, 0x7f, // LOGICAL_MAXIMUM (32767)
+ // 0x75, 0x10, // REPORT_SIZE (16)
+ // 0x95, 0x02, // REPORT_COUNT (2)
+ // 0x81, 0x06, // INPUT (Data,Var,Rel)
+ // 0x09, 0x38, // USAGE (WHEEL)
// 0x15, 0x81, // LOGICAL_MINIMUM (-127)
// 0x25, 0x7f, // LOGICAL_MAXIMUM (127)
- 0x75, 0x10, // REPORT_SIZE (16)
- 0x95, 0x02, // REPORT_COUNT (2)
- 0x81, 0x06, // INPUT (Data,Var,Rel)
- 0x09, 0x38, // USAGE (WHEEL)
- 0x15, 0x81, // LOGICAL_MINIMUM (-127)
- 0x25, 0x7f, // LOGICAL_MAXIMUM (127)
- 0x75, 0x08, // REPORT_SIZE (8)
- 0x95, 0x01, // REPORT_COUNT (1)
- 0x81, 0x06, // INPUT (Data,Var,Rel)
- 0xc0, // END_COLLECTION
- 0xc0, // END_COLLECTION
+ // 0x75, 0x08, // REPORT_SIZE (8)
+ // 0x95, 0x01, // REPORT_COUNT (1)
+ // 0x81, 0x06, // INPUT (Data,Var,Rel)
+ // 0xc0, // END_COLLECTION
+ // 0xc0, // END_COLLECTION
0x05, 0x01, // USAGE_PAGE (Generic Desktop)
0x09, 0x06, // USAGE (Keyboard)
0xa1, 0x01, // COLLECTION (Application)
- 0x85, 0x02, // REPORT_ID (2)
+ // 0x85, 0x02, // REPORT_ID (2)
0x05, 0x07, // USAGE_PAGE (Keyboard)
0x19, 0xe0, // USAGE_MINIMUM (Keyboard LeftControl)
0x29, 0xe7, // USAGE_MAXIMUM (Keyboard Right GUI)
@@ -168,38 +164,38 @@ __ALIGN_BEGIN static const uint8_t USBD_MHID_DefaultReportDesc[USBD_MHID_REPORT_
0x29, 0xdd, // USAGE_MAXIMUM (Keypad Hexadecimal)
0x81, 0x00, // INPUT (Data,Ary,Abs)
0xc0, // END_COLLECTION
- 0x05, 0x0d, // USAGE_PAGE (Digitizer)
- 0x09, 0x02, // USAGE (Pen)
- 0xa1, 0x01, // COLLECTION (Application)
- 0x85, 0x03, // REPORT_ID (3)
- 0x09, 0x20, // USAGE (Stylus)
- 0xa1, 0x00, // COLLECTION (Physical)
- 0x09, 0x42, // USAGE (Tip Switch)
- 0x09, 0x32, // USAGE (In Rnage)
- 0x15, 0x00, // LOGICAL_MINIMUM (0)
- 0x25, 0x01, // LOGICAL_MAXIMUM (1)
- 0x75, 0x01, // REPORT_SIZE (1)
- 0x95, 0x02, // REPORT_COUNT (2)
- 0x81, 0x02, // INPUT (Data,Var,Abs)
- 0x75, 0x01, // REPORT_SIZE (1)
- 0x95, 0x06, // REPORT_COUNT (6)
- 0x81, 0x01, // INPUT (Cnst,Ary,Abs)
- 0x05, 0x01, // USAGE_PAGE (Generic Desktop)
- 0x09, 0x01, // USAGE (Pointer)
- 0xa1, 0x00, // COLLECTION (Physical)
- 0x09, 0x30, // USAGE (X)
- 0x09, 0x31, // USAGE (Y)
- 0x16, 0x00, 0x00, // LOGICAL_MINIMUM (0)
- 0x26, 0xff, 0x7f, // LOGICAL_MAXIMUM (32767)
- 0x36, 0x00, 0x00, // PHYSICAL_MINIMUM (0)
- 0x46, 0xff, 0x7f, // PHYSICAL_MAXIMUM (32767)
- 0x65, 0x00, // UNIT (None)
- 0x75, 0x10, // REPORT_SIZE (16)
- 0x95, 0x02, // REPORT_COUNT (2)
- 0x81, 0x02, // INPUT (Data,Var,Abs)
- 0xc0, // END_COLLECTION
- 0xc0, // END_COLLECTION
- 0xc0 // END_COLLECTION
+ // 0x05, 0x0d, // USAGE_PAGE (Digitizer)
+ // 0x09, 0x02, // USAGE (Pen)
+ // 0xa1, 0x01, // COLLECTION (Application)
+ // 0x85, 0x03, // REPORT_ID (3)
+ // 0x09, 0x20, // USAGE (Stylus)
+ // 0xa1, 0x00, // COLLECTION (Physical)
+ // 0x09, 0x42, // USAGE (Tip Switch)
+ // 0x09, 0x32, // USAGE (In Rnage)
+ // 0x15, 0x00, // LOGICAL_MINIMUM (0)
+ // 0x25, 0x01, // LOGICAL_MAXIMUM (1)
+ // 0x75, 0x01, // REPORT_SIZE (1)
+ // 0x95, 0x02, // REPORT_COUNT (2)
+ // 0x81, 0x02, // INPUT (Data,Var,Abs)
+ // 0x75, 0x01, // REPORT_SIZE (1)
+ // 0x95, 0x06, // REPORT_COUNT (6)
+ // 0x81, 0x01, // INPUT (Cnst,Ary,Abs)
+ // 0x05, 0x01, // USAGE_PAGE (Generic Desktop)
+ // 0x09, 0x01, // USAGE (Pointer)
+ // 0xa1, 0x00, // COLLECTION (Physical)
+ // 0x09, 0x30, // USAGE (X)
+ // 0x09, 0x31, // USAGE (Y)
+ // 0x16, 0x00, 0x00, // LOGICAL_MINIMUM (0)
+ // 0x26, 0xff, 0x7f, // LOGICAL_MAXIMUM (32767)
+ // 0x36, 0x00, 0x00, // PHYSICAL_MINIMUM (0)
+ // 0x46, 0xff, 0x7f, // PHYSICAL_MAXIMUM (32767)
+ // 0x65, 0x00, // UNIT (None)
+ // 0x75, 0x10, // REPORT_SIZE (16)
+ // 0x95, 0x02, // REPORT_COUNT (2)
+ // 0x81, 0x02, // INPUT (Data,Var,Abs)
+ // 0xc0, // END_COLLECTION
+ // 0xc0, // END_COLLECTION
+ // 0xc0 // END_COLLECTION
};
static uint8_t USBD_MHID_Init(void* pdev, USBD_Composite_Class_Data* cls, uint8_t cfgidx)
diff --git a/wiring/inc/spark_wiring_usbkeyboard.h b/wiring/inc/spark_wiring_usbkeyboard.h
index 028923344..0537bdd1f 100644
--- a/wiring/inc/spark_wiring_usbkeyboard.h
+++ b/wiring/inc/spark_wiring_usbkeyboard.h
@@ -34,7 +34,7 @@
typedef struct
{
- uint8_t reportId; // 0x02
+ // uint8_t reportId; // 0x02
uint8_t modifiers;
uint8_t reserved;
uint8_t keys[6];
diff --git a/wiring/src/spark_wiring_usbkeyboard.cpp b/wiring/src/spark_wiring_usbkeyboard.cpp
index ab06089fb..135059aa2 100644
--- a/wiring/src/spark_wiring_usbkeyboard.cpp
+++ b/wiring/src/spark_wiring_usbkeyboard.cpp
@@ -168,7 +168,7 @@ extern const uint8_t usb_hid_asciimap[128] =
USBKeyboard::USBKeyboard(void)
{
memset((void*)&keyReport, 0, sizeof(keyReport));
- keyReport.reportId = 0x02;
+ //keyReport.reportId = 0x02;
HAL_USB_HID_Init(0, NULL);
}
@ameennihad
Copy link

@avtolstoy, I tried to apply this patch from git but I'm getting this error on both 0.6.3 & 0.6.4:

error: patch failed: wiring/src/spark_wiring_usbkeyboard.cpp:168
error: wiring/src/spark_wiring_usbkeyboard.cpp: patch does not apply

I updated the code manually, the firmware compiled without issues, and photon appeared as HID Keyboard Device in my computer but sending key strokes doesn't do any thing! I feel that I'm doing something wrong in usbd_mhid.c! can you please send me the patched version of (usbd_mhid.c) file?

Thanks

Ameen

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment