ukbd.c 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /*
  2. * File : ukbd.c
  3. * This file is part of RT-Thread RTOS
  4. * COPYRIGHT (C) 2011, RT-Thread Development Team
  5. *
  6. * The license and distribution terms for this file may be
  7. * found in the file LICENSE in this distribution or at
  8. * http://www.rt-thread.org/license/LICENSE
  9. *
  10. * Change Logs:
  11. * Date Author Notes
  12. * 2012-01-03 Yi Qiu first version
  13. */
  14. #include <rtthread.h>
  15. #include <drivers/usb_host.h>
  16. #include "hid.h"
  17. #if defined(RT_USBH_HID) && defined(RT_USBH_HID_KEYBOARD)
  18. static struct uprotocal kbd_protocal;
  19. static rt_err_t rt_usbh_hid_kbd_callback(void* arg)
  20. {
  21. int int1, int2;
  22. struct uhid* hid;
  23. hid = (struct uhid*)arg;
  24. int1 = *(rt_uint32_t*)hid->buffer;
  25. int2 = *(rt_uint32_t*)(&hid->buffer[4]);
  26. if(int1 != 0 || int2 != 0)
  27. {
  28. RT_DEBUG_LOG(RT_DEBUG_USB, ("key down 0x%x, 0x%x\n", int1, int2));
  29. }
  30. return RT_EOK;
  31. }
  32. static rt_err_t rt_usbh_hid_kbd_init(void* arg)
  33. {
  34. struct uintf* intf = (struct uintf*)arg;
  35. RT_ASSERT(intf != RT_NULL);
  36. rt_usbh_hid_set_protocal(intf, 0);
  37. rt_usbh_hid_set_idle(intf, 10, 0);
  38. //RT_DEBUG_LOG(RT_DEBUG_USB, ("start usb keyboard\n"));
  39. return RT_EOK;
  40. }
  41. /**
  42. * This function will define the hid keyboard protocal, it will be register to the protocal list.
  43. *
  44. * @return the keyboard protocal structure.
  45. */
  46. uprotocal_t rt_usbh_hid_protocal_kbd(void)
  47. {
  48. kbd_protocal.pro_id = USB_HID_KEYBOARD;
  49. kbd_protocal.init = rt_usbh_hid_kbd_init;
  50. kbd_protocal.callback = rt_usbh_hid_kbd_callback;
  51. return &kbd_protocal;
  52. }
  53. #endif