HID Mouse
HID Mouse
Hello,
I am new to HID and I have a question on HID Mouse communication.
I was able to modify the MikroBasic builtin HID example and successfully use it for PIC2550. But my problem is that when I change my descriptor file to a mouse descriptor, I get an error on detecting the HID interface in Winxp.
I would appriciate so much if someone can share some knowledge on HID mouse communication with me.
I am using Mikrobasic and PIC2550. My OS is Winxp.
Thanks,
Arin
I am new to HID and I have a question on HID Mouse communication.
I was able to modify the MikroBasic builtin HID example and successfully use it for PIC2550. But my problem is that when I change my descriptor file to a mouse descriptor, I get an error on detecting the HID interface in Winxp.
I would appriciate so much if someone can share some knowledge on HID mouse communication with me.
I am using Mikrobasic and PIC2550. My OS is Winxp.
Thanks,
Arin
look.
http://users.edpnet.be/rosseel01/DRO/PIC/index.htm?
Uses, my liby in C ansi.
read the comments.
Then I made an example of mouse, joystick etc.
http://users.edpnet.be/rosseel01/DRO/PIC/index.htm?
Uses, my liby in C ansi.
read the comments.
Then I made an example of mouse, joystick etc.
Hi Fabim,
Thank you very much for replying to my post. I have already checked the link you sent me. Currently, I am able to send and receive data to pc using hid. My main issue is that I am not sure why my mouse program does not connect correctly. Here is my code. I hope this helps you more. Thanks very much for all your help.
program USB_HID_test
include "USBdsc"
dim
k, i, ch ,j ,read as byte
userWR_buffer as byte[3]
userRD_buffer as byte[1]
text as string
temp_res as word
'******************************************************************************
' Main Interrupt Routine
'******************************************************************************
sub procedure interrupt
'** this is a way to call a procedure from interrupt
HID_InterruptProc
k = HID_Read()
i = 0
while i < k
ch = userRD_buffer[0]
userWR_buffer[0] =0x01 'sending left click message to test the interface
userWR_buffer[1] =0x00
userWR_buffer[2]=0x00
HID_Write(@userWR_buffer, 3)
inc(i)
wend
end sub
'******************************************************************************
'******************************************************************************
' Initialization Routine
'******************************************************************************
sub procedure Init_Main
'--------------------------------------
' Disable interrupts
'--------------------------------------
INTCON = 0 ' Disable GIE, PEIE, TMR0IE,INT0IE,RBIE
INTCON2 = 0xF5
INTCON3 = 0xC0
RCON.IPEN = 0 ' Disable Priority Levels on interrupts
PIE1 = 0
PIE2 = 0
PIR1 = 0
PIR2 = 0
ADCON1 = $80 'ports are analog
'ADCON1 = ADCON1 or 0x0F ' Configure all ports with analog function as digital
'--------------------------------------
' Ports Configuration
'--------------------------------------
TRISA = 0xFF 'input
TRISB = 0x0 'output
LATA = 0
LATB = 0
end sub
'******************************************************************************
' Main Program Routine
'******************************************************************************
main:
Init_Main()
read=0
HID_Enable(@userRD_buffer, @userWR_buffer)
'Delay_mS(1000)
Delay_mS(1000)
PORTB=0xff
j=65
while true
wend
HID_Disable()
end.
****************************************************
****************************************************
and here is the descriptor file:
module USBdsc
include "HIDconstant"
' File Version 1.01
'
'******************************************************************************
'******************************************************************************
' The number of bytes in each report,
' calculated from Report Size and Report Count in the report descriptor
'******************************************************************************
const HID_INPUT_REPORT_BYTES = 3
const HID_OUTPUT_REPORT_BYTES = 3
const HID_FEATURE_REPORT_BYTES = 2
'******************************************************************************
' Byte constants
'******************************************************************************
const NUM_ENDPOINTS = 2
const ConfigDescr_wTotalLength = USB_CONFIG_DESCRIPTOR_LEN + USB_INTERF_DESCRIPTOR_LEN + USB_HID_DESCRIPTOR_LEN + (NUM_ENDPOINTS * USB_ENDP_DESCRIPTOR_LEN)
const HID_ReportDesc_len = 50
const Low_HID_ReportDesc_len = HID_ReportDesc_len
const High_HID_ReportDesc_len = HID_ReportDesc_len >> 8
const Low_HID_PACKET_SIZE = HID_PACKET_SIZE
const High_HID_PACKET_SIZE = HID_PACKET_SIZE >> 8
'******************************************************************************
' Descriptor Tables
'******************************************************************************
const DescTables as byte[218] = (
' Device Descriptor
0x12, 0, ' bLength - Length of Device descriptor (always 0x12)
0x01, 0, ' bDescriptorType - 1 = DEVICE descriptor
0x00, 0, ' bcdUSB - USB revision 2.00 (low byte)
0x01, 0, ' (high byte)
0x00, 0, ' bDeviceClass - Zero means each interface operates independently (class code in the interface descriptor)
0x00, 0, ' bDeviceSubClass
0x00, 0, ' bDeviceProtocol
0x08, 0, ' bMaxPacketSize0 - maximum size of a data packet for a control transfer over EP0
0x83, 0, ' idVendor - Vendor ID (low byte)
0x04, 0, ' (high byte)
0x02, 0, ' idProduct - Product ID (low byte)
0x00, 0, ' (high byte)
0x06, 0, ' bcdDevice - ( low byte)
0x00, 0, ' (high byte)
0x01, 0, ' iManufacturer - String1
0x02, 0, ' iProduct - String2
0x00, 0, ' iSerialNumber - ( None )
0x01, 0, ' bNumConfigurations - 1
' Configuration Descriptor
0x09, 0, ' bLength - Length of Configuration descriptor (always 0x09)
0x02, 0, ' bDescriptorType - 2 = CONFIGURATION descriptor
0x22, 0, ' wTotalLength - Total length of this config. descriptor plus the interface and endpoint descriptors that are part of the configuration.
0x00, 0, ' ( high byte)
0x01, 0, ' bNumInterfaces - Number of interfaces
0x01, 0, ' bConfigurationValue - Configuration Value
0x00, 0, ' iConfiguration - String Index for this configuration ( None )
0x60, 0, ' bmAttributes - attributes - "Bus powered" and "Remote wakeup"
0x0A, 0, ' MaxPower - bus-powered draws 50*2 mA from the bus.
' Interface Descriptor
0x09, 0, ' bLength - Length of Interface descriptor (always 0x09)
0x04, 0, ' bDescriptorType - 4 = INTERFACE descriptor
0x01, 0, ' bInterfaceNumber - Number of interface, 0 based array
0x00, 0, ' bAlternateSetting - Alternate setting
0x01, 0, ' bNumEndPoints - Number of endpoints used in this interface
0x03, 0, ' bInterfaceClass - assigned by the USB
0x01, 0, ' bInterfaceSubClass - Not A boot device
0x02, 0, ' bInterfaceProtocol - none
0x00, 0, ' iInterface - Index to string descriptor that describes this interface ( None )
' HID Descriptor
0x09, 0, ' bLength - Length of HID descriptor (always 0x09)
0x21, 0, ' bDescriptorType - 0x21 = HID descriptor
0x00, 0, ' HID class release number (1.01)
0x01, 0,
0x21, 0, ' Localized country code (none)
0x01, 0, ' # of HID class descriptor to follow (1)
0x22, 0, ' Report descriptor type (HID)
Low_HID_ReportDesc_len, 0,
High_HID_ReportDesc_len, 0,
' EP1_RX Descriptor
0x07, 0, ' bLength - length of descriptor (always 0x07)
0x05, 0, ' bDescriptorType - 5 = ENDPOINT descriptor
0x81, 0, ' bEndpointAddress - In, EP1
0x03, 0, ' bmAttributes - Endpoint Type - Interrupt
0x08, 0, ' wMaxPacketSize - max packet size - low order byte
0x00, 0, ' - max packet size - high order byte
0x0A, 0, ' bInterval - polling interval (1 ms)
' HID_Report Descriptor
0x05,0, 0x01,0, ' // USAGE_PAGE (Generic Desktop)
0x09,0, 0x02,0, ' // USAGE (Mouse)
0xa1,0, 0x01,0, ' // COLLECTION (Application)
0x09,0, 0x01,0, ' // USAGE (Pointer)
0xa1,0, 0x00,0, ' // COLLECTION (Physical)
0x05,0, 0x09,0, ' // USAGE_PAGE (Button)
0x19,0, 0x01,0, ' // USAGE_MINIMUM (Button 1)
0x29,0, 0x03,0, ' // USAGE_MAXIMUM (Button 3)
0x15,0, 0x00,0, ' // LOGICAL_MINIMUM (0)
0x25,0, 0x01,0, ' // LOGICAL_MAXIMUM (1)
0x95,0, 0x03,0, ' // REPORT_COUNT (3)
0x75,0, 0x01,0, ' // REPORT_SIZE (1)
0x81,0, 0x02,0, ' // INPUT (Data,Var,Abs)
0x95,0, 0x01,0, ' // REPORT_COUNT (1)
0x75,0, 0x05,0, ' // REPORT_SIZE (5)
0x81,0, 0x01,0, ' // INPUT (Cnst,Var,Abs)
0x05,0, 0x01,0, ' // USAGE_PAGE (Generic Desktop)
0x09,0, 0x30,0, ' // USAGE (X)
0x09,0, 0x31,0, ' // USAGE (Y)
0x15,0, 0x81,0, ' // LOGICAL_MINIMUM (-127)
0x25,0, 0x7f,0, ' // LOGICAL_MAXIMUM (127)
0x75,0, 0x08,0, ' // REPORT_SIZE (8)
0x95,0, 0x02,0, ' // REPORT_COUNT (2)
0x81,0, 0x06,0, ' // INPUT (Data,Var,Rel)
0xc0,0, ' // END_COLLECTION
0xc0,0 ' // END_COLLECTION
' ; END_COLLECTION
)
'******************************************************************************
const LangIDDescr as byte[8] = (
0x04, 0,
USB_STRING_DESCRIPTOR_TYPE, 0,
0x09, 0, ' LangID (0x0409) - Low
0x04, 0 ' - High
)
'******************************************************************************
const ManufacturerDescr as byte[68] = (
34, 0,
USB_STRING_DESCRIPTOR_TYPE, 0,
"m", 0, 0, 0,
"i", 0, 0, 0,
"k", 0, 0, 0,
"r", 0, 0, 0,
"o", 0, 0, 0,
"E", 0, 0, 0,
"l", 0, 0, 0,
"e", 0, 0, 0,
"k", 0, 0, 0,
"t", 0, 0, 0,
"r", 0, 0, 0,
"o", 0, 0, 0,
"n", 0, 0, 0,
"i", 0, 0, 0,
"k", 0, 0, 0,
"a", 0, 0, 0
)
'******************************************************************************
const ProductDescr as byte[48] = (
24, 0,
USB_STRING_DESCRIPTOR_TYPE, 0,
"H", 0, 0, 0,
"I", 0, 0, 0,
"D", 0, 0, 0,
" ", 0, 0, 0,
"L", 0, 0, 0,
"i", 0, 0, 0,
"b", 0, 0, 0,
"r", 0, 0, 0,
"a", 0, 0, 0,
"r", 0, 0, 0,
"y", 0, 0, 0
)
'******************************************************************************
const StrUnknownDescr as byte[4] = (
2, 0,
USB_STRING_DESCRIPTOR_TYPE, 0
)
'******************************************************************************
'******************************************************************************
' Initialization Function
'******************************************************************************
implements
sub procedure InitUSBdsc
dim dummy as byte volatile register
dummy = NUM_ENDPOINTS
dummy = ConfigDescr_wTotalLength
dummy = HID_ReportDesc_len
dummy = Low_HID_ReportDesc_len
dummy = High_HID_ReportDesc_len
dummy = Low_HID_PACKET_SIZE
dummy = High_HID_PACKET_SIZE
dummy = HID_INPUT_REPORT_BYTES
dummy = HID_OUTPUT_REPORT_BYTES
dummy = HID_FEATURE_REPORT_BYTES
'******************************************************************************
' Byte constants
'******************************************************************************
dummy = NUM_ENDPOINTS
dummy = ConfigDescr_wTotalLength
dummy = HID_ReportDesc_len
dummy = Low_HID_ReportDesc_len
dummy = High_HID_ReportDesc_len
dummy = Low_HID_PACKET_SIZE
dummy = High_HID_PACKET_SIZE
dummy = @DescTables
dummy = @LangIDDescr
dummy = @ManufacturerDescr
dummy = @LangIDDescr
dummy = @ProductDescr
dummy = @StrUnknownDescr
end sub
end.
Thank you very much for replying to my post. I have already checked the link you sent me. Currently, I am able to send and receive data to pc using hid. My main issue is that I am not sure why my mouse program does not connect correctly. Here is my code. I hope this helps you more. Thanks very much for all your help.
program USB_HID_test
include "USBdsc"
dim
k, i, ch ,j ,read as byte
userWR_buffer as byte[3]
userRD_buffer as byte[1]
text as string
temp_res as word
'******************************************************************************
' Main Interrupt Routine
'******************************************************************************
sub procedure interrupt
'** this is a way to call a procedure from interrupt
HID_InterruptProc
k = HID_Read()
i = 0
while i < k
ch = userRD_buffer[0]
userWR_buffer[0] =0x01 'sending left click message to test the interface
userWR_buffer[1] =0x00
userWR_buffer[2]=0x00
HID_Write(@userWR_buffer, 3)
inc(i)
wend
end sub
'******************************************************************************
'******************************************************************************
' Initialization Routine
'******************************************************************************
sub procedure Init_Main
'--------------------------------------
' Disable interrupts
'--------------------------------------
INTCON = 0 ' Disable GIE, PEIE, TMR0IE,INT0IE,RBIE
INTCON2 = 0xF5
INTCON3 = 0xC0
RCON.IPEN = 0 ' Disable Priority Levels on interrupts
PIE1 = 0
PIE2 = 0
PIR1 = 0
PIR2 = 0
ADCON1 = $80 'ports are analog
'ADCON1 = ADCON1 or 0x0F ' Configure all ports with analog function as digital
'--------------------------------------
' Ports Configuration
'--------------------------------------
TRISA = 0xFF 'input
TRISB = 0x0 'output
LATA = 0
LATB = 0
end sub
'******************************************************************************
' Main Program Routine
'******************************************************************************
main:
Init_Main()
read=0
HID_Enable(@userRD_buffer, @userWR_buffer)
'Delay_mS(1000)
Delay_mS(1000)
PORTB=0xff
j=65
while true
wend
HID_Disable()
end.
****************************************************
****************************************************
and here is the descriptor file:
module USBdsc
include "HIDconstant"
' File Version 1.01
'
'******************************************************************************
'******************************************************************************
' The number of bytes in each report,
' calculated from Report Size and Report Count in the report descriptor
'******************************************************************************
const HID_INPUT_REPORT_BYTES = 3
const HID_OUTPUT_REPORT_BYTES = 3
const HID_FEATURE_REPORT_BYTES = 2
'******************************************************************************
' Byte constants
'******************************************************************************
const NUM_ENDPOINTS = 2
const ConfigDescr_wTotalLength = USB_CONFIG_DESCRIPTOR_LEN + USB_INTERF_DESCRIPTOR_LEN + USB_HID_DESCRIPTOR_LEN + (NUM_ENDPOINTS * USB_ENDP_DESCRIPTOR_LEN)
const HID_ReportDesc_len = 50
const Low_HID_ReportDesc_len = HID_ReportDesc_len
const High_HID_ReportDesc_len = HID_ReportDesc_len >> 8
const Low_HID_PACKET_SIZE = HID_PACKET_SIZE
const High_HID_PACKET_SIZE = HID_PACKET_SIZE >> 8
'******************************************************************************
' Descriptor Tables
'******************************************************************************
const DescTables as byte[218] = (
' Device Descriptor
0x12, 0, ' bLength - Length of Device descriptor (always 0x12)
0x01, 0, ' bDescriptorType - 1 = DEVICE descriptor
0x00, 0, ' bcdUSB - USB revision 2.00 (low byte)
0x01, 0, ' (high byte)
0x00, 0, ' bDeviceClass - Zero means each interface operates independently (class code in the interface descriptor)
0x00, 0, ' bDeviceSubClass
0x00, 0, ' bDeviceProtocol
0x08, 0, ' bMaxPacketSize0 - maximum size of a data packet for a control transfer over EP0
0x83, 0, ' idVendor - Vendor ID (low byte)
0x04, 0, ' (high byte)
0x02, 0, ' idProduct - Product ID (low byte)
0x00, 0, ' (high byte)
0x06, 0, ' bcdDevice - ( low byte)
0x00, 0, ' (high byte)
0x01, 0, ' iManufacturer - String1
0x02, 0, ' iProduct - String2
0x00, 0, ' iSerialNumber - ( None )
0x01, 0, ' bNumConfigurations - 1
' Configuration Descriptor
0x09, 0, ' bLength - Length of Configuration descriptor (always 0x09)
0x02, 0, ' bDescriptorType - 2 = CONFIGURATION descriptor
0x22, 0, ' wTotalLength - Total length of this config. descriptor plus the interface and endpoint descriptors that are part of the configuration.
0x00, 0, ' ( high byte)
0x01, 0, ' bNumInterfaces - Number of interfaces
0x01, 0, ' bConfigurationValue - Configuration Value
0x00, 0, ' iConfiguration - String Index for this configuration ( None )
0x60, 0, ' bmAttributes - attributes - "Bus powered" and "Remote wakeup"
0x0A, 0, ' MaxPower - bus-powered draws 50*2 mA from the bus.
' Interface Descriptor
0x09, 0, ' bLength - Length of Interface descriptor (always 0x09)
0x04, 0, ' bDescriptorType - 4 = INTERFACE descriptor
0x01, 0, ' bInterfaceNumber - Number of interface, 0 based array
0x00, 0, ' bAlternateSetting - Alternate setting
0x01, 0, ' bNumEndPoints - Number of endpoints used in this interface
0x03, 0, ' bInterfaceClass - assigned by the USB
0x01, 0, ' bInterfaceSubClass - Not A boot device
0x02, 0, ' bInterfaceProtocol - none
0x00, 0, ' iInterface - Index to string descriptor that describes this interface ( None )
' HID Descriptor
0x09, 0, ' bLength - Length of HID descriptor (always 0x09)
0x21, 0, ' bDescriptorType - 0x21 = HID descriptor
0x00, 0, ' HID class release number (1.01)
0x01, 0,
0x21, 0, ' Localized country code (none)
0x01, 0, ' # of HID class descriptor to follow (1)
0x22, 0, ' Report descriptor type (HID)
Low_HID_ReportDesc_len, 0,
High_HID_ReportDesc_len, 0,
' EP1_RX Descriptor
0x07, 0, ' bLength - length of descriptor (always 0x07)
0x05, 0, ' bDescriptorType - 5 = ENDPOINT descriptor
0x81, 0, ' bEndpointAddress - In, EP1
0x03, 0, ' bmAttributes - Endpoint Type - Interrupt
0x08, 0, ' wMaxPacketSize - max packet size - low order byte
0x00, 0, ' - max packet size - high order byte
0x0A, 0, ' bInterval - polling interval (1 ms)
' HID_Report Descriptor
0x05,0, 0x01,0, ' // USAGE_PAGE (Generic Desktop)
0x09,0, 0x02,0, ' // USAGE (Mouse)
0xa1,0, 0x01,0, ' // COLLECTION (Application)
0x09,0, 0x01,0, ' // USAGE (Pointer)
0xa1,0, 0x00,0, ' // COLLECTION (Physical)
0x05,0, 0x09,0, ' // USAGE_PAGE (Button)
0x19,0, 0x01,0, ' // USAGE_MINIMUM (Button 1)
0x29,0, 0x03,0, ' // USAGE_MAXIMUM (Button 3)
0x15,0, 0x00,0, ' // LOGICAL_MINIMUM (0)
0x25,0, 0x01,0, ' // LOGICAL_MAXIMUM (1)
0x95,0, 0x03,0, ' // REPORT_COUNT (3)
0x75,0, 0x01,0, ' // REPORT_SIZE (1)
0x81,0, 0x02,0, ' // INPUT (Data,Var,Abs)
0x95,0, 0x01,0, ' // REPORT_COUNT (1)
0x75,0, 0x05,0, ' // REPORT_SIZE (5)
0x81,0, 0x01,0, ' // INPUT (Cnst,Var,Abs)
0x05,0, 0x01,0, ' // USAGE_PAGE (Generic Desktop)
0x09,0, 0x30,0, ' // USAGE (X)
0x09,0, 0x31,0, ' // USAGE (Y)
0x15,0, 0x81,0, ' // LOGICAL_MINIMUM (-127)
0x25,0, 0x7f,0, ' // LOGICAL_MAXIMUM (127)
0x75,0, 0x08,0, ' // REPORT_SIZE (8)
0x95,0, 0x02,0, ' // REPORT_COUNT (2)
0x81,0, 0x06,0, ' // INPUT (Data,Var,Rel)
0xc0,0, ' // END_COLLECTION
0xc0,0 ' // END_COLLECTION
' ; END_COLLECTION
)
'******************************************************************************
const LangIDDescr as byte[8] = (
0x04, 0,
USB_STRING_DESCRIPTOR_TYPE, 0,
0x09, 0, ' LangID (0x0409) - Low
0x04, 0 ' - High
)
'******************************************************************************
const ManufacturerDescr as byte[68] = (
34, 0,
USB_STRING_DESCRIPTOR_TYPE, 0,
"m", 0, 0, 0,
"i", 0, 0, 0,
"k", 0, 0, 0,
"r", 0, 0, 0,
"o", 0, 0, 0,
"E", 0, 0, 0,
"l", 0, 0, 0,
"e", 0, 0, 0,
"k", 0, 0, 0,
"t", 0, 0, 0,
"r", 0, 0, 0,
"o", 0, 0, 0,
"n", 0, 0, 0,
"i", 0, 0, 0,
"k", 0, 0, 0,
"a", 0, 0, 0
)
'******************************************************************************
const ProductDescr as byte[48] = (
24, 0,
USB_STRING_DESCRIPTOR_TYPE, 0,
"H", 0, 0, 0,
"I", 0, 0, 0,
"D", 0, 0, 0,
" ", 0, 0, 0,
"L", 0, 0, 0,
"i", 0, 0, 0,
"b", 0, 0, 0,
"r", 0, 0, 0,
"a", 0, 0, 0,
"r", 0, 0, 0,
"y", 0, 0, 0
)
'******************************************************************************
const StrUnknownDescr as byte[4] = (
2, 0,
USB_STRING_DESCRIPTOR_TYPE, 0
)
'******************************************************************************
'******************************************************************************
' Initialization Function
'******************************************************************************
implements
sub procedure InitUSBdsc
dim dummy as byte volatile register
dummy = NUM_ENDPOINTS
dummy = ConfigDescr_wTotalLength
dummy = HID_ReportDesc_len
dummy = Low_HID_ReportDesc_len
dummy = High_HID_ReportDesc_len
dummy = Low_HID_PACKET_SIZE
dummy = High_HID_PACKET_SIZE
dummy = HID_INPUT_REPORT_BYTES
dummy = HID_OUTPUT_REPORT_BYTES
dummy = HID_FEATURE_REPORT_BYTES
'******************************************************************************
' Byte constants
'******************************************************************************
dummy = NUM_ENDPOINTS
dummy = ConfigDescr_wTotalLength
dummy = HID_ReportDesc_len
dummy = Low_HID_ReportDesc_len
dummy = High_HID_ReportDesc_len
dummy = Low_HID_PACKET_SIZE
dummy = High_HID_PACKET_SIZE
dummy = @DescTables
dummy = @LangIDDescr
dummy = @ManufacturerDescr
dummy = @LangIDDescr
dummy = @ProductDescr
dummy = @StrUnknownDescr
end sub
end.
Hi,
I think thatbelongs in the main routine in stead of in the interrupt routine...
I think that
Code: Select all
k = HID_Read()
i = 0
while i < k
ch = userRD_buffer[0]
userWR_buffer[0] =0x01 'sending left click message to test the interface
userWR_buffer[1] =0x00
userWR_buffer[2]=0x00
HID_Write(@userWR_buffer, 3)
inc(i)
wend
Kind regards, Dany.
Forget your perfect offering. There is a crack in everything, that's how the light gets in... (L. Cohen)
Remember when we were young? We shone like the sun. (David Gilmour)
Forget your perfect offering. There is a crack in everything, that's how the light gets in... (L. Cohen)
Remember when we were young? We shone like the sun. (David Gilmour)
Hi Dany,
Thanks for checking this. I have tested it also in the main routine but still no luck. :(
I am not sure if my descriptor is properly written. Could you please give me your opionion on my descriptor file?
Thanks,
Arin
main:
Init_Main()
read=0
HID_Enable(@userRD_buffer, @userWR_buffer)
'Delay_mS(1000)
Delay_mS(1000)
PORTB=0xff
j=65
while true
k = HID_Read()
i = 0
while i < k
ch = userRD_buffer[0]
userWR_buffer[0] =0x01 'sending left click message to test the interface
userWR_buffer[1] =0x00
userWR_buffer[2]=0x00
HID_Write(@userWR_buffer, 3)
inc(i)
wend
wend
HID_Disable()
end.
Thanks for checking this. I have tested it also in the main routine but still no luck. :(
I am not sure if my descriptor is properly written. Could you please give me your opionion on my descriptor file?
Thanks,
Arin
main:
Init_Main()
read=0
HID_Enable(@userRD_buffer, @userWR_buffer)
'Delay_mS(1000)
Delay_mS(1000)
PORTB=0xff
j=65
while true
k = HID_Read()
i = 0
while i < k
ch = userRD_buffer[0]
userWR_buffer[0] =0x01 'sending left click message to test the interface
userWR_buffer[1] =0x00
userWR_buffer[2]=0x00
HID_Write(@userWR_buffer, 3)
inc(i)
wend
wend
HID_Disable()
end.
Hi,
There is something wrong here:(*) because of the following:
See also http://users.edpnet.be/rosseel01/DRO/PI ... 0Usage.htm for some tips on usage of the HID library.
Here is one to be found in document "Universal Serial Bus, Device Class Definition for Human Interface Devices (HID)":Do not forget to adapt wDescriptorLength in the HID descriptor to the length of the adapted report.
There is something wrong here:
Code: Select all
dim
k, i, ch ,j ,read as byte
userWR_buffer as byte[3]
userRD_buffer as byte[1] // <-------- this should also be byte[3] (*)
text as string
temp_res as word
in the usb descriptor file. I know You want to receive 1 byte each time, but you are getting always 3 (some other -- non receive buffer -- ram memory will be overwritten here). I think however this will not solve your problem.const HID_OUTPUT_REPORT_BYTES = 3
See also http://users.edpnet.be/rosseel01/DRO/PI ... 0Usage.htm for some tips on usage of the HID library.
Did the code already work with a non changed descriptor file? I assume you did change the "report descriptor" part. Until now I used always the same report descriptor content (the "generic" one, with input, output and feature reports), and I do not know how a valid "mouse" device report looks like. I assume there are some examples on the web?I am not sure if my descriptor is properly written. Could you please give me your opionion on my descriptor file?
Here is one to be found in document "Universal Serial Bus, Device Class Definition for Human Interface Devices (HID)":
Code: Select all
E.10 Report Descriptor (Mouse)
// Item
Usage Page (Generic Desktop),
Usage (Mouse),
Collection (Application),
Usage (Pointer),
Collection (Physical),
Usage Page (Buttons),
Usage Minimum (01),
Usage Maximun (03),
Logical Minimum (0),
Logical Maximum (1),
Report Count (3),
Report Size (1),
Input (Data, Variable, Absolute), ;3 button bits
Report Count (1),
Report Size (5),
Input (Constant), ;5 bit padding
Usage Page (Generic Desktop),
Usage (X),
Usage (Y),
Logical Minimum (-127),
Logical Maximum (127),
Report Size (8),
Report Count (2),
Input (Data, Variable, Relative), ;2 position bytes (X & Y)
End Collection,
End Collection
// Value (Hex)
05 01
09 02
A1 01
09 01
A1 00
05 09
19 01
29 03
15 00
25 01
95 03
75 01
81 02
95 01
75 05
81 01
05 01
09 30
09 31
15 81
25 7F
75 08
95 02
81 06
C0
C0
Kind regards, Dany.
Forget your perfect offering. There is a crack in everything, that's how the light gets in... (L. Cohen)
Remember when we were young? We shone like the sun. (David Gilmour)
Forget your perfect offering. There is a crack in everything, that's how the light gets in... (L. Cohen)
Remember when we were young? We shone like the sun. (David Gilmour)
Hi Dany,
Thanks for the tips. I did check the internet for the hid mouse example and that is how I came up with my new descriptor file. But unfortunately I have not had any success getting it to work.
Here is also another message that once in a while windows pops up:
Thanks,
Arin
Thanks for the tips. I did check the internet for the hid mouse example and that is how I came up with my new descriptor file. But unfortunately I have not had any success getting it to work.
Here is also another message that once in a while windows pops up:
The Controller does not have enough bandwidth available for the USB Human Interface Device.USB Controller Bandwidth Exceeded
Thanks,
Arin
Dany,
First of all, condradulations on your website. it looks very helpful for beginers like me. ;)
I also wanted to add some more notes here after me working for another several hours on the interface.
Now, when connecting my usb device to my pc, I am geting Windows messgae saying that HID device detected and was properly installed! that's the good news. and the bad news is that I am also getting another message saying that the device cannot start and there is a problem starting it.
if I go to my device manager, I can see my hid device but there is a notification icon on the device and it has the following error:
This device cannot start. (Code 10)
Click Troubleshoot to start the troubleshooter for this device.
I hope this helps. I think the problem is that I do not know how exactly communicate as a mouse.
Here is some part of my new code:
please note that I increased the message delay to 0x50 to slowdown the interface a little a bit.
Thanks for the help,
Arin
First of all, condradulations on your website. it looks very helpful for beginers like me. ;)
I also wanted to add some more notes here after me working for another several hours on the interface.
Now, when connecting my usb device to my pc, I am geting Windows messgae saying that HID device detected and was properly installed! that's the good news. and the bad news is that I am also getting another message saying that the device cannot start and there is a problem starting it.
if I go to my device manager, I can see my hid device but there is a notification icon on the device and it has the following error:
This device cannot start. (Code 10)
Click Troubleshoot to start the troubleshooter for this device.
I hope this helps. I think the problem is that I do not know how exactly communicate as a mouse.
Here is some part of my new code:
Code: Select all
sub procedure interrupt
'** this is a way to call a procedure from interrupt
HID_InterruptProc
end sub
'******************************************************************************
'******************************************************************************
' Initialization Routine
'******************************************************************************
sub procedure Init_Main
'--------------------------------------
' Disable interrupts
'--------------------------------------
INTCON = 0 ' Disable GIE, PEIE, TMR0IE,INT0IE,RBIE
INTCON2 = 0xF5
INTCON3 = 0xC0
RCON.IPEN = 0 ' Disable Priority Levels on interrupts
PIE1 = 0
PIE2 = 0
PIR1 = 0
PIR2 = 0
ADCON1 = $80 'ports are analog
'ADCON1 = ADCON1 or 0x0F ' Configure all ports with analog function as digital
'--------------------------------------
' Ports Configuration
'--------------------------------------
TRISA = 0xFF 'input
TRISB = 0x0 'output
LATA = 0
LATB = 0
read=0
end sub
'******************************************************************************
' Main Program Routine
'******************************************************************************
main:
Init_Main()
read=0
HID_Enable(@userRD_buffer, @userWR_buffer)
Delay_mS(1000)
Delay_mS(1000)
'PORTB=0xff
j=65
while true
k = HID_Read()
i = 0
while i < k
ch = userRD_buffer[0]
'if read=1 then
userWR_buffer[0] =0x00
userWR_buffer[1] =0x00
userWR_buffer[2]=0x00
' userWR_buffer[3]=0x00
HID_Write(@userWR_buffer, 3)
'end if
inc(i)
wend
delay_ms(0x50)
' PORTB=not PORTB
wend
HID_Disable()
please note that I increased the message delay to 0x50 to slowdown the interface a little a bit.
Thanks for the help,
Arin
Hi,
I can not see anything wrong in the reportdescriptor.
But this is probably wrong:
Further: in your main code you try to read data coming from the host with "HID_Read()". This will always fail, since a mouse is only capable of sending data to the host (additionally, you have only 1 endpoint -- of IN type --, which can only send data to the host, not receive).
I can not see anything wrong in the reportdescriptor.
But this is probably wrong:
because you have only 1 endpoint descriptor (an IN endpoint)... So, the calculation of the total length will be also wrong.const NUM_ENDPOINTS = 2
I have also seen this situation while I was testing my HID library. If I only could remember what the reason was...This device cannot start. (Code 10)
Click Troubleshoot to start the troubleshooter for this device.
Further: in your main code you try to read data coming from the host with "HID_Read()". This will always fail, since a mouse is only capable of sending data to the host (additionally, you have only 1 endpoint -- of IN type --, which can only send data to the host, not receive).
Kind regards, Dany.
Forget your perfect offering. There is a crack in everything, that's how the light gets in... (L. Cohen)
Remember when we were young? We shone like the sun. (David Gilmour)
Forget your perfect offering. There is a crack in everything, that's how the light gets in... (L. Cohen)
Remember when we were young? We shone like the sun. (David Gilmour)
Hi Dany,
Sorry for the confusion. In my last descriptor I added another end point OUT. I just thought maybe that's how it should be and therefore I added the following to my descriptor:
and added HID_READ to my code.
Please let me know if you found any code that can be helpful on HID mouse communication. I have searched the internet days for any article and code and almost I don't see anything new when I do search. :?
One more thing I was kind of suspisious on my
0x08, 0, ' wMaxPacketSize - max packet size - low
but this is what everywhere they have suggested.
Also please let me know your thoughts on the delay I have in my main loop.
delay_ms(0x20)
should I leave the delay or I need to take it out?
Thanks,
Arin
Sorry for the confusion. In my last descriptor I added another end point OUT. I just thought maybe that's how it should be and therefore I added the following to my descriptor:
Code: Select all
' EP1_TX Descriptor
0x07, 0, ' bLength - length of descriptor (always 0x07)
0x05, 0, ' bDescriptorType - 5 = ENDPOINT descriptor
0x01, 0, ' bEndpointAddress - out, EP1
0x03, 0, ' bmAttributes - Endpoint Type - Interrupt
0x08, 0, ' wMaxPacketSize - max packet size - low order byte
0x00, 0, ' - max packet size - high order byte
0x50, 0, ' bInterval - polling interval (1 ms)
Please let me know if you found any code that can be helpful on HID mouse communication. I have searched the internet days for any article and code and almost I don't see anything new when I do search. :?
One more thing I was kind of suspisious on my
0x08, 0, ' wMaxPacketSize - max packet size - low
but this is what everywhere they have suggested.
Also please let me know your thoughts on the delay I have in my main loop.
delay_ms(0x20)
should I leave the delay or I need to take it out?
Thanks,
Arin
Seems to be fine now.Arin_t wrote:In my last descriptor I added another end point OUT. I just thought maybe that's how it should be and therefore I added the following to my descriptor:and added HID_READ to my code.Code: Select all
' EP1_TX Descriptor 0x07, 0, ' bLength - length of descriptor (always 0x07) 0x05, 0, ' bDescriptorType - 5 = ENDPOINT descriptor 0x01, 0, ' bEndpointAddress - out, EP1 0x03, 0, ' bmAttributes - Endpoint Type - Interrupt 0x08, 0, ' wMaxPacketSize - max packet size - low order byte 0x00, 0, ' - max packet size - high order byte 0x50, 0, ' bInterval - polling interval (1 ms)
Ok, I will keep an eye open for it.Arin_t wrote:Please let me know if you found any code that can be helpful on HID mouse communication. I have searched the internet days for any article and code and almost I don't see anything new when I do search.
Also that seems to be Ok.Arin_t wrote:One more thing I was kind of suspisious on my
0x08, 0, ' wMaxPacketSize - max packet size - low
but this is what everywhere they have suggested.
Leaving it in should be no problem.Arin_t wrote:Also please let me know your thoughts on the delay I have in my main loop.
delay_ms(0x20)
should I leave the delay or I need to take it out?
I am puzzled.
Kind regards, Dany.
Forget your perfect offering. There is a crack in everything, that's how the light gets in... (L. Cohen)
Remember when we were young? We shone like the sun. (David Gilmour)
Forget your perfect offering. There is a crack in everything, that's how the light gets in... (L. Cohen)
Remember when we were young? We shone like the sun. (David Gilmour)
look.
const HID_INPUT_REPORT_BYTES = 3; // device to pc
const HID_OUTPUT_REPORT_BYTES = 3; //pc to device
****************************************************
const HID_ReportDesc_len = 47; // number of bytes into the
// HID_ReportDesc
is not 47!! counter this.!!!
then.. number of bytes into .. const HID_ReportDesc_len = """50""";
Config´s. esactly..
const HID_INPUT_REPORT_BYTES = 3; // device to pc
const HID_OUTPUT_REPORT_BYTES = 3; //pc to device
const HID_ReportDesc_len = 50 ;// number of bytes descrp..
The values have assigned with..
Example.
Byte 0 = buttons
Byte 1 = X moviment = value -127.....+127
Byte 2 = Y moviment = value -127 ..... +127
.........
const HID_INPUT_REPORT_BYTES = 3; // device to pc
const HID_OUTPUT_REPORT_BYTES = 3; //pc to device
****************************************************
const HID_ReportDesc_len = 47; // number of bytes into the
// HID_ReportDesc
is not 47!! counter this.!!!
Code: Select all
look (((50))) decimal !!
char ReportDescriptor[50] = {
0x05, 0x01, // USAGE_PAGE (Generic Desktop)
0x09, 0x02, // USAGE (Mouse)
0xa1, 0x01, // COLLECTION (Application)
0x09, 0x01, // USAGE (Pointer)
0xa1, 0x00, // COLLECTION (Physical)
0x05, 0x09, // USAGE_PAGE (Button)
0x19, 0x01, // USAGE_MINIMUM (Button 1)
0x29, 0x03, // USAGE_MAXIMUM (Button 3)
0x15, 0x00, // LOGICAL_MINIMUM (0)
0x25, 0x01, // LOGICAL_MAXIMUM (1)
0x95, 0x03, // REPORT_COUNT (3)
0x75, 0x01, // REPORT_SIZE (1)
0x81, 0x02, // INPUT (Data,Var,Abs)
0x95, 0x01, // REPORT_COUNT (1)
0x75, 0x05, // REPORT_SIZE (5)
0x81, 0x03, // INPUT (Cnst,Var,Abs)
0x05, 0x01, // USAGE_PAGE (Generic Desktop)
0x09, 0x30, // USAGE (X)
0x09, 0x31, // USAGE (Y)
0x15, 0x81, // LOGICAL_MINIMUM (-127)
0x25, 0x7f, // LOGICAL_MAXIMUM (127)
0x75, 0x08, // REPORT_SIZE (8)
0x95, 0x02, // REPORT_COUNT (2)
0x81, 0x06, // INPUT (Data,Var,Rel)
0xc0, // END_COLLECTION
0xc0 // END_COLLECTION
};
then.. number of bytes into .. const HID_ReportDesc_len = """50""";
Config´s. esactly..
const HID_INPUT_REPORT_BYTES = 3; // device to pc
const HID_OUTPUT_REPORT_BYTES = 3; //pc to device
const HID_ReportDesc_len = 50 ;// number of bytes descrp..
The values have assigned with..
Example.
Byte 0 = buttons
Byte 1 = X moviment = value -127.....+127
Byte 2 = Y moviment = value -127 ..... +127
.........
unsigned char const HID_INPUT_REPORT_BYTES = 3; // 3 bytes de saida
unsigned char const HID_OUTPUT_REPORT_BYTES = 3; // 3 bytes de entrada
work´s fine !!! perfectly!!
unsigned char const HID_OUTPUT_REPORT_BYTES = 3; // 3 bytes de entrada
Code: Select all
unsigned char const DescTables[] = {
// Device Descriptor
USB_DEVICE_DESCRIPTOR_LEN, 0, // bLength - Length of Device descriptor (always 0x12)
USB_DEVICE_DESCRIPTOR_TYPE, 0, // bDescriptorType - 1 = DEVICE descriptor
0x00, 0, // bcdUSB - USB revision 2.00 (low byte)
0x02, 0, // (high byte)
0x00, 0, // bDeviceClass - Zero means each interface operates independently (class code in the interface descriptor)
0x00, 0, // bDeviceSubClass
0x00, 0, // bDeviceProtocol
EP0_PACKET_SIZE, 0, // bMaxPacketSize0 - maximum size of a data packet for a control transfer over EP0
0x35, 0, // idVendor - Vendor ID (low byte)
0x01, 0, // (high byte)
0x01, 0, // idProduct - Product ID (low byte)
0x0a, 0, // (high byte)
0x01, 0, // bcdDevice - ( low byte)
0x00, 0, // (high byte)
0x01, 0, // iManufacturer - String1
0x02, 0, // iProduct - String2
0x00, 0, // iSerialNumber - ( None )
0x01, 0, //01 // bNumConfigurations - 1
// Configuration Descriptor
USB_CONFIG_DESCRIPTOR_LEN, 0, // bLength - Length of Configuration descriptor (always 0x09)
USB_CONFIG_DESCRIPTOR_TYPE, 0, // bDescriptorType - 2 = CONFIGURATION descriptor
ConfigDescr_wTotalLength, 0, // wTotalLength - Total length of this config. descriptor plus the interface and endpoint descriptors that are part of the configuration.
0x00, 0, // ( high byte)
0x01, 0, // bNumInterfaces - Number of interfaces
0x01, 0, // bConfigurationValue - Configuration Value
0x00, 0, // iConfiguration - String Index for this configuration ( None )
0xA0, 0, // bmAttributes - attributes - "Bus powered" and "Remote wakeup"
50, 0, // MaxPower - bus-powered draws 50*2 mA from the bus.
// Interface Descriptor
USB_INTERF_DESCRIPTOR_LEN, 0, // bLength - Length of Interface descriptor (always 0x09)
USB_INTERFACE_DESCRIPTOR_TYPE, 0, // bDescriptorType - 4 = INTERFACE descriptor
0x00, 0, // bInterfaceNumber - Number of interface, 0 based array
0x00, 0, // bAlternateSetting - Alternate setting
NUM_ENDPOINTS, 0, // bNumEndPoints - Number of endpoints used in this interface
0x03, 0, // bInterfaceClass - assigned by the USB
0x00, 0, // bInterfaceSubClass - Not A boot device
0x00, 0, // bInterfaceProtocol - none
0x00, 0, // iInterface - Index to string descriptor that describes this interface ( None )
// HID Descriptor
USB_HID_DESCRIPTOR_LEN, 0, // bLength - Length of HID descriptor (always 0x09)
USB_HID_DESCRIPTOR_TYPE, 0, // bDescriptorType - 0x21 = HID descriptor
0x01, 0, // HID class release number (1.01)
0x01, 0,
0x00, 0, // Localized country code (none)
0x01, 0, // # of HID class descriptor to follow (1)
0x22, 0, // Report descriptor type (HID)
Low_HID_ReportDesc_len, 0,
High_HID_ReportDesc_len, 0,
// DESCRIPTOR DO SENTIDO HOST DEVICE
// EP1_RX Descriptor
USB_ENDP_DESCRIPTOR_LEN, 0, // bLength - length of descriptor (always 0x07)
USB_ENDPOINT_DESCRIPTOR_TYPE, 0, // bDescriptorType - 5 = ENDPOINT descriptor
0x81, 0, // bEndpointAddress - In, EP1
USB_ENDPOINT_TYPE_INTERRUPT, 0, // bmAttributes - Endpoint Type - Interrupt
Low_HID_PACKET_SIZE, 0, // wMaxPacketSize - max packet size - low order byte
High_HID_PACKET_SIZE, 0, // - max packet size - high order byte
1, 0, // bInterval - polling interval (1 ms)
// DESCRIPTOR DO SENTIDO DEVICE HOST
// EP1_TX Descriptor
USB_ENDP_DESCRIPTOR_LEN, 0, // bLength - length of descriptor (always 0x07)
USB_ENDPOINT_DESCRIPTOR_TYPE, 0, // bDescriptorType - 5 = ENDPOINT descriptor
0x01, 0, // bEndpointAddress - Out, EP1
USB_ENDPOINT_TYPE_INTERRUPT, 0, // bmAttributes - Endpoint Type - Interrupt
Low_HID_PACKET_SIZE, 0, // wMaxPacketSize - max packet size - low order byte
High_HID_PACKET_SIZE, 0, // - max packet size - high order byte
1, 0, // bInterval - polling interval (1 ms) */
//*************************************************************************
//
//************* daqui para baixo***************
// mouse descriptor
0x05, 0,
0x01, 0, // USAGE_PAGE (Generic Desktop)
0x09, 0,
0x02, 0, // USAGE (Mouse)
0xa1, 0,
0x01, 0, // COLLECTION (Application)
0x09, 0,
0x01, 0, // USAGE (Pointer)
0xa1, 0,
0x00, 0, // COLLECTION (Physical)
0x05, 0,
0x09, 0, // USAGE_PAGE (Button)
0x19, 0,
0x01, 0, // USAGE_MINIMUM (Button 1)
0x29, 0,
0x03, 0, // USAGE_MAXIMUM (Button 3)
0x15, 0,
0x00, 0, // LOGICAL_MINIMUM (0)
0x25, 0,
0x01, 0, // LOGICAL_MAXIMUM (1)
0x95, 0,
0x03, 0, // REPORT_COUNT (3)
0x75, 0,
0x01, 0, // REPORT_SIZE (1)
0x81, 0,
0x02, 0, // INPUT (Data,Var,Abs)
0x95, 0,
0x01, 0, // REPORT_COUNT (1)
0x75, 0,
0x05, 0, // REPORT_SIZE (5)
0x81, 0,
0x03, 0, // INPUT (Cnst,Var,Abs)
0x05, 0,
0x01, 0, // USAGE_PAGE (Generic Desktop)
0x09, 0,
0x30, 0, // USAGE (X)
0x09, 0,
0x31, 0, // USAGE (Y)
0x15, 0,
0x81, 0, // LOGICAL_MINIMUM (-127)
0x25, 0,
0x7f, 0, // LOGICAL_MAXIMUM (127)
0x75, 0,
0x08, 0, // REPORT_SIZE (8)
0x95, 0,
0x02, 0, // REPORT_COUNT (2)
0x81, 0,
0x06, 0, // INPUT (Data,Var,Rel)
0xc0, 0, // END_COLLECTION
0xc0, 0, // END_COLLECTION
};
Glad I could also be of some assistance.Arin_t wrote:IT IS WORKING NOW!!!!!!!!!!!!!!!!!!!!!!
Dave, also thanks very much for all your help.
Last edited by Dany on 22 Sep 2011 19:42, edited 1 time in total.
Kind regards, Dany.
Forget your perfect offering. There is a crack in everything, that's how the light gets in... (L. Cohen)
Remember when we were young? We shone like the sun. (David Gilmour)
Forget your perfect offering. There is a crack in everything, that's how the light gets in... (L. Cohen)
Remember when we were young? We shone like the sun. (David Gilmour)