Professional Documents
Culture Documents
Const Mdbg = 1 ' if you want to see all USB communication turn it on but turin it off
(0) for your application since it will cost space
Const Chiddevice = 1 ' set this on for HID devices
Config Clockdiv = 1 ' we let the internal clock divider divide by 1 which will result in 8 Mhz clock
Config Com1 = Dummy , Synchrone = 0 , Parity = None , Stopbits = 1 , Databits = 8 , Clockpol = 0
Const Nb_interface = 1
Const Conf_nb = 1
Const Conf_index = 0
Const Conf_attributes = Usb_config_buspowered
Const Max_power = 50 ' 100 mA
Const Interface_nb_mouse = 0
Const Alternate_mouse = 0
Const Nb_endpoint_mouse = 1
Const Interface_class_mouse = 3 ' HID Class
Const Interface_sub_class_mouse = 1 ' Sub Class is Mouse
Const Interface_protocol_mouse = 2 ' Mouse
Const Interface_index_mouse = 0
Const Nb_endpoints = 2 ' number of endpoints in the application including control endpoint
Const Ep_kbd_in = 1 ' Number of the mouse interrupt IN endpoint
Const Ep_hid_in = 1
Const Ep_hid_out = 2
Config Usb = Device , Language = &H0409 , Manufact = "MCS" , Product = "MCSHID162" , Serial = "MC0001"
If Dummy1 = &H55 And Dummy2 = &HAA Then ' Check if we received DFU mode command from host
Usb_detach ' Detach Actual Generic Hid Application
Waitms 500
Goto &H1800 'goto bootloader
'here you could call the bootloader then
End If
Usb_select_endpoint Ep_hid_in ' Ready to send these information to the host application
If Ueintx.txini = 1 Then ' Is_usb_in_ready())
Uedatx = 1
Uedatx = 2
Uedatx = 3
Uedatx = 4
Uedatx = 5
Uedatx = 6
Uedatx = 7
Uedatx = 8
Usb_ack_fifocon ' Send data over the USB
End If
End If
End Sub
'usb_init_device.
'This function initializes the USB device controller and
'configures the Default Control Endpoint.
Sub Usb_init_device()
#if Usbfunc
Usb_select_device
#endif
#if Usbfunc
If Usbsta.id = 1 Then 'is it an USB device?
#endif
Uenum = Ep_control ' select USB endpoint
If Ueconx.epen = 0 Then ' usb endpoint not enabled yet
Call Usb_configure_endpoint(ep_control , Type_control , Direction_out , Size_32 , One_bank , Nyet_disabled)
End If
#if Usbfunc
End If
#endif
End Sub
Usb_conf_desc:
Data 9 , Configuration_descriptor ' length , CONFIGURATION descriptor
Data User_conf_size% ' total length of data returned
Data Nb_interface , Conf_nb ' number of interfaces for this conf. , value for SetConfiguration resquest
Data Conf_index , Conf_attributes ' index of string descriptor , Configuration characteristics
Data Max_power ' maximum power consumption
Data 7 , Endpoint_descriptor ' Size Of This Descriptor In Bytes , ENDPOINT descriptor type
Data Endpoint_nb_1 , Ep_attributes_1 ' Address of the endpoint ,Endpoint's attributes
Data Ep_size_1% ' Maximum packet size for this EP , Interval for polling EP in ms
Data Ep_interval_1
Data 7 , Endpoint_descriptor ' Size Of This Descriptor In Bytes , ENDPOINT descriptor type
Data Endpoint_nb_2 , Ep_attributes_2 ' Address of the endpoint , Endpoint's attributes
Data Ep_size_2% ' Maximum packet size for this EP
Data Ep_interval_2 ' Interval for polling EP in ms
Usb_hid_report:
Data &H06 , &HFF , &HFF ' 04|2 , Usage Page (vendordefined?)
Data &H09 , &H01 ' 08|1 , Usage (vendordefined
Data &HA1 , &H01 ' A0|1 , Collection (Application)
' // IN report
Data &H09 , &H02 ' 08|1 , Usage (vendordefined)
Data &H09 , &H03 ' 08|1 , Usage (vendordefined)
Data &H15 , &H00 ' 14|1 , Logical Minimum(0 for signed byte?)
Data &H26 , &HFF , &H00 ' 24|1 , Logical Maximum(255 for signed byte?)
Data &H75 , &H08 ' 74|1 , Report Size(8) = field size in bits = 1 byte
Data &H95 , Length_of_report_in ' 94|1:ReportCount(size) = repeat count of previous item
Data &H81 , &H02 ' 80|1: IN report (Data,Variable, Absolute)
' // OUT report
Data &H09 , &H04 ' 08|1 , Usage (vendordefined)
Data &H09 , &H05 ' 08|1 , Usage (vendordefined)
Data &H15 , &H00 ' 14|1 , Logical Minimum(0 for signed byte?)
Data &H26 , &HFF , &H00 ' 24|1 , Logical Maximum(255 for signed byte?)
Data &H75 , &H08 ' 74|1 , Report Size(8) = field size in bits = 1 byte
Data &H95 , Length_of_report_out ' 94|1:ReportCount(size) = repeat count of previous item
Data &H91 , &H02 ' 90|1: OUT report (Data,Variable, Absolute)
' // Feature report
Data &H09 , &H06 ' 08|1 , Usage (vendordefined)
Data &H09 , &H07 ' 08|1 , Usage (vendordefined)
Data &H15 , &H00 ' 14|1 , LogicalMinimum(0 for signed byte)
Data &H26 , &HFF , &H00 ' 24|1 , Logical Maximum(255 for signed byte)
Data &H75 , &H08 ' 74|1 , Report Size(8) =field size in bits = 1 byte
Data &H95 , &H04 ' 94|1:ReportCount
Data &HB1 , &H02 ' B0|1: Feature report
Data &HC0 ' C0|0 , End Collection