From 3dea5b880f614660c4f741c91f013a661db2a6bf Mon Sep 17 00:00:00 2001 From: Oleg Mazurov Date: Mon, 8 Jul 2013 12:46:32 -0600 Subject: [PATCH 01/11] fixed low speed direct attach --- Usb.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Usb.cpp b/Usb.cpp index 30d13f13..2d7e539a 100644 --- a/Usb.cpp +++ b/Usb.cpp @@ -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; From b30c56a86e096ef3147cebc66e761f6ad2b1acfd Mon Sep 17 00:00:00 2001 From: "Andrew J. Kroll" Date: Thu, 8 Aug 2013 20:21:05 -0400 Subject: [PATCH 02/11] 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); } From f93c9d8a9a3fd43b575a6a8f8bafc26ac0a4edb5 Mon Sep 17 00:00:00 2001 From: "Andrew J. Kroll" Date: Fri, 9 Aug 2013 00:10:13 -0400 Subject: [PATCH 03/11] merge testusbhostFAT library updates --- examples/testusbhostFAT/Arduino_Makefile_master | 2 +- examples/testusbhostFAT/generic_storage | 2 +- examples/testusbhostFAT/xmem2 | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/examples/testusbhostFAT/Arduino_Makefile_master b/examples/testusbhostFAT/Arduino_Makefile_master index f379bae0..76e5edb2 160000 --- a/examples/testusbhostFAT/Arduino_Makefile_master +++ b/examples/testusbhostFAT/Arduino_Makefile_master @@ -1 +1 @@ -Subproject commit f379bae02aa3d9c3da558ba2041558b88db95bbb +Subproject commit 76e5edb248b9078916cf46bdd4fd1a9e8201ca64 diff --git a/examples/testusbhostFAT/generic_storage b/examples/testusbhostFAT/generic_storage index 071b65b9..e717f2df 160000 --- a/examples/testusbhostFAT/generic_storage +++ b/examples/testusbhostFAT/generic_storage @@ -1 +1 @@ -Subproject commit 071b65b923b2656bb1e1b622de5272b4ed9a4996 +Subproject commit e717f2df099491439877cc0d44a660688685dd54 diff --git a/examples/testusbhostFAT/xmem2 b/examples/testusbhostFAT/xmem2 index 8bcf5f90..e5f9968b 160000 --- a/examples/testusbhostFAT/xmem2 +++ b/examples/testusbhostFAT/xmem2 @@ -1 +1 @@ -Subproject commit 8bcf5f90f8bd967378b6eeebd7fd943f125fbc18 +Subproject commit e5f9968b42fb4970ec037290e5942e83accd4fad From 0169e99af7a115d85d497ab80c61b956aab856ca Mon Sep 17 00:00:00 2001 From: "Andrew J. Kroll" Date: Fri, 9 Aug 2013 00:18:25 -0400 Subject: [PATCH 04/11] Updates to testusbhostFAT --- examples/testusbhostFAT/testusbhostFAT.ino | 276 +++++++++++---------- 1 file changed, 139 insertions(+), 137 deletions(-) diff --git a/examples/testusbhostFAT/testusbhostFAT.ino b/examples/testusbhostFAT/testusbhostFAT.ino index b7b792f9..3b521a6c 100755 --- a/examples/testusbhostFAT/testusbhostFAT.ino +++ b/examples/testusbhostFAT/testusbhostFAT.ino @@ -30,6 +30,7 @@ #if WANT_HUB_TEST #include #endif +#include #include #include #include @@ -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()); @@ -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")); } From a57215fb727e481c75b6b4625c4c2f257a357e95 Mon Sep 17 00:00:00 2001 From: "Andrew J. Kroll" Date: Fri, 9 Aug 2013 02:17:01 -0400 Subject: [PATCH 05/11] GPX vbus controls --- usbhost.h | 53 ++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 40 insertions(+), 13 deletions(-) diff --git a/usbhost.h b/usbhost.h index e25e6805..538d9641 100644 --- a/usbhost.h +++ b/usbhost.h @@ -59,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; @@ -72,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; @@ -207,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 > @@ -226,8 +225,36 @@ int8_t MAX3421e< SS, INTR >::Init() { return( -1); } - // Delay 1 second to ensure any capacitors are drained. - delay(1000); + // GPX pin on. + 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 From b150524807e8f8a0dfc6693e16891ca73bd8774b Mon Sep 17 00:00:00 2001 From: "Andrew J. Kroll" Date: Fri, 9 Aug 2013 02:24:46 -0400 Subject: [PATCH 06/11] testusbhostFAT updates --- examples/testusbhostFAT/Arduino_Makefile_master | 2 +- examples/testusbhostFAT/generic_storage | 2 +- examples/testusbhostFAT/xmem2 | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/examples/testusbhostFAT/Arduino_Makefile_master b/examples/testusbhostFAT/Arduino_Makefile_master index f379bae0..76e5edb2 160000 --- a/examples/testusbhostFAT/Arduino_Makefile_master +++ b/examples/testusbhostFAT/Arduino_Makefile_master @@ -1 +1 @@ -Subproject commit f379bae02aa3d9c3da558ba2041558b88db95bbb +Subproject commit 76e5edb248b9078916cf46bdd4fd1a9e8201ca64 diff --git a/examples/testusbhostFAT/generic_storage b/examples/testusbhostFAT/generic_storage index 071b65b9..e717f2df 160000 --- a/examples/testusbhostFAT/generic_storage +++ b/examples/testusbhostFAT/generic_storage @@ -1 +1 @@ -Subproject commit 071b65b923b2656bb1e1b622de5272b4ed9a4996 +Subproject commit e717f2df099491439877cc0d44a660688685dd54 diff --git a/examples/testusbhostFAT/xmem2 b/examples/testusbhostFAT/xmem2 index 8bcf5f90..e5f9968b 160000 --- a/examples/testusbhostFAT/xmem2 +++ b/examples/testusbhostFAT/xmem2 @@ -1 +1 @@ -Subproject commit 8bcf5f90f8bd967378b6eeebd7fd943f125fbc18 +Subproject commit e5f9968b42fb4970ec037290e5942e83accd4fad From 3d16d6f9d6d19152f57e2dd6c1aa72e2530bdbcc Mon Sep 17 00:00:00 2001 From: "Andrew J. Kroll" Date: Fri, 9 Aug 2013 02:27:34 -0400 Subject: [PATCH 07/11] testusbhostFAT Updates --- examples/testusbhostFAT/testusbhostFAT.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/testusbhostFAT/testusbhostFAT.ino b/examples/testusbhostFAT/testusbhostFAT.ino index 3b521a6c..a7dfa361 100755 --- a/examples/testusbhostFAT/testusbhostFAT.ino +++ b/examples/testusbhostFAT/testusbhostFAT.ino @@ -196,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); } From 221fa78078a1b8ca53a25c11929bf4f2fc7d3d26 Mon Sep 17 00:00:00 2001 From: Oleg Mazurov Date: Fri, 9 Aug 2013 15:45:27 -0600 Subject: [PATCH 08/11] power control and stuff --- examples/testusbhostFAT/Arduino_Makefile_master | 2 +- examples/testusbhostFAT/generic_storage | 2 +- examples/testusbhostFAT/xmem2 | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/examples/testusbhostFAT/Arduino_Makefile_master b/examples/testusbhostFAT/Arduino_Makefile_master index 76e5edb2..f379bae0 160000 --- a/examples/testusbhostFAT/Arduino_Makefile_master +++ b/examples/testusbhostFAT/Arduino_Makefile_master @@ -1 +1 @@ -Subproject commit 76e5edb248b9078916cf46bdd4fd1a9e8201ca64 +Subproject commit f379bae02aa3d9c3da558ba2041558b88db95bbb diff --git a/examples/testusbhostFAT/generic_storage b/examples/testusbhostFAT/generic_storage index e717f2df..071b65b9 160000 --- a/examples/testusbhostFAT/generic_storage +++ b/examples/testusbhostFAT/generic_storage @@ -1 +1 @@ -Subproject commit e717f2df099491439877cc0d44a660688685dd54 +Subproject commit 071b65b923b2656bb1e1b622de5272b4ed9a4996 diff --git a/examples/testusbhostFAT/xmem2 b/examples/testusbhostFAT/xmem2 index e5f9968b..8bcf5f90 160000 --- a/examples/testusbhostFAT/xmem2 +++ b/examples/testusbhostFAT/xmem2 @@ -1 +1 @@ -Subproject commit e5f9968b42fb4970ec037290e5942e83accd4fad +Subproject commit 8bcf5f90f8bd967378b6eeebd7fd943f125fbc18 From c5684b8dfa9117a1e0507f21359c88d3bebf17ea Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Tue, 13 Aug 2013 12:54:03 +0200 Subject: [PATCH 09/11] fixes #61 --- examples/Xbox/XBOXRECV/XBOXRECV.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/Xbox/XBOXRECV/XBOXRECV.ino b/examples/Xbox/XBOXRECV/XBOXRECV.ino index b508e837..8490800f 100644 --- a/examples/Xbox/XBOXRECV/XBOXRECV.ino +++ b/examples/Xbox/XBOXRECV/XBOXRECV.ino @@ -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) { From 1f8322d54f64bd4f823c5dc5ae32ec26c52553f9 Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Tue, 13 Aug 2013 21:31:52 +0200 Subject: [PATCH 10/11] Some dongles have a hub inside --- examples/Bluetooth/PS3BT/PS3BT.ino | 3 +++ examples/Bluetooth/PS3Multi/PS3Multi.ino | 3 +++ examples/Bluetooth/PS3SPP/PS3SPP.ino | 3 +++ examples/Bluetooth/SPP/SPP.ino | 3 +++ examples/Bluetooth/SPPMulti/SPPMulti.ino | 3 +++ examples/Bluetooth/Wii/Wii.ino | 3 +++ examples/Bluetooth/WiiIRCamera/WiiIRCamera.ino | 4 ++++ examples/Bluetooth/WiiMulti/WiiMulti.ino | 3 +++ examples/Bluetooth/WiiUProController/WiiUProController.ino | 3 +++ 9 files changed, 28 insertions(+) diff --git a/examples/Bluetooth/PS3BT/PS3BT.ino b/examples/Bluetooth/PS3BT/PS3BT.ino index 9bd63261..df1b34fb 100644 --- a/examples/Bluetooth/PS3BT/PS3BT.ino +++ b/examples/Bluetooth/PS3BT/PS3BT.ino @@ -5,7 +5,10 @@ */ #include +#include + 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 diff --git a/examples/Bluetooth/PS3Multi/PS3Multi.ino b/examples/Bluetooth/PS3Multi/PS3Multi.ino index 6c4805bb..48335820 100644 --- a/examples/Bluetooth/PS3Multi/PS3Multi.ino +++ b/examples/Bluetooth/PS3Multi/PS3Multi.ino @@ -6,7 +6,10 @@ */ #include +#include + 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 diff --git a/examples/Bluetooth/PS3SPP/PS3SPP.ino b/examples/Bluetooth/PS3SPP/PS3SPP.ino index ed02f739..e0ba1acb 100644 --- a/examples/Bluetooth/PS3SPP/PS3SPP.ino +++ b/examples/Bluetooth/PS3SPP/PS3SPP.ino @@ -11,7 +11,10 @@ #include #include +#include + 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 */ diff --git a/examples/Bluetooth/SPP/SPP.ino b/examples/Bluetooth/SPP/SPP.ino index c7732955..fe3d4840 100644 --- a/examples/Bluetooth/SPP/SPP.ino +++ b/examples/Bluetooth/SPP/SPP.ino @@ -5,7 +5,10 @@ */ #include +#include + 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" diff --git a/examples/Bluetooth/SPPMulti/SPPMulti.ino b/examples/Bluetooth/SPPMulti/SPPMulti.ino index 639ebdda..8e02d52b 100644 --- a/examples/Bluetooth/SPPMulti/SPPMulti.ino +++ b/examples/Bluetooth/SPPMulti/SPPMulti.ino @@ -5,7 +5,10 @@ */ #include +#include + 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 diff --git a/examples/Bluetooth/Wii/Wii.ino b/examples/Bluetooth/Wii/Wii.ino index 8ed12d2f..082766e2 100644 --- a/examples/Bluetooth/Wii/Wii.ino +++ b/examples/Bluetooth/Wii/Wii.ino @@ -5,7 +5,10 @@ */ #include +#include + 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 diff --git a/examples/Bluetooth/WiiIRCamera/WiiIRCamera.ino b/examples/Bluetooth/WiiIRCamera/WiiIRCamera.ino index 720deaa6..f1a3ed72 100644 --- a/examples/Bluetooth/WiiIRCamera/WiiIRCamera.ino +++ b/examples/Bluetooth/WiiIRCamera/WiiIRCamera.ino @@ -12,10 +12,14 @@ Otherwise, wire up a IR LED yourself. */ #include +#include + #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 diff --git a/examples/Bluetooth/WiiMulti/WiiMulti.ino b/examples/Bluetooth/WiiMulti/WiiMulti.ino index 19813f19..2df008c2 100644 --- a/examples/Bluetooth/WiiMulti/WiiMulti.ino +++ b/examples/Bluetooth/WiiMulti/WiiMulti.ino @@ -6,7 +6,10 @@ */ #include +#include + 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 diff --git a/examples/Bluetooth/WiiUProController/WiiUProController.ino b/examples/Bluetooth/WiiUProController/WiiUProController.ino index 738bc899..86e22253 100644 --- a/examples/Bluetooth/WiiUProController/WiiUProController.ino +++ b/examples/Bluetooth/WiiUProController/WiiUProController.ino @@ -5,7 +5,10 @@ */ #include +#include + 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 From 4d4a329b266384b70f5b567710ab72d2de6c37d0 Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Tue, 13 Aug 2013 21:33:21 +0200 Subject: [PATCH 11/11] Add USBHub to keywords --- keywords.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/keywords.txt b/keywords.txt index bdd899c7..fb28eec1 100644 --- a/keywords.txt +++ b/keywords.txt @@ -7,6 +7,7 @@ #################################################### USB KEYWORD1 +USBHub KEYWORD1 #################################################### # Syntax Coloring Map For BTD (Bluetooth) Library