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) & HID_PROTOCOL_KEYBOARD)? 2 : 0) | (((p) & HID_PROTOCOL_MOUSE)? 1 : 0))
33 #define totalEndpoints(p) ((bitsEndpoints(p) == 3) ? 3 : 2)
34 #define epMUL(p) ((((p) & HID_PROTOCOL_KEYBOARD)? 1 : 0) + (((p) & HID_PROTOCOL_MOUSE)? 1 : 0))
59 virtual void Parse(
HID *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 virtual void Parse(
HID *hid,
bool is_rpt_id, uint8_t len, uint8_t *buf);
158 virtual void OnKeyUp(uint8_t mod, uint8_t key) {
178 template <const u
int8_t BOOT_PROTOCOL>
188 uint32_t qNextPollTime;
195 return pRptParser[id];
202 pRptParser[id] = prs;
207 virtual uint8_t
Init(uint8_t parent, uint8_t port,
bool lowspeed);
209 virtual uint8_t
Poll();
219 template <const u
int8_t BOOT_PROTOCOL>
226 for(
int i = 0; i <
epMUL(BOOT_PROTOCOL); i++) {
227 pRptParser[i] = NULL;
233 template <const u
int8_t BOOT_PROTOCOL>
236 epInfo[i].epAddr = 0;
237 epInfo[i].maxPktSize = (i) ? 0 : 8;
238 epInfo[i].epAttribs = 0;
246 template <const u
int8_t BOOT_PROTOCOL>
250 uint8_t buf[constBufSize];
290 rcode = pUsb->getDevDescr(0, 0, 8, (uint8_t*)buf);
293 len = (buf[0] > constBufSize) ? constBufSize : buf[0];
299 goto FailGetDevDescr;
315 rcode = pUsb->setAddr(0, 0, bAddress);
338 rcode = pUsb->getDevDescr(bAddress, 0, len, (uint8_t*)buf);
341 goto FailGetDevDescr;
349 USBTRACE(
"HID_PROTOCOL_KEYBOARD AND MOUSE\r\n");
355 confDescrParser.SetOR();
356 for(uint8_t i = 0; i < num_of_conf; i++) {
357 pUsb->getConfDescr(bAddress, 0, i, &confDescrParser);
364 USBTRACE(
"HID_PROTOCOL_KEYBOARD\r\n");
365 for(uint8_t i = 0; i < num_of_conf; i++) {
372 pUsb->getConfDescr(bAddress, 0, i, &confDescrParserA);
381 for(uint8_t i = 0; i < num_of_conf; i++) {
388 pUsb->getConfDescr(bAddress, 0, i, &confDescrParserB);
403 rcode = pUsb->setEpInfoEntry(bAddress, bNumEP, epInfo);
410 rcode = pUsb->setConf(bAddress, 0, bConfNum);
413 goto FailSetConfDescr;
421 for(uint8_t i = 0; i <
epMUL(BOOT_PROTOCOL); i++) {
424 if(rcode)
goto FailSetProtocol;
425 USBTRACE2(
"PROTOCOL SET HID_BOOT rcode:", rcode);
426 rcode = SetIdle(i, 0, 0);
431 rcode = GetReportDescr(i, &sink);
444 SetReport(0, 0, 2, 0, 1, &rcode);
454 #ifdef DEBUG_USB_HOST
472 #ifdef DEBUG_USB_HOST
478 #ifdef DEBUG_USB_HOST
489 #ifdef DEBUG_USB_HOST
497 template <const u
int8_t BOOT_PROTOCOL>
514 epInfo[bNumEP].epAttribs = 0;
521 template <const u
int8_t BOOT_PROTOCOL>
523 pUsb->GetAddressPool().FreeAddress(bAddress);
535 template <const u
int8_t BOOT_PROTOCOL>
539 if(bPollEnable && ((
long)(millis() - qNextPollTime) >= 0
L)) {
542 for(
int i = 0; i <
epMUL(BOOT_PROTOCOL); i++) {
543 const uint16_t const_buff_len = 16;
544 uint8_t buf[const_buff_len];
547 USBTRACE3(
"(hidboot.h) epInfo[epInterruptInIndex + i].epAddr=", epInfo[epInterruptInIndex + i].epAddr, 0x81);
548 USBTRACE3(
"(hidboot.h) epInfo[epInterruptInIndex + i].maxPktSize=", epInfo[epInterruptInIndex + i].maxPktSize, 0x81);
549 uint16_t read = (uint16_t)epInfo[epInterruptInIndex + i].maxPktSize;
551 rcode = pUsb->inTransfer(bAddress, epInfo[epInterruptInIndex + i].epAddr, &read, buf);
554 if(!rcode && read > 2) {
556 pRptParser[i]->Parse((
HID*)
this, 0, (uint8_t)read, buf);
557 #ifdef DEBUG_USB_HOST
561 USBTRACE3(
"(hidboot.h) Poll:", rcode, 0x81);
564 USBTRACE3(
"(hidboot.h) Strange read count: ", read, 0x80);
565 USBTRACE3(
"(hidboot.h) Interface:", i, 0x80);
570 for(uint8_t i = 0; i < read; i++) {
571 PrintHex<uint8_t > (buf[i], 0x80);
580 qNextPollTime = millis() + bInterval;
585 #endif // __HIDBOOTMOUSE_H__
#define CP_MASK_COMPARE_ALL
#define USB_ERROR_EPINFO_IS_NULL
virtual const uint8_t * getSymKeysLo()
virtual void OnRightButtonDown(MOUSEINFO *mi)
virtual void OnKeyDown(uint8_t mod, uint8_t key)
virtual void OnMiddleButtonUp(MOUSEINFO *mi)
virtual uint8_t HandleLockingKeys(HID *hid, uint8_t key)
virtual void Parse(HID *hid, bool is_rpt_id, uint8_t len, uint8_t *buf)
virtual void EndpointXtract(uint8_t conf, uint8_t iface, uint8_t alt, uint8_t proto, const USB_ENDPOINT_DESCRIPTOR *ep)
union KeyboardReportParser::@14 kbdLockingKeys
#define NotifyFailGetDevDescr(...)
virtual uint8_t Init(uint8_t parent, uint8_t port, bool lowspeed)
union KeyboardReportParser::@13 prevState
virtual bool SetReportParser(uint8_t id, HIDReportParser *prs)
virtual void OnKeyUp(uint8_t mod, uint8_t key)
virtual void FreeAddress(uint8_t addr)=0
#define HID_PROTOCOL_KEYBOARD
virtual UsbDevice * GetUsbDevicePtr(uint8_t addr)=0
virtual void Parse(HID *hid, bool is_rpt_id, uint8_t len, uint8_t *buf)
virtual const uint8_t * getSymKeysUp()
#define HID_BOOT_PROTOCOL
virtual void OnLeftButtonUp(MOUSEINFO *mi)
virtual uint8_t GetAddress()
#define USB_NAK_MAX_POWER
#define HID_BOOT_INTF_SUBCLASS
uint8_t bInfo[sizeof(KBDINFO)]
uint8_t bInfo[sizeof(MOUSEINFO)]
virtual void OnMouseMove(MOUSEINFO *mi)
virtual void OnRightButtonUp(MOUSEINFO *mi)
virtual void OnMiddleButtonDown(MOUSEINFO *mi)
virtual uint8_t AllocAddress(uint8_t parent, bool is_hub=false, uint8_t port=0)=0
#define USB_ERROR_CLASS_INSTANCE_ALREADY_IN_USE
#define totalEndpoints(p)
#define USB_ERROR_ADDRESS_NOT_FOUND_IN_POOL
#define USB_DEV_CONFIG_ERROR_DEVICE_NOT_SUPPORTED
virtual void OnControlKeysChanged(uint8_t before, uint8_t after)
virtual uint8_t Release()
virtual void OnLeftButtonDown(MOUSEINFO *mi)
virtual const uint8_t * getNumKeys()
#define HID_PROTOCOL_MOUSE
#define USB_ERROR_OUT_OF_ADDRESS_SPACE_IN_POOL
virtual const uint8_t * getPadKeys()
#define USBTRACE3(s, r, l)
uint8_t RegisterDeviceClass(USBDeviceConfig *pdev)
static const uint8_t totalEndpoints
#define NotifyFailSetConfDescr(...)
uint8_t OemToAscii(uint8_t mod, uint8_t key)