mirror of
https://github.com/felis/USB_Host_Shield_2.0.git
synced 2024-03-22 11:31:26 +01:00
Improve plugin detection in busprobe()
MAX3421E CONDETIRQ fails to detect device plugging sometimes, we have to check bus lines regularly during bus state is SE0 to know device insertion. https://github.com/tmk/USB_Host_Shield_2.0/issues/9
This commit is contained in:
parent
b56e8b76a1
commit
e43f86ad33
1 changed files with 23 additions and 0 deletions
23
usbhost.h
23
usbhost.h
|
@ -503,9 +503,28 @@ int8_t MAX3421e< SPI_SS, INTR >::Init(int mseconds) {
|
|||
/* probe bus to determine device presence and speed and switch host to this speed */
|
||||
template< typename SPI_SS, typename INTR >
|
||||
void MAX3421e< SPI_SS, INTR >::busprobe() {
|
||||
static uint8_t prev_bus = -1;
|
||||
uint8_t bus_sample;
|
||||
|
||||
if (regRd(rHIRQ) & bmCONDETIRQ) {
|
||||
// device plug/unplug is detected
|
||||
// clear CONDETIRQ
|
||||
regWr(rHIRQ, bmCONDETIRQ);
|
||||
} else {
|
||||
// check current bus state when no device(SE0),
|
||||
// otherwise transient state will be read due to bus activity.
|
||||
if (vbusState != SE0) return;
|
||||
|
||||
// read current bus state
|
||||
regWr(rHCTL, bmSAMPLEBUS);
|
||||
}
|
||||
|
||||
bus_sample = regRd(rHRSL); //Get J,K status
|
||||
bus_sample &= (bmJSTATUS | bmKSTATUS); //zero the rest of the byte
|
||||
|
||||
if (prev_bus == bus_sample) { return; }
|
||||
prev_bus = bus_sample;
|
||||
|
||||
switch(bus_sample) { //start full-speed or low-speed host
|
||||
case( bmJSTATUS):
|
||||
if((regRd(rMODE) & bmLOWSPEED) == 0) {
|
||||
|
@ -538,6 +557,7 @@ void MAX3421e< SPI_SS, INTR >::busprobe() {
|
|||
/* MAX3421 state change task and interrupt handler */
|
||||
template< typename SPI_SS, typename INTR >
|
||||
uint8_t MAX3421e< SPI_SS, INTR >::Task(void) {
|
||||
/*
|
||||
uint8_t rcode = 0;
|
||||
uint8_t pinvalue;
|
||||
//USB_HOST_SERIAL.print("Vbus state: ");
|
||||
|
@ -553,6 +573,9 @@ uint8_t MAX3421e< SPI_SS, INTR >::Task(void) {
|
|||
// }
|
||||
// usbSM(); //USB state machine
|
||||
return ( rcode);
|
||||
*/
|
||||
busprobe();
|
||||
return 0;
|
||||
}
|
||||
|
||||
template< typename SPI_SS, typename INTR >
|
||||
|
|
Loading…
Reference in a new issue