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;
#define USB_ERROR_OUT_OF_ADDRESS_SPACE_IN_POOL
#define USB_ERROR_CLASS_INSTANCE_ALREADY_IN_USE
#define USB_DEV_CONFIG_ERROR_DEVICE_NOT_SUPPORTED
#define USB_ERROR_EPINFO_IS_NULL
#define USB_ERROR_ADDRESS_NOT_FOUND_IN_POOL
#define USB_NAK_MAX_POWER
virtual void FreeAddress(uint8_t addr)=0
virtual uint8_t AllocAddress(uint8_t parent, bool is_hub=false, uint8_t port=0)=0
virtual UsbDevice * GetUsbDevicePtr(uint8_t addr)=0
virtual void EndpointXtract(uint8_t conf, uint8_t iface, uint8_t alt, uint8_t proto, const USB_ENDPOINT_DESCRIPTOR *ep)
virtual bool SetReportParser(uint8_t id, HIDReportParser *prs)
virtual uint8_t GetAddress()
virtual bool DEVCLASSOK(uint8_t klass)
uint8_t Init(uint8_t parent, uint8_t port, bool lowspeed)
HIDBoot(USB *p, bool bRptProtoEnable=false)
virtual bool DEVSUBCLASSOK(uint8_t subklass)
void Parse(USBHID *hid, bool is_rpt_id, uint8_t len, uint8_t *buf)
virtual const uint8_t * getSymKeysLo()
union KeyboardReportParser::@17 prevState
virtual const uint8_t * getSymKeysUp()
virtual void OnKeyUp(uint8_t mod, uint8_t key)
uint8_t bInfo[sizeof(KBDINFO)]
union KeyboardReportParser::@18 kbdLockingKeys
virtual const uint8_t * getNumKeys()
uint8_t OemToAscii(uint8_t mod, uint8_t key)
virtual void OnControlKeysChanged(uint8_t before, uint8_t after)
virtual void OnKeyDown(uint8_t mod, uint8_t key)
virtual const uint8_t * getPadKeys()
virtual uint8_t HandleLockingKeys(USBHID *hid, uint8_t key)
virtual void OnRightButtonUp(MOUSEINFO *mi)
virtual void OnMouseMove(MOUSEINFO *mi)
virtual void OnRightButtonDown(MOUSEINFO *mi)
virtual void OnLeftButtonUp(MOUSEINFO *mi)
virtual void OnMiddleButtonUp(MOUSEINFO *mi)
uint8_t bInfo[sizeof(MOUSEINFO)]
virtual void OnLeftButtonDown(MOUSEINFO *mi)
virtual void OnMiddleButtonDown(MOUSEINFO *mi)
void Parse(USBHID *hid, bool is_rpt_id, uint8_t len, uint8_t *buf)
static const uint8_t totalEndpoints
uint8_t SetReport(uint8_t ep, uint8_t iface, uint8_t report_type, uint8_t report_id, uint16_t nbytes, uint8_t *dataptr)
uint8_t RegisterDeviceClass(USBDeviceConfig *pdev)
#define CP_MASK_COMPARE_ALL
#define UHS_HID_BOOT_KEY_CAPS_LOCK
#define totalEndpoints(p)
#define UHS_HID_BOOT_KEY_NUM_LOCK
#define UHS_HID_BOOT_KEY_SCROLL_LOCK
#define USBTRACE3(s, r, l)
#define NotifyFailSetConfDescr(...)
#define NotifyFailGetDevDescr(...)
uint8_t bNumConfigurations
#define bmUSB_TRANSFER_TYPE
#define USB_TRANSFER_TYPE_INTERRUPT
#define USB_HID_PROTOCOL_MOUSE
#define USB_HID_BOOT_PROTOCOL
#define USB_HID_PROTOCOL_KEYBOARD
#define HID_BOOT_INTF_SUBCLASS