// Librería de descriptores HID modificadas para funcionar con la aplicación de Microchip.
#IFNDEF __USB_DESCRIPTORS__
#DEFINE __USB_DESCRIPTORS__
#include <usb.h> // Incluimos las funciones de control del puerto USB.
const char USB_CLASS_SPECIFIC_DESC[] = {
      6, 0, 255,       // Usage Page = Vendor Defined
      9, 1,            // Usage = IO device
      0xa1, 1,         // Collection = Application
      0x19, 1,         // Usage minimum
      0x29, 8,         // Usage maximum
      0x15, 0x80,        // Logical minimum (-128)
      0x25, 0x7F,        // Logical maximum (127)
      0x75, 8,        // Report size = 8 (bits)
      0x95, 2,        // Report count = 16 bits (2 bytes)
      0x81, 2,        // Input (Data, Var, Abs)
      0x19, 1,        // Usage minimum
      0x29, 8,        // Usage maximum
      0x75, 8,        // Report size = 8 (bits)
      0x95, 2,        // Report count = 16 bits (2 bytes)
      0x91, 2,        // Output (Data, Var, Abs)
      0xc0            // End Collection
   };
   // Descriptor extra.
   const int16 USB_CLASS_SPECIFIC_DESC_LOOKUP[USB_NUM_CONFIGURATIONS][1] =
   {
   //config 1
      //interface 0
         0
   };
   // Longitud del descriptor extra.
   const int16 USB_CLASS_SPECIFIC_DESC_LOOKUP_SIZE[USB_NUM_CONFIGURATIONS][1] =
   {
   //config 1
      //interface 0
         32
   };
//////////////////////////////////////////////////////////////////
/// Configuración de los diferentes descriptores.
//////////////////////////////////////////////////////////////////
   #DEFINE USB_TOTAL_CONFIG_LEN      41  // Longitud total de los descriptores.
   const char USB_CONFIG_DESC[] = {
  
   // Descriptor de configuración.
         USB_DESC_CONFIG_LEN, 
         USB_DESC_CONFIG_TYPE, 
         USB_TOTAL_CONFIG_LEN,0, 
         1, 
         0x01, 
         0x00, 
         0xC0, 
         0x32, // Corriente que va entregar el bus: 100mA (50mA * 2) (0x32mA*2)
   // Descriptor de interface.
         USB_DESC_INTERFACE_LEN, // Longitud del descriptor.
         USB_DESC_INTERFACE_TYPE, //Constante INTERFACE (INTERFACE 0x04)
         0x00, // Numero de definición de la interface (Si tenemos más de una interfaz)
         0x00, 
         2, // Número de endpoint's.
         0x03, // Código de clase: 0x03 = HID
         0x00, // Subcódigo de clase.
         0x00, // Protocolo de clase.
         0x00, // Descriptor específico para la interfaz.
   // Descriptor de la clase HID.
         USB_DESC_CLASS_LEN, // Longitud del descriptor.
         USB_DESC_CLASS_TYPE, // Tipo de descriptor (0x21 == HID)      
         0x00,0x01, // Versión de la clase HID: 1.0
         0x00, 
         0x01, 
         0x22, // Tipo de descriptor HID.
         USB_CLASS_SPECIFIC_DESC_LOOKUP_SIZE[0][0], 0x00, // Longitud del descriptor.
   // Descriptor del endpoint de salida.
         USB_DESC_ENDPOINT_LEN, // Longitud del descriptor.
         USB_DESC_ENDPOINT_TYPE, // Constante ENDPOINT. (ENDPOINT 0x05) 
         0x81, // Número del endpoint y dirección (0x81 = EP1 IN)       
         0x03, // Tipo de transferencia (0x03 = interruptiva)
         USB_EP1_TX_SIZE,0x00, // Tamaño del buffer de salida.
         10, // Intervalo de polling = 10ms.
   // Descriptor del endpoint de entrada.
         USB_DESC_ENDPOINT_LEN, // Longitud del descriptor.
         USB_DESC_ENDPOINT_TYPE, // Constante ENDPOINT. (ENDPOINT 0x05)          
         0x01, // Número del endpoint y dirección (0x01 = EP1 OUT).      
         0x03, // Tipo de transferencia (0x03 = interruptiva)
         USB_EP1_RX_SIZE,0x00, // Tamaño del buffer de entrada.
         10 // Intervalo de polling = 10ms.
   };
   #define USB_NUM_HID_INTERFACES   1 // Definimos el número de interfaces.
   #define USB_MAX_NUM_INTERFACES   1 // Definimos el número máximo de interfaces.
   const char USB_NUM_INTERFACES[USB_NUM_CONFIGURATIONS]={1};
   const int16 USB_CLASS_DESCRIPTORS[USB_NUM_CONFIGURATIONS][1][1]=
   {
   //config 1
      //interface 0
         //class 1
         18
   };
   #if (sizeof(USB_CONFIG_DESC) != USB_TOTAL_CONFIG_LEN)
      #error USB_TOTAL_CONFIG_LEN not defined correctly
   #endif
//////////////////////////////////////////////////////////////////
///
///   Descriptores del dispositivo
///
//////////////////////////////////////////////////////////////////
   const char USB_DEVICE_DESC[USB_DESC_DEVICE_LEN] ={
         USB_DESC_DEVICE_LEN, // Longitud del reporte.
         0x01, // Constante del dispositivo = 1
         0x10,0x01, // Versión del USB 1.10.
         0x00, // Código de clase.
         0x00, // Código de subclase.
         0x00, // Código de protocolo.
         USB_MAX_EP0_PACKET_LENGTH, // Tamaño máximo del paquete de datos del endpoint 0 = 8 para HID.
         0xD8,0x04, // Vendor  id =  decimal(1240), hexadecimal(04d8) // Identificadores de Microchip.
         0x3F,0x00, // Product id =  decimal(63), hexadecimal(003f)
         0x00,0x01, // Número del dispositivo.
         0x01, 
         0x02, 
         0x00, 
         USB_NUM_CONFIGURATIONS  // Número de posibles configuraciones.
   };
//////////////////////////////////////////////////////////////////
/// Descriptores del fabricante
//////////////////////////////////////////////////////////////////
char USB_STRING_DESC_OFFSET[]={0,4,12};
char const USB_STRING_DESC[]={
   // Primer descriptor.
         4, // Longitud del descriptor.
         USB_DESC_STRING_TYPE, 
         0x09,0x04,   // Lenguaje id = Inglés (Definido por microsoft).
   // Segundo descriptor.
         8, // Longitud del descriptor.
         USB_DESC_STRING_TYPE, // Descriptor del compilador utilizado. (STRING) (Puede ser el nombre de la compañía)
         'C',0,
         'C',0,
         'S',0,
   // Tercer descriptor.
         34, // Longitud del descriptor.
         USB_DESC_STRING_TYPE, // Descriptor del fabricante: MoyaPIC_HID_DEMO. (STRING)
         'M',0,
         'o',0,
         'y',0,
         'a',0,
         'P',0,
         'I',0,
         'C',0,
         '_',0,
         'H',0,
         'I',0,
         'D',0,
         '_',0,
         'D',0,
         'E',0,
         'M',0,
         'O',0
};
#ENDIF