cancel
Showing results for 
Search instead for 
Did you mean: 

Reg. USB HOST HID Class Keyboard Implementation

shefu
Associate II

Hello,

I have been using STM USB HOST HID class library to implement the USB keyboard on my STM32F429ZI custom board. I have been able to successfully enumerate the USB keyboard and getting the key pressed on the keyboard using the custom keyread() function in blocking mode as per mentioned below:

char keyread()
{
HID_KEYBD_Info_TypeDef *k_pinfo;
char c;
while(1){

MX_USB_HOST_Process();
if(Appli_state == APPLICATION_READY)
{
if(USBH_HID_GetDeviceType(&hUsbHostFS) == HID_KEYBOARD)
{
k_pinfo = USBH_HID_GetKeybdInfo(&hUsbHostFS);
if(k_pinfo != NULL)
{
c = USBH_HID_GetASCIICode(k_pinfo);
if(c != '\0')
return c;
}
}
}
}
return 0;
}

For my application I need to implement the RTC updating GLCD screen and if a key is pressed then it update the screen content with the custom character else it shows the RTC data continously. For this I need to detect the Keyboard key press in between but the above mentioned keyread() is a blocking function so it will not update GLCD screen data with the RTC data and will keep waiting for the key press.

 

Now for my application I need to implement a function which can identify if a key is pressed or not in non blocking mode. I have tried the above function without while loop but did not get any success.

char ifkeyread()
{
HID_KEYBD_Info_TypeDef *k_pinfo;
char c=0;
//while(1)
{

MX_USB_HOST_Process();
if(Appli_state == APPLICATION_READY)
{
if(USBH_HID_GetDeviceType(&hUsbHostFS) == HID_KEYBOARD)
{
k_pinfo = USBH_HID_GetKeybdInfo(&hUsbHostFS);
if(k_pinfo != NULL)
{
c = USBH_HID_GetASCIICode(k_pinfo);
//if(c != '\0')
// return c;
}
// else
// return 0;
}
// else
// return 0;
}
// else
// return 0;
}


return c;
}

 

This function is not working. Can anybody suggest me how to determine whether a key is pressed or not in non blocking mode.

1 REPLY 1
Pavel A.
Evangelist III

Get inside the USBH_HID_GetKeybdInfo functon, find where it blocks. The source is available.

Instead of blocking, return NULL when no data is ready.

If this sounds too hard and you'd like help with coding, look here.