2019-12-09 05:05 AM
Does anyone know how to make this keyboard work?
With the MAX3421E chip in conjunction with the USH30 library this works but with STM32CubeIDE not working properly.
https://www.amazon.com/Rii-Wireless-Keyboard-Touchpad%EF%BC%86QWERTY-Raspberry/dp/B00B9996LA
2019-12-12 05:47 AM
I manually set it to handle only the second interface and now things have reversed, the HID process no longer recognizes the keyboard keys but recognizes the touchpad buttons and movements.
File usbh_hid.c: (interface = 1)
static USBH_StatusTypeDef USBH_HID_InterfaceInit (USBH_HandleTypeDef *phost)
{
uint8_t max_ep;
uint8_t num = 0U;
uint8_t interface;
USBH_StatusTypeDef status = USBH_FAIL;
HID_HandleTypeDef *HID_Handle;
interface = 1; // USBH_FindInterface(phost, phost->pActiveClass->ClassCode, HID_BOOT_CODE, 0xFFU);
Debug output:
USB Device Attached
PID: 318h
VID: 513h
Address (#1) assigned.
Manufacturer : N/A
Product : N/A
Serial Number : N/A
Enumeration done.
This device has only 1 configuration.
Default configuration set.
Device remote wakeup enabled
Active Class: 3, Interface: 0
Number of Interfaces: 2
Switching to Interface (#1)
Class : 3h
SubClass : 1h
Protocol : 2h
Mouse device found!
HID class started.
Mouse action: x= 0x1, y= 0x0, button1 = 0x0, button2 = 0x0, button3 = 0x0
Mouse action: x= 0x2, y= 0x0, button1 = 0x1, button2 = 0x0, button3 = 0x0
Mouse action: x= 0x0, y= 0x0, button1 = 0x1, button2 = 0x0, button3 = 0x0
Mouse action: x= 0x2, y= 0x0, button1 = 0x1, button2 = 0x0, button3 = 0x0
Mouse action: x= 0x0, y= 0x0, button1 = 0x1, button2 = 0x0, button3 = 0x0
Mouse action: x= 0x0, y= 0xf3, button1 = 0x1, button2 = 0x0, button3 = 0x0
Mouse action: x= 0x0, y= 0xf3, button1 = 0x1, button2 = 0x0, button3 = 0x0
Mouse action: x= 0x0, y= 0xf3, button1 = 0x1, button2 = 0x0, button3 = 0x0
Mouse action: x= 0x0, y= 0xf6, button1 = 0x1, button2 = 0x0, button3 = 0x0
Mouse action: x= 0x0, y= 0xf5, button1 = 0x1, button2 = 0x0, button3 = 0x0
Mouse action: x= 0x0, y= 0xf4, button1 = 0x1, button2 = 0x0, button3 = 0x0
Mouse action: x= 0x0, y= 0xf9, button1 = 0x1, button2 = 0x0, button3 = 0x0
Mouse action: x= 0x0, y= 0xf9, button1 = 0x1, button2 = 0x0, button3 = 0x0
Mouse action: x= 0x0, y= 0xfb, button1 = 0x1, button2 = 0x0, button3 = 0x0
Mouse action: x= 0x0, y= 0xfd, button1 = 0x1, button2 = 0x0, button3 = 0x0
Mouse action: x= 0x0, y= 0xff, button1 = 0x1, button2 = 0x0, button3 = 0x0
Mouse action: x= 0x0, y= 0x0, button1 = 0x1, button2 = 0x0, button3 = 0x0
Mouse action: x= 0x0, y= 0x3, button1 = 0x1, button2 = 0x0, button3 = 0x0
Mouse action: x= 0x0, y= 0x5, button1 = 0x1, button2 = 0x0, button3 = 0x0
Mouse action: x= 0x0, y= 0x9, button1 = 0x1, button2 = 0x0, button3 = 0x0
Key of keyboard pressed:
USB Device disconnected
USB Device Attached
PID: 318h
VID: 513h
Address (#1) assigned.
Manufacturer : N/A
Product : N/A
Serial Number : N/A
Enumeration done.
This device has only 1 configuration.
Default configuration set.
Device remote wakeup enabled
Active Class: 3, Interface: 0
Number of Interfaces: 2
Switching to Interface (#1)
Class : 3h
SubClass : 1h
Protocol : 2h
Mouse device found!
HID class started.
Mouse action: x= 0x1, y= 0x0, button1 = 0x0, button2 = 0x0, button3 = 0x0
Mouse action: x= 0x0, y= 0x0, button1 = 0x1, button2 = 0x0, button3 = 0x0
Note that the HID process restarted when a key was pressed. So the problem is dealing with both interfaces, the library is working with only the first interface (0).
2019-12-12 08:15 AM
I managed to make it work poorly (for tests).
First I had the interface toggle each time a disconnect occurs. It seems that we need to treat both interfaces in sequence, if left as it is, alternating when switching from keyboard to touchpad, or vice versa, the first interaction is lost.
And the other thing I noticed was that an enumeration problem occurs, and so the process crashes, because there is no timeout to escape errors. I added a 32-bit variable to try to force a restart, and it seems to work.
usbh_core.c:
case HOST_ENUMERATION:
/* Check for enumeration status */
if ( USBH_HandleEnum(phost) == USBH_OK)
{
enumTimeout=0;
/* The function shall return USBH_OK when full enumeration is complete */
USBH_UsrLog ("Enumeration done.");
// phost->device.current_interface = 0U;
if(phost->device.current_interface != 0){
phost->device.current_interface = 0;
} else {
phost->device.current_interface = 1;
}
if(phost->device.DevDesc.bNumConfigurations == 1U)
{
USBH_UsrLog ("This device has only 1 configuration.");
phost->gState = HOST_SET_CONFIGURATION;
}
else
{
phost->gState = HOST_INPUT;
}
}
else
{
if(enumTimeout < 0xffff){
enumTimeout++;
}
else
{
enumTimeout=0;
USBH_UsrLog ("Enumeration fail.");
USBH_DeInit(phost);
MX_USB_HOST_Init();
}
}
break;
usbh_hid.c:
static USBH_StatusTypeDef USBH_HID_InterfaceInit (USBH_HandleTypeDef *phost)
{
uint8_t max_ep;
uint8_t num = 0U;
uint8_t interface;
USBH_StatusTypeDef status = USBH_FAIL;
HID_HandleTypeDef *HID_Handle;
interface = phost->device.current_interface; // USBH_FindInterface(phost, phost->pActiveClass->ClassCode, HID_BOOT_CODE, 0xFFU);