HID class handles host restart correctly

USG_1.0
Robert Fisk 8 years ago
parent 12a576b5af
commit 32ca5cdcf9

@ -126,16 +126,20 @@ void Upstream_HID_GetNextInterruptReportReceiveCallback(UpstreamPacketTypeDef* r
return; return;
} }
if ((UpstreamHidPacket != NULL) || if (UpstreamHidPacket != NULL)
(GetReportCallback == NULL))
{ {
UPSTREAM_SPI_FREAKOUT; while(1);
return;
} }
if (receivedPacket == NULL) if (receivedPacket == NULL) //Error receiving packet
{ {
return; //Just give up... return; //Just give up...
}
if (GetReportCallback == NULL) //HID class may have been DeInitted while we were waiting for our reply
{
Upstream_ReleasePacket(receivedPacket);
return;
} }
if (receivedPacket->Length16 == UPSTREAM_PACKET_HEADER_LEN_16) if (receivedPacket->Length16 == UPSTREAM_PACKET_HEADER_LEN_16)
@ -161,13 +165,13 @@ void Upstream_HID_GetNextInterruptReportReceiveCallback(UpstreamPacketTypeDef* r
{ {
if (receivedPacket->Length16 != (UPSTREAM_PACKET_HEADER_LEN_16 + ((HID_MOUSE_INPUT_DATA_LEN + 1) / 2))) if (receivedPacket->Length16 != (UPSTREAM_PACKET_HEADER_LEN_16 + ((HID_MOUSE_INPUT_DATA_LEN + 1) / 2)))
{ {
UPSTREAM_SPI_FREAKOUT; UPSTREAM_STATEMACHINE_FREAKOUT;
return; return;
} }
dataLength = HID_MOUSE_INPUT_DATA_LEN; dataLength = HID_MOUSE_INPUT_DATA_LEN;
if ((receivedPacket->Data[0] & ~((1 << HID_MOUSE_MAX_BUTTONS) - 1)) != 0) //Check number of buttons received if ((receivedPacket->Data[0] & ~((1 << HID_MOUSE_MAX_BUTTONS) - 1)) != 0) //Check number of buttons received
{ {
UPSTREAM_SPI_FREAKOUT; UPSTREAM_STATEMACHINE_FREAKOUT;
return; return;
} }
//Other mouse sanity checks & stuff go here... //Other mouse sanity checks & stuff go here...
@ -177,21 +181,21 @@ void Upstream_HID_GetNextInterruptReportReceiveCallback(UpstreamPacketTypeDef* r
{ {
if (receivedPacket->Length16 != (UPSTREAM_PACKET_HEADER_LEN_16 + ((HID_KEYBOARD_INPUT_DATA_LEN + 1) / 2))) if (receivedPacket->Length16 != (UPSTREAM_PACKET_HEADER_LEN_16 + ((HID_KEYBOARD_INPUT_DATA_LEN + 1) / 2)))
{ {
UPSTREAM_SPI_FREAKOUT; UPSTREAM_STATEMACHINE_FREAKOUT;
return; return;
} }
dataLength = HID_KEYBOARD_INPUT_DATA_LEN; dataLength = HID_KEYBOARD_INPUT_DATA_LEN;
if (receivedPacket->Data[1] != 0) if (receivedPacket->Data[1] != 0)
{ {
UPSTREAM_SPI_FREAKOUT; UPSTREAM_STATEMACHINE_FREAKOUT;
return; return;
} }
for (i = 2; i < HID_KEYBOARD_INPUT_DATA_LEN; i++) for (i = 2; i < HID_KEYBOARD_INPUT_DATA_LEN; i++)
{ {
if (receivedPacket->Data[i] > HID_KEYBOARD_MAX_KEY) if (receivedPacket->Data[i] > HID_KEYBOARD_MAX_KEY)
{ {
UPSTREAM_SPI_FREAKOUT; UPSTREAM_STATEMACHINE_FREAKOUT;
return; return;
} }
} }
@ -202,7 +206,7 @@ void Upstream_HID_GetNextInterruptReportReceiveCallback(UpstreamPacketTypeDef* r
else else
{ {
UPSTREAM_SPI_FREAKOUT; UPSTREAM_STATEMACHINE_FREAKOUT;
return; return;
} }
@ -230,15 +234,10 @@ void Upstream_HID_SendControlReport(UpstreamPacketTypeDef* packetToSend, uint8_t
(activeClass != COMMAND_CLASS_HID_KEYBOARD) || (activeClass != COMMAND_CLASS_HID_KEYBOARD) ||
(dataLength != HID_KEYBOARD_OUTPUT_DATA_LEN)) (dataLength != HID_KEYBOARD_OUTPUT_DATA_LEN))
{ {
UPSTREAM_SPI_FREAKOUT; UPSTREAM_STATEMACHINE_FREAKOUT;
return; return;
} }
if (GetReportCallback == NULL)
{
while(1); //checkme!
}
//Save data until after the next interrupt data is received from Downstream //Save data until after the next interrupt data is received from Downstream
KeyboardOutDataState = KEYBOARD_OUT_STATE_DATA_READY; KeyboardOutDataState = KEYBOARD_OUT_STATE_DATA_READY;
for (i = 0; i < HID_KEYBOARD_OUTPUT_DATA_LEN; i++) for (i = 0; i < HID_KEYBOARD_OUTPUT_DATA_LEN; i++)

Loading…
Cancel
Save