GPX vbus controls

This commit is contained in:
Andrew J. Kroll 2013-08-09 02:17:01 -04:00
parent 458c07d8c7
commit a57215fb72

View file

@ -59,6 +59,11 @@ typedef SPi< Pb5, Pb3, Pb4, Pb2 > spi;
typedef SPi< Pb7, Pb5, Pb6, Pb4 > spi; typedef SPi< Pb7, Pb5, Pb6, Pb4 > spi;
#endif #endif
typedef enum VBUS_t {
on = 0,
off = GPX_VBDET
};
template< typename SS, typename INTR > class MAX3421e /* : public spi */ { template< typename SS, typename INTR > class MAX3421e /* : public spi */ {
static uint8_t vbusState; static uint8_t vbusState;
@ -72,6 +77,11 @@ public:
uint8_t gpioRd(); uint8_t gpioRd();
uint16_t reset(); uint16_t reset();
int8_t Init(); int8_t Init();
int8_t Init(int mseconds);
void vbusPower(VBUS_t state) {
regWr(rPINCTL, (bmFDUPSPI | bmINTLEVEL | state));
}
uint8_t getVbusState(void) { uint8_t getVbusState(void) {
return vbusState; return vbusState;
@ -207,17 +217,6 @@ uint16_t MAX3421e< SS, INTR >::reset() {
} }
return( i); return( i);
} }
///* initialize MAX3421E. Set Host mode, pullups, and stuff. Returns 0 if success, -1 if not */
//template< typename SS, typename INTR >
//int8_t MAX3421e< SS, INTR >::Init()
//{
// if( reset() == 0 ) { //OSCOKIRQ hasn't asserted in time
// return ( -1 );
// }
// regWr( rMODE, bmDPPULLDN|bmDMPULLDN|bmHOST ); // set pull-downs, Host
//
// return( 0 );
//}
/* initialize MAX3421E. Set Host mode, pullups, and stuff. Returns 0 if success, -1 if not */ /* initialize MAX3421E. Set Host mode, pullups, and stuff. Returns 0 if success, -1 if not */
template< typename SS, typename INTR > template< typename SS, typename INTR >
@ -226,8 +225,36 @@ int8_t MAX3421e< SS, INTR >::Init() {
return( -1); return( -1);
} }
// Delay 1 second to ensure any capacitors are drained. // GPX pin on.
delay(1000); regWr(rPINCTL, (bmFDUPSPI | bmINTLEVEL));
regWr(rMODE, bmDPPULLDN | bmDMPULLDN | bmHOST); // set pull-downs, Host
regWr(rHIEN, bmCONDETIE | bmFRAMEIE); //connection detection
/* check if device is connected */
regWr(rHCTL, bmSAMPLEBUS); // sample USB bus
while(!(regRd(rHCTL) & bmSAMPLEBUS)); //wait for sample operation to finish
busprobe(); //check if anything is connected
regWr(rHIRQ, bmCONDETIRQ); //clear connection detect interrupt
regWr(rCPUCTL, 0x01); //enable interrupt pin
return( 0);
}
/* initialize MAX3421E. Set Host mode, pullups, and stuff. Returns 0 if success, -1 if not */
template< typename SS, typename INTR >
int8_t MAX3421e< SS, INTR >::Init(int mseconds) {
if(reset() == 0) { //OSCOKIRQ hasn't asserted in time
return( -1);
}
// Delay a minimum of 1 second to ensure any capacitors are drained.
// 1 second is required to make sure we do not smoke a Microdrive!
if(mseconds < 1000) mseconds = 1000;
delay(mseconds);
regWr(rMODE, bmDPPULLDN | bmDMPULLDN | bmHOST); // set pull-downs, Host regWr(rMODE, bmDPPULLDN | bmDMPULLDN | bmHOST); // set pull-downs, Host