mirror of
https://github.com/felis/USB_Host_Shield_2.0.git
synced 2024-03-22 11:31:26 +01:00
Fix hidboot not allocating or checking properly on mouse.
Removal of duplicate code: Force all drivers to delay after setting address.
This commit is contained in:
parent
fcaef6f5a2
commit
77efe42a71
7 changed files with 68 additions and 44 deletions
|
@ -129,7 +129,7 @@ uint8_t PS3USB::Init(uint8_t parent, uint8_t port, bool lowspeed) {
|
||||||
Notify(PSTR("\r\nAddr: "), 0x80);
|
Notify(PSTR("\r\nAddr: "), 0x80);
|
||||||
D_PrintHex<uint8_t > (bAddress, 0x80);
|
D_PrintHex<uint8_t > (bAddress, 0x80);
|
||||||
#endif
|
#endif
|
||||||
delay(300); // Spec says you should wait at least 200ms
|
//delay(300); // Spec says you should wait at least 200ms
|
||||||
|
|
||||||
p->lowspeed = false;
|
p->lowspeed = false;
|
||||||
|
|
||||||
|
|
6
Usb.cpp
6
Usb.cpp
|
@ -794,7 +794,11 @@ uint8_t USB::getStrDescr(uint8_t addr, uint8_t ep, uint16_t ns, uint8_t index, u
|
||||||
//set address
|
//set address
|
||||||
|
|
||||||
uint8_t USB::setAddr(uint8_t oldaddr, uint8_t ep, uint8_t newaddr) {
|
uint8_t USB::setAddr(uint8_t oldaddr, uint8_t ep, uint8_t newaddr) {
|
||||||
return ( ctrlReq(oldaddr, ep, bmREQ_SET, USB_REQUEST_SET_ADDRESS, newaddr, 0x00, 0x0000, 0x0000, 0x0000, NULL, NULL));
|
uint8_t rcode = ctrlReq(oldaddr, ep, bmREQ_SET, USB_REQUEST_SET_ADDRESS, newaddr, 0x00, 0x0000, 0x0000, 0x0000, NULL, NULL);
|
||||||
|
//delay(2); //per USB 2.0 sect.9.2.6.3
|
||||||
|
delay(300); // Older spec says you should wait at least 200ms
|
||||||
|
return rcode;
|
||||||
|
//return ( ctrlReq(oldaddr, ep, bmREQ_SET, USB_REQUEST_SET_ADDRESS, newaddr, 0x00, 0x0000, 0x0000, 0x0000, NULL, NULL));
|
||||||
}
|
}
|
||||||
//set configuration
|
//set configuration
|
||||||
|
|
||||||
|
|
|
@ -145,7 +145,7 @@ uint8_t XBOXOLD::Init(uint8_t parent, uint8_t port, bool lowspeed) {
|
||||||
Notify(PSTR("\r\nAddr: "), 0x80);
|
Notify(PSTR("\r\nAddr: "), 0x80);
|
||||||
D_PrintHex<uint8_t > (bAddress, 0x80);
|
D_PrintHex<uint8_t > (bAddress, 0x80);
|
||||||
#endif
|
#endif
|
||||||
delay(300); // Spec says you should wait at least 200ms
|
//delay(300); // Spec says you should wait at least 200ms
|
||||||
|
|
||||||
p->lowspeed = false;
|
p->lowspeed = false;
|
||||||
|
|
||||||
|
|
|
@ -133,7 +133,7 @@ uint8_t XBOXUSB::Init(uint8_t parent, uint8_t port, bool lowspeed) {
|
||||||
Notify(PSTR("\r\nAddr: "), 0x80);
|
Notify(PSTR("\r\nAddr: "), 0x80);
|
||||||
D_PrintHex<uint8_t > (bAddress, 0x80);
|
D_PrintHex<uint8_t > (bAddress, 0x80);
|
||||||
#endif
|
#endif
|
||||||
delay(300); // Spec says you should wait at least 200ms
|
//delay(300); // Spec says you should wait at least 200ms
|
||||||
|
|
||||||
p->lowspeed = false;
|
p->lowspeed = false;
|
||||||
|
|
||||||
|
|
2
adk.cpp
2
adk.cpp
|
@ -128,7 +128,7 @@ uint8_t ADK::Init(uint8_t parent, uint8_t port, bool lowspeed) {
|
||||||
|
|
||||||
//USBTRACE2("\r\nAddr:", bAddress);
|
//USBTRACE2("\r\nAddr:", bAddress);
|
||||||
// Spec says you should wait at least 200ms.
|
// Spec says you should wait at least 200ms.
|
||||||
delay(300);
|
//delay(300);
|
||||||
|
|
||||||
p->lowspeed = false;
|
p->lowspeed = false;
|
||||||
|
|
||||||
|
|
64
hidboot.h
64
hidboot.h
|
@ -28,7 +28,6 @@ e-mail : support@circuitsathome.com
|
||||||
#define UHS_HID_BOOT_KEY_ZERO2 0x62
|
#define UHS_HID_BOOT_KEY_ZERO2 0x62
|
||||||
#define UHS_HID_BOOT_KEY_PERIOD 0x63
|
#define UHS_HID_BOOT_KEY_PERIOD 0x63
|
||||||
|
|
||||||
|
|
||||||
struct MOUSEINFO {
|
struct MOUSEINFO {
|
||||||
|
|
||||||
struct {
|
struct {
|
||||||
|
@ -168,15 +167,16 @@ protected:
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
#define totalEndpoints (((BOOT_PROTOCOL & HID_PROTOCOL_KEYBOARD)? 2 : 0)+((BOOT_PROTOCOL & HID_PROTOCOL_MOUSE)? 1 : 0))
|
#define bitsEndpoints(p) (((p & HID_PROTOCOL_KEYBOARD)? 2 : 0)+((p & HID_PROTOCOL_MOUSE)? 1 : 0))
|
||||||
#define epMUL (((BOOT_PROTOCOL & HID_PROTOCOL_KEYBOARD)? 1 : 0)+((BOOT_PROTOCOL & HID_PROTOCOL_MOUSE)? 1 : 0))
|
#define totalEndpoints(p) ((bitsEndpoints(p) == 3) ? 3 : 2)
|
||||||
|
#define epMUL(p) (((p & HID_PROTOCOL_KEYBOARD)? 1 : 0)+((p & HID_PROTOCOL_MOUSE)? 1 : 0))
|
||||||
#define HID_MAX_HID_CLASS_DESCRIPTORS 5
|
#define HID_MAX_HID_CLASS_DESCRIPTORS 5
|
||||||
|
|
||||||
template <const uint8_t BOOT_PROTOCOL>
|
template <const uint8_t BOOT_PROTOCOL>
|
||||||
class HIDBoot : public HID //public USBDeviceConfig, public UsbConfigXtracter
|
class HIDBoot : public HID //public USBDeviceConfig, public UsbConfigXtracter
|
||||||
{
|
{
|
||||||
EpInfo epInfo[totalEndpoints];
|
EpInfo epInfo[totalEndpoints(BOOT_PROTOCOL)];
|
||||||
HIDReportParser *pRptParser[epMUL];
|
HIDReportParser *pRptParser[epMUL(BOOT_PROTOCOL)];
|
||||||
|
|
||||||
uint8_t bConfNum; // configuration number
|
uint8_t bConfNum; // configuration number
|
||||||
uint8_t bIfaceNum; // Interface Number
|
uint8_t bIfaceNum; // Interface Number
|
||||||
|
@ -219,7 +219,7 @@ qNextPollTime(0),
|
||||||
bPollEnable(false) {
|
bPollEnable(false) {
|
||||||
Initialize();
|
Initialize();
|
||||||
|
|
||||||
for(uint8_t i = 0; i < epMUL; i++) {
|
for(int i = 0; i < epMUL(BOOT_PROTOCOL); i++) {
|
||||||
pRptParser[i] = NULL;
|
pRptParser[i] = NULL;
|
||||||
}
|
}
|
||||||
if(pUsb)
|
if(pUsb)
|
||||||
|
@ -228,7 +228,7 @@ bPollEnable(false) {
|
||||||
|
|
||||||
template <const uint8_t BOOT_PROTOCOL>
|
template <const uint8_t BOOT_PROTOCOL>
|
||||||
void HIDBoot<BOOT_PROTOCOL>::Initialize() {
|
void HIDBoot<BOOT_PROTOCOL>::Initialize() {
|
||||||
for(uint8_t i = 0; i < totalEndpoints; i++) {
|
for(int i = 0; i < totalEndpoints(BOOT_PROTOCOL); i++) {
|
||||||
epInfo[i].epAddr = 0;
|
epInfo[i].epAddr = 0;
|
||||||
epInfo[i].maxPktSize = (i) ? 0 : 8;
|
epInfo[i].maxPktSize = (i) ? 0 : 8;
|
||||||
epInfo[i].epAttribs = 0;
|
epInfo[i].epAttribs = 0;
|
||||||
|
@ -314,6 +314,7 @@ uint8_t HIDBoot<BOOT_PROTOCOL>::Init(uint8_t parent, uint8_t port, bool lowspeed
|
||||||
USBTRACE2("setAddr:", rcode);
|
USBTRACE2("setAddr:", rcode);
|
||||||
return rcode;
|
return rcode;
|
||||||
}
|
}
|
||||||
|
delay(2); //per USB 2.0 sect.9.2.6.3
|
||||||
|
|
||||||
USBTRACE2("Addr:", bAddress);
|
USBTRACE2("Addr:", bAddress);
|
||||||
|
|
||||||
|
@ -335,15 +336,22 @@ uint8_t HIDBoot<BOOT_PROTOCOL>::Init(uint8_t parent, uint8_t port, bool lowspeed
|
||||||
num_of_conf = ((USB_DEVICE_DESCRIPTOR*) buf)->bNumConfigurations;
|
num_of_conf = ((USB_DEVICE_DESCRIPTOR*) buf)->bNumConfigurations;
|
||||||
|
|
||||||
// Assign epInfo to epinfo pointer
|
// Assign epInfo to epinfo pointer
|
||||||
rcode = pUsb->setEpInfoEntry(bAddress, 1, epInfo);
|
//rcode = pUsb->setEpInfoEntry(bAddress, 1, epInfo);
|
||||||
|
|
||||||
if(rcode)
|
//if(rcode)
|
||||||
goto FailSetDevTblEntry;
|
// goto FailSetDevTblEntry;
|
||||||
|
|
||||||
//USBTRACE2("NC:", num_of_conf);
|
//USBTRACE2("NC:", num_of_conf);
|
||||||
|
// GCC will optimize unused stuff away.
|
||||||
|
//if((totalEndpoints(BOOT_PROTOCOL)) != 3) {
|
||||||
|
// bNumEP = 0;
|
||||||
|
//}
|
||||||
|
|
||||||
|
USBTRACE2("bNumEP:", bNumEP);
|
||||||
|
USBTRACE2("totalEndpoints:", (uint8_t) (bitsEndpoints(BOOT_PROTOCOL)));
|
||||||
// GCC will optimize unused stuff away.
|
// GCC will optimize unused stuff away.
|
||||||
if(BOOT_PROTOCOL & HID_PROTOCOL_KEYBOARD) {
|
if(BOOT_PROTOCOL & HID_PROTOCOL_KEYBOARD) {
|
||||||
|
USBTRACE("HID_PROTOCOL_KEYBOARD\r\n");
|
||||||
for(uint8_t i = 0; i < num_of_conf; i++) {
|
for(uint8_t i = 0; i < num_of_conf; i++) {
|
||||||
ConfigDescParser<
|
ConfigDescParser<
|
||||||
USB_CLASS_HID,
|
USB_CLASS_HID,
|
||||||
|
@ -351,31 +359,36 @@ uint8_t HIDBoot<BOOT_PROTOCOL>::Init(uint8_t parent, uint8_t port, bool lowspeed
|
||||||
HID_PROTOCOL_KEYBOARD,
|
HID_PROTOCOL_KEYBOARD,
|
||||||
CP_MASK_COMPARE_ALL> confDescrParserA(this);
|
CP_MASK_COMPARE_ALL> confDescrParserA(this);
|
||||||
|
|
||||||
if(bNumEP == totalEndpoints)
|
|
||||||
break;
|
|
||||||
pUsb->getConfDescr(bAddress, 0, i, &confDescrParserA);
|
pUsb->getConfDescr(bAddress, 0, i, &confDescrParserA);
|
||||||
|
if(bNumEP == (uint8_t) (bitsEndpoints(BOOT_PROTOCOL)))
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// GCC will optimize unused stuff away.
|
// GCC will optimize unused stuff away.
|
||||||
if(BOOT_PROTOCOL & HID_PROTOCOL_MOUSE) {
|
if(BOOT_PROTOCOL & HID_PROTOCOL_MOUSE) {
|
||||||
|
USBTRACE("HID_PROTOCOL_MOUSE\r\n");
|
||||||
for(uint8_t i = 0; i < num_of_conf; i++) {
|
for(uint8_t i = 0; i < num_of_conf; i++) {
|
||||||
ConfigDescParser<
|
ConfigDescParser<
|
||||||
USB_CLASS_HID,
|
USB_CLASS_HID,
|
||||||
HID_BOOT_INTF_SUBCLASS,
|
HID_BOOT_INTF_SUBCLASS,
|
||||||
HID_PROTOCOL_MOUSE,
|
HID_PROTOCOL_MOUSE,
|
||||||
CP_MASK_COMPARE_ALL> confDescrParserB(this);
|
CP_MASK_COMPARE_ALL> confDescrParserB(this);
|
||||||
if(bNumEP == totalEndpoints)
|
|
||||||
break;
|
|
||||||
|
|
||||||
pUsb->getConfDescr(bAddress, 0, i, &confDescrParserB);
|
pUsb->getConfDescr(bAddress, 0, i, &confDescrParserB);
|
||||||
|
if(bNumEP > 1 /* (uint8_t) (totalEndpoints(BOOT_PROTOCOL))*/)
|
||||||
|
break;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
USBTRACE2("bAddr:", bAddress);
|
USBTRACE2("bAddr:", bAddress);
|
||||||
USBTRACE2("bNumEP:", bNumEP);
|
USBTRACE2("bNumEP:", bNumEP);
|
||||||
USBTRACE2("totalEndpoints:", totalEndpoints);
|
USBTRACE2("totalEndpoints:", (uint8_t) (bitsEndpoints(BOOT_PROTOCOL)));
|
||||||
if(bNumEP != totalEndpoints) {
|
USBTRACE2("epMUL:", epMUL(BOOT_PROTOCOL));
|
||||||
|
|
||||||
|
if(bNumEP != (uint8_t)(totalEndpoints(BOOT_PROTOCOL))) {
|
||||||
rcode = USB_DEV_CONFIG_ERROR_DEVICE_NOT_SUPPORTED;
|
rcode = USB_DEV_CONFIG_ERROR_DEVICE_NOT_SUPPORTED;
|
||||||
goto Fail;
|
goto Fail;
|
||||||
}
|
}
|
||||||
|
@ -385,12 +398,16 @@ uint8_t HIDBoot<BOOT_PROTOCOL>::Init(uint8_t parent, uint8_t port, bool lowspeed
|
||||||
USBTRACE2("setEpInfoEntry returned ", rcode);
|
USBTRACE2("setEpInfoEntry returned ", rcode);
|
||||||
USBTRACE2("Cnf:", bConfNum);
|
USBTRACE2("Cnf:", bConfNum);
|
||||||
|
|
||||||
|
delay(1000);
|
||||||
|
|
||||||
// Set Configuration Value
|
// Set Configuration Value
|
||||||
rcode = pUsb->setConf(bAddress, 0, bConfNum);
|
rcode = pUsb->setConf(bAddress, 0, bConfNum);
|
||||||
|
|
||||||
if(rcode)
|
if(rcode)
|
||||||
goto FailSetConfDescr;
|
goto FailSetConfDescr;
|
||||||
|
|
||||||
|
delay(1000);
|
||||||
|
|
||||||
USBTRACE2("If:", bIfaceNum);
|
USBTRACE2("If:", bIfaceNum);
|
||||||
|
|
||||||
rcode = SetProtocol(bIfaceNum, HID_BOOT_PROTOCOL);
|
rcode = SetProtocol(bIfaceNum, HID_BOOT_PROTOCOL);
|
||||||
|
@ -416,11 +433,11 @@ FailGetDevDescr:
|
||||||
goto Fail;
|
goto Fail;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
FailSetDevTblEntry:
|
//FailSetDevTblEntry:
|
||||||
#ifdef DEBUG_USB_HOST
|
//#ifdef DEBUG_USB_HOST
|
||||||
NotifyFailSetDevTblEntry();
|
// NotifyFailSetDevTblEntry();
|
||||||
goto Fail;
|
// goto Fail;
|
||||||
#endif
|
//#endif
|
||||||
|
|
||||||
//FailGetConfDescr:
|
//FailGetConfDescr:
|
||||||
//#ifdef DEBUG_USB_HOST
|
//#ifdef DEBUG_USB_HOST
|
||||||
|
@ -450,6 +467,7 @@ Fail:
|
||||||
NotifyFail(rcode);
|
NotifyFail(rcode);
|
||||||
#endif
|
#endif
|
||||||
Release();
|
Release();
|
||||||
|
|
||||||
return rcode;
|
return rcode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -463,6 +481,7 @@ void HIDBoot<BOOT_PROTOCOL>::EndpointXtract(uint8_t conf, uint8_t iface, uint8_t
|
||||||
bIfaceNum = iface;
|
bIfaceNum = iface;
|
||||||
|
|
||||||
if((pep->bmAttributes & 0x03) == 3 && (pep->bEndpointAddress & 0x80) == 0x80) {
|
if((pep->bmAttributes & 0x03) == 3 && (pep->bEndpointAddress & 0x80) == 0x80) {
|
||||||
|
|
||||||
uint8_t index = bNumEP; //epInterruptInIndex; //+ bNumEP;
|
uint8_t index = bNumEP; //epInterruptInIndex; //+ bNumEP;
|
||||||
|
|
||||||
// Fill in the endpoint info structure
|
// Fill in the endpoint info structure
|
||||||
|
@ -485,6 +504,7 @@ uint8_t HIDBoot<BOOT_PROTOCOL>::Release() {
|
||||||
bAddress = 0;
|
bAddress = 0;
|
||||||
qNextPollTime = 0;
|
qNextPollTime = 0;
|
||||||
bPollEnable = false;
|
bPollEnable = false;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -499,7 +519,7 @@ uint8_t HIDBoot<BOOT_PROTOCOL>::Poll() {
|
||||||
qNextPollTime = millis() + 10;
|
qNextPollTime = millis() + 10;
|
||||||
|
|
||||||
// To-do: optimize manually, getting rid of the loop
|
// To-do: optimize manually, getting rid of the loop
|
||||||
for(uint8_t i = 0; i < epMUL; i++) {
|
for(int i = 0; i < epMUL(BOOT_PROTOCOL); i++) {
|
||||||
const uint8_t const_buff_len = 16;
|
const uint8_t const_buff_len = 16;
|
||||||
uint8_t buf[const_buff_len];
|
uint8_t buf[const_buff_len];
|
||||||
|
|
||||||
|
|
|
@ -148,7 +148,7 @@ uint8_t HIDUniversal::Init(uint8_t parent, uint8_t port, bool lowspeed) {
|
||||||
return rcode;
|
return rcode;
|
||||||
}
|
}
|
||||||
|
|
||||||
delay( 2 ); //per USB 2.0 sect.9.2.6.3
|
//delay(2); //per USB 2.0 sect.9.2.6.3
|
||||||
|
|
||||||
USBTRACE2("Addr:", bAddress);
|
USBTRACE2("Addr:", bAddress);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue