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:
Jun Wako 2021-07-22 13:45:31 +09:00
parent b56e8b76a1
commit e43f86ad33

View file

@ -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 */ /* probe bus to determine device presence and speed and switch host to this speed */
template< typename SPI_SS, typename INTR > template< typename SPI_SS, typename INTR >
void MAX3421e< SPI_SS, INTR >::busprobe() { void MAX3421e< SPI_SS, INTR >::busprobe() {
static uint8_t prev_bus = -1;
uint8_t bus_sample; 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 = regRd(rHRSL); //Get J,K status
bus_sample &= (bmJSTATUS | bmKSTATUS); //zero the rest of the byte 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 switch(bus_sample) { //start full-speed or low-speed host
case( bmJSTATUS): case( bmJSTATUS):
if((regRd(rMODE) & bmLOWSPEED) == 0) { if((regRd(rMODE) & bmLOWSPEED) == 0) {
@ -538,6 +557,7 @@ void MAX3421e< SPI_SS, INTR >::busprobe() {
/* MAX3421 state change task and interrupt handler */ /* MAX3421 state change task and interrupt handler */
template< typename SPI_SS, typename INTR > template< typename SPI_SS, typename INTR >
uint8_t MAX3421e< SPI_SS, INTR >::Task(void) { uint8_t MAX3421e< SPI_SS, INTR >::Task(void) {
/*
uint8_t rcode = 0; uint8_t rcode = 0;
uint8_t pinvalue; uint8_t pinvalue;
//USB_HOST_SERIAL.print("Vbus state: "); //USB_HOST_SERIAL.print("Vbus state: ");
@ -553,6 +573,9 @@ uint8_t MAX3421e< SPI_SS, INTR >::Task(void) {
// } // }
// usbSM(); //USB state machine // usbSM(); //USB state machine
return ( rcode); return ( rcode);
*/
busprobe();
return 0;
} }
template< typename SPI_SS, typename INTR > template< typename SPI_SS, typename INTR >