Hello,
I am using the VNC2 chip as the USB host to handle HID devices (USB reader, barcode scanner and keyboard) scanning and transmitting data. Based on the example code "USBHostHIDKbd", I use the USBHost Driver and HID Driver in my code. In my code, I use the "usbhost_connect_state" function to check whether the plugin HID device has completed the enumertaion process and got the status of enumeration become PORT_STATE_ENUMERATED.
The following is my code which is almost the same as the sample function provided in example code:
unsigned char usbhost_connect_state(VOS_HANDLE hUSB) {
unsigned char connectstate = PORT_STATE_DISCONNECTED;
usbhost_ioctl_cb_t hc_iocb;
if (hUSB) {
hc_iocb.ioctl_code = VOS_IOCTL_USBHOST_GET_CONNECT_STATE;
hc_iocb.get = &connectstate;
vos_dev_ioctl(hUSB, &hc_iocb);
// repeat if connected to see if we move to enumerated
if (connectstate == PORT_STATE_CONNECTED) {
vos_dev_ioctl(hUSB, &hc_iocb);
}
}
return connectstate;
}
I can successfully transmit data on the very first plugin after flashing the .rom file on the VNC2 chip. However, when I remove the first plugined HID device and re-plugin another HID device, the status of enumeration result can not get into PORT_STATE_ENUMERATED. This made the another HID device cannot scan and transmit data.
I look up the Vinculum II User Guide documentation and found another code as follows:
unsigned char changeInEnumeration(VOS_HANDLE hUsbHost)
{
usbhost_ioctl_cb_t usbhost_iocb;
static unsigned short prev;
unsigned short i;
// wait until enumeration change
func_count++;
do
{
vos_delay_msecs(1);
usbhost_iocb.ioctl_code = VOS_IOCTL_USBHOST_GET_ENUMERATION_HANDLE;
usbhost_iocb.get = &i;
vos_dev_ioctl(hUsbHost, &usbhost_iocb);
} while (i == prev);
// keep handle for next call
prev = i;
return i;
}
When I declare the changeInEnumeration function in my code but not call it in main.c or any other functions, the enumeration works for all the HID devices no matter how many times for plugin, remove and re-plugin. I wonder is the changeInEnumeration function would be called in the background for VNC2 when plugin and remove the HID device? Or any suggestion to solve the enumeration between switches for different HID devices doing plugin and remove process of the HID devices are appreciated.
Thank you so much again!
Yvonne