/*! * @brief Initialize the common class and the supported classes. * * This function is used to initialize the common class and the supported classes. * * @param[in] controllerId The controller id of the USB IP. Please refer to the enumeration #usb_controller_index_t. * @param[in] configList The class configurations. The pointer must point to the goblal variable. * Please refer to the structure #usb_device_class_config_list_struct_t. * @param[out] handle It is out parameter, is used to return pointer of the device handle to the caller. * The value of parameter is a pointer points the device handle, and this design is uesd to * make simple device align with composite device. For composite device, there are many * kinds of class handle, but there is only one device handle. So the handle points to * a device instead of a class. And the class handle can be got from the * #usb_device_class_config_struct_t::classHandle after the the function successfully. * * @return A USB error code or kStatus_USB_Success. */ usb_status_t USB_DeviceClassInit( uint8_t controllerId, /*!< [IN] Controller ID */ usb_device_class_config_list_struct_t *configList, /*!< [IN] Pointer to class configuration list */ usb_device_handle *handle /*!< [OUT] Pointer to the device handle */ ) { usb_device_common_class_struct_t *classHandle; usb_status_t error = kStatus_USB_Error; uint8_t mapIndex; uint8_t classIndex; if ((NULL == handle) || (NULL == configList) || ((usb_device_callback_t)NULL == configList->deviceCallback)) { return kStatus_USB_InvalidParameter; } /* Allocate a common class driver handle. */ error = USB_DeviceClassAllocateHandle(controllerId, &classHandle); if (kStatus_USB_Success != error) { return error; } /* Save the configuration list */ classHandle->configList = configList; /* Initialize the device stack. */ error = USB_DeviceInit(controllerId, USB_DeviceClassCallback, &classHandle->handle); if (kStatus_USB_Success != error) { USB_DeviceDeinit(classHandle->handle); USB_DeviceClassFreeHandle(controllerId); return error; } /* Initialize the all supported classes according to the configuration list. */ for (classIndex = 0U; classIndex < classHandle->configList->count; classIndex++) { for (mapIndex = 0U; mapIndex < (sizeof(s_UsbDeviceClassInterfaceMap) / sizeof(usb_device_class_map_t)); mapIndex++) { if (classHandle->configList->config[classIndex].classInfomation->type == s_UsbDeviceClassInterfaceMap[mapIndex].type) { (void)s_UsbDeviceClassInterfaceMap[mapIndex].classInit( controllerId, &classHandle->configList->config[classIndex], &classHandle->configList->config[classIndex].classHandle); } } } *handle = classHandle->handle; return error; }
/* See virtual_com.h for documentation of this function. */ void USB_VcomDeinit(usb_device_handle deviceHandle) { USB_DeviceStop(deviceHandle); USB_DeviceDeinit(deviceHandle); s_cdcVcom.deviceHandle = NULL; #if defined(USB_DEVICE_CONFIG_EHCI) && (USB_DEVICE_CONFIG_EHCI > 0) USB_EhciPhyDeinit(CONTROLLER_ID); #endif #if defined(USB_DEVICE_CONFIG_KHCI) && (USB_DEVICE_CONFIG_KHCI > 0) CLOCK_DisableUsbfs0Clock(); #endif #if defined(USB_DEVICE_CONFIG_LPCIP3511FS) && (USB_DEVICE_CONFIG_LPCIP3511FS > 0U) /* enable USB IP clock, user code. */ CLOCK_DisableClock(kCLOCK_Usbd0); #endif /* USB_DEVICE_CONFIG_LPCIP3511FS */ #if defined(USB_DEVICE_CONFIG_LPCIP3511HS) && (USB_DEVICE_CONFIG_LPCIP3511HS > 0U) /* enable USB IP clock,user code. */ #endif /* USB_DEVICE_CONFIG_LPCIP3511HS */ }
/*! * @brief De-initialize the common class and the supported classes. * * This function is used to de-initialize the common class and the supported classes. * * @param controllerId The controller id of the USB IP. Please refer to the enumeration usb_controller_index_t. * * @return A USB error code or kStatus_USB_Success. */ usb_status_t USB_DeviceClassDeinit(uint8_t controllerId /*!< [IN] Controller ID */ ) { usb_device_common_class_struct_t *classHandle; usb_status_t error = kStatus_USB_Error; uint8_t mapIndex; uint8_t classIndex; /* Get the common class handle according to the controller id. */ error = USB_DeviceClassGetHandleByControllerId(controllerId, &classHandle); if (kStatus_USB_Success != error) { return error; } /* De-initialize the all supported classes according to the configuration list. */ for (classIndex = 0U; classIndex < classHandle->configList->count; classIndex++) { for (mapIndex = 0U; mapIndex < (sizeof(s_UsbDeviceClassInterfaceMap) / sizeof(usb_device_class_map_t)); mapIndex++) { if (classHandle->configList->config[classIndex].classInfomation->type == s_UsbDeviceClassInterfaceMap[mapIndex].type) { (void)s_UsbDeviceClassInterfaceMap[mapIndex].classDeinit( classHandle->configList->config[classIndex].classHandle); } } } /* De-initialize the USB device stack. */ error = USB_DeviceDeinit(classHandle->handle); if (kStatus_USB_Success == error) { /* Free the common class handle. */ (void)USB_DeviceClassFreeHandle(controllerId); } return error; }