From dfa140f237aefc1d5a2d30bbe0a00cf55b8f8b18 Mon Sep 17 00:00:00 2001 From: "Andrew J. Kroll" Date: Thu, 6 Jun 2013 20:15:04 -0400 Subject: [PATCH 01/20] Merge branches 'xxxajk' and 'xxxajk' of github.com:felis/USB_Host_Shield_2.0 into xxxajk From b528925d9edcde42529f758571326c3a47146654 Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Sun, 9 Jun 2013 19:22:24 +0200 Subject: [PATCH 02/20] Uploaded Andrew's example code --- .gitmodules | 6 + examples/testusbhostFAT/Makefile | 42 ++ examples/testusbhostFAT/README.md | 10 + examples/testusbhostFAT/avr-gdb.conf | 6 + examples/testusbhostFAT/generic_storage | 1 + examples/testusbhostFAT/testusbhostFAT.ino | 629 +++++++++++++++++++++ examples/testusbhostFAT/xmem2 | 1 + 7 files changed, 695 insertions(+) create mode 100644 .gitmodules create mode 100755 examples/testusbhostFAT/Makefile create mode 100755 examples/testusbhostFAT/README.md create mode 100755 examples/testusbhostFAT/avr-gdb.conf create mode 160000 examples/testusbhostFAT/generic_storage create mode 100755 examples/testusbhostFAT/testusbhostFAT.ino create mode 160000 examples/testusbhostFAT/xmem2 diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 00000000..60897bae --- /dev/null +++ b/.gitmodules @@ -0,0 +1,6 @@ +[submodule "examples/testusbhostFAT/generic_storage"] + path = examples/testusbhostFAT/generic_storage + url = https://github.com/xxxajk/generic_storage +[submodule "examples/testusbhostFAT/xmem2"] + path = examples/testusbhostFAT/xmem2 + url = https://github.com/xxxajk/xmem2 diff --git a/examples/testusbhostFAT/Makefile b/examples/testusbhostFAT/Makefile new file mode 100755 index 00000000..a359e2d8 --- /dev/null +++ b/examples/testusbhostFAT/Makefile @@ -0,0 +1,42 @@ +# +# These are set for a mega 1280 + quadram plus my serial patch. +# If you lack quadram, or want to disable LFN, just change _FS_TINY=1 _USE_LFN=0 +# +# If your board is a mega 2560 uncomment the following two lines +# BOARD = mega2560 +# PROGRAMMER = wiring +# ...and then comment out the following two lines +BOARD = mega +PROGRAMMER = arduino + +# set your Arduino tty port here +PORT = /dev/ttyUSB0 + +EXTRA_FLAGS = -D _FS_TINY=0 +EXTRA_FLAGS += -D _USE_LFN=1 + +# Don't worry if you don't have external RAM, xmem2 detects this situation. +# You *WILL* be wanting to get some kind of external ram on your mega in order to +# do anything that is intense. +EXTRA_FLAGS += -D HAVEXMEM=1 +EXTRA_FLAGS += -D EXT_RAM_STACK=1 +EXTRA_FLAGS += -D EXT_RAM_HEAP=1 + + + +EXTRA_FLAGS += -D DISABLE_SERIAL1 +EXTRA_FLAGS += -D DISABLE_SERIAL2 +EXTRA_FLAGS += -D DISABLE_SERIAL3 + +# You should not need to change this, but I place it here if you want to play. +# These are the defaults for the optimization of the flash and ram +#OPT_FLAGS = -Os -fno-exceptions -ffunction-sections -fdata-sections -MMD + +# The following are the libraries used. +LIB_DIRS = +LIB_DIRS += ../libraries/xmem +LIB_DIRS += ../libraries/USB_Host_Shield_2.0 +LIB_DIRS += ../libraries/generic_storage + +# And finally, the part that brings everything together for you. +include ../Arduino_Makefile_master/_Makefile.master diff --git a/examples/testusbhostFAT/README.md b/examples/testusbhostFAT/README.md new file mode 100755 index 00000000..d1ae27a7 --- /dev/null +++ b/examples/testusbhostFAT/README.md @@ -0,0 +1,10 @@ +This small sketch tests the USB host shield mass storage library. + +To compile this example you will need the following libraries as well: + +* [xmem2](https://github.com/xxxajk/xmem2) +* [generic_storage FATfs](https://github.com/xxxajk/generic_storage) + +It is recommended to use the bundled [Makefile](Makefile). + +The master makefile can be found at the following repository: . \ No newline at end of file diff --git a/examples/testusbhostFAT/avr-gdb.conf b/examples/testusbhostFAT/avr-gdb.conf new file mode 100755 index 00000000..7ab686f2 --- /dev/null +++ b/examples/testusbhostFAT/avr-gdb.conf @@ -0,0 +1,6 @@ +file build/testusbhostFAT.elf +target remote localhost:4242 +set {int}0x802200 = 0xffff +set {int}0x802220 = 0x0000 +#graph display `x /3xh 0x802200` + diff --git a/examples/testusbhostFAT/generic_storage b/examples/testusbhostFAT/generic_storage new file mode 160000 index 00000000..b87902bf --- /dev/null +++ b/examples/testusbhostFAT/generic_storage @@ -0,0 +1 @@ +Subproject commit b87902bf7a0934b62f43c2176fb11ea318da8629 diff --git a/examples/testusbhostFAT/testusbhostFAT.ino b/examples/testusbhostFAT/testusbhostFAT.ino new file mode 100755 index 00000000..1bcc1a7b --- /dev/null +++ b/examples/testusbhostFAT/testusbhostFAT.ino @@ -0,0 +1,629 @@ + + +/* + * Mega + USB storage + optional expansion RAM + funky status LED, + * Includes interactive debug level setting, and supports emulated hot-plug. + * + * IMPORTANT! PLEASE USE Arduino 1.0.5 or better! + * Older versions HAVE MAJOR BUGS AND WILL NOT WORK AT ALL! + * Use of gcc-avr and lib-c that is newer than the Arduino version is even better. + * + */ + +// Keep this at zero until enumeration is fixed. +// Set to 1 if you are fixing enumeration. +#define WANT_HUB_TEST 0 +#ifndef HAVE_XMEM +// Set this to zero to disable xmem +#define HAVE_XMEM 1 +#endif + + +#include +#if HAVE_XMEM +#include +#endif +#include +#include +#include +#include +#include +#include +#if WANT_HUB_TEST +#include +#endif +#include +#include +#include +#include +#include +#include + +// Warning! Do not use this unless you are aware of what it does! +#if HAVE_XMEM +#define GOD_MODE 0 +#endif +static FILE mystdout; + +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; +volatile uint32_t LEDnext_time; // fade timeout +volatile uint8_t last_state = 0; +volatile boolean fatready = false; +volatile boolean partsready = false; +volatile boolean notified = false; +volatile uint32_t HEAPnext_time; // when to print out next heap report +volatile boolean runtest = false; +volatile boolean usbon = false; +volatile uint32_t usbon_time; +volatile boolean change = false; +volatile boolean reportlvl = false; +int cpart = 0; +PCPartition *PT; + +#if WANT_HUB_TEST +#define MAX_HUBS 2 +static USBHub *Hubs[MAX_HUBS]; +#endif + +static PFAT *Fats[MAX_PARTS]; +static part_t parts[MAX_PARTS]; +static storage_t sto[MAX_PARTS]; + +#define prescale1 ((1 << WGM12) | (1 << CS10)) +#define prescale8 ((1 << WGM12) | (1 << CS11)) +#define prescale64 ((1 << WGM12) | (1 << CS10) | (1 << CS11)) +#define prescale256 ((1 << WGM12) | (1 << CS12)) +#define prescale1024 ((1 << WGM12) | (1 << CS12) | (1 << CS10)) + +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; + } +} + +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) { + Serial.write(c); +} + +void setup() { + for (int i = 0; i < MAX_PARTS; i++) { + Fats[i] = NULL; + } + // 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); + pinMode(2, OUTPUT); + // Initialize 'debug' serial port + Serial.begin(115200); + + //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; + + // Blink pin 9: + delay(500); + analogWrite(led, 255); + delay(500); + 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: " +#if _USE_LFN + "Enabled" +#else + "Disabled" +#endif + "\r\n")); + 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()); +#endif + printf_P(PSTR("Available heap: %u Bytes\r\n"), freeHeap()); + printf_P(PSTR("SP %x\r\n"), (uint8_t *)(SP)); + + // Even though I'm not going to actually be deleting, + // I want to be able to have slightly more control. + // Besides, it is easier to initialize stuff... +#if WANT_HUB_TEST + for (int i = 0; i < MAX_HUBS; i++) { + Hubs[i] = new USBHub(&Usb); + printf_P(PSTR("Available heap: %u Bytes\r\n"), freeHeap()); + } +#endif + while (Usb.Init() == -1) { + printf_P(PSTR("No\r\n")); + Notify(PSTR("OSC did not start."), 0x40); + } + // usb VBUS _OFF_ + Usb.gpioWr(0x00); + digitalWrite(2, 0); + usbon_time = millis() + 2000; + cli(); + TCCR3A = 0; + TCCR3B = 0; + // (0.01/(1/((16 *(10^6)) / 8))) - 1 = 19999 +#if GOD_MODE + OCR3A = 10; +#else + OCR3A = 19999; +#endif + TCCR3B |= prescale8; + TIMSK3 |= (1 << OCIE1A); + sei(); + + HEAPnext_time = millis() + 10000; +} + +#if GOD_MODE +volatile uint16_t *foof = reinterpret_cast(0x2200); +#endif + +void serialEvent() { + // Adjust UsbDEBUGlvl level on-the-fly. + // + to increase, - to decrease, * to display current level. + // . to increase by 16, , to decrease by 16 + // e to flick VBUS + // * to report debug level + if (Serial.available()) { + int inByte = Serial.read(); + switch (inByte) { + case '+': + if (UsbDEBUGlvl < 0xff) UsbDEBUGlvl++; + reportlvl = true; + break; + case '-': + if (UsbDEBUGlvl > 0x00) UsbDEBUGlvl--; + reportlvl = true; + break; + case '.': + if (UsbDEBUGlvl < 0xf0) UsbDEBUGlvl += 16; + reportlvl = true; + break; + case ',': + if (UsbDEBUGlvl > 0x0f) UsbDEBUGlvl -= 16; + reportlvl = true; + break; + case '*': + reportlvl = true; + break; + case 't': + runtest = true; + break; + case 'e': + change = true; + usbon = false; + break; +#if GOD_MODE + case 'z': + cli(); + *foof = 0xffff; + *(foof + 2) = 0x0000; + sei(); + break; +#endif + } + } +} + +ISR(TIMER3_COMPA_vect) { +#if GOD_MODE +#if !EXT_RAM_HEAP && !EXT_RAM_STACK + // Super cool debug feature to detect stack and heap collisions. + // We can use this in conjuction with the AVR dragon + // to check max depth of the stack and height of heap. + if (*foof >= (uint16_t)(SP)) { + *foof = (uint16_t)(SP); + *(foof + 2) = (uint16_t)__brkval; + } +#endif +#endif + if (millis() >= LEDnext_time) { + LEDnext_time = millis() + 30; + + // set the brightness of pin 9: + analogWrite(led, brightness); + + // change the brightness for next time through the loop: + brightness = brightness + fadeAmount; + + // reverse the direction of the fading at the ends of the fade: + if (brightness <= 0) { + brightness = 0; + fadeAmount = -fadeAmount; + } + if (brightness >= 255) { + brightness = 255; + fadeAmount = -fadeAmount; + } + } +} + + +bool isfat(uint8_t t) { + return (t == 0x01 || t == 0x04 || t == 0x06 || t == 0x0b || t == 0x0c || t == 0x0e || t == 0x1); +} + +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) { + if (UsbDEBUGlvl > 0x50) { + printf_P(PSTR("Available heap: %u Bytes\r\n"), freeHeap()); +#if GOD_MODE + cli(); + uint16_t p = *foof; + sei(); + printf_P(PSTR("MAXSP %4.4x, current %4.4x\r\n"), p, SP); +#endif + } + HEAPnext_time = millis() + 10000; + } + + // Horrid! This sort of thing really belongs in an ISR, not here! + // We also will be needing to test each hub port, we don't do this yet! + if (!change && !usbon && millis() >= usbon_time) { + change = true; + usbon = true; + } + + if (change) { + change = false; + if (usbon) { + printf_P(PSTR("VBUS on\r\n")); + Usb.gpioWr(0xFF); + digitalWrite(2, 1); + } else { + Usb.gpioWr(0x00); + digitalWrite(2, 0); + usbon = false; + usbon_time = millis() + 2000; + } + } + Usb.Task(); + current_state = Usb.getUsbTaskState(); + if (current_state != last_state) { + if (UsbDEBUGlvl > 0x50) + 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; + partsready = false; + for (int i = 0; i < cpart; i++) { + if (Fats[i] != NULL) + delete Fats[i]; + Fats[i] = NULL; + } + fatready = false; + 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; + } + + // only do any of this if usb is on + if (usbon) { + if (partsready && !fatready) { + if (cpart > 0) fatready = true; + } + + // This is horrible, and needs to be moved elsewhere! + for (int B = 0; B < MAX_DRIVERS; B++) { + if (!partsready && Bulk[B]->GetAddress() != NULL) { + // Build a list. + int ML = Bulk[B]->GetbMaxLUN(); + //printf("MAXLUN = %i\r\n", ML); + ML++; + 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; + info[i].volmap = 0; // TO-DO: keep track of > 1 + sto[i].Read = *PRead; + sto[i].Write = *PWrite; + sto[i].Reads = *PReads; + sto[i].Writes = *PWrites; + sto[i].Status = *PStatus; + sto[i].TotalSectors = Bulk[B]->GetCapacity(i); + sto[i].SectorSize = Bulk[B]->GetSectorSize(i); + printf_P(PSTR("LUN:\t\t%u\r\n"), i); + printf_P(PSTR("Total Sectors:\t%08lx\t%lu\r\n"), sto[i].TotalSectors, sto[i].TotalSectors); + printf_P(PSTR("Sector Size:\t%04x\t\t%u\r\n"), sto[i].SectorSize, sto[i].SectorSize); + // get the partition data... + PT = new PCPartition; + + if (!PT->Init(&sto[i])) { + part_t *apart; + for (int j = 0; j < 4; j++) { + apart = PT->GetPart(j); + if (apart != NULL && apart->type != 0x00) { + memcpy(&(parts[cpart]), apart, sizeof (part_t)); + printf_P(PSTR("Partition %u type %#02x\r\n"), j, parts[cpart].type); + // for now + if (isfat(parts[cpart].type)) { + Fats[cpart] = new PFAT; + int r = Fats[cpart]->Init(&sto[i], cpart, parts[cpart].firstSector); + if (r) { + delete Fats[cpart]; + Fats[cpart] = NULL; + } else cpart++; + } + } + } + } else { + // try superblock + Fats[cpart] = new PFAT; + int r = Fats[cpart]->Init(&sto[i], cpart, 0); + if (r) { + printf_P(PSTR("Superblock error %x\r\n"), r); + delete Fats[cpart]; + Fats[cpart] = NULL; + } else cpart++; + + } + delete PT; + } else { + sto[i].Read = NULL; + sto[i].Write = NULL; + sto[i].Writes = NULL; + sto[i].Reads = NULL; + sto[i].TotalSectors = 0UL; + sto[i].SectorSize = 0; + } + } + + } + } + + if (fatready) { + if (Fats[0] != NULL) { + struct Pvt * p; + p = ((struct Pvt *)(Fats[0]->storage->private_data)); + if (!Bulk[p->B]->LUNIsGood(p->lun)) { + // media change + fadeAmount = 80; + partsready = false; + for (int i = 0; i < cpart; i++) { + if (Fats[i] != NULL) + delete Fats[i]; + Fats[cpart] = NULL; + } + fatready = false; + notified = false; + cpart = 0; + } + + } + } + if (fatready) { + FRESULT rc; /* Result code */ + UINT bw, br, i; + ULONG ii, wt, rt, start, end; + + if (!notified) { + fadeAmount = 5; + notified = true; + printf_P(PSTR("\r\nOpen an existing file (message.txt).\r\n")); + rc = f_open(&My_File_Object_x, "0:/MESSAGE.TXT", FA_READ); + if (rc) printf_P(PSTR("Error %i, message.txt not found.\r\n")); + 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 */ + if (rc || !br) break; /* Error or end of file */ + for (i = 0; i < br; i++) { + /* Type the data */ + if (My_Buff_x[i] == '\n') + Serial.write('\r'); + if (My_Buff_x[i] != '\r') + Serial.write(My_Buff_x[i]); + Serial.flush(); + } + } + if (rc) { + f_close(&My_File_Object_x); + goto out; + } + + printf_P(PSTR("\r\nClose the file.\r\n")); + rc = f_close(&My_File_Object_x); + if (rc) goto out; + } + printf_P(PSTR("\r\nCreate a new file (hello.txt).\r\n")); + rc = f_open(&My_File_Object_x, "0:/Hello.TxT", FA_WRITE | FA_CREATE_ALWAYS); + if (rc) { + die(rc); + goto outdir; + } + printf_P(PSTR("\r\nWrite a text data. (Hello world!)\r\n")); + rc = f_write(&My_File_Object_x, "Hello world!\r\n", 14, &bw); + if (rc) { + goto out; + } + printf_P(PSTR("%u bytes written.\r\n"), bw); + + printf_P(PSTR("\r\nClose the file.\r\n")); + rc = f_close(&My_File_Object_x); + if (rc) { + die(rc); + 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 (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 +#endif + 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); + printf_P(PSTR("\r\nTest completed.\r\n")); + + } + + + + + if (runtest) { + runtest = false; + 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; + start = millis(); + for (ii = 10485760 / mbxs; ii > 0; ii--) { + rc = f_write(&My_File_Object_x, &My_Buff_x[0], mbxs, &bw); + if (rc || !bw) goto failed; + } + rc = f_close(&My_File_Object_x); + if (rc) goto failed; + end = millis(); + wt = end - start; + printf_P(PSTR("Time to write 10485760 bytes: %lu ms (%lu sec) \r\n"), wt, (500 + wt) / 1000UL); + rc = f_open(&My_File_Object_x, "0:/10MB.bin", FA_READ); + 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 */ + if (rc || !bw) break; /* Error or end of file */ + } + end = millis(); + if (rc) goto failed; + rc = f_close(&My_File_Object_x); + if (rc) goto failed; + 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")); + } + } + } +} diff --git a/examples/testusbhostFAT/xmem2 b/examples/testusbhostFAT/xmem2 new file mode 160000 index 00000000..b2adf124 --- /dev/null +++ b/examples/testusbhostFAT/xmem2 @@ -0,0 +1 @@ +Subproject commit b2adf12413e93de01334efeed0e5d46a73eb17ae From f69278c2b91d9700790ac8d8d8cacd8239d7f62f Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Sun, 9 Jun 2013 19:26:43 +0200 Subject: [PATCH 03/20] Fixed path to libraries --- examples/testusbhostFAT/Makefile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/examples/testusbhostFAT/Makefile b/examples/testusbhostFAT/Makefile index a359e2d8..e656d44f 100755 --- a/examples/testusbhostFAT/Makefile +++ b/examples/testusbhostFAT/Makefile @@ -34,9 +34,9 @@ EXTRA_FLAGS += -D DISABLE_SERIAL3 # The following are the libraries used. LIB_DIRS = -LIB_DIRS += ../libraries/xmem -LIB_DIRS += ../libraries/USB_Host_Shield_2.0 -LIB_DIRS += ../libraries/generic_storage +LIB_DIRS += ../../ +LIB_DIRS += xmem2 +LIB_DIRS += generic_storage # And finally, the part that brings everything together for you. include ../Arduino_Makefile_master/_Makefile.master From fb28094a30c198a4990f209cb88decd94058542c Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Sun, 9 Jun 2013 19:32:27 +0200 Subject: [PATCH 04/20] Added the master makefile as a submodule as well --- .gitmodules | 3 +++ examples/testusbhostFAT/Arduino_Makefile_master | 1 + examples/testusbhostFAT/Makefile | 2 +- 3 files changed, 5 insertions(+), 1 deletion(-) create mode 160000 examples/testusbhostFAT/Arduino_Makefile_master diff --git a/.gitmodules b/.gitmodules index 60897bae..8c705909 100644 --- a/.gitmodules +++ b/.gitmodules @@ -4,3 +4,6 @@ [submodule "examples/testusbhostFAT/xmem2"] path = examples/testusbhostFAT/xmem2 url = https://github.com/xxxajk/xmem2 +[submodule "examples/testusbhostFAT/Arduino_Makefile_master"] + path = examples/testusbhostFAT/Arduino_Makefile_master + url = https://github.com/xxxajk/Arduino_Makefile_master diff --git a/examples/testusbhostFAT/Arduino_Makefile_master b/examples/testusbhostFAT/Arduino_Makefile_master new file mode 160000 index 00000000..f379bae0 --- /dev/null +++ b/examples/testusbhostFAT/Arduino_Makefile_master @@ -0,0 +1 @@ +Subproject commit f379bae02aa3d9c3da558ba2041558b88db95bbb diff --git a/examples/testusbhostFAT/Makefile b/examples/testusbhostFAT/Makefile index e656d44f..b2a06045 100755 --- a/examples/testusbhostFAT/Makefile +++ b/examples/testusbhostFAT/Makefile @@ -39,4 +39,4 @@ LIB_DIRS += xmem2 LIB_DIRS += generic_storage # And finally, the part that brings everything together for you. -include ../Arduino_Makefile_master/_Makefile.master +include Arduino_Makefile_master/_Makefile.master From 4c5df3f56a88565f1d9f0e50eafac6ab5b0b416a Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Sun, 9 Jun 2013 19:45:45 +0200 Subject: [PATCH 05/20] Updated Readme --- examples/testusbhostFAT/README.md | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/examples/testusbhostFAT/README.md b/examples/testusbhostFAT/README.md index d1ae27a7..9b4ac3d2 100755 --- a/examples/testusbhostFAT/README.md +++ b/examples/testusbhostFAT/README.md @@ -1,10 +1,28 @@ This small sketch tests the USB host shield mass storage library. +__Note:__ This will not run a Arduino Uno due to the limited ram available in the ATmega328p. + To compile this example you will need the following libraries as well: * [xmem2](https://github.com/xxxajk/xmem2) * [generic_storage FATfs](https://github.com/xxxajk/generic_storage) -It is recommended to use the bundled [Makefile](Makefile). +It is recommended to get a external RAM shield and apply the following patch: . -The master makefile can be found at the following repository: . \ No newline at end of file +The following shield is recommended: . + +You must use the bundled [Makefile](Makefile) to compile the code instead of the Arduino IDE if you do not use external RAM. + +To download the USB Host library and all the needed libraries for this test. + +Run the following command in a terminal application: + +``` +git clone --recursive https://github.com/felis/USB_Host_Shield_2.0 +``` + +If you want to update all the submodules run: + +``` +git submodule foreach --recursive git pull origin master +``` \ No newline at end of file From 5df4fd56f648a3802a1ca930bbaf1de2141a83ea Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Sun, 9 Jun 2013 19:53:22 +0200 Subject: [PATCH 06/20] Added note about compatible Arduinos --- examples/testusbhostFAT/README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/examples/testusbhostFAT/README.md b/examples/testusbhostFAT/README.md index 9b4ac3d2..f8993d09 100755 --- a/examples/testusbhostFAT/README.md +++ b/examples/testusbhostFAT/README.md @@ -2,12 +2,14 @@ This small sketch tests the USB host shield mass storage library. __Note:__ This will not run a Arduino Uno due to the limited ram available in the ATmega328p. +The Arduino Mega (ATmega1280) and the Arduino Mega 2560 (ATmega2560) are confirmed to work with this test code. + To compile this example you will need the following libraries as well: * [xmem2](https://github.com/xxxajk/xmem2) * [generic_storage FATfs](https://github.com/xxxajk/generic_storage) -It is recommended to get a external RAM shield and apply the following patch: . +It is recommended to get a external RAM shield or apply the following patch: . The following shield is recommended: . From d3b2324b1efcaf0484bffe4c1938966cd9af53c3 Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Sun, 9 Jun 2013 20:24:44 +0200 Subject: [PATCH 07/20] Added link to master makefile --- examples/testusbhostFAT/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/testusbhostFAT/README.md b/examples/testusbhostFAT/README.md index f8993d09..6f05ef32 100755 --- a/examples/testusbhostFAT/README.md +++ b/examples/testusbhostFAT/README.md @@ -13,7 +13,7 @@ It is recommended to get a external RAM shield or apply the following patch: . -You must use the bundled [Makefile](Makefile) to compile the code instead of the Arduino IDE if you do not use external RAM. +You must use the bundled [Makefile](Makefile) to compile the code instead of the Arduino IDE if you do not use external RAM. The master makefile is bundled as a submodule, but can also be downloaded manually at the following link: . To download the USB Host library and all the needed libraries for this test. From df776e1f2c6c66c586e4544a6ea548437f3bbd6e Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Sun, 9 Jun 2013 20:49:32 +0200 Subject: [PATCH 08/20] Added note about how to enable serial debugging --- BTD.cpp | 2 +- PS3BT.cpp | 2 +- PS3USB.cpp | 2 +- SPP.cpp | 2 +- Wii.cpp | 2 +- XBOXRECV.cpp | 2 +- XBOXUSB.cpp | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/BTD.cpp b/BTD.cpp index 63d18580..8b3a5b24 100755 --- a/BTD.cpp +++ b/BTD.cpp @@ -16,7 +16,7 @@ */ #include "BTD.h" -// #define DEBUG // Uncomment to print data for debugging -- NO! see message.h +// To enable serial debugging uncomment "#define DEBUG" in message.h //#define EXTRADEBUG // Uncomment to get even more debugging data const uint8_t BTD::BTD_CONTROL_PIPE = 0; diff --git a/PS3BT.cpp b/PS3BT.cpp index cb72a71b..473c6099 100644 --- a/PS3BT.cpp +++ b/PS3BT.cpp @@ -16,7 +16,7 @@ */ #include "PS3BT.h" -//#define DEBUG // Uncomment to print data for debugging -- NO! see message.h +// To enable serial debugging uncomment "#define DEBUG" in message.h //#define EXTRADEBUG // Uncomment to get even more debugging data //#define PRINTREPORT // Uncomment to print the report send by the PS3 Controllers diff --git a/PS3USB.cpp b/PS3USB.cpp index a2a1a28a..de30777b 100644 --- a/PS3USB.cpp +++ b/PS3USB.cpp @@ -16,7 +16,7 @@ */ #include "PS3USB.h" -//#define DEBUG // Uncomment to print data for debugging -- NO! see message.h +// To enable serial debugging uncomment "#define DEBUG" in message.h //#define EXTRADEBUG // Uncomment to get even more debugging data //#define PRINTREPORT // Uncomment to print the report send by the PS3 Controllers diff --git a/SPP.cpp b/SPP.cpp index 461d9bda..18588f15 100644 --- a/SPP.cpp +++ b/SPP.cpp @@ -16,7 +16,7 @@ */ #include "SPP.h" -#define DEBUG // Uncomment to print data for debugging +// To enable serial debugging uncomment "#define DEBUG" in message.h //#define EXTRADEBUG // Uncomment to get even more debugging data //#define PRINTREPORT // Uncomment to print the report sent to the Arduino diff --git a/Wii.cpp b/Wii.cpp index 15bc58ed..53f37528 100755 --- a/Wii.cpp +++ b/Wii.cpp @@ -20,7 +20,7 @@ */ #include "Wii.h" -#define DEBUG // Uncomment to print data for debugging +// To enable serial debugging uncomment "#define DEBUG" in message.h //#define EXTRADEBUG // Uncomment to get even more debugging data //#define PRINTREPORT // Uncomment to print the report send by the Wii controllers diff --git a/XBOXRECV.cpp b/XBOXRECV.cpp index e5b19621..51e64e82 100644 --- a/XBOXRECV.cpp +++ b/XBOXRECV.cpp @@ -18,7 +18,7 @@ */ #include "XBOXRECV.h" -//#define DEBUG // Uncomment to print data for debugging -- NO! see message.h +// To enable serial debugging uncomment "#define DEBUG" in message.h //#define EXTRADEBUG // Uncomment to get even more debugging data //#define PRINTREPORT // Uncomment to print the report send by the Xbox 360 Controller diff --git a/XBOXUSB.cpp b/XBOXUSB.cpp index 988dbbeb..eff7d383 100644 --- a/XBOXUSB.cpp +++ b/XBOXUSB.cpp @@ -16,7 +16,7 @@ */ #include "XBOXUSB.h" -//#define DEBUG // Uncomment to print data for debugging -- NO! see message.h +// To enable serial debugging uncomment "#define DEBUG" in message.h //#define EXTRADEBUG // Uncomment to get even more debugging data //#define PRINTREPORT // Uncomment to print the report send by the Xbox 360 Controller From 78526fb479e90b2f25f7d2edc2b6c87e0bfc9afb Mon Sep 17 00:00:00 2001 From: "Andrew J. Kroll" Date: Sun, 9 Jun 2013 15:44:08 -0400 Subject: [PATCH 09/20] fix boo-boo in code. --- masstorage.cpp | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/masstorage.cpp b/masstorage.cpp index d5c50a57..681999ff 100644 --- a/masstorage.cpp +++ b/masstorage.cpp @@ -498,14 +498,8 @@ uint8_t BulkOnly::ClearEpHalt(uint8_t index) { } uint8_t BulkOnly::Reset() { - uint8_t r; while (pUsb->ctrlReq(bAddress, 0, bmREQ_MASSOUT, MASS_REQ_BOMSR, 0, 0, bIface, 0, 0, NULL, NULL) == 0x01) delay(6); -#if 0 - if (r) { - printf("Reset error %2.2X\r\n", r); - } -#endif - return r; + return 0; } uint8_t BulkOnly::ResetRecovery() { From ce151290a56adeecf2bd94244b0618a7ce3fe07f Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Sun, 9 Jun 2013 21:46:36 +0200 Subject: [PATCH 10/20] Updated comment --- BTD.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BTD.h b/BTD.h index c314e6cd..329b2dda 100755 --- a/BTD.h +++ b/BTD.h @@ -129,7 +129,7 @@ #define WI_PROTOCOL_BT 0x01 // Bluetooth Programming Interface #define BTD_MAX_ENDPOINTS 4 -#define BTD_NUMSERVICES 4 // Max number of Bluetooth services +#define BTD_NUMSERVICES 4 // Max number of Bluetooth services - if you need more than four simply increase this number /** All Bluetooth services should include this class. */ class BluetoothService { From b7d86a2f2135ea466be2e27cb82a05badad755cc Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Mon, 10 Jun 2013 00:03:34 +0200 Subject: [PATCH 11/20] Fixed typo --- avrpins.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/avrpins.h b/avrpins.h index e2a023bc..23961bf0 100644 --- a/avrpins.h +++ b/avrpins.h @@ -20,7 +20,7 @@ e-mail : support@circuitsathome.com #ifndef _avrpins_h_ #define _avrpins_h_ -#if defined(__AVR_ATmega1280__) || (__AVR_ATmega2560__) +#if defined(__AVR_ATmega2560__) /* Uncomment the following if you have Arduino Mega ADK board with MAX3421e built-in */ //#define BOARD_MEGA_ADK #endif @@ -448,7 +448,7 @@ public: //typedef Tp_Tc P11; //Arduino pin 11 /* Arduino pin definitions */ -#if defined(__AVR_ATmega1280__) || (__AVR_ATmega2560__) +#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) // "Mega" Arduino pin numbers @@ -512,7 +512,7 @@ public: #define P53 Pb0 #define P54 Pe6 // INT on Arduino ADK -#endif //"Mega" pin numbers +#endif // "Mega" pin numbers #if defined(__AVR_ATmega168__) || defined(__AVR_ATmega328P__) //"Classic" Arduino pin numbers From 2f04cc56ac1b3e23b5ed5162cb4798739c60ade6 Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Mon, 10 Jun 2013 00:07:14 +0200 Subject: [PATCH 12/20] Create instances dynamically --- examples/Bluetooth/PS3Multi/PS3Multi.ino | 12 +++--------- examples/Bluetooth/SPPMulti/SPPMulti.ino | 18 ++++-------------- examples/Bluetooth/WiiMulti/WiiMulti.ino | 13 +++---------- 3 files changed, 10 insertions(+), 33 deletions(-) diff --git a/examples/Bluetooth/PS3Multi/PS3Multi.ino b/examples/Bluetooth/PS3Multi/PS3Multi.ino index 98bc19a4..6bcdcdf5 100644 --- a/examples/Bluetooth/PS3Multi/PS3Multi.ino +++ b/examples/Bluetooth/PS3Multi/PS3Multi.ino @@ -8,18 +8,13 @@ #include USB Usb; BTD Btd(&Usb); // You have to create the Bluetooth Dongle instance like so -PS3BT PS3_1(&Btd); -PS3BT PS3_2(&Btd); -//PS3BT PS3_3(&Btd); // You can create as many instances as you like, but it will take up 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 +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 boolean printAngle[length]; void setup() { - PS3[0] = &PS3_1; // This will point to the first controller - PS3[1] = &PS3_2; // This will point to the second controller - //PS3[2] = &PS3_3; // You only need to uncomment this if you wanted to use another controller + for(uint8_t i=0;iPS3Connected || PS3[i]->PS3NavigationConnected) { if(PS3[i]->getAnalogHat(LeftHatX) > 137 || PS3[i]->getAnalogHat(LeftHatX) < 117 || PS3[i]->getAnalogHat(LeftHatY) > 137 || PS3[i]->getAnalogHat(LeftHatY) < 117 || PS3[i]->getAnalogHat(RightHatX) > 137 || PS3[i]->getAnalogHat(RightHatX) < 117 || PS3[i]->getAnalogHat(RightHatY) > 137 || PS3[i]->getAnalogHat(RightHatY) < 117) { Serial.print(F("\r\nLeftHatX: ")); diff --git a/examples/Bluetooth/SPPMulti/SPPMulti.ino b/examples/Bluetooth/SPPMulti/SPPMulti.ino index 173156e5..639ebdda 100644 --- a/examples/Bluetooth/SPPMulti/SPPMulti.ino +++ b/examples/Bluetooth/SPPMulti/SPPMulti.ino @@ -7,24 +7,14 @@ #include USB Usb; BTD Btd(&Usb); // You have to create the Bluetooth Dongle instance like so - -// This will set the name to the defaults: "Arduino" and the pin to "1234" for both connections -SPP SPP_1(&Btd); // This will allow you to communicate with two SPP devices simultaneously -SPP SPP_2(&Btd); -//SPP SPP_3(&Btd); // You can create as many instances as you like, but it will take up a lot of RAM!! - -// You can also set the name and pin like so -//SPP SerialBT(&Btd, "Lauszus's Arduino","0000"); - -SPP* SerialBT[2]; // We will use this pointer to store the two instance, you can easily make it larger if you like +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 boolean firstMessage[length] = { true }; // Set all to true uint8_t buffer[50]; void setup() { - SerialBT[0] = &SPP_1; // This will point to the first instance - SerialBT[1] = &SPP_2; // This will point to the second instance - //SerialBT[2] = &SPP_3; // You only need to uncomment this if you wanted to use another instance + for(uint8_t i=0;i USB Usb; BTD Btd(&Usb); // You have to create the Bluetooth Dongle instance like so -//WII Wii(&Btd,PAIR); // You will have to pair each controller with the dongle before you can define the instances like below -WII Wii_1(&Btd); -WII Wii_2(&Btd); -//WII Wii_3(&Btd); // You can create as many instances as you like, but it will take up 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 +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 bool printAngle[length]; void setup() { - Wii[0] = &Wii_1; - Wii[1] = &Wii_2; - //Wii[2] = &Wii_3; // You only need to uncomment this if you wanted to use another controller + for(uint8_t i=0;iwiimoteConnected) { if(Wii[i]->getButtonClick(HOME)) { // You can use getButtonPress to see if the button is held down Serial.print(F("\r\nHOME")); From 1073f33cea8558a75c5245d7d9b1827744600e52 Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Mon, 10 Jun 2013 01:44:47 +0200 Subject: [PATCH 13/20] Set interrupt endpoint nak limit to USB_NAK_NOWAIT --- BTD.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/BTD.cpp b/BTD.cpp index 8b3a5b24..9d663a7c 100755 --- a/BTD.cpp +++ b/BTD.cpp @@ -272,10 +272,10 @@ void BTD::EndpointXtract(uint8_t conf, uint8_t iface, uint8_t alt, uint8_t proto bConfNum = conf; uint8_t index; - if ((pep->bmAttributes & 0x03) == 3 && (pep->bEndpointAddress & 0x80) == 0x80) // Interrupt In endpoint found + if ((pep->bmAttributes & 0x03) == 3 && (pep->bEndpointAddress & 0x80) == 0x80) { // Interrupt In endpoint found index = BTD_EVENT_PIPE; - - else { + epInfo[index].bmNakPower = USB_NAK_NOWAIT; + } else { if ((pep->bmAttributes & 0x02) == 2) // Bulk endpoint found index = ((pep->bEndpointAddress & 0x80) == 0x80) ? BTD_DATAIN_PIPE : BTD_DATAOUT_PIPE; else From 159e8dc46b4c08efe43f3ae9f86d8811c0100afa Mon Sep 17 00:00:00 2001 From: "Andrew J. Kroll" Date: Mon, 10 Jun 2013 14:26:51 -0400 Subject: [PATCH 14/20] refactor DEBUG -> DEBUG_USB_HOST --- BTD.cpp | 84 +++++++++++++++++++------------------- PS3BT.cpp | 34 ++++++++-------- PS3USB.cpp | 30 +++++++------- SPP.cpp | 50 +++++++++++------------ Wii.cpp | 102 +++++++++++++++++++++++------------------------ XBOXRECV.cpp | 30 +++++++------- XBOXUSB.cpp | 26 ++++++------ adk.cpp | 14 +++---- cdcacm.cpp | 12 +++--- cdcftdi.cpp | 12 +++--- cdcprolific.cpp | 12 +++--- hidboot.h | 14 +++---- hiduniversal.cpp | 12 +++--- masstorage.cpp | 16 ++++---- message.cpp | 2 +- message.h | 8 ++-- printhex.h | 8 ++-- 17 files changed, 233 insertions(+), 233 deletions(-) diff --git a/BTD.cpp b/BTD.cpp index 8b3a5b24..02f442a5 100755 --- a/BTD.cpp +++ b/BTD.cpp @@ -16,7 +16,7 @@ */ #include "BTD.h" -// To enable serial debugging uncomment "#define DEBUG" in message.h +// To enable serial debugging uncomment "#define DEBUG_USB_HOST" in message.h //#define EXTRADEBUG // Uncomment to get even more debugging data const uint8_t BTD::BTD_CONTROL_PIPE = 0; @@ -58,7 +58,7 @@ uint8_t BTD::Init(uint8_t parent, uint8_t port, bool lowspeed) { #endif // check if address has already been assigned to an instance if (bAddress) { -#ifdef DEBUG +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nAddress in use"), 0x80); #endif return USB_ERROR_CLASS_INSTANCE_ALREADY_IN_USE; @@ -68,14 +68,14 @@ uint8_t BTD::Init(uint8_t parent, uint8_t port, bool lowspeed) { p = addrPool.GetUsbDevicePtr(0); if (!p) { -#ifdef DEBUG +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nAddress not found"), 0x80); #endif return USB_ERROR_ADDRESS_NOT_FOUND_IN_POOL; } if (!p->epinfo) { -#ifdef DEBUG +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nepinfo is null"), 0x80); #endif return USB_ERROR_EPINFO_IS_NULL; @@ -113,7 +113,7 @@ uint8_t BTD::Init(uint8_t parent, uint8_t port, bool lowspeed) { p->lowspeed = false; addrPool.FreeAddress(bAddress); bAddress = 0; -#ifdef DEBUG +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nsetAddr: "), 0x80); #endif PrintHex (rcode, 0x80); @@ -145,7 +145,7 @@ uint8_t BTD::Init(uint8_t parent, uint8_t port, bool lowspeed) { if (rcode) goto FailSetConfDescr; -#ifdef DEBUG +#ifdef DEBUG_USB_HOST if (PID == PS3_PID || PID == PS3NAVIGATION_PID) { if (PID == PS3_PID) Notify(PSTR("\r\nDualshock 3 Controller Connected"), 0x80); @@ -156,7 +156,7 @@ uint8_t BTD::Init(uint8_t parent, uint8_t port, bool lowspeed) { #endif if (my_bdaddr[0] == 0x00 && my_bdaddr[1] == 0x00 && my_bdaddr[2] == 0x00 && my_bdaddr[3] == 0x00 && my_bdaddr[4] == 0x00 && my_bdaddr[5] == 0x00) { -#ifdef DEBUG +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nPlease plug in the dongle before trying to pair with the PS3 Controller\n\rOr set the Bluetooth address in the constructor of the PS3BT class"), 0x80); #endif } else { @@ -164,7 +164,7 @@ uint8_t BTD::Init(uint8_t parent, uint8_t port, bool lowspeed) { setBdaddr(my_bdaddr); // Set internal Bluetooth address else setMoveBdaddr(my_bdaddr); // Set internal Bluetooth address -#ifdef DEBUG +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nBluetooth Address was set to: "), 0x80); for (int8_t i = 5; i > 0; i--) { PrintHex (my_bdaddr[i], 0x80); @@ -214,7 +214,7 @@ uint8_t BTD::Init(uint8_t parent, uint8_t port, bool lowspeed) { watingForConnection = false; bPollEnable = true; -#ifdef DEBUG +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nBluetooth Dongle Initialized"), 0x80); #endif } @@ -222,37 +222,37 @@ uint8_t BTD::Init(uint8_t parent, uint8_t port, bool lowspeed) { /* diagnostic messages */ FailGetDevDescr: -#ifdef DEBUG +#ifdef DEBUG_USB_HOST NotifyFailGetDevDescr(); goto Fail; #endif FailSetDevTblEntry: -#ifdef DEBUG +#ifdef DEBUG_USB_HOST NotifyFailSetDevTblEntry(); goto Fail; #endif FailGetConfDescr: -#ifdef DEBUG +#ifdef DEBUG_USB_HOST NotifyFailGetConfDescr(); goto Fail; #endif FailSetConfDescr: -#ifdef DEBUG +#ifdef DEBUG_USB_HOST NotifyFailSetConfDescr(); #endif goto Fail; FailUnknownDevice: -#ifdef DEBUG +#ifdef DEBUG_USB_HOST NotifyFailUnknownDevice(VID, PID); #endif pUsb->setAddr(bAddress, 0, 0); // Reset address rcode = USB_DEV_CONFIG_ERROR_DEVICE_NOT_SUPPORTED; Fail: -#ifdef DEBUG +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nBTD Init Failed, error code: "), 0x80); NotifyFail(rcode); #endif @@ -360,7 +360,7 @@ void BTD::HCI_event_task() { case EV_COMMAND_STATUS: if (hcibuf[2]) { // show status on serial if not OK -#ifdef DEBUG +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nHCI Command Failed: "), 0x80); PrintHex (hcibuf[2], 0x80); Notify(PSTR(" "), 0x80); @@ -374,7 +374,7 @@ void BTD::HCI_event_task() { case EV_INQUIRY_COMPLETE: if (inquiry_counter >= 5) { inquiry_counter = 0; -#ifdef DEBUG +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nCouldn't find Wiimote"), 0x80); #endif connectToWii = false; @@ -468,18 +468,18 @@ void BTD::HCI_event_task() { case EV_PIN_CODE_REQUEST: if (pairWithWii) { -#ifdef DEBUG +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nPairing with wiimote"), 0x80); #endif hci_pin_code_request_reply(); } else if (btdPin != NULL) { -#ifdef DEBUG +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nBluetooth pin is set too: "), 0x80); NotifyStr(btdPin, 0x80); #endif hci_pin_code_request_reply(); } else { -#ifdef DEBUG +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nNo pin was set"), 0x80); #endif hci_pin_code_negative_request_reply(); @@ -487,7 +487,7 @@ void BTD::HCI_event_task() { break; case EV_LINK_KEY_REQUEST: -#ifdef DEBUG +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nReceived Key Request"), 0x80); #endif hci_link_key_request_negative_reply(); @@ -495,7 +495,7 @@ void BTD::HCI_event_task() { case EV_AUTHENTICATION_COMPLETE: if (pairWithWii && !connectToWii) { -#ifdef DEBUG +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nPairing successful"), 0x80); #endif connectToWii = true; // Only send the ACL data to the Wii service @@ -549,7 +549,7 @@ void BTD::HCI_task() { hci_counter++; if (hci_cmd_complete) { hci_counter = 0; -#ifdef DEBUG +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nHCI Reset complete"), 0x80); #endif hci_state = HCI_CLASS_STATE; @@ -558,7 +558,7 @@ void BTD::HCI_task() { hci_num_reset_loops *= 10; if (hci_num_reset_loops > 2000) hci_num_reset_loops = 2000; -#ifdef DEBUG +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nNo response to HCI Reset"), 0x80); #endif hci_state = HCI_INIT_STATE; @@ -568,7 +568,7 @@ void BTD::HCI_task() { case HCI_CLASS_STATE: if (hci_cmd_complete) { -#ifdef DEBUG +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nWrite class of device"), 0x80); #endif hci_state = HCI_BDADDR_STATE; @@ -578,7 +578,7 @@ void BTD::HCI_task() { case HCI_BDADDR_STATE: if (hci_read_bdaddr_complete) { -#ifdef DEBUG +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nLocal Bluetooth Address: "), 0x80); for (int8_t i = 5; i > 0; i--) { PrintHex (my_bdaddr[i], 0x80); @@ -603,7 +603,7 @@ void BTD::HCI_task() { case HCI_SET_NAME_STATE: if (hci_cmd_complete) { -#ifdef DEBUG +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nThe name is set to: "), 0x80); NotifyStr(btdName, 0x80); #endif @@ -613,7 +613,7 @@ void BTD::HCI_task() { case HCI_CHECK_WII_SERVICE: if (pairWithWii) { // Check if it should try to connect to a wiimote -#ifdef DEBUG +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nStarting inquiry\r\nPress 1 & 2 on the Wiimote\r\nOr press sync if you are using a Wii U Pro Controller"), 0x80); #endif hci_inquiry(); @@ -625,7 +625,7 @@ void BTD::HCI_task() { case HCI_INQUIRY_STATE: if (hci_wii_found) { hci_inquiry_cancel(); // Stop inquiry -#ifdef DEBUG +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nWiimote found"), 0x80); Notify(PSTR("\r\nNow just create the instance like so:"), 0x80); Notify(PSTR("\r\nWII Wii(&Btd);"), 0x80); @@ -641,7 +641,7 @@ void BTD::HCI_task() { case HCI_CONNECT_WII_STATE: if (hci_cmd_complete) { -#ifdef DEBUG +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nConnecting to Wiimote"), 0x80); #endif hci_connect(); @@ -652,13 +652,13 @@ void BTD::HCI_task() { case HCI_CONNECTED_WII_STATE: if (hci_connect_event) { if (hci_connect_complete) { -#ifdef DEBUG +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nConnected to Wiimote"), 0x80); #endif hci_authentication_request(); // This will start the pairing with the wiimote hci_state = HCI_SCANNING_STATE; } else { -#ifdef DEBUG +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nTrying to connect one more time..."), 0x80); #endif hci_connect(); // Try to connect one more time @@ -668,7 +668,7 @@ void BTD::HCI_task() { case HCI_SCANNING_STATE: if (!connectToWii && !pairWithWii) { -#ifdef DEBUG +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nWait For Incoming Connection Request"), 0x80); #endif hci_write_scan_enable(); @@ -680,7 +680,7 @@ void BTD::HCI_task() { case HCI_CONNECT_IN_STATE: if (hci_incoming_connect_request) { watingForConnection = false; -#ifdef DEBUG +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nIncoming Connection Request"), 0x80); #endif hci_remote_name(); @@ -691,7 +691,7 @@ void BTD::HCI_task() { case HCI_REMOTE_NAME_STATE: if (hci_remote_name_complete) { -#ifdef DEBUG +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nRemote Name: "), 0x80); for (uint8_t i = 0; i < 30; i++) { if (remote_name[i] == NULL) @@ -701,16 +701,16 @@ void BTD::HCI_task() { #endif if (strncmp((const char*)remote_name, "Nintendo", 8) == 0) { incomingWii = true; -#ifdef DEBUG +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nWiimote is connecting"), 0x80); #endif if (strncmp((const char*)remote_name, "Nintendo RVL-CNT-01-TR", 22) == 0) { -#ifdef DEBUG +#ifdef DEBUG_USB_HOST Notify(PSTR(" with Motion Plus Inside"), 0x80); #endif motionPlusInside = true; } else if (strncmp((const char*)remote_name, "Nintendo RVL-CNT-01-UC", 22) == 0) { -#ifdef DEBUG +#ifdef DEBUG_USB_HOST Notify(PSTR(" - Wii U Pro Controller"), 0x80); #endif motionPlusInside = true; @@ -731,7 +731,7 @@ void BTD::HCI_task() { case HCI_CONNECTED_STATE: if (hci_connect_complete) { -#ifdef DEBUG +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nConnected to Device: "), 0x80); for (int8_t i = 5; i > 0; i--) { PrintHex (disc_bdaddr[i], 0x80); @@ -759,7 +759,7 @@ void BTD::HCI_task() { case HCI_DISCONNECT_STATE: if (hci_disconnect_complete) { -#ifdef DEBUG +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nHCI Disconnected from Device"), 0x80); #endif hci_event_flag = 0; // Clear all flags @@ -957,7 +957,7 @@ void BTD::hci_pin_code_request_reply() { if (pairWithWii) { hcibuf[9] = 6; // Pin length is the length of the Bluetooth address if (wiiUProController) { -#ifdef DEBUG +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nParing with Wii U Pro Controller"), 0x80); #endif for (uint8_t i = 0; i < 6; i++) @@ -1083,7 +1083,7 @@ void BTD::L2CAP_Command(uint16_t handle, uint8_t* data, uint8_t nbytes, uint8_t uint8_t rcode = pUsb->outTransfer(bAddress, epInfo[ BTD_DATAOUT_PIPE ].epAddr, (8 + nbytes), buf); if (rcode) { delay(100); // This small delay prevents it from overflowing if it fails -#ifdef DEBUG +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nError sending L2CAP message: 0x"), 0x80); PrintHex (rcode, 0x80); Notify(PSTR(" - Channel ID: "), 0x80); diff --git a/PS3BT.cpp b/PS3BT.cpp index 473c6099..26ad8772 100644 --- a/PS3BT.cpp +++ b/PS3BT.cpp @@ -16,7 +16,7 @@ */ #include "PS3BT.h" -// To enable serial debugging uncomment "#define DEBUG" in message.h +// To enable serial debugging uncomment "#define DEBUG_USB_HOST" in message.h //#define EXTRADEBUG // Uncomment to get even more debugging data //#define PRINTREPORT // Uncomment to print the report send by the PS3 Controllers @@ -255,7 +255,7 @@ void PS3BT::ACLData(uint8_t* ACLData) { l2cap_state = L2CAP_WAIT; for (uint8_t i = 0; i < 30; i++) remote_name[i] = pBtd->remote_name[i]; // Store the remote name for the connection -#ifdef DEBUG +#ifdef DEBUG_USB_HOST if (pBtd->hci_version < 3) { // Check the HCI Version of the Bluetooth dongle Notify(PSTR("\r\nYour dongle may not support reading the analog buttons, sensors and status\r\nYour HCI Version is: "), 0x80); Notify(pBtd->hci_version, 0x80); @@ -270,7 +270,7 @@ void PS3BT::ACLData(uint8_t* ACLData) { l2capinbuf[i] = ACLData[i]; if ((l2capinbuf[6] | (l2capinbuf[7] << 8)) == 0x0001) { //l2cap_control - Channel ID for ACL-U if (l2capinbuf[8] == L2CAP_CMD_COMMAND_REJECT) { -#ifdef DEBUG +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nL2CAP Command Rejected - Reason: "), 0x80); PrintHex (l2capinbuf[13], 0x80); Notify(PSTR(" "), 0x80); @@ -330,14 +330,14 @@ void PS3BT::ACLData(uint8_t* ACLData) { } } else if (l2capinbuf[8] == L2CAP_CMD_DISCONNECT_REQUEST) { if (l2capinbuf[12] == control_dcid[0] && l2capinbuf[13] == control_dcid[1]) { -#ifdef DEBUG +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nDisconnect Request: Control Channel"), 0x80); #endif identifier = l2capinbuf[9]; pBtd->l2cap_disconnection_response(hci_handle, identifier, control_dcid, control_scid); Reset(); } else if (l2capinbuf[12] == interrupt_dcid[0] && l2capinbuf[13] == interrupt_dcid[1]) { -#ifdef DEBUG +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nDisconnect Request: Interrupt Channel"), 0x80); #endif identifier = l2capinbuf[9]; @@ -397,7 +397,7 @@ void PS3BT::L2CAP_task() { switch (l2cap_state) { case L2CAP_WAIT: if (l2cap_connection_request_control_flag) { -#ifdef DEBUG +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nHID Control Incoming Connection Request"), 0x80); #endif pBtd->l2cap_connection_response(hci_handle, identifier, control_dcid, control_scid, PENDING); @@ -411,7 +411,7 @@ void PS3BT::L2CAP_task() { break; case L2CAP_CONTROL_REQUEST: if (l2cap_config_request_control_flag) { -#ifdef DEBUG +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nHID Control Configuration Request"), 0x80); #endif pBtd->l2cap_config_response(hci_handle, identifier, control_scid); @@ -421,7 +421,7 @@ void PS3BT::L2CAP_task() { case L2CAP_CONTROL_SUCCESS: if (l2cap_config_success_control_flag) { -#ifdef DEBUG +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nHID Control Successfully Configured"), 0x80); #endif l2cap_state = L2CAP_INTERRUPT_SETUP; @@ -429,7 +429,7 @@ void PS3BT::L2CAP_task() { break; case L2CAP_INTERRUPT_SETUP: if (l2cap_connection_request_interrupt_flag) { -#ifdef DEBUG +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nHID Interrupt Incoming Connection Request"), 0x80); #endif pBtd->l2cap_connection_response(hci_handle, identifier, interrupt_dcid, interrupt_scid, PENDING); @@ -444,7 +444,7 @@ void PS3BT::L2CAP_task() { break; case L2CAP_INTERRUPT_REQUEST: if (l2cap_config_request_interrupt_flag) { -#ifdef DEBUG +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nHID Interrupt Configuration Request"), 0x80); #endif pBtd->l2cap_config_response(hci_handle, identifier, interrupt_scid); @@ -453,7 +453,7 @@ void PS3BT::L2CAP_task() { break; case L2CAP_INTERRUPT_SUCCESS: if (l2cap_config_success_interrupt_flag) { -#ifdef DEBUG +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nHID Interrupt Successfully Configured"), 0x80); #endif if (remote_name[0] == 'M') { // First letter in Motion Controller ('M') @@ -473,7 +473,7 @@ void PS3BT::L2CAP_task() { case L2CAP_INTERRUPT_DISCONNECT: if (l2cap_disconnect_response_interrupt_flag) { -#ifdef DEBUG +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nDisconnected Interrupt Channel"), 0x80); #endif identifier++; @@ -484,7 +484,7 @@ void PS3BT::L2CAP_task() { case L2CAP_CONTROL_DISCONNECT: if (l2cap_disconnect_response_control_flag) { -#ifdef DEBUG +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nDisconnected Control Channel"), 0x80); #endif pBtd->hci_disconnect(hci_handle); @@ -517,20 +517,20 @@ void PS3BT::Run() { if (millis() - timer > 1000) { // loop 1 second before sending the command if (remote_name[0] == 'P') { // First letter in PLAYSTATION(R)3 Controller ('P') setLedOn(LED1); -#ifdef DEBUG +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nDualshock 3 Controller Enabled\r\n"), 0x80); #endif PS3Connected = true; } else if (remote_name[0] == 'N') { // First letter in Navigation Controller ('N') setLedOn(LED1); // This just turns LED constantly on, on the Navigation controller -#ifdef DEBUG +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nNavigation Controller Enabled\r\n"), 0x80); #endif PS3NavigationConnected = true; } else if (remote_name[0] == 'M') { // First letter in Motion Controller ('M') moveSetBulb(Red); timerBulbRumble = millis(); -#ifdef DEBUG +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nMotion Controller Enabled\r\n"), 0x80); #endif PS3MoveConnected = true; @@ -650,7 +650,7 @@ void PS3BT::moveSetBulb(Colors color) { //Use this to set the Color using the pr } void PS3BT::moveSetRumble(uint8_t rumble) { -#ifdef DEBUG +#ifdef DEBUG_USB_HOST if (rumble < 64 && rumble != 0) // The rumble value has to at least 64, or approximately 25% (64/255*100) Notify(PSTR("\r\nThe rumble value has to at least 64, or approximately 25%"), 0x80); #endif diff --git a/PS3USB.cpp b/PS3USB.cpp index de30777b..9b028f68 100644 --- a/PS3USB.cpp +++ b/PS3USB.cpp @@ -16,7 +16,7 @@ */ #include "PS3USB.h" -// To enable serial debugging uncomment "#define DEBUG" in message.h +// To enable serial debugging uncomment "#define DEBUG_USB_HOST" in message.h //#define EXTRADEBUG // Uncomment to get even more debugging data //#define PRINTREPORT // Uncomment to print the report send by the PS3 Controllers @@ -58,7 +58,7 @@ uint8_t PS3USB::Init(uint8_t parent, uint8_t port, bool lowspeed) { #endif // check if address has already been assigned to an instance if (bAddress) { -#ifdef DEBUG +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nAddress in use"), 0x80); #endif return USB_ERROR_CLASS_INSTANCE_ALREADY_IN_USE; @@ -68,14 +68,14 @@ uint8_t PS3USB::Init(uint8_t parent, uint8_t port, bool lowspeed) { p = addrPool.GetUsbDevicePtr(0); if (!p) { -#ifdef DEBUG +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nAddress not found"), 0x80); #endif return USB_ERROR_ADDRESS_NOT_FOUND_IN_POOL; } if (!p->epinfo) { -#ifdef DEBUG +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nepinfo is null"), 0x80); #endif return USB_ERROR_EPINFO_IS_NULL; @@ -118,7 +118,7 @@ uint8_t PS3USB::Init(uint8_t parent, uint8_t port, bool lowspeed) { p->lowspeed = false; addrPool.FreeAddress(bAddress); bAddress = 0; -#ifdef DEBUG +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nsetAddr: "), 0x80); #endif PrintHex (rcode, 0x80); @@ -173,12 +173,12 @@ uint8_t PS3USB::Init(uint8_t parent, uint8_t port, bool lowspeed) { if (PID == PS3_PID || PID == PS3NAVIGATION_PID) { if (PID == PS3_PID) { -#ifdef DEBUG +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nDualshock 3 Controller Connected"), 0x80); #endif PS3Connected = true; } else { // must be a navigation controller -#ifdef DEBUG +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nNavigation Controller Connected"), 0x80); #endif PS3NavigationConnected = true; @@ -195,7 +195,7 @@ uint8_t PS3USB::Init(uint8_t parent, uint8_t port, bool lowspeed) { for (uint8_t i = 6; i < 10; i++) readBuf[i] = 0x7F; // Set the analog joystick values to center position } else { // must be a Motion controller -#ifdef DEBUG +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nMotion Controller Connected"), 0x80); #endif PS3MoveConnected = true; @@ -205,7 +205,7 @@ uint8_t PS3USB::Init(uint8_t parent, uint8_t port, bool lowspeed) { writeBuf[0] = 0x02; // Set report ID, this is needed for Move commands to work } -#ifdef DEBUG +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nBluetooth Address was set to: "), 0x80); for (int8_t i = 5; i > 0; i--) { PrintHex (my_bdaddr[i], 0x80); @@ -221,29 +221,29 @@ uint8_t PS3USB::Init(uint8_t parent, uint8_t port, bool lowspeed) { /* diagnostic messages */ FailGetDevDescr: -#ifdef DEBUG +#ifdef DEBUG_USB_HOST NotifyFailGetDevDescr(); goto Fail; #endif FailSetDevTblEntry: -#ifdef DEBUG +#ifdef DEBUG_USB_HOST NotifyFailSetDevTblEntry(); goto Fail; #endif FailSetConfDescr: -#ifdef DEBUG +#ifdef DEBUG_USB_HOST NotifyFailSetConfDescr(); #endif goto Fail; FailUnknownDevice: -#ifdef DEBUG +#ifdef DEBUG_USB_HOST NotifyFailUnknownDevice(VID, PID); #endif rcode = USB_DEV_CONFIG_ERROR_DEVICE_NOT_SUPPORTED; Fail: -#ifdef DEBUG +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nPS3 Init Failed, error code: "), 0x80); NotifyFail(rcode); #endif @@ -513,7 +513,7 @@ void PS3USB::moveSetBulb(Colors color) { //Use this to set the Color using the p } void PS3USB::moveSetRumble(uint8_t rumble) { -#ifdef DEBUG +#ifdef DEBUG_USB_HOST if (rumble < 64 && rumble != 0) // The rumble value has to at least 64, or approximately 25% (64/255*100) Notify(PSTR("\r\nThe rumble value has to at least 64, or approximately 25%"), 0x80); #endif diff --git a/SPP.cpp b/SPP.cpp index 18588f15..ff12d0b5 100644 --- a/SPP.cpp +++ b/SPP.cpp @@ -16,7 +16,7 @@ */ #include "SPP.h" -// To enable serial debugging uncomment "#define DEBUG" in message.h +// To enable serial debugging uncomment "#define DEBUG_USB_HOST" in message.h //#define EXTRADEBUG // Uncomment to get even more debugging data //#define PRINTREPORT // Uncomment to print the report sent to the Arduino @@ -99,7 +99,7 @@ void SPP::ACLData(uint8_t* l2capinbuf) { if (((l2capinbuf[0] | (l2capinbuf[1] << 8)) == (hci_handle | 0x2000))) { // acl_handle_ok if ((l2capinbuf[6] | (l2capinbuf[7] << 8)) == 0x0001) { //l2cap_control - Channel ID for ACL-U if (l2capinbuf[8] == L2CAP_CMD_COMMAND_REJECT) { -#ifdef DEBUG +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nL2CAP Command Rejected - Reason: "), 0x80); PrintHex (l2capinbuf[13], 0x80); Notify(PSTR(" "), 0x80); @@ -178,7 +178,7 @@ void SPP::ACLData(uint8_t* l2capinbuf) { l2cap_event_flag |= L2CAP_FLAG_DISCONNECT_RESPONSE; } } else if (l2capinbuf[8] == L2CAP_CMD_INFORMATION_REQUEST) { -#ifdef DEBUG +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nInformation request"), 0x80); #endif identifier = l2capinbuf[9]; @@ -252,7 +252,7 @@ void SPP::ACLData(uint8_t* l2capinbuf) { PrintHex (rfcommPfBit, 0x80); #endif if (rfcommChannelType == RFCOMM_DISC) { -#ifdef DEBUG +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nReceived Disconnect RFCOMM Command on channel: "), 0x80); PrintHex (rfcommChannel >> 3, 0x80); #endif @@ -282,7 +282,7 @@ void SPP::ACLData(uint8_t* l2capinbuf) { Notifyc(l2capinbuf[i + 11 + offset], 0x80); #endif } else if (rfcommChannelType == RFCOMM_UIH && l2capinbuf[11] == BT_RFCOMM_RPN_CMD) { // UIH Remote Port Negotiation Command -#ifdef DEBUG +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nReceived UIH Remote Port Negotiation Command"), 0x80); #endif rfcommbuf[0] = BT_RFCOMM_RPN_RSP; // Command @@ -297,7 +297,7 @@ void SPP::ACLData(uint8_t* l2capinbuf) { rfcommbuf[9] = l2capinbuf[20]; // Number of Frames sendRfcomm(rfcommChannel, rfcommDirection, 0, RFCOMM_UIH, rfcommPfBit, rfcommbuf, 0x0A); // UIH Remote Port Negotiation Response } else if (rfcommChannelType == RFCOMM_UIH && l2capinbuf[11] == BT_RFCOMM_MSC_CMD) { // UIH Modem Status Command -#ifdef DEBUG +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nSend UIH Modem Status Response"), 0x80); #endif rfcommbuf[0] = BT_RFCOMM_MSC_RSP; // UIH Modem Status Response @@ -308,12 +308,12 @@ void SPP::ACLData(uint8_t* l2capinbuf) { } } else { if (rfcommChannelType == RFCOMM_SABM) { // SABM Command - this is sent twice: once for channel 0 and then for the channel to establish -#ifdef DEBUG +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nReceived SABM Command"), 0x80); #endif sendRfcomm(rfcommChannel, rfcommDirection, rfcommCommandResponse, RFCOMM_UA, rfcommPfBit, rfcommbuf, 0x00); // UA Command } else if (rfcommChannelType == RFCOMM_UIH && l2capinbuf[11] == BT_RFCOMM_PN_CMD) { // UIH Parameter Negotiation Command -#ifdef DEBUG +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nReceived UIH Parameter Negotiation Command"), 0x80); #endif rfcommbuf[0] = BT_RFCOMM_PN_RSP; // UIH Parameter Negotiation Response @@ -328,7 +328,7 @@ void SPP::ACLData(uint8_t* l2capinbuf) { rfcommbuf[9] = 0x00; // Number of Frames sendRfcomm(rfcommChannel, rfcommDirection, 0, RFCOMM_UIH, rfcommPfBit, rfcommbuf, 0x0A); } else if (rfcommChannelType == RFCOMM_UIH && l2capinbuf[11] == BT_RFCOMM_MSC_CMD) { // UIH Modem Status Command -#ifdef DEBUG +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nSend UIH Modem Status Response"), 0x80); #endif rfcommbuf[0] = BT_RFCOMM_MSC_RSP; // UIH Modem Status Response @@ -338,7 +338,7 @@ void SPP::ACLData(uint8_t* l2capinbuf) { sendRfcomm(rfcommChannel, rfcommDirection, 0, RFCOMM_UIH, rfcommPfBit, rfcommbuf, 0x04); delay(1); -#ifdef DEBUG +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nSend UIH Modem Status Command"), 0x80); #endif rfcommbuf[0] = BT_RFCOMM_MSC_CMD; // UIH Modem Status Command @@ -349,7 +349,7 @@ void SPP::ACLData(uint8_t* l2capinbuf) { sendRfcomm(rfcommChannel, rfcommDirection, 0, RFCOMM_UIH, rfcommPfBit, rfcommbuf, 0x04); } else if (rfcommChannelType == RFCOMM_UIH && l2capinbuf[11] == BT_RFCOMM_MSC_RSP) { // UIH Modem Status Response if (!creditSent) { -#ifdef DEBUG +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nSend UIH Command with credit"), 0x80); #endif sendRfcommCredit(rfcommChannelConnection, rfcommDirection, 0, RFCOMM_UIH, 0x10, sizeof (rfcommDataBuffer)); // Send credit @@ -358,11 +358,11 @@ void SPP::ACLData(uint8_t* l2capinbuf) { waitForLastCommand = true; } } else if (rfcommChannelType == RFCOMM_UIH && l2capinbuf[10] == 0x01) { // UIH Command with credit -#ifdef DEBUG +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nReceived UIH Command with credit"), 0x80); #endif } else if (rfcommChannelType == RFCOMM_UIH && l2capinbuf[11] == BT_RFCOMM_RPN_CMD) { // UIH Remote Port Negotiation Command -#ifdef DEBUG +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nReceived UIH Remote Port Negotiation Command"), 0x80); #endif rfcommbuf[0] = BT_RFCOMM_RPN_RSP; // Command @@ -376,7 +376,7 @@ void SPP::ACLData(uint8_t* l2capinbuf) { rfcommbuf[8] = l2capinbuf[19]; // MaxRatransm. rfcommbuf[9] = l2capinbuf[20]; // Number of Frames sendRfcomm(rfcommChannel, rfcommDirection, 0, RFCOMM_UIH, rfcommPfBit, rfcommbuf, 0x0A); // UIH Remote Port Negotiation Response -#ifdef DEBUG +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nRFCOMM Connection is now established\r\n"), 0x80); #endif waitForLastCommand = false; @@ -384,7 +384,7 @@ void SPP::ACLData(uint8_t* l2capinbuf) { connected = true; // The RFCOMM channel is now established sppIndex = 0; } -#ifdef DEBUG +#ifdef DEBUG_USB_HOST else if (rfcommChannelType != RFCOMM_DISC) { Notify(PSTR("\r\nUnsupported RFCOMM Data - ChannelType: "), 0x80); PrintHex (rfcommChannelType, 0x80); @@ -409,7 +409,7 @@ void SPP::ACLData(uint8_t* l2capinbuf) { void SPP::Run() { if (waitForLastCommand && (millis() - timer) > 100) { // We will only wait 100ms and see if the UIH Remote Port Negotiation Command is send, as some deviced don't send it -#ifdef DEBUG +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nRFCOMM Connection is now established - Automatic\r\n"), 0x80); #endif creditSent = false; @@ -425,7 +425,7 @@ void SPP::SDP_task() { case L2CAP_SDP_WAIT: if (l2cap_connection_request_sdp_flag) { l2cap_event_flag &= ~L2CAP_FLAG_CONNECTION_SDP_REQUEST; // Clear flag -#ifdef DEBUG +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nSDP Incoming Connection Request"), 0x80); #endif pBtd->l2cap_connection_response(hci_handle, identifier, sdp_dcid, sdp_scid, PENDING); @@ -440,7 +440,7 @@ void SPP::SDP_task() { case L2CAP_SDP_REQUEST: if (l2cap_config_request_sdp_flag) { l2cap_event_flag &= ~L2CAP_FLAG_CONFIG_SDP_REQUEST; // Clear flag -#ifdef DEBUG +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nSDP Configuration Request"), 0x80); #endif pBtd->l2cap_config_response(hci_handle, identifier, sdp_scid); @@ -450,7 +450,7 @@ void SPP::SDP_task() { case L2CAP_SDP_SUCCESS: if (l2cap_config_success_sdp_flag) { l2cap_event_flag &= ~L2CAP_FLAG_CONFIG_SDP_SUCCESS; // Clear flag -#ifdef DEBUG +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nSDP Successfully Configured"), 0x80); #endif firstMessage = true; // Reset bool @@ -462,7 +462,7 @@ void SPP::SDP_task() { if (l2cap_disconnect_request_sdp_flag) { l2cap_event_flag &= ~L2CAP_FLAG_DISCONNECT_SDP_REQUEST; // Clear flag SDPConnected = false; -#ifdef DEBUG +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nDisconnected SDP Channel"), 0x80); #endif pBtd->l2cap_disconnection_response(hci_handle, identifier, sdp_dcid, sdp_scid); @@ -472,7 +472,7 @@ void SPP::SDP_task() { break; case L2CAP_DISCONNECT_RESPONSE: // This is for both disconnection response from the RFCOMM and SDP channel if they were connected if (l2cap_disconnect_response_flag) { -#ifdef DEBUG +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nDisconnected L2CAP Connection"), 0x80); #endif RFCOMMConnected = false; @@ -492,7 +492,7 @@ void SPP::RFCOMM_task() { case L2CAP_RFCOMM_WAIT: if (l2cap_connection_request_rfcomm_flag) { l2cap_event_flag &= ~L2CAP_FLAG_CONNECTION_RFCOMM_REQUEST; // Clear flag -#ifdef DEBUG +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nRFCOMM Incoming Connection Request"), 0x80); #endif pBtd->l2cap_connection_response(hci_handle, identifier, rfcomm_dcid, rfcomm_scid, PENDING); @@ -507,7 +507,7 @@ void SPP::RFCOMM_task() { case L2CAP_RFCOMM_REQUEST: if (l2cap_config_request_rfcomm_flag) { l2cap_event_flag &= ~L2CAP_FLAG_CONFIG_RFCOMM_REQUEST; // Clear flag -#ifdef DEBUG +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nRFCOMM Configuration Request"), 0x80); #endif pBtd->l2cap_config_response(hci_handle, identifier, rfcomm_scid); @@ -517,7 +517,7 @@ void SPP::RFCOMM_task() { case L2CAP_RFCOMM_SUCCESS: if (l2cap_config_success_rfcomm_flag) { l2cap_event_flag &= ~L2CAP_FLAG_CONFIG_RFCOMM_SUCCESS; // Clear flag -#ifdef DEBUG +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nRFCOMM Successfully Configured"), 0x80); #endif rfcommAvailable = 0; // Reset number of bytes available @@ -531,7 +531,7 @@ void SPP::RFCOMM_task() { l2cap_event_flag &= ~L2CAP_FLAG_DISCONNECT_RFCOMM_REQUEST; // Clear flag RFCOMMConnected = false; connected = false; -#ifdef DEBUG +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nDisconnected RFCOMM Channel"), 0x80); #endif pBtd->l2cap_disconnection_response(hci_handle, identifier, rfcomm_dcid, rfcomm_scid); diff --git a/Wii.cpp b/Wii.cpp index 53f37528..f259bfdb 100755 --- a/Wii.cpp +++ b/Wii.cpp @@ -20,7 +20,7 @@ */ #include "Wii.h" -// To enable serial debugging uncomment "#define DEBUG" in message.h +// To enable serial debugging uncomment "#define DEBUG_USB_HOST" in message.h //#define EXTRADEBUG // Uncomment to get even more debugging data //#define PRINTREPORT // Uncomment to print the report send by the Wii controllers @@ -118,7 +118,7 @@ void WII::Reset() { void WII::disconnect() { // Use this void to disconnect any of the controllers if (motionPlusConnected && !pBtd->motionPlusInside) { // Disable the Motion Plus extension -#ifdef DEBUG +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nDeactivating Motion Plus"), 0x80); #endif initExtension1(); // This will disable the Motion Plus extension @@ -144,7 +144,7 @@ void WII::ACLData(uint8_t* l2capinbuf) { if ((l2capinbuf[0] | (l2capinbuf[1] << 8)) == (hci_handle | 0x2000)) { // acl_handle_ok or it's a new connection if ((l2capinbuf[6] | (l2capinbuf[7] << 8)) == 0x0001) { //l2cap_control - Channel ID for ACL-U if (l2capinbuf[8] == L2CAP_CMD_COMMAND_REJECT) { -#ifdef DEBUG +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nL2CAP Command Rejected - Reason: "), 0x80); PrintHex (l2capinbuf[13], 0x80); Notify(PSTR(" "), 0x80); @@ -220,14 +220,14 @@ void WII::ACLData(uint8_t* l2capinbuf) { } } else if (l2capinbuf[8] == L2CAP_CMD_DISCONNECT_REQUEST) { if (l2capinbuf[12] == control_dcid[0] && l2capinbuf[13] == control_dcid[1]) { -#ifdef DEBUG +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nDisconnect Request: Control Channel"), 0x80); #endif identifier = l2capinbuf[9]; pBtd->l2cap_disconnection_response(hci_handle, identifier, control_dcid, control_scid); Reset(); } else if (l2capinbuf[12] == interrupt_dcid[0] && l2capinbuf[13] == interrupt_dcid[1]) { -#ifdef DEBUG +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nDisconnect Request: Interrupt Channel"), 0x80); #endif identifier = l2capinbuf[9]; @@ -294,12 +294,12 @@ void WII::ACLData(uint8_t* l2capinbuf) { wiiState = l2capinbuf[12]; // (0x01: Battery is nearly empty), (0x02: An Extension Controller is connected), (0x04: Speaker enabled), (0x08: IR enabled), (0x10: LED1, 0x20: LED2, 0x40: LED3, 0x80: LED4) batteryLevel = l2capinbuf[15]; // Update battery level if (l2capinbuf[12] & 0x01) { -#ifdef DEBUG +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nWARNING: Battery is nearly empty"), 0x80); #endif } if (l2capinbuf[12] & 0x02) { // Check if a extension is connected -#ifdef DEBUG +#ifdef DEBUG_USB_HOST if (!unknownExtensionConnected) Notify(PSTR("\r\nExtension connected"), 0x80); #endif @@ -309,11 +309,11 @@ void WII::ACLData(uint8_t* l2capinbuf) { #endif setReportMode(false, 0x35); // Also read the extension } else { -#ifdef DEBUG +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nExtension disconnected"), 0x80); #endif if (motionPlusConnected) { -#ifdef DEBUG +#ifdef DEBUG_USB_HOST Notify(PSTR(" - from Motion Plus"), 0x80); #endif l2cap_event_flag &= ~WII_FLAG_NUNCHUCK_CONNECTED; @@ -321,7 +321,7 @@ void WII::ACLData(uint8_t* l2capinbuf) { nunchuckConnected = false; //else if(classicControllerConnected) } else if (nunchuckConnected) { -#ifdef DEBUG +#ifdef DEBUG_USB_HOST Notify(PSTR(" - Nunchuck"), 0x80); #endif nunchuckConnected = false; // It must be the Nunchuck controller then @@ -337,40 +337,40 @@ void WII::ACLData(uint8_t* l2capinbuf) { if ((l2capinbuf[12] & 0x0F) == 0) { // No error // See: http://wiibrew.org/wiki/Wiimote/Extension_Controllers if (l2capinbuf[16] == 0x00 && l2capinbuf[17] == 0xA4 && l2capinbuf[18] == 0x20 && l2capinbuf[19] == 0x00 && l2capinbuf[20] == 0x00) { -#ifdef DEBUG +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nNunchuck connected"), 0x80); #endif l2cap_event_flag |= WII_FLAG_NUNCHUCK_CONNECTED; } else if (l2capinbuf[16] == 0x00 && (l2capinbuf[17] == 0xA6 || l2capinbuf[17] == 0xA4) && l2capinbuf[18] == 0x20 && l2capinbuf[19] == 0x00 && l2capinbuf[20] == 0x05) { -#ifdef DEBUG +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nMotion Plus connected"), 0x80); #endif l2cap_event_flag |= WII_FLAG_MOTION_PLUS_CONNECTED; } else if (l2capinbuf[16] == 0x00 && l2capinbuf[17] == 0xA4 && l2capinbuf[18] == 0x20 && l2capinbuf[19] == 0x04 && l2capinbuf[20] == 0x05) { -#ifdef DEBUG +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nMotion Plus activated in normal mode"), 0x80); #endif motionPlusConnected = true; } else if (l2capinbuf[16] == 0x00 && l2capinbuf[17] == 0xA4 && l2capinbuf[18] == 0x20 && l2capinbuf[19] == 0x05 && l2capinbuf[20] == 0x05) { -#ifdef DEBUG +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nMotion Plus activated in Nunchuck pass-through mode"), 0x80); #endif activateNunchuck = false; motionPlusConnected = true; nunchuckConnected = true; } else if (l2capinbuf[16] == 0x00 && l2capinbuf[17] == 0xA6 && l2capinbuf[18] == 0x20 && (l2capinbuf[19] == 0x00 || l2capinbuf[19] == 0x04 || l2capinbuf[19] == 0x05 || l2capinbuf[19] == 0x07) && l2capinbuf[20] == 0x05) { -#ifdef DEBUG +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nInactive Wii Motion Plus"), 0x80); Notify(PSTR("\r\nPlease unplug the Motion Plus, disconnect the Wiimote and then replug the Motion Plus Extension"), 0x80); #endif stateCounter = 300; // Skip the rest in "L2CAP_CHECK_MOTION_PLUS_STATE" } else if (l2capinbuf[16] == 0x00 && l2capinbuf[17] == 0xA4 && l2capinbuf[18] == 0x20 && l2capinbuf[19] == 0x01 && l2capinbuf[20] == 0x20) { -#ifdef DEBUG +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nWii U Pro Controller connected"), 0x80); #endif wiiUProControllerConnected = true; } -#ifdef DEBUG +#ifdef DEBUG_USB_HOST else { Notify(PSTR("\r\nUnknown Device: "), 0x80); PrintHex (l2capinbuf[13], 0x80); @@ -392,7 +392,7 @@ void WII::ACLData(uint8_t* l2capinbuf) { #endif break; case 0x22: // Acknowledge output report, return function result -#ifdef DEBUG +#ifdef DEBUG_USB_HOST if (l2capinbuf[13] != 0x00) { // Check if there is an error Notify(PSTR("\r\nCommand failed: "), 0x80); PrintHex (l2capinbuf[12], 0x80); @@ -496,7 +496,7 @@ void WII::ACLData(uint8_t* l2capinbuf) { */ } else { if ((micros() - timer) > 1000000) { // Loop for 1 sec before resetting the values -#ifdef DEBUG +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nThe gyro values has been reset"), 0x80); #endif gyroYawZero = (l2capinbuf[15] | ((l2capinbuf[18] & 0xFC) << 6)); @@ -531,7 +531,7 @@ void WII::ACLData(uint8_t* l2capinbuf) { if (!extensionConnected) { extensionConnected = true; unknownExtensionConnected = true; -#ifdef DEBUG +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nExtension connected to Motion Plus"), 0x80); #endif } @@ -539,7 +539,7 @@ void WII::ACLData(uint8_t* l2capinbuf) { if (extensionConnected && !unknownExtensionConnected) { extensionConnected = false; unknownExtensionConnected = true; -#ifdef DEBUG +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nExtension disconnected from Motion Plus"), 0x80); #endif nunchuckConnected = false; // There is no extension connected to the Motion Plus if this report is sent @@ -564,7 +564,7 @@ void WII::ACLData(uint8_t* l2capinbuf) { hatValues[RightHatY] = (l2capinbuf[21] | l2capinbuf[22] << 8); } break; -#ifdef DEBUG +#ifdef DEBUG_USB_HOST default: Notify(PSTR("\r\nUnknown Report type: "), 0x80); PrintHex (l2capinbuf[9], 0x80); @@ -583,7 +583,7 @@ void WII::L2CAP_task() { /* These states are used if the Wiimote is the host */ case L2CAP_CONTROL_SUCCESS: if (l2cap_config_success_control_flag) { -#ifdef DEBUG +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nHID Control Successfully Configured"), 0x80); #endif l2cap_state = L2CAP_INTERRUPT_SETUP; @@ -592,7 +592,7 @@ void WII::L2CAP_task() { case L2CAP_INTERRUPT_SETUP: if (l2cap_connection_request_interrupt_flag) { -#ifdef DEBUG +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nHID Interrupt Incoming Connection Request"), 0x80); #endif pBtd->l2cap_connection_response(hci_handle, identifier, interrupt_dcid, interrupt_scid, PENDING); @@ -609,7 +609,7 @@ void WII::L2CAP_task() { /* These states are used if the Arduino is the host */ case L2CAP_CONTROL_CONNECT_REQUEST: if (l2cap_connected_control_flag) { -#ifdef DEBUG +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nSend HID Control Config Request"), 0x80); #endif identifier++; @@ -620,7 +620,7 @@ void WII::L2CAP_task() { case L2CAP_CONTROL_CONFIG_REQUEST: if (l2cap_config_success_control_flag) { -#ifdef DEBUG +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nSend HID Interrupt Connection Request"), 0x80); #endif identifier++; @@ -631,7 +631,7 @@ void WII::L2CAP_task() { case L2CAP_INTERRUPT_CONNECT_REQUEST: if (l2cap_connected_interrupt_flag) { -#ifdef DEBUG +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nSend HID Interrupt Config Request"), 0x80); #endif identifier++; @@ -642,7 +642,7 @@ void WII::L2CAP_task() { case L2CAP_INTERRUPT_CONFIG_REQUEST: if (l2cap_config_success_interrupt_flag) { // Now the HID channels is established -#ifdef DEBUG +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nHID Channels Established"), 0x80); #endif pBtd->connectToWii = false; @@ -657,7 +657,7 @@ void WII::L2CAP_task() { case L2CAP_INTERRUPT_DISCONNECT: if (l2cap_disconnect_response_interrupt_flag) { -#ifdef DEBUG +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nDisconnected Interrupt Channel"), 0x80); #endif identifier++; @@ -668,7 +668,7 @@ void WII::L2CAP_task() { case L2CAP_CONTROL_DISCONNECT: if (l2cap_disconnect_response_control_flag) { -#ifdef DEBUG +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nDisconnected Control Channel"), 0x80); #endif pBtd->hci_disconnect(hci_handle); @@ -686,7 +686,7 @@ void WII::Run() { if (pBtd->connectToWii && !pBtd->l2capConnectionClaimed && !wiimoteConnected && !activeConnection) { pBtd->l2capConnectionClaimed = true; activeConnection = true; -#ifdef DEBUG +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nSend HID Control Connection Request"), 0x80); #endif hci_handle = pBtd->hci_handle; // Store the HCI Handle for the connection @@ -695,7 +695,7 @@ void WII::Run() { pBtd->l2cap_connection_request(hci_handle, identifier, control_dcid, HID_CTRL_PSM); l2cap_state = L2CAP_CONTROL_CONNECT_REQUEST; } else if (l2cap_connection_request_control_flag) { -#ifdef DEBUG +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nHID Control Incoming Connection Request"), 0x80); #endif pBtd->l2cap_connection_response(hci_handle, identifier, control_dcid, control_scid, PENDING); @@ -709,7 +709,7 @@ void WII::Run() { break; case L2CAP_CHECK_MOTION_PLUS_STATE: -#ifdef DEBUG +#ifdef DEBUG_USB_HOST if (stateCounter == 0) // Only print onnce Notify(PSTR("\r\nChecking if a Motion Plus is connected"), 0x80); #endif @@ -722,14 +722,14 @@ void WII::Run() { timer = micros(); if (unknownExtensionConnected) { -#ifdef DEBUG +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nA extension is also connected"), 0x80); #endif activateNunchuck = true; // For we will just set this to true as this the only extension supported so far } } else if (stateCounter == 601) { // We will try three times to check for the motion plus -#ifdef DEBUG +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nNo Motion Plus was detected"), 0x80); #endif stateCounter = 0; @@ -738,7 +738,7 @@ void WII::Run() { break; case L2CAP_CHECK_EXTENSION_STATE: // This is used to check if there is anything plugged in to the extension port -#ifdef DEBUG +#ifdef DEBUG_USB_HOST if (stateCounter == 0) // Only print onnce Notify(PSTR("\r\nChecking if there is any extension connected"), 0x80); #endif @@ -785,7 +785,7 @@ void WII::Run() { case L2CAP_DONE: if (unknownExtensionConnected) { -#ifdef DEBUG +#ifdef DEBUG_USB_HOST if (stateCounter == 0) // Only print once Notify(PSTR("\r\nChecking extension port"), 0x80); #endif @@ -803,7 +803,7 @@ void WII::Run() { readExtensionType(); else if (stateCounter == 250) { if (nunchuck_connected_flag) { -#ifdef DEBUG +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nNunchuck was reconnected"), 0x80); #endif activateNunchuck = true; @@ -813,7 +813,7 @@ void WII::Run() { stateCounter = 449; } else if (stateCounter == 300) { if (motionPlusConnected) { -#ifdef DEBUG +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nReactivating the Motion Plus"), 0x80); #endif initMotionPlus(); @@ -967,19 +967,19 @@ void WII::initMotionPlus() { void WII::activateMotionPlus() { uint8_t buf[1]; if (pBtd->wiiUProController) { -#ifdef DEBUG +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nActivating Wii U Pro Controller"), 0x80); #endif buf[0] = 0x00; // It seems like you can send anything but 0x04, 0x05, and 0x07 } else if (activateNunchuck) { -#ifdef DEBUG +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nActivating Motion Plus in pass-through mode"), 0x80); #endif buf[0] = 0x05; // Activate nunchuck pass-through mode } //else if(classicControllerConnected && extensionConnected) //buf[0] = 0x07; else { -#ifdef DEBUG +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nActivating Motion Plus in normal mode"), 0x80); #endif buf[0] = 0x04; // Don't use any extension @@ -1071,58 +1071,58 @@ uint16_t WII::getAnalogHat(AnalogHat a) { void WII::IRinitialize() { // Turns on and initialises the IR camera enableIRCamera1(); -#ifdef DEBUG +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nEnable IR Camera1 Complete"), 0x80); #endif delay(80); enableIRCamera2(); -#ifdef DEBUG +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nEnable IR Camera2 Complete"), 0x80); #endif delay(80); write0x08Value(); -#ifdef DEBUG +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nWrote hex number 0x08"), 0x80); #endif delay(80); writeSensitivityBlock1(); -#ifdef DEBUG +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nWrote Sensitivity Block 1"), 0x80); #endif delay(80); writeSensitivityBlock2(); -#ifdef DEBUG +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nWrote Sensitivity Block 2"), 0x80); #endif delay(80); uint8_t mode_num = 0x03; setWiiModeNumber(mode_num); // Change input for whatever mode you want i.e. 0x01, 0x03, or 0x05 -#ifdef DEBUG +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nSet Wii Mode Number To 0x"), 0x80); PrintHex (mode_num, 0x80); #endif delay(80); write0x08Value(); -#ifdef DEBUG +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nWrote Hex Number 0x08"), 0x80); #endif delay(80); setReportMode(false, 0x33); //setReportMode(false, 0x3f); // For full reporting mode, doesn't work yet -#ifdef DEBUG +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nSet Report Mode to 0x33"), 0x80); #endif delay(80); statusRequest(); // Used to update wiiState - call isIRCameraEnabled() afterwards to check if it actually worked -#ifdef DEBUG +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nIR Initialized"), 0x80); #endif } diff --git a/XBOXRECV.cpp b/XBOXRECV.cpp index 51e64e82..4f39ce04 100644 --- a/XBOXRECV.cpp +++ b/XBOXRECV.cpp @@ -18,7 +18,7 @@ */ #include "XBOXRECV.h" -// To enable serial debugging uncomment "#define DEBUG" in message.h +// To enable serial debugging uncomment "#define DEBUG_USB_HOST" in message.h //#define EXTRADEBUG // Uncomment to get even more debugging data //#define PRINTREPORT // Uncomment to print the report send by the Xbox 360 Controller @@ -52,7 +52,7 @@ uint8_t XBOXRECV::Init(uint8_t parent, uint8_t port, bool lowspeed) { #endif // check if address has already been assigned to an instance if (bAddress) { -#ifdef DEBUG +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nAddress in use"), 0x80); #endif return USB_ERROR_CLASS_INSTANCE_ALREADY_IN_USE; @@ -62,14 +62,14 @@ uint8_t XBOXRECV::Init(uint8_t parent, uint8_t port, bool lowspeed) { p = addrPool.GetUsbDevicePtr(0); if (!p) { -#ifdef DEBUG +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nAddress not found"), 0x80); #endif return USB_ERROR_ADDRESS_NOT_FOUND_IN_POOL; } if (!p->epinfo) { -#ifdef DEBUG +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nepinfo is null"), 0x80); #endif return USB_ERROR_EPINFO_IS_NULL; @@ -97,7 +97,7 @@ uint8_t XBOXRECV::Init(uint8_t parent, uint8_t port, bool lowspeed) { if (VID != XBOX_VID && VID != MADCATZ_VID) // We just check if it's a xbox receiver using the Vendor ID goto FailUnknownDevice; else if (PID != XBOX_WIRELESS_RECEIVER_PID && PID != XBOX_WIRELESS_RECEIVER_THIRD_PARTY_PID) { -#ifdef DEBUG +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nYou'll need a wireless receiver for this libary to work"), 0x80); #endif goto FailUnknownDevice; @@ -118,7 +118,7 @@ uint8_t XBOXRECV::Init(uint8_t parent, uint8_t port, bool lowspeed) { p->lowspeed = false; addrPool.FreeAddress(bAddress); bAddress = 0; -#ifdef DEBUG +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nsetAddr: "), 0x80); PrintHex (rcode, 0x80); #endif @@ -209,7 +209,7 @@ uint8_t XBOXRECV::Init(uint8_t parent, uint8_t port, bool lowspeed) { if (rcode) goto FailSetConfDescr; -#ifdef DEBUG +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nXbox Wireless Receiver Connected\r\n"), 0x80); #endif XboxReceiverConnected = true; @@ -218,31 +218,31 @@ uint8_t XBOXRECV::Init(uint8_t parent, uint8_t port, bool lowspeed) { /* diagnostic messages */ FailGetDevDescr: -#ifdef DEBUG +#ifdef DEBUG_USB_HOST NotifyFailGetDevDescr(); goto Fail; #endif FailSetDevTblEntry: -#ifdef DEBUG +#ifdef DEBUG_USB_HOST NotifyFailSetDevTblEntry(); goto Fail; #endif FailSetConfDescr: -#ifdef DEBUG +#ifdef DEBUG_USB_HOST NotifyFailSetConfDescr(); #endif goto Fail; FailUnknownDevice: -#ifdef DEBUG +#ifdef DEBUG_USB_HOST NotifyFailUnknownDevice(VID,PID); #endif rcode = USB_DEV_CONFIG_ERROR_DEVICE_NOT_SUPPORTED; Fail: -#ifdef DEBUG +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nXbox 360 Init Failed, error code: "), 0x80); NotifyFail(rcode); #endif @@ -304,12 +304,12 @@ void XBOXRECV::readReport(uint8_t controller) { // This report is send when a controller is connected and disconnected if (readBuf[0] == 0x08 && readBuf[1] != Xbox360Connected[controller]) { Xbox360Connected[controller] = readBuf[1]; -#ifdef DEBUG +#ifdef DEBUG_USB_HOST Notify(PSTR("Controller "), 0x80); Notify(controller, 0x80); #endif if (Xbox360Connected[controller]) { -#ifdef DEBUG +#ifdef DEBUG_USB_HOST char* str = 0; switch (readBuf[1]) { case 0x80: str = PSTR(" as controller\r\n"); @@ -335,7 +335,7 @@ void XBOXRECV::readReport(uint8_t controller) { } setLedOn(led, controller); } -#ifdef DEBUG +#ifdef DEBUG_USB_HOST else Notify(PSTR(": disconnected\r\n"), 0x80); #endif diff --git a/XBOXUSB.cpp b/XBOXUSB.cpp index eff7d383..3b308306 100644 --- a/XBOXUSB.cpp +++ b/XBOXUSB.cpp @@ -16,7 +16,7 @@ */ #include "XBOXUSB.h" -// To enable serial debugging uncomment "#define DEBUG" in message.h +// To enable serial debugging uncomment "#define DEBUG_USB_HOST" in message.h //#define EXTRADEBUG // Uncomment to get even more debugging data //#define PRINTREPORT // Uncomment to print the report send by the Xbox 360 Controller @@ -50,7 +50,7 @@ uint8_t XBOXUSB::Init(uint8_t parent, uint8_t port, bool lowspeed) { #endif // check if address has already been assigned to an instance if (bAddress) { -#ifdef DEBUG +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nAddress in use"), 0x80); #endif return USB_ERROR_CLASS_INSTANCE_ALREADY_IN_USE; @@ -60,14 +60,14 @@ uint8_t XBOXUSB::Init(uint8_t parent, uint8_t port, bool lowspeed) { p = addrPool.GetUsbDevicePtr(0); if (!p) { -#ifdef DEBUG +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nAddress not found"), 0x80); #endif return USB_ERROR_ADDRESS_NOT_FOUND_IN_POOL; } if (!p->epinfo) { -#ifdef DEBUG +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nepinfo is null"), 0x80); #endif return USB_ERROR_EPINFO_IS_NULL; @@ -95,12 +95,12 @@ uint8_t XBOXUSB::Init(uint8_t parent, uint8_t port, bool lowspeed) { if (VID != XBOX_VID && VID != MADCATZ_VID && VID != JOYTECH_VID) // We just check if it's a xbox controller using the Vendor ID goto FailUnknownDevice; if (PID == XBOX_WIRELESS_PID) { -#ifdef DEBUG +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nYou have plugged in a wireless Xbox 360 controller - it doesn't support USB communication"), 0x80); #endif goto FailUnknownDevice; } else if (PID == XBOX_WIRELESS_RECEIVER_PID || PID == XBOX_WIRELESS_RECEIVER_THIRD_PARTY_PID) { -#ifdef DEBUG +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nThis library only supports Xbox 360 controllers via USB"), 0x80); #endif goto FailUnknownDevice; @@ -121,7 +121,7 @@ uint8_t XBOXUSB::Init(uint8_t parent, uint8_t port, bool lowspeed) { p->lowspeed = false; addrPool.FreeAddress(bAddress); bAddress = 0; -#ifdef DEBUG +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nsetAddr: "), 0x80); #endif PrintHex (rcode, 0x80); @@ -173,7 +173,7 @@ uint8_t XBOXUSB::Init(uint8_t parent, uint8_t port, bool lowspeed) { if (rcode) goto FailSetConfDescr; -#ifdef DEBUG +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nXbox 360 Controller Connected\r\n"), 0x80); #endif setLedOn(LED1); @@ -183,30 +183,30 @@ uint8_t XBOXUSB::Init(uint8_t parent, uint8_t port, bool lowspeed) { /* diagnostic messages */ FailGetDevDescr: -#ifdef DEBUG +#ifdef DEBUG_USB_HOST NotifyFailGetDevDescr(); goto Fail; #endif FailSetDevTblEntry: -#ifdef DEBUG +#ifdef DEBUG_USB_HOST NotifyFailSetDevTblEntry(); goto Fail; #endif FailSetConfDescr: -#ifdef DEBUG +#ifdef DEBUG_USB_HOST NotifyFailSetConfDescr(); goto Fail; #endif FailUnknownDevice: -#ifdef DEBUG +#ifdef DEBUG_USB_HOST NotifyFailUnknownDevice(VID, PID); #endif rcode = USB_DEV_CONFIG_ERROR_DEVICE_NOT_SUPPORTED; Fail: -#ifdef DEBUG +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nXbox 360 Init Failed, error code: "), 0x80); NotifyFail(rcode); #endif diff --git a/adk.cpp b/adk.cpp index 14904ade..14d35860 100644 --- a/adk.cpp +++ b/adk.cpp @@ -227,43 +227,43 @@ uint8_t ADK::Init(uint8_t parent, uint8_t port, bool lowspeed) { /* diagnostic messages */ FailGetDevDescr: -#ifdef DEBUG +#ifdef DEBUG_USB_HOST NotifyFailGetDevDescr(); goto Fail; #endif FailSetDevTblEntry: -#ifdef DEBUG +#ifdef DEBUG_USB_HOST NotifyFailSetDevTblEntry(); goto Fail; #endif FailGetConfDescr: -#ifdef DEBUG +#ifdef DEBUG_USB_HOST NotifyFailGetConfDescr(); goto Fail; #endif FailSetConfDescr: -#ifdef DEBUG +#ifdef DEBUG_USB_HOST NotifyFailSetConfDescr(); goto Fail; #endif FailGetProto: -#ifdef DEBUG +#ifdef DEBUG_USB_HOST USBTRACE("\r\ngetProto:"); goto Fail; #endif FailSwAcc: -#ifdef DEBUG +#ifdef DEBUG_USB_HOST USBTRACE("\r\nswAcc:"); goto Fail; #endif SwAttempt: -#ifdef DEBUG +#ifdef DEBUG_USB_HOST USBTRACE("\r\nAccessory mode switch attempt"); #endif //FailOnInit: diff --git a/cdcacm.cpp b/cdcacm.cpp index b6891615..2c75a594 100644 --- a/cdcacm.cpp +++ b/cdcacm.cpp @@ -183,36 +183,36 @@ uint8_t ACM::Init(uint8_t parent, uint8_t port, bool lowspeed) { return 0; FailGetDevDescr: -#ifdef DEBUG +#ifdef DEBUG_USB_HOST NotifyFailGetDevDescr(); goto Fail; #endif FailSetDevTblEntry: -#ifdef DEBUG +#ifdef DEBUG_USB_HOST NotifyFailSetDevTblEntry(); goto Fail; #endif FailGetConfDescr: -#ifdef DEBUG +#ifdef DEBUG_USB_HOST NotifyFailGetConfDescr(); goto Fail; #endif FailSetConfDescr: -#ifdef DEBUG +#ifdef DEBUG_USB_HOST NotifyFailSetConfDescr(); goto Fail; #endif FailOnInit: -#ifdef DEBUG +#ifdef DEBUG_USB_HOST USBTRACE("OnInit:"); #endif Fail: -#ifdef DEBUG +#ifdef DEBUG_USB_HOST NotifyFail(rcode); #endif Release(); diff --git a/cdcftdi.cpp b/cdcftdi.cpp index 626ed09f..a8489373 100644 --- a/cdcftdi.cpp +++ b/cdcftdi.cpp @@ -178,36 +178,36 @@ uint8_t FTDI::Init(uint8_t parent, uint8_t port, bool lowspeed) { return 0; FailGetDevDescr: -#ifdef DEBUG +#ifdef DEBUG_USB_HOST NotifyFailGetDevDescr(); goto Fail; #endif FailSetDevTblEntry: -#ifdef DEBUG +#ifdef DEBUG_USB_HOST NotifyFailSetDevTblEntry(); goto Fail; #endif FailGetConfDescr: -#ifdef DEBUG +#ifdef DEBUG_USB_HOST NotifyFailGetConfDescr(); goto Fail; #endif FailSetConfDescr: -#ifdef DEBUG +#ifdef DEBUG_USB_HOST NotifyFailSetConfDescr(); goto Fail; #endif FailOnInit: -#ifdef DEBUG +#ifdef DEBUG_USB_HOST USBTRACE("OnInit:"); #endif Fail: -#ifdef DEBUG +#ifdef DEBUG_USB_HOST NotifyFail(rcode); #endif Release(); diff --git a/cdcprolific.cpp b/cdcprolific.cpp index 4be8198d..ac4b0f63 100644 --- a/cdcprolific.cpp +++ b/cdcprolific.cpp @@ -155,36 +155,36 @@ uint8_t PL2303::Init(uint8_t parent, uint8_t port, bool lowspeed) { return 0; FailGetDevDescr: -#ifdef DEBUG +#ifdef DEBUG_USB_HOST NotifyFailGetDevDescr(); goto Fail; #endif FailSetDevTblEntry: -#ifdef DEBUG +#ifdef DEBUG_USB_HOST NotifyFailSetDevTblEntry(); goto Fail; #endif FailGetConfDescr: -#ifdef DEBUG +#ifdef DEBUG_USB_HOST NotifyFailGetConfDescr(); goto Fail; #endif FailSetConfDescr: -#ifdef DEBUG +#ifdef DEBUG_USB_HOST NotifyFailSetConfDescr(); goto Fail; #endif FailOnInit: -#ifdef DEBUG +#ifdef DEBUG_USB_HOST USBTRACE("OnInit:"); #endif Fail: -#ifdef DEBUG +#ifdef DEBUG_USB_HOST NotifyFail(rcode); #endif Release(); diff --git a/hidboot.h b/hidboot.h index bf002f64..797b3a3c 100644 --- a/hidboot.h +++ b/hidboot.h @@ -393,42 +393,42 @@ uint8_t HIDBoot::Init(uint8_t parent, uint8_t port, bool lowspeed return 0; FailGetDevDescr: -#ifdef DEBUG +#ifdef DEBUG_USB_HOST NotifyFailGetDevDescr(); goto Fail; #endif FailSetDevTblEntry: -#ifdef DEBUG +#ifdef DEBUG_USB_HOST NotifyFailSetDevTblEntry(); goto Fail; #endif FailGetConfDescr: -#ifdef DEBUG +#ifdef DEBUG_USB_HOST NotifyFailGetConfDescr(); goto Fail; #endif FailSetConfDescr: -#ifdef DEBUG +#ifdef DEBUG_USB_HOST NotifyFailSetConfDescr(); goto Fail; #endif FailSetProtocol: -#ifdef DEBUG +#ifdef DEBUG_USB_HOST USBTRACE("SetProto:"); goto Fail; #endif FailSetIdle: -#ifdef DEBUG +#ifdef DEBUG_USB_HOST USBTRACE("SetIdle:"); #endif Fail: -#ifdef DEBUG +#ifdef DEBUG_USB_HOST NotifyFail(rcode); #endif Release(); diff --git a/hiduniversal.cpp b/hiduniversal.cpp index d35480f7..800839e1 100644 --- a/hiduniversal.cpp +++ b/hiduniversal.cpp @@ -221,37 +221,37 @@ uint8_t HIDUniversal::Init(uint8_t parent, uint8_t port, bool lowspeed) { return 0; FailGetDevDescr: -#ifdef DEBUG +#ifdef DEBUG_USB_HOST NotifyFailGetDevDescr(); goto Fail; #endif FailSetDevTblEntry: -#ifdef DEBUG +#ifdef DEBUG_USB_HOST NotifyFailSetDevTblEntry(); goto Fail; #endif FailGetConfDescr: -#ifdef DEBUG +#ifdef DEBUG_USB_HOST NotifyFailGetConfDescr(); goto Fail; #endif FailSetConfDescr: -#ifdef DEBUG +#ifdef DEBUG_USB_HOST NotifyFailSetConfDescr(); goto Fail; #endif FailSetIdle: -#ifdef DEBUG +#ifdef DEBUG_USB_HOST USBTRACE("SetIdle:"); #endif Fail: -#ifdef DEBUG +#ifdef DEBUG_USB_HOST NotifyFail(rcode); #endif Release(); diff --git a/masstorage.cpp b/masstorage.cpp index 681999ff..6fae6ce1 100644 --- a/masstorage.cpp +++ b/masstorage.cpp @@ -174,7 +174,7 @@ uint8_t BulkOnly::ConfigureDevice(uint8_t parent, uint8_t port, bool lowspeed) { return USB_ERROR_CONFIG_REQUIRES_ADDITIONAL_RESET; FailGetDevDescr: -#ifdef DEBUG +#ifdef DEBUG_USB_HOST NotifyFailGetDevDescr(rcode); #endif rcode = USB_ERROR_FailGetDevDescr; @@ -362,42 +362,42 @@ uint8_t BulkOnly::Init(uint8_t parent, uint8_t port, bool lowspeed) { return 0; FailSetConfDescr: -#ifdef DEBUG +#ifdef DEBUG_USB_HOST NotifyFailSetConfDescr(); goto Fail; #endif FailOnInit: -#ifdef DEBUG +#ifdef DEBUG_USB_HOST USBTRACE("OnInit:"); goto Fail; #endif FailGetMaxLUN: -#ifdef DEBUG +#ifdef DEBUG_USB_HOST USBTRACE("GetMaxLUN:"); goto Fail; #endif FailInvalidSectorSize: -#ifdef DEBUG +#ifdef DEBUG_USB_HOST USBTRACE("Sector Size is NOT VALID: "); goto Fail; #endif FailSetDevTblEntry: -#ifdef DEBUG +#ifdef DEBUG_USB_HOST NotifyFailSetDevTblEntry(); goto Fail; #endif FailGetConfDescr: -#ifdef DEBUG +#ifdef DEBUG_USB_HOST NotifyFailGetConfDescr(); #endif Fail: -#ifdef DEBUG +#ifdef DEBUG_USB_HOST NotifyFail(rcode); #endif Release(); diff --git a/message.cpp b/message.cpp index 78883a73..393faa32 100644 --- a/message.cpp +++ b/message.cpp @@ -63,7 +63,7 @@ void E_Notify(double d, int lvl) { Serial.flush(); } -#ifdef DEBUG +#ifdef DEBUG_USB_HOST void NotifyFailGetDevDescr(void) { Notify(PSTR("\r\ngetDevDescr"), 0x80); } diff --git a/message.h b/message.h index 78de0dc6..a2fe5f25 100644 --- a/message.h +++ b/message.h @@ -18,7 +18,7 @@ e-mail : support@circuitsathome.com #define __MESSAGE_H__ // uncomment to activate -//#define DEBUG +//#define DEBUG_USB_HOST #include #include @@ -31,7 +31,7 @@ void E_Notify(uint8_t b, int lvl); void E_NotifyStr(char const * msg, int lvl); void E_Notifyc(char c, int lvl); -#ifdef DEBUG +#ifdef DEBUG_USB_HOST #define Notify E_Notify #define NotifyStr E_NotifyStr #define Notifyc E_Notifyc @@ -61,7 +61,7 @@ void NotifyFail(uint8_t rcode); template void ErrorMessage(uint8_t level, char const * msg, ERROR_TYPE rcode = 0) { -#ifdef DEBUG +#ifdef DEBUG_USB_HOST Notify(msg, level); Notify(PSTR(": "), level); PrintHex (rcode, level); @@ -71,7 +71,7 @@ void ErrorMessage(uint8_t level, char const * msg, ERROR_TYPE rcode = 0) { template void ErrorMessage(char const * msg, ERROR_TYPE rcode = 0) { -#ifdef DEBUG +#ifdef DEBUG_USB_HOST Notify(msg, 0x80); Notify(PSTR(": "), 0x80); PrintHex (rcode, 0x80); diff --git a/printhex.h b/printhex.h index 7ac8af6a..55a5b19f 100644 --- a/printhex.h +++ b/printhex.h @@ -27,7 +27,7 @@ void E_Notifyc(char c, int lvl); template void PrintHex(T val, int lvl) { -#ifdef DEBUG +#ifdef DEBUG_USB_HOST int num_nibbles = sizeof(T) * 2; do { @@ -40,7 +40,7 @@ void PrintHex(T val, int lvl) { template void PrintBin(T val, int lvl) { -#ifdef DEBUG +#ifdef DEBUG_USB_HOST for(T mask = (((T) 1) << ((sizeof(T) << 3) - 1)); mask; mask >>= 1) if(val & mask) E_Notifyc('1', lvl); @@ -51,7 +51,7 @@ void PrintBin(T val, int lvl) { template void SerialPrintHex(T val) { -#ifdef DEBUG +#ifdef DEBUG_USB_HOST int num_nibbles = sizeof(T) * 2; do { @@ -64,7 +64,7 @@ void SerialPrintHex(T val) { template void PrintHex2(Print *prn, T val) { -#ifdef DEBUG +#ifdef DEBUG_USB_HOST T mask = (((T) 1) << (((sizeof(T) << 1) - 1) << 2)); while(mask > 1) { From aee424c1969d44475523073b00d7412d923b4dbb Mon Sep 17 00:00:00 2001 From: "Andrew J. Kroll" Date: Mon, 10 Jun 2013 14:28:20 -0400 Subject: [PATCH 15/20] refactor DEBUG -> DEBUG_USB_HOST --- BTD.cpp | 84 +++++++++++++++++++------------------- PS3BT.cpp | 34 ++++++++-------- PS3USB.cpp | 30 +++++++------- SPP.cpp | 50 +++++++++++------------ Wii.cpp | 102 +++++++++++++++++++++++------------------------ XBOXRECV.cpp | 30 +++++++------- XBOXUSB.cpp | 26 ++++++------ adk.cpp | 14 +++---- cdcacm.cpp | 12 +++--- cdcftdi.cpp | 12 +++--- cdcprolific.cpp | 12 +++--- hidboot.h | 14 +++---- hiduniversal.cpp | 12 +++--- masstorage.cpp | 16 ++++---- message.cpp | 2 +- message.h | 8 ++-- printhex.h | 8 ++-- 17 files changed, 233 insertions(+), 233 deletions(-) diff --git a/BTD.cpp b/BTD.cpp index 7b27aacb..9dc783e2 100755 --- a/BTD.cpp +++ b/BTD.cpp @@ -16,7 +16,7 @@ */ #include "BTD.h" -// To enable serial debugging uncomment "#define DEBUG_USB_HOST" in message.h +// To enable serial debugging uncomment "#define DEBUG_USB_HOST_USB_HOST" in message.h //#define EXTRADEBUG // Uncomment to get even more debugging data const uint8_t BTD::BTD_CONTROL_PIPE = 0; @@ -58,7 +58,7 @@ uint8_t BTD::Init(uint8_t parent, uint8_t port, bool lowspeed) { #endif // check if address has already been assigned to an instance if (bAddress) { -#ifdef DEBUG_USB_HOST +#ifdef DEBUG_USB_HOST_USB_HOST Notify(PSTR("\r\nAddress in use"), 0x80); #endif return USB_ERROR_CLASS_INSTANCE_ALREADY_IN_USE; @@ -68,14 +68,14 @@ uint8_t BTD::Init(uint8_t parent, uint8_t port, bool lowspeed) { p = addrPool.GetUsbDevicePtr(0); if (!p) { -#ifdef DEBUG_USB_HOST +#ifdef DEBUG_USB_HOST_USB_HOST Notify(PSTR("\r\nAddress not found"), 0x80); #endif return USB_ERROR_ADDRESS_NOT_FOUND_IN_POOL; } if (!p->epinfo) { -#ifdef DEBUG_USB_HOST +#ifdef DEBUG_USB_HOST_USB_HOST Notify(PSTR("\r\nepinfo is null"), 0x80); #endif return USB_ERROR_EPINFO_IS_NULL; @@ -113,7 +113,7 @@ uint8_t BTD::Init(uint8_t parent, uint8_t port, bool lowspeed) { p->lowspeed = false; addrPool.FreeAddress(bAddress); bAddress = 0; -#ifdef DEBUG_USB_HOST +#ifdef DEBUG_USB_HOST_USB_HOST Notify(PSTR("\r\nsetAddr: "), 0x80); #endif PrintHex (rcode, 0x80); @@ -145,7 +145,7 @@ uint8_t BTD::Init(uint8_t parent, uint8_t port, bool lowspeed) { if (rcode) goto FailSetConfDescr; -#ifdef DEBUG_USB_HOST +#ifdef DEBUG_USB_HOST_USB_HOST if (PID == PS3_PID || PID == PS3NAVIGATION_PID) { if (PID == PS3_PID) Notify(PSTR("\r\nDualshock 3 Controller Connected"), 0x80); @@ -156,7 +156,7 @@ uint8_t BTD::Init(uint8_t parent, uint8_t port, bool lowspeed) { #endif if (my_bdaddr[0] == 0x00 && my_bdaddr[1] == 0x00 && my_bdaddr[2] == 0x00 && my_bdaddr[3] == 0x00 && my_bdaddr[4] == 0x00 && my_bdaddr[5] == 0x00) { -#ifdef DEBUG_USB_HOST +#ifdef DEBUG_USB_HOST_USB_HOST Notify(PSTR("\r\nPlease plug in the dongle before trying to pair with the PS3 Controller\n\rOr set the Bluetooth address in the constructor of the PS3BT class"), 0x80); #endif } else { @@ -164,7 +164,7 @@ uint8_t BTD::Init(uint8_t parent, uint8_t port, bool lowspeed) { setBdaddr(my_bdaddr); // Set internal Bluetooth address else setMoveBdaddr(my_bdaddr); // Set internal Bluetooth address -#ifdef DEBUG_USB_HOST +#ifdef DEBUG_USB_HOST_USB_HOST Notify(PSTR("\r\nBluetooth Address was set to: "), 0x80); for (int8_t i = 5; i > 0; i--) { PrintHex (my_bdaddr[i], 0x80); @@ -214,7 +214,7 @@ uint8_t BTD::Init(uint8_t parent, uint8_t port, bool lowspeed) { watingForConnection = false; bPollEnable = true; -#ifdef DEBUG_USB_HOST +#ifdef DEBUG_USB_HOST_USB_HOST Notify(PSTR("\r\nBluetooth Dongle Initialized"), 0x80); #endif } @@ -222,37 +222,37 @@ uint8_t BTD::Init(uint8_t parent, uint8_t port, bool lowspeed) { /* diagnostic messages */ FailGetDevDescr: -#ifdef DEBUG_USB_HOST +#ifdef DEBUG_USB_HOST_USB_HOST NotifyFailGetDevDescr(); goto Fail; #endif FailSetDevTblEntry: -#ifdef DEBUG_USB_HOST +#ifdef DEBUG_USB_HOST_USB_HOST NotifyFailSetDevTblEntry(); goto Fail; #endif FailGetConfDescr: -#ifdef DEBUG_USB_HOST +#ifdef DEBUG_USB_HOST_USB_HOST NotifyFailGetConfDescr(); goto Fail; #endif FailSetConfDescr: -#ifdef DEBUG_USB_HOST +#ifdef DEBUG_USB_HOST_USB_HOST NotifyFailSetConfDescr(); #endif goto Fail; FailUnknownDevice: -#ifdef DEBUG_USB_HOST +#ifdef DEBUG_USB_HOST_USB_HOST NotifyFailUnknownDevice(VID, PID); #endif pUsb->setAddr(bAddress, 0, 0); // Reset address rcode = USB_DEV_CONFIG_ERROR_DEVICE_NOT_SUPPORTED; Fail: -#ifdef DEBUG_USB_HOST +#ifdef DEBUG_USB_HOST_USB_HOST Notify(PSTR("\r\nBTD Init Failed, error code: "), 0x80); NotifyFail(rcode); #endif @@ -360,7 +360,7 @@ void BTD::HCI_event_task() { case EV_COMMAND_STATUS: if (hcibuf[2]) { // show status on serial if not OK -#ifdef DEBUG_USB_HOST +#ifdef DEBUG_USB_HOST_USB_HOST Notify(PSTR("\r\nHCI Command Failed: "), 0x80); PrintHex (hcibuf[2], 0x80); Notify(PSTR(" "), 0x80); @@ -374,7 +374,7 @@ void BTD::HCI_event_task() { case EV_INQUIRY_COMPLETE: if (inquiry_counter >= 5) { inquiry_counter = 0; -#ifdef DEBUG_USB_HOST +#ifdef DEBUG_USB_HOST_USB_HOST Notify(PSTR("\r\nCouldn't find Wiimote"), 0x80); #endif connectToWii = false; @@ -468,18 +468,18 @@ void BTD::HCI_event_task() { case EV_PIN_CODE_REQUEST: if (pairWithWii) { -#ifdef DEBUG_USB_HOST +#ifdef DEBUG_USB_HOST_USB_HOST Notify(PSTR("\r\nPairing with wiimote"), 0x80); #endif hci_pin_code_request_reply(); } else if (btdPin != NULL) { -#ifdef DEBUG_USB_HOST +#ifdef DEBUG_USB_HOST_USB_HOST Notify(PSTR("\r\nBluetooth pin is set too: "), 0x80); NotifyStr(btdPin, 0x80); #endif hci_pin_code_request_reply(); } else { -#ifdef DEBUG_USB_HOST +#ifdef DEBUG_USB_HOST_USB_HOST Notify(PSTR("\r\nNo pin was set"), 0x80); #endif hci_pin_code_negative_request_reply(); @@ -487,7 +487,7 @@ void BTD::HCI_event_task() { break; case EV_LINK_KEY_REQUEST: -#ifdef DEBUG_USB_HOST +#ifdef DEBUG_USB_HOST_USB_HOST Notify(PSTR("\r\nReceived Key Request"), 0x80); #endif hci_link_key_request_negative_reply(); @@ -495,7 +495,7 @@ void BTD::HCI_event_task() { case EV_AUTHENTICATION_COMPLETE: if (pairWithWii && !connectToWii) { -#ifdef DEBUG_USB_HOST +#ifdef DEBUG_USB_HOST_USB_HOST Notify(PSTR("\r\nPairing successful"), 0x80); #endif connectToWii = true; // Only send the ACL data to the Wii service @@ -549,7 +549,7 @@ void BTD::HCI_task() { hci_counter++; if (hci_cmd_complete) { hci_counter = 0; -#ifdef DEBUG_USB_HOST +#ifdef DEBUG_USB_HOST_USB_HOST Notify(PSTR("\r\nHCI Reset complete"), 0x80); #endif hci_state = HCI_CLASS_STATE; @@ -558,7 +558,7 @@ void BTD::HCI_task() { hci_num_reset_loops *= 10; if (hci_num_reset_loops > 2000) hci_num_reset_loops = 2000; -#ifdef DEBUG_USB_HOST +#ifdef DEBUG_USB_HOST_USB_HOST Notify(PSTR("\r\nNo response to HCI Reset"), 0x80); #endif hci_state = HCI_INIT_STATE; @@ -568,7 +568,7 @@ void BTD::HCI_task() { case HCI_CLASS_STATE: if (hci_cmd_complete) { -#ifdef DEBUG_USB_HOST +#ifdef DEBUG_USB_HOST_USB_HOST Notify(PSTR("\r\nWrite class of device"), 0x80); #endif hci_state = HCI_BDADDR_STATE; @@ -578,7 +578,7 @@ void BTD::HCI_task() { case HCI_BDADDR_STATE: if (hci_read_bdaddr_complete) { -#ifdef DEBUG_USB_HOST +#ifdef DEBUG_USB_HOST_USB_HOST Notify(PSTR("\r\nLocal Bluetooth Address: "), 0x80); for (int8_t i = 5; i > 0; i--) { PrintHex (my_bdaddr[i], 0x80); @@ -603,7 +603,7 @@ void BTD::HCI_task() { case HCI_SET_NAME_STATE: if (hci_cmd_complete) { -#ifdef DEBUG_USB_HOST +#ifdef DEBUG_USB_HOST_USB_HOST Notify(PSTR("\r\nThe name is set to: "), 0x80); NotifyStr(btdName, 0x80); #endif @@ -613,7 +613,7 @@ void BTD::HCI_task() { case HCI_CHECK_WII_SERVICE: if (pairWithWii) { // Check if it should try to connect to a wiimote -#ifdef DEBUG_USB_HOST +#ifdef DEBUG_USB_HOST_USB_HOST Notify(PSTR("\r\nStarting inquiry\r\nPress 1 & 2 on the Wiimote\r\nOr press sync if you are using a Wii U Pro Controller"), 0x80); #endif hci_inquiry(); @@ -625,7 +625,7 @@ void BTD::HCI_task() { case HCI_INQUIRY_STATE: if (hci_wii_found) { hci_inquiry_cancel(); // Stop inquiry -#ifdef DEBUG_USB_HOST +#ifdef DEBUG_USB_HOST_USB_HOST Notify(PSTR("\r\nWiimote found"), 0x80); Notify(PSTR("\r\nNow just create the instance like so:"), 0x80); Notify(PSTR("\r\nWII Wii(&Btd);"), 0x80); @@ -641,7 +641,7 @@ void BTD::HCI_task() { case HCI_CONNECT_WII_STATE: if (hci_cmd_complete) { -#ifdef DEBUG_USB_HOST +#ifdef DEBUG_USB_HOST_USB_HOST Notify(PSTR("\r\nConnecting to Wiimote"), 0x80); #endif hci_connect(); @@ -652,13 +652,13 @@ void BTD::HCI_task() { case HCI_CONNECTED_WII_STATE: if (hci_connect_event) { if (hci_connect_complete) { -#ifdef DEBUG_USB_HOST +#ifdef DEBUG_USB_HOST_USB_HOST Notify(PSTR("\r\nConnected to Wiimote"), 0x80); #endif hci_authentication_request(); // This will start the pairing with the wiimote hci_state = HCI_SCANNING_STATE; } else { -#ifdef DEBUG_USB_HOST +#ifdef DEBUG_USB_HOST_USB_HOST Notify(PSTR("\r\nTrying to connect one more time..."), 0x80); #endif hci_connect(); // Try to connect one more time @@ -668,7 +668,7 @@ void BTD::HCI_task() { case HCI_SCANNING_STATE: if (!connectToWii && !pairWithWii) { -#ifdef DEBUG_USB_HOST +#ifdef DEBUG_USB_HOST_USB_HOST Notify(PSTR("\r\nWait For Incoming Connection Request"), 0x80); #endif hci_write_scan_enable(); @@ -680,7 +680,7 @@ void BTD::HCI_task() { case HCI_CONNECT_IN_STATE: if (hci_incoming_connect_request) { watingForConnection = false; -#ifdef DEBUG_USB_HOST +#ifdef DEBUG_USB_HOST_USB_HOST Notify(PSTR("\r\nIncoming Connection Request"), 0x80); #endif hci_remote_name(); @@ -691,7 +691,7 @@ void BTD::HCI_task() { case HCI_REMOTE_NAME_STATE: if (hci_remote_name_complete) { -#ifdef DEBUG_USB_HOST +#ifdef DEBUG_USB_HOST_USB_HOST Notify(PSTR("\r\nRemote Name: "), 0x80); for (uint8_t i = 0; i < 30; i++) { if (remote_name[i] == NULL) @@ -701,16 +701,16 @@ void BTD::HCI_task() { #endif if (strncmp((const char*)remote_name, "Nintendo", 8) == 0) { incomingWii = true; -#ifdef DEBUG_USB_HOST +#ifdef DEBUG_USB_HOST_USB_HOST Notify(PSTR("\r\nWiimote is connecting"), 0x80); #endif if (strncmp((const char*)remote_name, "Nintendo RVL-CNT-01-TR", 22) == 0) { -#ifdef DEBUG_USB_HOST +#ifdef DEBUG_USB_HOST_USB_HOST Notify(PSTR(" with Motion Plus Inside"), 0x80); #endif motionPlusInside = true; } else if (strncmp((const char*)remote_name, "Nintendo RVL-CNT-01-UC", 22) == 0) { -#ifdef DEBUG_USB_HOST +#ifdef DEBUG_USB_HOST_USB_HOST Notify(PSTR(" - Wii U Pro Controller"), 0x80); #endif motionPlusInside = true; @@ -731,7 +731,7 @@ void BTD::HCI_task() { case HCI_CONNECTED_STATE: if (hci_connect_complete) { -#ifdef DEBUG_USB_HOST +#ifdef DEBUG_USB_HOST_USB_HOST Notify(PSTR("\r\nConnected to Device: "), 0x80); for (int8_t i = 5; i > 0; i--) { PrintHex (disc_bdaddr[i], 0x80); @@ -759,7 +759,7 @@ void BTD::HCI_task() { case HCI_DISCONNECT_STATE: if (hci_disconnect_complete) { -#ifdef DEBUG_USB_HOST +#ifdef DEBUG_USB_HOST_USB_HOST Notify(PSTR("\r\nHCI Disconnected from Device"), 0x80); #endif hci_event_flag = 0; // Clear all flags @@ -957,7 +957,7 @@ void BTD::hci_pin_code_request_reply() { if (pairWithWii) { hcibuf[9] = 6; // Pin length is the length of the Bluetooth address if (wiiUProController) { -#ifdef DEBUG_USB_HOST +#ifdef DEBUG_USB_HOST_USB_HOST Notify(PSTR("\r\nParing with Wii U Pro Controller"), 0x80); #endif for (uint8_t i = 0; i < 6; i++) @@ -1083,7 +1083,7 @@ void BTD::L2CAP_Command(uint16_t handle, uint8_t* data, uint8_t nbytes, uint8_t uint8_t rcode = pUsb->outTransfer(bAddress, epInfo[ BTD_DATAOUT_PIPE ].epAddr, (8 + nbytes), buf); if (rcode) { delay(100); // This small delay prevents it from overflowing if it fails -#ifdef DEBUG_USB_HOST +#ifdef DEBUG_USB_HOST_USB_HOST Notify(PSTR("\r\nError sending L2CAP message: 0x"), 0x80); PrintHex (rcode, 0x80); Notify(PSTR(" - Channel ID: "), 0x80); diff --git a/PS3BT.cpp b/PS3BT.cpp index 26ad8772..72d654c1 100644 --- a/PS3BT.cpp +++ b/PS3BT.cpp @@ -16,7 +16,7 @@ */ #include "PS3BT.h" -// To enable serial debugging uncomment "#define DEBUG_USB_HOST" in message.h +// To enable serial debugging uncomment "#define DEBUG_USB_HOST_USB_HOST" in message.h //#define EXTRADEBUG // Uncomment to get even more debugging data //#define PRINTREPORT // Uncomment to print the report send by the PS3 Controllers @@ -255,7 +255,7 @@ void PS3BT::ACLData(uint8_t* ACLData) { l2cap_state = L2CAP_WAIT; for (uint8_t i = 0; i < 30; i++) remote_name[i] = pBtd->remote_name[i]; // Store the remote name for the connection -#ifdef DEBUG_USB_HOST +#ifdef DEBUG_USB_HOST_USB_HOST if (pBtd->hci_version < 3) { // Check the HCI Version of the Bluetooth dongle Notify(PSTR("\r\nYour dongle may not support reading the analog buttons, sensors and status\r\nYour HCI Version is: "), 0x80); Notify(pBtd->hci_version, 0x80); @@ -270,7 +270,7 @@ void PS3BT::ACLData(uint8_t* ACLData) { l2capinbuf[i] = ACLData[i]; if ((l2capinbuf[6] | (l2capinbuf[7] << 8)) == 0x0001) { //l2cap_control - Channel ID for ACL-U if (l2capinbuf[8] == L2CAP_CMD_COMMAND_REJECT) { -#ifdef DEBUG_USB_HOST +#ifdef DEBUG_USB_HOST_USB_HOST Notify(PSTR("\r\nL2CAP Command Rejected - Reason: "), 0x80); PrintHex (l2capinbuf[13], 0x80); Notify(PSTR(" "), 0x80); @@ -330,14 +330,14 @@ void PS3BT::ACLData(uint8_t* ACLData) { } } else if (l2capinbuf[8] == L2CAP_CMD_DISCONNECT_REQUEST) { if (l2capinbuf[12] == control_dcid[0] && l2capinbuf[13] == control_dcid[1]) { -#ifdef DEBUG_USB_HOST +#ifdef DEBUG_USB_HOST_USB_HOST Notify(PSTR("\r\nDisconnect Request: Control Channel"), 0x80); #endif identifier = l2capinbuf[9]; pBtd->l2cap_disconnection_response(hci_handle, identifier, control_dcid, control_scid); Reset(); } else if (l2capinbuf[12] == interrupt_dcid[0] && l2capinbuf[13] == interrupt_dcid[1]) { -#ifdef DEBUG_USB_HOST +#ifdef DEBUG_USB_HOST_USB_HOST Notify(PSTR("\r\nDisconnect Request: Interrupt Channel"), 0x80); #endif identifier = l2capinbuf[9]; @@ -397,7 +397,7 @@ void PS3BT::L2CAP_task() { switch (l2cap_state) { case L2CAP_WAIT: if (l2cap_connection_request_control_flag) { -#ifdef DEBUG_USB_HOST +#ifdef DEBUG_USB_HOST_USB_HOST Notify(PSTR("\r\nHID Control Incoming Connection Request"), 0x80); #endif pBtd->l2cap_connection_response(hci_handle, identifier, control_dcid, control_scid, PENDING); @@ -411,7 +411,7 @@ void PS3BT::L2CAP_task() { break; case L2CAP_CONTROL_REQUEST: if (l2cap_config_request_control_flag) { -#ifdef DEBUG_USB_HOST +#ifdef DEBUG_USB_HOST_USB_HOST Notify(PSTR("\r\nHID Control Configuration Request"), 0x80); #endif pBtd->l2cap_config_response(hci_handle, identifier, control_scid); @@ -421,7 +421,7 @@ void PS3BT::L2CAP_task() { case L2CAP_CONTROL_SUCCESS: if (l2cap_config_success_control_flag) { -#ifdef DEBUG_USB_HOST +#ifdef DEBUG_USB_HOST_USB_HOST Notify(PSTR("\r\nHID Control Successfully Configured"), 0x80); #endif l2cap_state = L2CAP_INTERRUPT_SETUP; @@ -429,7 +429,7 @@ void PS3BT::L2CAP_task() { break; case L2CAP_INTERRUPT_SETUP: if (l2cap_connection_request_interrupt_flag) { -#ifdef DEBUG_USB_HOST +#ifdef DEBUG_USB_HOST_USB_HOST Notify(PSTR("\r\nHID Interrupt Incoming Connection Request"), 0x80); #endif pBtd->l2cap_connection_response(hci_handle, identifier, interrupt_dcid, interrupt_scid, PENDING); @@ -444,7 +444,7 @@ void PS3BT::L2CAP_task() { break; case L2CAP_INTERRUPT_REQUEST: if (l2cap_config_request_interrupt_flag) { -#ifdef DEBUG_USB_HOST +#ifdef DEBUG_USB_HOST_USB_HOST Notify(PSTR("\r\nHID Interrupt Configuration Request"), 0x80); #endif pBtd->l2cap_config_response(hci_handle, identifier, interrupt_scid); @@ -453,7 +453,7 @@ void PS3BT::L2CAP_task() { break; case L2CAP_INTERRUPT_SUCCESS: if (l2cap_config_success_interrupt_flag) { -#ifdef DEBUG_USB_HOST +#ifdef DEBUG_USB_HOST_USB_HOST Notify(PSTR("\r\nHID Interrupt Successfully Configured"), 0x80); #endif if (remote_name[0] == 'M') { // First letter in Motion Controller ('M') @@ -473,7 +473,7 @@ void PS3BT::L2CAP_task() { case L2CAP_INTERRUPT_DISCONNECT: if (l2cap_disconnect_response_interrupt_flag) { -#ifdef DEBUG_USB_HOST +#ifdef DEBUG_USB_HOST_USB_HOST Notify(PSTR("\r\nDisconnected Interrupt Channel"), 0x80); #endif identifier++; @@ -484,7 +484,7 @@ void PS3BT::L2CAP_task() { case L2CAP_CONTROL_DISCONNECT: if (l2cap_disconnect_response_control_flag) { -#ifdef DEBUG_USB_HOST +#ifdef DEBUG_USB_HOST_USB_HOST Notify(PSTR("\r\nDisconnected Control Channel"), 0x80); #endif pBtd->hci_disconnect(hci_handle); @@ -517,20 +517,20 @@ void PS3BT::Run() { if (millis() - timer > 1000) { // loop 1 second before sending the command if (remote_name[0] == 'P') { // First letter in PLAYSTATION(R)3 Controller ('P') setLedOn(LED1); -#ifdef DEBUG_USB_HOST +#ifdef DEBUG_USB_HOST_USB_HOST Notify(PSTR("\r\nDualshock 3 Controller Enabled\r\n"), 0x80); #endif PS3Connected = true; } else if (remote_name[0] == 'N') { // First letter in Navigation Controller ('N') setLedOn(LED1); // This just turns LED constantly on, on the Navigation controller -#ifdef DEBUG_USB_HOST +#ifdef DEBUG_USB_HOST_USB_HOST Notify(PSTR("\r\nNavigation Controller Enabled\r\n"), 0x80); #endif PS3NavigationConnected = true; } else if (remote_name[0] == 'M') { // First letter in Motion Controller ('M') moveSetBulb(Red); timerBulbRumble = millis(); -#ifdef DEBUG_USB_HOST +#ifdef DEBUG_USB_HOST_USB_HOST Notify(PSTR("\r\nMotion Controller Enabled\r\n"), 0x80); #endif PS3MoveConnected = true; @@ -650,7 +650,7 @@ void PS3BT::moveSetBulb(Colors color) { //Use this to set the Color using the pr } void PS3BT::moveSetRumble(uint8_t rumble) { -#ifdef DEBUG_USB_HOST +#ifdef DEBUG_USB_HOST_USB_HOST if (rumble < 64 && rumble != 0) // The rumble value has to at least 64, or approximately 25% (64/255*100) Notify(PSTR("\r\nThe rumble value has to at least 64, or approximately 25%"), 0x80); #endif diff --git a/PS3USB.cpp b/PS3USB.cpp index 9b028f68..e6a884a3 100644 --- a/PS3USB.cpp +++ b/PS3USB.cpp @@ -16,7 +16,7 @@ */ #include "PS3USB.h" -// To enable serial debugging uncomment "#define DEBUG_USB_HOST" in message.h +// To enable serial debugging uncomment "#define DEBUG_USB_HOST_USB_HOST" in message.h //#define EXTRADEBUG // Uncomment to get even more debugging data //#define PRINTREPORT // Uncomment to print the report send by the PS3 Controllers @@ -58,7 +58,7 @@ uint8_t PS3USB::Init(uint8_t parent, uint8_t port, bool lowspeed) { #endif // check if address has already been assigned to an instance if (bAddress) { -#ifdef DEBUG_USB_HOST +#ifdef DEBUG_USB_HOST_USB_HOST Notify(PSTR("\r\nAddress in use"), 0x80); #endif return USB_ERROR_CLASS_INSTANCE_ALREADY_IN_USE; @@ -68,14 +68,14 @@ uint8_t PS3USB::Init(uint8_t parent, uint8_t port, bool lowspeed) { p = addrPool.GetUsbDevicePtr(0); if (!p) { -#ifdef DEBUG_USB_HOST +#ifdef DEBUG_USB_HOST_USB_HOST Notify(PSTR("\r\nAddress not found"), 0x80); #endif return USB_ERROR_ADDRESS_NOT_FOUND_IN_POOL; } if (!p->epinfo) { -#ifdef DEBUG_USB_HOST +#ifdef DEBUG_USB_HOST_USB_HOST Notify(PSTR("\r\nepinfo is null"), 0x80); #endif return USB_ERROR_EPINFO_IS_NULL; @@ -118,7 +118,7 @@ uint8_t PS3USB::Init(uint8_t parent, uint8_t port, bool lowspeed) { p->lowspeed = false; addrPool.FreeAddress(bAddress); bAddress = 0; -#ifdef DEBUG_USB_HOST +#ifdef DEBUG_USB_HOST_USB_HOST Notify(PSTR("\r\nsetAddr: "), 0x80); #endif PrintHex (rcode, 0x80); @@ -173,12 +173,12 @@ uint8_t PS3USB::Init(uint8_t parent, uint8_t port, bool lowspeed) { if (PID == PS3_PID || PID == PS3NAVIGATION_PID) { if (PID == PS3_PID) { -#ifdef DEBUG_USB_HOST +#ifdef DEBUG_USB_HOST_USB_HOST Notify(PSTR("\r\nDualshock 3 Controller Connected"), 0x80); #endif PS3Connected = true; } else { // must be a navigation controller -#ifdef DEBUG_USB_HOST +#ifdef DEBUG_USB_HOST_USB_HOST Notify(PSTR("\r\nNavigation Controller Connected"), 0x80); #endif PS3NavigationConnected = true; @@ -195,7 +195,7 @@ uint8_t PS3USB::Init(uint8_t parent, uint8_t port, bool lowspeed) { for (uint8_t i = 6; i < 10; i++) readBuf[i] = 0x7F; // Set the analog joystick values to center position } else { // must be a Motion controller -#ifdef DEBUG_USB_HOST +#ifdef DEBUG_USB_HOST_USB_HOST Notify(PSTR("\r\nMotion Controller Connected"), 0x80); #endif PS3MoveConnected = true; @@ -205,7 +205,7 @@ uint8_t PS3USB::Init(uint8_t parent, uint8_t port, bool lowspeed) { writeBuf[0] = 0x02; // Set report ID, this is needed for Move commands to work } -#ifdef DEBUG_USB_HOST +#ifdef DEBUG_USB_HOST_USB_HOST Notify(PSTR("\r\nBluetooth Address was set to: "), 0x80); for (int8_t i = 5; i > 0; i--) { PrintHex (my_bdaddr[i], 0x80); @@ -221,29 +221,29 @@ uint8_t PS3USB::Init(uint8_t parent, uint8_t port, bool lowspeed) { /* diagnostic messages */ FailGetDevDescr: -#ifdef DEBUG_USB_HOST +#ifdef DEBUG_USB_HOST_USB_HOST NotifyFailGetDevDescr(); goto Fail; #endif FailSetDevTblEntry: -#ifdef DEBUG_USB_HOST +#ifdef DEBUG_USB_HOST_USB_HOST NotifyFailSetDevTblEntry(); goto Fail; #endif FailSetConfDescr: -#ifdef DEBUG_USB_HOST +#ifdef DEBUG_USB_HOST_USB_HOST NotifyFailSetConfDescr(); #endif goto Fail; FailUnknownDevice: -#ifdef DEBUG_USB_HOST +#ifdef DEBUG_USB_HOST_USB_HOST NotifyFailUnknownDevice(VID, PID); #endif rcode = USB_DEV_CONFIG_ERROR_DEVICE_NOT_SUPPORTED; Fail: -#ifdef DEBUG_USB_HOST +#ifdef DEBUG_USB_HOST_USB_HOST Notify(PSTR("\r\nPS3 Init Failed, error code: "), 0x80); NotifyFail(rcode); #endif @@ -513,7 +513,7 @@ void PS3USB::moveSetBulb(Colors color) { //Use this to set the Color using the p } void PS3USB::moveSetRumble(uint8_t rumble) { -#ifdef DEBUG_USB_HOST +#ifdef DEBUG_USB_HOST_USB_HOST if (rumble < 64 && rumble != 0) // The rumble value has to at least 64, or approximately 25% (64/255*100) Notify(PSTR("\r\nThe rumble value has to at least 64, or approximately 25%"), 0x80); #endif diff --git a/SPP.cpp b/SPP.cpp index ff12d0b5..243b7338 100644 --- a/SPP.cpp +++ b/SPP.cpp @@ -16,7 +16,7 @@ */ #include "SPP.h" -// To enable serial debugging uncomment "#define DEBUG_USB_HOST" in message.h +// To enable serial debugging uncomment "#define DEBUG_USB_HOST_USB_HOST" in message.h //#define EXTRADEBUG // Uncomment to get even more debugging data //#define PRINTREPORT // Uncomment to print the report sent to the Arduino @@ -99,7 +99,7 @@ void SPP::ACLData(uint8_t* l2capinbuf) { if (((l2capinbuf[0] | (l2capinbuf[1] << 8)) == (hci_handle | 0x2000))) { // acl_handle_ok if ((l2capinbuf[6] | (l2capinbuf[7] << 8)) == 0x0001) { //l2cap_control - Channel ID for ACL-U if (l2capinbuf[8] == L2CAP_CMD_COMMAND_REJECT) { -#ifdef DEBUG_USB_HOST +#ifdef DEBUG_USB_HOST_USB_HOST Notify(PSTR("\r\nL2CAP Command Rejected - Reason: "), 0x80); PrintHex (l2capinbuf[13], 0x80); Notify(PSTR(" "), 0x80); @@ -178,7 +178,7 @@ void SPP::ACLData(uint8_t* l2capinbuf) { l2cap_event_flag |= L2CAP_FLAG_DISCONNECT_RESPONSE; } } else if (l2capinbuf[8] == L2CAP_CMD_INFORMATION_REQUEST) { -#ifdef DEBUG_USB_HOST +#ifdef DEBUG_USB_HOST_USB_HOST Notify(PSTR("\r\nInformation request"), 0x80); #endif identifier = l2capinbuf[9]; @@ -252,7 +252,7 @@ void SPP::ACLData(uint8_t* l2capinbuf) { PrintHex (rfcommPfBit, 0x80); #endif if (rfcommChannelType == RFCOMM_DISC) { -#ifdef DEBUG_USB_HOST +#ifdef DEBUG_USB_HOST_USB_HOST Notify(PSTR("\r\nReceived Disconnect RFCOMM Command on channel: "), 0x80); PrintHex (rfcommChannel >> 3, 0x80); #endif @@ -282,7 +282,7 @@ void SPP::ACLData(uint8_t* l2capinbuf) { Notifyc(l2capinbuf[i + 11 + offset], 0x80); #endif } else if (rfcommChannelType == RFCOMM_UIH && l2capinbuf[11] == BT_RFCOMM_RPN_CMD) { // UIH Remote Port Negotiation Command -#ifdef DEBUG_USB_HOST +#ifdef DEBUG_USB_HOST_USB_HOST Notify(PSTR("\r\nReceived UIH Remote Port Negotiation Command"), 0x80); #endif rfcommbuf[0] = BT_RFCOMM_RPN_RSP; // Command @@ -297,7 +297,7 @@ void SPP::ACLData(uint8_t* l2capinbuf) { rfcommbuf[9] = l2capinbuf[20]; // Number of Frames sendRfcomm(rfcommChannel, rfcommDirection, 0, RFCOMM_UIH, rfcommPfBit, rfcommbuf, 0x0A); // UIH Remote Port Negotiation Response } else if (rfcommChannelType == RFCOMM_UIH && l2capinbuf[11] == BT_RFCOMM_MSC_CMD) { // UIH Modem Status Command -#ifdef DEBUG_USB_HOST +#ifdef DEBUG_USB_HOST_USB_HOST Notify(PSTR("\r\nSend UIH Modem Status Response"), 0x80); #endif rfcommbuf[0] = BT_RFCOMM_MSC_RSP; // UIH Modem Status Response @@ -308,12 +308,12 @@ void SPP::ACLData(uint8_t* l2capinbuf) { } } else { if (rfcommChannelType == RFCOMM_SABM) { // SABM Command - this is sent twice: once for channel 0 and then for the channel to establish -#ifdef DEBUG_USB_HOST +#ifdef DEBUG_USB_HOST_USB_HOST Notify(PSTR("\r\nReceived SABM Command"), 0x80); #endif sendRfcomm(rfcommChannel, rfcommDirection, rfcommCommandResponse, RFCOMM_UA, rfcommPfBit, rfcommbuf, 0x00); // UA Command } else if (rfcommChannelType == RFCOMM_UIH && l2capinbuf[11] == BT_RFCOMM_PN_CMD) { // UIH Parameter Negotiation Command -#ifdef DEBUG_USB_HOST +#ifdef DEBUG_USB_HOST_USB_HOST Notify(PSTR("\r\nReceived UIH Parameter Negotiation Command"), 0x80); #endif rfcommbuf[0] = BT_RFCOMM_PN_RSP; // UIH Parameter Negotiation Response @@ -328,7 +328,7 @@ void SPP::ACLData(uint8_t* l2capinbuf) { rfcommbuf[9] = 0x00; // Number of Frames sendRfcomm(rfcommChannel, rfcommDirection, 0, RFCOMM_UIH, rfcommPfBit, rfcommbuf, 0x0A); } else if (rfcommChannelType == RFCOMM_UIH && l2capinbuf[11] == BT_RFCOMM_MSC_CMD) { // UIH Modem Status Command -#ifdef DEBUG_USB_HOST +#ifdef DEBUG_USB_HOST_USB_HOST Notify(PSTR("\r\nSend UIH Modem Status Response"), 0x80); #endif rfcommbuf[0] = BT_RFCOMM_MSC_RSP; // UIH Modem Status Response @@ -338,7 +338,7 @@ void SPP::ACLData(uint8_t* l2capinbuf) { sendRfcomm(rfcommChannel, rfcommDirection, 0, RFCOMM_UIH, rfcommPfBit, rfcommbuf, 0x04); delay(1); -#ifdef DEBUG_USB_HOST +#ifdef DEBUG_USB_HOST_USB_HOST Notify(PSTR("\r\nSend UIH Modem Status Command"), 0x80); #endif rfcommbuf[0] = BT_RFCOMM_MSC_CMD; // UIH Modem Status Command @@ -349,7 +349,7 @@ void SPP::ACLData(uint8_t* l2capinbuf) { sendRfcomm(rfcommChannel, rfcommDirection, 0, RFCOMM_UIH, rfcommPfBit, rfcommbuf, 0x04); } else if (rfcommChannelType == RFCOMM_UIH && l2capinbuf[11] == BT_RFCOMM_MSC_RSP) { // UIH Modem Status Response if (!creditSent) { -#ifdef DEBUG_USB_HOST +#ifdef DEBUG_USB_HOST_USB_HOST Notify(PSTR("\r\nSend UIH Command with credit"), 0x80); #endif sendRfcommCredit(rfcommChannelConnection, rfcommDirection, 0, RFCOMM_UIH, 0x10, sizeof (rfcommDataBuffer)); // Send credit @@ -358,11 +358,11 @@ void SPP::ACLData(uint8_t* l2capinbuf) { waitForLastCommand = true; } } else if (rfcommChannelType == RFCOMM_UIH && l2capinbuf[10] == 0x01) { // UIH Command with credit -#ifdef DEBUG_USB_HOST +#ifdef DEBUG_USB_HOST_USB_HOST Notify(PSTR("\r\nReceived UIH Command with credit"), 0x80); #endif } else if (rfcommChannelType == RFCOMM_UIH && l2capinbuf[11] == BT_RFCOMM_RPN_CMD) { // UIH Remote Port Negotiation Command -#ifdef DEBUG_USB_HOST +#ifdef DEBUG_USB_HOST_USB_HOST Notify(PSTR("\r\nReceived UIH Remote Port Negotiation Command"), 0x80); #endif rfcommbuf[0] = BT_RFCOMM_RPN_RSP; // Command @@ -376,7 +376,7 @@ void SPP::ACLData(uint8_t* l2capinbuf) { rfcommbuf[8] = l2capinbuf[19]; // MaxRatransm. rfcommbuf[9] = l2capinbuf[20]; // Number of Frames sendRfcomm(rfcommChannel, rfcommDirection, 0, RFCOMM_UIH, rfcommPfBit, rfcommbuf, 0x0A); // UIH Remote Port Negotiation Response -#ifdef DEBUG_USB_HOST +#ifdef DEBUG_USB_HOST_USB_HOST Notify(PSTR("\r\nRFCOMM Connection is now established\r\n"), 0x80); #endif waitForLastCommand = false; @@ -384,7 +384,7 @@ void SPP::ACLData(uint8_t* l2capinbuf) { connected = true; // The RFCOMM channel is now established sppIndex = 0; } -#ifdef DEBUG_USB_HOST +#ifdef DEBUG_USB_HOST_USB_HOST else if (rfcommChannelType != RFCOMM_DISC) { Notify(PSTR("\r\nUnsupported RFCOMM Data - ChannelType: "), 0x80); PrintHex (rfcommChannelType, 0x80); @@ -409,7 +409,7 @@ void SPP::ACLData(uint8_t* l2capinbuf) { void SPP::Run() { if (waitForLastCommand && (millis() - timer) > 100) { // We will only wait 100ms and see if the UIH Remote Port Negotiation Command is send, as some deviced don't send it -#ifdef DEBUG_USB_HOST +#ifdef DEBUG_USB_HOST_USB_HOST Notify(PSTR("\r\nRFCOMM Connection is now established - Automatic\r\n"), 0x80); #endif creditSent = false; @@ -425,7 +425,7 @@ void SPP::SDP_task() { case L2CAP_SDP_WAIT: if (l2cap_connection_request_sdp_flag) { l2cap_event_flag &= ~L2CAP_FLAG_CONNECTION_SDP_REQUEST; // Clear flag -#ifdef DEBUG_USB_HOST +#ifdef DEBUG_USB_HOST_USB_HOST Notify(PSTR("\r\nSDP Incoming Connection Request"), 0x80); #endif pBtd->l2cap_connection_response(hci_handle, identifier, sdp_dcid, sdp_scid, PENDING); @@ -440,7 +440,7 @@ void SPP::SDP_task() { case L2CAP_SDP_REQUEST: if (l2cap_config_request_sdp_flag) { l2cap_event_flag &= ~L2CAP_FLAG_CONFIG_SDP_REQUEST; // Clear flag -#ifdef DEBUG_USB_HOST +#ifdef DEBUG_USB_HOST_USB_HOST Notify(PSTR("\r\nSDP Configuration Request"), 0x80); #endif pBtd->l2cap_config_response(hci_handle, identifier, sdp_scid); @@ -450,7 +450,7 @@ void SPP::SDP_task() { case L2CAP_SDP_SUCCESS: if (l2cap_config_success_sdp_flag) { l2cap_event_flag &= ~L2CAP_FLAG_CONFIG_SDP_SUCCESS; // Clear flag -#ifdef DEBUG_USB_HOST +#ifdef DEBUG_USB_HOST_USB_HOST Notify(PSTR("\r\nSDP Successfully Configured"), 0x80); #endif firstMessage = true; // Reset bool @@ -462,7 +462,7 @@ void SPP::SDP_task() { if (l2cap_disconnect_request_sdp_flag) { l2cap_event_flag &= ~L2CAP_FLAG_DISCONNECT_SDP_REQUEST; // Clear flag SDPConnected = false; -#ifdef DEBUG_USB_HOST +#ifdef DEBUG_USB_HOST_USB_HOST Notify(PSTR("\r\nDisconnected SDP Channel"), 0x80); #endif pBtd->l2cap_disconnection_response(hci_handle, identifier, sdp_dcid, sdp_scid); @@ -472,7 +472,7 @@ void SPP::SDP_task() { break; case L2CAP_DISCONNECT_RESPONSE: // This is for both disconnection response from the RFCOMM and SDP channel if they were connected if (l2cap_disconnect_response_flag) { -#ifdef DEBUG_USB_HOST +#ifdef DEBUG_USB_HOST_USB_HOST Notify(PSTR("\r\nDisconnected L2CAP Connection"), 0x80); #endif RFCOMMConnected = false; @@ -492,7 +492,7 @@ void SPP::RFCOMM_task() { case L2CAP_RFCOMM_WAIT: if (l2cap_connection_request_rfcomm_flag) { l2cap_event_flag &= ~L2CAP_FLAG_CONNECTION_RFCOMM_REQUEST; // Clear flag -#ifdef DEBUG_USB_HOST +#ifdef DEBUG_USB_HOST_USB_HOST Notify(PSTR("\r\nRFCOMM Incoming Connection Request"), 0x80); #endif pBtd->l2cap_connection_response(hci_handle, identifier, rfcomm_dcid, rfcomm_scid, PENDING); @@ -507,7 +507,7 @@ void SPP::RFCOMM_task() { case L2CAP_RFCOMM_REQUEST: if (l2cap_config_request_rfcomm_flag) { l2cap_event_flag &= ~L2CAP_FLAG_CONFIG_RFCOMM_REQUEST; // Clear flag -#ifdef DEBUG_USB_HOST +#ifdef DEBUG_USB_HOST_USB_HOST Notify(PSTR("\r\nRFCOMM Configuration Request"), 0x80); #endif pBtd->l2cap_config_response(hci_handle, identifier, rfcomm_scid); @@ -517,7 +517,7 @@ void SPP::RFCOMM_task() { case L2CAP_RFCOMM_SUCCESS: if (l2cap_config_success_rfcomm_flag) { l2cap_event_flag &= ~L2CAP_FLAG_CONFIG_RFCOMM_SUCCESS; // Clear flag -#ifdef DEBUG_USB_HOST +#ifdef DEBUG_USB_HOST_USB_HOST Notify(PSTR("\r\nRFCOMM Successfully Configured"), 0x80); #endif rfcommAvailable = 0; // Reset number of bytes available @@ -531,7 +531,7 @@ void SPP::RFCOMM_task() { l2cap_event_flag &= ~L2CAP_FLAG_DISCONNECT_RFCOMM_REQUEST; // Clear flag RFCOMMConnected = false; connected = false; -#ifdef DEBUG_USB_HOST +#ifdef DEBUG_USB_HOST_USB_HOST Notify(PSTR("\r\nDisconnected RFCOMM Channel"), 0x80); #endif pBtd->l2cap_disconnection_response(hci_handle, identifier, rfcomm_dcid, rfcomm_scid); diff --git a/Wii.cpp b/Wii.cpp index f259bfdb..e638d3ef 100755 --- a/Wii.cpp +++ b/Wii.cpp @@ -20,7 +20,7 @@ */ #include "Wii.h" -// To enable serial debugging uncomment "#define DEBUG_USB_HOST" in message.h +// To enable serial debugging uncomment "#define DEBUG_USB_HOST_USB_HOST" in message.h //#define EXTRADEBUG // Uncomment to get even more debugging data //#define PRINTREPORT // Uncomment to print the report send by the Wii controllers @@ -118,7 +118,7 @@ void WII::Reset() { void WII::disconnect() { // Use this void to disconnect any of the controllers if (motionPlusConnected && !pBtd->motionPlusInside) { // Disable the Motion Plus extension -#ifdef DEBUG_USB_HOST +#ifdef DEBUG_USB_HOST_USB_HOST Notify(PSTR("\r\nDeactivating Motion Plus"), 0x80); #endif initExtension1(); // This will disable the Motion Plus extension @@ -144,7 +144,7 @@ void WII::ACLData(uint8_t* l2capinbuf) { if ((l2capinbuf[0] | (l2capinbuf[1] << 8)) == (hci_handle | 0x2000)) { // acl_handle_ok or it's a new connection if ((l2capinbuf[6] | (l2capinbuf[7] << 8)) == 0x0001) { //l2cap_control - Channel ID for ACL-U if (l2capinbuf[8] == L2CAP_CMD_COMMAND_REJECT) { -#ifdef DEBUG_USB_HOST +#ifdef DEBUG_USB_HOST_USB_HOST Notify(PSTR("\r\nL2CAP Command Rejected - Reason: "), 0x80); PrintHex (l2capinbuf[13], 0x80); Notify(PSTR(" "), 0x80); @@ -220,14 +220,14 @@ void WII::ACLData(uint8_t* l2capinbuf) { } } else if (l2capinbuf[8] == L2CAP_CMD_DISCONNECT_REQUEST) { if (l2capinbuf[12] == control_dcid[0] && l2capinbuf[13] == control_dcid[1]) { -#ifdef DEBUG_USB_HOST +#ifdef DEBUG_USB_HOST_USB_HOST Notify(PSTR("\r\nDisconnect Request: Control Channel"), 0x80); #endif identifier = l2capinbuf[9]; pBtd->l2cap_disconnection_response(hci_handle, identifier, control_dcid, control_scid); Reset(); } else if (l2capinbuf[12] == interrupt_dcid[0] && l2capinbuf[13] == interrupt_dcid[1]) { -#ifdef DEBUG_USB_HOST +#ifdef DEBUG_USB_HOST_USB_HOST Notify(PSTR("\r\nDisconnect Request: Interrupt Channel"), 0x80); #endif identifier = l2capinbuf[9]; @@ -294,12 +294,12 @@ void WII::ACLData(uint8_t* l2capinbuf) { wiiState = l2capinbuf[12]; // (0x01: Battery is nearly empty), (0x02: An Extension Controller is connected), (0x04: Speaker enabled), (0x08: IR enabled), (0x10: LED1, 0x20: LED2, 0x40: LED3, 0x80: LED4) batteryLevel = l2capinbuf[15]; // Update battery level if (l2capinbuf[12] & 0x01) { -#ifdef DEBUG_USB_HOST +#ifdef DEBUG_USB_HOST_USB_HOST Notify(PSTR("\r\nWARNING: Battery is nearly empty"), 0x80); #endif } if (l2capinbuf[12] & 0x02) { // Check if a extension is connected -#ifdef DEBUG_USB_HOST +#ifdef DEBUG_USB_HOST_USB_HOST if (!unknownExtensionConnected) Notify(PSTR("\r\nExtension connected"), 0x80); #endif @@ -309,11 +309,11 @@ void WII::ACLData(uint8_t* l2capinbuf) { #endif setReportMode(false, 0x35); // Also read the extension } else { -#ifdef DEBUG_USB_HOST +#ifdef DEBUG_USB_HOST_USB_HOST Notify(PSTR("\r\nExtension disconnected"), 0x80); #endif if (motionPlusConnected) { -#ifdef DEBUG_USB_HOST +#ifdef DEBUG_USB_HOST_USB_HOST Notify(PSTR(" - from Motion Plus"), 0x80); #endif l2cap_event_flag &= ~WII_FLAG_NUNCHUCK_CONNECTED; @@ -321,7 +321,7 @@ void WII::ACLData(uint8_t* l2capinbuf) { nunchuckConnected = false; //else if(classicControllerConnected) } else if (nunchuckConnected) { -#ifdef DEBUG_USB_HOST +#ifdef DEBUG_USB_HOST_USB_HOST Notify(PSTR(" - Nunchuck"), 0x80); #endif nunchuckConnected = false; // It must be the Nunchuck controller then @@ -337,40 +337,40 @@ void WII::ACLData(uint8_t* l2capinbuf) { if ((l2capinbuf[12] & 0x0F) == 0) { // No error // See: http://wiibrew.org/wiki/Wiimote/Extension_Controllers if (l2capinbuf[16] == 0x00 && l2capinbuf[17] == 0xA4 && l2capinbuf[18] == 0x20 && l2capinbuf[19] == 0x00 && l2capinbuf[20] == 0x00) { -#ifdef DEBUG_USB_HOST +#ifdef DEBUG_USB_HOST_USB_HOST Notify(PSTR("\r\nNunchuck connected"), 0x80); #endif l2cap_event_flag |= WII_FLAG_NUNCHUCK_CONNECTED; } else if (l2capinbuf[16] == 0x00 && (l2capinbuf[17] == 0xA6 || l2capinbuf[17] == 0xA4) && l2capinbuf[18] == 0x20 && l2capinbuf[19] == 0x00 && l2capinbuf[20] == 0x05) { -#ifdef DEBUG_USB_HOST +#ifdef DEBUG_USB_HOST_USB_HOST Notify(PSTR("\r\nMotion Plus connected"), 0x80); #endif l2cap_event_flag |= WII_FLAG_MOTION_PLUS_CONNECTED; } else if (l2capinbuf[16] == 0x00 && l2capinbuf[17] == 0xA4 && l2capinbuf[18] == 0x20 && l2capinbuf[19] == 0x04 && l2capinbuf[20] == 0x05) { -#ifdef DEBUG_USB_HOST +#ifdef DEBUG_USB_HOST_USB_HOST Notify(PSTR("\r\nMotion Plus activated in normal mode"), 0x80); #endif motionPlusConnected = true; } else if (l2capinbuf[16] == 0x00 && l2capinbuf[17] == 0xA4 && l2capinbuf[18] == 0x20 && l2capinbuf[19] == 0x05 && l2capinbuf[20] == 0x05) { -#ifdef DEBUG_USB_HOST +#ifdef DEBUG_USB_HOST_USB_HOST Notify(PSTR("\r\nMotion Plus activated in Nunchuck pass-through mode"), 0x80); #endif activateNunchuck = false; motionPlusConnected = true; nunchuckConnected = true; } else if (l2capinbuf[16] == 0x00 && l2capinbuf[17] == 0xA6 && l2capinbuf[18] == 0x20 && (l2capinbuf[19] == 0x00 || l2capinbuf[19] == 0x04 || l2capinbuf[19] == 0x05 || l2capinbuf[19] == 0x07) && l2capinbuf[20] == 0x05) { -#ifdef DEBUG_USB_HOST +#ifdef DEBUG_USB_HOST_USB_HOST Notify(PSTR("\r\nInactive Wii Motion Plus"), 0x80); Notify(PSTR("\r\nPlease unplug the Motion Plus, disconnect the Wiimote and then replug the Motion Plus Extension"), 0x80); #endif stateCounter = 300; // Skip the rest in "L2CAP_CHECK_MOTION_PLUS_STATE" } else if (l2capinbuf[16] == 0x00 && l2capinbuf[17] == 0xA4 && l2capinbuf[18] == 0x20 && l2capinbuf[19] == 0x01 && l2capinbuf[20] == 0x20) { -#ifdef DEBUG_USB_HOST +#ifdef DEBUG_USB_HOST_USB_HOST Notify(PSTR("\r\nWii U Pro Controller connected"), 0x80); #endif wiiUProControllerConnected = true; } -#ifdef DEBUG_USB_HOST +#ifdef DEBUG_USB_HOST_USB_HOST else { Notify(PSTR("\r\nUnknown Device: "), 0x80); PrintHex (l2capinbuf[13], 0x80); @@ -392,7 +392,7 @@ void WII::ACLData(uint8_t* l2capinbuf) { #endif break; case 0x22: // Acknowledge output report, return function result -#ifdef DEBUG_USB_HOST +#ifdef DEBUG_USB_HOST_USB_HOST if (l2capinbuf[13] != 0x00) { // Check if there is an error Notify(PSTR("\r\nCommand failed: "), 0x80); PrintHex (l2capinbuf[12], 0x80); @@ -496,7 +496,7 @@ void WII::ACLData(uint8_t* l2capinbuf) { */ } else { if ((micros() - timer) > 1000000) { // Loop for 1 sec before resetting the values -#ifdef DEBUG_USB_HOST +#ifdef DEBUG_USB_HOST_USB_HOST Notify(PSTR("\r\nThe gyro values has been reset"), 0x80); #endif gyroYawZero = (l2capinbuf[15] | ((l2capinbuf[18] & 0xFC) << 6)); @@ -531,7 +531,7 @@ void WII::ACLData(uint8_t* l2capinbuf) { if (!extensionConnected) { extensionConnected = true; unknownExtensionConnected = true; -#ifdef DEBUG_USB_HOST +#ifdef DEBUG_USB_HOST_USB_HOST Notify(PSTR("\r\nExtension connected to Motion Plus"), 0x80); #endif } @@ -539,7 +539,7 @@ void WII::ACLData(uint8_t* l2capinbuf) { if (extensionConnected && !unknownExtensionConnected) { extensionConnected = false; unknownExtensionConnected = true; -#ifdef DEBUG_USB_HOST +#ifdef DEBUG_USB_HOST_USB_HOST Notify(PSTR("\r\nExtension disconnected from Motion Plus"), 0x80); #endif nunchuckConnected = false; // There is no extension connected to the Motion Plus if this report is sent @@ -564,7 +564,7 @@ void WII::ACLData(uint8_t* l2capinbuf) { hatValues[RightHatY] = (l2capinbuf[21] | l2capinbuf[22] << 8); } break; -#ifdef DEBUG_USB_HOST +#ifdef DEBUG_USB_HOST_USB_HOST default: Notify(PSTR("\r\nUnknown Report type: "), 0x80); PrintHex (l2capinbuf[9], 0x80); @@ -583,7 +583,7 @@ void WII::L2CAP_task() { /* These states are used if the Wiimote is the host */ case L2CAP_CONTROL_SUCCESS: if (l2cap_config_success_control_flag) { -#ifdef DEBUG_USB_HOST +#ifdef DEBUG_USB_HOST_USB_HOST Notify(PSTR("\r\nHID Control Successfully Configured"), 0x80); #endif l2cap_state = L2CAP_INTERRUPT_SETUP; @@ -592,7 +592,7 @@ void WII::L2CAP_task() { case L2CAP_INTERRUPT_SETUP: if (l2cap_connection_request_interrupt_flag) { -#ifdef DEBUG_USB_HOST +#ifdef DEBUG_USB_HOST_USB_HOST Notify(PSTR("\r\nHID Interrupt Incoming Connection Request"), 0x80); #endif pBtd->l2cap_connection_response(hci_handle, identifier, interrupt_dcid, interrupt_scid, PENDING); @@ -609,7 +609,7 @@ void WII::L2CAP_task() { /* These states are used if the Arduino is the host */ case L2CAP_CONTROL_CONNECT_REQUEST: if (l2cap_connected_control_flag) { -#ifdef DEBUG_USB_HOST +#ifdef DEBUG_USB_HOST_USB_HOST Notify(PSTR("\r\nSend HID Control Config Request"), 0x80); #endif identifier++; @@ -620,7 +620,7 @@ void WII::L2CAP_task() { case L2CAP_CONTROL_CONFIG_REQUEST: if (l2cap_config_success_control_flag) { -#ifdef DEBUG_USB_HOST +#ifdef DEBUG_USB_HOST_USB_HOST Notify(PSTR("\r\nSend HID Interrupt Connection Request"), 0x80); #endif identifier++; @@ -631,7 +631,7 @@ void WII::L2CAP_task() { case L2CAP_INTERRUPT_CONNECT_REQUEST: if (l2cap_connected_interrupt_flag) { -#ifdef DEBUG_USB_HOST +#ifdef DEBUG_USB_HOST_USB_HOST Notify(PSTR("\r\nSend HID Interrupt Config Request"), 0x80); #endif identifier++; @@ -642,7 +642,7 @@ void WII::L2CAP_task() { case L2CAP_INTERRUPT_CONFIG_REQUEST: if (l2cap_config_success_interrupt_flag) { // Now the HID channels is established -#ifdef DEBUG_USB_HOST +#ifdef DEBUG_USB_HOST_USB_HOST Notify(PSTR("\r\nHID Channels Established"), 0x80); #endif pBtd->connectToWii = false; @@ -657,7 +657,7 @@ void WII::L2CAP_task() { case L2CAP_INTERRUPT_DISCONNECT: if (l2cap_disconnect_response_interrupt_flag) { -#ifdef DEBUG_USB_HOST +#ifdef DEBUG_USB_HOST_USB_HOST Notify(PSTR("\r\nDisconnected Interrupt Channel"), 0x80); #endif identifier++; @@ -668,7 +668,7 @@ void WII::L2CAP_task() { case L2CAP_CONTROL_DISCONNECT: if (l2cap_disconnect_response_control_flag) { -#ifdef DEBUG_USB_HOST +#ifdef DEBUG_USB_HOST_USB_HOST Notify(PSTR("\r\nDisconnected Control Channel"), 0x80); #endif pBtd->hci_disconnect(hci_handle); @@ -686,7 +686,7 @@ void WII::Run() { if (pBtd->connectToWii && !pBtd->l2capConnectionClaimed && !wiimoteConnected && !activeConnection) { pBtd->l2capConnectionClaimed = true; activeConnection = true; -#ifdef DEBUG_USB_HOST +#ifdef DEBUG_USB_HOST_USB_HOST Notify(PSTR("\r\nSend HID Control Connection Request"), 0x80); #endif hci_handle = pBtd->hci_handle; // Store the HCI Handle for the connection @@ -695,7 +695,7 @@ void WII::Run() { pBtd->l2cap_connection_request(hci_handle, identifier, control_dcid, HID_CTRL_PSM); l2cap_state = L2CAP_CONTROL_CONNECT_REQUEST; } else if (l2cap_connection_request_control_flag) { -#ifdef DEBUG_USB_HOST +#ifdef DEBUG_USB_HOST_USB_HOST Notify(PSTR("\r\nHID Control Incoming Connection Request"), 0x80); #endif pBtd->l2cap_connection_response(hci_handle, identifier, control_dcid, control_scid, PENDING); @@ -709,7 +709,7 @@ void WII::Run() { break; case L2CAP_CHECK_MOTION_PLUS_STATE: -#ifdef DEBUG_USB_HOST +#ifdef DEBUG_USB_HOST_USB_HOST if (stateCounter == 0) // Only print onnce Notify(PSTR("\r\nChecking if a Motion Plus is connected"), 0x80); #endif @@ -722,14 +722,14 @@ void WII::Run() { timer = micros(); if (unknownExtensionConnected) { -#ifdef DEBUG_USB_HOST +#ifdef DEBUG_USB_HOST_USB_HOST Notify(PSTR("\r\nA extension is also connected"), 0x80); #endif activateNunchuck = true; // For we will just set this to true as this the only extension supported so far } } else if (stateCounter == 601) { // We will try three times to check for the motion plus -#ifdef DEBUG_USB_HOST +#ifdef DEBUG_USB_HOST_USB_HOST Notify(PSTR("\r\nNo Motion Plus was detected"), 0x80); #endif stateCounter = 0; @@ -738,7 +738,7 @@ void WII::Run() { break; case L2CAP_CHECK_EXTENSION_STATE: // This is used to check if there is anything plugged in to the extension port -#ifdef DEBUG_USB_HOST +#ifdef DEBUG_USB_HOST_USB_HOST if (stateCounter == 0) // Only print onnce Notify(PSTR("\r\nChecking if there is any extension connected"), 0x80); #endif @@ -785,7 +785,7 @@ void WII::Run() { case L2CAP_DONE: if (unknownExtensionConnected) { -#ifdef DEBUG_USB_HOST +#ifdef DEBUG_USB_HOST_USB_HOST if (stateCounter == 0) // Only print once Notify(PSTR("\r\nChecking extension port"), 0x80); #endif @@ -803,7 +803,7 @@ void WII::Run() { readExtensionType(); else if (stateCounter == 250) { if (nunchuck_connected_flag) { -#ifdef DEBUG_USB_HOST +#ifdef DEBUG_USB_HOST_USB_HOST Notify(PSTR("\r\nNunchuck was reconnected"), 0x80); #endif activateNunchuck = true; @@ -813,7 +813,7 @@ void WII::Run() { stateCounter = 449; } else if (stateCounter == 300) { if (motionPlusConnected) { -#ifdef DEBUG_USB_HOST +#ifdef DEBUG_USB_HOST_USB_HOST Notify(PSTR("\r\nReactivating the Motion Plus"), 0x80); #endif initMotionPlus(); @@ -967,19 +967,19 @@ void WII::initMotionPlus() { void WII::activateMotionPlus() { uint8_t buf[1]; if (pBtd->wiiUProController) { -#ifdef DEBUG_USB_HOST +#ifdef DEBUG_USB_HOST_USB_HOST Notify(PSTR("\r\nActivating Wii U Pro Controller"), 0x80); #endif buf[0] = 0x00; // It seems like you can send anything but 0x04, 0x05, and 0x07 } else if (activateNunchuck) { -#ifdef DEBUG_USB_HOST +#ifdef DEBUG_USB_HOST_USB_HOST Notify(PSTR("\r\nActivating Motion Plus in pass-through mode"), 0x80); #endif buf[0] = 0x05; // Activate nunchuck pass-through mode } //else if(classicControllerConnected && extensionConnected) //buf[0] = 0x07; else { -#ifdef DEBUG_USB_HOST +#ifdef DEBUG_USB_HOST_USB_HOST Notify(PSTR("\r\nActivating Motion Plus in normal mode"), 0x80); #endif buf[0] = 0x04; // Don't use any extension @@ -1071,58 +1071,58 @@ uint16_t WII::getAnalogHat(AnalogHat a) { void WII::IRinitialize() { // Turns on and initialises the IR camera enableIRCamera1(); -#ifdef DEBUG_USB_HOST +#ifdef DEBUG_USB_HOST_USB_HOST Notify(PSTR("\r\nEnable IR Camera1 Complete"), 0x80); #endif delay(80); enableIRCamera2(); -#ifdef DEBUG_USB_HOST +#ifdef DEBUG_USB_HOST_USB_HOST Notify(PSTR("\r\nEnable IR Camera2 Complete"), 0x80); #endif delay(80); write0x08Value(); -#ifdef DEBUG_USB_HOST +#ifdef DEBUG_USB_HOST_USB_HOST Notify(PSTR("\r\nWrote hex number 0x08"), 0x80); #endif delay(80); writeSensitivityBlock1(); -#ifdef DEBUG_USB_HOST +#ifdef DEBUG_USB_HOST_USB_HOST Notify(PSTR("\r\nWrote Sensitivity Block 1"), 0x80); #endif delay(80); writeSensitivityBlock2(); -#ifdef DEBUG_USB_HOST +#ifdef DEBUG_USB_HOST_USB_HOST Notify(PSTR("\r\nWrote Sensitivity Block 2"), 0x80); #endif delay(80); uint8_t mode_num = 0x03; setWiiModeNumber(mode_num); // Change input for whatever mode you want i.e. 0x01, 0x03, or 0x05 -#ifdef DEBUG_USB_HOST +#ifdef DEBUG_USB_HOST_USB_HOST Notify(PSTR("\r\nSet Wii Mode Number To 0x"), 0x80); PrintHex (mode_num, 0x80); #endif delay(80); write0x08Value(); -#ifdef DEBUG_USB_HOST +#ifdef DEBUG_USB_HOST_USB_HOST Notify(PSTR("\r\nWrote Hex Number 0x08"), 0x80); #endif delay(80); setReportMode(false, 0x33); //setReportMode(false, 0x3f); // For full reporting mode, doesn't work yet -#ifdef DEBUG_USB_HOST +#ifdef DEBUG_USB_HOST_USB_HOST Notify(PSTR("\r\nSet Report Mode to 0x33"), 0x80); #endif delay(80); statusRequest(); // Used to update wiiState - call isIRCameraEnabled() afterwards to check if it actually worked -#ifdef DEBUG_USB_HOST +#ifdef DEBUG_USB_HOST_USB_HOST Notify(PSTR("\r\nIR Initialized"), 0x80); #endif } diff --git a/XBOXRECV.cpp b/XBOXRECV.cpp index 4f39ce04..070747b6 100644 --- a/XBOXRECV.cpp +++ b/XBOXRECV.cpp @@ -18,7 +18,7 @@ */ #include "XBOXRECV.h" -// To enable serial debugging uncomment "#define DEBUG_USB_HOST" in message.h +// To enable serial debugging uncomment "#define DEBUG_USB_HOST_USB_HOST" in message.h //#define EXTRADEBUG // Uncomment to get even more debugging data //#define PRINTREPORT // Uncomment to print the report send by the Xbox 360 Controller @@ -52,7 +52,7 @@ uint8_t XBOXRECV::Init(uint8_t parent, uint8_t port, bool lowspeed) { #endif // check if address has already been assigned to an instance if (bAddress) { -#ifdef DEBUG_USB_HOST +#ifdef DEBUG_USB_HOST_USB_HOST Notify(PSTR("\r\nAddress in use"), 0x80); #endif return USB_ERROR_CLASS_INSTANCE_ALREADY_IN_USE; @@ -62,14 +62,14 @@ uint8_t XBOXRECV::Init(uint8_t parent, uint8_t port, bool lowspeed) { p = addrPool.GetUsbDevicePtr(0); if (!p) { -#ifdef DEBUG_USB_HOST +#ifdef DEBUG_USB_HOST_USB_HOST Notify(PSTR("\r\nAddress not found"), 0x80); #endif return USB_ERROR_ADDRESS_NOT_FOUND_IN_POOL; } if (!p->epinfo) { -#ifdef DEBUG_USB_HOST +#ifdef DEBUG_USB_HOST_USB_HOST Notify(PSTR("\r\nepinfo is null"), 0x80); #endif return USB_ERROR_EPINFO_IS_NULL; @@ -97,7 +97,7 @@ uint8_t XBOXRECV::Init(uint8_t parent, uint8_t port, bool lowspeed) { if (VID != XBOX_VID && VID != MADCATZ_VID) // We just check if it's a xbox receiver using the Vendor ID goto FailUnknownDevice; else if (PID != XBOX_WIRELESS_RECEIVER_PID && PID != XBOX_WIRELESS_RECEIVER_THIRD_PARTY_PID) { -#ifdef DEBUG_USB_HOST +#ifdef DEBUG_USB_HOST_USB_HOST Notify(PSTR("\r\nYou'll need a wireless receiver for this libary to work"), 0x80); #endif goto FailUnknownDevice; @@ -118,7 +118,7 @@ uint8_t XBOXRECV::Init(uint8_t parent, uint8_t port, bool lowspeed) { p->lowspeed = false; addrPool.FreeAddress(bAddress); bAddress = 0; -#ifdef DEBUG_USB_HOST +#ifdef DEBUG_USB_HOST_USB_HOST Notify(PSTR("\r\nsetAddr: "), 0x80); PrintHex (rcode, 0x80); #endif @@ -209,7 +209,7 @@ uint8_t XBOXRECV::Init(uint8_t parent, uint8_t port, bool lowspeed) { if (rcode) goto FailSetConfDescr; -#ifdef DEBUG_USB_HOST +#ifdef DEBUG_USB_HOST_USB_HOST Notify(PSTR("\r\nXbox Wireless Receiver Connected\r\n"), 0x80); #endif XboxReceiverConnected = true; @@ -218,31 +218,31 @@ uint8_t XBOXRECV::Init(uint8_t parent, uint8_t port, bool lowspeed) { /* diagnostic messages */ FailGetDevDescr: -#ifdef DEBUG_USB_HOST +#ifdef DEBUG_USB_HOST_USB_HOST NotifyFailGetDevDescr(); goto Fail; #endif FailSetDevTblEntry: -#ifdef DEBUG_USB_HOST +#ifdef DEBUG_USB_HOST_USB_HOST NotifyFailSetDevTblEntry(); goto Fail; #endif FailSetConfDescr: -#ifdef DEBUG_USB_HOST +#ifdef DEBUG_USB_HOST_USB_HOST NotifyFailSetConfDescr(); #endif goto Fail; FailUnknownDevice: -#ifdef DEBUG_USB_HOST +#ifdef DEBUG_USB_HOST_USB_HOST NotifyFailUnknownDevice(VID,PID); #endif rcode = USB_DEV_CONFIG_ERROR_DEVICE_NOT_SUPPORTED; Fail: -#ifdef DEBUG_USB_HOST +#ifdef DEBUG_USB_HOST_USB_HOST Notify(PSTR("\r\nXbox 360 Init Failed, error code: "), 0x80); NotifyFail(rcode); #endif @@ -304,12 +304,12 @@ void XBOXRECV::readReport(uint8_t controller) { // This report is send when a controller is connected and disconnected if (readBuf[0] == 0x08 && readBuf[1] != Xbox360Connected[controller]) { Xbox360Connected[controller] = readBuf[1]; -#ifdef DEBUG_USB_HOST +#ifdef DEBUG_USB_HOST_USB_HOST Notify(PSTR("Controller "), 0x80); Notify(controller, 0x80); #endif if (Xbox360Connected[controller]) { -#ifdef DEBUG_USB_HOST +#ifdef DEBUG_USB_HOST_USB_HOST char* str = 0; switch (readBuf[1]) { case 0x80: str = PSTR(" as controller\r\n"); @@ -335,7 +335,7 @@ void XBOXRECV::readReport(uint8_t controller) { } setLedOn(led, controller); } -#ifdef DEBUG_USB_HOST +#ifdef DEBUG_USB_HOST_USB_HOST else Notify(PSTR(": disconnected\r\n"), 0x80); #endif diff --git a/XBOXUSB.cpp b/XBOXUSB.cpp index 3b308306..c5ec2786 100644 --- a/XBOXUSB.cpp +++ b/XBOXUSB.cpp @@ -16,7 +16,7 @@ */ #include "XBOXUSB.h" -// To enable serial debugging uncomment "#define DEBUG_USB_HOST" in message.h +// To enable serial debugging uncomment "#define DEBUG_USB_HOST_USB_HOST" in message.h //#define EXTRADEBUG // Uncomment to get even more debugging data //#define PRINTREPORT // Uncomment to print the report send by the Xbox 360 Controller @@ -50,7 +50,7 @@ uint8_t XBOXUSB::Init(uint8_t parent, uint8_t port, bool lowspeed) { #endif // check if address has already been assigned to an instance if (bAddress) { -#ifdef DEBUG_USB_HOST +#ifdef DEBUG_USB_HOST_USB_HOST Notify(PSTR("\r\nAddress in use"), 0x80); #endif return USB_ERROR_CLASS_INSTANCE_ALREADY_IN_USE; @@ -60,14 +60,14 @@ uint8_t XBOXUSB::Init(uint8_t parent, uint8_t port, bool lowspeed) { p = addrPool.GetUsbDevicePtr(0); if (!p) { -#ifdef DEBUG_USB_HOST +#ifdef DEBUG_USB_HOST_USB_HOST Notify(PSTR("\r\nAddress not found"), 0x80); #endif return USB_ERROR_ADDRESS_NOT_FOUND_IN_POOL; } if (!p->epinfo) { -#ifdef DEBUG_USB_HOST +#ifdef DEBUG_USB_HOST_USB_HOST Notify(PSTR("\r\nepinfo is null"), 0x80); #endif return USB_ERROR_EPINFO_IS_NULL; @@ -95,12 +95,12 @@ uint8_t XBOXUSB::Init(uint8_t parent, uint8_t port, bool lowspeed) { if (VID != XBOX_VID && VID != MADCATZ_VID && VID != JOYTECH_VID) // We just check if it's a xbox controller using the Vendor ID goto FailUnknownDevice; if (PID == XBOX_WIRELESS_PID) { -#ifdef DEBUG_USB_HOST +#ifdef DEBUG_USB_HOST_USB_HOST Notify(PSTR("\r\nYou have plugged in a wireless Xbox 360 controller - it doesn't support USB communication"), 0x80); #endif goto FailUnknownDevice; } else if (PID == XBOX_WIRELESS_RECEIVER_PID || PID == XBOX_WIRELESS_RECEIVER_THIRD_PARTY_PID) { -#ifdef DEBUG_USB_HOST +#ifdef DEBUG_USB_HOST_USB_HOST Notify(PSTR("\r\nThis library only supports Xbox 360 controllers via USB"), 0x80); #endif goto FailUnknownDevice; @@ -121,7 +121,7 @@ uint8_t XBOXUSB::Init(uint8_t parent, uint8_t port, bool lowspeed) { p->lowspeed = false; addrPool.FreeAddress(bAddress); bAddress = 0; -#ifdef DEBUG_USB_HOST +#ifdef DEBUG_USB_HOST_USB_HOST Notify(PSTR("\r\nsetAddr: "), 0x80); #endif PrintHex (rcode, 0x80); @@ -173,7 +173,7 @@ uint8_t XBOXUSB::Init(uint8_t parent, uint8_t port, bool lowspeed) { if (rcode) goto FailSetConfDescr; -#ifdef DEBUG_USB_HOST +#ifdef DEBUG_USB_HOST_USB_HOST Notify(PSTR("\r\nXbox 360 Controller Connected\r\n"), 0x80); #endif setLedOn(LED1); @@ -183,30 +183,30 @@ uint8_t XBOXUSB::Init(uint8_t parent, uint8_t port, bool lowspeed) { /* diagnostic messages */ FailGetDevDescr: -#ifdef DEBUG_USB_HOST +#ifdef DEBUG_USB_HOST_USB_HOST NotifyFailGetDevDescr(); goto Fail; #endif FailSetDevTblEntry: -#ifdef DEBUG_USB_HOST +#ifdef DEBUG_USB_HOST_USB_HOST NotifyFailSetDevTblEntry(); goto Fail; #endif FailSetConfDescr: -#ifdef DEBUG_USB_HOST +#ifdef DEBUG_USB_HOST_USB_HOST NotifyFailSetConfDescr(); goto Fail; #endif FailUnknownDevice: -#ifdef DEBUG_USB_HOST +#ifdef DEBUG_USB_HOST_USB_HOST NotifyFailUnknownDevice(VID, PID); #endif rcode = USB_DEV_CONFIG_ERROR_DEVICE_NOT_SUPPORTED; Fail: -#ifdef DEBUG_USB_HOST +#ifdef DEBUG_USB_HOST_USB_HOST Notify(PSTR("\r\nXbox 360 Init Failed, error code: "), 0x80); NotifyFail(rcode); #endif diff --git a/adk.cpp b/adk.cpp index 14d35860..24f22173 100644 --- a/adk.cpp +++ b/adk.cpp @@ -227,43 +227,43 @@ uint8_t ADK::Init(uint8_t parent, uint8_t port, bool lowspeed) { /* diagnostic messages */ FailGetDevDescr: -#ifdef DEBUG_USB_HOST +#ifdef DEBUG_USB_HOST_USB_HOST NotifyFailGetDevDescr(); goto Fail; #endif FailSetDevTblEntry: -#ifdef DEBUG_USB_HOST +#ifdef DEBUG_USB_HOST_USB_HOST NotifyFailSetDevTblEntry(); goto Fail; #endif FailGetConfDescr: -#ifdef DEBUG_USB_HOST +#ifdef DEBUG_USB_HOST_USB_HOST NotifyFailGetConfDescr(); goto Fail; #endif FailSetConfDescr: -#ifdef DEBUG_USB_HOST +#ifdef DEBUG_USB_HOST_USB_HOST NotifyFailSetConfDescr(); goto Fail; #endif FailGetProto: -#ifdef DEBUG_USB_HOST +#ifdef DEBUG_USB_HOST_USB_HOST USBTRACE("\r\ngetProto:"); goto Fail; #endif FailSwAcc: -#ifdef DEBUG_USB_HOST +#ifdef DEBUG_USB_HOST_USB_HOST USBTRACE("\r\nswAcc:"); goto Fail; #endif SwAttempt: -#ifdef DEBUG_USB_HOST +#ifdef DEBUG_USB_HOST_USB_HOST USBTRACE("\r\nAccessory mode switch attempt"); #endif //FailOnInit: diff --git a/cdcacm.cpp b/cdcacm.cpp index 2c75a594..3035bc71 100644 --- a/cdcacm.cpp +++ b/cdcacm.cpp @@ -183,36 +183,36 @@ uint8_t ACM::Init(uint8_t parent, uint8_t port, bool lowspeed) { return 0; FailGetDevDescr: -#ifdef DEBUG_USB_HOST +#ifdef DEBUG_USB_HOST_USB_HOST NotifyFailGetDevDescr(); goto Fail; #endif FailSetDevTblEntry: -#ifdef DEBUG_USB_HOST +#ifdef DEBUG_USB_HOST_USB_HOST NotifyFailSetDevTblEntry(); goto Fail; #endif FailGetConfDescr: -#ifdef DEBUG_USB_HOST +#ifdef DEBUG_USB_HOST_USB_HOST NotifyFailGetConfDescr(); goto Fail; #endif FailSetConfDescr: -#ifdef DEBUG_USB_HOST +#ifdef DEBUG_USB_HOST_USB_HOST NotifyFailSetConfDescr(); goto Fail; #endif FailOnInit: -#ifdef DEBUG_USB_HOST +#ifdef DEBUG_USB_HOST_USB_HOST USBTRACE("OnInit:"); #endif Fail: -#ifdef DEBUG_USB_HOST +#ifdef DEBUG_USB_HOST_USB_HOST NotifyFail(rcode); #endif Release(); diff --git a/cdcftdi.cpp b/cdcftdi.cpp index a8489373..4d0baa8e 100644 --- a/cdcftdi.cpp +++ b/cdcftdi.cpp @@ -178,36 +178,36 @@ uint8_t FTDI::Init(uint8_t parent, uint8_t port, bool lowspeed) { return 0; FailGetDevDescr: -#ifdef DEBUG_USB_HOST +#ifdef DEBUG_USB_HOST_USB_HOST NotifyFailGetDevDescr(); goto Fail; #endif FailSetDevTblEntry: -#ifdef DEBUG_USB_HOST +#ifdef DEBUG_USB_HOST_USB_HOST NotifyFailSetDevTblEntry(); goto Fail; #endif FailGetConfDescr: -#ifdef DEBUG_USB_HOST +#ifdef DEBUG_USB_HOST_USB_HOST NotifyFailGetConfDescr(); goto Fail; #endif FailSetConfDescr: -#ifdef DEBUG_USB_HOST +#ifdef DEBUG_USB_HOST_USB_HOST NotifyFailSetConfDescr(); goto Fail; #endif FailOnInit: -#ifdef DEBUG_USB_HOST +#ifdef DEBUG_USB_HOST_USB_HOST USBTRACE("OnInit:"); #endif Fail: -#ifdef DEBUG_USB_HOST +#ifdef DEBUG_USB_HOST_USB_HOST NotifyFail(rcode); #endif Release(); diff --git a/cdcprolific.cpp b/cdcprolific.cpp index ac4b0f63..53fdee73 100644 --- a/cdcprolific.cpp +++ b/cdcprolific.cpp @@ -155,36 +155,36 @@ uint8_t PL2303::Init(uint8_t parent, uint8_t port, bool lowspeed) { return 0; FailGetDevDescr: -#ifdef DEBUG_USB_HOST +#ifdef DEBUG_USB_HOST_USB_HOST NotifyFailGetDevDescr(); goto Fail; #endif FailSetDevTblEntry: -#ifdef DEBUG_USB_HOST +#ifdef DEBUG_USB_HOST_USB_HOST NotifyFailSetDevTblEntry(); goto Fail; #endif FailGetConfDescr: -#ifdef DEBUG_USB_HOST +#ifdef DEBUG_USB_HOST_USB_HOST NotifyFailGetConfDescr(); goto Fail; #endif FailSetConfDescr: -#ifdef DEBUG_USB_HOST +#ifdef DEBUG_USB_HOST_USB_HOST NotifyFailSetConfDescr(); goto Fail; #endif FailOnInit: -#ifdef DEBUG_USB_HOST +#ifdef DEBUG_USB_HOST_USB_HOST USBTRACE("OnInit:"); #endif Fail: -#ifdef DEBUG_USB_HOST +#ifdef DEBUG_USB_HOST_USB_HOST NotifyFail(rcode); #endif Release(); diff --git a/hidboot.h b/hidboot.h index 797b3a3c..34c46922 100644 --- a/hidboot.h +++ b/hidboot.h @@ -393,42 +393,42 @@ uint8_t HIDBoot::Init(uint8_t parent, uint8_t port, bool lowspeed return 0; FailGetDevDescr: -#ifdef DEBUG_USB_HOST +#ifdef DEBUG_USB_HOST_USB_HOST NotifyFailGetDevDescr(); goto Fail; #endif FailSetDevTblEntry: -#ifdef DEBUG_USB_HOST +#ifdef DEBUG_USB_HOST_USB_HOST NotifyFailSetDevTblEntry(); goto Fail; #endif FailGetConfDescr: -#ifdef DEBUG_USB_HOST +#ifdef DEBUG_USB_HOST_USB_HOST NotifyFailGetConfDescr(); goto Fail; #endif FailSetConfDescr: -#ifdef DEBUG_USB_HOST +#ifdef DEBUG_USB_HOST_USB_HOST NotifyFailSetConfDescr(); goto Fail; #endif FailSetProtocol: -#ifdef DEBUG_USB_HOST +#ifdef DEBUG_USB_HOST_USB_HOST USBTRACE("SetProto:"); goto Fail; #endif FailSetIdle: -#ifdef DEBUG_USB_HOST +#ifdef DEBUG_USB_HOST_USB_HOST USBTRACE("SetIdle:"); #endif Fail: -#ifdef DEBUG_USB_HOST +#ifdef DEBUG_USB_HOST_USB_HOST NotifyFail(rcode); #endif Release(); diff --git a/hiduniversal.cpp b/hiduniversal.cpp index 800839e1..fba0715e 100644 --- a/hiduniversal.cpp +++ b/hiduniversal.cpp @@ -221,37 +221,37 @@ uint8_t HIDUniversal::Init(uint8_t parent, uint8_t port, bool lowspeed) { return 0; FailGetDevDescr: -#ifdef DEBUG_USB_HOST +#ifdef DEBUG_USB_HOST_USB_HOST NotifyFailGetDevDescr(); goto Fail; #endif FailSetDevTblEntry: -#ifdef DEBUG_USB_HOST +#ifdef DEBUG_USB_HOST_USB_HOST NotifyFailSetDevTblEntry(); goto Fail; #endif FailGetConfDescr: -#ifdef DEBUG_USB_HOST +#ifdef DEBUG_USB_HOST_USB_HOST NotifyFailGetConfDescr(); goto Fail; #endif FailSetConfDescr: -#ifdef DEBUG_USB_HOST +#ifdef DEBUG_USB_HOST_USB_HOST NotifyFailSetConfDescr(); goto Fail; #endif FailSetIdle: -#ifdef DEBUG_USB_HOST +#ifdef DEBUG_USB_HOST_USB_HOST USBTRACE("SetIdle:"); #endif Fail: -#ifdef DEBUG_USB_HOST +#ifdef DEBUG_USB_HOST_USB_HOST NotifyFail(rcode); #endif Release(); diff --git a/masstorage.cpp b/masstorage.cpp index 6fae6ce1..d3a89ff2 100644 --- a/masstorage.cpp +++ b/masstorage.cpp @@ -174,7 +174,7 @@ uint8_t BulkOnly::ConfigureDevice(uint8_t parent, uint8_t port, bool lowspeed) { return USB_ERROR_CONFIG_REQUIRES_ADDITIONAL_RESET; FailGetDevDescr: -#ifdef DEBUG_USB_HOST +#ifdef DEBUG_USB_HOST_USB_HOST NotifyFailGetDevDescr(rcode); #endif rcode = USB_ERROR_FailGetDevDescr; @@ -362,42 +362,42 @@ uint8_t BulkOnly::Init(uint8_t parent, uint8_t port, bool lowspeed) { return 0; FailSetConfDescr: -#ifdef DEBUG_USB_HOST +#ifdef DEBUG_USB_HOST_USB_HOST NotifyFailSetConfDescr(); goto Fail; #endif FailOnInit: -#ifdef DEBUG_USB_HOST +#ifdef DEBUG_USB_HOST_USB_HOST USBTRACE("OnInit:"); goto Fail; #endif FailGetMaxLUN: -#ifdef DEBUG_USB_HOST +#ifdef DEBUG_USB_HOST_USB_HOST USBTRACE("GetMaxLUN:"); goto Fail; #endif FailInvalidSectorSize: -#ifdef DEBUG_USB_HOST +#ifdef DEBUG_USB_HOST_USB_HOST USBTRACE("Sector Size is NOT VALID: "); goto Fail; #endif FailSetDevTblEntry: -#ifdef DEBUG_USB_HOST +#ifdef DEBUG_USB_HOST_USB_HOST NotifyFailSetDevTblEntry(); goto Fail; #endif FailGetConfDescr: -#ifdef DEBUG_USB_HOST +#ifdef DEBUG_USB_HOST_USB_HOST NotifyFailGetConfDescr(); #endif Fail: -#ifdef DEBUG_USB_HOST +#ifdef DEBUG_USB_HOST_USB_HOST NotifyFail(rcode); #endif Release(); diff --git a/message.cpp b/message.cpp index 393faa32..568c0642 100644 --- a/message.cpp +++ b/message.cpp @@ -63,7 +63,7 @@ void E_Notify(double d, int lvl) { Serial.flush(); } -#ifdef DEBUG_USB_HOST +#ifdef DEBUG_USB_HOST_USB_HOST void NotifyFailGetDevDescr(void) { Notify(PSTR("\r\ngetDevDescr"), 0x80); } diff --git a/message.h b/message.h index a2fe5f25..bd5b60ff 100644 --- a/message.h +++ b/message.h @@ -18,7 +18,7 @@ e-mail : support@circuitsathome.com #define __MESSAGE_H__ // uncomment to activate -//#define DEBUG_USB_HOST +//#define DEBUG_USB_HOST_USB_HOST #include #include @@ -31,7 +31,7 @@ void E_Notify(uint8_t b, int lvl); void E_NotifyStr(char const * msg, int lvl); void E_Notifyc(char c, int lvl); -#ifdef DEBUG_USB_HOST +#ifdef DEBUG_USB_HOST_USB_HOST #define Notify E_Notify #define NotifyStr E_NotifyStr #define Notifyc E_Notifyc @@ -61,7 +61,7 @@ void NotifyFail(uint8_t rcode); template void ErrorMessage(uint8_t level, char const * msg, ERROR_TYPE rcode = 0) { -#ifdef DEBUG_USB_HOST +#ifdef DEBUG_USB_HOST_USB_HOST Notify(msg, level); Notify(PSTR(": "), level); PrintHex (rcode, level); @@ -71,7 +71,7 @@ void ErrorMessage(uint8_t level, char const * msg, ERROR_TYPE rcode = 0) { template void ErrorMessage(char const * msg, ERROR_TYPE rcode = 0) { -#ifdef DEBUG_USB_HOST +#ifdef DEBUG_USB_HOST_USB_HOST Notify(msg, 0x80); Notify(PSTR(": "), 0x80); PrintHex (rcode, 0x80); diff --git a/printhex.h b/printhex.h index 55a5b19f..3a86d698 100644 --- a/printhex.h +++ b/printhex.h @@ -27,7 +27,7 @@ void E_Notifyc(char c, int lvl); template void PrintHex(T val, int lvl) { -#ifdef DEBUG_USB_HOST +#ifdef DEBUG_USB_HOST_USB_HOST int num_nibbles = sizeof(T) * 2; do { @@ -40,7 +40,7 @@ void PrintHex(T val, int lvl) { template void PrintBin(T val, int lvl) { -#ifdef DEBUG_USB_HOST +#ifdef DEBUG_USB_HOST_USB_HOST for(T mask = (((T) 1) << ((sizeof(T) << 3) - 1)); mask; mask >>= 1) if(val & mask) E_Notifyc('1', lvl); @@ -51,7 +51,7 @@ void PrintBin(T val, int lvl) { template void SerialPrintHex(T val) { -#ifdef DEBUG_USB_HOST +#ifdef DEBUG_USB_HOST_USB_HOST int num_nibbles = sizeof(T) * 2; do { @@ -64,7 +64,7 @@ void SerialPrintHex(T val) { template void PrintHex2(Print *prn, T val) { -#ifdef DEBUG_USB_HOST +#ifdef DEBUG_USB_HOST_USB_HOST T mask = (((T) 1) << (((sizeof(T) << 1) - 1) << 2)); while(mask > 1) { From d27ca9822d78dc10a094b3e76a12fffabc3a6a8c Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Mon, 10 Jun 2013 20:32:09 +0200 Subject: [PATCH 16/20] Fixed path to libraries --- examples/testusbhostFAT/Makefile | 4 ++-- examples/testusbhostFAT/generic_storage | 2 +- examples/testusbhostFAT/xmem2 | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/examples/testusbhostFAT/Makefile b/examples/testusbhostFAT/Makefile index b2a06045..47cc738b 100755 --- a/examples/testusbhostFAT/Makefile +++ b/examples/testusbhostFAT/Makefile @@ -35,8 +35,8 @@ EXTRA_FLAGS += -D DISABLE_SERIAL3 # The following are the libraries used. LIB_DIRS = LIB_DIRS += ../../ -LIB_DIRS += xmem2 -LIB_DIRS += generic_storage +LIB_DIRS += ../testusbhostFAT/xmem2 +LIB_DIRS += ../testusbhostFAT/generic_storage # And finally, the part that brings everything together for you. include Arduino_Makefile_master/_Makefile.master diff --git a/examples/testusbhostFAT/generic_storage b/examples/testusbhostFAT/generic_storage index b87902bf..071b65b9 160000 --- a/examples/testusbhostFAT/generic_storage +++ b/examples/testusbhostFAT/generic_storage @@ -1 +1 @@ -Subproject commit b87902bf7a0934b62f43c2176fb11ea318da8629 +Subproject commit 071b65b923b2656bb1e1b622de5272b4ed9a4996 diff --git a/examples/testusbhostFAT/xmem2 b/examples/testusbhostFAT/xmem2 index b2adf124..8bcf5f90 160000 --- a/examples/testusbhostFAT/xmem2 +++ b/examples/testusbhostFAT/xmem2 @@ -1 +1 @@ -Subproject commit b2adf12413e93de01334efeed0e5d46a73eb17ae +Subproject commit 8bcf5f90f8bd967378b6eeebd7fd943f125fbc18 From 8f9948521d7b16bf24a2bae685d222412c894f54 Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Mon, 10 Jun 2013 20:32:44 +0200 Subject: [PATCH 17/20] Ignore build directory --- .gitignore | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index d5b665b9..7e69f457 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ *.bak *.zip -*.rar \ No newline at end of file +*.rar +build/ \ No newline at end of file From 48345f219a55c43b7f30e4ad8b2e29a05833b3be Mon Sep 17 00:00:00 2001 From: "Andrew J. Kroll" Date: Mon, 10 Jun 2013 14:34:00 -0400 Subject: [PATCH 18/20] finalize refactor DEBUG -> DEBUG_USB_HOST --- BTD.cpp | 84 +++++++++++++++++++------------------- PS3BT.cpp | 34 ++++++++-------- PS3USB.cpp | 30 +++++++------- SPP.cpp | 50 +++++++++++------------ Wii.cpp | 102 +++++++++++++++++++++++------------------------ XBOXRECV.cpp | 30 +++++++------- XBOXUSB.cpp | 26 ++++++------ adk.cpp | 14 +++---- cdcacm.cpp | 12 +++--- cdcftdi.cpp | 12 +++--- cdcprolific.cpp | 12 +++--- hidboot.h | 14 +++---- hiduniversal.cpp | 12 +++--- masstorage.cpp | 16 ++++---- message.cpp | 2 +- message.h | 8 ++-- printhex.h | 8 ++-- 17 files changed, 233 insertions(+), 233 deletions(-) diff --git a/BTD.cpp b/BTD.cpp index 9dc783e2..7b27aacb 100755 --- a/BTD.cpp +++ b/BTD.cpp @@ -16,7 +16,7 @@ */ #include "BTD.h" -// To enable serial debugging uncomment "#define DEBUG_USB_HOST_USB_HOST" in message.h +// To enable serial debugging uncomment "#define DEBUG_USB_HOST" in message.h //#define EXTRADEBUG // Uncomment to get even more debugging data const uint8_t BTD::BTD_CONTROL_PIPE = 0; @@ -58,7 +58,7 @@ uint8_t BTD::Init(uint8_t parent, uint8_t port, bool lowspeed) { #endif // check if address has already been assigned to an instance if (bAddress) { -#ifdef DEBUG_USB_HOST_USB_HOST +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nAddress in use"), 0x80); #endif return USB_ERROR_CLASS_INSTANCE_ALREADY_IN_USE; @@ -68,14 +68,14 @@ uint8_t BTD::Init(uint8_t parent, uint8_t port, bool lowspeed) { p = addrPool.GetUsbDevicePtr(0); if (!p) { -#ifdef DEBUG_USB_HOST_USB_HOST +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nAddress not found"), 0x80); #endif return USB_ERROR_ADDRESS_NOT_FOUND_IN_POOL; } if (!p->epinfo) { -#ifdef DEBUG_USB_HOST_USB_HOST +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nepinfo is null"), 0x80); #endif return USB_ERROR_EPINFO_IS_NULL; @@ -113,7 +113,7 @@ uint8_t BTD::Init(uint8_t parent, uint8_t port, bool lowspeed) { p->lowspeed = false; addrPool.FreeAddress(bAddress); bAddress = 0; -#ifdef DEBUG_USB_HOST_USB_HOST +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nsetAddr: "), 0x80); #endif PrintHex (rcode, 0x80); @@ -145,7 +145,7 @@ uint8_t BTD::Init(uint8_t parent, uint8_t port, bool lowspeed) { if (rcode) goto FailSetConfDescr; -#ifdef DEBUG_USB_HOST_USB_HOST +#ifdef DEBUG_USB_HOST if (PID == PS3_PID || PID == PS3NAVIGATION_PID) { if (PID == PS3_PID) Notify(PSTR("\r\nDualshock 3 Controller Connected"), 0x80); @@ -156,7 +156,7 @@ uint8_t BTD::Init(uint8_t parent, uint8_t port, bool lowspeed) { #endif if (my_bdaddr[0] == 0x00 && my_bdaddr[1] == 0x00 && my_bdaddr[2] == 0x00 && my_bdaddr[3] == 0x00 && my_bdaddr[4] == 0x00 && my_bdaddr[5] == 0x00) { -#ifdef DEBUG_USB_HOST_USB_HOST +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nPlease plug in the dongle before trying to pair with the PS3 Controller\n\rOr set the Bluetooth address in the constructor of the PS3BT class"), 0x80); #endif } else { @@ -164,7 +164,7 @@ uint8_t BTD::Init(uint8_t parent, uint8_t port, bool lowspeed) { setBdaddr(my_bdaddr); // Set internal Bluetooth address else setMoveBdaddr(my_bdaddr); // Set internal Bluetooth address -#ifdef DEBUG_USB_HOST_USB_HOST +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nBluetooth Address was set to: "), 0x80); for (int8_t i = 5; i > 0; i--) { PrintHex (my_bdaddr[i], 0x80); @@ -214,7 +214,7 @@ uint8_t BTD::Init(uint8_t parent, uint8_t port, bool lowspeed) { watingForConnection = false; bPollEnable = true; -#ifdef DEBUG_USB_HOST_USB_HOST +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nBluetooth Dongle Initialized"), 0x80); #endif } @@ -222,37 +222,37 @@ uint8_t BTD::Init(uint8_t parent, uint8_t port, bool lowspeed) { /* diagnostic messages */ FailGetDevDescr: -#ifdef DEBUG_USB_HOST_USB_HOST +#ifdef DEBUG_USB_HOST NotifyFailGetDevDescr(); goto Fail; #endif FailSetDevTblEntry: -#ifdef DEBUG_USB_HOST_USB_HOST +#ifdef DEBUG_USB_HOST NotifyFailSetDevTblEntry(); goto Fail; #endif FailGetConfDescr: -#ifdef DEBUG_USB_HOST_USB_HOST +#ifdef DEBUG_USB_HOST NotifyFailGetConfDescr(); goto Fail; #endif FailSetConfDescr: -#ifdef DEBUG_USB_HOST_USB_HOST +#ifdef DEBUG_USB_HOST NotifyFailSetConfDescr(); #endif goto Fail; FailUnknownDevice: -#ifdef DEBUG_USB_HOST_USB_HOST +#ifdef DEBUG_USB_HOST NotifyFailUnknownDevice(VID, PID); #endif pUsb->setAddr(bAddress, 0, 0); // Reset address rcode = USB_DEV_CONFIG_ERROR_DEVICE_NOT_SUPPORTED; Fail: -#ifdef DEBUG_USB_HOST_USB_HOST +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nBTD Init Failed, error code: "), 0x80); NotifyFail(rcode); #endif @@ -360,7 +360,7 @@ void BTD::HCI_event_task() { case EV_COMMAND_STATUS: if (hcibuf[2]) { // show status on serial if not OK -#ifdef DEBUG_USB_HOST_USB_HOST +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nHCI Command Failed: "), 0x80); PrintHex (hcibuf[2], 0x80); Notify(PSTR(" "), 0x80); @@ -374,7 +374,7 @@ void BTD::HCI_event_task() { case EV_INQUIRY_COMPLETE: if (inquiry_counter >= 5) { inquiry_counter = 0; -#ifdef DEBUG_USB_HOST_USB_HOST +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nCouldn't find Wiimote"), 0x80); #endif connectToWii = false; @@ -468,18 +468,18 @@ void BTD::HCI_event_task() { case EV_PIN_CODE_REQUEST: if (pairWithWii) { -#ifdef DEBUG_USB_HOST_USB_HOST +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nPairing with wiimote"), 0x80); #endif hci_pin_code_request_reply(); } else if (btdPin != NULL) { -#ifdef DEBUG_USB_HOST_USB_HOST +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nBluetooth pin is set too: "), 0x80); NotifyStr(btdPin, 0x80); #endif hci_pin_code_request_reply(); } else { -#ifdef DEBUG_USB_HOST_USB_HOST +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nNo pin was set"), 0x80); #endif hci_pin_code_negative_request_reply(); @@ -487,7 +487,7 @@ void BTD::HCI_event_task() { break; case EV_LINK_KEY_REQUEST: -#ifdef DEBUG_USB_HOST_USB_HOST +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nReceived Key Request"), 0x80); #endif hci_link_key_request_negative_reply(); @@ -495,7 +495,7 @@ void BTD::HCI_event_task() { case EV_AUTHENTICATION_COMPLETE: if (pairWithWii && !connectToWii) { -#ifdef DEBUG_USB_HOST_USB_HOST +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nPairing successful"), 0x80); #endif connectToWii = true; // Only send the ACL data to the Wii service @@ -549,7 +549,7 @@ void BTD::HCI_task() { hci_counter++; if (hci_cmd_complete) { hci_counter = 0; -#ifdef DEBUG_USB_HOST_USB_HOST +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nHCI Reset complete"), 0x80); #endif hci_state = HCI_CLASS_STATE; @@ -558,7 +558,7 @@ void BTD::HCI_task() { hci_num_reset_loops *= 10; if (hci_num_reset_loops > 2000) hci_num_reset_loops = 2000; -#ifdef DEBUG_USB_HOST_USB_HOST +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nNo response to HCI Reset"), 0x80); #endif hci_state = HCI_INIT_STATE; @@ -568,7 +568,7 @@ void BTD::HCI_task() { case HCI_CLASS_STATE: if (hci_cmd_complete) { -#ifdef DEBUG_USB_HOST_USB_HOST +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nWrite class of device"), 0x80); #endif hci_state = HCI_BDADDR_STATE; @@ -578,7 +578,7 @@ void BTD::HCI_task() { case HCI_BDADDR_STATE: if (hci_read_bdaddr_complete) { -#ifdef DEBUG_USB_HOST_USB_HOST +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nLocal Bluetooth Address: "), 0x80); for (int8_t i = 5; i > 0; i--) { PrintHex (my_bdaddr[i], 0x80); @@ -603,7 +603,7 @@ void BTD::HCI_task() { case HCI_SET_NAME_STATE: if (hci_cmd_complete) { -#ifdef DEBUG_USB_HOST_USB_HOST +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nThe name is set to: "), 0x80); NotifyStr(btdName, 0x80); #endif @@ -613,7 +613,7 @@ void BTD::HCI_task() { case HCI_CHECK_WII_SERVICE: if (pairWithWii) { // Check if it should try to connect to a wiimote -#ifdef DEBUG_USB_HOST_USB_HOST +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nStarting inquiry\r\nPress 1 & 2 on the Wiimote\r\nOr press sync if you are using a Wii U Pro Controller"), 0x80); #endif hci_inquiry(); @@ -625,7 +625,7 @@ void BTD::HCI_task() { case HCI_INQUIRY_STATE: if (hci_wii_found) { hci_inquiry_cancel(); // Stop inquiry -#ifdef DEBUG_USB_HOST_USB_HOST +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nWiimote found"), 0x80); Notify(PSTR("\r\nNow just create the instance like so:"), 0x80); Notify(PSTR("\r\nWII Wii(&Btd);"), 0x80); @@ -641,7 +641,7 @@ void BTD::HCI_task() { case HCI_CONNECT_WII_STATE: if (hci_cmd_complete) { -#ifdef DEBUG_USB_HOST_USB_HOST +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nConnecting to Wiimote"), 0x80); #endif hci_connect(); @@ -652,13 +652,13 @@ void BTD::HCI_task() { case HCI_CONNECTED_WII_STATE: if (hci_connect_event) { if (hci_connect_complete) { -#ifdef DEBUG_USB_HOST_USB_HOST +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nConnected to Wiimote"), 0x80); #endif hci_authentication_request(); // This will start the pairing with the wiimote hci_state = HCI_SCANNING_STATE; } else { -#ifdef DEBUG_USB_HOST_USB_HOST +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nTrying to connect one more time..."), 0x80); #endif hci_connect(); // Try to connect one more time @@ -668,7 +668,7 @@ void BTD::HCI_task() { case HCI_SCANNING_STATE: if (!connectToWii && !pairWithWii) { -#ifdef DEBUG_USB_HOST_USB_HOST +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nWait For Incoming Connection Request"), 0x80); #endif hci_write_scan_enable(); @@ -680,7 +680,7 @@ void BTD::HCI_task() { case HCI_CONNECT_IN_STATE: if (hci_incoming_connect_request) { watingForConnection = false; -#ifdef DEBUG_USB_HOST_USB_HOST +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nIncoming Connection Request"), 0x80); #endif hci_remote_name(); @@ -691,7 +691,7 @@ void BTD::HCI_task() { case HCI_REMOTE_NAME_STATE: if (hci_remote_name_complete) { -#ifdef DEBUG_USB_HOST_USB_HOST +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nRemote Name: "), 0x80); for (uint8_t i = 0; i < 30; i++) { if (remote_name[i] == NULL) @@ -701,16 +701,16 @@ void BTD::HCI_task() { #endif if (strncmp((const char*)remote_name, "Nintendo", 8) == 0) { incomingWii = true; -#ifdef DEBUG_USB_HOST_USB_HOST +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nWiimote is connecting"), 0x80); #endif if (strncmp((const char*)remote_name, "Nintendo RVL-CNT-01-TR", 22) == 0) { -#ifdef DEBUG_USB_HOST_USB_HOST +#ifdef DEBUG_USB_HOST Notify(PSTR(" with Motion Plus Inside"), 0x80); #endif motionPlusInside = true; } else if (strncmp((const char*)remote_name, "Nintendo RVL-CNT-01-UC", 22) == 0) { -#ifdef DEBUG_USB_HOST_USB_HOST +#ifdef DEBUG_USB_HOST Notify(PSTR(" - Wii U Pro Controller"), 0x80); #endif motionPlusInside = true; @@ -731,7 +731,7 @@ void BTD::HCI_task() { case HCI_CONNECTED_STATE: if (hci_connect_complete) { -#ifdef DEBUG_USB_HOST_USB_HOST +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nConnected to Device: "), 0x80); for (int8_t i = 5; i > 0; i--) { PrintHex (disc_bdaddr[i], 0x80); @@ -759,7 +759,7 @@ void BTD::HCI_task() { case HCI_DISCONNECT_STATE: if (hci_disconnect_complete) { -#ifdef DEBUG_USB_HOST_USB_HOST +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nHCI Disconnected from Device"), 0x80); #endif hci_event_flag = 0; // Clear all flags @@ -957,7 +957,7 @@ void BTD::hci_pin_code_request_reply() { if (pairWithWii) { hcibuf[9] = 6; // Pin length is the length of the Bluetooth address if (wiiUProController) { -#ifdef DEBUG_USB_HOST_USB_HOST +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nParing with Wii U Pro Controller"), 0x80); #endif for (uint8_t i = 0; i < 6; i++) @@ -1083,7 +1083,7 @@ void BTD::L2CAP_Command(uint16_t handle, uint8_t* data, uint8_t nbytes, uint8_t uint8_t rcode = pUsb->outTransfer(bAddress, epInfo[ BTD_DATAOUT_PIPE ].epAddr, (8 + nbytes), buf); if (rcode) { delay(100); // This small delay prevents it from overflowing if it fails -#ifdef DEBUG_USB_HOST_USB_HOST +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nError sending L2CAP message: 0x"), 0x80); PrintHex (rcode, 0x80); Notify(PSTR(" - Channel ID: "), 0x80); diff --git a/PS3BT.cpp b/PS3BT.cpp index 72d654c1..26ad8772 100644 --- a/PS3BT.cpp +++ b/PS3BT.cpp @@ -16,7 +16,7 @@ */ #include "PS3BT.h" -// To enable serial debugging uncomment "#define DEBUG_USB_HOST_USB_HOST" in message.h +// To enable serial debugging uncomment "#define DEBUG_USB_HOST" in message.h //#define EXTRADEBUG // Uncomment to get even more debugging data //#define PRINTREPORT // Uncomment to print the report send by the PS3 Controllers @@ -255,7 +255,7 @@ void PS3BT::ACLData(uint8_t* ACLData) { l2cap_state = L2CAP_WAIT; for (uint8_t i = 0; i < 30; i++) remote_name[i] = pBtd->remote_name[i]; // Store the remote name for the connection -#ifdef DEBUG_USB_HOST_USB_HOST +#ifdef DEBUG_USB_HOST if (pBtd->hci_version < 3) { // Check the HCI Version of the Bluetooth dongle Notify(PSTR("\r\nYour dongle may not support reading the analog buttons, sensors and status\r\nYour HCI Version is: "), 0x80); Notify(pBtd->hci_version, 0x80); @@ -270,7 +270,7 @@ void PS3BT::ACLData(uint8_t* ACLData) { l2capinbuf[i] = ACLData[i]; if ((l2capinbuf[6] | (l2capinbuf[7] << 8)) == 0x0001) { //l2cap_control - Channel ID for ACL-U if (l2capinbuf[8] == L2CAP_CMD_COMMAND_REJECT) { -#ifdef DEBUG_USB_HOST_USB_HOST +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nL2CAP Command Rejected - Reason: "), 0x80); PrintHex (l2capinbuf[13], 0x80); Notify(PSTR(" "), 0x80); @@ -330,14 +330,14 @@ void PS3BT::ACLData(uint8_t* ACLData) { } } else if (l2capinbuf[8] == L2CAP_CMD_DISCONNECT_REQUEST) { if (l2capinbuf[12] == control_dcid[0] && l2capinbuf[13] == control_dcid[1]) { -#ifdef DEBUG_USB_HOST_USB_HOST +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nDisconnect Request: Control Channel"), 0x80); #endif identifier = l2capinbuf[9]; pBtd->l2cap_disconnection_response(hci_handle, identifier, control_dcid, control_scid); Reset(); } else if (l2capinbuf[12] == interrupt_dcid[0] && l2capinbuf[13] == interrupt_dcid[1]) { -#ifdef DEBUG_USB_HOST_USB_HOST +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nDisconnect Request: Interrupt Channel"), 0x80); #endif identifier = l2capinbuf[9]; @@ -397,7 +397,7 @@ void PS3BT::L2CAP_task() { switch (l2cap_state) { case L2CAP_WAIT: if (l2cap_connection_request_control_flag) { -#ifdef DEBUG_USB_HOST_USB_HOST +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nHID Control Incoming Connection Request"), 0x80); #endif pBtd->l2cap_connection_response(hci_handle, identifier, control_dcid, control_scid, PENDING); @@ -411,7 +411,7 @@ void PS3BT::L2CAP_task() { break; case L2CAP_CONTROL_REQUEST: if (l2cap_config_request_control_flag) { -#ifdef DEBUG_USB_HOST_USB_HOST +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nHID Control Configuration Request"), 0x80); #endif pBtd->l2cap_config_response(hci_handle, identifier, control_scid); @@ -421,7 +421,7 @@ void PS3BT::L2CAP_task() { case L2CAP_CONTROL_SUCCESS: if (l2cap_config_success_control_flag) { -#ifdef DEBUG_USB_HOST_USB_HOST +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nHID Control Successfully Configured"), 0x80); #endif l2cap_state = L2CAP_INTERRUPT_SETUP; @@ -429,7 +429,7 @@ void PS3BT::L2CAP_task() { break; case L2CAP_INTERRUPT_SETUP: if (l2cap_connection_request_interrupt_flag) { -#ifdef DEBUG_USB_HOST_USB_HOST +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nHID Interrupt Incoming Connection Request"), 0x80); #endif pBtd->l2cap_connection_response(hci_handle, identifier, interrupt_dcid, interrupt_scid, PENDING); @@ -444,7 +444,7 @@ void PS3BT::L2CAP_task() { break; case L2CAP_INTERRUPT_REQUEST: if (l2cap_config_request_interrupt_flag) { -#ifdef DEBUG_USB_HOST_USB_HOST +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nHID Interrupt Configuration Request"), 0x80); #endif pBtd->l2cap_config_response(hci_handle, identifier, interrupt_scid); @@ -453,7 +453,7 @@ void PS3BT::L2CAP_task() { break; case L2CAP_INTERRUPT_SUCCESS: if (l2cap_config_success_interrupt_flag) { -#ifdef DEBUG_USB_HOST_USB_HOST +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nHID Interrupt Successfully Configured"), 0x80); #endif if (remote_name[0] == 'M') { // First letter in Motion Controller ('M') @@ -473,7 +473,7 @@ void PS3BT::L2CAP_task() { case L2CAP_INTERRUPT_DISCONNECT: if (l2cap_disconnect_response_interrupt_flag) { -#ifdef DEBUG_USB_HOST_USB_HOST +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nDisconnected Interrupt Channel"), 0x80); #endif identifier++; @@ -484,7 +484,7 @@ void PS3BT::L2CAP_task() { case L2CAP_CONTROL_DISCONNECT: if (l2cap_disconnect_response_control_flag) { -#ifdef DEBUG_USB_HOST_USB_HOST +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nDisconnected Control Channel"), 0x80); #endif pBtd->hci_disconnect(hci_handle); @@ -517,20 +517,20 @@ void PS3BT::Run() { if (millis() - timer > 1000) { // loop 1 second before sending the command if (remote_name[0] == 'P') { // First letter in PLAYSTATION(R)3 Controller ('P') setLedOn(LED1); -#ifdef DEBUG_USB_HOST_USB_HOST +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nDualshock 3 Controller Enabled\r\n"), 0x80); #endif PS3Connected = true; } else if (remote_name[0] == 'N') { // First letter in Navigation Controller ('N') setLedOn(LED1); // This just turns LED constantly on, on the Navigation controller -#ifdef DEBUG_USB_HOST_USB_HOST +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nNavigation Controller Enabled\r\n"), 0x80); #endif PS3NavigationConnected = true; } else if (remote_name[0] == 'M') { // First letter in Motion Controller ('M') moveSetBulb(Red); timerBulbRumble = millis(); -#ifdef DEBUG_USB_HOST_USB_HOST +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nMotion Controller Enabled\r\n"), 0x80); #endif PS3MoveConnected = true; @@ -650,7 +650,7 @@ void PS3BT::moveSetBulb(Colors color) { //Use this to set the Color using the pr } void PS3BT::moveSetRumble(uint8_t rumble) { -#ifdef DEBUG_USB_HOST_USB_HOST +#ifdef DEBUG_USB_HOST if (rumble < 64 && rumble != 0) // The rumble value has to at least 64, or approximately 25% (64/255*100) Notify(PSTR("\r\nThe rumble value has to at least 64, or approximately 25%"), 0x80); #endif diff --git a/PS3USB.cpp b/PS3USB.cpp index e6a884a3..9b028f68 100644 --- a/PS3USB.cpp +++ b/PS3USB.cpp @@ -16,7 +16,7 @@ */ #include "PS3USB.h" -// To enable serial debugging uncomment "#define DEBUG_USB_HOST_USB_HOST" in message.h +// To enable serial debugging uncomment "#define DEBUG_USB_HOST" in message.h //#define EXTRADEBUG // Uncomment to get even more debugging data //#define PRINTREPORT // Uncomment to print the report send by the PS3 Controllers @@ -58,7 +58,7 @@ uint8_t PS3USB::Init(uint8_t parent, uint8_t port, bool lowspeed) { #endif // check if address has already been assigned to an instance if (bAddress) { -#ifdef DEBUG_USB_HOST_USB_HOST +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nAddress in use"), 0x80); #endif return USB_ERROR_CLASS_INSTANCE_ALREADY_IN_USE; @@ -68,14 +68,14 @@ uint8_t PS3USB::Init(uint8_t parent, uint8_t port, bool lowspeed) { p = addrPool.GetUsbDevicePtr(0); if (!p) { -#ifdef DEBUG_USB_HOST_USB_HOST +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nAddress not found"), 0x80); #endif return USB_ERROR_ADDRESS_NOT_FOUND_IN_POOL; } if (!p->epinfo) { -#ifdef DEBUG_USB_HOST_USB_HOST +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nepinfo is null"), 0x80); #endif return USB_ERROR_EPINFO_IS_NULL; @@ -118,7 +118,7 @@ uint8_t PS3USB::Init(uint8_t parent, uint8_t port, bool lowspeed) { p->lowspeed = false; addrPool.FreeAddress(bAddress); bAddress = 0; -#ifdef DEBUG_USB_HOST_USB_HOST +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nsetAddr: "), 0x80); #endif PrintHex (rcode, 0x80); @@ -173,12 +173,12 @@ uint8_t PS3USB::Init(uint8_t parent, uint8_t port, bool lowspeed) { if (PID == PS3_PID || PID == PS3NAVIGATION_PID) { if (PID == PS3_PID) { -#ifdef DEBUG_USB_HOST_USB_HOST +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nDualshock 3 Controller Connected"), 0x80); #endif PS3Connected = true; } else { // must be a navigation controller -#ifdef DEBUG_USB_HOST_USB_HOST +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nNavigation Controller Connected"), 0x80); #endif PS3NavigationConnected = true; @@ -195,7 +195,7 @@ uint8_t PS3USB::Init(uint8_t parent, uint8_t port, bool lowspeed) { for (uint8_t i = 6; i < 10; i++) readBuf[i] = 0x7F; // Set the analog joystick values to center position } else { // must be a Motion controller -#ifdef DEBUG_USB_HOST_USB_HOST +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nMotion Controller Connected"), 0x80); #endif PS3MoveConnected = true; @@ -205,7 +205,7 @@ uint8_t PS3USB::Init(uint8_t parent, uint8_t port, bool lowspeed) { writeBuf[0] = 0x02; // Set report ID, this is needed for Move commands to work } -#ifdef DEBUG_USB_HOST_USB_HOST +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nBluetooth Address was set to: "), 0x80); for (int8_t i = 5; i > 0; i--) { PrintHex (my_bdaddr[i], 0x80); @@ -221,29 +221,29 @@ uint8_t PS3USB::Init(uint8_t parent, uint8_t port, bool lowspeed) { /* diagnostic messages */ FailGetDevDescr: -#ifdef DEBUG_USB_HOST_USB_HOST +#ifdef DEBUG_USB_HOST NotifyFailGetDevDescr(); goto Fail; #endif FailSetDevTblEntry: -#ifdef DEBUG_USB_HOST_USB_HOST +#ifdef DEBUG_USB_HOST NotifyFailSetDevTblEntry(); goto Fail; #endif FailSetConfDescr: -#ifdef DEBUG_USB_HOST_USB_HOST +#ifdef DEBUG_USB_HOST NotifyFailSetConfDescr(); #endif goto Fail; FailUnknownDevice: -#ifdef DEBUG_USB_HOST_USB_HOST +#ifdef DEBUG_USB_HOST NotifyFailUnknownDevice(VID, PID); #endif rcode = USB_DEV_CONFIG_ERROR_DEVICE_NOT_SUPPORTED; Fail: -#ifdef DEBUG_USB_HOST_USB_HOST +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nPS3 Init Failed, error code: "), 0x80); NotifyFail(rcode); #endif @@ -513,7 +513,7 @@ void PS3USB::moveSetBulb(Colors color) { //Use this to set the Color using the p } void PS3USB::moveSetRumble(uint8_t rumble) { -#ifdef DEBUG_USB_HOST_USB_HOST +#ifdef DEBUG_USB_HOST if (rumble < 64 && rumble != 0) // The rumble value has to at least 64, or approximately 25% (64/255*100) Notify(PSTR("\r\nThe rumble value has to at least 64, or approximately 25%"), 0x80); #endif diff --git a/SPP.cpp b/SPP.cpp index 243b7338..ff12d0b5 100644 --- a/SPP.cpp +++ b/SPP.cpp @@ -16,7 +16,7 @@ */ #include "SPP.h" -// To enable serial debugging uncomment "#define DEBUG_USB_HOST_USB_HOST" in message.h +// To enable serial debugging uncomment "#define DEBUG_USB_HOST" in message.h //#define EXTRADEBUG // Uncomment to get even more debugging data //#define PRINTREPORT // Uncomment to print the report sent to the Arduino @@ -99,7 +99,7 @@ void SPP::ACLData(uint8_t* l2capinbuf) { if (((l2capinbuf[0] | (l2capinbuf[1] << 8)) == (hci_handle | 0x2000))) { // acl_handle_ok if ((l2capinbuf[6] | (l2capinbuf[7] << 8)) == 0x0001) { //l2cap_control - Channel ID for ACL-U if (l2capinbuf[8] == L2CAP_CMD_COMMAND_REJECT) { -#ifdef DEBUG_USB_HOST_USB_HOST +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nL2CAP Command Rejected - Reason: "), 0x80); PrintHex (l2capinbuf[13], 0x80); Notify(PSTR(" "), 0x80); @@ -178,7 +178,7 @@ void SPP::ACLData(uint8_t* l2capinbuf) { l2cap_event_flag |= L2CAP_FLAG_DISCONNECT_RESPONSE; } } else if (l2capinbuf[8] == L2CAP_CMD_INFORMATION_REQUEST) { -#ifdef DEBUG_USB_HOST_USB_HOST +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nInformation request"), 0x80); #endif identifier = l2capinbuf[9]; @@ -252,7 +252,7 @@ void SPP::ACLData(uint8_t* l2capinbuf) { PrintHex (rfcommPfBit, 0x80); #endif if (rfcommChannelType == RFCOMM_DISC) { -#ifdef DEBUG_USB_HOST_USB_HOST +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nReceived Disconnect RFCOMM Command on channel: "), 0x80); PrintHex (rfcommChannel >> 3, 0x80); #endif @@ -282,7 +282,7 @@ void SPP::ACLData(uint8_t* l2capinbuf) { Notifyc(l2capinbuf[i + 11 + offset], 0x80); #endif } else if (rfcommChannelType == RFCOMM_UIH && l2capinbuf[11] == BT_RFCOMM_RPN_CMD) { // UIH Remote Port Negotiation Command -#ifdef DEBUG_USB_HOST_USB_HOST +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nReceived UIH Remote Port Negotiation Command"), 0x80); #endif rfcommbuf[0] = BT_RFCOMM_RPN_RSP; // Command @@ -297,7 +297,7 @@ void SPP::ACLData(uint8_t* l2capinbuf) { rfcommbuf[9] = l2capinbuf[20]; // Number of Frames sendRfcomm(rfcommChannel, rfcommDirection, 0, RFCOMM_UIH, rfcommPfBit, rfcommbuf, 0x0A); // UIH Remote Port Negotiation Response } else if (rfcommChannelType == RFCOMM_UIH && l2capinbuf[11] == BT_RFCOMM_MSC_CMD) { // UIH Modem Status Command -#ifdef DEBUG_USB_HOST_USB_HOST +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nSend UIH Modem Status Response"), 0x80); #endif rfcommbuf[0] = BT_RFCOMM_MSC_RSP; // UIH Modem Status Response @@ -308,12 +308,12 @@ void SPP::ACLData(uint8_t* l2capinbuf) { } } else { if (rfcommChannelType == RFCOMM_SABM) { // SABM Command - this is sent twice: once for channel 0 and then for the channel to establish -#ifdef DEBUG_USB_HOST_USB_HOST +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nReceived SABM Command"), 0x80); #endif sendRfcomm(rfcommChannel, rfcommDirection, rfcommCommandResponse, RFCOMM_UA, rfcommPfBit, rfcommbuf, 0x00); // UA Command } else if (rfcommChannelType == RFCOMM_UIH && l2capinbuf[11] == BT_RFCOMM_PN_CMD) { // UIH Parameter Negotiation Command -#ifdef DEBUG_USB_HOST_USB_HOST +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nReceived UIH Parameter Negotiation Command"), 0x80); #endif rfcommbuf[0] = BT_RFCOMM_PN_RSP; // UIH Parameter Negotiation Response @@ -328,7 +328,7 @@ void SPP::ACLData(uint8_t* l2capinbuf) { rfcommbuf[9] = 0x00; // Number of Frames sendRfcomm(rfcommChannel, rfcommDirection, 0, RFCOMM_UIH, rfcommPfBit, rfcommbuf, 0x0A); } else if (rfcommChannelType == RFCOMM_UIH && l2capinbuf[11] == BT_RFCOMM_MSC_CMD) { // UIH Modem Status Command -#ifdef DEBUG_USB_HOST_USB_HOST +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nSend UIH Modem Status Response"), 0x80); #endif rfcommbuf[0] = BT_RFCOMM_MSC_RSP; // UIH Modem Status Response @@ -338,7 +338,7 @@ void SPP::ACLData(uint8_t* l2capinbuf) { sendRfcomm(rfcommChannel, rfcommDirection, 0, RFCOMM_UIH, rfcommPfBit, rfcommbuf, 0x04); delay(1); -#ifdef DEBUG_USB_HOST_USB_HOST +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nSend UIH Modem Status Command"), 0x80); #endif rfcommbuf[0] = BT_RFCOMM_MSC_CMD; // UIH Modem Status Command @@ -349,7 +349,7 @@ void SPP::ACLData(uint8_t* l2capinbuf) { sendRfcomm(rfcommChannel, rfcommDirection, 0, RFCOMM_UIH, rfcommPfBit, rfcommbuf, 0x04); } else if (rfcommChannelType == RFCOMM_UIH && l2capinbuf[11] == BT_RFCOMM_MSC_RSP) { // UIH Modem Status Response if (!creditSent) { -#ifdef DEBUG_USB_HOST_USB_HOST +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nSend UIH Command with credit"), 0x80); #endif sendRfcommCredit(rfcommChannelConnection, rfcommDirection, 0, RFCOMM_UIH, 0x10, sizeof (rfcommDataBuffer)); // Send credit @@ -358,11 +358,11 @@ void SPP::ACLData(uint8_t* l2capinbuf) { waitForLastCommand = true; } } else if (rfcommChannelType == RFCOMM_UIH && l2capinbuf[10] == 0x01) { // UIH Command with credit -#ifdef DEBUG_USB_HOST_USB_HOST +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nReceived UIH Command with credit"), 0x80); #endif } else if (rfcommChannelType == RFCOMM_UIH && l2capinbuf[11] == BT_RFCOMM_RPN_CMD) { // UIH Remote Port Negotiation Command -#ifdef DEBUG_USB_HOST_USB_HOST +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nReceived UIH Remote Port Negotiation Command"), 0x80); #endif rfcommbuf[0] = BT_RFCOMM_RPN_RSP; // Command @@ -376,7 +376,7 @@ void SPP::ACLData(uint8_t* l2capinbuf) { rfcommbuf[8] = l2capinbuf[19]; // MaxRatransm. rfcommbuf[9] = l2capinbuf[20]; // Number of Frames sendRfcomm(rfcommChannel, rfcommDirection, 0, RFCOMM_UIH, rfcommPfBit, rfcommbuf, 0x0A); // UIH Remote Port Negotiation Response -#ifdef DEBUG_USB_HOST_USB_HOST +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nRFCOMM Connection is now established\r\n"), 0x80); #endif waitForLastCommand = false; @@ -384,7 +384,7 @@ void SPP::ACLData(uint8_t* l2capinbuf) { connected = true; // The RFCOMM channel is now established sppIndex = 0; } -#ifdef DEBUG_USB_HOST_USB_HOST +#ifdef DEBUG_USB_HOST else if (rfcommChannelType != RFCOMM_DISC) { Notify(PSTR("\r\nUnsupported RFCOMM Data - ChannelType: "), 0x80); PrintHex (rfcommChannelType, 0x80); @@ -409,7 +409,7 @@ void SPP::ACLData(uint8_t* l2capinbuf) { void SPP::Run() { if (waitForLastCommand && (millis() - timer) > 100) { // We will only wait 100ms and see if the UIH Remote Port Negotiation Command is send, as some deviced don't send it -#ifdef DEBUG_USB_HOST_USB_HOST +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nRFCOMM Connection is now established - Automatic\r\n"), 0x80); #endif creditSent = false; @@ -425,7 +425,7 @@ void SPP::SDP_task() { case L2CAP_SDP_WAIT: if (l2cap_connection_request_sdp_flag) { l2cap_event_flag &= ~L2CAP_FLAG_CONNECTION_SDP_REQUEST; // Clear flag -#ifdef DEBUG_USB_HOST_USB_HOST +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nSDP Incoming Connection Request"), 0x80); #endif pBtd->l2cap_connection_response(hci_handle, identifier, sdp_dcid, sdp_scid, PENDING); @@ -440,7 +440,7 @@ void SPP::SDP_task() { case L2CAP_SDP_REQUEST: if (l2cap_config_request_sdp_flag) { l2cap_event_flag &= ~L2CAP_FLAG_CONFIG_SDP_REQUEST; // Clear flag -#ifdef DEBUG_USB_HOST_USB_HOST +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nSDP Configuration Request"), 0x80); #endif pBtd->l2cap_config_response(hci_handle, identifier, sdp_scid); @@ -450,7 +450,7 @@ void SPP::SDP_task() { case L2CAP_SDP_SUCCESS: if (l2cap_config_success_sdp_flag) { l2cap_event_flag &= ~L2CAP_FLAG_CONFIG_SDP_SUCCESS; // Clear flag -#ifdef DEBUG_USB_HOST_USB_HOST +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nSDP Successfully Configured"), 0x80); #endif firstMessage = true; // Reset bool @@ -462,7 +462,7 @@ void SPP::SDP_task() { if (l2cap_disconnect_request_sdp_flag) { l2cap_event_flag &= ~L2CAP_FLAG_DISCONNECT_SDP_REQUEST; // Clear flag SDPConnected = false; -#ifdef DEBUG_USB_HOST_USB_HOST +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nDisconnected SDP Channel"), 0x80); #endif pBtd->l2cap_disconnection_response(hci_handle, identifier, sdp_dcid, sdp_scid); @@ -472,7 +472,7 @@ void SPP::SDP_task() { break; case L2CAP_DISCONNECT_RESPONSE: // This is for both disconnection response from the RFCOMM and SDP channel if they were connected if (l2cap_disconnect_response_flag) { -#ifdef DEBUG_USB_HOST_USB_HOST +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nDisconnected L2CAP Connection"), 0x80); #endif RFCOMMConnected = false; @@ -492,7 +492,7 @@ void SPP::RFCOMM_task() { case L2CAP_RFCOMM_WAIT: if (l2cap_connection_request_rfcomm_flag) { l2cap_event_flag &= ~L2CAP_FLAG_CONNECTION_RFCOMM_REQUEST; // Clear flag -#ifdef DEBUG_USB_HOST_USB_HOST +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nRFCOMM Incoming Connection Request"), 0x80); #endif pBtd->l2cap_connection_response(hci_handle, identifier, rfcomm_dcid, rfcomm_scid, PENDING); @@ -507,7 +507,7 @@ void SPP::RFCOMM_task() { case L2CAP_RFCOMM_REQUEST: if (l2cap_config_request_rfcomm_flag) { l2cap_event_flag &= ~L2CAP_FLAG_CONFIG_RFCOMM_REQUEST; // Clear flag -#ifdef DEBUG_USB_HOST_USB_HOST +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nRFCOMM Configuration Request"), 0x80); #endif pBtd->l2cap_config_response(hci_handle, identifier, rfcomm_scid); @@ -517,7 +517,7 @@ void SPP::RFCOMM_task() { case L2CAP_RFCOMM_SUCCESS: if (l2cap_config_success_rfcomm_flag) { l2cap_event_flag &= ~L2CAP_FLAG_CONFIG_RFCOMM_SUCCESS; // Clear flag -#ifdef DEBUG_USB_HOST_USB_HOST +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nRFCOMM Successfully Configured"), 0x80); #endif rfcommAvailable = 0; // Reset number of bytes available @@ -531,7 +531,7 @@ void SPP::RFCOMM_task() { l2cap_event_flag &= ~L2CAP_FLAG_DISCONNECT_RFCOMM_REQUEST; // Clear flag RFCOMMConnected = false; connected = false; -#ifdef DEBUG_USB_HOST_USB_HOST +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nDisconnected RFCOMM Channel"), 0x80); #endif pBtd->l2cap_disconnection_response(hci_handle, identifier, rfcomm_dcid, rfcomm_scid); diff --git a/Wii.cpp b/Wii.cpp index e638d3ef..f259bfdb 100755 --- a/Wii.cpp +++ b/Wii.cpp @@ -20,7 +20,7 @@ */ #include "Wii.h" -// To enable serial debugging uncomment "#define DEBUG_USB_HOST_USB_HOST" in message.h +// To enable serial debugging uncomment "#define DEBUG_USB_HOST" in message.h //#define EXTRADEBUG // Uncomment to get even more debugging data //#define PRINTREPORT // Uncomment to print the report send by the Wii controllers @@ -118,7 +118,7 @@ void WII::Reset() { void WII::disconnect() { // Use this void to disconnect any of the controllers if (motionPlusConnected && !pBtd->motionPlusInside) { // Disable the Motion Plus extension -#ifdef DEBUG_USB_HOST_USB_HOST +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nDeactivating Motion Plus"), 0x80); #endif initExtension1(); // This will disable the Motion Plus extension @@ -144,7 +144,7 @@ void WII::ACLData(uint8_t* l2capinbuf) { if ((l2capinbuf[0] | (l2capinbuf[1] << 8)) == (hci_handle | 0x2000)) { // acl_handle_ok or it's a new connection if ((l2capinbuf[6] | (l2capinbuf[7] << 8)) == 0x0001) { //l2cap_control - Channel ID for ACL-U if (l2capinbuf[8] == L2CAP_CMD_COMMAND_REJECT) { -#ifdef DEBUG_USB_HOST_USB_HOST +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nL2CAP Command Rejected - Reason: "), 0x80); PrintHex (l2capinbuf[13], 0x80); Notify(PSTR(" "), 0x80); @@ -220,14 +220,14 @@ void WII::ACLData(uint8_t* l2capinbuf) { } } else if (l2capinbuf[8] == L2CAP_CMD_DISCONNECT_REQUEST) { if (l2capinbuf[12] == control_dcid[0] && l2capinbuf[13] == control_dcid[1]) { -#ifdef DEBUG_USB_HOST_USB_HOST +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nDisconnect Request: Control Channel"), 0x80); #endif identifier = l2capinbuf[9]; pBtd->l2cap_disconnection_response(hci_handle, identifier, control_dcid, control_scid); Reset(); } else if (l2capinbuf[12] == interrupt_dcid[0] && l2capinbuf[13] == interrupt_dcid[1]) { -#ifdef DEBUG_USB_HOST_USB_HOST +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nDisconnect Request: Interrupt Channel"), 0x80); #endif identifier = l2capinbuf[9]; @@ -294,12 +294,12 @@ void WII::ACLData(uint8_t* l2capinbuf) { wiiState = l2capinbuf[12]; // (0x01: Battery is nearly empty), (0x02: An Extension Controller is connected), (0x04: Speaker enabled), (0x08: IR enabled), (0x10: LED1, 0x20: LED2, 0x40: LED3, 0x80: LED4) batteryLevel = l2capinbuf[15]; // Update battery level if (l2capinbuf[12] & 0x01) { -#ifdef DEBUG_USB_HOST_USB_HOST +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nWARNING: Battery is nearly empty"), 0x80); #endif } if (l2capinbuf[12] & 0x02) { // Check if a extension is connected -#ifdef DEBUG_USB_HOST_USB_HOST +#ifdef DEBUG_USB_HOST if (!unknownExtensionConnected) Notify(PSTR("\r\nExtension connected"), 0x80); #endif @@ -309,11 +309,11 @@ void WII::ACLData(uint8_t* l2capinbuf) { #endif setReportMode(false, 0x35); // Also read the extension } else { -#ifdef DEBUG_USB_HOST_USB_HOST +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nExtension disconnected"), 0x80); #endif if (motionPlusConnected) { -#ifdef DEBUG_USB_HOST_USB_HOST +#ifdef DEBUG_USB_HOST Notify(PSTR(" - from Motion Plus"), 0x80); #endif l2cap_event_flag &= ~WII_FLAG_NUNCHUCK_CONNECTED; @@ -321,7 +321,7 @@ void WII::ACLData(uint8_t* l2capinbuf) { nunchuckConnected = false; //else if(classicControllerConnected) } else if (nunchuckConnected) { -#ifdef DEBUG_USB_HOST_USB_HOST +#ifdef DEBUG_USB_HOST Notify(PSTR(" - Nunchuck"), 0x80); #endif nunchuckConnected = false; // It must be the Nunchuck controller then @@ -337,40 +337,40 @@ void WII::ACLData(uint8_t* l2capinbuf) { if ((l2capinbuf[12] & 0x0F) == 0) { // No error // See: http://wiibrew.org/wiki/Wiimote/Extension_Controllers if (l2capinbuf[16] == 0x00 && l2capinbuf[17] == 0xA4 && l2capinbuf[18] == 0x20 && l2capinbuf[19] == 0x00 && l2capinbuf[20] == 0x00) { -#ifdef DEBUG_USB_HOST_USB_HOST +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nNunchuck connected"), 0x80); #endif l2cap_event_flag |= WII_FLAG_NUNCHUCK_CONNECTED; } else if (l2capinbuf[16] == 0x00 && (l2capinbuf[17] == 0xA6 || l2capinbuf[17] == 0xA4) && l2capinbuf[18] == 0x20 && l2capinbuf[19] == 0x00 && l2capinbuf[20] == 0x05) { -#ifdef DEBUG_USB_HOST_USB_HOST +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nMotion Plus connected"), 0x80); #endif l2cap_event_flag |= WII_FLAG_MOTION_PLUS_CONNECTED; } else if (l2capinbuf[16] == 0x00 && l2capinbuf[17] == 0xA4 && l2capinbuf[18] == 0x20 && l2capinbuf[19] == 0x04 && l2capinbuf[20] == 0x05) { -#ifdef DEBUG_USB_HOST_USB_HOST +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nMotion Plus activated in normal mode"), 0x80); #endif motionPlusConnected = true; } else if (l2capinbuf[16] == 0x00 && l2capinbuf[17] == 0xA4 && l2capinbuf[18] == 0x20 && l2capinbuf[19] == 0x05 && l2capinbuf[20] == 0x05) { -#ifdef DEBUG_USB_HOST_USB_HOST +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nMotion Plus activated in Nunchuck pass-through mode"), 0x80); #endif activateNunchuck = false; motionPlusConnected = true; nunchuckConnected = true; } else if (l2capinbuf[16] == 0x00 && l2capinbuf[17] == 0xA6 && l2capinbuf[18] == 0x20 && (l2capinbuf[19] == 0x00 || l2capinbuf[19] == 0x04 || l2capinbuf[19] == 0x05 || l2capinbuf[19] == 0x07) && l2capinbuf[20] == 0x05) { -#ifdef DEBUG_USB_HOST_USB_HOST +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nInactive Wii Motion Plus"), 0x80); Notify(PSTR("\r\nPlease unplug the Motion Plus, disconnect the Wiimote and then replug the Motion Plus Extension"), 0x80); #endif stateCounter = 300; // Skip the rest in "L2CAP_CHECK_MOTION_PLUS_STATE" } else if (l2capinbuf[16] == 0x00 && l2capinbuf[17] == 0xA4 && l2capinbuf[18] == 0x20 && l2capinbuf[19] == 0x01 && l2capinbuf[20] == 0x20) { -#ifdef DEBUG_USB_HOST_USB_HOST +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nWii U Pro Controller connected"), 0x80); #endif wiiUProControllerConnected = true; } -#ifdef DEBUG_USB_HOST_USB_HOST +#ifdef DEBUG_USB_HOST else { Notify(PSTR("\r\nUnknown Device: "), 0x80); PrintHex (l2capinbuf[13], 0x80); @@ -392,7 +392,7 @@ void WII::ACLData(uint8_t* l2capinbuf) { #endif break; case 0x22: // Acknowledge output report, return function result -#ifdef DEBUG_USB_HOST_USB_HOST +#ifdef DEBUG_USB_HOST if (l2capinbuf[13] != 0x00) { // Check if there is an error Notify(PSTR("\r\nCommand failed: "), 0x80); PrintHex (l2capinbuf[12], 0x80); @@ -496,7 +496,7 @@ void WII::ACLData(uint8_t* l2capinbuf) { */ } else { if ((micros() - timer) > 1000000) { // Loop for 1 sec before resetting the values -#ifdef DEBUG_USB_HOST_USB_HOST +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nThe gyro values has been reset"), 0x80); #endif gyroYawZero = (l2capinbuf[15] | ((l2capinbuf[18] & 0xFC) << 6)); @@ -531,7 +531,7 @@ void WII::ACLData(uint8_t* l2capinbuf) { if (!extensionConnected) { extensionConnected = true; unknownExtensionConnected = true; -#ifdef DEBUG_USB_HOST_USB_HOST +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nExtension connected to Motion Plus"), 0x80); #endif } @@ -539,7 +539,7 @@ void WII::ACLData(uint8_t* l2capinbuf) { if (extensionConnected && !unknownExtensionConnected) { extensionConnected = false; unknownExtensionConnected = true; -#ifdef DEBUG_USB_HOST_USB_HOST +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nExtension disconnected from Motion Plus"), 0x80); #endif nunchuckConnected = false; // There is no extension connected to the Motion Plus if this report is sent @@ -564,7 +564,7 @@ void WII::ACLData(uint8_t* l2capinbuf) { hatValues[RightHatY] = (l2capinbuf[21] | l2capinbuf[22] << 8); } break; -#ifdef DEBUG_USB_HOST_USB_HOST +#ifdef DEBUG_USB_HOST default: Notify(PSTR("\r\nUnknown Report type: "), 0x80); PrintHex (l2capinbuf[9], 0x80); @@ -583,7 +583,7 @@ void WII::L2CAP_task() { /* These states are used if the Wiimote is the host */ case L2CAP_CONTROL_SUCCESS: if (l2cap_config_success_control_flag) { -#ifdef DEBUG_USB_HOST_USB_HOST +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nHID Control Successfully Configured"), 0x80); #endif l2cap_state = L2CAP_INTERRUPT_SETUP; @@ -592,7 +592,7 @@ void WII::L2CAP_task() { case L2CAP_INTERRUPT_SETUP: if (l2cap_connection_request_interrupt_flag) { -#ifdef DEBUG_USB_HOST_USB_HOST +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nHID Interrupt Incoming Connection Request"), 0x80); #endif pBtd->l2cap_connection_response(hci_handle, identifier, interrupt_dcid, interrupt_scid, PENDING); @@ -609,7 +609,7 @@ void WII::L2CAP_task() { /* These states are used if the Arduino is the host */ case L2CAP_CONTROL_CONNECT_REQUEST: if (l2cap_connected_control_flag) { -#ifdef DEBUG_USB_HOST_USB_HOST +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nSend HID Control Config Request"), 0x80); #endif identifier++; @@ -620,7 +620,7 @@ void WII::L2CAP_task() { case L2CAP_CONTROL_CONFIG_REQUEST: if (l2cap_config_success_control_flag) { -#ifdef DEBUG_USB_HOST_USB_HOST +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nSend HID Interrupt Connection Request"), 0x80); #endif identifier++; @@ -631,7 +631,7 @@ void WII::L2CAP_task() { case L2CAP_INTERRUPT_CONNECT_REQUEST: if (l2cap_connected_interrupt_flag) { -#ifdef DEBUG_USB_HOST_USB_HOST +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nSend HID Interrupt Config Request"), 0x80); #endif identifier++; @@ -642,7 +642,7 @@ void WII::L2CAP_task() { case L2CAP_INTERRUPT_CONFIG_REQUEST: if (l2cap_config_success_interrupt_flag) { // Now the HID channels is established -#ifdef DEBUG_USB_HOST_USB_HOST +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nHID Channels Established"), 0x80); #endif pBtd->connectToWii = false; @@ -657,7 +657,7 @@ void WII::L2CAP_task() { case L2CAP_INTERRUPT_DISCONNECT: if (l2cap_disconnect_response_interrupt_flag) { -#ifdef DEBUG_USB_HOST_USB_HOST +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nDisconnected Interrupt Channel"), 0x80); #endif identifier++; @@ -668,7 +668,7 @@ void WII::L2CAP_task() { case L2CAP_CONTROL_DISCONNECT: if (l2cap_disconnect_response_control_flag) { -#ifdef DEBUG_USB_HOST_USB_HOST +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nDisconnected Control Channel"), 0x80); #endif pBtd->hci_disconnect(hci_handle); @@ -686,7 +686,7 @@ void WII::Run() { if (pBtd->connectToWii && !pBtd->l2capConnectionClaimed && !wiimoteConnected && !activeConnection) { pBtd->l2capConnectionClaimed = true; activeConnection = true; -#ifdef DEBUG_USB_HOST_USB_HOST +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nSend HID Control Connection Request"), 0x80); #endif hci_handle = pBtd->hci_handle; // Store the HCI Handle for the connection @@ -695,7 +695,7 @@ void WII::Run() { pBtd->l2cap_connection_request(hci_handle, identifier, control_dcid, HID_CTRL_PSM); l2cap_state = L2CAP_CONTROL_CONNECT_REQUEST; } else if (l2cap_connection_request_control_flag) { -#ifdef DEBUG_USB_HOST_USB_HOST +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nHID Control Incoming Connection Request"), 0x80); #endif pBtd->l2cap_connection_response(hci_handle, identifier, control_dcid, control_scid, PENDING); @@ -709,7 +709,7 @@ void WII::Run() { break; case L2CAP_CHECK_MOTION_PLUS_STATE: -#ifdef DEBUG_USB_HOST_USB_HOST +#ifdef DEBUG_USB_HOST if (stateCounter == 0) // Only print onnce Notify(PSTR("\r\nChecking if a Motion Plus is connected"), 0x80); #endif @@ -722,14 +722,14 @@ void WII::Run() { timer = micros(); if (unknownExtensionConnected) { -#ifdef DEBUG_USB_HOST_USB_HOST +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nA extension is also connected"), 0x80); #endif activateNunchuck = true; // For we will just set this to true as this the only extension supported so far } } else if (stateCounter == 601) { // We will try three times to check for the motion plus -#ifdef DEBUG_USB_HOST_USB_HOST +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nNo Motion Plus was detected"), 0x80); #endif stateCounter = 0; @@ -738,7 +738,7 @@ void WII::Run() { break; case L2CAP_CHECK_EXTENSION_STATE: // This is used to check if there is anything plugged in to the extension port -#ifdef DEBUG_USB_HOST_USB_HOST +#ifdef DEBUG_USB_HOST if (stateCounter == 0) // Only print onnce Notify(PSTR("\r\nChecking if there is any extension connected"), 0x80); #endif @@ -785,7 +785,7 @@ void WII::Run() { case L2CAP_DONE: if (unknownExtensionConnected) { -#ifdef DEBUG_USB_HOST_USB_HOST +#ifdef DEBUG_USB_HOST if (stateCounter == 0) // Only print once Notify(PSTR("\r\nChecking extension port"), 0x80); #endif @@ -803,7 +803,7 @@ void WII::Run() { readExtensionType(); else if (stateCounter == 250) { if (nunchuck_connected_flag) { -#ifdef DEBUG_USB_HOST_USB_HOST +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nNunchuck was reconnected"), 0x80); #endif activateNunchuck = true; @@ -813,7 +813,7 @@ void WII::Run() { stateCounter = 449; } else if (stateCounter == 300) { if (motionPlusConnected) { -#ifdef DEBUG_USB_HOST_USB_HOST +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nReactivating the Motion Plus"), 0x80); #endif initMotionPlus(); @@ -967,19 +967,19 @@ void WII::initMotionPlus() { void WII::activateMotionPlus() { uint8_t buf[1]; if (pBtd->wiiUProController) { -#ifdef DEBUG_USB_HOST_USB_HOST +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nActivating Wii U Pro Controller"), 0x80); #endif buf[0] = 0x00; // It seems like you can send anything but 0x04, 0x05, and 0x07 } else if (activateNunchuck) { -#ifdef DEBUG_USB_HOST_USB_HOST +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nActivating Motion Plus in pass-through mode"), 0x80); #endif buf[0] = 0x05; // Activate nunchuck pass-through mode } //else if(classicControllerConnected && extensionConnected) //buf[0] = 0x07; else { -#ifdef DEBUG_USB_HOST_USB_HOST +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nActivating Motion Plus in normal mode"), 0x80); #endif buf[0] = 0x04; // Don't use any extension @@ -1071,58 +1071,58 @@ uint16_t WII::getAnalogHat(AnalogHat a) { void WII::IRinitialize() { // Turns on and initialises the IR camera enableIRCamera1(); -#ifdef DEBUG_USB_HOST_USB_HOST +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nEnable IR Camera1 Complete"), 0x80); #endif delay(80); enableIRCamera2(); -#ifdef DEBUG_USB_HOST_USB_HOST +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nEnable IR Camera2 Complete"), 0x80); #endif delay(80); write0x08Value(); -#ifdef DEBUG_USB_HOST_USB_HOST +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nWrote hex number 0x08"), 0x80); #endif delay(80); writeSensitivityBlock1(); -#ifdef DEBUG_USB_HOST_USB_HOST +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nWrote Sensitivity Block 1"), 0x80); #endif delay(80); writeSensitivityBlock2(); -#ifdef DEBUG_USB_HOST_USB_HOST +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nWrote Sensitivity Block 2"), 0x80); #endif delay(80); uint8_t mode_num = 0x03; setWiiModeNumber(mode_num); // Change input for whatever mode you want i.e. 0x01, 0x03, or 0x05 -#ifdef DEBUG_USB_HOST_USB_HOST +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nSet Wii Mode Number To 0x"), 0x80); PrintHex (mode_num, 0x80); #endif delay(80); write0x08Value(); -#ifdef DEBUG_USB_HOST_USB_HOST +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nWrote Hex Number 0x08"), 0x80); #endif delay(80); setReportMode(false, 0x33); //setReportMode(false, 0x3f); // For full reporting mode, doesn't work yet -#ifdef DEBUG_USB_HOST_USB_HOST +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nSet Report Mode to 0x33"), 0x80); #endif delay(80); statusRequest(); // Used to update wiiState - call isIRCameraEnabled() afterwards to check if it actually worked -#ifdef DEBUG_USB_HOST_USB_HOST +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nIR Initialized"), 0x80); #endif } diff --git a/XBOXRECV.cpp b/XBOXRECV.cpp index 070747b6..4f39ce04 100644 --- a/XBOXRECV.cpp +++ b/XBOXRECV.cpp @@ -18,7 +18,7 @@ */ #include "XBOXRECV.h" -// To enable serial debugging uncomment "#define DEBUG_USB_HOST_USB_HOST" in message.h +// To enable serial debugging uncomment "#define DEBUG_USB_HOST" in message.h //#define EXTRADEBUG // Uncomment to get even more debugging data //#define PRINTREPORT // Uncomment to print the report send by the Xbox 360 Controller @@ -52,7 +52,7 @@ uint8_t XBOXRECV::Init(uint8_t parent, uint8_t port, bool lowspeed) { #endif // check if address has already been assigned to an instance if (bAddress) { -#ifdef DEBUG_USB_HOST_USB_HOST +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nAddress in use"), 0x80); #endif return USB_ERROR_CLASS_INSTANCE_ALREADY_IN_USE; @@ -62,14 +62,14 @@ uint8_t XBOXRECV::Init(uint8_t parent, uint8_t port, bool lowspeed) { p = addrPool.GetUsbDevicePtr(0); if (!p) { -#ifdef DEBUG_USB_HOST_USB_HOST +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nAddress not found"), 0x80); #endif return USB_ERROR_ADDRESS_NOT_FOUND_IN_POOL; } if (!p->epinfo) { -#ifdef DEBUG_USB_HOST_USB_HOST +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nepinfo is null"), 0x80); #endif return USB_ERROR_EPINFO_IS_NULL; @@ -97,7 +97,7 @@ uint8_t XBOXRECV::Init(uint8_t parent, uint8_t port, bool lowspeed) { if (VID != XBOX_VID && VID != MADCATZ_VID) // We just check if it's a xbox receiver using the Vendor ID goto FailUnknownDevice; else if (PID != XBOX_WIRELESS_RECEIVER_PID && PID != XBOX_WIRELESS_RECEIVER_THIRD_PARTY_PID) { -#ifdef DEBUG_USB_HOST_USB_HOST +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nYou'll need a wireless receiver for this libary to work"), 0x80); #endif goto FailUnknownDevice; @@ -118,7 +118,7 @@ uint8_t XBOXRECV::Init(uint8_t parent, uint8_t port, bool lowspeed) { p->lowspeed = false; addrPool.FreeAddress(bAddress); bAddress = 0; -#ifdef DEBUG_USB_HOST_USB_HOST +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nsetAddr: "), 0x80); PrintHex (rcode, 0x80); #endif @@ -209,7 +209,7 @@ uint8_t XBOXRECV::Init(uint8_t parent, uint8_t port, bool lowspeed) { if (rcode) goto FailSetConfDescr; -#ifdef DEBUG_USB_HOST_USB_HOST +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nXbox Wireless Receiver Connected\r\n"), 0x80); #endif XboxReceiverConnected = true; @@ -218,31 +218,31 @@ uint8_t XBOXRECV::Init(uint8_t parent, uint8_t port, bool lowspeed) { /* diagnostic messages */ FailGetDevDescr: -#ifdef DEBUG_USB_HOST_USB_HOST +#ifdef DEBUG_USB_HOST NotifyFailGetDevDescr(); goto Fail; #endif FailSetDevTblEntry: -#ifdef DEBUG_USB_HOST_USB_HOST +#ifdef DEBUG_USB_HOST NotifyFailSetDevTblEntry(); goto Fail; #endif FailSetConfDescr: -#ifdef DEBUG_USB_HOST_USB_HOST +#ifdef DEBUG_USB_HOST NotifyFailSetConfDescr(); #endif goto Fail; FailUnknownDevice: -#ifdef DEBUG_USB_HOST_USB_HOST +#ifdef DEBUG_USB_HOST NotifyFailUnknownDevice(VID,PID); #endif rcode = USB_DEV_CONFIG_ERROR_DEVICE_NOT_SUPPORTED; Fail: -#ifdef DEBUG_USB_HOST_USB_HOST +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nXbox 360 Init Failed, error code: "), 0x80); NotifyFail(rcode); #endif @@ -304,12 +304,12 @@ void XBOXRECV::readReport(uint8_t controller) { // This report is send when a controller is connected and disconnected if (readBuf[0] == 0x08 && readBuf[1] != Xbox360Connected[controller]) { Xbox360Connected[controller] = readBuf[1]; -#ifdef DEBUG_USB_HOST_USB_HOST +#ifdef DEBUG_USB_HOST Notify(PSTR("Controller "), 0x80); Notify(controller, 0x80); #endif if (Xbox360Connected[controller]) { -#ifdef DEBUG_USB_HOST_USB_HOST +#ifdef DEBUG_USB_HOST char* str = 0; switch (readBuf[1]) { case 0x80: str = PSTR(" as controller\r\n"); @@ -335,7 +335,7 @@ void XBOXRECV::readReport(uint8_t controller) { } setLedOn(led, controller); } -#ifdef DEBUG_USB_HOST_USB_HOST +#ifdef DEBUG_USB_HOST else Notify(PSTR(": disconnected\r\n"), 0x80); #endif diff --git a/XBOXUSB.cpp b/XBOXUSB.cpp index c5ec2786..3b308306 100644 --- a/XBOXUSB.cpp +++ b/XBOXUSB.cpp @@ -16,7 +16,7 @@ */ #include "XBOXUSB.h" -// To enable serial debugging uncomment "#define DEBUG_USB_HOST_USB_HOST" in message.h +// To enable serial debugging uncomment "#define DEBUG_USB_HOST" in message.h //#define EXTRADEBUG // Uncomment to get even more debugging data //#define PRINTREPORT // Uncomment to print the report send by the Xbox 360 Controller @@ -50,7 +50,7 @@ uint8_t XBOXUSB::Init(uint8_t parent, uint8_t port, bool lowspeed) { #endif // check if address has already been assigned to an instance if (bAddress) { -#ifdef DEBUG_USB_HOST_USB_HOST +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nAddress in use"), 0x80); #endif return USB_ERROR_CLASS_INSTANCE_ALREADY_IN_USE; @@ -60,14 +60,14 @@ uint8_t XBOXUSB::Init(uint8_t parent, uint8_t port, bool lowspeed) { p = addrPool.GetUsbDevicePtr(0); if (!p) { -#ifdef DEBUG_USB_HOST_USB_HOST +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nAddress not found"), 0x80); #endif return USB_ERROR_ADDRESS_NOT_FOUND_IN_POOL; } if (!p->epinfo) { -#ifdef DEBUG_USB_HOST_USB_HOST +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nepinfo is null"), 0x80); #endif return USB_ERROR_EPINFO_IS_NULL; @@ -95,12 +95,12 @@ uint8_t XBOXUSB::Init(uint8_t parent, uint8_t port, bool lowspeed) { if (VID != XBOX_VID && VID != MADCATZ_VID && VID != JOYTECH_VID) // We just check if it's a xbox controller using the Vendor ID goto FailUnknownDevice; if (PID == XBOX_WIRELESS_PID) { -#ifdef DEBUG_USB_HOST_USB_HOST +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nYou have plugged in a wireless Xbox 360 controller - it doesn't support USB communication"), 0x80); #endif goto FailUnknownDevice; } else if (PID == XBOX_WIRELESS_RECEIVER_PID || PID == XBOX_WIRELESS_RECEIVER_THIRD_PARTY_PID) { -#ifdef DEBUG_USB_HOST_USB_HOST +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nThis library only supports Xbox 360 controllers via USB"), 0x80); #endif goto FailUnknownDevice; @@ -121,7 +121,7 @@ uint8_t XBOXUSB::Init(uint8_t parent, uint8_t port, bool lowspeed) { p->lowspeed = false; addrPool.FreeAddress(bAddress); bAddress = 0; -#ifdef DEBUG_USB_HOST_USB_HOST +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nsetAddr: "), 0x80); #endif PrintHex (rcode, 0x80); @@ -173,7 +173,7 @@ uint8_t XBOXUSB::Init(uint8_t parent, uint8_t port, bool lowspeed) { if (rcode) goto FailSetConfDescr; -#ifdef DEBUG_USB_HOST_USB_HOST +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nXbox 360 Controller Connected\r\n"), 0x80); #endif setLedOn(LED1); @@ -183,30 +183,30 @@ uint8_t XBOXUSB::Init(uint8_t parent, uint8_t port, bool lowspeed) { /* diagnostic messages */ FailGetDevDescr: -#ifdef DEBUG_USB_HOST_USB_HOST +#ifdef DEBUG_USB_HOST NotifyFailGetDevDescr(); goto Fail; #endif FailSetDevTblEntry: -#ifdef DEBUG_USB_HOST_USB_HOST +#ifdef DEBUG_USB_HOST NotifyFailSetDevTblEntry(); goto Fail; #endif FailSetConfDescr: -#ifdef DEBUG_USB_HOST_USB_HOST +#ifdef DEBUG_USB_HOST NotifyFailSetConfDescr(); goto Fail; #endif FailUnknownDevice: -#ifdef DEBUG_USB_HOST_USB_HOST +#ifdef DEBUG_USB_HOST NotifyFailUnknownDevice(VID, PID); #endif rcode = USB_DEV_CONFIG_ERROR_DEVICE_NOT_SUPPORTED; Fail: -#ifdef DEBUG_USB_HOST_USB_HOST +#ifdef DEBUG_USB_HOST Notify(PSTR("\r\nXbox 360 Init Failed, error code: "), 0x80); NotifyFail(rcode); #endif diff --git a/adk.cpp b/adk.cpp index 24f22173..14d35860 100644 --- a/adk.cpp +++ b/adk.cpp @@ -227,43 +227,43 @@ uint8_t ADK::Init(uint8_t parent, uint8_t port, bool lowspeed) { /* diagnostic messages */ FailGetDevDescr: -#ifdef DEBUG_USB_HOST_USB_HOST +#ifdef DEBUG_USB_HOST NotifyFailGetDevDescr(); goto Fail; #endif FailSetDevTblEntry: -#ifdef DEBUG_USB_HOST_USB_HOST +#ifdef DEBUG_USB_HOST NotifyFailSetDevTblEntry(); goto Fail; #endif FailGetConfDescr: -#ifdef DEBUG_USB_HOST_USB_HOST +#ifdef DEBUG_USB_HOST NotifyFailGetConfDescr(); goto Fail; #endif FailSetConfDescr: -#ifdef DEBUG_USB_HOST_USB_HOST +#ifdef DEBUG_USB_HOST NotifyFailSetConfDescr(); goto Fail; #endif FailGetProto: -#ifdef DEBUG_USB_HOST_USB_HOST +#ifdef DEBUG_USB_HOST USBTRACE("\r\ngetProto:"); goto Fail; #endif FailSwAcc: -#ifdef DEBUG_USB_HOST_USB_HOST +#ifdef DEBUG_USB_HOST USBTRACE("\r\nswAcc:"); goto Fail; #endif SwAttempt: -#ifdef DEBUG_USB_HOST_USB_HOST +#ifdef DEBUG_USB_HOST USBTRACE("\r\nAccessory mode switch attempt"); #endif //FailOnInit: diff --git a/cdcacm.cpp b/cdcacm.cpp index 3035bc71..2c75a594 100644 --- a/cdcacm.cpp +++ b/cdcacm.cpp @@ -183,36 +183,36 @@ uint8_t ACM::Init(uint8_t parent, uint8_t port, bool lowspeed) { return 0; FailGetDevDescr: -#ifdef DEBUG_USB_HOST_USB_HOST +#ifdef DEBUG_USB_HOST NotifyFailGetDevDescr(); goto Fail; #endif FailSetDevTblEntry: -#ifdef DEBUG_USB_HOST_USB_HOST +#ifdef DEBUG_USB_HOST NotifyFailSetDevTblEntry(); goto Fail; #endif FailGetConfDescr: -#ifdef DEBUG_USB_HOST_USB_HOST +#ifdef DEBUG_USB_HOST NotifyFailGetConfDescr(); goto Fail; #endif FailSetConfDescr: -#ifdef DEBUG_USB_HOST_USB_HOST +#ifdef DEBUG_USB_HOST NotifyFailSetConfDescr(); goto Fail; #endif FailOnInit: -#ifdef DEBUG_USB_HOST_USB_HOST +#ifdef DEBUG_USB_HOST USBTRACE("OnInit:"); #endif Fail: -#ifdef DEBUG_USB_HOST_USB_HOST +#ifdef DEBUG_USB_HOST NotifyFail(rcode); #endif Release(); diff --git a/cdcftdi.cpp b/cdcftdi.cpp index 4d0baa8e..a8489373 100644 --- a/cdcftdi.cpp +++ b/cdcftdi.cpp @@ -178,36 +178,36 @@ uint8_t FTDI::Init(uint8_t parent, uint8_t port, bool lowspeed) { return 0; FailGetDevDescr: -#ifdef DEBUG_USB_HOST_USB_HOST +#ifdef DEBUG_USB_HOST NotifyFailGetDevDescr(); goto Fail; #endif FailSetDevTblEntry: -#ifdef DEBUG_USB_HOST_USB_HOST +#ifdef DEBUG_USB_HOST NotifyFailSetDevTblEntry(); goto Fail; #endif FailGetConfDescr: -#ifdef DEBUG_USB_HOST_USB_HOST +#ifdef DEBUG_USB_HOST NotifyFailGetConfDescr(); goto Fail; #endif FailSetConfDescr: -#ifdef DEBUG_USB_HOST_USB_HOST +#ifdef DEBUG_USB_HOST NotifyFailSetConfDescr(); goto Fail; #endif FailOnInit: -#ifdef DEBUG_USB_HOST_USB_HOST +#ifdef DEBUG_USB_HOST USBTRACE("OnInit:"); #endif Fail: -#ifdef DEBUG_USB_HOST_USB_HOST +#ifdef DEBUG_USB_HOST NotifyFail(rcode); #endif Release(); diff --git a/cdcprolific.cpp b/cdcprolific.cpp index 53fdee73..ac4b0f63 100644 --- a/cdcprolific.cpp +++ b/cdcprolific.cpp @@ -155,36 +155,36 @@ uint8_t PL2303::Init(uint8_t parent, uint8_t port, bool lowspeed) { return 0; FailGetDevDescr: -#ifdef DEBUG_USB_HOST_USB_HOST +#ifdef DEBUG_USB_HOST NotifyFailGetDevDescr(); goto Fail; #endif FailSetDevTblEntry: -#ifdef DEBUG_USB_HOST_USB_HOST +#ifdef DEBUG_USB_HOST NotifyFailSetDevTblEntry(); goto Fail; #endif FailGetConfDescr: -#ifdef DEBUG_USB_HOST_USB_HOST +#ifdef DEBUG_USB_HOST NotifyFailGetConfDescr(); goto Fail; #endif FailSetConfDescr: -#ifdef DEBUG_USB_HOST_USB_HOST +#ifdef DEBUG_USB_HOST NotifyFailSetConfDescr(); goto Fail; #endif FailOnInit: -#ifdef DEBUG_USB_HOST_USB_HOST +#ifdef DEBUG_USB_HOST USBTRACE("OnInit:"); #endif Fail: -#ifdef DEBUG_USB_HOST_USB_HOST +#ifdef DEBUG_USB_HOST NotifyFail(rcode); #endif Release(); diff --git a/hidboot.h b/hidboot.h index 34c46922..797b3a3c 100644 --- a/hidboot.h +++ b/hidboot.h @@ -393,42 +393,42 @@ uint8_t HIDBoot::Init(uint8_t parent, uint8_t port, bool lowspeed return 0; FailGetDevDescr: -#ifdef DEBUG_USB_HOST_USB_HOST +#ifdef DEBUG_USB_HOST NotifyFailGetDevDescr(); goto Fail; #endif FailSetDevTblEntry: -#ifdef DEBUG_USB_HOST_USB_HOST +#ifdef DEBUG_USB_HOST NotifyFailSetDevTblEntry(); goto Fail; #endif FailGetConfDescr: -#ifdef DEBUG_USB_HOST_USB_HOST +#ifdef DEBUG_USB_HOST NotifyFailGetConfDescr(); goto Fail; #endif FailSetConfDescr: -#ifdef DEBUG_USB_HOST_USB_HOST +#ifdef DEBUG_USB_HOST NotifyFailSetConfDescr(); goto Fail; #endif FailSetProtocol: -#ifdef DEBUG_USB_HOST_USB_HOST +#ifdef DEBUG_USB_HOST USBTRACE("SetProto:"); goto Fail; #endif FailSetIdle: -#ifdef DEBUG_USB_HOST_USB_HOST +#ifdef DEBUG_USB_HOST USBTRACE("SetIdle:"); #endif Fail: -#ifdef DEBUG_USB_HOST_USB_HOST +#ifdef DEBUG_USB_HOST NotifyFail(rcode); #endif Release(); diff --git a/hiduniversal.cpp b/hiduniversal.cpp index fba0715e..800839e1 100644 --- a/hiduniversal.cpp +++ b/hiduniversal.cpp @@ -221,37 +221,37 @@ uint8_t HIDUniversal::Init(uint8_t parent, uint8_t port, bool lowspeed) { return 0; FailGetDevDescr: -#ifdef DEBUG_USB_HOST_USB_HOST +#ifdef DEBUG_USB_HOST NotifyFailGetDevDescr(); goto Fail; #endif FailSetDevTblEntry: -#ifdef DEBUG_USB_HOST_USB_HOST +#ifdef DEBUG_USB_HOST NotifyFailSetDevTblEntry(); goto Fail; #endif FailGetConfDescr: -#ifdef DEBUG_USB_HOST_USB_HOST +#ifdef DEBUG_USB_HOST NotifyFailGetConfDescr(); goto Fail; #endif FailSetConfDescr: -#ifdef DEBUG_USB_HOST_USB_HOST +#ifdef DEBUG_USB_HOST NotifyFailSetConfDescr(); goto Fail; #endif FailSetIdle: -#ifdef DEBUG_USB_HOST_USB_HOST +#ifdef DEBUG_USB_HOST USBTRACE("SetIdle:"); #endif Fail: -#ifdef DEBUG_USB_HOST_USB_HOST +#ifdef DEBUG_USB_HOST NotifyFail(rcode); #endif Release(); diff --git a/masstorage.cpp b/masstorage.cpp index d3a89ff2..6fae6ce1 100644 --- a/masstorage.cpp +++ b/masstorage.cpp @@ -174,7 +174,7 @@ uint8_t BulkOnly::ConfigureDevice(uint8_t parent, uint8_t port, bool lowspeed) { return USB_ERROR_CONFIG_REQUIRES_ADDITIONAL_RESET; FailGetDevDescr: -#ifdef DEBUG_USB_HOST_USB_HOST +#ifdef DEBUG_USB_HOST NotifyFailGetDevDescr(rcode); #endif rcode = USB_ERROR_FailGetDevDescr; @@ -362,42 +362,42 @@ uint8_t BulkOnly::Init(uint8_t parent, uint8_t port, bool lowspeed) { return 0; FailSetConfDescr: -#ifdef DEBUG_USB_HOST_USB_HOST +#ifdef DEBUG_USB_HOST NotifyFailSetConfDescr(); goto Fail; #endif FailOnInit: -#ifdef DEBUG_USB_HOST_USB_HOST +#ifdef DEBUG_USB_HOST USBTRACE("OnInit:"); goto Fail; #endif FailGetMaxLUN: -#ifdef DEBUG_USB_HOST_USB_HOST +#ifdef DEBUG_USB_HOST USBTRACE("GetMaxLUN:"); goto Fail; #endif FailInvalidSectorSize: -#ifdef DEBUG_USB_HOST_USB_HOST +#ifdef DEBUG_USB_HOST USBTRACE("Sector Size is NOT VALID: "); goto Fail; #endif FailSetDevTblEntry: -#ifdef DEBUG_USB_HOST_USB_HOST +#ifdef DEBUG_USB_HOST NotifyFailSetDevTblEntry(); goto Fail; #endif FailGetConfDescr: -#ifdef DEBUG_USB_HOST_USB_HOST +#ifdef DEBUG_USB_HOST NotifyFailGetConfDescr(); #endif Fail: -#ifdef DEBUG_USB_HOST_USB_HOST +#ifdef DEBUG_USB_HOST NotifyFail(rcode); #endif Release(); diff --git a/message.cpp b/message.cpp index 568c0642..393faa32 100644 --- a/message.cpp +++ b/message.cpp @@ -63,7 +63,7 @@ void E_Notify(double d, int lvl) { Serial.flush(); } -#ifdef DEBUG_USB_HOST_USB_HOST +#ifdef DEBUG_USB_HOST void NotifyFailGetDevDescr(void) { Notify(PSTR("\r\ngetDevDescr"), 0x80); } diff --git a/message.h b/message.h index bd5b60ff..a2fe5f25 100644 --- a/message.h +++ b/message.h @@ -18,7 +18,7 @@ e-mail : support@circuitsathome.com #define __MESSAGE_H__ // uncomment to activate -//#define DEBUG_USB_HOST_USB_HOST +//#define DEBUG_USB_HOST #include #include @@ -31,7 +31,7 @@ void E_Notify(uint8_t b, int lvl); void E_NotifyStr(char const * msg, int lvl); void E_Notifyc(char c, int lvl); -#ifdef DEBUG_USB_HOST_USB_HOST +#ifdef DEBUG_USB_HOST #define Notify E_Notify #define NotifyStr E_NotifyStr #define Notifyc E_Notifyc @@ -61,7 +61,7 @@ void NotifyFail(uint8_t rcode); template void ErrorMessage(uint8_t level, char const * msg, ERROR_TYPE rcode = 0) { -#ifdef DEBUG_USB_HOST_USB_HOST +#ifdef DEBUG_USB_HOST Notify(msg, level); Notify(PSTR(": "), level); PrintHex (rcode, level); @@ -71,7 +71,7 @@ void ErrorMessage(uint8_t level, char const * msg, ERROR_TYPE rcode = 0) { template void ErrorMessage(char const * msg, ERROR_TYPE rcode = 0) { -#ifdef DEBUG_USB_HOST_USB_HOST +#ifdef DEBUG_USB_HOST Notify(msg, 0x80); Notify(PSTR(": "), 0x80); PrintHex (rcode, 0x80); diff --git a/printhex.h b/printhex.h index 3a86d698..55a5b19f 100644 --- a/printhex.h +++ b/printhex.h @@ -27,7 +27,7 @@ void E_Notifyc(char c, int lvl); template void PrintHex(T val, int lvl) { -#ifdef DEBUG_USB_HOST_USB_HOST +#ifdef DEBUG_USB_HOST int num_nibbles = sizeof(T) * 2; do { @@ -40,7 +40,7 @@ void PrintHex(T val, int lvl) { template void PrintBin(T val, int lvl) { -#ifdef DEBUG_USB_HOST_USB_HOST +#ifdef DEBUG_USB_HOST for(T mask = (((T) 1) << ((sizeof(T) << 3) - 1)); mask; mask >>= 1) if(val & mask) E_Notifyc('1', lvl); @@ -51,7 +51,7 @@ void PrintBin(T val, int lvl) { template void SerialPrintHex(T val) { -#ifdef DEBUG_USB_HOST_USB_HOST +#ifdef DEBUG_USB_HOST int num_nibbles = sizeof(T) * 2; do { @@ -64,7 +64,7 @@ void SerialPrintHex(T val) { template void PrintHex2(Print *prn, T val) { -#ifdef DEBUG_USB_HOST_USB_HOST +#ifdef DEBUG_USB_HOST T mask = (((T) 1) << (((sizeof(T) << 1) - 1) << 2)); while(mask > 1) { From 3740adc947777ef4a5cc9a46547eb2f37a9d6ccc Mon Sep 17 00:00:00 2001 From: "Andrew J. Kroll" Date: Mon, 10 Jun 2013 14:55:44 -0400 Subject: [PATCH 19/20] Allow change of debug port --- Usb.h | 2 +- address.h | 14 ++++---- cdcacm.cpp | 2 +- cdcftdi.cpp | 2 +- cdcprolific.cpp | 2 +- hidboot.h | 2 +- hidescriptorparser.cpp | 8 ++--- message.cpp | 16 ++++----- message.h | 5 +++ printhex.h | 2 +- usbhost.h | 4 +-- usbhub.cpp | 74 +++++++++++++++++++++--------------------- 12 files changed, 69 insertions(+), 64 deletions(-) diff --git a/Usb.h b/Usb.h index 18b25498..af8bdced 100644 --- a/Usb.h +++ b/Usb.h @@ -58,7 +58,7 @@ typedef MAX3421e MAX3421E; // Balanduino typedef MAX3421e MAX3421E; // Official Arduinos (UNO, Duemilanove, Mega, 2560, Leonardo etc.) #endif -//Debug macros. In 1.0 it is possible to move strings to PROGMEM by defining USBTRACE (Serial.print(F(s))) +//Debug macros. In 1.0 it is possible to move strings to PROGMEM by defining USBTRACE (USB_HOST_SERIAL.print(F(s))) #define USBTRACE(s) (Notify(PSTR(s), 0x80)) #define USBTRACE2(s,r) (Notify(PSTR(s), 0x80), PrintHex((r), 0x80), Notify(PSTR("\r\n"), 0x80)) diff --git a/address.h b/address.h index 59b7245f..7825e58b 100644 --- a/address.h +++ b/address.h @@ -194,7 +194,7 @@ public: virtual uint8_t AllocAddress(uint8_t parent, bool is_hub = false, uint8_t port = 0) { /* if (parent != 0 && port == 0) - Serial.println("PRT:0"); */ + USB_HOST_SERIAL.println("PRT:0"); */ if(parent > 127 || port > 7) return 0; @@ -231,12 +231,12 @@ public: } thePool[index].address = *((uint8_t*) & addr); /* - Serial.print("Addr:"); - Serial.print(addr.bmHub, HEX); - Serial.print("."); - Serial.print(addr.bmParent, HEX); - Serial.print("."); - Serial.println(addr.bmAddress, HEX); + USB_HOST_SERIAL.print("Addr:"); + USB_HOST_SERIAL.print(addr.bmHub, HEX); + USB_HOST_SERIAL.print("."); + USB_HOST_SERIAL.print(addr.bmParent, HEX); + USB_HOST_SERIAL.print("."); + USB_HOST_SERIAL.println(addr.bmAddress, HEX); */ return thePool[index].address; }; diff --git a/cdcacm.cpp b/cdcacm.cpp index 2c75a594..0f9fffde 100644 --- a/cdcacm.cpp +++ b/cdcacm.cpp @@ -288,7 +288,7 @@ uint8_t ACM::Poll() { // for (uint8_t i=0; i(buf[i]); - // Serial.print(" "); + // USB_HOST_SERIAL.print(" "); // } // USBTRACE("\r\n"); //} diff --git a/cdcftdi.cpp b/cdcftdi.cpp index a8489373..20d1dd66 100644 --- a/cdcftdi.cpp +++ b/cdcftdi.cpp @@ -259,7 +259,7 @@ uint8_t FTDI::Poll() { //if (qNextPollTime <= millis()) //{ - // Serial.println(bAddress, HEX); + // USB_HOST_SERIAL.println(bAddress, HEX); // qNextPollTime = millis() + 100; //} diff --git a/cdcprolific.cpp b/cdcprolific.cpp index ac4b0f63..f17feaf7 100644 --- a/cdcprolific.cpp +++ b/cdcprolific.cpp @@ -200,7 +200,7 @@ Fail: // // //if (qNextPollTime <= millis()) // //{ -// // Serial.println(bAddress, HEX); +// // USB_HOST_SERIAL.println(bAddress, HEX); // // // qNextPollTime = millis() + 100; // //} diff --git a/hidboot.h b/hidboot.h index 797b3a3c..44cbc1aa 100644 --- a/hidboot.h +++ b/hidboot.h @@ -497,7 +497,7 @@ uint8_t HIDBoot::Poll() { //for (uint8_t i=0; i(buf[i]); //if (read) - // Serial.println(""); + // USB_HOST_SERIAL.println(""); if(pRptParser) pRptParser->Parse((HID*)this, 0, (uint8_t) read, buf); diff --git a/hidescriptorparser.cpp b/hidescriptorparser.cpp index a0226f2f..ded864fe 100644 --- a/hidescriptorparser.cpp +++ b/hidescriptorparser.cpp @@ -981,9 +981,9 @@ void ReportDescParserBase::Parse(const uint16_t len, const uint8_t *pbuf, const totalSize = 0; while (cntdn) { - //Serial.println(""); + //USB_HOST_SERIAL.println(""); //PrintHex(offset + len - cntdn); - //Serial.print(":"); + //USB_HOST_SERIAL.print(":"); ParseItem(&p, &cntdn); @@ -1267,7 +1267,7 @@ void ReportDescParserBase::PrintButtonPageUsage(uint16_t usage) { Notify(PSTR("Btn"), 0x80); PrintHex (usage, 0x80); Notify(PSTR("\r\n"), 0x80); - //Serial.print(usage, HEX); + //USB_HOST_SERIAL.print(usage, HEX); } void ReportDescParserBase::PrintOrdinalPageUsage(uint16_t usage) { @@ -1276,7 +1276,7 @@ void ReportDescParserBase::PrintOrdinalPageUsage(uint16_t usage) { // Sorry, HEX for now... PrintHex (usage, 0x80); Notify(PSTR("\r\n"), 0x80); - //Serial.print(usage, DEC); + //USB_HOST_SERIAL.print(usage, DEC); } void ReportDescParserBase::PrintGenericDesktopPageUsage(uint16_t usage) { diff --git a/message.cpp b/message.cpp index 393faa32..58538796 100644 --- a/message.cpp +++ b/message.cpp @@ -24,11 +24,11 @@ int UsbDEBUGlvl = 0x80; void E_Notifyc(char c, int lvl) { if (UsbDEBUGlvl < lvl) return; #if defined(ARDUINO) && ARDUINO >=100 - Serial.print(c); + USB_HOST_SERIAL.print(c); #else - Serial.print(c, BYTE); + USB_HOST_SERIAL.print(c, BYTE); #endif - Serial.flush(); + USB_HOST_SERIAL.flush(); } void E_Notify(char const * msg, int lvl) { @@ -50,17 +50,17 @@ void E_NotifyStr(char const * msg, int lvl) { void E_Notify(uint8_t b, int lvl) { if (UsbDEBUGlvl < lvl) return; #if defined(ARDUINO) && ARDUINO >=100 - Serial.print(b); + USB_HOST_SERIAL.print(b); #else - Serial.print(b, DEC); + USB_HOST_SERIAL.print(b, DEC); #endif - Serial.flush(); + USB_HOST_SERIAL.flush(); } void E_Notify(double d, int lvl) { if (UsbDEBUGlvl < lvl) return; - Serial.print(d); - Serial.flush(); + USB_HOST_SERIAL.print(d); + USB_HOST_SERIAL.flush(); } #ifdef DEBUG_USB_HOST diff --git a/message.h b/message.h index a2fe5f25..4dfcb62b 100644 --- a/message.h +++ b/message.h @@ -20,6 +20,11 @@ e-mail : support@circuitsathome.com // uncomment to activate //#define DEBUG_USB_HOST + +#ifndef USB_HOST_SERIAL +#define USB_HOST_SERIAL Serial +#endif + #include #include diff --git a/printhex.h b/printhex.h index 55a5b19f..3c3ab6ef 100644 --- a/printhex.h +++ b/printhex.h @@ -57,7 +57,7 @@ void SerialPrintHex(T val) { do { char v = 48 + (((val >> (num_nibbles - 1) * 4)) & 0x0f); if(v > 57) v += 7; - Serial.print(v); + USB_HOST_SERIAL.print(v); } while(--num_nibbles); #endif } diff --git a/usbhost.h b/usbhost.h index a6b3135b..819ba971 100644 --- a/usbhost.h +++ b/usbhost.h @@ -273,8 +273,8 @@ template< typename SS, typename INTR > uint8_t MAX3421e< SS, INTR >::Task(void) { uint8_t rcode = 0; uint8_t pinvalue; - //Serial.print("Vbus state: "); - //Serial.println( vbusState, HEX ); + //USB_HOST_SERIAL.print("Vbus state: "); + //USB_HOST_SERIAL.println( vbusState, HEX ); pinvalue = INTR::IsSet(); //Read(); //pinvalue = digitalRead( MAX_INT ); if(pinvalue == 0) { diff --git a/usbhub.cpp b/usbhub.cpp index 3692a6ab..51f736d6 100644 --- a/usbhub.cpp +++ b/usbhub.cpp @@ -247,8 +247,8 @@ uint8_t USBHub::CheckHubStatus() { //rcode = GetHubStatus(1, 0, 1, 4, buf); //if (rcode) //{ - // Serial.print("GetHubStatus Error"); - // Serial.println(rcode, HEX); + // USB_HOST_SERIAL.print("GetHubStatus Error"); + // USB_HOST_SERIAL.println(rcode, HEX); // return rcode; //} } @@ -350,46 +350,46 @@ void PrintHubPortStatus(USBHub *hubptr, uint8_t addr, uint8_t port, bool print_c rcode = hubptr->GetPortStatus(port, 4, evt.evtBuff); if (rcode) { - Serial.println("ERROR!"); + USB_HOST_SERIAL.println("ERROR!"); return; } - Serial.print("\r\nPort "); - Serial.println(port, DEC); + USB_HOST_SERIAL.print("\r\nPort "); + USB_HOST_SERIAL.println(port, DEC); - Serial.println("Status"); - Serial.print("CONNECTION:\t"); - Serial.println((evt.bmStatus & bmHUB_PORT_STATUS_PORT_CONNECTION) > 0, DEC); - Serial.print("ENABLE:\t\t"); - Serial.println((evt.bmStatus & bmHUB_PORT_STATUS_PORT_ENABLE) > 0, DEC); - Serial.print("SUSPEND:\t"); - Serial.println((evt.bmStatus & bmHUB_PORT_STATUS_PORT_SUSPEND) > 0, DEC); - Serial.print("OVER_CURRENT:\t"); - Serial.println((evt.bmStatus & bmHUB_PORT_STATUS_PORT_OVER_CURRENT) > 0, DEC); - Serial.print("RESET:\t\t"); - Serial.println((evt.bmStatus & bmHUB_PORT_STATUS_PORT_RESET) > 0, DEC); - Serial.print("POWER:\t\t"); - Serial.println((evt.bmStatus & bmHUB_PORT_STATUS_PORT_POWER) > 0, DEC); - Serial.print("LOW_SPEED:\t"); - Serial.println((evt.bmStatus & bmHUB_PORT_STATUS_PORT_LOW_SPEED) > 0, DEC); - Serial.print("HIGH_SPEED:\t"); - Serial.println((evt.bmStatus & bmHUB_PORT_STATUS_PORT_HIGH_SPEED) > 0, DEC); - Serial.print("TEST:\t\t"); - Serial.println((evt.bmStatus & bmHUB_PORT_STATUS_PORT_TEST) > 0, DEC); - Serial.print("INDICATOR:\t"); - Serial.println((evt.bmStatus & bmHUB_PORT_STATUS_PORT_INDICATOR) > 0, DEC); + USB_HOST_SERIAL.println("Status"); + USB_HOST_SERIAL.print("CONNECTION:\t"); + USB_HOST_SERIAL.println((evt.bmStatus & bmHUB_PORT_STATUS_PORT_CONNECTION) > 0, DEC); + USB_HOST_SERIAL.print("ENABLE:\t\t"); + USB_HOST_SERIAL.println((evt.bmStatus & bmHUB_PORT_STATUS_PORT_ENABLE) > 0, DEC); + USB_HOST_SERIAL.print("SUSPEND:\t"); + USB_HOST_SERIAL.println((evt.bmStatus & bmHUB_PORT_STATUS_PORT_SUSPEND) > 0, DEC); + USB_HOST_SERIAL.print("OVER_CURRENT:\t"); + USB_HOST_SERIAL.println((evt.bmStatus & bmHUB_PORT_STATUS_PORT_OVER_CURRENT) > 0, DEC); + USB_HOST_SERIAL.print("RESET:\t\t"); + USB_HOST_SERIAL.println((evt.bmStatus & bmHUB_PORT_STATUS_PORT_RESET) > 0, DEC); + USB_HOST_SERIAL.print("POWER:\t\t"); + USB_HOST_SERIAL.println((evt.bmStatus & bmHUB_PORT_STATUS_PORT_POWER) > 0, DEC); + USB_HOST_SERIAL.print("LOW_SPEED:\t"); + USB_HOST_SERIAL.println((evt.bmStatus & bmHUB_PORT_STATUS_PORT_LOW_SPEED) > 0, DEC); + USB_HOST_SERIAL.print("HIGH_SPEED:\t"); + USB_HOST_SERIAL.println((evt.bmStatus & bmHUB_PORT_STATUS_PORT_HIGH_SPEED) > 0, DEC); + USB_HOST_SERIAL.print("TEST:\t\t"); + USB_HOST_SERIAL.println((evt.bmStatus & bmHUB_PORT_STATUS_PORT_TEST) > 0, DEC); + USB_HOST_SERIAL.print("INDICATOR:\t"); + USB_HOST_SERIAL.println((evt.bmStatus & bmHUB_PORT_STATUS_PORT_INDICATOR) > 0, DEC); if (!print_changes) return; - Serial.println("\r\nChange"); - Serial.print("CONNECTION:\t"); - Serial.println((evt.bmChange & bmHUB_PORT_STATUS_C_PORT_CONNECTION) > 0, DEC); - Serial.print("ENABLE:\t\t"); - Serial.println((evt.bmChange & bmHUB_PORT_STATUS_C_PORT_ENABLE) > 0, DEC); - Serial.print("SUSPEND:\t"); - Serial.println((evt.bmChange & bmHUB_PORT_STATUS_C_PORT_SUSPEND) > 0, DEC); - Serial.print("OVER_CURRENT:\t"); - Serial.println((evt.bmChange & bmHUB_PORT_STATUS_C_PORT_OVER_CURRENT) > 0, DEC); - Serial.print("RESET:\t\t"); - Serial.println((evt.bmChange & bmHUB_PORT_STATUS_C_PORT_RESET) > 0, DEC); + USB_HOST_SERIAL.println("\r\nChange"); + USB_HOST_SERIAL.print("CONNECTION:\t"); + USB_HOST_SERIAL.println((evt.bmChange & bmHUB_PORT_STATUS_C_PORT_CONNECTION) > 0, DEC); + USB_HOST_SERIAL.print("ENABLE:\t\t"); + USB_HOST_SERIAL.println((evt.bmChange & bmHUB_PORT_STATUS_C_PORT_ENABLE) > 0, DEC); + USB_HOST_SERIAL.print("SUSPEND:\t"); + USB_HOST_SERIAL.println((evt.bmChange & bmHUB_PORT_STATUS_C_PORT_SUSPEND) > 0, DEC); + USB_HOST_SERIAL.print("OVER_CURRENT:\t"); + USB_HOST_SERIAL.println((evt.bmChange & bmHUB_PORT_STATUS_C_PORT_OVER_CURRENT) > 0, DEC); + USB_HOST_SERIAL.print("RESET:\t\t"); + USB_HOST_SERIAL.println((evt.bmChange & bmHUB_PORT_STATUS_C_PORT_RESET) > 0, DEC); } From 901f97310023e076a732b39526e3da52b7d40be5 Mon Sep 17 00:00:00 2001 From: "Andrew J. Kroll" Date: Mon, 10 Jun 2013 18:17:37 -0400 Subject: [PATCH 20/20] Serial, flush is not multitask safe. --- message.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/message.cpp b/message.cpp index 58538796..97809b16 100644 --- a/message.cpp +++ b/message.cpp @@ -28,7 +28,7 @@ void E_Notifyc(char c, int lvl) { #else USB_HOST_SERIAL.print(c, BYTE); #endif - USB_HOST_SERIAL.flush(); + //USB_HOST_SERIAL.flush(); } void E_Notify(char const * msg, int lvl) { @@ -54,13 +54,13 @@ void E_Notify(uint8_t b, int lvl) { #else USB_HOST_SERIAL.print(b, DEC); #endif - USB_HOST_SERIAL.flush(); + //USB_HOST_SERIAL.flush(); } void E_Notify(double d, int lvl) { if (UsbDEBUGlvl < lvl) return; USB_HOST_SERIAL.print(d); - USB_HOST_SERIAL.flush(); + //USB_HOST_SERIAL.flush(); } #ifdef DEBUG_USB_HOST