/*! * @brief cdc open control interface. * * @param cdcInstance cdc instance pointer. * * @return kStatus_USB_Success or error codes. */ static usb_status_t USB_HostCdcOpenControlInterface(usb_host_cdc_instance_struct_t *cdcInstance) { usb_status_t status; uint8_t ep_index = 0; usb_host_pipe_init_t pipeInit; usb_descriptor_endpoint_t *ep_desc = NULL; usb_host_interface_t *interfaceHandle; if (cdcInstance->interruptPipe != NULL) { status = USB_HostCancelTransfer(cdcInstance->hostHandle, cdcInstance->interruptPipe, NULL); status = USB_HostClosePipe(cdcInstance->hostHandle, cdcInstance->interruptPipe); if (status != kStatus_USB_Success) { #ifdef HOST_ECHO usb_echo("error when close pipe\r\n"); #endif } cdcInstance->interruptPipe = NULL; } status = USB_HostOpenDeviceInterface(cdcInstance->deviceHandle, cdcInstance->controlInterfaceHandle); /* open interface pipes */ interfaceHandle = (usb_host_interface_t *)cdcInstance->controlInterfaceHandle; for (ep_index = 0; ep_index < interfaceHandle->epCount; ++ep_index) { ep_desc = interfaceHandle->epList[ep_index].epDesc; if (((ep_desc->bEndpointAddress & USB_DESCRIPTOR_ENDPOINT_ADDRESS_DIRECTION_MASK) == USB_DESCRIPTOR_ENDPOINT_ADDRESS_DIRECTION_IN) && ((ep_desc->bmAttributes & USB_DESCRIPTOR_ENDPOINT_ATTRIBUTE_TYPE_MASK) == USB_ENDPOINT_INTERRUPT)) { pipeInit.devInstance = cdcInstance->deviceHandle; pipeInit.pipeType = USB_ENDPOINT_INTERRUPT; pipeInit.direction = USB_IN; pipeInit.endpointAddress = (ep_desc->bEndpointAddress & USB_DESCRIPTOR_ENDPOINT_ADDRESS_NUMBER_MASK); pipeInit.interval = ep_desc->bInterval; pipeInit.maxPacketSize = (uint16_t)(USB_SHORT_FROM_LITTLE_ENDIAN_ADDRESS(ep_desc->wMaxPacketSize) & USB_DESCRIPTOR_ENDPOINT_MAXPACKETSIZE_SIZE_MASK); pipeInit.numberPerUframe = (USB_SHORT_FROM_LITTLE_ENDIAN_ADDRESS(ep_desc->wMaxPacketSize) & USB_DESCRIPTOR_ENDPOINT_MAXPACKETSIZE_MULT_TRANSACTIONS_MASK); pipeInit.nakCount = USB_HOST_CONFIG_MAX_NAK; cdcInstance->packetSize = pipeInit.maxPacketSize; status = USB_HostOpenPipe(cdcInstance->hostHandle, &cdcInstance->interruptPipe, &pipeInit); if (status != kStatus_USB_Success) { #ifdef HOST_ECHO usb_echo("USB_HostCdcSetControlInterface fail to open pipe\r\n"); #endif return kStatus_USB_Error; } } } return kStatus_USB_Success; }
usb_status_t USB_HostHelperGetPeripheralInformation(usb_device_handle deviceHandle, uint32_t infoCode, uint32_t *infoValue) { usb_host_device_instance_t *deviceInstance = (usb_host_device_instance_t *)deviceHandle; if ((deviceHandle == NULL) || (infoValue == NULL)) { return kStatus_USB_InvalidParameter; } switch (infoCode) { case kUSB_HostGetDeviceAddress: /* device address */ *infoValue = (uint32_t)deviceInstance->setAddress; break; case kUSB_HostGetDeviceControlPipe: /* device control pipe */ *infoValue = (uint32_t)deviceInstance->controlPipe; break; case kUSB_HostGetHostHandle: /* device host handle */ *infoValue = (uint32_t)deviceInstance->hostHandle; break; #if ((defined USB_HOST_CONFIG_HUB) && (USB_HOST_CONFIG_HUB)) case kUSB_HostGetDeviceHubNumber: /* device hub address */ *infoValue = (uint32_t)deviceInstance->hubNumber; break; case kUSB_HostGetDevicePortNumber: /* device port no */ *infoValue = (uint32_t)deviceInstance->portNumber; break; case kUSB_HostGetDeviceLevel: /* device level */ *infoValue = (uint32_t)deviceInstance->level; break; case kUSB_HostGetDeviceHSHubNumber: /* device high-speed hub address */ *infoValue = (uint32_t)deviceInstance->hsHubNumber; break; case kUSB_HostGetDeviceHSHubPort: /* device high-speed hub port no */ *infoValue = (uint32_t)deviceInstance->hsHubPort; break; case kUSB_HostGetHubThinkTime: /* device hub think time */ *infoValue = USB_HostHubGetTotalThinkTime(deviceInstance->hostHandle, deviceInstance->hubNumber); break; #else case kUSB_HostGetDeviceHubNumber: /* device hub address */ case kUSB_HostGetDevicePortNumber: /* device port no */ case kUSB_HostGetDeviceHSHubNumber: /* device high-speed hub address */ case kUSB_HostGetDeviceHSHubPort: /* device high-speed hub port no */ case kUSB_HostGetHubThinkTime: /* device hub think time */ *infoValue = 0; break; case kUSB_HostGetDeviceLevel: /* device level */ *infoValue = 1; break; #endif /* USB_HOST_CONFIG_HUB */ case kUSB_HostGetDeviceSpeed: /* device speed */ *infoValue = (uint32_t)deviceInstance->speed; break; case kUSB_HostGetDevicePID: /* device pid */ *infoValue = (uint32_t)USB_SHORT_FROM_LITTLE_ENDIAN_ADDRESS(deviceInstance->deviceDescriptor->idProduct); break; case kUSB_HostGetDeviceVID: /* device vid */ *infoValue = (uint32_t)USB_SHORT_FROM_LITTLE_ENDIAN_ADDRESS(deviceInstance->deviceDescriptor->idVendor); break; case kUSB_HostGetDeviceConfigIndex: /* device config index */ *infoValue = (uint32_t)deviceInstance->configurationValue - 1U; break; case kUSB_HostGetConfigurationDes: /* configuration descriptor pointer */ *infoValue = (uint32_t)deviceInstance->configurationDesc; break; case kUSB_HostGetConfigurationLength: /* configuration descriptor length */ *infoValue = (uint32_t)deviceInstance->configurationLen; break; default: return kStatus_USB_Error; } return kStatus_USB_Success; }