diff --git a/Downstream/.cproject b/Downstream/.cproject
index 2730d12..a64ae34 100644
--- a/Downstream/.cproject
+++ b/Downstream/.cproject
@@ -48,7 +48,7 @@
-
@@ -61,6 +61,7 @@
+
@@ -223,7 +225,7 @@
-
+
diff --git a/Downstream/.settings/org.eclipse.cdt.codan.core.prefs b/Downstream/.settings/org.eclipse.cdt.codan.core.prefs
index 77386c2..ff135cf 100644
--- a/Downstream/.settings/org.eclipse.cdt.codan.core.prefs
+++ b/Downstream/.settings/org.eclipse.cdt.codan.core.prefs
@@ -3,6 +3,10 @@ org.eclipse.cdt.codan.checkers.errnoreturn=Warning
org.eclipse.cdt.codan.checkers.errnoreturn.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},implicit\=>false}
org.eclipse.cdt.codan.checkers.errreturnvalue=Error
org.eclipse.cdt.codan.checkers.errreturnvalue.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true}}
+org.eclipse.cdt.codan.checkers.nocommentinside=-Error
+org.eclipse.cdt.codan.checkers.nocommentinside.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true}}
+org.eclipse.cdt.codan.checkers.nolinecomment=-Error
+org.eclipse.cdt.codan.checkers.nolinecomment.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true}}
org.eclipse.cdt.codan.checkers.noreturn=Error
org.eclipse.cdt.codan.checkers.noreturn.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},implicit\=>false}
org.eclipse.cdt.codan.internal.checkers.AbstractClassCreation=Error
diff --git a/Downstream/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_hcd.c b/Downstream/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_hcd.c
index 1c26e4d..cb659bf 100644
--- a/Downstream/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_hcd.c
+++ b/Downstream/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_hcd.c
@@ -879,11 +879,14 @@ static void HCD_HC_IN_IRQHandler(HCD_HandleTypeDef *hhcd, uint8_t chnum)
hhcd->hc[chnum].urb_state = URB_NOTREADY;
}
- /* re-activate the channel */
- tmpreg = USBx_HC(chnum)->HCCHAR;
- tmpreg &= ~USB_OTG_HCCHAR_CHDIS;
- tmpreg |= USB_OTG_HCCHAR_CHENA;
- USBx_HC(chnum)->HCCHAR = tmpreg;
+ if (hhcd->hc[chnum].ep_type != EP_TYPE_INTR) //DON'T re-enable an interrupt-in transaction
+ {
+ /* re-activate the channel */
+ tmpreg = USBx_HC(chnum)->HCCHAR;
+ tmpreg &= ~USB_OTG_HCCHAR_CHDIS;
+ tmpreg |= USB_OTG_HCCHAR_CHENA;
+ USBx_HC(chnum)->HCCHAR = tmpreg;
+ }
}
__HAL_HCD_CLEAR_HC_INT(chnum, USB_OTG_HCINT_CHH);
HAL_HCD_HC_NotifyURBChange_Callback(hhcd, chnum, hhcd->hc[chnum].urb_state);
diff --git a/Downstream/Inc/downstream_interface_def.h b/Downstream/Inc/downstream_interface_def.h
index 435d6e8..b3dfaf2 100644
--- a/Downstream/Inc/downstream_interface_def.h
+++ b/Downstream/Inc/downstream_interface_def.h
@@ -15,7 +15,7 @@
//***************
// Attention!
-// Keep this file synchronised with downstream_interface_def.h
+// Keep this file synchronised with upstream_interface_def.h
// in the Upstream project.
//***************
@@ -29,6 +29,7 @@ typedef enum
{
COMMAND_CLASS_INTERFACE,
COMMAND_CLASS_MASS_STORAGE,
+ COMMAND_CLASS_HID_MOUSE,
//...
COMMAND_CLASS_ERROR
}
@@ -53,6 +54,13 @@ typedef enum
InterfaceCommandMscTypeDef;
+typedef enum
+{
+ COMMAND_HID_REPORT, //Downstream initiates HID report transfer to Upstream. Upstream just needs to Upstream_ReceivePacket each time.
+}
+InterfaceCommandHidTypeDef;
+
+
typedef enum
{
COMMAND_ERROR_GENERIC,
diff --git a/Downstream/Inc/usbh_config.h b/Downstream/Inc/usbh_config.h
index a576fa4..59e70eb 100644
--- a/Downstream/Inc/usbh_config.h
+++ b/Downstream/Inc/usbh_config.h
@@ -62,13 +62,13 @@
#define USBH_KEEP_CFG_DESCRIPTOR 1
/*---------- -----------*/
-#define USBH_MAX_NUM_SUPPORTED_CLASS 1
+#define USBH_MAX_NUM_SUPPORTED_CLASS 2
/*---------- -----------*/
#define USBH_MAX_SIZE_CONFIGURATION 256
/*---------- -----------*/
-#define USBH_MAX_DATA_BUFFER 512
+#define USBH_MAX_DATA_BUFFER 256 //was 512, string descriptors are max 255 bytes
/*---------- -----------*/
#define USBH_DEBUG_LEVEL 0
diff --git a/Downstream/Middlewares/ST/STM32_USB_Host_Library/Class/HID/Inc/usbh_hid.h b/Downstream/Middlewares/ST/STM32_USB_Host_Library/Class/HID/Inc/usbh_hid.h
index 9d4bdd2..1f292f3 100644
--- a/Downstream/Middlewares/ST/STM32_USB_Host_Library/Class/HID/Inc/usbh_hid.h
+++ b/Downstream/Middlewares/ST/STM32_USB_Host_Library/Class/HID/Inc/usbh_hid.h
@@ -112,8 +112,8 @@ typedef enum
{
HID_INIT= 0,
HID_IDLE,
- HID_SEND_DATA,
- HID_BUSY,
+// HID_SEND_DATA,
+// HID_BUSY,
HID_GET_DATA,
HID_SYNC,
HID_POLL,
@@ -227,9 +227,9 @@ typedef struct _HID_Process
uint8_t ep_addr;
uint16_t poll;
uint32_t timer;
- uint8_t DataReady;
+// uint8_t DataReady;
HID_DescTypeDef HID_Desc;
- USBH_StatusTypeDef ( * Init)(USBH_HandleTypeDef *phost);
+ //USBH_StatusTypeDef ( * Init)(USBH_HandleTypeDef *phost);
}
HID_HandleTypeDef;
diff --git a/Downstream/Middlewares/ST/STM32_USB_Host_Library/Class/HID/Src/usbh_hid.c b/Downstream/Middlewares/ST/STM32_USB_Host_Library/Class/HID/Src/usbh_hid.c
index 8b8ea93..972bf23 100644
--- a/Downstream/Middlewares/ST/STM32_USB_Host_Library/Class/HID/Src/usbh_hid.c
+++ b/Downstream/Middlewares/ST/STM32_USB_Host_Library/Class/HID/Src/usbh_hid.c
@@ -37,6 +37,8 @@
* limitations under the License.
*
******************************************************************************
+ *
+ * Modifications by Robert Fisk
*/
/* Includes ------------------------------------------------------------------*/
@@ -105,8 +107,8 @@ static USBH_StatusTypeDef USBH_HID_Process(USBH_HandleTypeDef *phost);
static USBH_StatusTypeDef USBH_HID_SOFProcess(USBH_HandleTypeDef *phost);
static void USBH_HID_ParseHIDDesc (HID_DescTypeDef *desc, uint8_t *buf);
-extern USBH_StatusTypeDef USBH_HID_MouseInit(USBH_HandleTypeDef *phost);
-extern USBH_StatusTypeDef USBH_HID_KeybdInit(USBH_HandleTypeDef *phost);
+//extern USBH_StatusTypeDef USBH_HID_MouseInit(USBH_HandleTypeDef *phost);
+//extern USBH_StatusTypeDef USBH_HID_KeybdInit(USBH_HandleTypeDef *phost);
USBH_ClassTypeDef HID_Class =
{
@@ -162,12 +164,12 @@ static USBH_StatusTypeDef USBH_HID_InterfaceInit (USBH_HandleTypeDef *phost)
if(phost->device.CfgDesc.Itf_Desc[phost->device.current_interface].bInterfaceProtocol == HID_KEYBRD_BOOT_CODE)
{
USBH_UsrLog ("KeyBoard device found!");
- HID_Handle->Init = USBH_HID_KeybdInit;
+ //HID_Handle->Init = USBH_HID_KeybdInit;
}
else if(phost->device.CfgDesc.Itf_Desc[phost->device.current_interface].bInterfaceProtocol == HID_MOUSE_BOOT_CODE)
{
USBH_UsrLog ("Mouse device found!");
- HID_Handle->Init = USBH_HID_MouseInit;
+ //HID_Handle->Init = USBH_HID_MouseInit;
}
else
{
@@ -296,22 +298,22 @@ static USBH_StatusTypeDef USBH_HID_ClassRequest(USBH_HandleTypeDef *phost)
{
USBH_HID_ParseHIDDesc(&HID_Handle->HID_Desc, phost->device.Data);
- HID_Handle->ctl_state = HID_REQ_GET_REPORT_DESC;
+ HID_Handle->ctl_state = HID_REQ_SET_IDLE; //HID_REQ_GET_REPORT_DESC;
}
break;
- case HID_REQ_GET_REPORT_DESC:
-
-
- /* Get Report Desc */
- if (USBH_HID_GetHIDReportDescriptor(phost, HID_Handle->HID_Desc.wItemLength) == USBH_OK)
- {
- /* The descriptor is available in phost->device.Data */
-
- HID_Handle->ctl_state = HID_REQ_SET_IDLE;
- }
-
- break;
+// case HID_REQ_GET_REPORT_DESC:
+//
+//
+// /* Get Report Desc */
+// if (USBH_HID_GetHIDReportDescriptor(phost, HID_Handle->HID_Desc.wItemLength) == USBH_OK)
+// {
+// /* The descriptor is available in phost->device.Data */
+//
+// HID_Handle->ctl_state = HID_REQ_SET_IDLE;
+// }
+//
+// break;
case HID_REQ_SET_IDLE:
@@ -356,41 +358,41 @@ static USBH_StatusTypeDef USBH_HID_ClassRequest(USBH_HandleTypeDef *phost)
*/
static USBH_StatusTypeDef USBH_HID_Process(USBH_HandleTypeDef *phost)
{
- USBH_StatusTypeDef status = USBH_OK;
+ USBH_URBStateTypeDef urbStatus;
HID_HandleTypeDef *HID_Handle = (HID_HandleTypeDef *) phost->pActiveClass->pData;
switch (HID_Handle->state)
{
case HID_INIT:
- HID_Handle->Init(phost);
- case HID_IDLE:
- if(USBH_HID_GetReport (phost,
- 0x01,
- 0,
- HID_Handle->pData,
- HID_Handle->length) == USBH_OK)
- {
-
- fifo_write(&HID_Handle->fifo, HID_Handle->pData, HID_Handle->length);
- HID_Handle->state = HID_SYNC;
- }
-
- break;
+// HID_Handle->Init(phost);
+ HID_Handle->pData = phost->device.Data;
+
+// case HID_IDLE:
+// if(USBH_HID_GetReport (phost,
+// 0x01,
+// 0,
+// HID_Handle->pData,
+// HID_Handle->length) == USBH_OK)
+// {
+//
+// fifo_write(&HID_Handle->fifo, HID_Handle->pData, HID_Handle->length);
+// HID_Handle->state = HID_SYNC;
+// }
+//
+// break;
case HID_SYNC:
-
/* Sync with start of Even Frame */
+ //Uhhh, doesn't this sync with an odd frame?
+ //Also, do we need to sync at all?
+
if(phost->Timer & 1)
{
HID_Handle->state = HID_GET_DATA;
}
-#if (USBH_USE_OS == 1)
- osMessagePut ( phost->os_event, USBH_URB_EVENT, 0);
-#endif
break;
case HID_GET_DATA:
-
USBH_InterruptReceiveData(phost,
HID_Handle->pData,
HID_Handle->length,
@@ -398,42 +400,43 @@ static USBH_StatusTypeDef USBH_HID_Process(USBH_HandleTypeDef *phost)
HID_Handle->state = HID_POLL;
HID_Handle->timer = phost->Timer;
- HID_Handle->DataReady = 0;
break;
case HID_POLL:
+ urbStatus = USBH_LL_GetURBState(phost , HID_Handle->InPipe);
- if(USBH_LL_GetURBState(phost , HID_Handle->InPipe) == USBH_URB_DONE)
+ if (urbStatus == USBH_URB_DONE)
{
- if(HID_Handle->DataReady == 0)
- {
- fifo_write(&HID_Handle->fifo, HID_Handle->pData, HID_Handle->length);
- HID_Handle->DataReady = 1;
USBH_HID_EventCallback(phost);
-#if (USBH_USE_OS == 1)
- osMessagePut ( phost->os_event, USBH_URB_EVENT, 0);
-#endif
- }
+ HID_Handle->state = HID_IDLE;
+ break;
}
- else if(USBH_LL_GetURBState(phost , HID_Handle->InPipe) == USBH_URB_STALL) /* IN Endpoint Stalled */
+
+ if (urbStatus == USBH_URB_NOTREADY)
+ {
+ HID_Handle->state = HID_IDLE;
+ break;
+ }
+
+ if (urbStatus == USBH_URB_STALL)
{
-
/* Issue Clear Feature on interrupt IN endpoint */
if(USBH_ClrFeature(phost,
HID_Handle->ep_addr) == USBH_OK)
{
- /* Change state to issue next IN token */
- HID_Handle->state = HID_GET_DATA;
+ HID_Handle->state = HID_IDLE;
}
- }
-
-
+ }
break;
+
+ case HID_IDLE:
+ break;
+
default:
break;
}
- return status;
+ return USBH_OK;
}
/**
@@ -446,14 +449,11 @@ static USBH_StatusTypeDef USBH_HID_SOFProcess(USBH_HandleTypeDef *phost)
{
HID_HandleTypeDef *HID_Handle = (HID_HandleTypeDef *) phost->pActiveClass->pData;
- if(HID_Handle->state == HID_POLL)
+ if (HID_Handle->state == HID_IDLE)
{
- if(( phost->Timer - HID_Handle->timer) >= HID_Handle->poll)
+ if ((int32_t)(phost->Timer - HID_Handle->timer) >= HID_Handle->poll)
{
HID_Handle->state = HID_GET_DATA;
-#if (USBH_USE_OS == 1)
- osMessagePut ( phost->os_event, USBH_URB_EVENT, 0);
-#endif
}
}
return USBH_OK;
diff --git a/Downstream/Src/downstream_statemachine.c b/Downstream/Src/downstream_statemachine.c
index d4482cd..75ea5b3 100644
--- a/Downstream/Src/downstream_statemachine.c
+++ b/Downstream/Src/downstream_statemachine.c
@@ -190,7 +190,7 @@ void Downstream_HostUserCallback(USBH_HandleTypeDef *phost, uint8_t id)
}
//Called from main()
- if (id == HOST_USER_CLASS_ACTIVE)
+ if (id == HOST_USER_CLASS_SELECTED)
{
switch (phost->pActiveClass->ClassCode)
{
diff --git a/Downstream/Src/usb_host.c b/Downstream/Src/usb_host.c
index 442eea1..5db673e 100644
--- a/Downstream/Src/usb_host.c
+++ b/Downstream/Src/usb_host.c
@@ -38,6 +38,7 @@
#include "usb_host.h"
#include "usbh_core.h"
#include "usbh_msc.h"
+#include "usbh_hid.h"
#include "downstream_statemachine.h"
/* USB Host Core handle declaration */
@@ -51,6 +52,7 @@ void USB_Host_Init(void)
USBH_Init(&hUsbHostFS, Downstream_HostUserCallback, HOST_FS);
USBH_RegisterClass(&hUsbHostFS, USBH_MSC_CLASS);
+ USBH_RegisterClass(&hUsbHostFS, USBH_HID_CLASS);
USBH_Start(&hUsbHostFS);
}
diff --git a/Upstream/Inc/upstream_interface_def.h b/Upstream/Inc/upstream_interface_def.h
index d2366a6..f76a6df 100644
--- a/Upstream/Inc/upstream_interface_def.h
+++ b/Upstream/Inc/upstream_interface_def.h
@@ -58,7 +58,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, //Downstream initiates HID report transfer to Upstream. Upstream just needs to Upstream_ReceivePacket each time.
}
InterfaceCommandHidTypeDef;
diff --git a/Upstream/Src/upstream_hid.c b/Upstream/Src/upstream_hid.c
index cd7502f..6a48b2d 100644
--- a/Upstream/Src/upstream_hid.c
+++ b/Upstream/Src/upstream_hid.c
@@ -21,7 +21,7 @@
-InterfaceCommandClassTypeDef ActiveHidClass = COMMAND_CLASS_INTERFACE;
+InterfaceCommandClassTypeDef ActiveHidClass = COMMAND_CLASS_INTERFACE;
UpstreamPacketTypeDef* UpstreamHidPacket = NULL;
@@ -37,7 +37,8 @@ void Upstream_HID_Init(InterfaceCommandClassTypeDef newClass)
return;
}
- if (UpstreamHidPacket != NULL)
+ if ((ActiveHidClass != COMMAND_CLASS_INTERFACE) ||
+ (UpstreamHidPacket != NULL))
{
UPSTREAM_SPI_FREAKOUT;
return;
@@ -81,7 +82,7 @@ void Upstream_HID_GetNextReport(UpstreamHidSendReportCallback callback)
void Upstream_HID_GetNextReportReceiveCallback(UpstreamPacketTypeDef* receivedPacket)
{
- uint8_t reportLength;
+ uint8_t reportLength = 0;
if (UpstreamHidPacket != NULL)
{
@@ -111,7 +112,14 @@ void Upstream_HID_GetNextReportReceiveCallback(UpstreamPacketTypeDef* receivedPa
//Other HID classes go here...
+ if (reportLength == 0)
+ {
+ UPSTREAM_SPI_FREAKOUT;
+ return;
+ }
+
UpstreamHidPacket = receivedPacket; //Save packet so we can free it when upstream USB transaction is done
USBD_HID_SendReport(receivedPacket->Data, reportLength);
}
+
diff --git a/Upstream/Src/upstream_statemachine.c b/Upstream/Src/upstream_statemachine.c
index 1f1fdbe..0b38360 100644
--- a/Upstream/Src/upstream_statemachine.c
+++ b/Upstream/Src/upstream_statemachine.c
@@ -176,11 +176,11 @@ void Upstream_StateMachine_NotifyDeviceReplyCallback(UpstreamPacketTypeDef* repl
break;
case COMMAND_CLASS_HID_MOUSE:
- newActiveClass = COMMAND_CLASS_HID_MOUSE;
- newClassPointer = &USBD_HID_Mouse;
- break;
+ newActiveClass = COMMAND_CLASS_HID_MOUSE;
+ newClassPointer = &USBD_HID_Mouse;
+ break;
- //Add other supported classes here...
+ //Add other supported classes here...
}
Upstream_ReleasePacket(replyPacket);