Hello to everyone.
I'm trying to make some initial experiments to build a minimal USB Host system, HID device only, based on a PIC24FJ64GB002. I installed the PIC24F USB Host library available on Libstock, courtesy of Dany. Built a bare minimum board with PIC, USB Socket and a 2x16 character LCD. Translated the provided examples in Mikropascal and adjusted the code to output on the LCD instead of the RS232 called for in the example code.
At first I'd be happy just to recognize that a HID device has plugged, but unfortunately it does not seem to work. Plugging either a keyboard or a mouse lets me see some kind of activity in the form of a longer pause between successive USB bus scan, but that's all, the USB_HID_Device_Ready boolean is never set to TRUE.
What am I doing wrong? Has anyone tried successfully this library before?
Trying to put Dany's USB Host library to good use...
Trying to put Dany's USB Host library to good use...
SeeYa!
Andrea
Andrea
Re: Trying to put Dany's USB Host library to good use...
Falco-F8L wrote:Hello to everyone.
I'm trying to make some initial experiments to build a minimal USB Host system, HID device only, based on a PIC24FJ64GB002. I installed the PIC24F USB Host library available on Libstock, courtesy of Dany. Built a bare minimum board with PIC, USB Socket and a 2x16 character LCD. Translated the provided examples in Mikropascal and adjusted the code to output on the LCD instead of the RS232 called for in the example code.
At first I'd be happy just to recognize that a HID device has plugged, but unfortunately it does not seem to work. Plugging either a keyboard or a mouse lets me see some kind of activity in the form of a longer pause between successive USB bus scan, but that's all, the USB_HID_Device_Ready boolean is never set to TRUE.
What am I doing wrong? Has anyone tried successfully this library before?
Hi, At this moment the (my) HID host library does not read the packet sizes and the mapping of the dataparts in the packets. So keyboards and mouses will not work as expected...I installed the PIC24F USB Host library available on Libstock, courtesy of Dany
The library assumes always devices 64 byte packets (generic HID devices). Making the library aware of all possible HID configurations is virtually impossible. Sorry for the inconvenience.
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)
Re: Trying to put Dany's USB Host library to good use...
okay, so what kind of HID device am I supposed to connect in order to at least see USB_HID_Device_Ready boolean set to TRUE?Dany wrote:Hi, At this moment the (my) HID host library does not read the packet sizes and the mapping of the dataparts in the packets. So keyboards and mouses will not work as expected...
The library assumes always devices 64 byte packets (generic HID devices). Making the library aware of all possible HID configurations is virtually impossible. Sorry for the inconvenience.
SeeYa!
Andrea
Andrea
Re: Trying to put Dany's USB Host library to good use...
Hi,Falco-F8L wrote:okay, so what kind of HID device am I supposed to connect in order to at least see USB_HID_Device_Ready boolean set to TRUE?
I do not know it there are any "generic" USB devices commericially available (I doubt it), you will have to make one yourself (with e.g. a PIC). In the mE USB HID device help there is an example of the USB descriptor (which defines the kind of HID device) that makes a 'generic' HID device, see https://libstock.mikroe.com/projects/vi ... ce-library.
It looks like this:
Code: Select all
module HID_Descriptor
const _USB_HID_MANUFACTURER_STRING as string[16] = "Mikroelektronika"
const _USB_HID_PRODUCT_STRING as string[18] = "HID Custom Demo"
const _USB_HID_SERIALNUMBER_STRING as string[11] = "0x00000003"
const _USB_HID_CONFIGURATION_STRING as string[22] = "HID Config desc string"
const _USB_HID_INTERFACE_STRING as string[25] = "HID Interface desc string"
const _USB_HID_CONFIG_DESC_SIZ as byte = 34 + 7
const _USB_HID_DESC_SIZ as byte = 9
const _USB_HID_REPORT_DESC_SIZE as byte = 33
const _USB_HID_DESCRIPTOR_TYPE as byte = 0x21
const _USB_HID_IN_PACKET as byte = 64
const _USB_HID_OUT_PACKET as byte = 64
const _USB_HID_IN_EP as byte = 0x81
const _USB_HID_OUT_EP as byte = 0x01
'String Descriptor Zero, Specifying Languages Supported by the Device
const USB_HID_LangIDDesc as byte[4] = (
0x04,
_USB_DEV_DESCRIPTOR_TYPE_STRING,
0x409 and 0xFF,
0x409 >> 8)
' device descriptor
const USB_HID_device_descriptor as byte[18] = (
0x12, ' bLength
0x01, ' bDescriptorType
0x00, ' bcdUSB
0x02,
0x00, ' bDeviceClass
0x00, ' bDeviceSubClass
0x00, ' bDeviceProtocol
0x40, ' bMaxPacketSize0
0x00, 0x00, ' idVendor
0x00, 0x03, ' idProduct
0x00, ' bcdDevice
0x02,
0x01, ' iManufacturer
0x02, ' iProduct
0x03, ' iSerialNumber
0x01 ' bNumConfigurations
)
'contain configuration descriptor, all interface descriptors, and endpoint
'descriptors for all of the interfaces
const USB_HID_cfg_descriptor as byte[_USB_HID_CONFIG_DESC_SIZ] = (
' Configuration descriptor
0x09, ' bLength: Configuration Descriptor size
_USB_DEV_DESCRIPTOR_TYPE_CONFIGURATION, ' bDescriptorType: Configuration
_USB_HID_CONFIG_DESC_SIZ and 0xFF, ' wTotalLength: Bytes returned
_USB_HID_CONFIG_DESC_SIZ >> 8,
0x01, ' bNumInterfaces: 1 interface
0x01, ' bConfigurationValue: Configuration value
0x04, ' iConfiguration: Index of string descriptor describing the configuration
0xE0, ' bmAttributes: self powered and Support Remote Wake-up
0x32, ' MaxPower 100 mA: this current is used for detecting Vbus
' Interface Descriptor
0x09, ' bLength: Interface Descriptor size
4, ' bDescriptorType: Interface descriptor type
0x00, ' bInterfaceNumber: Number of Interface
0x00, ' bAlternateSetting: Alternate setting
0x02, ' bNumEndpoints
0x03, ' bInterfaceClass: HID
0x00, ' bInterfaceSubClass : 1=BOOT, 0=no boot
0x00, ' nInterfaceProtocol : 0=none, 1=keyboard, 2=mouse
5, ' iInterface: Index of string descriptor
' HID Descriptor
0x09, ' bLength: HID Descriptor size
_USB_HID_DESCRIPTOR_TYPE, ' bDescriptorType: HID
0x11, ' bcdHID: HID Class Spec release number
0x01,
0x00, ' bCountryCode: Hardware target country
0x01, ' bNumDescriptors: Number of HID class descriptors to follow
0x22, ' bDescriptorType
_USB_HID_REPORT_DESC_SIZE, ' wItemLength: Total length of Report descriptor
0x00,
' Endpoint descriptor
0x07, ' bLength: Endpoint Descriptor size
_USB_DEV_DESCRIPTOR_TYPE_ENDPOINT, ' bDescriptorType:
_USB_HID_IN_EP, ' bEndpointAddress: Endpoint Address (IN)
0x03, ' bmAttributes: Interrupt endpoint
_USB_HID_IN_PACKET, ' wMaxPacketSize
0x00,
0x0A, ' bInterval: Polling Interval (10 ms)
' Endpoint descriptor
0x07, ' bLength: Endpoint Descriptor size
_USB_DEV_DESCRIPTOR_TYPE_ENDPOINT, ' bDescriptorType:
_USB_HID_OUT_EP, ' bEndpointAddress: Endpoint Address (OUT)
0x03, ' bmAttributes: Interrupt endpoint
_USB_HID_OUT_PACKET, ' wMaxPacketSize
0x00,
0x0A ' bInterval: Polling Interval (10 ms)
)
' HID report descriptor
const USB_HID_ReportDesc as byte[_USB_HID_REPORT_DESC_SIZE] = (
0x06, 0x00, 0xFF, ' Usage Page = 0xFF00 (Vendor Defined Page 1)
0x09, 0x01, ' Usage (Vendor Usage 1)
0xA1, 0x01, ' Collection (Application)
' Input report
0x19, 0x01, ' Usage Minimum
0x29, 0x40, ' Usage Maximum
0x15, 0x00, ' Logical Minimum (data bytes in the report may have minimum value = 0x00)
0x26, 0xFF, 0x00, ' Logical Maximum (data bytes in the report may have maximum value = 0x00FF = unsigned 255)
0x75, 0x08, ' Report Size: 8-bit field size
0x95, 64, ' Report Count
0x81, 0x02, ' Input (Data, Array, Abs)
' Output report
0x19, 0x01, ' Usage Minimum
0x29, 0x40, ' Usage Maximum
0x75, 0x08, ' Report Size: 8-bit field size
0x95, 64, ' Report Count
0x91, 0x02, ' Output (Data, Array, Abs)
0xC0 ' End Collection
)
end.
I assume the mE host library has more capabilities than the 'generic' one only.
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)
Re: Trying to put Dany's USB Host library to good use...
Hi, I am working on a more flexible HID Host library. It will be able to also handle devices with an other endpoint size than 64 (e.g. keyboards and mouses).
So, a little patience...
So, a little patience...
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)
Re: Trying to put Dany's USB Host library to good use...
Not wanting to pester you, but... Any news yet?Dany wrote:Hi, I am working on a more flexible HID Host library. It will be able to also handle devices with an other endpoint size than 64 (e.g. keyboards and mouses).
So, a little patience...
SeeYa!
Andrea
Andrea
-
- Posts: 6
- Joined: 09 Aug 2019 09:09
Re: Trying to put Dany's USB Host library to good use...
Dany wrote:Hi, I am working on a more flexible HID Host library. It will be able to also handle devices with an other endpoint size than 64 (e.g. keyboards and mouses).
So, a little patience...
Hi I need to communicate with another product that has a USB CDC.
Are there any examples of using MikroE with a HOST USB CDC? I have already done this using MPLAB-X, so I know its going to be a pain if I have to start from scratch.
Thanks
Rick
Re: Trying to put Dany's USB Host library to good use...
Hi, there is a new version of the HOST HID library, see https://libstock.mikroe.com/projects/vi ... st-library. It is capable now of handling mouses and keyboards.Falco-F8L wrote:Not wanting to pester you, but... Any news yet?Dany wrote:Hi, I am working on a more flexible HID Host library. It will be able to also handle devices with an other endpoint size than 64 (e.g. keyboards and mouses).
So, a little patience...
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)
Re: Trying to put Dany's USB Host library to good use...
Great - Thanks! It sems I'm in business now...Dany wrote:Hi, there is a new version of the HOST HID library, see https://libstock.mikroe.com/projects/vi ... st-library. It is capable now of handling mouses and keyboards.Falco-F8L wrote:Not wanting to pester you, but... Any news yet?Dany wrote:Hi, I am working on a more flexible HID Host library. It will be able to also handle devices with an other endpoint size than 64 (e.g. keyboards and mouses).
So, a little patience...
SeeYa!
Andrea
Andrea