Ejemplo n.º 1
0
int
usbConfigureDevice (
  UsbDevice *device,
  unsigned char configuration
) {
  usbCloseInterface(device);

  if (usbSetConfiguration(device, configuration)) {
    usbDeallocateConfigurationDescriptor(device);
    return 1;
  }

  {
    const UsbConfigurationDescriptor *descriptor = usbConfigurationDescriptor(device);

    if (descriptor)
      if (descriptor->bConfigurationValue == configuration)
        return 1;
  }

  return 0;
}
Ejemplo n.º 2
0
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;
}