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 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 void Parse(
HID *hid,
bool is_rpt_id, uint8_t len, uint8_t *buf);
178 virtual void OnKeyUp(uint8_t mod, uint8_t key) {
198 template <const u
int8_t BOOT_PROTOCOL>
208 uint32_t qNextPollTime;
215 return pRptParser[id];
222 pRptParser[id] = prs;
227 uint8_t
Init(uint8_t parent, uint8_t port,
bool lowspeed);
248 return (subklass == BOOT_PROTOCOL);
252 template <const u
int8_t BOOT_PROTOCOL>
259 for(
int i = 0; i <
epMUL(BOOT_PROTOCOL); i++) {
260 pRptParser[i] = NULL;
266 template <const u
int8_t BOOT_PROTOCOL>
269 epInfo[i].epAddr = 0;
270 epInfo[i].maxPktSize = (i) ? 0 : 8;
271 epInfo[i].epAttribs = 0;
279 template <const u
int8_t BOOT_PROTOCOL>
283 uint8_t buf[constBufSize];
323 rcode = pUsb->getDevDescr(0, 0, 8, (uint8_t*)buf);
326 len = (buf[0] > constBufSize) ? constBufSize : buf[0];
332 goto FailGetDevDescr;
348 rcode = pUsb->setAddr(0, 0, bAddress);
371 rcode = pUsb->getDevDescr(bAddress, 0, len, (uint8_t*)buf);
374 goto FailGetDevDescr;
382 USBTRACE(
"HID_PROTOCOL_KEYBOARD AND MOUSE\r\n");
388 confDescrParser.SetOR();
389 for(uint8_t i = 0; i < num_of_conf; i++) {
390 pUsb->getConfDescr(bAddress, 0, i, &confDescrParser);
397 USBTRACE(
"HID_PROTOCOL_KEYBOARD\r\n");
398 for(uint8_t i = 0; i < num_of_conf; i++) {
405 pUsb->getConfDescr(bAddress, 0, i, &confDescrParserA);
414 for(uint8_t i = 0; i < num_of_conf; i++) {
421 pUsb->getConfDescr(bAddress, 0, i, &confDescrParserB);
436 rcode = pUsb->setEpInfoEntry(bAddress, bNumEP, epInfo);
443 rcode = pUsb->setConf(bAddress, 0, bConfNum);
446 goto FailSetConfDescr;
454 for(uint8_t i = 0; i <
epMUL(BOOT_PROTOCOL); i++) {
457 if(rcode)
goto FailSetProtocol;
458 USBTRACE2(
"PROTOCOL SET HID_BOOT rcode:", rcode);
459 rcode = SetIdle(i, 0, 0);
464 rcode = GetReportDescr(i, &sink);
477 SetReport(0, 0, 2, 0, 1, &rcode);
487 #ifdef DEBUG_USB_HOST
505 #ifdef DEBUG_USB_HOST
511 #ifdef DEBUG_USB_HOST
522 #ifdef DEBUG_USB_HOST
530 template <const u
int8_t BOOT_PROTOCOL>
547 epInfo[bNumEP].epAttribs = 0;
554 template <const u
int8_t BOOT_PROTOCOL>
556 pUsb->GetAddressPool().FreeAddress(bAddress);
568 template <const u
int8_t BOOT_PROTOCOL>
572 if(bPollEnable && ((
long)(millis() - qNextPollTime) >= 0
L)) {
575 for(
int i = 0; i <
epMUL(BOOT_PROTOCOL); i++) {
576 const uint16_t const_buff_len = 16;
577 uint8_t buf[const_buff_len];
580 USBTRACE3(
"(hidboot.h) epInfo[epInterruptInIndex + i].epAddr=", epInfo[epInterruptInIndex + i].epAddr, 0x81);
581 USBTRACE3(
"(hidboot.h) epInfo[epInterruptInIndex + i].maxPktSize=", epInfo[epInterruptInIndex + i].maxPktSize, 0x81);
582 uint16_t read = (uint16_t)epInfo[epInterruptInIndex + i].maxPktSize;
584 rcode = pUsb->inTransfer(bAddress, epInfo[epInterruptInIndex + i].epAddr, &read, buf);
587 if(!rcode && read > 2) {
589 pRptParser[i]->Parse((
HID*)
this, 0, (uint8_t)read, buf);
590 #ifdef DEBUG_USB_HOST
594 USBTRACE3(
"(hidboot.h) Poll:", rcode, 0x81);
597 USBTRACE3(
"(hidboot.h) Strange read count: ", read, 0x80);
598 USBTRACE3(
"(hidboot.h) Interface:", i, 0x80);
603 for(uint8_t i = 0; i < read; i++) {
604 PrintHex<uint8_t > (buf[i], 0x80);
613 qNextPollTime = millis() + bInterval;
618 #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)
uint8_t SetReport(uint8_t ep, uint8_t iface, uint8_t report_type, uint8_t report_id, uint16_t nbytes, uint8_t *dataptr)
virtual uint8_t HandleLockingKeys(HID *hid, uint8_t key)
virtual void OnMiddleButtonUp(MOUSEINFO *mi)
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)
virtual bool DEVCLASSOK(uint8_t klass)
#define UHS_HID_BOOT_KEY_SCROLL_LOCK
#define NotifyFailGetDevDescr(...)
uint8_t Init(uint8_t parent, uint8_t port, bool lowspeed)
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
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 UHS_HID_BOOT_KEY_NUM_LOCK
#define USB_ERROR_CLASS_INSTANCE_ALREADY_IN_USE
#define totalEndpoints(p)
#define USB_ERROR_ADDRESS_NOT_FOUND_IN_POOL
union KeyboardReportParser::@17 prevState
#define USB_DEV_CONFIG_ERROR_DEVICE_NOT_SUPPORTED
virtual void OnControlKeysChanged(uint8_t before, uint8_t after)
virtual void OnLeftButtonDown(MOUSEINFO *mi)
virtual const uint8_t * getNumKeys()
#define HID_PROTOCOL_MOUSE
union KeyboardReportParser::@18 kbdLockingKeys
#define USB_ERROR_OUT_OF_ADDRESS_SPACE_IN_POOL
virtual const uint8_t * getPadKeys()
virtual bool DEVSUBCLASSOK(uint8_t subklass)
#define USBTRACE3(s, r, l)
uint8_t RegisterDeviceClass(USBDeviceConfig *pdev)
static const uint8_t totalEndpoints
#define NotifyFailSetConfDescr(...)
#define UHS_HID_BOOT_KEY_CAPS_LOCK
uint8_t OemToAscii(uint8_t mod, uint8_t key)