USB HID - Keyboard Mouse Examples

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

USB HID - Keyboard Mouse Examples

1,805 Views
tomtalkington
Contributor III

I am using two boards one running the keyboard and mouse host examples and one running the keyboard and mouse device examples. Unfortunately, the device examples are set up to constantly output data from the mouse or keyboard device.  When I plug the boards together I see a stream of data from the keyboard / mouse HID eval board on my host eval board.  If I plug in an actual keyboard to my hose eval board I only see data when I press a key.  

How do I make the device eval board behave this way?  When it is plugged into the host eval board the USB_DeviceHidKeyboardCallback is constantly being executed and it appears that it must result in a USB_DeviceHidSend call to function properly.

If I plug an real keyboard in the USB_DeviceHidKeyboardCallback is only executed when I press a key.

How do I get this behavior in the example code?

HID example is the frdmkl27z_dev_composite_hid_mouse_hid_keybaord_bm

Thanks,

Tom

0 Kudos
Reply
1 Reply

1,364 Views
FelipeGarcia
NXP Employee
NXP Employee

Hi Tom,

The behavior you mention is implemented in USB_DeviceHidKeyboardAction(void) in hid_keyboard.c

Please take the following code as an example of how you can send data by pressing SW1 and SW3 of your board.

static usb_status_t USB_DeviceHidKeyboardAction(void)
{
 s_UsbDeviceHidKeyboard.buffer[2] = 0x00U;
 if (g_Button1Press)
 {
  s_UsbDeviceHidKeyboard.buffer[2] = KEY_A;
  /* Reset state of button. */
  g_Button1Press = false;
 }
 if (g_Button3Press)
 {
  s_UsbDeviceHidKeyboard.buffer[2] = KEY_B;
  /* Reset state of button. */
  g_Button3Press = false;
 }

 return USB_DeviceHidSend(s_UsbDeviceComposite->hidKeyboardHandle, USB_HID_KEYBOARD_ENDPOINT_IN,
   s_UsbDeviceHidKeyboard.buffer, USB_HID_KEYBOARD_REPORT_LENGTH);
}‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

I hope this helps you.

Best regards,

Felipe

-------------------------------------------------------------------------------
Note:
- If this post answers your question, please click the "Mark Correct" button. Thank you!

- We are following threads for 7 weeks after the last post, later replies are ignored
Please open a new thread and refer to the closed one, if you have a related question at a later point in time.
-------------------------------------------------------------------------------

0 Kudos
Reply