// Called in ISR context // Set configuration. Return false if the configuration is not supported. bool USBAudio::USBCallback_setConfiguration(uint8_t configuration) { if (configuration != DEFAULT_CONFIGURATION) { return false; } // Configure isochronous endpoint realiseEndpoint(EPISO_OUT, PACKET_SIZE_ISO_IN, ISOCHRONOUS); realiseEndpoint(EPISO_IN, PACKET_SIZE_ISO_OUT, ISOCHRONOUS); // activate readings on this endpoint readStart(EPISO_OUT, PACKET_SIZE_ISO_IN); return true; }
bool USB::USBCallback_setConfiguration(uint8_t configuration) { iprintf("[CONFIGURE %d]", configuration); int i = findDescriptorIndex(0, DT_CONFIGURATION, configuration, 0); if (i > 0) { iprintf("[FOUND at %d]", i); uint8_t lastAlternate = 0; i++; for (; descriptors[i] != (usbdesc_base *) 0 && descriptors[i]->bDescType != DT_CONFIGURATION; i++) { switch(descriptors[i]->bDescType) { case DT_INTERFACE: { usbdesc_interface *interface = (usbdesc_interface *) descriptors[i]; iprintf("[INTERFACE %d:%d]",interface->bInterfaceNumber, interface->bAlternateSetting); interface->selectedAlternate = 0; lastAlternate = interface->bAlternateSetting; break; }; case DT_ENDPOINT: { usbdesc_endpoint *ep = (usbdesc_endpoint *) descriptors[i]; iprintf("[EP 0x%02X](%d)", ep->bEndpointAddress, lastAlternate); if (lastAlternate == 0) { iprintf("[Realised!]\n"); realiseEndpoint(ep->bEndpointAddress, ep->wMaxPacketSize, ((ep->bmAttributes & 3) == EA_ISOCHRONOUS)?ISOCHRONOUS:0); } break; }; } } return true; } return false; }
bool USB::USBCallback_setInterface(uint16_t interface, uint8_t alternate) { int i = findDescriptorIndex(0, DT_INTERFACE, interface, alternate); if (i > 0) { int j = findDescriptorIndex(0, DT_INTERFACE, interface, 0); if (j > 0) { ((usbdesc_interface *) descriptors[j])->selectedAlternate = alternate; for (; (descriptors[i]->bDescType != DT_INTERFACE) && (descriptors[i]->bDescType != DT_CONFIGURATION); i++) { if (descriptors[i]->bDescType == DT_ENDPOINT) { usbdesc_endpoint *ep = (usbdesc_endpoint *) descriptors[i]; realiseEndpoint(ep->bEndpointAddress, ep->wMaxPacketSize, ((ep->bmAttributes & 3) == EA_ISOCHRONOUS)?ISOCHRONOUS:0); } } } } return false; }