Skip to content

Commit

Permalink
Merge pull request #300 from TheTechnobear/master
Browse files Browse the repository at this point in the history
change usbh_core.c stm host lib, so it skips non supported interfaces
  • Loading branch information
axoloti committed Mar 31, 2016
2 parents ba49a5e + 36f8a98 commit 5b96816
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 16 deletions.
40 changes: 25 additions & 15 deletions firmware/STM32_USB_Host_Library/Core/Src/usbh_core.c
Expand Up @@ -525,13 +525,26 @@ USBH_StatusTypeDef USBH_Process(USBH_HandleTypeDef *phost)
else
{
phost->pActiveClass = NULL;
bool bFound = false;

for (idx = 0; idx < USBH_MAX_NUM_SUPPORTED_CLASS ; idx ++)
USBH_StatusTypeDef initStatus = USBH_NOT_SUPPORTED;
for (idx = 0; idx < USBH_MAX_NUM_SUPPORTED_CLASS && !bFound; idx ++)
{
for (intf = 0; intf < phost->device.CfgDesc.bNumInterfaces; intf ++) {
for (intf = 0; intf < phost->device.CfgDesc.bNumInterfaces && !bFound; intf ++) {
if(phost->pClass[idx]->ClassCode == phost->device.CfgDesc.Itf_Desc[intf].bInterfaceClass)
{
phost->pActiveClass = phost->pClass[idx];
initStatus = phost->pActiveClass->Init(phost);
if (initStatus == USBH_OK) {
bFound = true;
} else if (initStatus == USBH_NOT_SUPPORTED) {
// its not supported by this class, try others
phost->pActiveClass = NULL;
}
else {
// failed to start
bFound = true;
}
break;
}
}
Expand All @@ -540,19 +553,16 @@ USBH_StatusTypeDef USBH_Process(USBH_HandleTypeDef *phost)

if(phost->pActiveClass != NULL)
{
if(phost->pActiveClass->Init(phost)== USBH_OK)
{
phost->gState = HOST_CLASS_REQUEST;
USBH_UsrLog ("%s class started.", phost->pActiveClass->Name);

/* Inform user that a class has been activated */
phost->pUser(phost, HOST_USER_CLASS_SELECTED);
}
else
{
phost->gState = HOST_ABORT_STATE;
USBH_UsrLog ("Device not supporting %s class.", phost->pActiveClass->Name);
}
if (initStatus == USBH_OK) {
phost->gState = HOST_CLASS_REQUEST;
USBH_UsrLog ("%s class started.", phost->pActiveClass->Name);

/* Inform user that a class has been activated */
phost->pUser(phost, HOST_USER_CLASS_SELECTED);
} else {
phost->gState = HOST_ABORT_STATE;
USBH_UsrLog ("%s class failed to init", phost->pActiveClass->Name);
}
}
else
{
Expand Down
2 changes: 1 addition & 1 deletion firmware/usbh_vendor.c
Expand Up @@ -37,7 +37,7 @@ USBH_ClassTypeDef Vendor_Class = {

static USBH_StatusTypeDef USBH_Vendor_InterfaceInit(USBH_HandleTypeDef *phost) {

USBH_StatusTypeDef status = USBH_FAIL;
USBH_StatusTypeDef status = USBH_NOT_SUPPORTED;

if(phost->device.DevDesc.idVendor == USB_ACCESS_VID && phost->device.DevDesc.idProduct == USB_VIRUS_PID) {
USBH_UsrLog("USB Access Virus detected");
Expand Down

0 comments on commit 5b96816

Please sign in to comment.