Restructure & bugfix Upstream HID. Still some issue with Downstream...

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

@ -45,7 +45,7 @@
<option id="ilg.gnuarmeclipse.managedbuild.cross.option.warnings.logicalop.1966851850" name="Warn if suspicious logical ops (-Wlogical-op)" superClass="ilg.gnuarmeclipse.managedbuild.cross.option.warnings.logicalop" value="true" valueType="boolean"/>
<option id="ilg.gnuarmeclipse.managedbuild.cross.option.warnings.pointerarith.1529172556" name="Warn if pointer arithmetic (-Wpointer-arith)" superClass="ilg.gnuarmeclipse.managedbuild.cross.option.warnings.pointerarith" value="true" valueType="boolean"/>
<targetPlatform archList="all" binaryParser="org.eclipse.cdt.core.ELF" id="ilg.gnuarmeclipse.managedbuild.cross.targetPlatform.1042769951" isAbstract="false" osList="all" superClass="ilg.gnuarmeclipse.managedbuild.cross.targetPlatform"/>
<builder autoBuildTarget="all" buildPath="${workspace_loc:/Downstream}/Debug" cleanBuildTarget="clean" command="${cross_make}" id="org.eclipse.cdt.build.core.internal.builder.1804403788" incrementalBuildTarget="all" keepEnvironmentInBuildfile="false" managedBuildOn="true" name="CDT Internal Builder" superClass="org.eclipse.cdt.build.core.internal.builder"/>
<builder autoBuildTarget="all" buildPath="${workspace_loc:/Downstream}/Debug" cleanBuildTarget="clean" command="${cross_make}" id="org.eclipse.cdt.build.core.internal.builder.1804403788" incrementalBuildTarget="all" keepEnvironmentInBuildfile="false" managedBuildOn="true" name="CDT Internal Builder" parallelBuildOn="true" parallelizationNumber="optimal" superClass="org.eclipse.cdt.build.core.internal.builder"/>
<tool id="ilg.gnuarmeclipse.managedbuild.cross.tool.assembler.789837881" name="Cross ARM GNU Assembler" superClass="ilg.gnuarmeclipse.managedbuild.cross.tool.assembler">
<option id="ilg.gnuarmeclipse.managedbuild.cross.option.assembler.usepreprocessor.1524992420" name="Use preprocessor" superClass="ilg.gnuarmeclipse.managedbuild.cross.option.assembler.usepreprocessor" value="true" valueType="boolean"/>
<option id="ilg.gnuarmeclipse.managedbuild.cross.option.assembler.defs.559716966" name="Defined symbols (-D)" superClass="ilg.gnuarmeclipse.managedbuild.cross.option.assembler.defs" valueType="definedSymbols">
@ -167,7 +167,7 @@
<option id="ilg.gnuarmeclipse.managedbuild.cross.option.warnings.pointerarith.1192110404" name="Warn if pointer arithmetic (-Wpointer-arith)" superClass="ilg.gnuarmeclipse.managedbuild.cross.option.warnings.pointerarith" value="true" valueType="boolean"/>
<option id="ilg.gnuarmeclipse.managedbuild.cross.option.warnings.logicalop.322411367" name="Warn if suspicious logical ops (-Wlogical-op)" superClass="ilg.gnuarmeclipse.managedbuild.cross.option.warnings.logicalop" value="true" valueType="boolean"/>
<targetPlatform archList="all" binaryParser="org.eclipse.cdt.core.ELF" id="ilg.gnuarmeclipse.managedbuild.cross.targetPlatform.777514892" isAbstract="false" osList="all" superClass="ilg.gnuarmeclipse.managedbuild.cross.targetPlatform"/>
<builder autoBuildTarget="all" buildPath="${workspace_loc:/Downstream}/Release" cleanBuildTarget="clean" command="${cross_make}" id="org.eclipse.cdt.build.core.internal.builder.1921336679" incrementalBuildTarget="all" keepEnvironmentInBuildfile="false" managedBuildOn="true" name="CDT Internal Builder" superClass="org.eclipse.cdt.build.core.internal.builder"/>
<builder autoBuildTarget="all" buildPath="${workspace_loc:/Downstream}/Release" cleanBuildTarget="clean" command="${cross_make}" id="org.eclipse.cdt.build.core.internal.builder.1921336679" incrementalBuildTarget="all" keepEnvironmentInBuildfile="false" managedBuildOn="true" name="CDT Internal Builder" parallelBuildOn="true" parallelizationNumber="optimal" superClass="org.eclipse.cdt.build.core.internal.builder"/>
<tool id="ilg.gnuarmeclipse.managedbuild.cross.tool.assembler.314526004" name="Cross ARM GNU Assembler" superClass="ilg.gnuarmeclipse.managedbuild.cross.tool.assembler">
<option id="ilg.gnuarmeclipse.managedbuild.cross.option.assembler.usepreprocessor.2143421487" name="Use preprocessor" superClass="ilg.gnuarmeclipse.managedbuild.cross.option.assembler.usepreprocessor" value="true" valueType="boolean"/>
<option id="ilg.gnuarmeclipse.managedbuild.cross.option.assembler.defs.1659712048" name="Defined symbols (-D)" superClass="ilg.gnuarmeclipse.managedbuild.cross.option.assembler.defs" valueType="definedSymbols">

@ -57,7 +57,7 @@ InterfaceCommandMscTypeDef;
typedef enum
{
COMMAND_HID_REPORT, //Downstream initiates HID report transfer to Upstream. Upstream just needs to Upstream_ReceivePacket each time.
COMMAND_HID_REPORT, //Returns HID report
}
InterfaceCommandHidTypeDef;

@ -33,7 +33,7 @@ typedef enum
do { \
USB_Host_Disconnect(); \
LED_Fault_SetBlinkRate(LED_FAST_BLINK_RATE); \
DownstreamState = STATE_ERROR; \
/*DownstreamState = STATE_ERROR; */ \
while (1); \
} while (0);

@ -394,7 +394,7 @@ static USBH_StatusTypeDef USBH_HID_Process(USBH_HandleTypeDef *phost)
if (urbStatus == USBH_URB_NOTREADY)
{
HID_Handle->state = HID_IDLE;
HID_Handle->state = HID_GET_DATA;
break;
}
@ -404,7 +404,7 @@ static USBH_StatusTypeDef USBH_HID_Process(USBH_HandleTypeDef *phost)
if(USBH_ClrFeature(phost,
HID_Handle->ep_addr) == USBH_OK)
{
HID_Handle->state = HID_IDLE;
HID_Handle->state = HID_GET_DATA;
}
}
break;

@ -74,8 +74,7 @@ void Downstream_HID_InterruptReportCallback(DownstreamPacketTypeDef* packetToSen
return;
}
Downstream_TransmitPacket(packetToSend);
Downstream_PacketProcessor_ClassReply(packetToSend);
}

@ -15,9 +15,7 @@
//#include "usbd_def.h"
#include "stm32f4xx_hal.h"
#include "upstream_interface_def.h"
typedef uint8_t (*UpstreamHidSendReportCallback)(uint8_t *report,
@ -25,9 +23,8 @@ typedef uint8_t (*UpstreamHidSendReportCallback)(uint8_t *report,
void Upstream_HID_Init(InterfaceCommandClassTypeDef newClass);
void Upstream_HID_DeInit(void);
void Upstream_HID_GetNextReport(UpstreamHidSendReportCallback callback);
HAL_StatusTypeDef Upstream_HID_GetNextReport(UpstreamHidSendReportCallback callback);

@ -59,7 +59,7 @@ InterfaceCommandMscTypeDef;
typedef enum
{
COMMAND_HID_REPORT, //Downstream initiates HID report transfer to Upstream. Upstream just needs to Upstream_ReceivePacket each time.
COMMAND_HID_REPORT, //Returns HID report
}
InterfaceCommandHidTypeDef;

@ -87,8 +87,7 @@ HAL_StatusTypeDef Upstream_ReceivePacket(SpiPacketReceivedCallbackTypeDef callba
void Upstream_TxOkInterrupt(void);
void HAL_SPI_TxRxCpltCallback(SPI_HandleTypeDef *hspi);
void HAL_SPI_ErrorCallback(SPI_HandleTypeDef *hspi);
void Upstream_SetExpectedReceivedCommand(uint8_t expectedCommandClass,
uint8_t expectedCommand);
#endif /* INC_UPSTREAM_SPI_H_ */

@ -14,6 +14,7 @@
#include "led.h"
#include "upstream_interface_def.h"
typedef enum
@ -37,7 +38,7 @@ typedef enum
void Upstream_InitStateMachine(void);
void Upstream_StateMachine_SetErrorState(void);
HAL_StatusTypeDef Upstream_StateMachine_CheckClassOperationOk(void);
InterfaceCommandClassTypeDef Upstream_StateMachine_CheckActiveClass(void);
void Upstream_StateMachine_DeviceDisconnected(void);

@ -21,7 +21,6 @@
InterfaceCommandClassTypeDef ActiveHidClass = COMMAND_CLASS_INTERFACE;
UpstreamPacketTypeDef* UpstreamHidPacket = NULL;
UpstreamHidSendReportCallback ReportCallback = NULL;
@ -31,28 +30,8 @@ void Upstream_HID_GetNextReportReceiveCallback(UpstreamPacketTypeDef* receivedPa
void Upstream_HID_Init(InterfaceCommandClassTypeDef newClass)
{
if ((newClass != COMMAND_CLASS_HID_MOUSE)) //add classes here
{
UPSTREAM_SPI_FREAKOUT;
return;
}
if ((ActiveHidClass != COMMAND_CLASS_INTERFACE) ||
(UpstreamHidPacket != NULL))
{
UPSTREAM_SPI_FREAKOUT;
return;
}
ActiveHidClass = newClass;
}
void Upstream_HID_DeInit(void)
{
ActiveHidClass = COMMAND_CLASS_INTERFACE;
if (UpstreamHidPacket != NULL)
{
Upstream_ReleasePacket(UpstreamHidPacket);
@ -61,12 +40,17 @@ void Upstream_HID_DeInit(void)
}
void Upstream_HID_GetNextReport(UpstreamHidSendReportCallback callback)
HAL_StatusTypeDef Upstream_HID_GetNextReport(UpstreamHidSendReportCallback callback)
{
if ((ActiveHidClass != COMMAND_CLASS_HID_MOUSE)) //add classes here
UpstreamPacketTypeDef* freePacket;
InterfaceCommandClassTypeDef activeClass;
activeClass = Upstream_StateMachine_CheckActiveClass();
if ((activeClass != COMMAND_CLASS_HID_MOUSE)) //add classes here
{
UPSTREAM_SPI_FREAKOUT;
return;
UPSTREAM_STATEMACHINE_FREAKOUT;
return HAL_ERROR;
}
//Release packet used for last transaction (if any)
@ -78,23 +62,47 @@ void Upstream_HID_GetNextReport(UpstreamHidSendReportCallback callback)
if (ReportCallback != NULL)
{
UPSTREAM_SPI_FREAKOUT;
return;
UPSTREAM_STATEMACHINE_FREAKOUT;
return HAL_ERROR;
}
ReportCallback = callback;
//Get next packet
Upstream_SetExpectedReceivedCommand(ActiveHidClass, COMMAND_HID_REPORT);
Upstream_ReceivePacket(Upstream_HID_GetNextReportReceiveCallback);
freePacket = Upstream_GetFreePacketImmediately();
if (freePacket == NULL)
{
return HAL_ERROR;
}
freePacket->Length16 = UPSTREAM_PACKET_HEADER_LEN_16;
freePacket->CommandClass = activeClass;
freePacket->Command = COMMAND_HID_REPORT;
if (Upstream_TransmitPacket(freePacket) == HAL_OK)
{
return Upstream_ReceivePacket(Upstream_HID_GetNextReportReceiveCallback);
}
//else:
Upstream_ReleasePacket(freePacket);
return HAL_ERROR;
}
void Upstream_HID_GetNextReportReceiveCallback(UpstreamPacketTypeDef* receivedPacket)
{
UpstreamHidSendReportCallback tempReportCallback;
InterfaceCommandClassTypeDef activeClass;
uint8_t dataLength = 0;
uint8_t i;
activeClass = Upstream_StateMachine_CheckActiveClass();
if ((activeClass != COMMAND_CLASS_HID_MOUSE)) //add classes here
{
UPSTREAM_STATEMACHINE_FREAKOUT;
return;
}
if ((UpstreamHidPacket != NULL) ||
(ReportCallback == NULL))
{
@ -108,7 +116,7 @@ void Upstream_HID_GetNextReportReceiveCallback(UpstreamPacketTypeDef* receivedPa
}
if (ActiveHidClass == COMMAND_CLASS_HID_MOUSE)
if (activeClass == COMMAND_CLASS_HID_MOUSE)
{
if (receivedPacket->Length16 != (UPSTREAM_PACKET_HEADER_LEN_16 + ((HID_MOUSE_DATA_LEN + 1) / 2)))
{

@ -41,8 +41,9 @@ static void Upstream_MSC_BeginWriteReplyCallback(UpstreamPacketTypeDef* replyPac
HAL_StatusTypeDef Upstream_MSC_TestReady(UpstreamMSCCallbackTypeDef callback)
{
if (Upstream_StateMachine_CheckClassOperationOk() != HAL_OK)
if (Upstream_StateMachine_CheckActiveClass() != COMMAND_CLASS_MASS_STORAGE)
{
//UPSTREAM_STATEMACHINE_FREAKOUT;
return HAL_ERROR;
}
@ -60,7 +61,7 @@ void Upstream_MSC_TestReadyFreePacketCallback(UpstreamPacketTypeDef* freePacket)
if (Upstream_TransmitPacket(freePacket) == HAL_OK)
{
Upstream_ReleasePacket(freePacket);
Upstream_ReleasePacket(freePacket); /////////!!!!!!!!!!!!!???????????
if (Upstream_ReceivePacket(Upstream_MSC_TestReadyReplyCallback) != HAL_OK)
{
TestReadyCallback(HAL_ERROR);
@ -77,7 +78,7 @@ void Upstream_MSC_TestReadyFreePacketCallback(UpstreamPacketTypeDef* freePacket)
void Upstream_MSC_TestReadyReplyCallback(UpstreamPacketTypeDef* replyPacket)
{
if (Upstream_StateMachine_CheckClassOperationOk() != HAL_OK)
if (Upstream_StateMachine_CheckActiveClass() != COMMAND_CLASS_MASS_STORAGE)
{
return;
}
@ -106,7 +107,7 @@ HAL_StatusTypeDef Upstream_MSC_GetCapacity(UpstreamMSCCallbackUintPacketTypeDef
{
UpstreamPacketTypeDef* freePacket;
if (Upstream_StateMachine_CheckClassOperationOk() != HAL_OK)
if (Upstream_StateMachine_CheckActiveClass() != COMMAND_CLASS_MASS_STORAGE)
{
return HAL_ERROR;
}
@ -126,6 +127,7 @@ HAL_StatusTypeDef Upstream_MSC_GetCapacity(UpstreamMSCCallbackUintPacketTypeDef
return Upstream_ReceivePacket(Upstream_MSC_GetCapacityReplyCallback);
}
//else:
Upstream_ReleasePacket(freePacket); ////////?????????
return HAL_ERROR;
}
@ -135,7 +137,7 @@ void Upstream_MSC_GetCapacityReplyCallback(UpstreamPacketTypeDef* replyPacket)
uint32_t uint1;
uint32_t uint2;
if (Upstream_StateMachine_CheckClassOperationOk() != HAL_OK)
if (Upstream_StateMachine_CheckActiveClass() != COMMAND_CLASS_MASS_STORAGE)
{
return;
}
@ -164,7 +166,7 @@ HAL_StatusTypeDef Upstream_MSC_BeginRead(UpstreamMSCCallbackTypeDef callback,
uint32_t readBlockCount,
uint32_t readByteCount)
{
if (Upstream_StateMachine_CheckClassOperationOk() != HAL_OK)
if (Upstream_StateMachine_CheckActiveClass() != COMMAND_CLASS_MASS_STORAGE)
{
return HAL_ERROR;
}
@ -207,7 +209,7 @@ void Upstream_MSC_BeginReadFreePacketCallback(UpstreamPacketTypeDef* freePacket)
HAL_StatusTypeDef Upstream_MSC_GetStreamDataPacket(UpstreamMSCCallbackPacketTypeDef callback)
{
if (Upstream_StateMachine_CheckClassOperationOk() != HAL_OK)
if (Upstream_StateMachine_CheckActiveClass() != COMMAND_CLASS_MASS_STORAGE)
{
return HAL_ERROR;
}
@ -236,7 +238,7 @@ void Upstream_MSC_GetStreamDataPacketCallback(UpstreamPacketTypeDef* replyPacket
ReadStreamBusy = 0;
if (Upstream_StateMachine_CheckClassOperationOk() != HAL_OK)
if (Upstream_StateMachine_CheckActiveClass() != COMMAND_CLASS_MASS_STORAGE)
{
return;
}
@ -277,7 +279,7 @@ HAL_StatusTypeDef Upstream_MSC_BeginWrite(UpstreamMSCCallbackTypeDef callback,
uint64_t writeBlockStart,
uint32_t writeBlockCount)
{
if (Upstream_StateMachine_CheckClassOperationOk() != HAL_OK)
if (Upstream_StateMachine_CheckActiveClass() != COMMAND_CLASS_MASS_STORAGE)
{
return HAL_ERROR;
}
@ -318,7 +320,7 @@ void Upstream_MSC_BeginWriteReplyCallback(UpstreamPacketTypeDef* replyPacket)
{
uint8_t tempResult;
if (Upstream_StateMachine_CheckClassOperationOk() != HAL_OK)
if (Upstream_StateMachine_CheckActiveClass() != COMMAND_CLASS_MASS_STORAGE)
{
return;
}
@ -347,7 +349,7 @@ void Upstream_MSC_BeginWriteReplyCallback(UpstreamPacketTypeDef* replyPacket)
HAL_StatusTypeDef Upstream_MSC_PutStreamDataPacket(UpstreamPacketTypeDef* packetToSend,
uint32_t dataLength8)
{
if (Upstream_StateMachine_CheckClassOperationOk() != HAL_OK)
if (Upstream_StateMachine_CheckActiveClass() != COMMAND_CLASS_MASS_STORAGE)
{
return HAL_ERROR;
}

@ -540,12 +540,4 @@ void HAL_SPI_ErrorCallback(SPI_HandleTypeDef *hspi)
}
//Used by USB interface classes.
//This is required when Downstream sends a packet without an initiating request from us
void Upstream_SetExpectedReceivedCommand(uint8_t expectedCommandClass,
uint8_t expectedCommand)
{
SentCommandClass = expectedCommandClass;
SentCommand = expectedCommand;
}

@ -12,7 +12,6 @@
#include "upstream_statemachine.h"
#include "upstream_spi.h"
#include "upstream_interface_def.h"
#include "usb_device.h"
#include "usbd_core.h"
#include "usbd_msc.h"
@ -76,20 +75,20 @@ void Upstream_StateMachine_SetErrorState(void)
}
HAL_StatusTypeDef Upstream_StateMachine_CheckClassOperationOk(void)
InterfaceCommandClassTypeDef Upstream_StateMachine_CheckActiveClass(void)
{
if (UpstreamState == STATE_ERROR)
{
return HAL_ERROR;
return COMMAND_CLASS_ERROR;
}
if (UpstreamState != STATE_DEVICE_ACTIVE)
{
UPSTREAM_STATEMACHINE_FREAKOUT;
return HAL_ERROR;
return COMMAND_CLASS_INTERFACE;
}
return HAL_OK;
return ConfiguredDeviceClass;
}

Loading…
Cancel
Save