原创 AT91 USB Core Project Test Note

2009-11-4 00:15 3074 5 5 分类: MCU/ 嵌入式


/// Configuration descriptors.
const struct SimpleConfigurationDescriptors configurationDescriptors = {



    // Standard configuration descriptor.
    {
        sizeof(USBConfigurationDescriptor),
        USBGenericDescriptor_CONFIGURATION,
        sizeof(configurationDescriptors),
        1, // Configuration has one interface.
        1, // This is configuration #1.
        0, // No string descriptor for configuration.
        BOARD_USB_BMATTRIBUTES,
        USBConfigurationDescriptor_POWER(100)
    },
#if defined(BOARD_USB_OTGHS)
    // OTG descriptor
    {
        sizeof(USBOtgDescriptor),
        USBGenericDescriptor_OTG,
        USBOTGDescriptor_HNP_SRP
    },
#endif
    // interface descriptor.
    {
        sizeof(USBInterfaceDescriptor),
        USBGenericDescriptor_INTERFACE,
        0, // This is interface #0.
        0, // This is alternate setting #0.
        3, // Interface uses two endpoints.
        0xFF, //MSInterfaceDescriptor_CLASS,
        0xFF, //MSInterfaceDescriptor_SCSI,
        0xFF, //MSInterfaceDescriptor_BULKONLY,
        0 // No string descriptor for interface.
    },


    // Bulk-IN endpoint descriptor
    {
        sizeof(USBEndpointDescriptor),
        USBGenericDescriptor_ENDPOINT,
        USBEndpointDescriptor_ADDRESS(
            USBEndpointDescriptor_IN,
            1),
        USBEndpointDescriptor_BULK,
        USBEndpointDescriptor_MAXBULKSIZE_FS,
        0 // Must be 0 for full-speed Bulk endpoints.
    },


    // Bulk-OUT endpoint descriptor
    {
        sizeof(USBEndpointDescriptor),
        USBGenericDescriptor_ENDPOINT,
        USBEndpointDescriptor_ADDRESS(
            USBEndpointDescriptor_OUT,
            2),
        USBEndpointDescriptor_BULK,
        USBEndpointDescriptor_MAXBULKSIZE_FS,
        0 // Must be 0 for full-speed Bulk endpoints.
    },


// to here total size = 32 byte


// 32 % 8 = 0


// SetConf will be failed



    // Bulk-IN endpoint descriptor
    {
        sizeof(USBEndpointDescriptor),
        USBGenericDescriptor_ENDPOINT,
        USBEndpointDescriptor_ADDRESS(
            USBEndpointDescriptor_IN,
            3),
        USBEndpointDescriptor_BULK,
        USBEndpointDescriptor_MAXBULKSIZE_FS,
        0 // Must be 0 for full-speed Bulk endpoints.
    }
};


// to here total size = 39 byte


// 39 % 8 = 7


// SetConf will be success !


 


        case USBGenericDescriptor_CONFIGURATION:
            TRACE_INFO_WP("Cfg ");


            // Adjust length and send descriptor
            if (length > USBConfigurationDescriptor_GetTotalLength(pConfiguration)) {


                length = USBConfigurationDescriptor_GetTotalLength(pConfiguration);
            }
            USBD_Write(0,
                       pConfiguration,
                       length,
                       ((length % pDevice->bMaxPacketSize0) == 0) ? TerminateCtrlInWithNull : 0,
                       0);
            break;


// Write Zero Length Packet to Buffer,


// When PC read last packet ( its size is bMaxPacketSize0 )


// then PC will read Zero Length Packet, no more data need be read


// but if (request length % pDevice->bMaxPacketSize0) == 0, PC will not read ZLP


 


**********************************************************************


//------------------------------------------------------------------------------
//         Local types
//------------------------------------------------------------------------------
/// Configuration descriptors with one interface.
struct SimpleConfigurationDescriptors {


    USBConfigurationDescriptor configuration;
    USBInterfaceDescriptor interface;
    /// Bulk-in endpoint descriptor.
    USBEndpointDescriptor bulkIn1;
    /// Bulk-out endpoint descriptor.
    USBEndpointDescriptor bulkOut2;
    /// Bulk-in endpoint descriptor.
    USBEndpointDescriptor bulkIn3;
    /// Bulk-out endpoint descriptor.
    USBEndpointDescriptor bulkOut4;
    /// Bulk-in endpoint descriptor.
    USBEndpointDescriptor bulkIn5;
};


//------------------------------------------------------------------------------
//         Local variables
//------------------------------------------------------------------------------


/// Device descriptor.
const USBDeviceDescriptor usbDeviceDescriptor = {



    sizeof(USBDeviceDescriptor),
    USBGenericDescriptor_DEVICE,
    USBDeviceDescriptor_USB2_00,
    0xFF, //MSDeviceDescriptor_CLASS,
    0xFF, //MSDeviceDescriptor_SUBCLASS,
    0xFF, //MSDeviceDescriptor_PROTOCOL,
    BOARD_USB_ENDPOINTS_MAXPACKETSIZE(0),
    0xFFFF, //MSDDriverDescriptors_VENDORID,
    0x9999, //MSDDriverDescriptors_PRODUCTID,
    0x0005, //MSDDriverDescriptors_RELEASE,
    0, // Manufacturer string descriptor index.
    1, // Product string descriptor index.
    0, // Serial number string descriptor index.
    1  // Device has one possible configuration.
};


/// Configuration descriptors.
const struct SimpleConfigurationDescriptors configurationDescriptors = {



    // Standard configuration descriptor.
    {
        sizeof(USBConfigurationDescriptor),
        USBGenericDescriptor_CONFIGURATION,
        sizeof(configurationDescriptors),
        1, // Configuration has one interface.
        1, // This is configuration #1.
        0, // No string descriptor for configuration.
        BOARD_USB_BMATTRIBUTES,
        USBConfigurationDescriptor_POWER(100)
    },
#if defined(BOARD_USB_OTGHS)
    // OTG descriptor
    {
        sizeof(USBOtgDescriptor),
        USBGenericDescriptor_OTG,
        USBOTGDescriptor_HNP_SRP
    },
#endif
    // Mass Storage interface descriptor.
    {
        sizeof(USBInterfaceDescriptor),
        USBGenericDescriptor_INTERFACE,
        0, // This is interface #0.
        0, // This is alternate setting #0.
        5, // Interface uses two endpoints.
        0xFF, //MSInterfaceDescriptor_CLASS,
        0xFF, //MSInterfaceDescriptor_SCSI,
        0xFF, //MSInterfaceDescriptor_BULKONLY,
        0 // No string descriptor for interface.
    },


    // Bulk-IN endpoint descriptor
    {
        sizeof(USBEndpointDescriptor),
        USBGenericDescriptor_ENDPOINT,
        USBEndpointDescriptor_ADDRESS(
            USBEndpointDescriptor_IN,
            1),
        USBEndpointDescriptor_BULK,
        USBEndpointDescriptor_MAXBULKSIZE_FS,
        0 // Must be 0 for full-speed Bulk endpoints.
    },


    // Bulk-OUT endpoint descriptor
    {
        sizeof(USBEndpointDescriptor),
        USBGenericDescriptor_ENDPOINT,
        USBEndpointDescriptor_ADDRESS(
            USBEndpointDescriptor_OUT,
            2),
        USBEndpointDescriptor_BULK,
        USBEndpointDescriptor_MAXBULKSIZE_FS,
        0 // Must be 0 for full-speed Bulk endpoints.
    },
    // Bulk-IN endpoint descriptor
    {
        sizeof(USBEndpointDescriptor),
        USBGenericDescriptor_ENDPOINT,
        USBEndpointDescriptor_ADDRESS(
            USBEndpointDescriptor_IN,
            3),
        USBEndpointDescriptor_BULK,
        USBEndpointDescriptor_MAXBULKSIZE_FS,
        0 // Must be 0 for full-speed Bulk endpoints.
    },


    // Bulk-OUT endpoint descriptor
    {
        sizeof(USBEndpointDescriptor),
        USBGenericDescriptor_ENDPOINT,
        USBEndpointDescriptor_ADDRESS(
            USBEndpointDescriptor_OUT,
            4),
        USBEndpointDescriptor_BULK,
        USBEndpointDescriptor_MAXBULKSIZE_FS,
        0 // Must be 0 for full-speed Bulk endpoints.
    },


    // Bulk-IN endpoint descriptor
    {
        sizeof(USBEndpointDescriptor),
        USBGenericDescriptor_ENDPOINT,
        USBEndpointDescriptor_ADDRESS(
            USBEndpointDescriptor_IN,
            5),
        USBEndpointDescriptor_BULK,
        USBEndpointDescriptor_MAXBULKSIZE_FS,
        0 // Must be 0 for full-speed Bulk endpoints.
    }
};


 


/// Language ID string descriptor.
static const unsigned char languageIdDescriptor[] = {


    USBStringDescriptor_LENGTH(1),
    USBGenericDescriptor_STRING,
    USBStringDescriptor_ENGLISH_US
};
/// Product string descriptor.
static const unsigned char productDescriptor[] = {


    USBStringDescriptor_LENGTH(7),
    USBGenericDescriptor_STRING,
    USBStringDescriptor_UNICODE('A'),
    USBStringDescriptor_UNICODE('T'),
    USBStringDescriptor_UNICODE('9'),
    USBStringDescriptor_UNICODE('1'),
    USBStringDescriptor_UNICODE('U'),
    USBStringDescriptor_UNICODE('S'),
    USBStringDescriptor_UNICODE('B')
};


/// List of all string descriptors used.
static const unsigned char *stringDescriptors[] = {


    languageIdDescriptor,
    productDescriptor
};


/// List of descriptors used by the device.
const USBDDriverDescriptors usbdDriverDescriptors = {


    &usbDeviceDescriptor,
    (const USBConfigurationDescriptor *) &configurationDescriptors,
#ifdef BOARD_USB_UDPHS
    0, // No full-speed device qualifier descriptor
    0, // No full-speed other speed configuration descriptor
    &usbDeviceDescriptor,
    (const USBConfigurationDescriptor *) &configurationDescriptors,
    0, // No high-speed device qualifier descriptor
    0, // No high-speed other speed configuration descriptor
#else
    0, // No full-speed device qualifier descriptor
    0, // No full-speed other speed configuration descriptor
    0, // No high-speed device descriptor
    0, // No high-speed configuration descriptor
    0, // No high-speed device qualifier descriptor
    0, // No high-speed other speed configuration descriptor
#endif
    stringDescriptors,
    2 // Four string descriptors in array
};



 


 

文章评论0条评论)

登录后参与讨论
我要评论
0
5
关闭 站长推荐上一条 /2 下一条