Upstream HID bugfixes.

USG_1.0
Robert Fisk 9 years ago
parent cda254c8bb
commit 4d9e26b6ef

@ -17,9 +17,6 @@
#include "downstream_spi.h" #include "downstream_spi.h"
#define HID_MOUSE_TRANSFER_BYTES 5
#define HID_KEYBOARD_TRANSFER_BYTES 0
InterfaceCommandClassTypeDef Downstream_HID_ApproveConnectedDevice(void); InterfaceCommandClassTypeDef Downstream_HID_ApproveConnectedDevice(void);

@ -17,6 +17,10 @@
#define HID_MOUSE_DATA_LEN 4
#define HID_KEYBOARD_DATA_LEN 0
extern USBH_HandleTypeDef hUsbHostFS; //Hard-link ourselves to usb_host.c extern USBH_HandleTypeDef hUsbHostFS; //Hard-link ourselves to usb_host.c
extern InterfaceCommandClassTypeDef ConfiguredDeviceClass; //Do a cheap hard-link to downstream_statemachine.c, rather than keep a duplicate here extern InterfaceCommandClassTypeDef ConfiguredDeviceClass; //Do a cheap hard-link to downstream_statemachine.c, rather than keep a duplicate here
@ -61,7 +65,7 @@ void Downstream_HID_InterruptReportCallback(DownstreamPacketTypeDef* packetToSen
{ {
if (ConfiguredDeviceClass == COMMAND_CLASS_HID_MOUSE) if (ConfiguredDeviceClass == COMMAND_CLASS_HID_MOUSE)
{ {
packetToSend->Length16 = (HID_MOUSE_TRANSFER_BYTES / 2) + DOWNSTREAM_PACKET_HEADER_LEN_16; packetToSend->Length16 = ((HID_MOUSE_DATA_LEN + 1) / 2) + DOWNSTREAM_PACKET_HEADER_LEN_16;
} }
//else if... //else if...
else else

@ -20,10 +20,11 @@
#include "upstream_interface_def.h" #include "upstream_interface_def.h"
typedef uint8_t UpstreamHidSendReportCallback(uint8_t *report, typedef uint8_t (*UpstreamHidSendReportCallback)(uint8_t *report,
uint16_t len); uint16_t len);
void Upstream_HID_Init(InterfaceCommandClassTypeDef newClass); void Upstream_HID_Init(InterfaceCommandClassTypeDef newClass);
void Upstream_HID_DeInit(void); void Upstream_HID_DeInit(void);
void Upstream_HID_GetNextReport(UpstreamHidSendReportCallback callback); void Upstream_HID_GetNextReport(UpstreamHidSendReportCallback callback);

@ -113,8 +113,8 @@ USBD_HID_HandleTypeDef;
* @{ * @{
*/ */
extern USBD_ClassTypeDef USBD_HID_Mouse; extern USBD_ClassTypeDef USBD_HID;
extern USBD_ClassTypeDef USBD_HID_Keyboard;
//#define USBD_HID_CLASS &USBD_HID //#define USBD_HID_CLASS &USBD_HID
/** /**
@ -124,11 +124,13 @@ extern USBD_ClassTypeDef USBD_HID_Keyboard;
/** @defgroup USB_CORE_Exported_Functions /** @defgroup USB_CORE_Exported_Functions
* @{ * @{
*/ */
uint8_t USBD_HID_SendReport (uint8_t *report,
uint16_t len);
uint32_t USBD_HID_GetPollingInterval (USBD_HandleTypeDef *pdev); uint32_t USBD_HID_GetPollingInterval (USBD_HandleTypeDef *pdev);
void USBD_HID_PreinitMouse(void);
void USBD_HID_PreinitKeyboard(void);
/** /**
* @} * @}
*/ */

@ -55,12 +55,6 @@
static uint8_t USBD_HID_InitMouse(USBD_HandleTypeDef *pdev,
uint8_t cfgidx);
static uint8_t USBD_HID_InitKeyboard(USBD_HandleTypeDef *pdev,
uint8_t cfgidx);
static uint8_t USBD_HID_Init (USBD_HandleTypeDef *pdev, static uint8_t USBD_HID_Init (USBD_HandleTypeDef *pdev,
uint8_t cfgidx); uint8_t cfgidx);
@ -76,29 +70,14 @@ static uint8_t *USBD_HID_GetDeviceQualifierDesc (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);
static uint8_t USBD_HID_SendReport (uint8_t *report,
uint16_t len);
USBD_ClassTypeDef USBD_HID_Mouse =
{
USBD_HID_InitMouse,
USBD_HID_DeInit,
USBD_HID_Setup,
NULL, /*EP0_TxSent*/
NULL, /*EP0_RxReady*/
USBD_HID_DataIn, /*DataIn*/
NULL, /*DataOut*/
NULL, /*SOF */
NULL,
NULL,
USBD_HID_GetCfgDesc,
USBD_HID_GetCfgDesc,
USBD_HID_GetCfgDesc,
USBD_HID_GetDeviceQualifierDesc,
};
USBD_ClassTypeDef USBD_HID_Keyboard = USBD_ClassTypeDef USBD_HID =
{ {
USBD_HID_InitKeyboard, USBD_HID_Init,
USBD_HID_DeInit, USBD_HID_DeInit,
USBD_HID_Setup, USBD_HID_Setup,
NULL, /*EP0_TxSent*/ NULL, /*EP0_TxSent*/
@ -108,6 +87,7 @@ USBD_ClassTypeDef USBD_HID_Keyboard =
NULL, /*SOF */ NULL, /*SOF */
NULL, NULL,
NULL, NULL,
NULL,
USBD_HID_GetCfgDesc, USBD_HID_GetCfgDesc,
USBD_HID_GetCfgDesc, USBD_HID_GetCfgDesc,
USBD_HID_GetCfgDesc, USBD_HID_GetCfgDesc,
@ -155,7 +135,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*/ 0x00, //HID_MOUSE_REPORT_DESC_SIZE, /*wItemLength: Total length of Report descriptor*/
0x00, 0x00,
/******************** Descriptor of Mouse endpoint ********************/ /******************** Descriptor of Mouse endpoint ********************/
/* 27 */ /* 27 */
@ -180,7 +160,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*/ 0x00, //HID_MOUSE_REPORT_DESC_SIZE, /*wItemLength: Total length of Report descriptor*/
0x00, 0x00,
}; };
@ -264,18 +244,13 @@ uint8_t ActiveReportDescriptorLength;
* @param cfgidx: Configuration index * @param cfgidx: Configuration index
* @retval status * @retval status
*/ */
static uint8_t USBD_HID_InitMouse(USBD_HandleTypeDef *pdev, void USBD_HID_PreinitMouse(void)
uint8_t cfgidx)
{ {
ActiveReportDescriptor = HID_MOUSE_ReportDesc; ActiveReportDescriptor = HID_MOUSE_ReportDesc;
ActiveReportDescriptorLength = HID_MOUSE_REPORT_DESC_SIZE; ActiveReportDescriptorLength = HID_MOUSE_REPORT_DESC_SIZE;
USBD_HID_CfgDesc[USB_HID_CFGDESC__HID_REPORT_DESC_SIZE_OFFSET] = HID_MOUSE_REPORT_DESC_SIZE; USBD_HID_CfgDesc[USB_HID_CFGDESC__HID_REPORT_DESC_SIZE_OFFSET] = HID_MOUSE_REPORT_DESC_SIZE;
USBD_HID_Desc[USB_HID_DESC__HID_REPORT_DESC_SIZE_OFFSET] = HID_MOUSE_REPORT_DESC_SIZE; USBD_HID_Desc[USB_HID_DESC__HID_REPORT_DESC_SIZE_OFFSET] = HID_MOUSE_REPORT_DESC_SIZE;
Upstream_HID_Init(COMMAND_CLASS_HID_MOUSE);
return USBD_HID_Init(pdev, cfgidx);
} }
@ -396,7 +371,7 @@ static uint8_t USBD_HID_Setup (USBD_HandleTypeDef *pdev,
if( req->wValue >> 8 == HID_REPORT_DESC) if( req->wValue >> 8 == HID_REPORT_DESC)
{ {
len = MIN(ActiveReportDescriptorLength , req->wLength); len = MIN(ActiveReportDescriptorLength , req->wLength);
pbuf = HID_MOUSE_ReportDesc; pbuf = ActiveReportDescriptor;
} }
else if( req->wValue >> 8 == HID_DESCRIPTOR_TYPE) else if( req->wValue >> 8 == HID_DESCRIPTOR_TYPE)
{ {
@ -407,7 +382,6 @@ static uint8_t USBD_HID_Setup (USBD_HandleTypeDef *pdev,
USBD_CtlSendData (pdev, USBD_CtlSendData (pdev,
pbuf, pbuf,
len); len);
break; break;
case USB_REQ_GET_INTERFACE : case USB_REQ_GET_INTERFACE :

@ -547,8 +547,11 @@ USBD_StatusTypeDef USBD_DevDisconnected(USBD_HandleTypeDef *pdev)
} }
USBD_StatusTypeDef USBD_BufferFreed(USBD_HandleTypeDef *pdev) USBD_StatusTypeDef USBD_BufferFreed(USBD_HandleTypeDef *pdev)
{
if(pdev->pClass->FreeDataBuffer != NULL)
{ {
pdev->pClass->FreeDataBuffer(pdev); pdev->pClass->FreeDataBuffer(pdev);
}
return USBD_OK; return USBD_OK;
} }
/** /**

@ -14,15 +14,17 @@
#include "upstream_hid.h" #include "upstream_hid.h"
#include "upstream_spi.h" #include "upstream_spi.h"
#include "upstream_interface_def.h" #include "upstream_interface_def.h"
#include "usbd_hid.h"
#define HID_MOUSE_REPORT_LEN 4 #define HID_REPORT_DATA_LEN 8
#define HID_MOUSE_DATA_LEN 4
InterfaceCommandClassTypeDef ActiveHidClass = COMMAND_CLASS_INTERFACE; InterfaceCommandClassTypeDef ActiveHidClass = COMMAND_CLASS_INTERFACE;
UpstreamPacketTypeDef* UpstreamHidPacket = NULL; UpstreamPacketTypeDef* UpstreamHidPacket = NULL;
UpstreamHidSendReportCallback ReportCallback = NULL;
void Upstream_HID_GetNextReportReceiveCallback(UpstreamPacketTypeDef* receivedPacket); void Upstream_HID_GetNextReportReceiveCallback(UpstreamPacketTypeDef* receivedPacket);
@ -74,6 +76,13 @@ void Upstream_HID_GetNextReport(UpstreamHidSendReportCallback callback)
UpstreamHidPacket = NULL; UpstreamHidPacket = NULL;
} }
if (ReportCallback != NULL)
{
UPSTREAM_SPI_FREAKOUT;
return;
}
ReportCallback = callback;
//Get next packet //Get next packet
Upstream_SetExpectedReceivedCommand(ActiveHidClass, COMMAND_HID_REPORT); Upstream_SetExpectedReceivedCommand(ActiveHidClass, COMMAND_HID_REPORT);
Upstream_ReceivePacket(Upstream_HID_GetNextReportReceiveCallback); Upstream_ReceivePacket(Upstream_HID_GetNextReportReceiveCallback);
@ -82,9 +91,12 @@ void Upstream_HID_GetNextReport(UpstreamHidSendReportCallback callback)
void Upstream_HID_GetNextReportReceiveCallback(UpstreamPacketTypeDef* receivedPacket) void Upstream_HID_GetNextReportReceiveCallback(UpstreamPacketTypeDef* receivedPacket)
{ {
uint8_t reportLength = 0; UpstreamHidSendReportCallback tempReportCallback;
uint8_t dataLength = 0;
uint8_t i;
if (UpstreamHidPacket != NULL) if ((UpstreamHidPacket != NULL) ||
(ReportCallback == NULL))
{ {
UPSTREAM_SPI_FREAKOUT; UPSTREAM_SPI_FREAKOUT;
return; return;
@ -98,7 +110,7 @@ void Upstream_HID_GetNextReportReceiveCallback(UpstreamPacketTypeDef* receivedPa
if (ActiveHidClass == COMMAND_CLASS_HID_MOUSE) if (ActiveHidClass == COMMAND_CLASS_HID_MOUSE)
{ {
if (receivedPacket->Length16 != (UPSTREAM_PACKET_HEADER_LEN_16 + ((HID_MOUSE_REPORT_LEN + 1) / 2))) if (receivedPacket->Length16 != (UPSTREAM_PACKET_HEADER_LEN_16 + ((HID_MOUSE_DATA_LEN + 1) / 2)))
{ {
UPSTREAM_SPI_FREAKOUT; UPSTREAM_SPI_FREAKOUT;
return; return;
@ -106,20 +118,27 @@ void Upstream_HID_GetNextReportReceiveCallback(UpstreamPacketTypeDef* receivedPa
//Mouse sanity checks & stuff go here... //Mouse sanity checks & stuff go here...
reportLength = HID_MOUSE_REPORT_LEN; dataLength = HID_MOUSE_DATA_LEN;
} }
//Other HID classes go here... //Other HID classes go here...
if (reportLength == 0) if (dataLength == 0)
{ {
UPSTREAM_SPI_FREAKOUT; UPSTREAM_SPI_FREAKOUT;
return; return;
} }
for (i = dataLength; i > HID_REPORT_DATA_LEN; i++)
{
receivedPacket->Data[i] = 0; //Zero out unused bytes before we send report upstream
}
UpstreamHidPacket = receivedPacket; //Save packet so we can free it when upstream USB transaction is done UpstreamHidPacket = receivedPacket; //Save packet so we can free it when upstream USB transaction is done
USBD_HID_SendReport(receivedPacket->Data, reportLength); tempReportCallback = ReportCallback;
ReportCallback = NULL;
tempReportCallback(receivedPacket->Data, HID_REPORT_DATA_LEN);
} }

@ -177,7 +177,8 @@ void Upstream_StateMachine_NotifyDeviceReplyCallback(UpstreamPacketTypeDef* repl
case COMMAND_CLASS_HID_MOUSE: case COMMAND_CLASS_HID_MOUSE:
newActiveClass = COMMAND_CLASS_HID_MOUSE; newActiveClass = COMMAND_CLASS_HID_MOUSE;
newClassPointer = &USBD_HID_Mouse; newClassPointer = &USBD_HID;
USBD_HID_PreinitMouse();
break; break;
//Add other supported classes here... //Add other supported classes here...

Loading…
Cancel
Save