Merge branch 'master' into issue59

This commit is contained in:
Kristian Sloth Lauszus 2013-08-13 21:35:29 +02:00
commit c42cef8833
14 changed files with 232 additions and 159 deletions

16
Usb.cpp
View file

@ -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
@ -452,9 +452,9 @@ void USB::Task(void) //USB state machine
lowspeed = false;
break;
case LSHOST:
// if ((usb_task_state & USB_STATE_MASK) == USB_STATE_DETACHED) {
lowspeed = true;
// }
lowspeed = true;
//intentional fallthrough
case FSHOST: //attached
if ((usb_task_state & USB_STATE_MASK) == USB_STATE_DETACHED) {
delay = millis() + USB_SETTLE_DELAY;
@ -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) {

View file

@ -5,7 +5,10 @@
*/
#include <PS3BT.h>
#include <usbhub.h>
USB Usb;
USBHub Hub1(&Usb); // Some dongles have a hub inside
BTD Btd(&Usb); // You have to create the Bluetooth Dongle instance like so
/* You can create the instance of the class in two ways */
PS3BT PS3(&Btd); // This will just create the instance

View file

@ -6,7 +6,10 @@
*/
#include <PS3BT.h>
#include <usbhub.h>
USB Usb;
USBHub Hub1(&Usb); // Some dongles have a hub inside
BTD Btd(&Usb); // You have to create the Bluetooth Dongle instance like so
PS3BT *PS3[2]; // We will use this pointer to store the two instance, you can easily make it larger if you like, but it will use a lot of RAM!
const uint8_t length = sizeof(PS3)/sizeof(PS3[0]); // Get the lenght of the array

View file

@ -11,7 +11,10 @@
#include <PS3BT.h>
#include <SPP.h>
#include <usbhub.h>
USB Usb;
USBHub Hub1(&Usb); // Some dongles have a hub inside
BTD Btd(&Usb); // You have to create the Bluetooth Dongle instance like so
/* You can create the instances of the bluetooth services in two ways */

View file

@ -5,7 +5,10 @@
*/
#include <SPP.h>
#include <usbhub.h>
USB Usb;
USBHub Hub1(&Usb); // Some dongles have a hub inside
BTD Btd(&Usb); // You have to create the Bluetooth Dongle instance like so
/* You can create the instance of the class in two ways */
SPP SerialBT(&Btd); // This will set the name to the defaults: "Arduino" and the pin to "1234"

View file

@ -5,7 +5,10 @@
*/
#include <SPP.h>
#include <usbhub.h>
USB Usb;
USBHub Hub1(&Usb); // Some dongles have a hub inside
BTD Btd(&Usb); // You have to create the Bluetooth Dongle instance like so
SPP* SerialBT[2]; // We will use this pointer to store the two instance, you can easily make it larger if you like, but it will use a lot of RAM!
const uint8_t length = sizeof(SerialBT)/sizeof(SerialBT[0]); // Get the lenght of the array

View file

@ -5,7 +5,10 @@
*/
#include <Wii.h>
#include <usbhub.h>
USB Usb;
USBHub Hub1(&Usb); // Some dongles have a hub inside
BTD Btd(&Usb); // You have to create the Bluetooth Dongle instance like so
/* You can create the instance of the class in two ways */
WII Wii(&Btd,PAIR); // This will start an inquiry and then pair with your Wiimote - you only have to do this once

View file

@ -12,10 +12,14 @@ Otherwise, wire up a IR LED yourself.
*/
#include <Wii.h>
#include <usbhub.h>
#ifndef WIICAMERA // Used to check if WIICAMERA is defined
#error "Uncomment WIICAMERA in Wii.h to use this example"
#endif
USB Usb;
USBHub Hub1(&Usb); // Some dongles have a hub inside
BTD Btd(&Usb); // You have to create the Bluetooth Dongle instance like so
/* You can create the instance of the class in two ways */
WII Wii(&Btd,PAIR); // This will start an inquiry and then pair with your Wiimote - you only have to do this once

View file

@ -6,7 +6,10 @@
*/
#include <Wii.h>
#include <usbhub.h>
USB Usb;
USBHub Hub1(&Usb); // Some dongles have a hub inside
BTD Btd(&Usb); // You have to create the Bluetooth Dongle instance like so
WII *Wii[2]; // We will use this pointer to store the two instance, you can easily make it larger if you like, but it will use a lot of RAM!
const uint8_t length = sizeof(Wii)/sizeof(Wii[0]); // Get the lenght of the array

View file

@ -5,7 +5,10 @@
*/
#include <Wii.h>
#include <usbhub.h>
USB Usb;
USBHub Hub1(&Usb); // Some dongles have a hub inside
BTD Btd(&Usb); // You have to create the Bluetooth Dongle instance like so
/* You can create the instance of the class in two ways */
WII Wii(&Btd,PAIR); // This will start an inquiry and then pair with your Wiimote - you only have to do this once

View file

@ -27,7 +27,7 @@ void loop() {
Serial.print(Xbox.getButtonPress(L2,i));
Serial.print("\tR2: ");
Serial.println(Xbox.getButtonPress(R2,i));
Xbox.setRumbleOn(Xbox.getButtonPress(L2,i),Xbox.getButtonPress(R2,i));
Xbox.setRumbleOn(Xbox.getButtonPress(L2,i),Xbox.getButtonPress(R2,i),i);
}
if(Xbox.getAnalogHat(LeftHatX,i) > 7500 || Xbox.getAnalogHat(LeftHatX,i) < -7500 || Xbox.getAnalogHat(LeftHatY,i) > 7500 || Xbox.getAnalogHat(LeftHatY,i) < -7500 || Xbox.getAnalogHat(RightHatX,i) > 7500 || Xbox.getAnalogHat(RightHatX,i) < -7500 || Xbox.getAnalogHat(RightHatY,i) > 7500 || Xbox.getAnalogHat(RightHatY,i) < -7500) {
if(Xbox.getAnalogHat(LeftHatX,i) > 7500 || Xbox.getAnalogHat(LeftHatX,i) < -7500) {

View file

@ -30,6 +30,7 @@
#if WANT_HUB_TEST
#include <usbhub.h>
#endif
#include <RTClib.h>
#include <masstorage.h>
#include <message.h>
#include <avr/interrupt.h>
@ -41,9 +42,12 @@
#if HAVE_XMEM
#define GOD_MODE 0
#endif
static FILE mystdout;
static FILE tty_stdio;
static FILE tty_stderr;
USB Usb;
#define LED 13 // the pin that the LED is attached to
int led = 13; // the pin that the LED is attached to
volatile int brightness = 0; // how bright the LED is
volatile int fadeAmount = 80; // how many points to fade the LED by
volatile uint8_t current_state = 1;
@ -63,13 +67,18 @@ PCPartition *PT;
#if WANT_HUB_TEST
#define MAX_HUBS 2
static USBHub *Hubs[MAX_HUBS];
USBHub *Hubs[MAX_HUBS];
#endif
static PFAT *Fats[_VOLUMES];
static part_t parts[_VOLUMES];
static storage_t sto[_VOLUMES];
/*make sure this is a power of two. */
#define mbxs 128
static uint8_t My_Buff_x[mbxs]; /* File read buffer */
#define prescale1 ((1 << WGM12) | (1 << CS10))
#define prescale8 ((1 << WGM12) | (1 << CS11))
#define prescale64 ((1 << WGM12) | (1 << CS10) | (1 << CS11))
@ -78,85 +87,99 @@ static storage_t sto[_VOLUMES];
extern "C" unsigned int freeHeap();
/*
unsigned int getHeapend(){
extern unsigned int __heap_start;
if ((unsigned int)__brkval == 0) {
return (unsigned int)&__heap_start;
} else {
return (unsigned int)__brkval;
}
static int tty_stderr_putc(char c, FILE *t) {
USB_HOST_SERIAL.write(c);
}
unsigned int freeHeap() {
if (SP < (unsigned int)__malloc_heap_start) {
return ((unsigned int)__malloc_heap_end - getHeapend());
} else {
return (SP - getHeapend());
}
}
*/
static int my_putc(char c, FILE *t) {
static int tty_std_putc(char c, FILE *t) {
Serial.write(c);
}
static int tty_std_getc(FILE *t) {
while (!Serial.available());
return Serial.read();
}
void setup() {
boolean serr = false;
for (int i = 0; i < _VOLUMES; i++) {
Fats[i] = NULL;
sto[i].private_data = new pvt_t;
((pvt_t *)sto[i].private_data)->B = 255; // impossible
}
// Set this to higher values to enable more debug information
// minimum 0x00, maximum 0xff
UsbDEBUGlvl = 0x51;
// declare pin 9 to be an output:
pinMode(led, OUTPUT);
// make LED pin as an output:
pinMode(LED, OUTPUT);
pinMode(2, OUTPUT);
// Ensure TX is off
_SFR_BYTE(UCSR0B) &= ~_BV(TXEN0);
// Initialize 'debug' serial port
Serial.begin(115200);
USB_HOST_SERIAL.begin(115200);
// Do not start primary Serial port if already started.
if (bit_is_clear(UCSR0B, TXEN0)) {
Serial.begin(115200);
serr = true;
}
//fdevopen(&my_putc, 0);
// too bad we can't tinker with iob directly, oh well.
mystdout.put = my_putc;
mystdout.get = NULL;
mystdout.flags = _FDEV_SETUP_WRITE;
mystdout.udata = 0;
stdout = &mystdout;
// Set up stdio/stderr
tty_stdio.put = tty_std_putc;
tty_stdio.get = tty_std_getc;
tty_stdio.flags = _FDEV_SETUP_RW;
tty_stdio.udata = 0;
stdout = &tty_stdio;
stdin = &tty_stdio;
// Blink pin 9:
tty_stderr.put = tty_stderr_putc;
tty_stderr.get = NULL;
tty_stderr.flags = _FDEV_SETUP_WRITE;
tty_stderr.udata = 0;
stderr = &tty_stderr;
// Blink LED
delay(500);
analogWrite(led, 255);
analogWrite(LED, 255);
delay(500);
analogWrite(led, 0);
analogWrite(LED, 0);
delay(500);
analogWrite(led, 255);
delay(500);
analogWrite(led, 0);
delay(500);
analogWrite(led, 255);
delay(500);
analogWrite(led, 0);
printf_P(PSTR("\r\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nStart\r\n"));
printf_P(PSTR("Current UsbDEBUGlvl %02x\r\n"), UsbDEBUGlvl);
printf_P(PSTR("'+' and '-' increase/decrease by 0x01\r\n"));
printf_P(PSTR("'.' and ',' increase/decrease by 0x10\r\n"));
printf_P(PSTR("'t' will run a 10MB write/read test and print out the time it took.\r\n"));
printf_P(PSTR("'e' will toggle vbus off for a few moments.\r\n"));
printf_P(PSTR("\r\n\r\nLong filename support: "
printf_P(PSTR("'e' will toggle vbus off for a few moments.\r\n\r\n"));
printf_P(PSTR("Long filename support: "
#if _USE_LFN
"Enabled"
#else
"Disabled"
#endif
"\r\n"));
analogWrite(led, 255);
if (serr) {
fprintf_P(stderr, PSTR("\r\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nStart\r\n"));
fprintf_P(stderr, PSTR("Current UsbDEBUGlvl %02x\r\n"), UsbDEBUGlvl);
fprintf_P(stderr, PSTR("Long filename support: "
#if _USE_LFN
"Enabled"
#else
"Disabled"
#endif
"\r\n"));
}
analogWrite(LED, 255);
delay(500);
analogWrite(led, 0);
analogWrite(LED, 0);
delay(500);
analogWrite(LED, 255);
delay(500);
analogWrite(LED, 0);
delay(500);
analogWrite(LED, 255);
delay(500);
analogWrite(LED, 0);
delay(500);
delay(100);
analogWrite(led, 255);
delay(100);
analogWrite(led, 0);
LEDnext_time = millis() + 1;
#ifdef EXT_RAM
printf_P(PSTR("Total EXT RAM banks %i\r\n"), xmem::getTotalBanks());
@ -173,7 +196,7 @@ void setup() {
printf_P(PSTR("Available heap: %u Bytes\r\n"), freeHeap());
}
#endif
while (Usb.Init() == -1) {
while (Usb.Init(1000) == -1) {
printf_P(PSTR("No\r\n"));
Notify(PSTR("OSC did not start."), 0x40);
}
@ -263,8 +286,8 @@ ISR(TIMER3_COMPA_vect) {
if (millis() >= LEDnext_time) {
LEDnext_time = millis() + 30;
// set the brightness of pin 9:
analogWrite(led, brightness);
// set the brightness of LED
analogWrite(LED, brightness);
// change the brightness for next time through the loop:
brightness = brightness + fadeAmount;
@ -281,7 +304,6 @@ ISR(TIMER3_COMPA_vect) {
}
}
bool isfat(uint8_t t) {
return (t == 0x01 || t == 0x04 || t == 0x06 || t == 0x0b || t == 0x0c || t == 0x0e || t == 0x1);
}
@ -289,17 +311,10 @@ bool isfat(uint8_t t) {
void die(FRESULT rc) {
printf_P(PSTR("Failed with rc=%u.\r\n"), rc);
//for (;;);
}
/*make sure this is a power of two. */
#define mbxs 128
void loop() {
uint8_t My_Buff_x[mbxs]; /* File read buffer */
FIL My_File_Object_x; /* File object */
DIR My_Dir_Object_x; /* Directory object */
FILINFO My_File_Info_Object_x; /* File information object */
// Print a heap status report about every 10 seconds.
if (millis() >= HEAPnext_time) {
@ -342,16 +357,6 @@ void loop() {
printf_P(PSTR("USB state = %x\r\n"), current_state);
if (current_state == USB_STATE_RUNNING) {
fadeAmount = 30;
/*
partsready = false;
for (int i = 0; i < cpart; i++) {
if (Fats[i] != NULL)
delete Fats[i];
}
fatready = false;
notified = false;
cpart = 0;
*/
}
if (current_state == USB_DETACHED_SUBSTATE_WAIT_FOR_DEVICE) {
fadeAmount = 80;
@ -365,17 +370,6 @@ void loop() {
notified = false;
cpart = 0;
}
#if 0
if (current_state == 0xa0) {
printf_P(PSTR("VBUS off\r\n"));
// safe to do here
Usb.gpioWr(0x00);
digitalWrite(2, 0);
usbon = false;
usbon_time = millis() + 2000;
change = false;
}
#endif
last_state = current_state;
}
@ -386,7 +380,7 @@ void loop() {
}
// This is horrible, and needs to be moved elsewhere!
for (int B = 0; B < MAX_DRIVERS; B++) {
for (int B = 0; B < MAX_USB_MS_DRIVERS; B++) {
if (!partsready && Bulk[B]->GetAddress() != NULL) {
// Build a list.
int ML = Bulk[B]->GetbMaxLUN();
@ -395,9 +389,8 @@ void loop() {
for (int i = 0; i < ML; i++) {
if (Bulk[B]->LUNIsGood(i)) {
partsready = true;
sto[i].private_data = &info[i];
info[i].lun = i;
info[i].B = B;
((pvt_t *)sto[i].private_data)->lun = i;
((pvt_t *)sto[i].private_data)->B = B;
sto[i].Read = *PRead;
sto[i].Write = *PWrite;
sto[i].Reads = *PReads;
@ -477,7 +470,6 @@ void loop() {
if (fatready) {
FRESULT rc; /* Result code */
UINT bw, br, i;
ULONG ii, wt, rt, start, end;
if (!notified) {
fadeAmount = 5;
@ -488,7 +480,7 @@ void loop() {
else {
printf_P(PSTR("\r\nType the file content.\r\n"));
for (;;) {
rc = f_read(&My_File_Object_x, &(My_Buff_x[0]), mbxs, &br); /* Read a chunk of file */
rc = f_read(&My_File_Object_x, My_Buff_x, mbxs, &br); /* Read a chunk of file */
if (rc || !br) break; /* Error or end of file */
for (i = 0; i < br; i++) {
/* Type the data */
@ -528,55 +520,67 @@ void loop() {
goto out;
}
outdir:
printf_P(PSTR("\r\nOpen root directory.\r\n"));
rc = f_opendir(&My_Dir_Object_x, "0:/");
if (rc) {
die(rc);
goto out;
}
printf_P(PSTR("\r\nDirectory listing...\r\n"));
printf_P(PSTR("Available heap: %u Bytes\r\n"), freeHeap());
for (;;) {
rc = f_readdir(&My_Dir_Object_x, &My_File_Info_Object_x); /* Read a directory item */
if (rc || !My_File_Info_Object_x.fname[0]) break; /* Error or end of dir */
if (My_File_Info_Object_x.fattrib & AM_DIR) {
Serial.write('d');
} else {
Serial.write('-');
}
Serial.write('r');
if (My_File_Info_Object_x.fattrib & AM_RDO) {
Serial.write('-');
} else {
Serial.write('w');
}
if (My_File_Info_Object_x.fattrib & AM_HID) {
Serial.write('h');
} else {
Serial.write('-');
{
#if _USE_LFN
char lfn[_MAX_LFN + 1];
FILINFO My_File_Info_Object_x; /* File information object */
My_File_Info_Object_x.lfname = lfn;
#endif
DIR My_Dir_Object_x; /* Directory object */
printf_P(PSTR("\r\nOpen root directory.\r\n"));
rc = f_opendir(&My_Dir_Object_x, "0:/");
if (rc) {
die(rc);
goto out;
}
if (My_File_Info_Object_x.fattrib & AM_SYS) {
Serial.write('s');
} else {
Serial.write('-');
}
printf_P(PSTR("\r\nDirectory listing...\r\n"));
printf_P(PSTR("Available heap: %u Bytes\r\n"), freeHeap());
for (;;) {
#if _USE_LFN
My_File_Info_Object_x.lfsize = _MAX_LFN;
#endif
if (My_File_Info_Object_x.fattrib & AM_ARC) {
Serial.write('a');
} else {
Serial.write('-');
}
rc = f_readdir(&My_Dir_Object_x, &My_File_Info_Object_x); /* Read a directory item */
if (rc || !My_File_Info_Object_x.fname[0]) break; /* Error or end of dir */
if (My_File_Info_Object_x.fattrib & AM_DIR) {
Serial.write('d');
} else {
Serial.write('-');
}
Serial.write('r');
if (My_File_Info_Object_x.fattrib & AM_RDO) {
Serial.write('-');
} else {
Serial.write('w');
}
if (My_File_Info_Object_x.fattrib & AM_HID) {
Serial.write('h');
} else {
Serial.write('-');
}
if (My_File_Info_Object_x.fattrib & AM_SYS) {
Serial.write('s');
} else {
Serial.write('-');
}
if (My_File_Info_Object_x.fattrib & AM_ARC) {
Serial.write('a');
} else {
Serial.write('-');
}
#if _USE_LFN
if (*My_File_Info_Object_x.lfname)
printf_P(PSTR(" %8lu %s (%s)\r\n"), My_File_Info_Object_x.fsize, My_File_Info_Object_x.fname, My_File_Info_Object_x.lfname);
else
if (*My_File_Info_Object_x.lfname)
printf_P(PSTR(" %8lu %s (%s)\r\n"), My_File_Info_Object_x.fsize, My_File_Info_Object_x.fname, My_File_Info_Object_x.lfname);
else
#endif
printf_P(PSTR(" %8lu %s\r\n"), My_File_Info_Object_x.fsize, &(My_File_Info_Object_x.fname[0]));
printf_P(PSTR(" %8lu %s\r\n"), My_File_Info_Object_x.fsize, &(My_File_Info_Object_x.fname[0]));
}
}
out:
if (rc) die(rc);
@ -584,18 +588,17 @@ out:
}
if (runtest) {
ULONG ii, wt, rt, start, end;
runtest = false;
f_unlink("0:/10MB.bin");
printf_P(PSTR("\r\nCreate a new 10MB test file (10MB.bin).\r\n"));
for (bw = 0; bw < mbxs; bw++) My_Buff_x[bw] = bw & 0xff;
rc = f_open(&My_File_Object_x, "0:/10MB.bin", FA_WRITE | FA_CREATE_ALWAYS);
if (rc) goto failed;
for (bw = 0; bw < mbxs; bw++) My_Buff_x[bw] = bw & 0xff;
start = millis();
for (ii = 10485760 / mbxs; ii > 0; ii--) {
rc = f_write(&My_File_Object_x, &My_Buff_x[0], mbxs, &bw);
for (ii = 10485760LU / mbxs; ii > 0LU; ii--) {
rc = f_write(&My_File_Object_x, My_Buff_x, mbxs, &bw);
if (rc || !bw) goto failed;
}
rc = f_close(&My_File_Object_x);
@ -607,7 +610,7 @@ out:
start = millis();
if (rc) goto failed;
for (;;) {
rc = f_read(&My_File_Object_x, &My_Buff_x[0], mbxs, &bw); /* Read a chunk of file */
rc = f_read(&My_File_Object_x, My_Buff_x, mbxs, &bw); /* Read a chunk of file */
if (rc || !bw) break; /* Error or end of file */
}
end = millis();
@ -617,7 +620,6 @@ out:
rt = end - start;
printf_P(PSTR("Time to read 10485760 bytes: %lu ms (%lu sec)\r\nDelete test file\r\n"), rt, (500 + rt) / 1000UL);
failed:
rc = f_unlink("0:/10MB.bin");
if (rc) die(rc);
printf_P(PSTR("10MB timing test finished.\r\n"));
}

View file

@ -7,6 +7,7 @@
####################################################
USB KEYWORD1
USBHub KEYWORD1
####################################################
# Syntax Coloring Map For BTD (Bluetooth) Library

View file

@ -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 <WProgram.h>
#endif
#include "avrpins.h"
#include "max3421e.h"
#include "usb_ch9.h"
@ -52,6 +59,11 @@ typedef SPi< Pb5, Pb3, Pb4, Pb2 > spi;
typedef SPi< Pb7, Pb5, Pb6, Pb4 > spi;
#endif
typedef enum VBUS_t {
on = 0,
off = GPX_VBDET
};
template< typename SS, typename INTR > class MAX3421e /* : public spi */ {
static uint8_t vbusState;
@ -65,6 +77,11 @@ public:
uint8_t gpioRd();
uint16_t reset();
int8_t Init();
int8_t Init(int mseconds);
void vbusPower(VBUS_t state) {
regWr(rPINCTL, (bmFDUPSPI | bmINTLEVEL | state));
}
uint8_t getVbusState(void) {
return vbusState;
@ -94,7 +111,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 */
@ -200,17 +217,6 @@ uint16_t MAX3421e< SS, INTR >::reset() {
}
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 */
template< typename SS, typename INTR >
@ -218,6 +224,10 @@ int8_t MAX3421e< SS, INTR >::Init() {
if(reset() == 0) { //OSCOKIRQ hasn't asserted in time
return( -1);
}
// GPX pin on.
regWr(rPINCTL, (bmFDUPSPI | bmINTLEVEL));
regWr(rMODE, bmDPPULLDN | bmDMPULLDN | bmHOST); // set pull-downs, Host
regWr(rHIEN, bmCONDETIE | bmFRAMEIE); //connection detection
@ -230,6 +240,38 @@ int8_t MAX3421e< SS, INTR >::Init() {
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(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
// GPX pin on. This is done here so that busprobe will fail if we have a switch connected.
regWr(rPINCTL, (bmFDUPSPI | bmINTLEVEL));
return( 0);
}