From b30c56a86e096ef3147cebc66e761f6ad2b1acfd Mon Sep 17 00:00:00 2001 From: "Andrew J. Kroll" Date: Thu, 8 Aug 2013 20:21:05 -0400 Subject: [PATCH] Control switch via GPX pin. --- Usb.cpp | 10 +++++----- usbhost.h | 17 ++++++++++++++++- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/Usb.cpp b/Usb.cpp index 31d9bb9b..8884774d 100644 --- a/Usb.cpp +++ b/Usb.cpp @@ -110,14 +110,14 @@ uint8_t USB::SetAddress(uint8_t addr, uint8_t ep, EpInfo **ppep, uint16_t &nak_l USBTRACE("\r\n"); */ regWr(rPERADDR, addr); //set peripheral address - + uint8_t mode = regRd(rMODE); - + //Serial.print("\r\nMode: "); //Serial.println( mode, HEX); //Serial.print("\r\nLS: "); //Serial.println(p->lowspeed, HEX); - + // Set bmLOWSPEED and bmHUBPRE in case of low-speed device, reset them otherwise @@ -512,10 +512,10 @@ void USB::Task(void) //USB state machine if (delay < millis()) usb_task_state = USB_STATE_CONFIGURING; break; case USB_STATE_CONFIGURING: - + //Serial.print("\r\nConf.LS: "); //Serial.println(lowspeed, HEX); - + rcode = Configuring(0, 0, lowspeed); if (rcode) { diff --git a/usbhost.h b/usbhost.h index 819ba971..e25e6805 100644 --- a/usbhost.h +++ b/usbhost.h @@ -18,6 +18,13 @@ e-mail : support@circuitsathome.com #ifndef _USBHOST_H_ #define _USBHOST_H_ +// So we can use delay() -- xxxajk +#if defined(ARDUINO) && ARDUINO >=100 +#include "Arduino.h" +#else +#include +#endif + #include "avrpins.h" #include "max3421e.h" #include "usb_ch9.h" @@ -94,7 +101,7 @@ MAX3421e< SS, INTR >::MAX3421e() { #endif /* MAX3421E - full-duplex SPI, level interrupt */ - regWr(rPINCTL, (bmFDUPSPI + bmINTLEVEL)); + regWr(rPINCTL, (bmFDUPSPI | bmINTLEVEL | GPX_VBDET)); }; /* write single byte into MAX3421 register */ @@ -218,6 +225,10 @@ int8_t MAX3421e< SS, INTR >::Init() { if(reset() == 0) { //OSCOKIRQ hasn't asserted in time return( -1); } + + // Delay 1 second to ensure any capacitors are drained. + delay(1000); + regWr(rMODE, bmDPPULLDN | bmDMPULLDN | bmHOST); // set pull-downs, Host regWr(rHIEN, bmCONDETIE | bmFRAMEIE); //connection detection @@ -230,6 +241,10 @@ int8_t MAX3421e< SS, INTR >::Init() { regWr(rHIRQ, bmCONDETIRQ); //clear connection detect interrupt regWr(rCPUCTL, 0x01); //enable interrupt pin + + // GPX pin on. This is done here so that busprobe will fail if we have a switch connected. + regWr(rPINCTL, (bmFDUPSPI | bmINTLEVEL)); + return( 0); }