text: /*******************************************************************************
    System Initialization File
  
    File Name:
      usb_device_init_data.c
  
    Summary:
      This file contains source code necessary to initialize the system.
  
    Description:
      This file contains source code necessary to initialize the system.  It
      implements the "SYS_Initialize" function, defines the configuration bits,
      and allocates any necessary global system resources,
   *******************************************************************************/
  
  // DOM-IGNORE-BEGIN
  /*******************************************************************************
  * Copyright (C) 2018 Microchip Technology Inc. and its subsidiaries.
  *
  * Subject to your compliance with these terms, you may use Microchip software
  * and any derivatives exclusively with Microchip products. It is your
  * responsibility to comply with third party license terms applicable to your
  * use of third party software (including open source software) that may
  * accompany Microchip software.
  *
  * THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES, WHETHER
  * EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE, INCLUDING ANY IMPLIED
  * WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, AND FITNESS FOR A
  * PARTICULAR PURPOSE.
  *
  * IN NO EVENT WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE,
  * INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND
  * WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP HAS
  * BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO THE
  * FULLEST EXTENT ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL CLAIMS IN
  * ANY WAY RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES, IF ANY,
  * THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS SOFTWARE.
   *******************************************************************************/
  // DOM-IGNORE-END
  
  // *****************************************************************************
  // *****************************************************************************
  // Section: Included Files
  // *****************************************************************************
  // *****************************************************************************
  
  #include "configuration.h"
  #include "definitions.h"
  /**************************************************
   * USB Device Function Driver Init Data
   **************************************************/
  	/****************************************************
   * Class specific descriptor - HID Report descriptor
   ****************************************************/
  const uint8_t hid_rpt0[] =
  {  
      0x06, 0x00, 0xFF,   // Usage Page = 0xFF00 (Vendor Defined Page 1)
      0x09, 0x01,             // Usage (Vendor Usage 1)
      0xA1, 0x01,             // Colsslection (Application)
      0x85, 0x01,                 // Report ID = 1
      0x19, 0x01,                 // Usage Minimum
  //    0x29, 0x40,                 // Usage Maximum 	// 64 input usages total (0x01 to 0x40)
      0x29, 0x01,                 // Usage Maximum 	// 64 input usages total (0x01 to 0x40)
  //    0x15, 0x01,               // Logical Minimum (data bytes in the report may have minimum value = 0x00)
  //    0x25, 0x40,               // Logical Maximum (data bytes in the report may have maximum value = 0x00FF = unsigned 255)
      0x75, 0x08,                 // Report Size: 8-bit field size
      0x95, 0x01,                 // 8bit (Report Size) * 1
  //    0x95, 0x40,               // Report Count: Make sixty-four 8-bit fields (the next time the parser hits an "Input", "Output", or "Feature" item)
      0x81, 0x00,                 // Input (Data, Array, Abs): Instantiates input packet fields based on the above report size, count, logical min/max, and usage.
      
      0x19, 0x01,                 // Usage Minimum
      0x29, 0x40,                 // Usage Maximum 	//64 output usages total (0x01 to 0x40)
      0x91, 0x00,                 // Output (Data, Array, Abs): Instantiates output packet fields.  Uses same report size and count as "Input" fields, since nothing new/different was specified to the parser since the "Input" item.
      0xC0,
      
      // Media Key
      0x05, 0x0C, //  Usage Page (Consumer Device)
  	0x09, 0x01, //  Usage (Consumer Control)			
  	0xA1, 0x01, //  Collection (Application)			
  	0x85, 0x02,	//      Report ID = 2
  	0x05, 0x0C, //		Usage Page (Consumer Devices)		
  	0x15, 0x00, //		Logical Minimum (0), bit value
  	0x25, 0x01, //		Logical Maximum (1), bit value
  	0x75, 0x01, //		Report Size (1)
      0x95, 0x06, //		Report Count (6)
  	0x09, USB_HID_CONSUMER_SCAN_NEXT_TRACK,         //	Usage
  	0x09, USB_HID_CONSUMER_SCAN_PREVIOUS_TRACK,     //	Usage    
      0x09, USB_HID_CONSUMER_PLAY_PAUSE,              // Usage (Play / Pause)
  	0x09, USB_HID_CONSUMER_MUTE,                    // Usage
  	0x09, USB_HID_CONSUMER_VOLUME_INCREMENT,        // Usage
  	0x09, USB_HID_CONSUMER_VOLUME_DECREMENT,        // Usage
  	0x81, 0x02, // Input (Data, Variable, Absolute)
  	0x95, 0x02, // Report Count (2)
  	0x81, 0x01, // Input (Constant)
  	0xC0
              
              
  };
  
  /**************************************************
   * USB Device HID Function Init Data
   **************************************************/
  const USB_DEVICE_HID_INIT hidInit0 =
  {
  	 .hidReportDescriptorSize = sizeof(hid_rpt0),
  	 .hidReportDescriptor = (void *)&hid_rpt0,
  	 .queueSizeReportReceive = 1,
  	 .queueSizeReportSend = 1
  };
  
  
  
  /**************************************************
   * USB Device Layer Function Driver Registration 
   * Table
   **************************************************/
  const USB_DEVICE_FUNCTION_REGISTRATION_TABLE funcRegistrationTable[1] =
  {
      
  	/* HID Function 0 */
      { 
          .configurationValue = 1,    /* Configuration value */ 
          .interfaceNumber = 0,       /* First interfaceNumber of this function */ 
          .speed = USB_SPEED_HIGH|USB_SPEED_FULL,    /* Function Speed */ 
          .numberOfInterfaces = 1,    /* Number of interfaces */
          .funcDriverIndex = 0,  /* Index of HID Function Driver */
          .driver = (void*)USB_DEVICE_HID_FUNCTION_DRIVER,    /* USB HID function data exposed to device layer */
          .funcDriverInit = (void*)&hidInit0    /* Function driver init data */
      },
  
  
  
  };
  
  /*******************************************
   * USB Device Layer Descriptors
   *******************************************/
  /*******************************************
   *  USB Device Descriptor 
   *******************************************/
  
  const USB_DEVICE_DESCRIPTOR deviceDescriptor =
  {
      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_DEVICE_EP0_BUFFER_SIZE,                             // Max packet size for EP0, see configuration.h
      0x04D8,                                                 // Vendor ID
      0x0055,                                                 // Product ID				
      0x0100,                                                 // 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
  };
  
  
  /*******************************************
   *  USB Full Speed Configuration Descriptor
   *******************************************/
  const uint8_t fullSpeedConfigurationDescriptor[]=
  {
  	/* Configuration Descriptor */
  
      0x09,                                                   // Size of this descriptor in bytes
      USB_DESCRIPTOR_CONFIGURATION,                           // Descriptor Type
      USB_DEVICE_16bitTo8bitArrange(41),                      //(41 Bytes)Size of the Configuration descriptor
      1,                                                      // Number of interfaces in this configuration
      0x01,                                                   // Index value of this configuration
      0x00,                                                   // Configuration string index
      USB_ATTRIBUTE_DEFAULT | USB_ATTRIBUTE_SELF_POWERED, // Attributes
      50,
  	
  
  	/* Interface Descriptor */
  
      0x09,                               // Size of this descriptor in bytes
      USB_DESCRIPTOR_INTERFACE,           // Descriptor Type is Interface descriptor
      0,                                  // Interface Number
      0x00,                                  // Alternate Setting Number
      0x02,                                  // Number of endpoints in this interface
      USB_HID_CLASS_CODE,                 // Class code
      USB_HID_SUBCLASS_CODE_NO_SUBCLASS , // Subclass code
      USB_HID_PROTOCOL_CODE_NONE,         // No Protocol
      0x00,                                  // Interface string index
  
      /* HID Class-Specific Descriptor */
  
      0x09,                           // Size of this descriptor in bytes
      USB_HID_DESCRIPTOR_TYPES_HID,   // HID descriptor type
      0x11,0x01,                      // HID Spec Release Number in BCD format (1.11)
      0x00,                           // Country Code (0x00 for Not supported)
      1,                              // Number of class descriptors
      USB_HID_DESCRIPTOR_TYPES_REPORT,// Report descriptor type
      USB_DEVICE_16bitTo8bitArrange(sizeof(hid_rpt0)),   // Size of the report descriptor
  
      /* Endpoint Descriptor */
  
      0x07,                           // Size of this descriptor in bytes
      USB_DESCRIPTOR_ENDPOINT,        // Endpoint Descriptor
      1 | USB_EP_DIRECTION_IN,    // EndpointAddress ( EP1 IN )
      USB_TRANSFER_TYPE_INTERRUPT,    // Attributes
      0x40,0x00,                      // Size
      0x01,                           // Interval
  
      /* Endpoint Descriptor */
  
      0x07,                           // Size of this descriptor in bytes
      USB_DESCRIPTOR_ENDPOINT,        // Endpoint Descriptor
      1 | USB_EP_DIRECTION_OUT,   // EndpointAddress ( EP1 OUT )
      USB_TRANSFER_TYPE_INTERRUPT,    // Attributes
      0x40,0x00,                      // size
      0x01,                           // Interval
      
      
  
  
  
  };
  
  /*******************************************
   * Array of Full speed Configuration 
   * descriptors
   *******************************************/
  USB_DEVICE_CONFIGURATION_DESCRIPTORS_TABLE fullSpeedConfigDescSet[1] =
  {
      fullSpeedConfigurationDescriptor
  };
  
  
  /**************************************
   *  String descriptors.
   *************************************/
   /*******************************************
   *  Language code string descriptor
   *******************************************/
      const struct
      {
          uint8_t bLength;
          uint8_t bDscType;
          uint16_t string[1];
      }
      sd000 =
      {
          sizeof(sd000),                                      // Size of this descriptor in bytes
          USB_DESCRIPTOR_STRING,                              // STRING descriptor type
          {0x0409}                                            // Language ID
      };
  /*******************************************
   *  Manufacturer string descriptor
   *******************************************/
      const struct
      {
          uint8_t bLength;                                    // Size of this descriptor in bytes
          uint8_t bDscType;                                   // STRING descriptor type
          uint16_t string[4];                                // String
      }
      sd001 =
      {
          sizeof(sd001),
          USB_DESCRIPTOR_STRING,
          {'Y','o','g','o'}
  		
      };
  
  /*******************************************
   *  Product string descriptor
   *******************************************/
  	const struct
      {
          uint8_t bLength;                                    // Size of this descriptor in bytes
          uint8_t bDscType;                                   // STRING descriptor type
          uint16_t string[24];                                // String
      }
      sd002 =
      {
          sizeof(sd002),
          USB_DESCRIPTOR_STRING,
  		{'Y','o','u','t','u','b','e',' ','M','e','d','i','a',' ','C','o','n','t','r','o','l','l','e','r'}
      }; 
  
  /***************************************
   * Array of string descriptors
   ***************************************/
  USB_DEVICE_STRING_DESCRIPTORS_TABLE stringDescriptors[3]=
  {
      (const uint8_t *const)&sd000,
      (const uint8_t *const)&sd001,
      (const uint8_t *const)&sd002,
  };
  
  /*******************************************
   * USB Device Layer Master Descriptor Table 
   *******************************************/
   
  const USB_DEVICE_MASTER_DESCRIPTOR usbMasterDescriptor =
  {
      &deviceDescriptor,                                      // Full speed descriptor
      1,                                                      // Total number of full speed configurations available
      fullSpeedConfigDescSet,                                 // Pointer to array of full speed configurations descriptors
  	NULL, 
  	0,
  	NULL,
  	3,  													// Total number of string descriptors available.
      stringDescriptors,                                      // Pointer to array of string descriptors.
  	NULL, 
  	NULL
  };
  
  
  /****************************************************
   * USB Device Layer Initialization Data
   ****************************************************/
  
  const USB_DEVICE_INIT usbDevInitData =
  {
      /* Number of function drivers registered to this instance of the
         USB device layer */
      .registeredFuncCount = 1,
  	
      /* Function driver table registered to this instance of the USB device layer*/
      .registeredFunctions = (USB_DEVICE_FUNCTION_REGISTRATION_TABLE*)funcRegistrationTable,
  
      /* Pointer to USB Descriptor structure */
      .usbMasterDescriptor = (USB_DEVICE_MASTER_DESCRIPTOR*)&usbMasterDescriptor,
  
      /* USB Device Speed */
  	.deviceSpeed =  USB_SPEED_FULL,
  	
  	/* Index of the USB Driver to be used by this Device Layer Instance */
      .driverIndex = DRV_USBFS_INDEX_0,
  
      /* Pointer to the USB Driver Functions. */
      .usbDriverInterface = DRV_USBFS_DEVICE_INTERFACE,
  	
  };
  // </editor-fold>
  