/*! * @brief cdc setControlLineState. * * This function implements cdc etControlLineState request.refer to pstn spec. * * @param classHandle the class handle. * @param buffer the buffer pointer. * @param bufferLength the buffer length. * @param callbackFn this callback is called after this function completes. * @param callbackParam the first parameter in the callback function. * * @retval kStatus_USB_Success request successfully. * @retval kStatus_USB_InvalidHandle The classHandle is NULL pointer. * @retval kStatus_USB_Busy There is no idle transfer. * @retval kStatus_USB_Error send transfer fail, please reference to USB_HostSendSetup. */ usb_status_t USB_HostCdcSetAcmCtrlState( usb_host_class_handle classHandle, uint8_t dtr, uint8_t rts, transfer_callback_t callbackFn, void *callbackParam) { uint16_t lineState = 0; usb_host_cdc_instance_struct_t *cdcInstance = (usb_host_cdc_instance_struct_t *)classHandle; lineState = dtr ? USB_HOST_CDC_CONTROL_LINE_STATE_DTR : 0; lineState |= rts ? USB_HOST_CDC_CONTROL_LINE_STATE_RTS : 0; return USB_HostCdcControl( cdcInstance, USB_REQUEST_TYPE_DIR_OUT | USB_REQUEST_TYPE_TYPE_CLASS | USB_REQUEST_TYPE_RECIPIENT_INTERFACE, USB_HOST_CDC_SET_CONTROL_LINE_STATE, USB_SHORT_GET_LOW(lineState), USB_SHORT_GET_HIGH(lineState), 0, NULL, callbackFn, callbackParam); }
/* Due to the difference of HS and FS descriptors, the device descriptors and configurations need to be updated to match * current speed. * As the default, the device descriptors and configurations are configured by using FS parameters for both EHCI and * KHCI. * When the EHCI is enabled, the application needs to call this fucntion to update device by using current speed. * The updated information includes endpoint max packet size, endpoint interval, etc. */ usb_status_t USB_DeviceSetSpeed(usb_device_handle handle, uint8_t speed) { usb_descriptor_union_t *descriptorHead; usb_descriptor_union_t *descriptorTail; descriptorHead = (usb_descriptor_union_t *)&g_UsbDeviceConfigurationDescriptor[0]; descriptorTail = (usb_descriptor_union_t *)(&g_UsbDeviceConfigurationDescriptor[USB_DESCRIPTOR_LENGTH_CONFIGURATION_ALL - 1]); while (descriptorHead < descriptorTail) { if (descriptorHead->endpoint.bDescriptorType == USB_DESCRIPTOR_TYPE_ENDPOINT) { if (USB_SPEED_HIGH == speed) { if (descriptorHead->endpoint.bEndpointAddress & USB_DESCRIPTOR_ENDPOINT_ADDRESS_DIRECTION_MASK) { descriptorHead->endpoint.wMaxPacketSize[0] = USB_SHORT_GET_LOW(HS_MSC_BULK_IN_PACKET_SIZE); descriptorHead->endpoint.wMaxPacketSize[1] = USB_SHORT_GET_HIGH(HS_MSC_BULK_IN_PACKET_SIZE); } else { descriptorHead->endpoint.wMaxPacketSize[0] = USB_SHORT_GET_LOW(HS_MSC_BULK_OUT_PACKET_SIZE); descriptorHead->endpoint.wMaxPacketSize[1] = USB_SHORT_GET_HIGH(HS_MSC_BULK_OUT_PACKET_SIZE); } } else { if (descriptorHead->endpoint.bEndpointAddress & USB_DESCRIPTOR_ENDPOINT_ADDRESS_DIRECTION_MASK) { descriptorHead->endpoint.wMaxPacketSize[0] = USB_SHORT_GET_LOW(FS_MSC_BULK_IN_PACKET_SIZE); descriptorHead->endpoint.wMaxPacketSize[1] = USB_SHORT_GET_HIGH(FS_MSC_BULK_IN_PACKET_SIZE); } else { descriptorHead->endpoint.wMaxPacketSize[0] = USB_SHORT_GET_LOW(FS_MSC_BULK_OUT_PACKET_SIZE); descriptorHead->endpoint.wMaxPacketSize[1] = USB_SHORT_GET_HIGH(FS_MSC_BULK_OUT_PACKET_SIZE); } } } descriptorHead = (usb_descriptor_union_t *)((uint8_t *)descriptorHead + descriptorHead->common.bLength); } for (int i = 0; i < USB_MSC_ENDPOINT_COUNT; i++) { if (USB_SPEED_HIGH == speed) { if ((USB_IN << USB_DESCRIPTOR_ENDPOINT_ADDRESS_DIRECTION_SHIFT) == (g_UsbDeviceMscEndpoints[i].endpointAddress & USB_DESCRIPTOR_ENDPOINT_ADDRESS_DIRECTION_MASK)) { g_UsbDeviceMscEndpoints[i].maxPacketSize = HS_MSC_BULK_IN_PACKET_SIZE; } else { g_UsbDeviceMscEndpoints[i].maxPacketSize = HS_MSC_BULK_OUT_PACKET_SIZE; } } else { if ((USB_IN << USB_DESCRIPTOR_ENDPOINT_ADDRESS_DIRECTION_SHIFT) == (g_UsbDeviceMscEndpoints[i].endpointAddress & USB_DESCRIPTOR_ENDPOINT_ADDRESS_DIRECTION_MASK)) { g_UsbDeviceMscEndpoints[i].maxPacketSize = FS_MSC_BULK_IN_PACKET_SIZE; } else { g_UsbDeviceMscEndpoints[i].maxPacketSize = FS_MSC_BULK_OUT_PACKET_SIZE; } } } return kStatus_USB_Success; }
USB_MSC_INTERFACE_COUNT, /* The interface count of the msc */ g_UsbDeviceMscInterfaces, /* The interfaces handle */ }, }; usb_device_class_struct_t g_UsbDeviceMscConfig = { g_UsbDeviceMscInterfaceList, /* The interface list of the msc */ kUSB_DeviceClassTypeMsc, /* The msc class type */ USB_CONFIGURE_COUNT, /* The configuration count */ }; uint8_t g_UsbDeviceDescriptor[USB_DESCRIPTOR_LENGTH_DEVICE] = { USB_DESCRIPTOR_LENGTH_DEVICE, /* Size of this descriptor in bytes */ USB_DESCRIPTOR_TYPE_DEVICE, /* DEVICE Descriptor Type */ USB_SHORT_GET_LOW(USB_DEVICE_SPECIFIC_BCD_VERSION), USB_SHORT_GET_HIGH(USB_DEVICE_SPECIFIC_BCD_VERSION), /* USB Specification Release Number in Binary-Coded Decimal (i.e., 2.10 is 210H). */ USB_DEVICE_CLASS, /* Class code (assigned by the USB-IF). */ USB_DEVICE_SUBCLASS, /* Subclass code (assigned by the USB-IF). */ USB_DEVICE_PROTOCOL, /* Protocol code (assigned by the USB-IF). */ USB_CONTROL_MAX_PACKET_SIZE, /* Maximum packet size for endpoint zero (only 8, 16, 32, or 64 are valid) */ 0xa2U, 0x15U, /* Vendor ID (assigned by the USB-IF) */ 0x00U, 0x02U, /* Product ID (assigned by the manufacturer) */ USB_SHORT_GET_LOW(USB_DEVICE_DEMO_BCD_VERSION), USB_SHORT_GET_HIGH(USB_DEVICE_DEMO_BCD_VERSION), /* Device release number in binary-coded decimal */ 0x01U, /* Index of string descriptor describing manufacturer */ 0x02U, /* Index of string descriptor describing product */ 0x03U, /* Index of string descriptor describing the device's serial number */ USB_CONFIGURE_COUNT, /* Number of possible configurations */
{ USB_HID_MOUSE_INTERFACE_COUNT, /* The interface count of the HID mouse */ g_UsbDeviceHidMouseInterfaces, /* The interfaces handle */ }, }; usb_device_class_struct_t g_UsbDeviceHidMouseConfig = { g_UsbDeviceHidMouseInterfaceList, /* The interface list of the HID mouse */ kUSB_DeviceClassTypeHid, /* The HID class type */ USB_DEVICE_CONFIGURATION_COUNT, /* The configuration count */ }; uint8_t g_UsbDeviceDescriptor[USB_DESCRIPTOR_LENGTH_DEVICE] = { USB_DESCRIPTOR_LENGTH_DEVICE, /* Size of this descriptor in bytes */ USB_DESCRIPTOR_TYPE_DEVICE, /* DEVICE Descriptor Type */ USB_SHORT_GET_LOW(USB_DEVICE_SPECIFIC_BCD_VERSION), USB_SHORT_GET_HIGH(USB_DEVICE_SPECIFIC_BCD_VERSION), /* USB Specification Release Number in Binary-Coded Decimal (i.e., 2.10 is 210H). */ USB_DEVICE_CLASS, /* Class code (assigned by the USB-IF). */ USB_DEVICE_SUBCLASS, /* Subclass code (assigned by the USB-IF). */ USB_DEVICE_PROTOCOL, /* Protocol code (assigned by the USB-IF). */ USB_CONTROL_MAX_PACKET_SIZE, /* Maximum packet size for endpoint zero (only 8, 16, 32, or 64 are valid) */ 0xA2U, 0x15U, /* Vendor ID (assigned by the USB-IF) */ 0x7EU, 0x00U, /* Product ID (assigned by the manufacturer) */ USB_SHORT_GET_LOW(USB_DEVICE_DEMO_BCD_VERSION), USB_SHORT_GET_HIGH(USB_DEVICE_DEMO_BCD_VERSION), /* Device release number in binary-coded decimal */ 0x01U, /* Index of string descriptor describing manufacturer */ 0x02U, /* Index of string descriptor describing product */ 0x00U, /* Index of string descriptor describing the device's serial number */
/******************************************************************************* * Prototypes ******************************************************************************/ /******************************************************************************* * Variables ******************************************************************************/ uint8_t g_UsbDeviceCurrentConfigure = 0U; uint8_t g_UsbDeviceInterface[USB_AUDIO_GENERATOR_INTERFACE_COUNT]; /* Define device descriptor */ uint8_t g_UsbDeviceDescriptor[USB_DESCRIPTOR_LENGTH_DEVICE] = { USB_DESCRIPTOR_LENGTH_DEVICE, /* Size of this descriptor in bytes */ USB_DESCRIPTOR_TYPE_DEVICE, /* DEVICE Descriptor Type */ USB_SHORT_GET_LOW(USB_DEVICE_SPECIFIC_BCD_VERSION), USB_SHORT_GET_HIGH(USB_DEVICE_SPECIFIC_BCD_VERSION), /* USB Specification Release Number in Binary-Coded Decimal (i.e., 2.10 is 210H). */ USB_DEVICE_CLASS, /* Class code (assigned by the USB-IF). */ USB_DEVICE_SUBCLASS, /* Subclass code (assigned by the USB-IF). */ USB_DEVICE_PROTOCOL, /* Protocol code (assigned by the USB-IF). */ USB_CONTROL_MAX_PACKET_SIZE, /* Maximum packet size for endpoint zero (only 8, 16, 32, or 64 are valid) */ 0xC9U, 0x1FU, /* Vendor ID (assigned by the USB-IF) */ 0x72U, 0x02U, /* Product ID (assigned by the manufacturer) */ USB_SHORT_GET_LOW(USB_DEVICE_DEMO_BCD_VERSION), USB_SHORT_GET_HIGH(USB_DEVICE_DEMO_BCD_VERSION), /* Device release number in binary-coded decimal */ 0x01U, /* Index of string descriptor describing manufacturer */ 0x02U, /* Index of string descriptor describing product */ 0x00U, /* Index of string descriptor describing the device's serial number */
0x01, /* Collection (Application) */ HID_USAGE_HIDTC_DATA_OUT(kBootloaderReportID_CommandOut, BL_REPORT_SIZE, 8), HID_USAGE_HIDTC_DATA_OUT(kBootloaderReportID_DataOut, BL_REPORT_SIZE, 8), HID_USAGE_HIDTC_DATA_IN(kBootloaderReportID_CommandIn, BL_REPORT_SIZE, 8), HID_USAGE_HIDTC_DATA_IN(kBootloaderReportID_DataIn, BL_REPORT_SIZE, 8), 0xC0 /* end collection */ }; /* Define device descriptor */ uint8_t g_device_descriptor[USB_DEVICE_DESCRIPTOR_LENGTH] = { /* "Device Descriptor Size */ USB_DEVICE_DESCRIPTOR_LENGTH, /* "Device" Type of descriptor */ USB_DESCRIPTOR_TYPE_DEVICE, /* BCD USB version */ USB_SHORT_GET_LOW(USB_BCD_VERSION), USB_SHORT_GET_HIGH(USB_BCD_VERSION), /* Device Class is indicated in the interface descriptors */ USB_DEVICE_CLASS, /* Device Subclass is indicated in the interface descriptors */ USB_DEVICE_SUBCLASS, /* Device Protocol */ USB_DEVICE_PROTOCOL, /* Max Packet size */ USB_CONTROL_MAX_PACKET_SIZE, /* Vendor ID */ 0xa2, 0x15, /* Vendor ID for Freescale */ /* Product ID */ 0x73, 0x00, /* 0x73,0x00,ProductID for KL25Z48M */ /* BCD Device version */ 0x02, 0x00, /* Manufacturer string index */
#include "usb_device_descriptor.h" /******************************************************************************* * Variables ******************************************************************************/ uint8_t g_currentConfigure = 0; uint8_t g_interface[USB_CDC_VCOM_INTERFACE_COUNT]; /* Define device descriptor */ uint8_t g_UsbDeviceDescriptor[USB_DESCRIPTOR_LENGTH_DEVICE] = { /* Size of this descriptor in bytes */ USB_DESCRIPTOR_LENGTH_DEVICE, /* DEVICE Descriptor Type */ USB_DESCRIPTOR_TYPE_DEVICE, /* USB Specification Release Number in Binary-Coded Decimal (i.e., 2.10 is 210H). */ USB_SHORT_GET_LOW(USB_DEVICE_SPECIFIC_BCD_VERSION), USB_SHORT_GET_HIGH(USB_DEVICE_SPECIFIC_BCD_VERSION), /* Class code (assigned by the USB-IF). */ USB_DEVICE_CLASS, /* Subclass code (assigned by the USB-IF). */ USB_DEVICE_SUBCLASS, /* Protocol code (assigned by the USB-IF). */ USB_DEVICE_PROTOCOL, /* Maximum packet size for endpoint zero (only 8, 16, 32, or 64 are valid) */ USB_CONTROL_MAX_PACKET_SIZE, /* Vendor ID (assigned by the USB-IF) */ 0xC9U, 0x1FU, /* Product ID (assigned by the manufacturer) */ 0x00, 0x03, /* Device release number in binary-coded decimal */ USB_SHORT_GET_LOW(USB_DEVICE_DEMO_BCD_VERSION), USB_SHORT_GET_HIGH(USB_DEVICE_DEMO_BCD_VERSION), /* Index of string descriptor describing manufacturer */
/* Define class information for virtual com */ usb_device_class_struct_t g_UsbDeviceCdcVcomConfig = { g_UsbDeviceCdcVcomInterfaceList, kUSB_DeviceClassTypeCdc, USB_DEVICE_CONFIGURATION_COUNT, }; // AR/JBW - 21JUL18 /* Define device descriptor */ USB_DMA_INIT_DATA_ALIGN(USB_DATA_ALIGN_SIZE) uint8_t g_UsbDeviceDescriptor[] = { /* Size of this descriptor in bytes */ USB_DESCRIPTOR_LENGTH_DEVICE, /* DEVICE Descriptor Type */ USB_DESCRIPTOR_TYPE_DEVICE, /* USB Specification Release Number in Binary-Coded Decimal (i.e., 2.10 is 210H). */ USB_SHORT_GET_LOW(USB_DEVICE_SPECIFIC_BCD_VERSION), USB_SHORT_GET_HIGH(USB_DEVICE_SPECIFIC_BCD_VERSION), /* Class code (assigned by the USB-IF). */ USB_DEVICE_CLASS, /* Subclass code (assigned by the USB-IF). */ USB_DEVICE_SUBCLASS, /* Protocol code (assigned by the USB-IF). */ USB_DEVICE_PROTOCOL, /* Maximum packet size for endpoint zero (only 8, 16, 32, or 64 are valid) */ USB_CONTROL_MAX_PACKET_SIZE, /* Vendor ID (assigned by the USB-IF) */ 0x41U, 0x23U, /* Product ID (assigned by the manufacturer) */ 0x01, 0x00, /* Device release number in binary-coded decimal */ USB_SHORT_GET_LOW(USB_DEVICE_DEMO_BCD_VERSION), USB_SHORT_GET_HIGH(USB_DEVICE_DEMO_BCD_VERSION), /* Index of string descriptor describing manufacturer */
* Prototypes ******************************************************************************/ extern usb_status_t USB_DeviceCallback(usb_device_handle deviceHandle, uint32_t event, void *param); /******************************************************************************* * Variables ******************************************************************************/ uint8_t g_UsbDeviceCurrentConfigure = 0U; uint8_t g_UsbDeviceInterface[USB_VIDEO_VIRTUAL_CAMERA_INTERFACE_COUNT]; uint8_t g_UsbDeviceDescriptor[USB_DESCRIPTOR_LENGTH_DEVICE] = { USB_DESCRIPTOR_LENGTH_DEVICE, /* Size of this descriptor in bytes */ USB_DESCRIPTOR_TYPE_DEVICE, /* DEVICE Descriptor Type */ USB_SHORT_GET_LOW(USB_DEVICE_SPECIFIC_BCD_VERSION), USB_SHORT_GET_HIGH(USB_DEVICE_SPECIFIC_BCD_VERSION), /* USB Specification Release Number in Binary-Coded Decimal (i.e., 2.10 is 210H). */ USB_DEVICE_CLASS, /* Class code (assigned by the USB-IF). */ USB_DEVICE_SUBCLASS, /* Subclass code (assigned by the USB-IF). */ USB_DEVICE_PROTOCOL, /* Protocol code (assigned by the USB-IF). */ USB_CONTROL_MAX_PACKET_SIZE, /* Maximum packet size for endpoint zero (only 8, 16, 32, or 64 are valid) */ 0xA2U, 0x15U, /* Vendor ID (assigned by the USB-IF) */ 0x81U, 0x00U, /* Product ID (assigned by the manufacturer) */ USB_SHORT_GET_LOW(USB_DEVICE_DEMO_BCD_VERSION), USB_SHORT_GET_HIGH(USB_DEVICE_DEMO_BCD_VERSION), /* Device release number in binary-coded decimal */ 0x01U, /* Index of string descriptor describing manufacturer */ 0x02U, /* Index of string descriptor describing product */ 0x00U, /* Index of string descriptor describing the device's serial number */