/** * @brief USBH_ADK_configAndroid * Setup bulk transfer endpoint and open channel. * @param pdev: Selected device * @param hdev: Selected device property * @retval USBH_StatusTypeDef */ static USBH_StatusTypeDef USBH_AOA_ConfigEndpoints(USBH_HandleTypeDef * phost) { AOA_HandleTypeDef* aoa = phost->pActiveClass->pData; USBH_UsrLog("AOA: Configure bulk endpoint."); if (phost->device.CfgDesc.Itf_Desc[0].Ep_Desc[0].bEndpointAddress & 0x80) { aoa->BulkInEp = (phost->device.CfgDesc.Itf_Desc[0].Ep_Desc[0].bEndpointAddress); aoa->BulkInEpSize = phost->device.CfgDesc.Itf_Desc[0].Ep_Desc[0].wMaxPacketSize; } else { aoa->BulkOutEp = (phost->device.CfgDesc.Itf_Desc[0].Ep_Desc[0].bEndpointAddress); aoa->BulkOutEpSize = phost->device.CfgDesc.Itf_Desc[0].Ep_Desc[0].wMaxPacketSize; } if (phost->device.CfgDesc.Itf_Desc[0].Ep_Desc[1].bEndpointAddress & 0x80) { aoa->BulkInEp = (phost->device.CfgDesc.Itf_Desc[0].Ep_Desc[1].bEndpointAddress); aoa->BulkInEpSize = phost->device.CfgDesc.Itf_Desc[0].Ep_Desc[1].wMaxPacketSize; } else { aoa->BulkOutEp = (phost->device.CfgDesc.Itf_Desc[0].Ep_Desc[1].bEndpointAddress); aoa->BulkOutEpSize = phost->device.CfgDesc.Itf_Desc[0].Ep_Desc[1].wMaxPacketSize; } aoa->hc_num_out = USBH_AllocPipe(phost, aoa->BulkOutEp); aoa->hc_num_in = USBH_AllocPipe(phost, aoa->BulkInEp); USBH_UsrLog("AOA: in pipe %d, out pipe %d", aoa->hc_num_in, aoa->hc_num_out); /* Open the new channels */ USBH_OpenPipe(phost, aoa->hc_num_out, aoa->BulkOutEp, phost->device.address, phost->device.speed, EP_TYPE_BULK, aoa->BulkOutEpSize); USBH_OpenPipe(phost, aoa->hc_num_in, aoa->BulkInEp, phost->device.address, phost->device.speed, EP_TYPE_BULK, aoa->BulkInEpSize); return USBH_OK; }
/** * @brief USBH_CDC_InterfaceInit * The function init the CDC class. * @param phost: Host handle * @retval USBH Status */ static USBH_StatusTypeDef USBH_CDC_InterfaceInit (USBH_HandleTypeDef *phost) { USBH_StatusTypeDef status = USBH_FAIL ; uint8_t interface; CDC_HandleTypeDef *CDC_Handle; interface = USBH_FindInterface(phost, COMMUNICATION_INTERFACE_CLASS_CODE, ABSTRACT_CONTROL_MODEL, COMMON_AT_COMMAND); if(interface == 0xFF) /* No Valid Interface */ { USBH_DbgLog ("Cannot Find the interface for Communication Interface Class.", phost->pActiveClass->Name); } else { USBH_SelectInterface (phost, interface); phost->pActiveClass->pData = (CDC_HandleTypeDef *)USBH_malloc (sizeof(CDC_HandleTypeDef)); CDC_Handle = (CDC_HandleTypeDef*) phost->pActiveClass->pData; /*Collect the notification endpoint address and length*/ if(phost->device.CfgDesc.Itf_Desc[interface].Ep_Desc[0].bEndpointAddress & 0x80) { CDC_Handle->CommItf.NotifEp = phost->device.CfgDesc.Itf_Desc[interface].Ep_Desc[0].bEndpointAddress; CDC_Handle->CommItf.NotifEpSize = phost->device.CfgDesc.Itf_Desc[interface].Ep_Desc[0].wMaxPacketSize; } /*Allocate the length for host channel number in*/ CDC_Handle->CommItf.NotifPipe = USBH_AllocPipe(phost, CDC_Handle->CommItf.NotifEp); /* Open pipe for Notification endpoint */ USBH_OpenPipe (phost, CDC_Handle->CommItf.NotifPipe, CDC_Handle->CommItf.NotifEp, phost->device.address, phost->device.speed, USB_EP_TYPE_INTR, CDC_Handle->CommItf.NotifEpSize); USBH_LL_SetToggle (phost, CDC_Handle->CommItf.NotifPipe, 0); interface = USBH_FindInterface(phost, DATA_INTERFACE_CLASS_CODE, RESERVED, NO_CLASS_SPECIFIC_PROTOCOL_CODE); if(interface == 0xFF) /* No Valid Interface */ { USBH_DbgLog ("Cannot Find the interface for Data Interface Class.", phost->pActiveClass->Name); } else { /*Collect the class specific endpoint address and length*/ if(phost->device.CfgDesc.Itf_Desc[interface].Ep_Desc[0].bEndpointAddress & 0x80) { CDC_Handle->DataItf.InEp = phost->device.CfgDesc.Itf_Desc[interface].Ep_Desc[0].bEndpointAddress; CDC_Handle->DataItf.InEpSize = phost->device.CfgDesc.Itf_Desc[interface].Ep_Desc[0].wMaxPacketSize; } else { CDC_Handle->DataItf.OutEp = phost->device.CfgDesc.Itf_Desc[interface].Ep_Desc[0].bEndpointAddress; CDC_Handle->DataItf.OutEpSize = phost->device.CfgDesc.Itf_Desc[interface].Ep_Desc[0].wMaxPacketSize; } if(phost->device.CfgDesc.Itf_Desc[interface].Ep_Desc[1].bEndpointAddress & 0x80) { CDC_Handle->DataItf.InEp = phost->device.CfgDesc.Itf_Desc[interface].Ep_Desc[1].bEndpointAddress; CDC_Handle->DataItf.InEpSize = phost->device.CfgDesc.Itf_Desc[interface].Ep_Desc[1].wMaxPacketSize; } else { CDC_Handle->DataItf.OutEp = phost->device.CfgDesc.Itf_Desc[interface].Ep_Desc[1].bEndpointAddress; CDC_Handle->DataItf.OutEpSize = phost->device.CfgDesc.Itf_Desc[interface].Ep_Desc[1].wMaxPacketSize; } /*Allocate the length for host channel number out*/ CDC_Handle->DataItf.OutPipe = USBH_AllocPipe(phost, CDC_Handle->DataItf.OutEp); /*Allocate the length for host channel number in*/ CDC_Handle->DataItf.InPipe = USBH_AllocPipe(phost, CDC_Handle->DataItf.InEp); /* Open channel for OUT endpoint */ USBH_OpenPipe (phost, CDC_Handle->DataItf.OutPipe, CDC_Handle->DataItf.OutEp, phost->device.address, phost->device.speed, USB_EP_TYPE_BULK, CDC_Handle->DataItf.OutEpSize); /* Open channel for IN endpoint */ USBH_OpenPipe (phost, CDC_Handle->DataItf.InPipe, CDC_Handle->DataItf.InEp, phost->device.address, phost->device.speed, USB_EP_TYPE_BULK, CDC_Handle->DataItf.InEpSize); CDC_Handle->state = CDC_IDLE_STATE; USBH_LL_SetToggle (phost, CDC_Handle->DataItf.OutPipe,0); USBH_LL_SetToggle (phost, CDC_Handle->DataItf.InPipe,0); status = USBH_OK; } } return status; }
/** * @brief USBH_HID_InterfaceInit * The function init the HID class. * @param phost: Host handle * @retval USBH Status */ static USBH_StatusTypeDef USBH_HID_InterfaceInit (USBH_HandleTypeDef *phost) { uint8_t max_ep; uint8_t num = 0; uint8_t interface; USBH_StatusTypeDef status = USBH_FAIL ; HID_HandleTypeDef *HID_Handle; interface = USBH_FindInterface(phost, phost->pActiveClass->ClassCode, HID_BOOT_CODE, 0xFF); if(interface == 0xFF) /* No Valid Interface */ { status = USBH_FAIL; USBH_DbgLog ("Cannot Find the interface for %s class.", phost->pActiveClass->Name); } else { USBH_SelectInterface (phost, interface); phost->pActiveClass->pData = (HID_HandleTypeDef *)USBH_malloc (sizeof(HID_HandleTypeDef)); HID_Handle = (HID_HandleTypeDef *) phost->pActiveClass->pData; HID_Handle->state = HID_ERROR; /*Decode Bootclass Protocol: Mouse or Keyboard*/ 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; } 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; } else { USBH_UsrLog ("Protocol not supported."); return USBH_FAIL; } HID_Handle->state = HID_INIT; HID_Handle->ctl_state = HID_REQ_INIT; HID_Handle->ep_addr = phost->device.CfgDesc.Itf_Desc[phost->device.current_interface].Ep_Desc[0].bEndpointAddress; HID_Handle->length = phost->device.CfgDesc.Itf_Desc[phost->device.current_interface].Ep_Desc[0].wMaxPacketSize; HID_Handle->poll = phost->device.CfgDesc.Itf_Desc[phost->device.current_interface].Ep_Desc[0].bInterval ; if (HID_Handle->poll < HID_MIN_POLL) { HID_Handle->poll = HID_MIN_POLL; } /* Check fo available number of endpoints */ /* Find the number of EPs in the Interface Descriptor */ /* Choose the lower number in order not to overrun the buffer allocated */ max_ep = ( (phost->device.CfgDesc.Itf_Desc[phost->device.current_interface].bNumEndpoints <= USBH_MAX_NUM_ENDPOINTS) ? phost->device.CfgDesc.Itf_Desc[phost->device.current_interface].bNumEndpoints : USBH_MAX_NUM_ENDPOINTS); /* Decode endpoint IN and OUT address from interface descriptor */ for ( ;num < max_ep; num++) { if(phost->device.CfgDesc.Itf_Desc[phost->device.current_interface].Ep_Desc[num].bEndpointAddress & 0x80) { HID_Handle->InEp = (phost->device.CfgDesc.Itf_Desc[phost->device.current_interface].Ep_Desc[num].bEndpointAddress); HID_Handle->InPipe =\ USBH_AllocPipe(phost, HID_Handle->InEp); /* Open pipe for IN endpoint */ USBH_OpenPipe (phost, HID_Handle->InPipe, HID_Handle->InEp, phost->device.address, phost->device.speed, USB_EP_TYPE_INTR, HID_Handle->length); USBH_LL_SetToggle (phost, HID_Handle->InPipe, 0); } else { HID_Handle->OutEp = (phost->device.CfgDesc.Itf_Desc[phost->device.current_interface].Ep_Desc[num].bEndpointAddress); HID_Handle->OutPipe =\ USBH_AllocPipe(phost, HID_Handle->OutEp); /* Open pipe for OUT endpoint */ USBH_OpenPipe (phost, HID_Handle->OutPipe, HID_Handle->OutEp, phost->device.address, phost->device.speed, USB_EP_TYPE_INTR, HID_Handle->length); USBH_LL_SetToggle (phost, HID_Handle->OutPipe, 0); } } status = USBH_OK; } return status; }
/** * @brief USBH_Process * Background process of the USB Core. * @param phost: Host Handle * @retval USBH Status */ USBH_StatusTypeDef USBH_Process(USBH_HandleTypeDef *phost) { __IO USBH_StatusTypeDef status = USBH_FAIL; uint8_t idx = 0; switch (phost->gState) { case HOST_IDLE : if (phost->device.is_connected) { /* Wait for 200 ms after connection */ phost->gState = HOST_DEV_WAIT_FOR_ATTACHMENT; USBH_Delay(200); USBH_LL_ResetPort(phost); #if (USBH_USE_OS == 1) osMessagePut ( phost->os_event, USBH_PORT_EVENT, 0); #endif } break; case HOST_DEV_WAIT_FOR_ATTACHMENT: break; case HOST_DEV_ATTACHED : USBH_UsrLog("USB Device Attached"); /* Wait for 100 ms after Reset */ USBH_Delay(100); phost->device.speed = USBH_LL_GetSpeed(phost); phost->gState = HOST_ENUMERATION; phost->Control.pipe_out = USBH_AllocPipe (phost, 0x00); phost->Control.pipe_in = USBH_AllocPipe (phost, 0x80); /* Open Control pipes */ USBH_OpenPipe (phost, phost->Control.pipe_in, 0x80, phost->device.address, phost->device.speed, USBH_EP_CONTROL, phost->Control.pipe_size); /* Open Control pipes */ USBH_OpenPipe (phost, phost->Control.pipe_out, 0x00, phost->device.address, phost->device.speed, USBH_EP_CONTROL, phost->Control.pipe_size); #if (USBH_USE_OS == 1) osMessagePut ( phost->os_event, USBH_PORT_EVENT, 0); #endif break; case HOST_ENUMERATION: /* Check for enumeration status */ if ( USBH_HandleEnum(phost) == USBH_OK) { /* The function shall return USBH_OK when full enumeration is complete */ USBH_UsrLog ("Enumeration done."); phost->device.current_interface = 0; if(phost->device.DevDesc.bNumConfigurations == 1) { USBH_UsrLog ("This device has only 1 configuration."); phost->gState = HOST_SET_CONFIGURATION; } else { phost->gState = HOST_INPUT; } } break; case HOST_INPUT: { /* user callback for end of device basic enumeration */ if(phost->pUser != NULL) { phost->pUser(phost, HOST_USER_SELECT_CONFIGURATION); phost->gState = HOST_SET_CONFIGURATION; #if (USBH_USE_OS == 1) osMessagePut ( phost->os_event, USBH_STATE_CHANGED_EVENT, 0); #endif } } break; case HOST_SET_CONFIGURATION: /* set configuration */ if (USBH_SetCfg(phost, phost->device.CfgDesc.bConfigurationValue) == USBH_OK) { phost->gState = HOST_CHECK_CLASS; USBH_UsrLog ("Default configuration set."); } break; case HOST_CHECK_CLASS: if(phost->ClassNumber == 0) { USBH_UsrLog ("No Class has been registered."); } else { phost->pActiveClass = NULL; for (idx = 0; idx < USBH_MAX_NUM_SUPPORTED_CLASS ; idx ++) { if(phost->pClass[idx]->ClassCode == phost->device.CfgDesc.Itf_Desc[0].bInterfaceClass) { phost->pActiveClass = phost->pClass[idx]; } } 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); } } else { phost->gState = HOST_ABORT_STATE; USBH_UsrLog ("No registered class for this device."); } } #if (USBH_USE_OS == 1) osMessagePut ( phost->os_event, USBH_STATE_CHANGED_EVENT, 0); #endif break; case HOST_CLASS_REQUEST: /* process class standard control requests state machine */ if(phost->pActiveClass != NULL) { status = phost->pActiveClass->Requests(phost); if(status == USBH_OK) { phost->gState = HOST_CLASS; } } else { phost->gState = HOST_ABORT_STATE; USBH_ErrLog ("Invalid Class Driver."); #if (USBH_USE_OS == 1) osMessagePut ( phost->os_event, USBH_STATE_CHANGED_EVENT, 0); #endif } break; case HOST_CLASS: /* process class state machine */ if(phost->pActiveClass != NULL) { phost->pActiveClass->BgndProcess(phost); } break; case HOST_DEV_DISCONNECTED : DeInitStateMachine(phost); /* Re-Initilaize Host for new Enumeration */ if(phost->pActiveClass != NULL) { phost->pActiveClass->DeInit(phost); phost->pActiveClass = NULL; } break; case HOST_ABORT_STATE: default : break; } return USBH_OK; }
/** * @brief USBH_Process * Background process of the USB Core. * @param phost: Host Handle * @retval USBH Status */ USBH_StatusTypeDef USBH_Process(USBH_HandleTypeDef *phost) { __IO USBH_StatusTypeDef status = USBH_FAIL; int reset_core = 0; uint8_t idx = 0, j; if (mapped_port_state(phost) == PORT_UP) { if (!phost->device.is_attached) { phost->gState = HOST_DEV_DISCONNECTED; } else if (phost->requestCoreReset) { phost->gState = HOST_DEV_DISCONNECTED; reset_core = 1; } } switch (phost->gState) { case HOST_IDLE : if (phost->device.is_connected) { /* Wait for 200 ms after connection */ USBH_UsrLog("."); USBH_UsrLog("."); USBH_UsrLog("."); USBH_UsrLog("Connected, delay %dms before port reset", USBH_CONNECT_DELAY); USBH_Delay(USBH_CONNECT_DELAY); /* TODO QUICK FIX: making sure Global Int is enabled, may be disabled by * unpaired port down event in hcd, ridiculous bug */ USBH_LL_Start(phost); USBH_LL_ResetPort(phost); phost->gState = HOST_DEV_WAIT_FOR_ATTACHMENT; phost->gStateTimer = HAL_GetTick(); #if (USBH_USE_OS == 1) osMessagePut ( phost->os_event, USBH_PORT_EVENT, 0); #endif } break; case HOST_DEV_WAIT_FOR_ATTACHMENT: if (!phost->device.is_connected) { // phost->device.is_connected = 0; phost->gState = HOST_IDLE; } else if (phost->device.is_attached) { phost->gState = HOST_DEV_ATTACHED; } else if (HAL_GetTick() - phost->gStateTimer > 1000) { // phost->device.is_connected = 0; phost->gState = HOST_IDLE; } break; case HOST_DEV_ATTACHED : if (!phost->device.is_connected) { // phost->device.is_connected = 0; phost->gState = HOST_IDLE; } USBH_UsrLog("USB Device Attached"); /* Wait for 100 ms after Reset */ USBH_Delay(100); phost->device.speed = USBH_LL_GetSpeed(phost); phost->gState = HOST_ENUMERATION; phost->Control.pipe_out = USBH_AllocPipe (phost, 0x00); phost->Control.pipe_in = USBH_AllocPipe (phost, 0x80); /* Open Control pipes */ USBH_OpenPipe (phost, phost->Control.pipe_in, 0x80, phost->device.address, phost->device.speed, USBH_EP_CONTROL, phost->Control.pipe_size); /* Open Control pipes */ USBH_OpenPipe (phost, phost->Control.pipe_out, 0x00, phost->device.address, phost->device.speed, USBH_EP_CONTROL, phost->Control.pipe_size); /* do this here, instead in interrupt context **/ if (phost->pUser != NULL) { phost->pUser(phost, HOST_USER_CONNECTION); } #if (USBH_USE_OS == 1) osMessagePut ( phost->os_event, USBH_PORT_EVENT, 0); #endif break; case HOST_ENUMERATION: /* Check for enumeration status */ if ( USBH_HandleEnum(phost) == USBH_OK) { /* The function shall return USBH_OK when full enumeration is complete */ USBH_UsrLog ("Enumeration done."); USBH_Print_DeviceDescriptor(phost); phost->device.current_interface = 0; if(phost->device.DevDesc.bNumConfigurations == 1) { USBH_UsrLog ("This device has only 1 configuration."); phost->gState = HOST_SET_CONFIGURATION; } else { phost->gState = HOST_INPUT; } } break; case HOST_INPUT: { /* user callback for end of device basic enumeration */ if(phost->pUser != NULL) { phost->pUser(phost, HOST_USER_SELECT_CONFIGURATION); phost->gState = HOST_SET_CONFIGURATION; #if (USBH_USE_OS == 1) osMessagePut ( phost->os_event, USBH_STATE_CHANGED_EVENT, 0); #endif } } break; case HOST_SET_CONFIGURATION: /* set configuration */ if (USBH_SetCfg(phost, phost->device.CfgDesc.bConfigurationValue) == USBH_OK) { phost->gState = HOST_CHECK_CLASS; USBH_UsrLog ("Default configuration set."); } break; case HOST_CHECK_CLASS: if(phost->ClassNumber == 0) { USBH_UsrLog ("No Class has been registered."); phost->AbortReason = ABORT_NOCLASS_REGISTERED; phost->gState = HOST_ABORT_STATE; } else { phost->pActiveClass = NULL; // for (idx = 0; idx < USBH_MAX_NUM_SUPPORTED_CLASS ; idx ++) for (idx = 0; idx < phost->ClassNumber; idx++) { // search all interfaces, not only interface 0 for (j = 0; j < phost->device.CfgDesc.bNumInterfaces; j++) { if (phost->pClass[idx]->ClassCode == phost->device.CfgDesc.Itf_Desc[j].bInterfaceClass) { phost->pActiveClass = phost->pClass[idx]; USBH_UsrLog( "Registered %s class with code 0x%02x matches interface #%d", phost->pClass[idx]->Name, phost->pClass[idx]->ClassCode, j); break; } } if (phost->pActiveClass != NULL) break; } 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->AbortReason = ABORT_CLASSINIT_FAIL; phost->gState = HOST_ABORT_STATE; USBH_UsrLog ("Device not supporting %s class.", phost->pActiveClass->Name); phost->pActiveClass = NULL; } } else { phost->AbortReason = ABORT_NOCLASS_MATCH; phost->gState = HOST_ABORT_STATE; USBH_UsrLog ("No registered class for this device."); } } #if (USBH_USE_OS == 1) osMessagePut ( phost->os_event, USBH_STATE_CHANGED_EVENT, 0); #endif break; case HOST_CLASS_REQUEST: /* process class standard control requests state machine */ if(phost->pActiveClass != NULL) { /* as long as pActiveClass is set, this state is */ status = phost->pActiveClass->Requests(phost); if(status == USBH_OK) { phost->gState = HOST_CLASS; } else if (status == USBH_FAIL || status == USBH_NOT_SUPPORTED) { phost->pActiveClass->DeInit(phost); phost->pActiveClass = NULL; phost->AbortReason = ABORT_CLASSREQUEST_FAIL; phost->gState = HOST_ABORT_STATE; USBH_ErrLog("Class Request fail.") } }
/** * @brief USBH_MTP_InterfaceInit * The function init the MTP class. * @param phost: Host handle * @retval USBH Status */ static USBH_StatusTypeDef USBH_MTP_InterfaceInit (USBH_HandleTypeDef *phost) { USBH_StatusTypeDef status = USBH_OK ; uint8_t interface, endpoint; MTP_HandleTypeDef *MTP_Handle; interface = USBH_FindInterface(phost, USB_MTP_CLASS, 1, 1); if(interface == 0xFF) /* No Valid Interface */ { status = USBH_FAIL; USBH_DbgLog ("Cannot Find the interface for Still Image Class."); } else { USBH_SelectInterface (phost, interface); endpoint = MTP_FindCtlEndpoint(phost); phost->pActiveClass->pData = (MTP_HandleTypeDef *)USBH_malloc (sizeof(MTP_HandleTypeDef)); MTP_Handle = phost->pActiveClass->pData; if( MTP_Handle == NULL) { status = USBH_FAIL; USBH_DbgLog ("Cannot allocate RAM for MTP Handle"); } /*Collect the control endpoint address and length*/ MTP_Handle->NotificationEp = phost->device.CfgDesc.Itf_Desc[interface].Ep_Desc[endpoint].bEndpointAddress; MTP_Handle->NotificationEpSize = phost->device.CfgDesc.Itf_Desc[interface].Ep_Desc[endpoint].wMaxPacketSize; MTP_Handle->NotificationPipe = USBH_AllocPipe(phost, MTP_Handle->NotificationEp); MTP_Handle->events.poll = phost->device.CfgDesc.Itf_Desc[interface].Ep_Desc[endpoint].bInterval; /* Open pipe for Notification endpoint */ USBH_OpenPipe (phost, MTP_Handle->NotificationPipe, MTP_Handle->NotificationEp, phost->device.address, phost->device.speed, USB_EP_TYPE_INTR, MTP_Handle->NotificationEpSize); USBH_LL_SetToggle (phost, MTP_Handle->NotificationPipe, 0); endpoint = MTP_FindDataInEndpoint(phost); /*Collect the control endpoint address and length*/ MTP_Handle->DataInEp = phost->device.CfgDesc.Itf_Desc[interface].Ep_Desc[endpoint].bEndpointAddress; MTP_Handle->DataInEpSize = phost->device.CfgDesc.Itf_Desc[interface].Ep_Desc[endpoint].wMaxPacketSize; MTP_Handle->DataInPipe = USBH_AllocPipe(phost, MTP_Handle->DataInEp); /* Open pipe for DATA IN endpoint */ USBH_OpenPipe (phost, MTP_Handle->DataInPipe, MTP_Handle->DataInEp, phost->device.address, phost->device.speed, USB_EP_TYPE_BULK, MTP_Handle->DataInEpSize); USBH_LL_SetToggle (phost, MTP_Handle->DataInPipe, 0); endpoint = MTP_FindDataOutEndpoint(phost); /*Collect the DATA OUT endpoint address and length*/ MTP_Handle->DataOutEp = phost->device.CfgDesc.Itf_Desc[interface].Ep_Desc[endpoint].bEndpointAddress; MTP_Handle->DataOutEpSize = phost->device.CfgDesc.Itf_Desc[interface].Ep_Desc[endpoint].wMaxPacketSize; MTP_Handle->DataOutPipe = USBH_AllocPipe(phost, MTP_Handle->DataOutEp); /* Open pipe for DATA OUT endpoint */ USBH_OpenPipe (phost, MTP_Handle->DataOutPipe, MTP_Handle->DataOutEp, phost->device.address, phost->device.speed, USB_EP_TYPE_BULK, MTP_Handle->DataOutEpSize); USBH_LL_SetToggle (phost, MTP_Handle->DataOutPipe, 0); MTP_Handle->state = MTP_OPENSESSION; MTP_Handle->is_ready = 0; MTP_Handle->events.state = MTP_EVENTS_INIT; return USBH_PTP_Init(phost); } return status; }
/** * @brief USBH_MSC_InterfaceInit * The function init the MSC class. * @param phost: Host handle * @retval USBH Status */ static USBH_StatusTypeDef USBH_MSC_InterfaceInit (USBH_HandleTypeDef *phost) { uint8_t interface = 0; USBH_StatusTypeDef status = USBH_FAIL ; MSC_HandleTypeDef *MSC_Handle; interface = USBH_FindInterface(phost, phost->pActiveClass->ClassCode, MSC_TRANSPARENT, MSC_BOT); if(interface == 0xFF) /* Not Valid Interface */ { USBH_DbgLog ("Cannot Find the interface for %s class.", phost->pActiveClass->Name); status = USBH_FAIL; } else { USBH_SelectInterface (phost, interface); phost->pActiveClass->pData = (MSC_HandleTypeDef *)USBH_malloc (sizeof(MSC_HandleTypeDef)); MSC_Handle = (MSC_HandleTypeDef *) phost->pActiveClass->pData; if(phost->device.CfgDesc.Itf_Desc[phost->device.current_interface].Ep_Desc[0].bEndpointAddress & 0x80) { MSC_Handle->InEp = (phost->device.CfgDesc.Itf_Desc[phost->device.current_interface].Ep_Desc[0].bEndpointAddress); MSC_Handle->InEpSize = phost->device.CfgDesc.Itf_Desc[phost->device.current_interface].Ep_Desc[0].wMaxPacketSize; } else { MSC_Handle->OutEp = (phost->device.CfgDesc.Itf_Desc[phost->device.current_interface].Ep_Desc[0].bEndpointAddress); MSC_Handle->OutEpSize = phost->device.CfgDesc.Itf_Desc[phost->device.current_interface].Ep_Desc[0].wMaxPacketSize; } if(phost->device.CfgDesc.Itf_Desc[phost->device.current_interface].Ep_Desc[1].bEndpointAddress & 0x80) { MSC_Handle->InEp = (phost->device.CfgDesc.Itf_Desc[phost->device.current_interface].Ep_Desc[1].bEndpointAddress); MSC_Handle->InEpSize = phost->device.CfgDesc.Itf_Desc[phost->device.current_interface].Ep_Desc[1].wMaxPacketSize; } else { MSC_Handle->OutEp = (phost->device.CfgDesc.Itf_Desc[phost->device.current_interface].Ep_Desc[1].bEndpointAddress); MSC_Handle->OutEpSize = phost->device.CfgDesc.Itf_Desc[phost->device.current_interface].Ep_Desc[1].wMaxPacketSize; } MSC_Handle->current_lun = 0; MSC_Handle->rw_lun = 0; MSC_Handle->state = MSC_INIT; MSC_Handle->error = MSC_OK; MSC_Handle->req_state = MSC_REQ_IDLE; MSC_Handle->OutPipe = USBH_AllocPipe(phost, MSC_Handle->OutEp); MSC_Handle->InPipe = USBH_AllocPipe(phost, MSC_Handle->InEp); USBH_MSC_BOT_Init(phost); /* De-Initialize LUNs information */ USBH_memset(MSC_Handle->unit, 0, sizeof(MSC_Handle->unit)); /* Open the new channels */ USBH_OpenPipe (phost, MSC_Handle->OutPipe, MSC_Handle->OutEp, phost->device.address, phost->device.speed, USB_EP_TYPE_BULK, MSC_Handle->OutEpSize); USBH_OpenPipe (phost, MSC_Handle->InPipe, MSC_Handle->InEp, phost->device.address, phost->device.speed, USB_EP_TYPE_BULK, MSC_Handle->InEpSize); USBH_LL_SetToggle (phost, MSC_Handle->InPipe,0); USBH_LL_SetToggle (phost, MSC_Handle->OutPipe,0); status = USBH_OK; } return status; }