Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -------------------------------------------------------------------------------
- USB DESCRIPTOR
- -------------------------------------------------------------------------------
- ********************************************************************/
- /*********************************************************************
- * Descriptor specific type definitions are defined in:
- * usb_device.h
- *
- * Configuration options are defined in:
- * usb_config.h
- ********************************************************************/
- #ifndef __USB_DESCRIPTORS_C
- #define __USB_DESCRIPTORS_C
- /** INCLUDES *******************************************************/
- #include "usb.h"
- /** CONSTANTS ******************************************************/
- #if defined(COMPILER_MPLAB_C18)
- #pragma romdata
- #endif
- /* Device Descriptor */
- const USB_DEVICE_DESCRIPTOR device_dsc=
- {
- 0x12, // Size of this descriptor in bytes
- USB_DESCRIPTOR_DEVICE, // DEVICE descriptor type
- 0x0200, // USB Spec Release Number in BCD format
- 0x00, // Class Code
- 0x00, // Subclass code
- 0x00, // Protocol code
- USB_EP0_BUFF_SIZE, // Max packet size for EP0, see usb_config.h
- 0x04D8, // Vendor ID: 0x04D8 is Microchip's Vendor ID
- 0x0052, // Product ID: 0x0052
- 0x0000, // Device release number in BCD format
- 0x01, // Manufacturer string index
- 0x02, // Product string index
- 0x00, // Device serial number string index
- 0x01 // Number of possible configurations
- };
- /* Configuration 1 Descriptor */
- const uint8_t configDescriptor1[]={
- /* Configuration Descriptor */
- 0x09,//sizeof(USB_CFG_DSC), // Size of this descriptor in bytes
- USB_DESCRIPTOR_CONFIGURATION, // CONFIGURATION descriptor type
- 0x2E,0x00, // Total length of data for this cfg// 0x19 for 1 EP, 0x20 for 2 EP,0x27 for 3 EP, 0x2E for 4 EP,add 7 for every EP
- 1, // Number of interfaces in this cfg
- 1, // Index value of this configuration
- 0, // Configuration string index
- _DEFAULT | _SELF, // Attributes, see usb_device.h
- 50, // Max power consumption (2X mA)
- /* Interface Descriptor */
- 0x09,//sizeof(USB_INTF_DSC), // Size of this descriptor in bytes
- USB_DESCRIPTOR_INTERFACE, // INTERFACE descriptor type
- 0, // Interface Number
- 0, // Alternate Setting Number
- 4, // Number of endpoints in this intf
- 0xFF, // Class code
- 0xFF, // Subclass code
- 0xFF, // Protocol code
- 0, // Interface string index
- /* Endpoint Descriptor */
- 0x07, /*sizeof(USB_EP_DSC)*/
- USB_DESCRIPTOR_ENDPOINT, //Endpoint Descriptor
- _EP01_OUT, //EndpointAddress
- // _EP01_IN,
- _BULK, //Attributes
- 64,0x00, //size
- 1, //Interval
- 0x07, /*sizeof(USB_EP_DSC)*/
- USB_DESCRIPTOR_ENDPOINT, //Endpoint Descriptor
- _EP02_OUT, //EndpointAddress
- _BULK, //Attributes
- 64,0x00, //size
- 1, //Interval
- 0x07, /*sizeof(USB_EP_DSC)*/
- USB_DESCRIPTOR_ENDPOINT, //Endpoint Descriptor
- _EP03_OUT, //EndpointAddress
- _BULK, //Attributes
- 64,0x00, //size
- 1, //Interval
- 0x07, /*sizeof(USB_EP_DSC)*/
- USB_DESCRIPTOR_ENDPOINT, //Endpoint Descriptor
- _EP01_IN, //EndpointAddress
- _BULK, //Attributes
- 64,0x00, //size
- 1
- };
- //Language code string descriptor
- const struct{uint8_t bLength;uint8_t bDscType;uint16_t string[1];}sd000={
- sizeof(sd000),USB_DESCRIPTOR_STRING,{0x0409}};
- //Manufacturer string descriptor
- const struct{uint8_t bLength;uint8_t bDscType;uint16_t string[25];}sd001={
- sizeof(sd001),USB_DESCRIPTOR_STRING,
- {'M','i','c','r','o','c','h','i','p',' ',
- 'T','e','c','h','n','o','l','o','g','y',' ','I','n','c','.'
- }};
- //Product string descriptor
- const struct{uint8_t bLength;uint8_t bDscType;uint16_t string[31];}sd002={
- sizeof(sd002),USB_DESCRIPTOR_STRING,
- {'M','i','c','r','o','c','h','i','p',' ','W','i','n','U','S','B',
- ' ','E','x','a','m','p','l','e',' ','D','e','v','i','c','e'}};
- //Serial number string descriptor. If a serial number string is implemented,
- //it should be unique for every single device coming off the production assembly
- //line. Plugging two devices with the same serial number into a computer
- //simultaneously will cause problems (in extreme cases BSOD).
- //Note: Common OSes put restrictions on the possible values that are allowed.
- //For best OS compatibility, the serial number string should only consist
- //of UNICODE encoded numbers 0 through 9 and capital letters A through F.
- //const struct{uint8_t bLength;uint8_t bDscType;uint16_t string[10];}sd003={
- //sizeof(sd003),USB_DESCRIPTOR_STRING,
- //{'0','1','2','3','4','5','6','7','8','9'}};
- //Array of configuration descriptors
- const uint8_t *const USB_CD_Ptr[]=
- {
- (const uint8_t *const)&configDescriptor1
- };
- //Array of string descriptors
- const uint8_t *const USB_SD_Ptr[]=
- {
- (const uint8_t *const)&sd000,
- (const uint8_t *const)&sd001,
- (const uint8_t *const)&sd002,
- //(const uint8_t *const)&sd003
- };
- #if defined(IMPLEMENT_MICROSOFT_OS_DESCRIPTOR)
- //Microsoft "OS Descriptor" - This descriptor is based on a Microsoft specific
- //specification (not part of the standard USB 2.0 specs or class specs).
- //Implementing this special descriptor allows WinUSB driver package installation
- //to be automatic on Windows 8. For additional details, see:
- //http://msdn.microsoft.com/en-us/library/windows/hardware/hh450799(v=vs.85).aspx
- const MS_OS_DESCRIPTOR MSOSDescriptor =
- {
- sizeof(MSOSDescriptor), //bLength - lenght of this descriptor in bytes
- USB_DESCRIPTOR_STRING, //bDescriptorType - "string"
- {'M','S','F','T','1','0','0'}, //qwSignature - special values that specifies the OS descriptor spec version that this firmware implements
- GET_MS_DESCRIPTOR, //bMS_VendorCode - defines the "GET_MS_DESCRIPTOR" bRequest literal value
- 0x00 //bPad - always 0x00
- };
- //Extended Compat ID OS Feature Descriptor
- const MS_COMPAT_ID_FEATURE_DESC CompatIDFeatureDescriptor =
- {
- //----------Header Section--------------
- sizeof(CompatIDFeatureDescriptor), //dwLength
- 0x0100, //bcdVersion = 1.00
- EXTENDED_COMPAT_ID, //wIndex
- 0x01, //bCount - 0x01 "Function Section(s)" implemented in this descriptor
- {0,0,0,0,0,0,0}, //Reserved[7]
- //----------Function Section 1----------
- 0x00, //bFirstInterfaceNumber: the WinUSB interface in this firmware is interface #0
- 0x01, //Reserved - fill this reserved byte with 0x01 according to documentation
- {'W','I','N','U','S','B',0x00,0x00},//compatID - "WINUSB" (with two null terminators to fill all 8 bytes)
- {0,0,0,0,0,0,0,0}, //subCompatID - eight bytes of 0
- {0,0,0,0,0,0} //Reserved
- };
- //Extended Properties OS Feature Descriptor
- const MS_EXT_PROPERTY_FEATURE_DESC ExtPropertyFeatureDescriptor =
- {
- //----------Header Section--------------
- sizeof(ExtPropertyFeatureDescriptor), //dwLength
- 0x0100, //bcdVersion = 1.00
- EXTENDED_PROPERTIES, //wIndex
- 0x0001, //wCount - 0x0001 "Property Sections" implemented in this descriptor
- //----------Property Section 1----------
- 132, //dwSize - 132 bytes in this Property Section
- 0x00000001, //dwPropertyDataType (Unicode string)
- 40, //wPropertyNameLength - 40 bytes in the bPropertyName field
- {'D','e','v','i','c','e','I','n','t','e','r','f','a','c','e','G','U','I','D', 0x0000}, //bPropertyName - "DeviceInterfaceGUID"
- 78, //dwPropertyDataLength - 78 bytes in the bPropertyData field (GUID value in UNICODE formatted string, with braces and dashes)
- //The below value is the Device Interface GUID (a 128-bit long "globally unique identifier")
- //Please modify the GUID value in your application before moving to production.
- //When you change the GUID, you must also change the PC application software
- //that connects to this device, as the software looks for the device based on
- //VID, PID, and GUID. All three values in the PC application must match
- //the values in this firmware.
- //The GUID value can be a randomly generated 128-bit hexadecimal number,
- //formatted like the below value. The actual value is not important,
- //so long as it is almost certain to be globally unique, and matches the
- //PC software that communicates with this firmware.
- {'{','5','8','d','0','7','2','1','0','-','2','7','c','1','-','1','1','d','d','-','b','d','0','b','-','0','8','0','0','2','0','0','c','9','a','6','6','}',0x0000} //bPropertyData - this is the actual GUID value. Make sure this matches the PC application code trying to connect to the device.
- };
- #endif
- /** EOF usb_descriptors.c ***************************************************/
- #endif
- ------------------------------------------------------------------------------------
- USB CONFIGURATION
- ---------------------------------------------------------------------------------
- *******************************************************************************/
- /*********************************************************************
- * Descriptor specific type definitions are defined in: usbd.h
- ********************************************************************/
- #ifndef USBCFG_H
- #define USBCFG_H
- #include <stdint.h>
- /** DEFINITIONS ****************************************************/
- #define USB_EP0_BUFF_SIZE 8 // Valid Options: 8, 16, 32, or 64 bytes.
- // Using larger options take more SRAM, but
- // does not provide much advantage in most types
- // of applications. Exceptions to this, are applications
- // that use EP0 IN or OUT for sending large amounts of
- // application related data.
- #define USB_MAX_NUM_INT 1 //Set this number to match the maximum interface number used in the descriptors for this firmware project
- #define USB_MAX_EP_NUMBER 4 //Set this number to match the maximum endpoint number used in the descriptors for this firmware project
- //Device descriptor - if these two definitions are not defined then
- // a const USB_DEVICE_DESCRIPTOR variable by the exact name of device_dsc
- // must exist.
- #define USB_USER_DEVICE_DESCRIPTOR &device_dsc
- #define USB_USER_DEVICE_DESCRIPTOR_INCLUDE extern const USB_DEVICE_DESCRIPTOR device_dsc
- //Configuration descriptors - if these two definitions do not exist then
- // a const uint8_t *const variable named exactly USB_CD_Ptr[] must exist.
- #define USB_USER_CONFIG_DESCRIPTOR USB_CD_Ptr
- #define USB_USER_CONFIG_DESCRIPTOR_INCLUDE extern const uint8_t *const USB_CD_Ptr[]
- //------------------------------------------------------------------------------
- //Select an endpoint ping-pong bufferring mode. Some microcontrollers only
- //support certain modes. For most applications, it is recommended to use either
- //the USB_PING_PONG__FULL_PING_PONG or USB_PING_PONG__EP0_OUT_ONLY options.
- //The other settings are supported on some devices, but they are not
- //recommended, as they offer inferior control transfer timing performance.
- //See inline code comments in usb_device.c for additional details.
- //Enabling ping pong bufferring on an endpoint generally increases firmware
- //overhead somewhat, but when both buffers are used simultaneously in the
- //firmware, can offer better sustained bandwidth, especially for OUT endpoints.
- //------------------------------------------------------
- //#define USB_PING_PONG_MODE USB_PING_PONG__NO_PING_PONG //Not recommended
- #define USB_PING_PONG_MODE USB_PING_PONG__FULL_PING_PONG //Required setting for this particular demo
- //#define USB_PING_PONG_MODE USB_PING_PONG__EP0_OUT_ONLY
- //#define USB_PING_PONG_MODE USB_PING_PONG__ALL_BUT_EP0 //Not recommended
- //------------------------------------------------------------------------------
- //------------------------------------------------------------------------------
- //Select a USB stack operating mode. In the USB_INTERRUPT mode, the USB stack
- //main task handler gets called only when necessary as an interrupt handler.
- //This can potentially minimize CPU utilization, but adds context saving
- //and restoring overhead associated with interrupts, which can potentially
- //decrease performance.
- //When the USB_POLLING mode is selected, the USB stack main task handler
- //(ex: USBDeviceTasks()) must be called periodically by the application firmware
- //at a minimum rate as described in the inline code comments in usb_device.c.
- //------------------------------------------------------
- #define USB_POLLING
- //#define USB_INTERRUPT
- //------------------------------------------------------------------------------
- /* Parameter definitions are defined in usb_device.h */
- #define USB_PULLUP_OPTION USB_PULLUP_ENABLE
- //#define USB_PULLUP_OPTION USB_PULLUP_DISABLED
- #define USB_TRANSCEIVER_OPTION USB_INTERNAL_TRANSCEIVER
- //External Transceiver support is not available on all product families. Please
- // refer to the product family datasheet for more information if this feature
- // is available on the target processor.
- //#define USB_TRANSCEIVER_OPTION USB_EXTERNAL_TRANSCEIVER
- #define USB_SPEED_OPTION USB_FULL_SPEED
- //#define USB_SPEED_OPTION USB_LOW_SPEED //(this mode is only supported on some microcontrollers)
- #define USB_ENABLE_STATUS_STAGE_TIMEOUTS //Comment this out to disable this feature.
- #define USB_STATUS_STAGE_TIMEOUT (uint8_t)45 //Approximate timeout in milliseconds, except when
- //USB_POLLING mode is used, and USBDeviceTasks() is called at < 1kHz
- //In this special case, the timeout becomes approximately:
- //Timeout(in milliseconds) = ((1000 * (USB_STATUS_STAGE_TIMEOUT - 1)) / (USBDeviceTasks() polling frequency in Hz))
- //------------------------------------------------------------------------------------------------------------------
- #define IMPLEMENT_MICROSOFT_OS_DESCRIPTOR
- //Some definitions, only needed when using the MS OS descriptor.
- #if defined(IMPLEMENT_MICROSOFT_OS_DESCRIPTOR)
- #if defined(__XC8)
- #define __attribute__(a)
- #endif
- #define MICROSOFT_OS_DESCRIPTOR_INDEX (unsigned char)0xEE //Magic string index number for the Microsoft OS descriptor
- #define GET_MS_DESCRIPTOR (unsigned char)0xEE //(arbitarily assigned, but should not clobber/overlap normal bRequests)
- #define EXTENDED_COMPAT_ID (uint16_t)0x0004
- #define EXTENDED_PROPERTIES (uint16_t)0x0005
- typedef struct __attribute__ ((packed)) _MS_OS_DESCRIPTOR
- {
- uint8_t bLength;
- uint8_t bDscType;
- uint16_t string[7];
- uint8_t vendorCode;
- uint8_t bPad;
- }MS_OS_DESCRIPTOR;
- typedef struct __attribute__ ((packed)) _MS_COMPAT_ID_FEATURE_DESC
- {
- uint32_t dwLength;
- uint16_t bcdVersion;
- uint16_t wIndex;
- uint8_t bCount;
- uint8_t Reserved[7];
- uint8_t bFirstInterfaceNumber;
- uint8_t Reserved1;
- uint8_t compatID[8];
- uint8_t subCompatID[8];
- uint8_t Reserved2[6];
- }MS_COMPAT_ID_FEATURE_DESC;
- typedef struct __attribute__ ((packed)) _MS_EXT_PROPERTY_FEATURE_DESC
- {
- uint32_t dwLength;
- uint16_t bcdVersion;
- uint16_t wIndex;
- uint16_t wCount;
- uint32_t dwSize;
- uint32_t dwPropertyDataType;
- uint16_t wPropertyNameLength;
- uint16_t bPropertyName[20];
- uint32_t dwPropertyDataLength;
- uint16_t bPropertyData[39];
- }MS_EXT_PROPERTY_FEATURE_DESC;
- extern const MS_OS_DESCRIPTOR MSOSDescriptor;
- extern const MS_COMPAT_ID_FEATURE_DESC CompatIDFeatureDescriptor;
- extern const MS_EXT_PROPERTY_FEATURE_DESC ExtPropertyFeatureDescriptor;
- #endif
- #define USB_SUPPORT_DEVICE
- #define USB_NUM_STRING_DESCRIPTORS 3 //Set this number to match the total number of string descriptors that are implemented in the usb_descriptors.c file
- /*******************************************************************
- * Event disable options
- * Enable a definition to suppress a specific event. By default
- * all events are sent.
- *******************************************************************/
- //#define USB_DISABLE_SUSPEND_HANDLER
- //#define USB_DISABLE_WAKEUP_FROM_SUSPEND_HANDLER
- //#define USB_DISABLE_SOF_HANDLER
- //#define USB_DISABLE_TRANSFER_TERMINATED_HANDLER
- //#define USB_DISABLE_ERROR_HANDLER
- //#define USB_DISABLE_NONSTANDARD_EP0_REQUEST_HANDLER
- //#define USB_DISABLE_SET_DESCRIPTOR_HANDLER
- //#define USB_DISABLE_SET_CONFIGURATION_HANDLER
- //#define USB_DISABLE_TRANSFER_COMPLETE_HANDLER
- /** DEVICE CLASS USAGE *********************************************/
- #define USB_USE_GEN
- /** ENDPOINTS ALLOCATION *******************************************/
- /* Generic */
- #define USBGEN_EP_SIZE 64
- #define USBGEN_EP_NUM 1
- /** DEFINITIONS ****************************************************/
- #endif //USBCFG_H
Add Comment
Please, Sign In to add comment