From 53a0d9feec356222a9a93f8a7a9766a24fc7016a Mon Sep 17 00:00:00 2001 From: WiseLord Date: Tue, 14 May 2019 13:40:11 +0300 Subject: [PATCH] Improve HID descriptors to work on Windows --- actions.c | 20 +++---- files/utils/emuldisp/emuldisp_stub.c | 5 ++ usb/amp.hid | Bin 0 -> 434 bytes usb/hidkeys.h | 38 ++++-------- usb/usbd_conf.h | 2 +- usb/usbd_desc.c | 8 +-- usb/usbhid.c | 86 +++++++++++++++++---------- usb/usbhid.h | 6 ++ 8 files changed, 94 insertions(+), 71 deletions(-) create mode 100644 usb/amp.hid diff --git a/actions.c b/actions.c index 58c188a6..3af19ac6 100644 --- a/actions.c +++ b/actions.c @@ -137,10 +137,10 @@ static void actionNavigateCommon(RcCmd cmd) actionSet(ACTION_DISP_EXPIRED, 0); break; case RC_CMD_NAV_RIGHT: - actionSet(ACTION_MEDIA, HIDKEY_MEDIA_FORWARD); + actionSet(ACTION_MEDIA, HIDMEDIAKEY_FFD); break; case RC_CMD_NAV_LEFT: - actionSet(ACTION_MEDIA, HIDKEY_MEDIA_BACK); + actionSet(ACTION_MEDIA, HIDMEDIAKEY_REWIND); break; case RC_CMD_NAV_UP: case RC_CMD_CHAN_NEXT: @@ -494,19 +494,19 @@ static void actionRemapRemote(void) break; case RC_CMD_STOP: - actionSet(ACTION_MEDIA, HIDKEY_MEDIA_STOPCD); + actionSet(ACTION_MEDIA, HIDMEDIAKEY_STOP); break; case RC_CMD_PLAY: - actionSet(ACTION_MEDIA, HIDKEY_MEDIA_PLAYPAUSE); + actionSet(ACTION_MEDIA, HIDMEDIAKEY_PLAY); break; case RC_CMD_PAUSE: - actionSet(ACTION_MEDIA, HIDKEY_PAUSE); + actionSet(ACTION_MEDIA, HIDMEDIAKEY_PAUSE); break; case RC_CMD_REW: - actionSet(ACTION_MEDIA, HIDKEY_MEDIA_BACK); + actionSet(ACTION_MEDIA, HIDMEDIAKEY_REWIND); break; case RC_CMD_FWD: - actionSet(ACTION_MEDIA, HIDKEY_MEDIA_FORWARD); + actionSet(ACTION_MEDIA, HIDMEDIAKEY_FFD); break; case RC_CMD_TIMER: actionSet(ACTION_TIMER, 0); @@ -794,7 +794,7 @@ void actionHandle(bool visible) case ACTION_MEDIA: switch (inType) { case IN_PC: - usbHidSendKey((HidKey)action.value); + usbHidSendMediaKey((HidKey)action.value); break; } break; @@ -810,9 +810,9 @@ void actionHandle(bool visible) break; case IN_PC: if (action.value > 0) { - usbHidSendKey(HIDKEY_MEDIA_NEXTSONG); + usbHidSendMediaKey(HIDMEDIAKEY_NEXT_TRACK); } else if (action.value < 0) { - usbHidSendKey(HIDKEY_MEDIA_PREVIOUSSONG); + usbHidSendMediaKey(HIDMEDIAKEY_PREV_TRACK); } break; } diff --git a/files/utils/emuldisp/emuldisp_stub.c b/files/utils/emuldisp/emuldisp_stub.c index 85a6c6d7..4a812c70 100644 --- a/files/utils/emuldisp/emuldisp_stub.c +++ b/files/utils/emuldisp/emuldisp_stub.c @@ -174,3 +174,8 @@ void usbHidSendKey(HidKey key) { (void)key; } + +void usbHidSendMediaKey(HidMediaKey key) +{ + (void)key; +} diff --git a/usb/amp.hid b/usb/amp.hid new file mode 100644 index 0000000000000000000000000000000000000000..d5955b96823a4cae9f6c6a602844ce7fc2dbe76a GIT binary patch literal 434 zcmY#lU}X4rN`rxm0T*CpgvoHS0TqM6LbzBfh{XgFWMzl3O5tKtIbdRv4;a`X>NKCj zSfU_pV7;nv9gQG9x_NL@rov?<8DOSp*27px=GDVYX@uKx0K@{>!@$Y|B0+$Ykpap^ z@)6t)usX0?N)axAyHpg;QiaQMZUdSJ*1@?I&e{%VZGf{j!dYA3tj%!NBNz*t>j7Ox B73Tl| literal 0 HcmV?d00001 diff --git a/usb/hidkeys.h b/usb/hidkeys.h index dc8699c5..8f5bc459 100644 --- a/usb/hidkeys.h +++ b/usb/hidkeys.h @@ -9,7 +9,6 @@ extern "C" { typedef uint8_t HidKey; enum { - // key codes HIDKEY_A = 4, HIDKEY_B = 5, HIDKEY_C = 6, @@ -139,31 +138,6 @@ enum { HIDKEY_FIND = 0x7e, HIDKEY_MUTE = 0x7f, - HIDKEY_VOLUME_UP = 0x80, - HIDKEY_VOLUME_DOWN = 0x81, - - - HIDKEY_MEDIA_PLAYPAUSE = 0xe8, - HIDKEY_MEDIA_STOPCD = 0xe9, - HIDKEY_MEDIA_PREVIOUSSONG = 0xea, - HIDKEY_MEDIA_NEXTSONG = 0xeb, - HIDKEY_MEDIA_EJECTCD = 0xec, - HIDKEY_MEDIA_VOLUMEUP = 0xed, - HIDKEY_MEDIA_VOLUMEDOWN = 0xee, - HIDKEY_MEDIA_MUTE = 0xef, - HIDKEY_MEDIA_WWW = 0xf0, - HIDKEY_MEDIA_BACK = 0xf1, - HIDKEY_MEDIA_FORWARD = 0xf2, - HIDKEY_MEDIA_STOP = 0xf3, - HIDKEY_MEDIA_FIND = 0xf4, - HIDKEY_MEDIA_SCROLLUP = 0xf5, - HIDKEY_MEDIA_SCROLLDOWN = 0xf6, - HIDKEY_MEDIA_EDIT = 0xf7, - HIDKEY_MEDIA_SLEEP = 0xf8, - HIDKEY_MEDIA_COFFEE = 0xf9, - HIDKEY_MEDIA_REFRESH = 0xfa, - HIDKEY_MEDIA_CALC = 0xfb, - // Modifiers bit sets HIDKEY_MODIFIER_NONE = 0x00, HIDKEY_MODIFIER_LEFT_CTRL = 0x01, @@ -176,6 +150,18 @@ enum { HIDKEY_MODIFIER_RIGHT_UI = 0x80, }; +typedef uint8_t HidMediaKey; +enum { + HIDMEDIAKEY_NONE = 0, + HIDMEDIAKEY_PREV_TRACK , + HIDMEDIAKEY_NEXT_TRACK, + HIDMEDIAKEY_STOP, + HIDMEDIAKEY_PLAY, + HIDMEDIAKEY_PAUSE, + HIDMEDIAKEY_REWIND, + HIDMEDIAKEY_FFD, +}; + #ifdef __cplusplus } #endif diff --git a/usb/usbd_conf.h b/usb/usbd_conf.h index 87b2b3e9..50911069 100644 --- a/usb/usbd_conf.h +++ b/usb/usbd_conf.h @@ -17,7 +17,7 @@ extern "C" { #define USBD_SUPPORT_USER_STRING 0 #define USBD_SELF_POWERED 1 #define USBD_CUSTOMHID_OUTREPORT_BUF_SIZE 2 -#define USBD_AMP_REPORT_DESC_SIZE 41 +#define USBD_AMP_REPORT_DESC_SIZE 78 #define DEVICE_FS 0 diff --git a/usb/usbd_desc.c b/usb/usbd_desc.c index 5458d6cd..929ab5d8 100644 --- a/usb/usbd_desc.c +++ b/usb/usbd_desc.c @@ -6,10 +6,10 @@ #define USBD_LANGID_STRING 0x0409 #define USBD_MANUFACTURER_STRING "WiseLord" #define USBD_PID_FS 0x5750 -#define USBD_PRODUCT_STRING_FS "Ampcontrol HID" -#define USBD_SERIALNUMBER_STRING_FS "00000000001A" -#define USBD_CONFIGURATION_STRING_FS "Amp HID Config" -#define USBD_INTERFACE_STRING_FS "Amp HID Interface" +#define USBD_PRODUCT_STRING_FS "Ampcontrol" +#define USBD_SERIALNUMBER_STRING_FS "000032F103CB" +#define USBD_CONFIGURATION_STRING_FS "Amp Config" +#define USBD_INTERFACE_STRING_FS "Amp Interface" // Internal string descriptor buffer static uint8_t USBD_StrDescBuf[USBD_MAX_STR_DESC_SIZ] __ALIGN_END; diff --git a/usb/usbhid.c b/usb/usbhid.c index 45f3d107..cce9d070 100644 --- a/usb/usbhid.c +++ b/usb/usbhid.c @@ -4,9 +4,10 @@ #include "usbd_amp.h" #include +#include -#define REPORT_ID_KEYBOARD 0x01 -#define REPORT_ID_MOUSE 0x02 +#define REPORT_ID_KEYBOARD 0x01 +#define REPORT_ID_MEDIAKEYS 0x02 static int8_t usbHidInitFS(void); static int8_t usbHidDeInitFS(void); @@ -15,33 +16,51 @@ static int8_t usbHidOutEventFS(uint8_t event_idx, uint8_t state); static USBD_HandleTypeDef hUsbDeviceFS; static HidKeyboard keyboardHID; +static HidMediaKeys mediakeysHID; static uint8_t usbHidReportDescFS[USBD_AMP_REPORT_DESC_SIZE] __ALIGN_END = { - // 41 bytes - 0x05, 0x01, // Usage Page (Generic Desktop Ctrls) - 0x09, 0x06, // Usage (Keyboard) - 0xA1, 0x01, // Collection (Application) - 0x85, REPORT_ID_KEYBOARD, // Report ID (1) - 0x05, 0x07, // Usage Page (Kbrd/Keypad) - 0x75, 0x01, // Report Size (1) - 0x95, 0x08, // Report Count (8) - 0x19, 0xE0, // Usage Minimum (0xE0) - 0x29, 0xE7, // Usage Maximum (0xE7) - 0x15, 0x00, // Logical Minimum (0) - 0x25, 0x01, // Logical Maximum (1) - 0x81, 0x02, // Input (Data,Var,Abs,No Wrap,Linear,Preferred State,No Null Position) - 0x95, KBD_KEYS, // Report Count (KBD_KEYS) - 0x75, 0x08, // Report Size (8) - 0x15, 0x00, // Logical Minimum (0) - 0x25, 0xff, // Logical Maximum (255) - 0x05, 0x07, // Usage Page (Kbrd/Keypad) - 0x19, 0x00, // Usage Minimum (0) - 0x29, 0xff, // Usage Maximum (255) - 0x81, 0x00, // Input (Data,Array,Abs,No Wrap,Linear,Preferred State,No Null Position) - 0xC0, // End Collection + 0x05, 0x01, // USAGE_PAGE (Generic Desktop) + 0x09, 0x06, // USAGE (Keyboard) + 0xa1, 0x01, // COLLECTION (Application) + 0x85, 0x01, // REPORT_ID (1) + 0x05, 0x07, // USAGE_PAGE (Keyboard) + 0x75, 0x01, // REPORT_SIZE (1) + 0x95, 0x08, // REPORT_COUNT (8) + 0x19, 0xe0, // USAGE_MINIMUM (Keyboard LeftControl) + 0x29, 0xe7, // USAGE_MAXIMUM (Keyboard Right GUI) + 0x15, 0x00, // LOGICAL_MINIMUM (0) + 0x25, 0x01, // LOGICAL_MAXIMUM (1) + 0x81, 0x02, // INPUT (Data,Var,Abs) + 0x05, 0x07, // USAGE_PAGE (Keyboard) + 0x75, 0x08, // REPORT_SIZE (8) + 0x95, 0x02, // REPORT_COUNT (2) + 0x19, 0x00, // USAGE_MINIMUM (Reserved (no event indicated)) + 0x29, 0x7f, // USAGE_MAXIMUM (Keyboard Mute) + 0x15, 0x00, // LOGICAL_MINIMUM (0) + 0x25, 0x7f, // LOGICAL_MAXIMUM (127) + 0x81, 0x00, // INPUT (Data,Ary,Abs) + 0xc0, // END_COLLECTION + 0x05, 0x0c, // USAGE_PAGE (Consumer Devices) + 0x09, 0x01, // USAGE (Consumer Control) + 0xa1, 0x01, // COLLECTION (Application) + 0x85, 0x02, // REPORT_ID (2) + 0x05, 0x0c, // USAGE_PAGE (Consumer Devices) + 0x75, 0x08, // REPORT_SIZE (8) + 0x95, 0x01, // REPORT_COUNT (1) + 0x15, 0x01, // LOGICAL_MINIMUM (1) + 0x25, 0x08, // LOGICAL_MAXIMUM (8) + 0x09, 0xb6, // USAGE (Scan Previous Track) + 0x09, 0xb5, // USAGE (Scan Next Track) + 0x09, 0xb7, // USAGE (Stop) + 0x09, 0xb0, // USAGE (Play) + 0x09, 0xb1, // USAGE (Pause) + 0x09, 0xb4, // USAGE (Rewind) + 0x09, 0xb3, // USAGE (Fast Forward) + 0x09, 0xe2, // USAGE (Mute) + 0x81, 0x00, // INPUT (Data,Ary,Abs) + 0xc0 // END_COLLECTION }; - static USBD_AMP_ItfTypeDef USBD_AmpHidFopsFS = { usbHidReportDescFS, usbHidInitFS, @@ -80,12 +99,11 @@ static void usbHidSend(void *data, uint16_t size) void usbHidInit(void) { - keyboardHID.id = REPORT_ID_KEYBOARD; - keyboardHID.modifiers = 0; + memset(&keyboardHID, 0, sizeof (keyboardHID)); + memset(&mediakeysHID, 0, sizeof (mediakeysHID)); - for (uint8_t i = 0; i < KBD_KEYS; i++) { - keyboardHID.key[i] = 0; - } + keyboardHID.id = REPORT_ID_KEYBOARD; + mediakeysHID.id = REPORT_ID_MEDIAKEYS; USBD_Init(&hUsbDeviceFS, &FS_Desc, DEVICE_FS); USBD_RegisterClass(&hUsbDeviceFS, &USBD_AMP); @@ -103,3 +121,11 @@ void usbHidSendKey(HidKey key) keyboardHID.key[0] = 0; usbHidSend(&keyboardHID, sizeof(keyboardHID)); } + +void usbHidSendMediaKey(HidMediaKey key) +{ + mediakeysHID.key = key; + usbHidSend(&mediakeysHID, sizeof(mediakeysHID)); + mediakeysHID.key = HIDMEDIAKEY_NONE; + usbHidSend(&mediakeysHID, sizeof(mediakeysHID)); +} diff --git a/usb/usbhid.h b/usb/usbhid.h index 852b02bd..689658a8 100644 --- a/usb/usbhid.h +++ b/usb/usbhid.h @@ -16,9 +16,15 @@ typedef struct { uint8_t key[KBD_KEYS]; } HidKeyboard; +typedef struct { + uint8_t id; + uint8_t key; +} HidMediaKeys; + void usbHidInit(void); void usbHidSendKey(HidKey key); +void usbHidSendMediaKey(HidMediaKey key); #ifdef __cplusplus }