ukbd.c 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /*
  2. * Copyright (c) 2006-2018, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2012-01-03 Yi Qiu first version
  9. */
  10. #include <rtthread.h>
  11. #include <drivers/usb_host.h>
  12. #include "hid.h"
  13. #if defined(RT_USBH_HID) && defined(RT_USBH_HID_KEYBOARD)
  14. static struct uprotocal kbd_protocal;
  15. static rt_err_t rt_usbh_hid_kbd_callback(void* arg)
  16. {
  17. int int1, int2;
  18. struct uhid* hid;
  19. hid = (struct uhid*)arg;
  20. int1 = *(rt_uint32_t*)hid->buffer;
  21. int2 = *(rt_uint32_t*)(&hid->buffer[4]);
  22. if(int1 != 0 || int2 != 0)
  23. {
  24. RT_DEBUG_LOG(RT_DEBUG_USB, ("key down 0x%x, 0x%x\n", int1, int2));
  25. }
  26. return RT_EOK;
  27. }
  28. static rt_err_t rt_usbh_hid_kbd_init(void* arg)
  29. {
  30. struct uintf* intf = (struct uintf*)arg;
  31. RT_ASSERT(intf != RT_NULL);
  32. rt_usbh_hid_set_protocal(intf, 0);
  33. rt_usbh_hid_set_idle(intf, 10, 0);
  34. //RT_DEBUG_LOG(RT_DEBUG_USB, ("start usb keyboard\n"));
  35. return RT_EOK;
  36. }
  37. /**
  38. * This function will define the hid keyboard protocal, it will be register to the protocal list.
  39. *
  40. * @return the keyboard protocal structure.
  41. */
  42. uprotocal_t rt_usbh_hid_protocal_kbd(void)
  43. {
  44. kbd_protocal.pro_id = USB_HID_KEYBOARD;
  45. kbd_protocal.init = rt_usbh_hid_kbd_init;
  46. kbd_protocal.callback = rt_usbh_hid_kbd_callback;
  47. return &kbd_protocal;
  48. }
  49. #endif