Example #1
0
void usb_resetRecoveryMSD(usb_device_t* device, uint32_t Interface)
{
    // Reset Interface
    usb_bulkReset(device, Interface);

    // TEST ////////////////////////////////////
    //usbSetFeatureHALT(device, device->numEndpointInMSD);
    //usbSetFeatureHALT(device, device->numEndpointOutMSD);

    // Clear Feature HALT to the Bulk-In  endpoint
    printf("\nGetStatus: %u", usb_getStatus(device, device->numEndpointInMSD));
    usb_clearFeatureHALT(device, device->numEndpointInMSD);
    printf("\nGetStatus: %u", usb_getStatus(device, device->numEndpointInMSD));

    // Clear Feature HALT to the Bulk-Out endpoint
    printf("\nGetStatus: %u", usb_getStatus(device, device->numEndpointOutMSD));
    usb_clearFeatureHALT(device, device->numEndpointOutMSD);
    printf("\nGetStatus: %u", usb_getStatus(device, device->numEndpointOutMSD));

    // set configuration to 1 and endpoint IN/OUT toggles to 0
    usb_setConfiguration(device, 1); // set first configuration
    uint8_t config = usb_getConfiguration(device);
    if (config != 1)
    {
        textColor(ERROR);
        printf("\tconfiguration: %u (to be: 1)", config);
        textColor(TEXT);
    }

    // start with correct endpoint toggles and reset interface
    device->endpoints[device->numEndpointOutMSD].toggle = 0;
    device->endpoints[device->numEndpointInMSD].toggle = 0;
    usb_bulkReset(device, device->numInterfaceMSD); // Reset Interface
}
Example #2
0
int usb_initDevice(usb_device * device, int configuration)
{
	char buf[4];

	uint8_t rcode;

	// Set the configuration for this USB device.
	rcode = usb_setConfiguration(device, configuration);
	if (rcode<0) return rcode;

	// Get the first supported language.
	rcode = usb_getString(device, 0, 0, 4, buf);
	if (rcode<0) return rcode;
    device->firstStringLanguage = (buf[3] << 8) | buf[2];

    return rcode;
}
Example #3
0
void usb_setupDevice(usb_device_t* device, uint8_t address)
{
    device->num = 0; // device number has to be set to 0
    bool success = false;

    success = usb_getDeviceDescriptor(device);
    if (!success)
    {
        success = usb_getDeviceDescriptor(device);
    }

    if (!success)
    {
        textColor(ERROR);
        printf("\nSetup Device interrupted!");
        textColor(TEXT);
        return;
    }
    waitForKeyStroke();

    device->num = usb_setDeviceAddress(device->disk->port, address);

    success = usb_getConfigDescriptor(device);
    if (!success)
    {
        success = usb_getConfigDescriptor(device);
    }

    if (!success)
    {
        textColor(ERROR);
        printf("\nSetup Device interrupted!");
        textColor(TEXT);
        return;
    }
    waitForKeyStroke();

    usb_getStringDescriptor(device); waitForKeyStroke();

    for (uint8_t i=1; i<4; i++) // fetch 3 strings
    {
        usb_getUnicodeStringDescriptor(device, i); waitForKeyStroke();
    }

    usb_setConfiguration(device, 1); // set first configuration
    waitForKeyStroke();

  #ifdef _USB_DIAGNOSIS_
    uint8_t config = usb_getConfiguration(device);
    printf("\nconfiguration: %u", config); // check configuration
    waitForKeyStroke();
  #endif

    if (device->InterfaceClass != 0x08)
    {
        textColor(ERROR);
        printf("\nThis is no Mass Storage Device! MSD test and addition to device manager will not be carried out.");
        textColor(TEXT);
        waitForKeyStroke();
    }
    else
    {
        // Disk
        device->disk->type       = &USB_MSD;
        device->disk->sectorSize = 512;
        strcpy(device->disk->name, device->productName);
        attachDisk(device->disk);

      #ifdef _USB_DIAGNOSIS_
        showPortList(); // TEST
        showDiskList(); // TEST

        // device, interface, endpoints
        textColor(HEADLINE);
        printf("\n\nMSD test now with device: %X  interface: %u  endpOUT: %u  endpIN: %u\n",
                                                device, device->numInterfaceMSD,
                                                device->numEndpointOutMSD,
                                                device->numEndpointInMSD);
        textColor(TEXT);
      #endif

        testMSD(device); // test with some SCSI commands
    }
}