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

View file

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

View file

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

View file

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

View file

@ -5,7 +5,10 @@
*/ */
#include <SPP.h> #include <SPP.h>
#include <usbhub.h>
USB Usb; USB Usb;
USBHub Hub1(&Usb); // Some dongles have a hub inside
BTD Btd(&Usb); // You have to create the Bluetooth Dongle instance like so BTD Btd(&Usb); // You have to create the Bluetooth Dongle instance like so
/* You can create the instance of the class in two ways */ /* 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" 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 <SPP.h>
#include <usbhub.h>
USB Usb; USB Usb;
USBHub Hub1(&Usb); // Some dongles have a hub inside
BTD Btd(&Usb); // You have to create the Bluetooth Dongle instance like so 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! 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 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 <Wii.h>
#include <usbhub.h>
USB Usb; USB Usb;
USBHub Hub1(&Usb); // Some dongles have a hub inside
BTD Btd(&Usb); // You have to create the Bluetooth Dongle instance like so BTD Btd(&Usb); // You have to create the Bluetooth Dongle instance like so
/* You can create the instance of the class in two ways */ /* 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 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 <Wii.h>
#include <usbhub.h>
#ifndef WIICAMERA // Used to check if WIICAMERA is defined #ifndef WIICAMERA // Used to check if WIICAMERA is defined
#error "Uncomment WIICAMERA in Wii.h to use this example" #error "Uncomment WIICAMERA in Wii.h to use this example"
#endif #endif
USB Usb; USB Usb;
USBHub Hub1(&Usb); // Some dongles have a hub inside
BTD Btd(&Usb); // You have to create the Bluetooth Dongle instance like so BTD Btd(&Usb); // You have to create the Bluetooth Dongle instance like so
/* You can create the instance of the class in two ways */ /* 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 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 <Wii.h>
#include <usbhub.h>
USB Usb; USB Usb;
USBHub Hub1(&Usb); // Some dongles have a hub inside
BTD Btd(&Usb); // You have to create the Bluetooth Dongle instance like so 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! 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 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 <Wii.h>
#include <usbhub.h>
USB Usb; USB Usb;
USBHub Hub1(&Usb); // Some dongles have a hub inside
BTD Btd(&Usb); // You have to create the Bluetooth Dongle instance like so BTD Btd(&Usb); // You have to create the Bluetooth Dongle instance like so
/* You can create the instance of the class in two ways */ /* 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 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(Xbox.getButtonPress(L2,i));
Serial.print("\tR2: "); Serial.print("\tR2: ");
Serial.println(Xbox.getButtonPress(R2,i)); 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 || 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) { if(Xbox.getAnalogHat(LeftHatX,i) > 7500 || Xbox.getAnalogHat(LeftHatX,i) < -7500) {

View file

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

View file

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

View file

@ -18,6 +18,13 @@ e-mail : support@circuitsathome.com
#ifndef _USBHOST_H_ #ifndef _USBHOST_H_
#define _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 "avrpins.h"
#include "max3421e.h" #include "max3421e.h"
#include "usb_ch9.h" #include "usb_ch9.h"
@ -52,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;
@ -65,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;
@ -94,7 +111,7 @@ MAX3421e< SS, INTR >::MAX3421e() {
#endif #endif
/* MAX3421E - full-duplex SPI, level interrupt */ /* MAX3421E - full-duplex SPI, level interrupt */
regWr(rPINCTL, (bmFDUPSPI + bmINTLEVEL)); regWr(rPINCTL, (bmFDUPSPI | bmINTLEVEL | GPX_VBDET));
}; };
/* write single byte into MAX3421 register */ /* write single byte into MAX3421 register */
@ -200,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 >
@ -218,6 +224,10 @@ int8_t MAX3421e< SS, INTR >::Init() {
if(reset() == 0) { //OSCOKIRQ hasn't asserted in time if(reset() == 0) { //OSCOKIRQ hasn't asserted in time
return( -1); return( -1);
} }
// GPX pin on.
regWr(rPINCTL, (bmFDUPSPI | bmINTLEVEL));
regWr(rMODE, bmDPPULLDN | bmDMPULLDN | bmHOST); // set pull-downs, Host regWr(rMODE, bmDPPULLDN | bmDMPULLDN | bmHOST); // set pull-downs, Host
regWr(rHIEN, bmCONDETIE | bmFRAMEIE); //connection detection regWr(rHIEN, bmCONDETIE | bmFRAMEIE); //connection detection
@ -230,6 +240,38 @@ int8_t MAX3421e< SS, INTR >::Init() {
regWr(rHIRQ, bmCONDETIRQ); //clear connection detect interrupt regWr(rHIRQ, bmCONDETIRQ); //clear connection detect interrupt
regWr(rCPUCTL, 0x01); //enable interrupt pin 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); return( 0);
} }