Skip to content

Commit

Permalink
Merge branch 'master_add_duckyone2_support'
Browse files Browse the repository at this point in the history
  • Loading branch information
tmk committed Feb 1, 2023
2 parents 8d7ecfa + 204bc5d commit a98e6f7
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
16 changes: 16 additions & 0 deletions Usb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -550,6 +550,10 @@ void USB::Task(void) //USB state machine
case USB_STATE_RUNNING:
break;
case USB_STATE_ERROR:
USBTRACE2("ERROR:", usb_error);
// Wait and Bus Reset
delay = (uint32_t)millis() + USB_SETTLE_DELAY;
usb_task_state = USB_ATTACHED_SUBSTATE_SETTLE;
//MAX3421E::Init();
break;
} // switch( usb_task_state )
Expand Down Expand Up @@ -603,10 +607,16 @@ uint8_t USB::AttemptConfig(uint8_t driver, uint8_t parent, uint8_t port, bool lo
uint8_t rcode = devConfig[driver]->ConfigureDevice(parent, port, lowspeed);
if(rcode == USB_ERROR_CONFIG_REQUIRES_ADDITIONAL_RESET) {
if(parent == 0) {
USBTRACE(">>BUSRST\n");
// Send a bus reset on the root interface.
regWr(rHCTL, bmBUSRST); //issue bus reset
while ((regRd(rHCTL) & bmBUSRST)) { ; }
regWr(rHIRQ, bmFRAMEIRQ);
regWr(rMODE, regRd(rMODE) | bmSOFKAENAB);
while (!(regRd(rHIRQ) & bmFRAMEIRQ)) { ; }
delay(102); // delay 102ms, compensate for clock inaccuracy.
} else {
USBTRACE(">>HUBRST\n");
// reset parent port
devConfig[parent]->ResetHubPort(port);
}
Expand All @@ -626,10 +636,16 @@ uint8_t USB::AttemptConfig(uint8_t driver, uint8_t parent, uint8_t port, bool lo
if(rcode) {
// Issue a bus reset, because the device may be in a limbo state
if(parent == 0) {
USBTRACE(">>>>BUSRST\n");
// Send a bus reset on the root interface.
regWr(rHCTL, bmBUSRST); //issue bus reset
while ((regRd(rHCTL) & bmBUSRST)) { ; }
regWr(rHIRQ, bmFRAMEIRQ);
regWr(rMODE, regRd(rMODE) | bmSOFKAENAB);
while (!(regRd(rHIRQ) & bmFRAMEIRQ)) { ; }
delay(102); // delay 102ms, compensate for clock inaccuracy.
} else {
USBTRACE(">>>>HUBRST\n");
// reset parent port
devConfig[parent]->ResetHubPort(port);
}
Expand Down
21 changes: 21 additions & 0 deletions hidboot.h
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,8 @@ uint8_t HIDBoot<BOOT_PROTOCOL>::Init(uint8_t parent, uint8_t port, bool lowspeed
uint8_t num_of_conf; // number of configurations
//uint8_t num_of_intf; // number of interfaces

bool boot_interface = true;

AddressPool &addrPool = pUsb->GetAddressPool();

USBTRACE("BM Init\r\n");
Expand Down Expand Up @@ -418,6 +420,20 @@ uint8_t HIDBoot<BOOT_PROTOCOL>::Init(uint8_t parent, uint8_t port, bool lowspeed
pUsb->getConfDescr(bAddress, 0, i, &confDescrParserA);
if(bNumEP == (uint8_t)(totalEndpoints(BOOT_PROTOCOL)))
break;

// Not boot in SubClass
ConfigDescParser<
USB_CLASS_HID,
HID_BOOT_INTF_SUBCLASS,
USB_HID_PROTOCOL_KEYBOARD,
CP_MASK_COMPARE_CLASS | CP_MASK_COMPARE_PROTOCOL> confDescrParser2(this);

pUsb->getConfDescr(bAddress, 0, i, &confDescrParser2);
if(bNumEP == (uint8_t)(totalEndpoints(BOOT_PROTOCOL))) {
// not boot keyboard
boot_interface = false;
break;
}
}
}

Expand Down Expand Up @@ -467,9 +483,14 @@ uint8_t HIDBoot<BOOT_PROTOCOL>::Init(uint8_t parent, uint8_t port, bool lowspeed
for(uint8_t i = 0; i < epMUL(BOOT_PROTOCOL); i++) {
USBTRACE2("\r\nInterface:", bootIf[i]);

if (!boot_interface) {
USBTRACE("skip SET_PROTOCOL\n");
goto SKIP_SET_PROTOCOL;
}
rcode = SetProtocol(bootIf[i], bRptProtoEnable ? HID_RPT_PROTOCOL : USB_HID_BOOT_PROTOCOL);
USBTRACE2("SET_PROTOCOL: ", rcode);
if (rcode && rcode != hrSTALL) goto Fail;
SKIP_SET_PROTOCOL:

rcode = SetIdle(bootIf[i], 0, 0);
USBTRACE2("SET_IDLE: ", rcode);
Expand Down

0 comments on commit a98e6f7

Please sign in to comment.