static void USB_Device_GetDescriptor(void) { const void* DescriptorPointer; uint16_t DescriptorSize; #if defined(ARCH_HAS_MULTI_ADDRESS_SPACE) && \ !(defined(USE_FLASH_DESCRIPTORS) || defined(USE_EEPROM_DESCRIPTORS) || defined(USE_RAM_DESCRIPTORS)) uint8_t DescriptorAddressSpace; #endif #if !defined(NO_INTERNAL_SERIAL) && (USE_INTERNAL_SERIAL != NO_DESCRIPTOR) if (USB_ControlRequest.wValue == ((DTYPE_String << 8) | USE_INTERNAL_SERIAL)) { USB_Device_GetInternalSerialDescriptor(); return; } #endif if ((DescriptorSize = CALLBACK_USB_GetDescriptor(USB_ControlRequest.wValue, USB_ControlRequest.wIndex, &DescriptorPointer #if defined(ARCH_HAS_MULTI_ADDRESS_SPACE) && \ !(defined(USE_FLASH_DESCRIPTORS) || defined(USE_EEPROM_DESCRIPTORS) || defined(USE_RAM_DESCRIPTORS)) , &DescriptorAddressSpace #endif )) == NO_DESCRIPTOR) { return; } Endpoint_ClearSETUP(); #if defined(USE_RAM_DESCRIPTORS) || !defined(ARCH_HAS_MULTI_ADDRESS_SPACE) Endpoint_Write_Control_Stream_LE(DescriptorPointer, DescriptorSize); #elif defined(USE_EEPROM_DESCRIPTORS) Endpoint_Write_Control_EStream_LE(DescriptorPointer, DescriptorSize); #elif defined(USE_FLASH_DESCRIPTORS) Endpoint_Write_Control_PStream_LE(DescriptorPointer, DescriptorSize); #else if (DescriptorAddressSpace == MEMSPACE_FLASH) Endpoint_Write_Control_PStream_LE(DescriptorPointer, DescriptorSize); else if (DescriptorAddressSpace == MEMSPACE_EEPROM) Endpoint_Write_Control_EStream_LE(DescriptorPointer, DescriptorSize); else Endpoint_Write_Control_Stream_LE(DescriptorPointer, DescriptorSize); #endif Endpoint_ClearOUT(); }
void EVENT_USB_Device_UnhandledControlRequest(void) { /* Process UFI specific control requests */ switch (USB_ControlRequest.bRequest) { case REQ_GetOSFeatureDescriptor: if (USB_ControlRequest.bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_VENDOR | REQREC_DEVICE)) { void* DescriptorPointer; uint16_t DescriptorSize; if (!(USB_GetOSFeatureDescriptor(USB_ControlRequest.wValue, USB_ControlRequest.wIndex, &DescriptorPointer, &DescriptorSize))) { return; } Endpoint_ClearSETUP(); Endpoint_Write_Control_PStream_LE(DescriptorPointer, DescriptorSize); Endpoint_ClearOUT(); } break; } }
void EVENT_USB_Device_ControlRequest(void){ void* buffer = NULL; uint16_t length = 0; if(change != NULL) { usb_set_device(change, 1); Endpoint_ClearSETUP(); Endpoint_ClearIN(); Endpoint_ClearOUT(); } else { Endpoint_ClearSETUP(); } uart_print("Type: %x, req: %x, val: %x, idx: %x, len: %d\n", USB_ControlRequest.bmRequestType, USB_ControlRequest.bRequest, USB_ControlRequest.wValue, USB_ControlRequest.wIndex, USB_ControlRequest.wLength); device->handle_configuration( device, USB_ControlRequest.bmRequestType, USB_ControlRequest.bRequest, USB_ControlRequest.wValue, USB_ControlRequest.wIndex, USB_ControlRequest.wLength, &buffer, &length); if(buffer) { if(length == 0xFFFF) { return; } if(length) { if(length & CONST_PTR) { Endpoint_Write_Control_PStream_LE(buffer, length & ~CONST_PTR); } else { Endpoint_Write_Control_Stream_LE(buffer, length); } } Endpoint_ClearStatusStage(); if(deferred_addr >= 0) { _usb_set_addr(deferred_addr); uart_print("Setting addr to %d\n", deferred_addr); deferred_addr = -1; } } else { Endpoint_StallTransaction(); uart_print("STALLED!\n"); } }
void EVENT_USB_Device_UnhandledControlRequest(void) { switch (USB_ControlRequest.bRequest) { case REQ_GetOSFeatureDescriptor: if (USB_ControlRequest.bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_VENDOR | REQREC_DEVICE)) { void* DescriptorPointer; uint16_t DescriptorSize = USB_GetOSFeatureDescriptor(USB_ControlRequest.wValue, USB_ControlRequest.wIndex, &DescriptorPointer); if (DescriptorSize == NO_DESCRIPTOR) return; Endpoint_ClearSETUP(); Endpoint_Write_Control_PStream_LE(DescriptorPointer, DescriptorSize); Endpoint_ClearOUT(); } break; } }