17 #if !defined(__HIDBOOT_H__)
22 #define UHS_HID_BOOT_KEY_ZERO 0x27
23 #define UHS_HID_BOOT_KEY_ENTER 0x28
24 #define UHS_HID_BOOT_KEY_SPACE 0x2c
25 #define UHS_HID_BOOT_KEY_CAPS_LOCK 0x39
26 #define UHS_HID_BOOT_KEY_SCROLL_LOCK 0x47
27 #define UHS_HID_BOOT_KEY_NUM_LOCK 0x53
28 #define UHS_HID_BOOT_KEY_ZERO2 0x62
29 #define UHS_HID_BOOT_KEY_PERIOD 0x63
32 #define bitsEndpoints(p) ((((p) & USB_HID_PROTOCOL_KEYBOARD)? 2 : 0) | (((p) & USB_HID_PROTOCOL_MOUSE)? 1 : 0))
33 #define totalEndpoints(p) ((bitsEndpoints(p) == 3) ? 3 : 2)
34 #define epMUL(p) ((((p) & USB_HID_PROTOCOL_KEYBOARD)? 1 : 0) + (((p) & USB_HID_PROTOCOL_MOUSE)? 1 : 0))
59 void Parse(
USBHID *hid,
bool is_rpt_id, uint8_t len, uint8_t *buf);
122 static const uint8_t numKeys[10];
123 static const uint8_t symKeysUp[12];
124 static const uint8_t symKeysLo[12];
125 static const uint8_t padKeys[5];
147 void Parse(
USBHID *hid,
bool is_rpt_id, uint8_t len, uint8_t *buf);
168 return (hid->
SetReport(0, 0, 2, 0, 1, &lockLeds));
174 virtual void OnControlKeysChanged(uint8_t before __attribute__((unused)), uint8_t after __attribute__((unused))) {
177 virtual void OnKeyDown(uint8_t mod __attribute__((unused)), uint8_t key __attribute__((unused))) {
180 virtual void OnKeyUp(uint8_t mod __attribute__((unused)), uint8_t key __attribute__((unused))) {
200 template <const u
int8_t BOOT_PROTOCOL>
210 uint32_t qNextPollTime;
213 bool bRptProtoEnable;
218 return pRptParser[id];
222 HIDBoot(
USB *p,
bool bRptProtoEnable =
false);
225 pRptParser[id] = prs;
230 uint8_t
Init(uint8_t parent, uint8_t port,
bool lowspeed);
251 return (subklass == BOOT_PROTOCOL);
255 template <const u
int8_t BOOT_PROTOCOL>
260 bRptProtoEnable(bRptProtoEnable) {
263 for(
int i = 0; i <
epMUL(BOOT_PROTOCOL); i++) {
264 pRptParser[i] = NULL;
270 template <const u
int8_t BOOT_PROTOCOL>
273 epInfo[i].epAddr = 0;
274 epInfo[i].maxPktSize = (i) ? 0 : 8;
275 epInfo[i].bmSndToggle = 0;
276 epInfo[i].bmRcvToggle = 0;
284 template <const u
int8_t BOOT_PROTOCOL>
288 uint8_t buf[constBufSize];
329 rcode = pUsb->getDevDescr(0, 0, 8, (uint8_t*)buf);
332 len = (buf[0] > constBufSize) ? constBufSize : buf[0];
340 goto FailGetDevDescr;
356 rcode = pUsb->setAddr(0, 0, bAddress);
379 rcode = pUsb->getDevDescr(bAddress, 0, len, (uint8_t*)buf);
382 goto FailGetDevDescr;
390 USBTRACE(
"HID_PROTOCOL_KEYBOARD AND MOUSE\r\n");
396 confDescrParser.SetOR();
397 for(uint8_t i = 0; i < num_of_conf; i++) {
398 pUsb->getConfDescr(bAddress, 0, i, &confDescrParser);
405 USBTRACE(
"HID_PROTOCOL_KEYBOARD\r\n");
406 for(uint8_t i = 0; i < num_of_conf; i++) {
413 pUsb->getConfDescr(bAddress, 0, i, &confDescrParserA);
422 for(uint8_t i = 0; i < num_of_conf; i++) {
429 pUsb->getConfDescr(bAddress, 0, i, &confDescrParserB);
444 rcode = pUsb->setEpInfoEntry(bAddress, bNumEP, epInfo);
451 rcode = pUsb->setConf(bAddress, 0, bConfNum);
454 goto FailSetConfDescr;
462 for(uint8_t i = 0; i <
epMUL(BOOT_PROTOCOL); i++) {
465 if(rcode)
goto FailSetProtocol;
466 USBTRACE2(
"PROTOCOL SET HID_BOOT rcode:", rcode);
467 rcode = SetIdle(i, 0, 0);
472 rcode = GetReportDescr(i, &sink);
485 SetReport(0, 0, 2, 0, 1, &rcode);
495 #ifdef DEBUG_USB_HOST
513 #ifdef DEBUG_USB_HOST
519 #ifdef DEBUG_USB_HOST
530 #ifdef DEBUG_USB_HOST
538 template <const u
int8_t BOOT_PROTOCOL>
555 epInfo[bNumEP].bmSndToggle = 0;
556 epInfo[bNumEP].bmRcvToggle = 0;
563 template <const u
int8_t BOOT_PROTOCOL>
565 pUsb->GetAddressPool().FreeAddress(bAddress);
577 template <const u
int8_t BOOT_PROTOCOL>
581 if(bPollEnable && ((int32_t)((uint32_t)millis() - qNextPollTime) >= 0
L)) {
584 for(
int i = 0; i <
epMUL(BOOT_PROTOCOL); i++) {
585 const uint16_t const_buff_len = 64;
588 USBTRACE3(
"(hidboot.h) epInfo[epInterruptInIndex + i].epAddr=", epInfo[epInterruptInIndex + i].epAddr, 0x81);
589 USBTRACE3(
"(hidboot.h) epInfo[epInterruptInIndex + i].maxPktSize=", epInfo[epInterruptInIndex + i].maxPktSize, 0x81);
590 uint16_t read = (uint16_t)epInfo[epInterruptInIndex + i].maxPktSize;
592 if (read > const_buff_len)
593 read = const_buff_len;
597 rcode = pUsb->inTransfer(bAddress, epInfo[epInterruptInIndex + i].epAddr, &read, buf);
600 if(!rcode && read > 2) {
602 pRptParser[i]->Parse((
USBHID*)
this, 0, (uint8_t)read, buf);
603 #ifdef DEBUG_USB_HOST
607 USBTRACE3(
"(hidboot.h) Poll:", rcode, 0x81);
610 USBTRACE3(
"(hidboot.h) Strange read count: ", read, 0x80);
611 USBTRACE3(
"(hidboot.h) Interface:", i, 0x80);
616 for(uint8_t i = 0; i < read; i++) {
617 PrintHex<uint8_t > (buf[i], 0x80);
626 qNextPollTime = (uint32_t)millis() + bInterval;
631 #endif // __HIDBOOTMOUSE_H__