2019-07-08 12:48 AM
Hello All,
I have successfully Combined Mouse and Keyboard as a USB device by modifying the USB HID Mouse example and my PC can recognize them. However, I can easily detect the mouse movement and can't detect the Keyboard. By using Bus Hound I could see there is something related to the Keyboard when I press the Button I used for the Keyboard on my board (Which I assign for it Letter 'A').
I made the following modifications:
file: usbd_hid.h
#define USB_ENDPOINT_DESCRIPTOR_TYPE 0x09//0x05
#define HID_EPIN_SIZE 0x08U//0x04U
#define HID_MOUSE_REPORT_DESC_SIZE 101//(47+54)
file: usbd_hid.c
/* USB HID device FS Configuration Descriptor */
__ALIGN_BEGIN static uint8_t USBD_HID_CfgFSDesc[USB_HID_CONFIG_DESC_SIZ] __ALIGN_END =
{
.
.
.
.
0x00,/*0x01*/ /*bInterfaceSubClass : 1=BOOT, 0=no boot*/
0x00,/*0x02*/ /*nInterfaceProtocol : 0=none, 1=keyboard, 2=mouse*/
.
.
.
.
}
MOUSE and Keyboard Report Descriptor
__ALIGN_BEGIN static uint8_t HID_MOUSE_ReportDesc[HID_MOUSE_REPORT_DESC_SIZE] __ALIGN_END =
{
/* 47 */
0x05, 0x01, // USAGE_PAGE (Generic Desktop)
0x09, 0x06, // USAGE (Keyboard)
0xa1, 0x01, // COLLECTION (Application)
0x85, 0x01, // REPORT_ID (1)
0x05, 0x07, // USAGE_PAGE (Keyboard)
0x19, 0xe0, // USAGE_MINIMUM (Keyboard LeftControl)
0x29, 0xe7, // USAGE_MAXIMUM (Keyboard Right GUI)
0x15, 0x00, // LOGICAL_MINIMUM (0)
0x25, 0x01, // LOGICAL_MAXIMUM (1)
0x75, 0x01, // REPORT_SIZE (1)
0x95, 0x08, // REPORT_COUNT (8)
0x81, 0x02, // INPUT (Data,Var,Abs)
0x95, 0x01, // REPORT_COUNT (1)
0x75, 0x08, // REPORT_SIZE (8)
0x81, 0x03, // INPUT (Cnst,Var,Abs)
0x95, 0x06, // REPORT_COUNT (6)
0x75, 0x08, // REPORT_SIZE (8)
0x15, 0x00, // LOGICAL_MINIMUM (0)
0x25, 0x65, // LOGICAL_MAXIMUM (101)
0x05, 0x07, // USAGE_PAGE (Keyboard)
0x19, 0x00, // USAGE_MINIMUM (Reserved (no event indicated))
0x29, 0x65, // USAGE_MAXIMUM (Keyboard Application)
0x81, 0x00, // INPUT (Data,Ary,Abs)
0xc0, // END_COLLECTION
/* 54 */
0x05, 0x01, // USAGE_PAGE (Generic Desktop)
0x09, 0x02, // USAGE (Mouse)
0xa1, 0x01, // COLLECTION (Application)
0x09, 0x01, // USAGE (Pointer)
0xa1, 0x00, // COLLECTION (Physical)
0x85, 0x02, // REPORT_ID (2)
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)
0x09, 0x38, // USAGE (Wheel)
0x15, 0x81, // LOGICAL_MINIMUM (-127)
0x25, 0x7f, // LOGICAL_MAXIMUM (127)
0x75, 0x08, // REPORT_SIZE (8)
0x95, 0x03, // REPORT_COUNT (3)
0x81, 0x06, // INPUT (Data,Var,Rel)
0xc0, // END_COLLECTION
0xc0, // END_COLLECTION
};
Please, I need your assistance to finish this part.
2019-07-08 04:04 AM
I've made a similar thing with multiple collections on STM32F072. Maybe the problem is in code that you have not shown.
Check translation of the letter A to HID code. After sending it, send another "empty" report to indicate release of the key.
-- pa
2019-07-08 04:30 PM
Dear @Pavel A. ,
I really appreciate your response and I uploaded my code on Github for your check.
Could you please have a look and guide me to fix it?
https://github.com/hossamfadeel/STEM32_CustomHID_USB_4
The design has two main parts:
1- Joystick acts as a mouse.
2- Push Button to send Page Down control of Keyboard.
Waiting for your reply ....
Thanks again,
Hossam
2019-07-13 02:34 PM
Hi @HHass
For the keyboard release report:
you need to wait until the USB TX becomes ready. And it becomes ready only when the host sends IN token.
This takes time. I think this is the reason why keyboard reports don't work.
Waiting in the EXTI interrupt handler is possible if USB interrupt priority is higher and it can preempt the EXTI ISR.
But it is better to avoid waiting in ISRs and make a more complex design with a "background process".
Sorry I don't have a ready code to share but the idea is to call USBD_HID_SendReport only when the TX is ready.
Regards,
-- pa