Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/usb hid enhancements #1110

Merged
merged 3 commits into from
Sep 7, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion hal/inc/hal_dynalib_usb.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ DYNALIB_FN(BASE_IDX2 + 0, hal_usb, HAL_USB_Set_Vendor_Request_Callback, void(HAL

#ifdef USB_HID_ENABLE
DYNALIB_FN(BASE_IDX4 + 0, hal_usb, HAL_USB_HID_Status, int32_t(uint8_t, void*))
# define BASE_IDX5 (BASE_IDX4 + 1)
DYNALIB_FN(BASE_IDX4 + 1, hal_usb, HAL_USB_HID_Set_State, uint8_t(uint8_t, uint8_t, void*))
# define BASE_IDX5 (BASE_IDX4 + 2)
#else
# define BASE_IDX5 BASE_IDX4
#endif
Expand Down
1 change: 1 addition & 0 deletions hal/inc/usb_hal.h
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ void HAL_USB_HID_Begin(uint8_t reserved, void* reserved1);
void HAL_USB_HID_Send_Report(uint8_t reserved, void *pHIDReport, uint16_t reportSize, void* reserved1);
int32_t HAL_USB_HID_Status(uint8_t reserved, void* reserved1);
void HAL_USB_HID_End(uint8_t reserved);
uint8_t HAL_USB_HID_Set_State(uint8_t id, uint8_t state, void* reserved);
#endif


Expand Down
12 changes: 12 additions & 0 deletions hal/src/stm32f2xx/usb_hal.c
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,18 @@ void HAL_USB_HID_End(uint8_t reserved)
}
}

uint8_t HAL_USB_HID_Set_State(uint8_t id, uint8_t state, void* reserved)
{
uint8_t ret = 0;
if (usbHid.registered) {
HAL_USB_Detach();
ret = USBD_MHID_SetDigitizerState(&USB_OTG_dev, NULL, id, state);
HAL_USB_Attach();
}

return ret;
}

/*******************************************************************************
* Function Name : USB_HID_Send_Report.
* Description : Send HID Report Info to Host.
Expand Down
5 changes: 4 additions & 1 deletion platform/MCU/STM32F2xx/SPARK_Firmware_Driver/inc/usbd_mhid.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@

#define USBD_MHID_CONFIG_DESC_SIZE 32
#define USBD_MHID_DESC_SIZE 9
#define USBD_MHID_REPORT_DESC_SIZE 99
#define USBD_MHID_REPORT_DESC_SIZE 178

#define USBD_MHID_DIGITIZER_REPORT_DESC_SIZE 65

#define HID_DESCRIPTOR_TYPE 0x21
#define HID_REPORT_DESC 0x22
Expand Down Expand Up @@ -44,5 +46,6 @@ typedef struct USBD_MHID_Instance_Data {

uint8_t USBD_MHID_SendReport (USB_OTG_CORE_HANDLE* pdev, USBD_MHID_Instance_Data* priv, uint8_t* report, uint16_t len);
int32_t USBD_MHID_Transfer_Status(void* pdev, USBD_Composite_Class_Data* cls);
uint8_t USBD_MHID_SetDigitizerState(void* pdev, USBD_Composite_Class_Data* cls, uint8_t idx, uint8_t state);

#endif /* USBD_MHID_H_ */
62 changes: 58 additions & 4 deletions platform/MCU/STM32F2xx/SPARK_Firmware_Driver/src/usbd_mhid.c
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,9 @@ __ALIGN_BEGIN static const uint8_t USBD_MHID_DefaultReportDesc[USBD_MHID_REPORT_
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)
0x85, 0x01, // REPORT_ID (1)
0x05, 0x09, // USAGE_PAGE (Button)
0x19, 0x01, // USAGE_MINIMUM (Button 1)
0x29, 0x03, // USAGE_MAXIMUM (Button 3)
Expand All @@ -117,14 +117,24 @@ __ALIGN_BEGIN static const uint8_t USBD_MHID_DefaultReportDesc[USBD_MHID_REPORT_
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)
// 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, 0x03, // REPORT_COUNT (3)
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)
Expand Down Expand Up @@ -152,11 +162,43 @@ __ALIGN_BEGIN static const uint8_t USBD_MHID_DefaultReportDesc[USBD_MHID_REPORT_
0x95, 0x06, // REPORT_COUNT (6)
0x75, 0x08, // REPORT_SIZE (8)
0x15, 0x00, // LOGICAL_MINIMUM (0)
0x25, 0x65, // LOGICAL_MAXIMUM (101)
0x25, 0xdd, // LOGICAL_MAXIMUM (221)
0x05, 0x07, // USAGE_PAGE (Keyboard)
0x19, 0x00, // USAGE_MINIMUM (Reserved (no event indicated))
0x29, 0x65, // USAGE_MAXIMUM (Keyboard Application)
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
};

Expand Down Expand Up @@ -333,3 +375,15 @@ int32_t USBD_MHID_Transfer_Status(void* pdev, USBD_Composite_Class_Data* cls)
USBD_MHID_Instance_Data* priv = &USBD_MHID_Instance; /* (USBD_MHID_Instance_Data*)cls->priv; */
return priv->intransfer && (((USB_OTG_CORE_HANDLE*)pdev)->dev.device_status == USB_OTG_CONFIGURED && priv->configured);
}

uint8_t USBD_MHID_SetDigitizerState(void* pdev, USBD_Composite_Class_Data* cls, uint8_t idx, uint8_t state)
{
USBD_MHID_Instance_Data* priv = &USBD_MHID_Instance; /* (USBD_MHID_Instance_Data*)cls->priv; */
if (state) {
priv->report_descriptor_size = USBD_MHID_REPORT_DESC_SIZE;
} else {
priv->report_descriptor_size = USBD_MHID_REPORT_DESC_SIZE - USBD_MHID_DIGITIZER_REPORT_DESC_SIZE;
}

return 1;
}
6 changes: 6 additions & 0 deletions user/tests/wiring/usbhid2/application.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#include "application.h"
#include "unit-test/unit-test.h"

UNIT_TEST_APP();

SYSTEM_MODE(SEMI_AUTOMATIC);
Loading