UsbEndpoint * usbGetEndpoint (UsbDevice *device, unsigned char endpointAddress) { UsbEndpoint *endpoint; const UsbEndpointDescriptor *descriptor; if ((endpoint = findItem(device->endpoints, usbTestEndpoint, &endpointAddress))) return endpoint; if ((descriptor = usbEndpointDescriptor(device, endpointAddress))) { { const char *direction; const char *transfer; switch (USB_ENDPOINT_DIRECTION(descriptor)) { default: direction = "?"; break; case UsbEndpointDirection_Input: direction = "in"; break; case UsbEndpointDirection_Output: direction = "out"; break; } switch (USB_ENDPOINT_TRANSFER(descriptor)) { default: transfer = "?"; break; case UsbEndpointTransfer_Control: transfer = "ctl"; break; case UsbEndpointTransfer_Isochronous: transfer = "iso"; break; case UsbEndpointTransfer_Bulk: transfer = "blk"; break; case UsbEndpointTransfer_Interrupt: transfer = "int"; break; } logMessage(LOG_CATEGORY(USB_IO), "ept=%02X dir=%s xfr=%s pkt=%d ivl=%dms", descriptor->bEndpointAddress, direction, transfer, getLittleEndian16(descriptor->wMaxPacketSize), descriptor->bInterval); } if ((endpoint = malloc(sizeof(*endpoint)))) { memset(endpoint, 0, sizeof(*endpoint)); endpoint->device = device; endpoint->descriptor = descriptor; endpoint->extension = NULL; endpoint->prepare = NULL; switch (USB_ENDPOINT_DIRECTION(endpoint->descriptor)) { case UsbEndpointDirection_Input: endpoint->direction.input.pending.requests = NULL; endpoint->direction.input.pending.alarm = NULL; endpoint->direction.input.pending.delay = 0; endpoint->direction.input.completed.request = NULL; endpoint->direction.input.completed.buffer = NULL; endpoint->direction.input.completed.length = 0; endpoint->direction.input.pipe.input = INVALID_FILE_DESCRIPTOR; endpoint->direction.input.pipe.output = INVALID_FILE_DESCRIPTOR; endpoint->direction.input.pipe.monitor = NULL; endpoint->direction.input.pipe.error = 0; break; } if (usbAllocateEndpointExtension(endpoint)) { if (enqueueItem(device->endpoints, endpoint)) { if (device->disableEndpointReset) { logMessage(LOG_CATEGORY(USB_IO), "endpoint reset disabled"); } else { usbClearHalt(device, endpoint->descriptor->bEndpointAddress); } if (!endpoint->prepare || endpoint->prepare(endpoint)) return endpoint; deleteItem(device->endpoints, endpoint); } usbDeallocateEndpointExtension(endpoint->extension); usbDestroyInputPipe(endpoint); } free(endpoint); } } return NULL; }
int Sdr1kUsb::Open(BOOL rfe, BOOL adc, int select) { if (usbStatus >= 0) Close(); GetNumDevs(); int idx = select; if (select < 0) idx = 0; while (idx < devcount) { if (usbOpen(device[idx])) { if (usbSetConfiguration(1) == 0 && usbClaimInterface(0) == 0 && usbSetAltinterface(1) == 0) { usbStatus = 0; break; } usbClose(); } if (select < 0) idx++; else return usbStatus; } if (usbStatus < 0) return usbStatus; #ifdef SDR1KUSB_INFO printf("device %d: %s\n", idx, device[idx]->filename); printf("hardware: %s\n", hw[idx]->name); #endif inEP = hw[idx]->inEP; outEP = hw[idx]->outEP; usbClearHalt(inEP); usbClearHalt(outEP); int* fwSize = hw[idx]->fwSize; int* fwAddr = hw[idx]->fwAddr; BYTE** fwBytes = hw[idx]->fwBytes; for (int i = 0; fwSize[i] > 0; i++) { ezusbFirmwareDownload(fwAddr[i], fwBytes[i], fwSize[i]); } int eepromSize = hw[idx]->eepromSize; if (eepromSize == 16) { BYTE eeprom[16]; usbBulkRead(inEP, eeprom, 16); #ifdef SDR1KUSB_INFO printf("EEPROM:"); for (int i = 0; i < 16; i++) { printf(" %02X", eeprom[i]); } printf("\n"); #endif } inputEvent = 0; usbUpdatePeriod = USB_UPDATE_DEFAULT; outcount = 0; startUsbThread(); Latch(0x0F, 0); DDSReset(); rfeEnabled = rfe; if (rfeEnabled) { LatchBpf(0); // bpfBits |= 0x24 adcEnabled = adc; SRLoadIC11(0); SRLoadIC7(0); SRLoadIC10(0); SRLoadIC9(0); } else adcEnabled = 0; if (Commit() < 0) { Close(); return usbStatus; } return idx; }