Proton BASIC Compiler - USB HID Example


  • Pic® Basic


  • USB HID Examples

    Taken from Les's example.
    Using Proton IDE 3.5.5.6 and PDS_USB_HID_Wizard
    PIC18F2455 running on a breadboard using 4Mhz crystal module and 470nF capacitor from Vusb to ground.
    Data can be verified by using Harms HID Terminal also found on this Forum.
    The Proton Microchip USB Routines were downloaded from the Forums Update page and used in these examples.
    With thanks to the many people on the Forum for their help.
    Dick


    Example 1
    Type data on keyboard and receive on HID Terminal and RS232 terminal.

    [PHP]
    '************************************************* ***************
    '* Name : HID1.BAS *
    '* Author : [select VIEW...EDITOR OPTIONS] *
    '* Notice : Copyright (c) 2013 [select VIEW...EDITOR OPTIONS] *
    '* : All Rights Reserved *
    '* Date : 5/16/2013 *
    '* Version : 1.0 *
    '* Notes : Working *
    '* : An HID example by Les *
    '************************************************* ***************

    ' Demonstrate a USB generic HID interface using the Proton BASIC language
    ' The demonstration is configured to use a 4MHz crystal
    ' This can be changed by altering the fuse setting located in the USB_Defs.inc file
    '
    ;----------------------------------------------------------------------------
    ;**** Added by Fuse Configurator ****
    ; Use the Fuse Configurator plug-in to change these settings

    Device = 18F2455

    Declare Reminders Off
    @ CONFIG_REQ = 0 ; Override Compiler's configuration settings
    Asm-
    Config PLLDIV = 1 ;No prescale (4 MHz oscillator input drives PLL directly)
    Config CPUDIV = OSC1_PLL2 ;[Primary Oscillator Src: /1][96 MHz PLL Src: /2]

    Config USBDIV = 2 ;USB clock source comes from the 96 MHz PLL divided by 2
    Config FOSC = XTPLL_XT ;XT oscillator, PLL enabled (XTPLL)
    Config FCMEN = OFF ;Fail-Safe Clock Monitor disabled
    Config IESO = OFF ;Oscillator Switchover mode disabled
    Config PWRT = OFF ;PWRT disabled
    Config BOR = On ;Brown-out Reset enabled in hardware only (SBOREN is disabled)
    Config BORV = 3 ;Minimum setting
    Config VREGEN = On ;USB voltage regulator enabled
    Config WDT = OFF ;WDT disabled (control is placed on the SWDTEN bit)
    Config WDTPS = 32768 ;1:32768
    Config CCP2MX = On ;CCP2 input/output is multiplexed with RC1
    Config PBADEN = OFF ;PORTB<4:0> pins are configured as digital I/O on Reset
    Config LPT1OSC = OFF ;Timer1 configured for higher power operation
    Config MCLRE = On ;MCLR pin enabled; RE3 input pin disabled
    Config STVREN = On ;Stack full/underflow will cause Reset
    Config LVP = Off ;Single-Supply ICSP disabled
    Config XINST = OFF ;Instruction set extension and Indexed Addressing mode disabled (Legacy mode)
    Config Debug = OFF ;Background debugger disabled, RB6 and RB7 configured as general purpose I/O pins
    Config CP0 = OFF ;Block 0 (000800-001FFFh) is not code-protected
    Config CP1 = OFF ;Block 1 (002000-003FFFh) is not code-protected
    Config CP2 = OFF ;Block 2 (004000-005FFFh) is not code-protected
    Config CPB = OFF ;Boot block (000000-0007FFh) is not code-protected
    Config CPD = OFF ;Data EEPROM is not code-protected
    Config WRT0 = OFF ;Block 0 (000800-001FFFh) is not write-protected
    Config WRT1 = OFF ;Block 1 (002000-003FFFh) is not write-protected
    Config WRT2 = OFF ;Block 2 (004000-005FFFh) is not write-protected
    Config WRTC = OFF ;Configuration registers (300000-3000FFh) are not write-protected
    Config WRTB = OFF ;Boot block (000000-0007FFh) is not write-protected
    Config WRTD = OFF ;Data EEPROM is not write-protected
    Config EBTR0 = OFF ;Block 0 (000800-001FFFh) is not protected from table reads executed in other blocks
    Config EBTR1 = OFF ;Block 1 (002000-003FFFh) is not protected from table reads executed in other blocks
    Config EBTR2 = OFF ;Block 2 (004000-005FFFh) is not protected from table reads executed in other blocks
    Config EBTRB = OFF ;Boot block (000000-0007FFh) is not protected from table reads executed in other blocks
    Endasm-
    Declare Reminders On

    ;**** End of Fuse Configurator Settings ****
    ;----------------------------------------------------------------------------
    Declare Xtal = 48 ' Using 4Mhz Ext Xtal and PLL/2 [96/2]Mhz
    '


    Declare Reminders = Off
    Declare Optimiser_Level = 3 ' Maximum optimisation
    Declare Dead_Code_Remove = On ' Squeeze the code further

    ;Calculated Baudrate = 57692 @ Xtal 48MHz, Error = 0.16%
    Declare Hserial_RCSTA = 144 ; Enable continuous receive
    Declare Hserial_TXSTA = 32 ; Enable transmit, BRGH = 0
    Declare Hserial_SPBRG = 12 ; Baud Rate Generator Value
    Declare Hserial_Clear = On ; Clear overflow automatically


    Dim Buffer As String * 20
    Dim bAmount As Byte
    '
    '--------------------------------------------------------------------------
    Include "HID1_WIZ.inc"
    ' Load the USB routines and descriptor into the program
    '--------------------------------------------------------------------------

    Main:

    While 1 = 1 ' Create an infinite loop
    If tUSB_Attached = True Then ' Is the USB attached?
    If HID_DataAvailable() = True Then ' Yes. So is there any USB data for us?
    HID_ReadReport() ' Yes. So receive it
    HRSOut RXReport ' Transmit the data received to the serial terminal
    TXReport = RXReport ' Transfer RX buffer to TX buffer
    HID_WriteReport() ' Echo back the data received
    EndIf
    EndIf
    Wend

    [/PHP]

    HID1_WIZ.inc file

    [PHP]
    HID1_WIZ.inc
    ' USB HID descriptor generated by PDS USB_HID_Wizard, version 0.1.3.3
    ' Do not change the order of the commands and directives
    ' Place any $defines here. i.e. before the loading of USB_MemAlloc.inc
    ' See USB_Defs.inc for the defines used
    '
    $define USB_VID 6017
    $define USB_PID 2001
    $define HID_BUFFER_SIZE 64
    $define USB_BUS_POWER 50
    $define USB_DEVICE_VERSION 1
    $define USB_HAVE_SERIAL_STRING 1
    '
    $define USB_SERVICE
    $define USB_USE_HID
    $define HID_EP_OUT_POLLING_MS 1
    $define HID_EP_IN_POLLING_MS 1
    '
    $define HID_INTF_ID $00
    $define HID_EP 1
    $define HID_INT_OUT_EP_SIZE 64
    $define HID_INT_IN_EP_SIZE 64
    $define HID_NUM_OF_DSC 1
    '
    '--------------------------------------------------------
    '
    Include "USB_MemAlloc.inc" '** Load the USB Stack and Dual Port RAM variable definitions **
    '
    '--------------------------------------------------------
    '
    '--------------------------------------------------------
    '
    GoTo OverDescriptorTables ' Jump over the descriptor tables
    '
    '---------------------------------------------------------------------------------------------------------
    '
    $define HID_RPT01_SIZE 47 ' Size of "hid_rpt01" table
    '
    ' This section may be modified to suit your requirements
    ' Do not change any of the label names, or the format of the tables
    '
    device_dsc:
    CData SizeOf_Table,_ ' Size of this descriptor (in bytes)
    USB_DESCRIPTOR_DEVICE,_ ' device descriptor type
    $02, $00,_ ' USB Spec Release Number in BCD format (low byte, high byte)
    $00,_ ' Class Code
    $00,_ ' Subclass code
    $00,_ ' Protocol code
    USB_EP0_BUFF_SIZE,_ ' Max packet size For EP0
    USB_VID & $FF, USB_VID >> 8,_ ' Vendor ID (low byte, byte byte)
    USB_PID & $FF, USB_PID >> 8,_ ' Product ID (low byte, high byte)
    USB_DEVICE_VERSION & $FF,_ ' Device release number in BCD format (low byte)
    USB_DEVICE_VERSION >> 8,_ ' Device release number in BCD format (high byte)
    USB_MANUFACTURER_INDEX,_ ' Manufacturer String index
    USB_PRODUCT_INDEX,_ ' Product String index
    USB_SERIAL_INDEX,_ ' Device serial number String index
    $01 ' Number of possible configurations
    '
    ' Configuration Descriptor
    '
    configDescriptor1:
    CData $09,_ ' Size of this section of the descriptor (in bytes)
    USB_DESCRIPTOR_CONFIGURATION,_ ' Configuration descriptor type
    SizeOf_Table, $00,_ ' Size Of "configDescriptor1" table - Total length of data (low byte, high byte)
    $01,_ ' Number of interfaces in this cfg
    $01,_ ' Index value of this configuration
    $00,_ ' Configuration string index
    _DEFAULT | _RWU,_ ' Attributes, see USB_Defs.inc
    USB_BUS_POWER,_ ' Max power consumption (2X mA)
    '
    ' Interface descriptor
    '
    $09,_ ' Size of this section of the descriptor (in bytes)
    USB_DESCRIPTOR_INTERFACE,_ ' Interface descriptor type
    $00,_ ' Interface Number
    $00,_ ' Alternate Setting Number
    $02,_ ' Number of endpoints in this intf
    HID_INTF,_ ' Class code
    $00,_ ' Subclass code
    $00,_ ' Protocol code
    $00,_ ' Interface string index
    '
    ' HID class-specific descriptor
    '
    $09,_ ' Size of this section of the descriptor (in bytes)
    DSC_HID,_ ' HID descriptor type
    $10, $01,_ ' HID Spec Release Number in BCD format (low byte, high byte)
    $00,_ ' Country Code (0x00 for Not supported)
    HID_NUM_OF_DSC,_ ' Number of class descriptors
    DSC_RPT,_ ' Report descriptor type
    HID_RPT01_SIZE, $00,_ ' Size of "hid_rpt01" table (low byte, high byte)
    '
    ' Endpoint descriptor (IN)
    '
    $07,_ ' Size of this section of the descriptor (in bytes)
    USB_DESCRIPTOR_ENDPOINT,_ ' Endpoint descriptor type
    _EP01_IN,_ ' Endpoint 1 In
    _INTERRUPT,_ ' Interrupt transfers
    HID_INT_IN_EP_SIZE, $00,_ ' Maximum packet size (low byte, high byte)
    HID_EP_IN_POLLING_MS,_ ' Polling interval (milliseconds)
    '
    ' Enpoint descriptor (OUT)
    '
    $07,_ ' Size of This section of the descriptor (in bytes)
    USB_DESCRIPTOR_ENDPOINT,_ ' Endpoint descriptor type
    _EP01_OUT,_ ' Endpoint 1 Out
    _INTERRUPT,_ ' Interrupt transfers
    HID_INT_OUT_EP_SIZE, $00,_ ' Maximum packet size (low byte, high byte)
    HID_EP_OUT_POLLING_MS ' Polling interval (milliseconds)
    '
    ' Language string - unicode format
    '
    sd000:
    CData Byte SizeOf_Table,_ ' Size of this descriptor (in bytes)
    Byte USB_DESCRIPTOR_STRING,_ ' Descriptor Type
    Word $0904 ' language ID - (high byte, low byte)
    '
    ' Manufacturer string - unicode format
    '
    sd001:
    CData Byte SizeOf_Table,_ ' Size of this descriptor (in bytes)
    Byte USB_DESCRIPTOR_STRING,_ ' Descriptor Type
    Word "China"
    '
    ' Product string - unicode format
    '
    sd002:
    CData Byte SizeOf_Table,_ ' Size of this descriptor (in bytes)
    Byte USB_DESCRIPTOR_STRING,_ ' Descriptor Type
    Word "Terminal"

    $ifdef USB_HAVE_SERIAL_STRING
    sd003:
    CData Byte SizeOf_Table,_ ' Size of this descriptor (in bytes)
    Byte USB_DESCRIPTOR_STRING,_ ' Descriptor Type
    Word "12345"
    $endif
    '
    ' This example report descriptor for a generic HID defines one report of each type.
    ' Each report contains two bytes of data with a vendor-defined Usage.
    '
    hid_rpt01:
    CData $06, $A0, $FF,_ ' Usage page (vendor defined)
    $09, $01,_ ' Usage ID (vendor defined)
    $A1, $01,_ ' Collection (application)
    '
    ' The Input report:
    '
    $09, $03,_ ' Usage ID - vendor defined
    $15, $00,_ ' Logical Minimum (0)
    $26, $FF, $00,_ ' Logical Maximum (255)
    $75, $08,_ ' Report Size (8 bits)
    $95, HID_REPORT_BYTES_IN,_ ' Report Count (2 fields)
    $81, $02,_ ' Input (Data, Variable, Absolute)
    '
    ' The Output report:
    '
    $09, $04,_ ' Usage ID - vendor defined
    $15, $00,_ ' Logical Minimum (0)
    $26, $FF, $00,_ ' Logical Maximum (255)
    $75, $08,_ ' Report Size (8 bits)
    $95, HID_REPORT_BYTES_OUT,_ ' Report Count (2 fields)
    $91, $02,_ ' Output (Data, Variable, Absolute)
    '
    ' The Feature report:
    '
    $09, $05,_ ' Usage ID - vendor defined
    $15, $00,_ ' Logical Minimum (0)
    $26, $FF, $00,_ ' Logical Maximum (255)
    $75, $08,_ ' Report Size (8 bits)
    $95, $02,_ ' Report Count (2 fields)
    $B1, $02,_ ' Feature (Data, Variable, Absolute)
    $C0 ' end collection
    '
    '---------------------------------------------------------------------------------------------------------
    '
    USB_CD_Pointer:
    CData configDescriptor1, configDescriptor1 ' Create a pointer to the descriptor's cfg tables

    USB_SD_Pointer:
    $ifdef USB_HAVE_SERIAL_STRING
    CData sd000, sd001, sd002, sd003 ' Create a pointer to the descriptor's sd tables(with serial)
    $else
    CData sd000, sd001, sd002 ' Create a pointer to the descriptor's sd tables (without serial)
    $endif

    OverDescriptorTables:
    Include "USB_System.inc" ' ** Load the USB routines into the program **

    $ifdef USB_USE_HID
    Include "USB_UserHID.inc" ' ** Load the User HID routines into the program (if a HID interface is being used)
    $endif

    [/PHP]

    Example 2
    Read ADC and send result to HID Terminal and RS232 Terminal.

    [PHP]
    '************************************************* ***************
    '* Name : TestHID.BAS *
    '* Author : [select VIEW...EDITOR OPTIONS] *
    '* Notice : Copyright (c) 2013 [select VIEW...EDITOR OPTIONS] *
    '* : All Rights Reserved *
    '* Date : 5 May 2013 *
    '* Version : 1.0 *
    '* Notes : 18F2455 PROTON PLUS Compiler 3.5.5.6 *
    '* : 4Mhz Crystal Module, 470nF Vusb -> GND *
    '* : *
    '************************************************* ***************

    ' Using 4Mhz Crystal Osc Module
    ' Demonstrate a USB generic HID interface using the Proton BASIC language
    '
    ' The demonstration is configured to use a 4MHz crystal
    ' This can be changed by altering the fuse setting located in the USB_Defs.inc file
    '
    ;-------------------------------------------------------------------------------
    ;**** Added by Fuse Configurator ****
    ; Use the Fuse Configurator plug-in to change these settings

    ;-------------------------------------------------------------------------------
    ;**** Added by Fuse Configurator ****
    ; Use the Fuse Configurator plug-in to change these settings

    Device = 18F2455


    Declare Reminders Off
    @ CONFIG_REQ = 0 ; Override Compiler's configuration settings
    Asm-
    Config PLLDIV = 1 ;No prescale (4 MHz oscillator input drives PLL directly)
    Config CPUDIV = OSC1_PLL2 ;[Primary Oscillator Src: /1][96 MHz PLL Src: /2]
    Config USBDIV = 2 ;USB clock source comes from the 96 MHz PLL divided by 2
    Config FOSC = XTPLL_XT ;XT oscillator, PLL enabled (XTPLL)
    Config FCMEN = OFF ;Fail-Safe Clock Monitor disabled
    Config IESO = OFF ;Oscillator Switchover mode disabled
    Config PWRT = OFF ;PWRT disabled
    Config BOR = On ;Brown-out Reset enabled in hardware only (SBOREN is disabled)
    Config BORV = 3 ;Minimum setting
    Config VREGEN = On ;USB voltage regulator enabled
    Config WDT = OFF ;WDT disabled (control is placed on the SWDTEN bit)
    Config WDTPS = 32768 ;1:32768
    Config CCP2MX = On ;CCP2 input/output is multiplexed with RC1
    Config PBADEN = OFF ;PORTB<4:0> pins are configured as digital I/O on Reset
    Config LPT1OSC = OFF ;Timer1 configured for higher power operation
    Config MCLRE = On ;MCLR pin enabled; RE3 input pin disabled
    Config STVREN = On ;Stack full/underflow will cause Reset
    Config LVP = OFF ;Single-Supply ICSP disabled
    Config XINST = OFF ;Instruction set extension and Indexed Addressing mode disabled (Legacy mode)
    Config Debug = OFF ;Background debugger disabled, RB6 and RB7 configured as general purpose I/O pins
    Config CP0 = OFF ;Block 0 (000800-001FFFh) is not code-protected
    Config CP1 = OFF ;Block 1 (002000-003FFFh) is not code-protected
    Config CP2 = OFF ;Block 2 (004000-005FFFh) is not code-protected
    Config CPB = OFF ;Boot block (000000-0007FFh) is not code-protected
    Config CPD = OFF ;Data EEPROM is not code-protected
    Config WRT0 = OFF ;Block 0 (000800-001FFFh) is not write-protected
    Config WRT1 = OFF ;Block 1 (002000-003FFFh) is not write-protected
    Config WRT2 = OFF ;Block 2 (004000-005FFFh) is not write-protected
    Config WRTC = OFF ;Configuration registers (300000-3000FFh) are not write-protected
    Config WRTB = OFF ;Boot block (000000-0007FFh) is not write-protected
    Config WRTD = OFF ;Data EEPROM is not write-protected
    Config EBTR0 = OFF ;Block 0 (000800-001FFFh) is not protected from table reads executed in other blocks
    Config EBTR1 = OFF ;Block 1 (002000-003FFFh) is not protected from table reads executed in other blocks
    Config EBTR2 = OFF ;Block 2 (004000-005FFFh) is not protected from table reads executed in other blocks
    Config EBTRB = OFF ;Boot block (000000-0007FFh) is not protected from table reads executed in other blocks
    Endasm-
    Declare Reminders On

    ;**** End of Fuse Configurator Settings ****
    ;-------------------------------------------------------------------------------
    Declare Xtal = 48 ' Using 8Mhz Ext Xtal and PLL/2 [96/2]Mhz for internal clock
    Declare Optimiser_Level = 3 ' Maximum optimisation
    Declare Dead_Code_Remove = On ' Squeeze the code further
    '
    '


    ;Calculated Baudrate = 115385 @ Xtal 48MHz, Error = 0.16%
    Declare Hserial_RCSTA = 144 ; Enable continuous receive
    Declare Hserial_TXSTA = 32 ; Enable transmit, BRGH = 0
    Declare Hserial_Clear = On ; Clear overflow automatically
    Declare Hserial_SPBRG = 25 ; Baud Rate Generator Low Byte Value
    SPBRGH = 0 ; Baud Rate Generator High Byte Value
    BAUDCON.3 = 1 ; Enable the 16 bit Baud Rate Generator
    '
    '
    '
    'ADC Setup
    TRISA = %00000001 ' All Outputs except AN0
    CMCON = 7 ' Compartors OFF
    ADCON0 = %00000001 ' Select ADC Chan 0, ADC ON
    ADCON1 = %00001110 ' AN0 Analog - remainder digital
    ADCON2 = %11110110 '
    '
    '
    '
    ' GP Registers
    Dim Char As Byte '
    Dim ADVAL As Word ' ADC value
    Dim Buffer As String * 20 '
    Dim bAmount As Byte '
    Dim Fvolts As Float '
    '
    UCFG.4 = 1 ' Enable pullup
    ' UCFG.2 = 1 ' Full speed
    '--------------------------------------------------------------------------
    Include "TestHid.inc" ' Load the USB routines and descriptor into the program
    '--------------------------------------------------------------------------

    Main:

    While 1 = 1 ' Create an infinite loop
    If tUSB_Attached = True Then ' Is the USB attached?
    ' If HID_DataAvailable() = True Then ' Yes. So is there any USB data for us?
    ' HID_ReadReport() ' Yes. So receive it
    ADVAL = ADIn 0 ' Read the ADC
    DelayUS 50 '
    '
    Fvolts = (ADVAL * 0.004883)
    HSerOut [ Dec2 Fvolts," Volts",10,13] ' Transmit the data received to the serial terminal
    Buffer = Str$(Dec2,Fvolts) + " Volts\n\r" ' Convert the value into a string
    '
    TXReport = Buffer '
    HID_WriteReport() ' Echo back the data received
    Clear RXReport '
    Clear TXReport ' Clear buffers
    DelayMS 1000 '
    EndIf '
    Wend '

    End

    [/PHP]

    TestHID.inc
    [PHP]
    USB HID descriptor generated by PDS USB_HID_Wizard, version 0.1.3.3
    '
    ' Do not change the order of the commands and directives
    '
    ' Place any $defines here. i.e. before the loading of USB_MemAlloc.inc
    ' See USB_Defs.inc for the defines used
    '
    $define USB_VID 6017
    $define USB_PID 2001
    $define HID_BUFFER_SIZE 64
    $define USB_BUS_POWER 50
    $define USB_DEVICE_VERSION 1
    $define USB_HAVE_SERIAL_STRING 1
    '
    $define USB_SERVICE
    $define USB_USE_HID
    $define HID_EP_OUT_POLLING_MS 1
    $define HID_EP_IN_POLLING_MS 1
    '
    $define HID_INTF_ID $00
    $define HID_EP 1
    $define HID_INT_OUT_EP_SIZE 64
    $define HID_INT_IN_EP_SIZE 64
    $define HID_NUM_OF_DSC 1
    '
    '--------------------------------------------------------
    '
    Include "USB_MemAlloc.inc" '** Load the USB Stack and Dual Port RAM variable definitions **
    '
    '--------------------------------------------------------
    '
    '--------------------------------------------------------
    '
    GoTo OverDescriptorTables ' Jump over the descriptor tables
    '
    '---------------------------------------------------------------------------------------------------------
    '
    $define HID_RPT01_SIZE 47 ' Size of "hid_rpt01" table
    '
    ' This section may be modified to suit your requirements
    ' Do not change any of the label names, or the format of the tables
    '
    device_dsc:
    CData SizeOf_Table,_ ' Size of this descriptor (in bytes)
    USB_DESCRIPTOR_DEVICE,_ ' device descriptor type
    $02, $00,_ ' USB Spec Release Number in BCD format (low byte, high byte)
    $00,_ ' Class Code
    $00,_ ' Subclass code
    $00,_ ' Protocol code
    USB_EP0_BUFF_SIZE,_ ' Max packet size For EP0
    USB_VID & $FF, USB_VID >> 8,_ ' Vendor ID (low byte, byte byte)
    USB_PID & $FF, USB_PID >> 8,_ ' Product ID (low byte, high byte)
    USB_DEVICE_VERSION & $FF,_ ' Device release number in BCD format (low byte)
    USB_DEVICE_VERSION >> 8,_ ' Device release number in BCD format (high byte)
    USB_MANUFACTURER_INDEX,_ ' Manufacturer String index
    USB_PRODUCT_INDEX,_ ' Product String index
    USB_SERIAL_INDEX,_ ' Device serial number String index
    $01 ' Number of possible configurations
    '
    ' Configuration Descriptor
    '
    configDescriptor1:
    CData $09,_ ' Size of this section of the descriptor (in bytes)
    USB_DESCRIPTOR_CONFIGURATION,_ ' Configuration descriptor type
    SizeOf_Table, $00,_ ' Size Of "configDescriptor1" table - Total length of data (low byte, high byte)
    $01,_ ' Number of interfaces in this cfg
    $01,_ ' Index value of this configuration
    $00,_ ' Configuration string index
    _DEFAULT | _RWU,_ ' Attributes, see USB_Defs.inc
    USB_BUS_POWER,_ ' Max power consumption (2X mA)
    '
    ' Interface descriptor
    '
    $09,_ ' Size of this section of the descriptor (in bytes)
    USB_DESCRIPTOR_INTERFACE,_ ' Interface descriptor type
    $00,_ ' Interface Number
    $00,_ ' Alternate Setting Number
    $02,_ ' Number of endpoints in this intf
    HID_INTF,_ ' Class code
    $00,_ ' Subclass code
    $00,_ ' Protocol code
    $00,_ ' Interface string index
    '
    ' HID class-specific descriptor
    '
    $09,_ ' Size of this section of the descriptor (in bytes)
    DSC_HID,_ ' HID descriptor type
    $10, $01,_ ' HID Spec Release Number in BCD format (low byte, high byte)
    $00,_ ' Country Code (0x00 for Not supported)
    HID_NUM_OF_DSC,_ ' Number of class descriptors
    DSC_RPT,_ ' Report descriptor type
    HID_RPT01_SIZE, $00,_ ' Size of "hid_rpt01" table (low byte, high byte)
    '
    ' Endpoint descriptor (IN)
    '
    $07,_ ' Size of this section of the descriptor (in bytes)
    USB_DESCRIPTOR_ENDPOINT,_ ' Endpoint descriptor type
    _EP01_IN,_ ' Endpoint 1 In
    _INTERRUPT,_ ' Interrupt transfers
    HID_INT_IN_EP_SIZE, $00,_ ' Maximum packet size (low byte, high byte)
    HID_EP_IN_POLLING_MS,_ ' Polling interval (milliseconds)
    '
    ' Enpoint descriptor (OUT)
    '
    $07,_ ' Size of This section of the descriptor (in bytes)
    USB_DESCRIPTOR_ENDPOINT,_ ' Endpoint descriptor type
    _EP01_OUT,_ ' Endpoint 1 Out
    _INTERRUPT,_ ' Interrupt transfers
    HID_INT_OUT_EP_SIZE, $00,_ ' Maximum packet size (low byte, high byte)
    HID_EP_OUT_POLLING_MS ' Polling interval (milliseconds)
    '
    ' Language string - unicode format
    '
    sd000:
    CData Byte SizeOf_Table,_ ' Size of this descriptor (in bytes)
    Byte USB_DESCRIPTOR_STRING,_ ' Descriptor Type
    Word $0904 ' language ID - (high byte, low byte)
    '
    ' Manufacturer string - unicode format
    '
    sd001:
    CData Byte SizeOf_Table,_ ' Size of this descriptor (in bytes)
    Byte USB_DESCRIPTOR_STRING,_ ' Descriptor Type
    Word "Topsy Turvy"
    '
    ' Product string - unicode format
    '
    sd002:
    CData Byte SizeOf_Table,_ ' Size of this descriptor (in bytes)
    Byte USB_DESCRIPTOR_STRING,_ ' Descriptor Type
    Word "TempSens2"

    $ifdef USB_HAVE_SERIAL_STRING
    sd003:
    CData Byte SizeOf_Table,_ ' Size of this descriptor (in bytes)
    Byte USB_DESCRIPTOR_STRING,_ ' Descriptor Type
    Word "1"
    $endif
    '
    ' This example report descriptor for a generic HID defines one report of each type.
    ' Each report contains two bytes of data with a vendor-defined Usage.
    '
    hid_rpt01:
    CData $06, $A0, $FF,_ ' Usage page (vendor defined)
    $09, $01,_ ' Usage ID (vendor defined)

    $A1, $01,_ ' Collection (application)
    '
    ' The Input report:
    '
    $09, $03,_ ' Usage ID - vendor defined
    $15, $00,_ ' Logical Minimum (0)
    $26, $FF, $00,_ ' Logical Maximum (255)
    $75, $08,_ ' Report Size (8 bits)
    $95, HID_REPORT_BYTES_IN,_ ' Report Count (2 fields)
    $81, $02,_ ' Input (Data, Variable, Absolute)
    '
    ' The Output report:
    '
    $09, $04,_ ' Usage ID - vendor defined
    $15, $00,_ ' Logical Minimum (0)
    $26, $FF, $00,_ ' Logical Maximum (255)
    $75, $08,_ ' Report Size (8 bits)
    $95, HID_REPORT_BYTES_OUT,_ ' Report Count (2 fields)
    $91, $02,_ ' Output (Data, Variable, Absolute)
    '
    ' The Feature report:
    '
    $09, $05,_ ' Usage ID - vendor defined
    $15, $00,_ ' Logical Minimum (0)
    $26, $FF, $00,_ ' Logical Maximum (255)
    $75, $08,_ ' Report Size (8 bits)
    $95, $02,_ ' Report Count (2 fields)
    $B1, $02,_ ' Feature (Data, Variable, Absolute)
    $C0 ' end collection
    '
    '---------------------------------------------------------------------------------------------------------
    '
    USB_CD_Pointer:
    CData configDescriptor1, configDescriptor1 ' Create a pointer to the descriptor's cfg tables

    USB_SD_Pointer:
    $ifdef USB_HAVE_SERIAL_STRING
    CData sd000, sd001, sd002, sd003 ' Create a pointer to the descriptor's sd tables(with serial)
    $else
    CData sd000, sd001, sd002 ' Create a pointer to the descriptor's sd tables (without serial)
    $endif

    OverDescriptorTables:
    Include "USB_System.inc" ' ** Load the USB routines into the program **


    $ifdef USB_USE_HID
    Include "USB_UserHID.inc" ' ** Load the User HID routines into the program (if a HID interface is being used)
    $endif
    [/PHP]