|
|
@ -47,6 +47,7 @@ |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
|
|
/* Includes ------------------------------------------------------------------*/ |
|
|
|
/* Includes ------------------------------------------------------------------*/ |
|
|
|
|
|
|
|
#include <main.h> |
|
|
|
#include "usbd_hid.h" |
|
|
|
#include "usbd_hid.h" |
|
|
|
#include "usbd_desc.h" |
|
|
|
#include "usbd_desc.h" |
|
|
|
#include "usbd_ctlreq.h" |
|
|
|
#include "usbd_ctlreq.h" |
|
|
@ -163,7 +164,7 @@ __ALIGN_BEGIN static uint8_t USBD_HID_CfgDesc[USB_HID_CONFIG_DESC_SIZ] __ALIGN_ |
|
|
|
0x01, /*bNumEndpoints*/ |
|
|
|
0x01, /*bNumEndpoints*/ |
|
|
|
0x03, /*bInterfaceClass: HID*/ |
|
|
|
0x03, /*bInterfaceClass: HID*/ |
|
|
|
0x01, /*bInterfaceSubClass : 1=BOOT, 0=no boot*/ |
|
|
|
0x01, /*bInterfaceSubClass : 1=BOOT, 0=no boot*/ |
|
|
|
0x02, /*nInterfaceProtocol : 0=none, 1=keyboard, 2=mouse*/ |
|
|
|
0x01, /*nInterfaceProtocol : 0=none, 1=keyboard, 2=mouse*//* CHANGED */ |
|
|
|
0, /*iInterface: Index of string descriptor*/ |
|
|
|
0, /*iInterface: Index of string descriptor*/ |
|
|
|
/******************** Descriptor of Joystick Mouse HID ********************/ |
|
|
|
/******************** Descriptor of Joystick Mouse HID ********************/ |
|
|
|
/* 18 */ |
|
|
|
/* 18 */ |
|
|
@ -174,7 +175,7 @@ __ALIGN_BEGIN static uint8_t USBD_HID_CfgDesc[USB_HID_CONFIG_DESC_SIZ] __ALIGN_ |
|
|
|
0x00, /*bCountryCode: Hardware target country*/ |
|
|
|
0x00, /*bCountryCode: Hardware target country*/ |
|
|
|
0x01, /*bNumDescriptors: Number of HID class descriptors to follow*/ |
|
|
|
0x01, /*bNumDescriptors: Number of HID class descriptors to follow*/ |
|
|
|
0x22, /*bDescriptorType*/ |
|
|
|
0x22, /*bDescriptorType*/ |
|
|
|
HID_MOUSE_REPORT_DESC_SIZE,/*wItemLength: Total length of Report descriptor*/ |
|
|
|
HID_KEYBD_REPORT_DESC_SIZE,/*wItemLength: Total length of Report descriptor*//* CHANGED */ |
|
|
|
0x00, |
|
|
|
0x00, |
|
|
|
/******************** Descriptor of Mouse endpoint ********************/ |
|
|
|
/******************** Descriptor of Mouse endpoint ********************/ |
|
|
|
/* 27 */ |
|
|
|
/* 27 */ |
|
|
@ -200,7 +201,7 @@ __ALIGN_BEGIN static uint8_t USBD_HID_Desc[USB_HID_DESC_SIZ] __ALIGN_END = |
|
|
|
0x00, /*bCountryCode: Hardware target country*/ |
|
|
|
0x00, /*bCountryCode: Hardware target country*/ |
|
|
|
0x01, /*bNumDescriptors: Number of HID class descriptors to follow*/ |
|
|
|
0x01, /*bNumDescriptors: Number of HID class descriptors to follow*/ |
|
|
|
0x22, /*bDescriptorType*/ |
|
|
|
0x22, /*bDescriptorType*/ |
|
|
|
HID_MOUSE_REPORT_DESC_SIZE,/*wItemLength: Total length of Report descriptor*/ |
|
|
|
HID_KEYBD_REPORT_DESC_SIZE,/*wItemLength: Total length of Report descriptor*//* CHANGED */ |
|
|
|
0x00, |
|
|
|
0x00, |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
@ -219,54 +220,40 @@ __ALIGN_BEGIN static uint8_t USBD_HID_DeviceQualifierDesc[USB_LEN_DEV_QUALIFIER_ |
|
|
|
0x00, |
|
|
|
0x00, |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
__ALIGN_BEGIN static uint8_t HID_MOUSE_ReportDesc[HID_MOUSE_REPORT_DESC_SIZE] __ALIGN_END = |
|
|
|
__ALIGN_BEGIN static uint8_t HID_KEYBD_ReportDesc[HID_KEYBD_REPORT_DESC_SIZE] __ALIGN_END = |
|
|
|
{ |
|
|
|
{ |
|
|
|
0x05, 0x01, |
|
|
|
0x05, 0x01, // USAGE_PAGE (Generic Desktop)
|
|
|
|
0x09, 0x02, |
|
|
|
0x09, 0x06, // USAGE (Keyboard)
|
|
|
|
0xA1, 0x01, |
|
|
|
0xa1, 0x01, // COLLECTION (Application)
|
|
|
|
0x09, 0x01, |
|
|
|
0x05, 0x07, // USAGE_PAGE (Keyboard)
|
|
|
|
|
|
|
|
0x19, 0xe0, // USAGE_MINIMUM (Keyboard LeftControl)
|
|
|
|
0xA1, 0x00, |
|
|
|
0x29, 0xe7, // USAGE_MAXIMUM (Keyboard Right GUI)
|
|
|
|
0x05, 0x09, |
|
|
|
0x15, 0x00, // LOGICAL_MINIMUM (0)
|
|
|
|
0x19, 0x01, |
|
|
|
0x25, 0x01, // LOGICAL_MAXIMUM (1)
|
|
|
|
0x29, 0x03, |
|
|
|
0x75, 0x01, // REPORT_SIZE (1)
|
|
|
|
|
|
|
|
0x95, 0x08, // REPORT_COUNT (8)
|
|
|
|
0x15, 0x00, |
|
|
|
0x81, 0x02, // INPUT (Data,Var,Abs)
|
|
|
|
0x25, 0x01, |
|
|
|
0x95, 0x01, // REPORT_COUNT (1)
|
|
|
|
0x95, 0x03, |
|
|
|
0x75, 0x08, // REPORT_SIZE (8)
|
|
|
|
0x75, 0x01, |
|
|
|
0x81, 0x03, // INPUT (Cnst,Var,Abs)
|
|
|
|
|
|
|
|
0x95, 0x05, // REPORT_COUNT (5)
|
|
|
|
0x81, 0x02, |
|
|
|
0x75, 0x01, // REPORT_SIZE (1)
|
|
|
|
0x95, 0x01, |
|
|
|
0x05, 0x08, // USAGE_PAGE (LEDs)
|
|
|
|
0x75, 0x05, |
|
|
|
0x19, 0x01, // USAGE_MINIMUM (Num Lock)
|
|
|
|
0x81, 0x01, |
|
|
|
0x29, 0x05, // USAGE_MAXIMUM (Kana)
|
|
|
|
|
|
|
|
0x91, 0x02, // OUTPUT (Data,Var,Abs)
|
|
|
|
0x05, 0x01, |
|
|
|
0x95, 0x01, // REPORT_COUNT (1)
|
|
|
|
0x09, 0x30, |
|
|
|
0x75, 0x03, // REPORT_SIZE (3)
|
|
|
|
0x09, 0x31, |
|
|
|
0x91, 0x03, // OUTPUT (Cnst,Var,Abs)
|
|
|
|
0x09, 0x38, |
|
|
|
0x95, 0x06, // REPORT_COUNT (6)
|
|
|
|
|
|
|
|
0x75, 0x08, // REPORT_SIZE (8)
|
|
|
|
0x15, 0x81, |
|
|
|
0x15, 0x00, // LOGICAL_MINIMUM (0)
|
|
|
|
0x25, 0x7F, |
|
|
|
0x25, 0x65, // LOGICAL_MAXIMUM (101)
|
|
|
|
0x75, 0x08, |
|
|
|
0x05, 0x07, // USAGE_PAGE (Keyboard)
|
|
|
|
0x95, 0x03, |
|
|
|
0x19, 0x00, // USAGE_MINIMUM (Reserved (no event indicated))
|
|
|
|
|
|
|
|
0x29, 0x65, // USAGE_MAXIMUM (Keyboard Application)
|
|
|
|
0x81, 0x06, |
|
|
|
0x81, 0x00, // INPUT (Data,Ary,Abs)
|
|
|
|
0xC0, 0x09, |
|
|
|
0xc0 // END_COLLECTION
|
|
|
|
0x3c, 0x05, |
|
|
|
|
|
|
|
0xff, 0x09, |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
0x01, 0x15, |
|
|
|
|
|
|
|
0x00, 0x25, |
|
|
|
|
|
|
|
0x01, 0x75, |
|
|
|
|
|
|
|
0x01, 0x95, |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
0x02, 0xb1, |
|
|
|
|
|
|
|
0x22, 0x75, |
|
|
|
|
|
|
|
0x06, 0x95, |
|
|
|
|
|
|
|
0x01, 0xb1, |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
0x01, 0xc0 |
|
|
|
|
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
@ -315,8 +302,7 @@ static uint8_t USBD_HID_Init(USBD_HandleTypeDef *pdev, uint8_t cfgidx) |
|
|
|
static uint8_t USBD_HID_DeInit(USBD_HandleTypeDef *pdev, uint8_t cfgidx) |
|
|
|
static uint8_t USBD_HID_DeInit(USBD_HandleTypeDef *pdev, uint8_t cfgidx) |
|
|
|
{ |
|
|
|
{ |
|
|
|
/* Close HID EPs */ |
|
|
|
/* Close HID EPs */ |
|
|
|
USBD_LL_CloseEP(pdev, |
|
|
|
USBD_LL_CloseEP(pdev, HID_EPIN_ADDR); |
|
|
|
HID_EPIN_ADDR); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* FRee allocated memory */ |
|
|
|
/* FRee allocated memory */ |
|
|
|
if (pdev->pClassData != NULL) { |
|
|
|
if (pdev->pClassData != NULL) { |
|
|
@ -350,9 +336,7 @@ static uint8_t USBD_HID_Setup(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *re |
|
|
|
break; |
|
|
|
break; |
|
|
|
|
|
|
|
|
|
|
|
case HID_REQ_GET_PROTOCOL: |
|
|
|
case HID_REQ_GET_PROTOCOL: |
|
|
|
USBD_CtlSendData(pdev, |
|
|
|
USBD_CtlSendData(pdev, (uint8_t *) &hhid->Protocol, 1); |
|
|
|
(uint8_t *) &hhid->Protocol, |
|
|
|
|
|
|
|
1); |
|
|
|
|
|
|
|
break; |
|
|
|
break; |
|
|
|
|
|
|
|
|
|
|
|
case HID_REQ_SET_IDLE: |
|
|
|
case HID_REQ_SET_IDLE: |
|
|
@ -360,9 +344,7 @@ static uint8_t USBD_HID_Setup(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *re |
|
|
|
break; |
|
|
|
break; |
|
|
|
|
|
|
|
|
|
|
|
case HID_REQ_GET_IDLE: |
|
|
|
case HID_REQ_GET_IDLE: |
|
|
|
USBD_CtlSendData(pdev, |
|
|
|
USBD_CtlSendData(pdev, (uint8_t *) &hhid->IdleState, 1); |
|
|
|
(uint8_t *) &hhid->IdleState, |
|
|
|
|
|
|
|
1); |
|
|
|
|
|
|
|
break; |
|
|
|
break; |
|
|
|
|
|
|
|
|
|
|
|
default: |
|
|
|
default: |
|
|
@ -375,8 +357,8 @@ static uint8_t USBD_HID_Setup(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *re |
|
|
|
switch (req->bRequest) { |
|
|
|
switch (req->bRequest) { |
|
|
|
case USB_REQ_GET_DESCRIPTOR: |
|
|
|
case USB_REQ_GET_DESCRIPTOR: |
|
|
|
if (req->wValue >> 8 == HID_REPORT_DESC) { |
|
|
|
if (req->wValue >> 8 == HID_REPORT_DESC) { |
|
|
|
len = MIN(HID_MOUSE_REPORT_DESC_SIZE, req->wLength); |
|
|
|
len = MIN(HID_KEYBD_REPORT_DESC_SIZE, req->wLength); |
|
|
|
pbuf = HID_MOUSE_ReportDesc; |
|
|
|
pbuf = HID_KEYBD_ReportDesc; |
|
|
|
} |
|
|
|
} |
|
|
|
else if (req->wValue >> 8 == HID_DESCRIPTOR_TYPE) { |
|
|
|
else if (req->wValue >> 8 == HID_DESCRIPTOR_TYPE) { |
|
|
|
pbuf = USBD_HID_Desc; |
|
|
|
pbuf = USBD_HID_Desc; |
|
|
@ -476,7 +458,6 @@ static uint8_t *USBD_HID_GetCfgDesc(uint16_t *length) |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
static uint8_t USBD_HID_DataIn(USBD_HandleTypeDef *pdev, uint8_t epnum) |
|
|
|
static uint8_t USBD_HID_DataIn(USBD_HandleTypeDef *pdev, uint8_t epnum) |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
|
|
|
|
/* Ensure that the FIFO is empty before a new transfer, this condition could
|
|
|
|
/* Ensure that the FIFO is empty before a new transfer, this condition could
|
|
|
|
be caused by a new transfer before the end of the previous transfer */ |
|
|
|
be caused by a new transfer before the end of the previous transfer */ |
|
|
|
((USBD_HID_HandleTypeDef *) pdev->pClassData)->state = HID_IDLE; |
|
|
|
((USBD_HID_HandleTypeDef *) pdev->pClassData)->state = HID_IDLE; |
|
|
|