Keyboard firmwares for Atmel AVR and Cortex-M
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

hid.cpp 4.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. /* Copyright (C) 2011 Circuits At Home, LTD. All rights reserved.
  2. This software may be distributed and modified under the terms of the GNU
  3. General Public License version 2 (GPL2) as published by the Free Software
  4. Foundation and appearing in the file GPL2.TXT included in the packaging of
  5. this file. Please note that GPL2 Section 2[b] requires that all works based
  6. on this software must also be made publicly available under the terms of
  7. the GPL2 ("Copyleft").
  8. Contact information
  9. -------------------
  10. Circuits At Home, LTD
  11. Web : http://www.circuitsathome.com
  12. e-mail : [email protected]
  13. */
  14. #include "hid.h"
  15. //get HID report descriptor
  16. /* WRONG! Endpoint is _ALWAYS_ ZERO for HID! We want the _INTERFACE_ value here!
  17. uint8_t HID::GetReportDescr(uint8_t ep, USBReadParser *parser) {
  18. const uint8_t constBufLen = 64;
  19. uint8_t buf[constBufLen];
  20. uint8_t rcode = pUsb->ctrlReq(bAddress, ep, bmREQ_HID_REPORT, USB_REQUEST_GET_DESCRIPTOR, 0x00,
  21. HID_DESCRIPTOR_REPORT, 0x0000, 128, constBufLen, buf, (USBReadParser*)parser);
  22. //return ((rcode != hrSTALL) ? rcode : 0);
  23. return rcode;
  24. }
  25. */
  26. uint8_t HID::GetReportDescr(uint16_t wIndex, USBReadParser *parser) {
  27. const uint8_t constBufLen = 64;
  28. uint8_t buf[constBufLen];
  29. uint8_t rcode = pUsb->ctrlReq(bAddress, 0x00, bmREQ_HID_REPORT, USB_REQUEST_GET_DESCRIPTOR, 0x00,
  30. HID_DESCRIPTOR_REPORT, wIndex, 128, constBufLen, buf, (USBReadParser*)parser);
  31. //return ((rcode != hrSTALL) ? rcode : 0);
  32. return rcode;
  33. }
  34. //uint8_t HID::getHidDescr( uint8_t ep, uint16_t nbytes, uint8_t* dataptr )
  35. //{
  36. // return( pUsb->ctrlReq( bAddress, ep, bmREQ_GET_DESCR, USB_REQUEST_GET_DESCRIPTOR, 0x00, HID_DESCRIPTOR_HID, 0x0000, nbytes, dataptr ));
  37. //}
  38. uint8_t HID::SetReport(uint8_t ep, uint8_t iface, uint8_t report_type, uint8_t report_id, uint16_t nbytes, uint8_t* dataptr) {
  39. return ( pUsb->ctrlReq(bAddress, ep, bmREQ_HID_OUT, HID_REQUEST_SET_REPORT, report_id, report_type, iface, nbytes, nbytes, dataptr, NULL));
  40. }
  41. uint8_t HID::GetReport(uint8_t ep, uint8_t iface, uint8_t report_type, uint8_t report_id, uint16_t nbytes, uint8_t* dataptr) {
  42. return ( pUsb->ctrlReq(bAddress, ep, bmREQ_HID_IN, HID_REQUEST_GET_REPORT, report_id, report_type, iface, nbytes, nbytes, dataptr, NULL));
  43. }
  44. uint8_t HID::GetIdle(uint8_t iface, uint8_t reportID, uint8_t* dataptr) {
  45. return ( pUsb->ctrlReq(bAddress, 0, bmREQ_HID_IN, HID_REQUEST_GET_IDLE, reportID, 0, iface, 0x0001, 0x0001, dataptr, NULL));
  46. }
  47. uint8_t HID::SetIdle(uint8_t iface, uint8_t reportID, uint8_t duration) {
  48. return ( pUsb->ctrlReq(bAddress, 0, bmREQ_HID_OUT, HID_REQUEST_SET_IDLE, reportID, duration, iface, 0x0000, 0x0000, NULL, NULL));
  49. }
  50. uint8_t HID::SetProtocol(uint8_t iface, uint8_t protocol) {
  51. return ( pUsb->ctrlReq(bAddress, 0, bmREQ_HID_OUT, HID_REQUEST_SET_PROTOCOL, protocol, 0x00, iface, 0x0000, 0x0000, NULL, NULL));
  52. }
  53. uint8_t HID::GetProtocol(uint8_t iface, uint8_t* dataptr) {
  54. return ( pUsb->ctrlReq(bAddress, 0, bmREQ_HID_IN, HID_REQUEST_GET_PROTOCOL, 0x00, 0x00, iface, 0x0001, 0x0001, dataptr, NULL));
  55. }
  56. void HID::PrintEndpointDescriptor(const USB_ENDPOINT_DESCRIPTOR* ep_ptr) {
  57. Notify(PSTR("Endpoint descriptor:"), 0x80);
  58. Notify(PSTR("\r\nLength:\t\t"), 0x80);
  59. D_PrintHex<uint8_t > (ep_ptr->bLength, 0x80);
  60. Notify(PSTR("\r\nType:\t\t"), 0x80);
  61. D_PrintHex<uint8_t > (ep_ptr->bDescriptorType, 0x80);
  62. Notify(PSTR("\r\nAddress:\t"), 0x80);
  63. D_PrintHex<uint8_t > (ep_ptr->bEndpointAddress, 0x80);
  64. Notify(PSTR("\r\nAttributes:\t"), 0x80);
  65. D_PrintHex<uint8_t > (ep_ptr->bmAttributes, 0x80);
  66. Notify(PSTR("\r\nMaxPktSize:\t"), 0x80);
  67. D_PrintHex<uint16_t > (ep_ptr->wMaxPacketSize, 0x80);
  68. Notify(PSTR("\r\nPoll Intrv:\t"), 0x80);
  69. D_PrintHex<uint8_t > (ep_ptr->bInterval, 0x80);
  70. }
  71. void HID::PrintHidDescriptor(const USB_HID_DESCRIPTOR *pDesc) {
  72. Notify(PSTR("\r\n\r\nHID Descriptor:\r\n"), 0x80);
  73. Notify(PSTR("bDescLength:\t\t"), 0x80);
  74. D_PrintHex<uint8_t > (pDesc->bLength, 0x80);
  75. Notify(PSTR("\r\nbDescriptorType:\t"), 0x80);
  76. D_PrintHex<uint8_t > (pDesc->bDescriptorType, 0x80);
  77. Notify(PSTR("\r\nbcdHID:\t\t\t"), 0x80);
  78. D_PrintHex<uint16_t > (pDesc->bcdHID, 0x80);
  79. Notify(PSTR("\r\nbCountryCode:\t\t"), 0x80);
  80. D_PrintHex<uint8_t > (pDesc->bCountryCode, 0x80);
  81. Notify(PSTR("\r\nbNumDescriptors:\t"), 0x80);
  82. D_PrintHex<uint8_t > (pDesc->bNumDescriptors, 0x80);
  83. Notify(PSTR("\r\nbDescrType:\t\t"), 0x80);
  84. D_PrintHex<uint8_t > (pDesc->bDescrType, 0x80);
  85. Notify(PSTR("\r\nwDescriptorLength:\t"), 0x80);
  86. D_PrintHex<uint16_t > (pDesc->wDescriptorLength, 0x80);
  87. }