void EVENT_CDC_Device_LineEncodingChanged(USB_ClassInfo_CDC_Device_t *const CDCInterfaceInfo) { /*TODO: add LineEncoding processing here * this is just a simple statement, only Baud rate is set */ // Serial_Init(CDCInterfaceInfo->State.LineEncoding.BaudRateBPS, false); USB_DEBUG_MSG("EVENT_CDC_Device_LineEncodingChanged\r\n"); }
/** Event handler for the library USB Control Request reception event. */ void EVENT_USB_Device_ControlRequest(void) { #if defined(USB_CDC_CLASS) || defined(USB_COMP_MOUSE_CDC_CLASS) CDC_Device_ProcessControlRequest(CDC_IF_PTR); #endif // #if defined(USB_CDC_CLASS) || defined(USB_COMP_MOUSE_CDC_CLASS) #if defined(USB_MOUSE_CLASS) || defined(USB_COMP_MOUSE_CDC_CLASS) HID_Device_ProcessControlRequest(HID_Mouse_PTR); USB_DEBUG_MSG("EVENT_USB_Device_ControlRequest\r\n"); #endif // #if defined(USB_MOUSE_CLASS) || defined(USB_COMP_MOUSE_CDC_CLASS) }
/** Event handler for the library USB Configuration Changed event. */ void EVENT_USB_Device_ConfigurationChanged(void) { bool ConfigSuccess = true; #if defined(USB_CDC_CLASS) || defined(USB_COMP_MOUSE_CDC_CLASS) ConfigSuccess &= CDC_Device_ConfigureEndpoints(CDC_IF_PTR); #endif // #if defined(USB_CDC_CLASS) || defined(USB_COMP_MOUSE_CDC_CLASS) #if defined(USB_MOUSE_CLASS) || defined(USB_COMP_MOUSE_CDC_CLASS) ConfigSuccess &= HID_Device_ConfigureEndpoints(HID_Mouse_PTR); USB_Device_EnableSOFEvents(); // USB Mouse Only?? #endif // #if defined(USB_MOUSE_CLASS) || defined(USB_COMP_MOUSE_CDC_CLASS) USB_DEBUG_MSG("EVENT_USB_Device_ConfigurationChanged\r\n"); }
/** This function is called by the library when in device mode, and must be overridden (see library "USB Descriptors" * documentation) by the application code so that the address and size of a requested descriptor can be given * to the USB library. When the device receives a Get Descriptor request on the control endpoint, this function * is called so that the descriptor details can be passed back and the appropriate descriptor sent back to the * USB host. */ uint16_t CALLBACK_USB_GetDescriptor(uint8_t corenum, const uint16_t wValue, const uint8_t wIndex, const void * *const DescriptorAddress) { const uint8_t DescriptorType = (wValue >> 8); const uint8_t DescriptorNumber = (wValue & 0xFF); const void *Address = NULL; uint16_t Size = NO_DESCRIPTOR; switch (DescriptorType) { case DTYPE_Device: Address = &DeviceDescriptor; Size = sizeof(USB_Descriptor_Device_t); USB_DEBUG_MSG("Device\r\n"); break; case DTYPE_Configuration: Address = &ConfigurationDescriptor; Size = sizeof(MYUSB_CONFIGURATION_TYPE); USB_DEBUG_MSG("Configuration\r\n"); break; case DTYPE_String: switch (DescriptorNumber) { case 0x00: Address = LanguageStringPtr; Size = pgm_read_byte(&LanguageStringPtr->Header.Size); USB_DEBUG_MSG("DescriptorNumber\r\n"); break; case 0x01: Address = ManufacturerStringPtr; Size = pgm_read_byte(&ManufacturerStringPtr->Header.Size); USB_DEBUG_MSG("ManufacturerString\r\n"); break; case 0x02: Address = ProductStringPtr; Size = pgm_read_byte(&ProductStringPtr->Header.Size); USB_DEBUG_MSG("ProductString\r\n"); break; } break; #if defined(USB_MOUSE_CLASS) || defined(USB_COMP_MOUSE_CDC_CLASS) case HID_DTYPE_HID: Address = &ConfigurationDescriptor.HID_MouseHID; Size = sizeof(USB_HID_Descriptor_HID_t); USB_DEBUG_MSG("HID_DTYPE\r\n"); break; case HID_DTYPE_Report: Address = &MouseReport; Size = MouseReportSize; USB_DEBUG_MSG("MouseReport\r\n"); break; #endif // #if defined(USB_MOUSE_CLASS) || defined(USB_COMP_MOUSE_CDC_CLASS) } *DescriptorAddress = Address; return Size; }
/** Event handler for the library USB Disconnection event. */ void EVENT_USB_Device_Disconnect(void) {USB_DEBUG_MSG("EVENT_USB_Device_Disconnect\r\n");}
int usb_reset( usb_dev_handle *dev) { USB_DEBUG_MSG( "usb_reset"); return (usb_control_msg( dev, USB_TYPE_CLASS | USB_RECIP_DEVICE, USB_REQ_CLEAR_FEATURE, 0, 0, 0, 0, 0)); }
int usb_resetep( usb_dev_handle *dev, unsigned int ep) { USB_DEBUG_MSG( "usb_resetep - ep= %x", ep); return (usb_control_msg( dev, USB_RECIP_ENDPOINT, USB_REQ_CLEAR_FEATURE, 0, ep, 0, 0, 0)); }
int usb_os_find_devices( struct usb_bus *bus, struct usb_device **devices) { int rtn = 0; APIRET rc; ULONG cntDev; ULONG ctr; ULONG i; ULONG len; struct usb_device * fdev = NULL; struct usb_device * dev; char report[4096]; rc = UsbQueryNumberDevices( &cntDev); if (rc) { USB_ERROR_MSG( "unable to query number of USB devices - rc= %x", (int)rc); return -1; } for (ctr = 1; ctr <= cntDev; ctr++) { len = sizeof(report); rc = UsbQueryDeviceReport( ctr, &len, report); if (rc) { USB_ERROR_MSG( "unable to query device report - device= %d rc= %x", (int)ctr, (int)rc); return -1; } dev = calloc( 1, sizeof(struct usb_device)); if (!dev) { USB_ERROR_MSG( "unable to allocate memory in usb_os_find_devices"); return -1; } dev->bus = bus; dev->devnum = ctr; itoa( ctr, dev->filename, 10); memcpy( &dev->descriptor, report, sizeof(dev->descriptor)); LIST_ADD( fdev, dev); USB_DEBUG_MSG( "Found device %s on bus %s", dev->filename, bus->dirname); if (dev->descriptor.bNumConfigurations > USB_MAXCONFIG || dev->descriptor.bNumConfigurations < 1) { USB_DEBUG_MSG( "invalid number of device configurations - nbr= %d continuing...", dev->descriptor.bNumConfigurations); continue; } i = sizeof(struct usb_device_descriptor) + (dev->descriptor.bNumConfigurations * sizeof(struct usb_config_descriptor)); if (len < i) { USB_DEBUG_MSG( "device report too short - expected= %d actual= %d continuing...", (int)i, (int)len); continue; } dev->config = (struct usb_config_descriptor *)calloc( dev->descriptor.bNumConfigurations, sizeof(struct usb_config_descriptor)); if (!dev->config) { USB_ERROR_MSG( "unable to allocate memory in usb_os_find_devices"); return -1; } for (i = 0, len = sizeof(struct usb_device_descriptor); i < dev->descriptor.bNumConfigurations; i++) { char * ptr; ptr = &report[len]; len += ((struct usb_config_descriptor *)ptr)->wTotalLength; rtn = usb_parse_configuration( &dev->config[i], ptr); if (rtn > 0) USB_DEBUG_MSG( "Descriptor data still left - bytes= %d", rtn); else if (rtn < 0) USB_DEBUG_MSG( "Unable to parse descriptors"); } // configs } // devices *devices = fdev; return 0; }