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 = 16;
586 uint8_t buf[const_buff_len];
589 USBTRACE3(
"(hidboot.h) epInfo[epInterruptInIndex + i].epAddr=", epInfo[epInterruptInIndex + i].epAddr, 0x81);
590 USBTRACE3(
"(hidboot.h) epInfo[epInterruptInIndex + i].maxPktSize=", epInfo[epInterruptInIndex + i].maxPktSize, 0x81);
591 uint16_t read = (uint16_t)epInfo[epInterruptInIndex + i].maxPktSize;
593 rcode = pUsb->inTransfer(bAddress, epInfo[epInterruptInIndex + i].epAddr, &read, buf);
596 if(!rcode && read > 2) {
598 pRptParser[i]->Parse((
USBHID*)
this, 0, (uint8_t)read, buf);
599 #ifdef DEBUG_USB_HOST 603 USBTRACE3(
"(hidboot.h) Poll:", rcode, 0x81);
606 USBTRACE3(
"(hidboot.h) Strange read count: ", read, 0x80);
607 USBTRACE3(
"(hidboot.h) Interface:", i, 0x80);
612 for(uint8_t i = 0; i < read; i++) {
613 PrintHex<uint8_t > (buf[i], 0x80);
622 qNextPollTime = (uint32_t)millis() + bInterval;
627 #endif // __HIDBOOTMOUSE_H__
#define CP_MASK_COMPARE_ALL
#define HID_BOOT_INTF_SUBCLASS
#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 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 USB_TRANSFER_TYPE_INTERRUPT
#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
virtual UsbDevice * GetUsbDevicePtr(uint8_t addr)=0
virtual const uint8_t * getSymKeysUp()
void Parse(USBHID *hid, bool is_rpt_id, uint8_t len, uint8_t *buf)
virtual void OnLeftButtonUp(MOUSEINFO *mi)
virtual uint8_t GetAddress()
#define USB_NAK_MAX_POWER
HIDBoot(USB *p, bool bRptProtoEnable=false)
uint8_t bInfo[sizeof(KBDINFO)]
virtual uint8_t HandleLockingKeys(USBHID *hid, uint8_t key)
uint8_t bInfo[sizeof(MOUSEINFO)]
virtual void OnMouseMove(MOUSEINFO *mi)
virtual void OnRightButtonUp(MOUSEINFO *mi)
#define bmUSB_TRANSFER_TYPE
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 USB_HID_PROTOCOL_KEYBOARD
#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)
static const uint8_t totalEndpoints
virtual void OnLeftButtonDown(MOUSEINFO *mi)
uint8_t SetReport(uint8_t ep, uint8_t iface, uint8_t report_type, uint8_t report_id, uint16_t nbytes, uint8_t *dataptr)
virtual const uint8_t * getNumKeys()
uint8_t bNumConfigurations
union KeyboardReportParser::@18 kbdLockingKeys
#define USB_ERROR_OUT_OF_ADDRESS_SPACE_IN_POOL
#define USB_HID_BOOT_PROTOCOL
virtual const uint8_t * getPadKeys()
void Parse(USBHID *hid, bool is_rpt_id, uint8_t len, uint8_t *buf)
virtual bool DEVSUBCLASSOK(uint8_t subklass)
#define USB_HID_PROTOCOL_MOUSE
#define USBTRACE3(s, r, l)
uint8_t RegisterDeviceClass(USBDeviceConfig *pdev)
#define NotifyFailSetConfDescr(...)
#define UHS_HID_BOOT_KEY_CAPS_LOCK
uint8_t OemToAscii(uint8_t mod, uint8_t key)