parent
7de9898bc6
commit
ee8419cc15
@ -1,81 +0,0 @@ |
|||||||
/*************************************************************************
|
|
||||||
* This demo uses the BALibrary library to provide enhanced control of |
|
||||||
* the TGA Pro board. |
|
||||||
*
|
|
||||||
* The latest copy of the BA Guitar library can be obtained from |
|
||||||
* https://github.com/Blackaddr/BALibrary
|
|
||||||
*
|
|
||||||
* This program can be used to find out the calibration values for each of your POTs |
|
||||||
* on the Blackaddr Audio Expansion Control Board. |
|
||||||
*
|
|
||||||
* USE THE ARDUINO SERIAL MONITOR TO PERFORM THE CALIBRATION |
|
||||||
*
|
|
||||||
* When prompted turn the appropriate POT in the specified direction and |
|
||||||
* enter any character on the terminal input line and press enter to send the character. |
|
||||||
*/ |
|
||||||
#include "BALibrary.h" |
|
||||||
|
|
||||||
using namespace BALibrary; |
|
||||||
|
|
||||||
// Create physical controls for Expansion Board, 2 switches, 3 pots, 0 encoders, 2 LEDs
|
|
||||||
BAPhysicalControls controls(BA_EXPAND_NUM_SW, BA_EXPAND_NUM_POT, 0, BA_EXPAND_NUM_LED); |
|
||||||
|
|
||||||
void setup() { |
|
||||||
delay(100); |
|
||||||
Serial.begin(57600); |
|
||||||
delay(500); // long delay to wait for Serial to init
|
|
||||||
|
|
||||||
TGA_PRO_EXPAND_REV2(); // Set the expansion board revision
|
|
||||||
|
|
||||||
// put your setup code here, to run once:
|
|
||||||
Serial.println("Calibrating POT1"); |
|
||||||
Potentiometer::Calib pot1Calib = Potentiometer::calibrate(BA_EXPAND_POT1_PIN); |
|
||||||
if (pot1Calib.min == pot1Calib.max) { Serial.println("\n!!! The knob didn't appear to move. Are you SURE you're turning the right knob? !!!"); } |
|
||||||
|
|
||||||
Serial.println("\nCalibrating POT2"); |
|
||||||
Potentiometer::Calib pot2Calib = Potentiometer::calibrate(BA_EXPAND_POT2_PIN); |
|
||||||
if (pot2Calib.min == pot2Calib.max) { Serial.println("\n!!! The knob didn't appear to move. Are you SURE you're turning the right knob? !!!"); } |
|
||||||
|
|
||||||
Serial.println("\nCalibrating POT3"); |
|
||||||
Potentiometer::Calib pot3Calib = Potentiometer::calibrate(BA_EXPAND_POT3_PIN); |
|
||||||
if (pot3Calib.min == pot3Calib.max) { Serial.println("\n!!! The knob didn't appear to move. Are you SURE you're turning the right knob? !!!"); } |
|
||||||
|
|
||||||
// Create the controls using the calib values
|
|
||||||
controls.addPot(BA_EXPAND_POT1_PIN, pot1Calib.min, pot1Calib.max, pot1Calib.swap); |
|
||||||
controls.addPot(BA_EXPAND_POT2_PIN, pot2Calib.min, pot2Calib.max, pot2Calib.swap); |
|
||||||
controls.addPot(BA_EXPAND_POT3_PIN, pot3Calib.min, pot3Calib.max, pot3Calib.swap); |
|
||||||
|
|
||||||
// Add the pushbuttons
|
|
||||||
controls.addSwitch(BA_EXPAND_SW1_PIN); |
|
||||||
controls.addSwitch(BA_EXPAND_SW2_PIN); |
|
||||||
|
|
||||||
// Setup the LEDs
|
|
||||||
controls.addOutput(BA_EXPAND_LED1_PIN); |
|
||||||
controls.setOutput(BA_EXPAND_LED1_PIN, 0); |
|
||||||
controls.addOutput(BA_EXPAND_LED2_PIN); |
|
||||||
controls.setOutput(BA_EXPAND_LED2_PIN, 0); |
|
||||||
|
|
||||||
Serial.println("DONE SETUP! Try turning knobs and pushing buttons!\n"); |
|
||||||
|
|
||||||
} |
|
||||||
|
|
||||||
void loop() { |
|
||||||
// put your main code here, to run repeatedly:
|
|
||||||
float value; |
|
||||||
for (unsigned i=0; i<BA_EXPAND_NUM_POT; i++) { |
|
||||||
if (controls.checkPotValue(i, value)) { |
|
||||||
Serial.println(String("POT") + (i+1) + String(" new value: ") + value); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
// Check pushbuttons
|
|
||||||
for (unsigned i=0; i<BA_EXPAND_NUM_SW; i++) { |
|
||||||
if (controls.isSwitchToggled(i)) { |
|
||||||
Serial.println(String("Button") + (i+1) + String(" pushed!")); |
|
||||||
controls.toggleOutput(i); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
delay(10); |
|
||||||
|
|
||||||
} |
|
@ -1,106 +0,0 @@ |
|||||||
/*************************************************************************
|
|
||||||
* This demo uses the BALibrary library to provide enhanced control of |
|
||||||
* the TGA Pro board. |
|
||||||
*
|
|
||||||
* The latest copy of the BA Guitar library can be obtained from |
|
||||||
* https://github.com/Blackaddr/BALibrary
|
|
||||||
*
|
|
||||||
* This demo will provide an audio passthrough, as well as exercise the |
|
||||||
* MIDI interface. |
|
||||||
*
|
|
||||||
*/ |
|
||||||
#include <Wire.h> |
|
||||||
#include <Audio.h> |
|
||||||
#include <MIDI.h> |
|
||||||
#include "BALibrary.h" |
|
||||||
|
|
||||||
MIDI_CREATE_DEFAULT_INSTANCE(); |
|
||||||
using namespace midi; |
|
||||||
using namespace BALibrary; |
|
||||||
|
|
||||||
AudioInputI2S i2sIn; |
|
||||||
AudioOutputI2S i2sOut; |
|
||||||
|
|
||||||
// Audio Thru Connection
|
|
||||||
AudioConnection patch0(i2sIn,0, i2sOut, 0); |
|
||||||
AudioConnection patch1(i2sIn,1, i2sOut, 1); |
|
||||||
|
|
||||||
BAAudioControlWM8731 codecControl; |
|
||||||
BAGpio gpio; // access to User LED
|
|
||||||
|
|
||||||
unsigned long t=0; |
|
||||||
|
|
||||||
void setup() { |
|
||||||
|
|
||||||
MIDI.begin(MIDI_CHANNEL_OMNI); |
|
||||||
Serial.begin(57600); |
|
||||||
delay(5); |
|
||||||
while (!Serial) { yield(); } |
|
||||||
|
|
||||||
// If the codec was already powered up (due to reboot) power itd own first
|
|
||||||
codecControl.disable(); |
|
||||||
delay(100); |
|
||||||
AudioMemory(24); |
|
||||||
|
|
||||||
Serial.println("Enabling codec...\n"); |
|
||||||
codecControl.enable(); |
|
||||||
delay(100); |
|
||||||
|
|
||||||
} |
|
||||||
|
|
||||||
void loop() {
|
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////
|
|
||||||
// MIDI TESTING
|
|
||||||
// Connect a loopback cable between the MIDI IN and MIDI OUT on the
|
|
||||||
// GTA Pro. This test code will periodically send MIDI events which
|
|
||||||
// will loop back and get printed in the Serial Monitor.
|
|
||||||
///////////////////////////////////////////////////////////////////////
|
|
||||||
DataByte note, velocity, channel, d1, d2; |
|
||||||
|
|
||||||
// Send MIDI OUT
|
|
||||||
int cc, val=0xA, channelSend = 1; |
|
||||||
for (cc=32; cc<40; cc++) { |
|
||||||
MIDI.sendControlChange(cc, val, channelSend); val++; channelSend++; |
|
||||||
delay(100); |
|
||||||
MIDI.sendNoteOn(10, 100, channelSend); |
|
||||||
delay(100); |
|
||||||
} |
|
||||||
|
|
||||||
if (MIDI.read()) { // Is there a MIDI message incoming ?
|
|
||||||
MidiType type = MIDI.getType(); |
|
||||||
Serial.println(String("MIDI IS WORKING!!!")); |
|
||||||
switch (type) { |
|
||||||
case NoteOn: |
|
||||||
note = MIDI.getData1(); |
|
||||||
velocity = MIDI.getData2(); |
|
||||||
channel = MIDI.getChannel(); |
|
||||||
if (velocity > 0) { |
|
||||||
Serial.println(String("Note On: ch=") + channel + ", note=" + note + ", velocity=" + velocity); |
|
||||||
} else { |
|
||||||
Serial.println(String("Note Off: ch=") + channel + ", note=" + note); |
|
||||||
} |
|
||||||
break; |
|
||||||
case NoteOff: |
|
||||||
note = MIDI.getData1(); |
|
||||||
velocity = MIDI.getData2(); |
|
||||||
channel = MIDI.getChannel(); |
|
||||||
Serial.println(String("Note Off: ch=") + channel + ", note=" + note + ", velocity=" + velocity); |
|
||||||
break; |
|
||||||
default: |
|
||||||
d1 = MIDI.getData1(); |
|
||||||
d2 = MIDI.getData2(); |
|
||||||
Serial.println(String("Message, type=") + type + ", data = " + d1 + " " + d2); |
|
||||||
} |
|
||||||
t = millis(); |
|
||||||
} |
|
||||||
|
|
||||||
if (millis() - t > 10000) { |
|
||||||
t += 10000; |
|
||||||
Serial.println("(no MIDI activity, check cables)"); |
|
||||||
} |
|
||||||
|
|
||||||
// Toggle the USR LED state
|
|
||||||
gpio.toggleLed(); |
|
||||||
|
|
||||||
} |
|
@ -1,209 +0,0 @@ |
|||||||
/*************************************************************************
|
|
||||||
* This demo uses the BALibrary library to provide enhanced control of |
|
||||||
* the TGA Pro board. |
|
||||||
*
|
|
||||||
* The latest copy of the BA Guitar library can be obtained from |
|
||||||
* https://github.com/Blackaddr/BALibrary
|
|
||||||
*
|
|
||||||
* This demo will provide an audio passthrough, as well as exercise the |
|
||||||
* MIDI interface. |
|
||||||
*
|
|
||||||
* It will also peform a sweep of SPI MEM0. |
|
||||||
*
|
|
||||||
* NOTE: SPI MEM0 can be used by a Teensy 3.1/3.2/3.5/3.6. |
|
||||||
* pins. |
|
||||||
*
|
|
||||||
*/ |
|
||||||
#include <Wire.h> |
|
||||||
#include <Audio.h> |
|
||||||
#include <MIDI.h> |
|
||||||
#include "BALibrary.h" |
|
||||||
|
|
||||||
MIDI_CREATE_DEFAULT_INSTANCE(); |
|
||||||
using namespace midi; |
|
||||||
|
|
||||||
using namespace BALibrary; |
|
||||||
|
|
||||||
AudioInputI2S i2sIn; |
|
||||||
AudioOutputI2S i2sOut; |
|
||||||
|
|
||||||
// Audio Thru Connection
|
|
||||||
AudioConnection patch0(i2sIn,0, i2sOut, 0); |
|
||||||
AudioConnection patch1(i2sIn,1, i2sOut, 1); |
|
||||||
|
|
||||||
BAAudioControlWM8731 codecControl; |
|
||||||
BAGpio gpio; // access to User LED
|
|
||||||
BASpiMemory spiMem0(SpiDeviceId::SPI_DEVICE0); |
|
||||||
|
|
||||||
unsigned long t=0; |
|
||||||
|
|
||||||
// SPI stuff
|
|
||||||
unsigned spiAddress0 = 0; |
|
||||||
uint16_t spiData0 = 0xABCD; |
|
||||||
int spiErrorCount0 = 0; |
|
||||||
|
|
||||||
constexpr int mask0 = 0x5555; |
|
||||||
constexpr int mask1 = 0xaaaa; |
|
||||||
|
|
||||||
int maskPhase = 0; |
|
||||||
int loopPhase = 0; |
|
||||||
|
|
||||||
void setup() { |
|
||||||
|
|
||||||
MIDI.begin(MIDI_CHANNEL_OMNI); |
|
||||||
Serial.begin(57600); |
|
||||||
while (!Serial) { yield(); } |
|
||||||
delay(5); |
|
||||||
|
|
||||||
SPI_MEM0_1M(); // Set the Spi memory size to 1Mbit
|
|
||||||
|
|
||||||
// If the codec was already powered up (due to reboot) power itd own first
|
|
||||||
codecControl.disable(); |
|
||||||
delay(100); |
|
||||||
AudioMemory(24); |
|
||||||
|
|
||||||
Serial.println("Sketch: Enabling codec...\n"); |
|
||||||
codecControl.enable(); |
|
||||||
delay(100); |
|
||||||
|
|
||||||
Serial.println("Enabling SPI"); |
|
||||||
spiMem0.begin(); |
|
||||||
|
|
||||||
} |
|
||||||
|
|
||||||
int calcData(int spiAddress, int loopPhase, int maskPhase) |
|
||||||
{ |
|
||||||
int data; |
|
||||||
|
|
||||||
int phase = ((loopPhase << 1) + maskPhase) & 0x3; |
|
||||||
switch(phase) |
|
||||||
{ |
|
||||||
case 0 : |
|
||||||
data = spiAddress ^ mask0; |
|
||||||
break; |
|
||||||
case 1: |
|
||||||
data = spiAddress ^ mask1; |
|
||||||
break; |
|
||||||
case 2: |
|
||||||
data = ~spiAddress ^ mask0; |
|
||||||
break; |
|
||||||
case 3: |
|
||||||
data = ~spiAddress ^ mask1; |
|
||||||
|
|
||||||
} |
|
||||||
return (data & 0xffff); |
|
||||||
} |
|
||||||
|
|
||||||
void loop() { |
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////
|
|
||||||
// Write test data to the SPI Memory 0
|
|
||||||
//////////////////////////////////////////////////////////////////
|
|
||||||
maskPhase = 0; |
|
||||||
for (spiAddress0=0; spiAddress0 <= BAHardwareConfig.getSpiMemMaxAddr(0); spiAddress0=spiAddress0+2) { |
|
||||||
if ((spiAddress0 % 32768) == 0) { |
|
||||||
//Serial.print("Writing to ");
|
|
||||||
//Serial.println(spiAddress0, HEX);
|
|
||||||
} |
|
||||||
|
|
||||||
spiData0 = calcData(spiAddress0, loopPhase, maskPhase); |
|
||||||
spiMem0.write16(spiAddress0, spiData0); |
|
||||||
maskPhase = (maskPhase+1) % 2; |
|
||||||
} |
|
||||||
Serial.println("SPI0 writing DONE!"); |
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////
|
|
||||||
// Read back from the SPI Memory 0
|
|
||||||
///////////////////////////////////////////////////////////////////
|
|
||||||
spiErrorCount0 = 0; |
|
||||||
spiAddress0 = 0; |
|
||||||
maskPhase = 0; |
|
||||||
|
|
||||||
for (spiAddress0=0; spiAddress0 <= BAHardwareConfig.getSpiMemMaxAddr(0); spiAddress0=spiAddress0+2) { |
|
||||||
if ((spiAddress0 % 32768) == 0) { |
|
||||||
// Serial.print("Reading ");
|
|
||||||
// Serial.print(spiAddress0, HEX);
|
|
||||||
} |
|
||||||
|
|
||||||
spiData0 = calcData(spiAddress0, loopPhase, maskPhase); |
|
||||||
int data = spiMem0.read16(spiAddress0); |
|
||||||
if (data != spiData0) { |
|
||||||
spiErrorCount0++; |
|
||||||
Serial.println(""); |
|
||||||
Serial.print("ERROR MEM0: (expected) (actual):"); |
|
||||||
Serial.print(spiData0, HEX); Serial.print(":"); |
|
||||||
Serial.print(data, HEX); |
|
||||||
|
|
||||||
delay(100); |
|
||||||
} |
|
||||||
maskPhase = (maskPhase+1) % 2; |
|
||||||
|
|
||||||
if ((spiAddress0 % 32768) == 0) { |
|
||||||
// Serial.print(", data = ");
|
|
||||||
// Serial.println(data, HEX);
|
|
||||||
// Serial.println(String(" loopPhase: ") + loopPhase + String(" maskPhase: ") + maskPhase);
|
|
||||||
} |
|
||||||
|
|
||||||
// Break out of test once the error count reaches 10
|
|
||||||
if (spiErrorCount0 > 10) { break; } |
|
||||||
|
|
||||||
} |
|
||||||
|
|
||||||
if (spiErrorCount0 == 0) { Serial.println("SPI0 TEST PASSED!!!"); } |
|
||||||
|
|
||||||
loopPhase = (loopPhase+1) % 2; |
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////
|
|
||||||
// MIDI TESTING
|
|
||||||
// Connect a loopback cable between the MIDI IN and MIDI OUT on the
|
|
||||||
// GTA Pro. This test code will periodically send MIDI events which
|
|
||||||
// will loop back and get printed in the Serial Monitor.
|
|
||||||
///////////////////////////////////////////////////////////////////////
|
|
||||||
DataByte note, velocity, channel, d1, d2; |
|
||||||
|
|
||||||
// Send MIDI OUT
|
|
||||||
int cc, val=0xA, channelSend = 1; |
|
||||||
for (cc=32; cc<40; cc++) { |
|
||||||
MIDI.sendControlChange(cc, val, channelSend); val++; channelSend++; |
|
||||||
delay(100); |
|
||||||
MIDI.sendNoteOn(10, 100, channelSend); |
|
||||||
delay(100); |
|
||||||
} |
|
||||||
|
|
||||||
if (MIDI.read()) { // Is there a MIDI message incoming ?
|
|
||||||
MidiType type = MIDI.getType(); |
|
||||||
Serial.println(String("MIDI IS WORKING!!!")); |
|
||||||
switch (type) { |
|
||||||
case NoteOn: |
|
||||||
note = MIDI.getData1(); |
|
||||||
velocity = MIDI.getData2(); |
|
||||||
channel = MIDI.getChannel(); |
|
||||||
if (velocity > 0) { |
|
||||||
Serial.println(String("Note On: ch=") + channel + ", note=" + note + ", velocity=" + velocity); |
|
||||||
} else { |
|
||||||
Serial.println(String("Note Off: ch=") + channel + ", note=" + note); |
|
||||||
} |
|
||||||
break; |
|
||||||
case NoteOff: |
|
||||||
note = MIDI.getData1(); |
|
||||||
velocity = MIDI.getData2(); |
|
||||||
channel = MIDI.getChannel(); |
|
||||||
Serial.println(String("Note Off: ch=") + channel + ", note=" + note + ", velocity=" + velocity); |
|
||||||
break; |
|
||||||
default: |
|
||||||
d1 = MIDI.getData1(); |
|
||||||
d2 = MIDI.getData2(); |
|
||||||
Serial.println(String("Message, type=") + type + ", data = " + d1 + " " + d2); |
|
||||||
} |
|
||||||
t = millis(); |
|
||||||
} |
|
||||||
|
|
||||||
if (millis() - t > 10000) { |
|
||||||
t += 10000; |
|
||||||
Serial.println("(no MIDI activity, check cables)"); |
|
||||||
} |
|
||||||
|
|
||||||
// Toggle the USR LED state
|
|
||||||
gpio.toggleLed(); |
|
||||||
|
|
||||||
} |
|
@ -1,271 +0,0 @@ |
|||||||
/*************************************************************************
|
|
||||||
* This demo uses the BALibrary library to provide enhanced control of |
|
||||||
* the TGA Pro board. |
|
||||||
*
|
|
||||||
* The latest copy of the BA Guitar library can be obtained from |
|
||||||
* https://github.com/Blackaddr/BALibrary
|
|
||||||
*
|
|
||||||
* This demo will provide an audio passthrough, as well as exercise the |
|
||||||
* MIDI interface. |
|
||||||
*
|
|
||||||
* It will also peform a sweep of SPI MEM0 and MEM1. |
|
||||||
*
|
|
||||||
* NOTE: SPI MEM0 can be used by a Teensy 3.1/3.2/3.5/3.6. SPI MEM1 |
|
||||||
* can only be used by a Teensy 3.5/3.6 since it is mapped to the extended |
|
||||||
* pins. |
|
||||||
*
|
|
||||||
*/ |
|
||||||
#include <Wire.h> |
|
||||||
#include <Audio.h> |
|
||||||
#include <MIDI.h> |
|
||||||
#include "BALibrary.h" |
|
||||||
|
|
||||||
MIDI_CREATE_DEFAULT_INSTANCE(); |
|
||||||
using namespace midi; |
|
||||||
using namespace BALibrary; |
|
||||||
|
|
||||||
AudioInputI2S i2sIn; |
|
||||||
AudioOutputI2S i2sOut; |
|
||||||
|
|
||||||
// Audio Thru Connection
|
|
||||||
AudioConnection patch0(i2sIn,0, i2sOut, 0); |
|
||||||
AudioConnection patch1(i2sIn,1, i2sOut, 1); |
|
||||||
|
|
||||||
BAAudioControlWM8731 codecControl; |
|
||||||
BAGpio gpio; // access to User LED
|
|
||||||
BASpiMemory spiMem0(SpiDeviceId::SPI_DEVICE0); |
|
||||||
BASpiMemory spiMem1(SpiDeviceId::SPI_DEVICE1); |
|
||||||
|
|
||||||
unsigned long t=0; |
|
||||||
|
|
||||||
// SPI stuff
|
|
||||||
int spiAddress0 = 0; |
|
||||||
uint16_t spiData0 = 0xABCD; |
|
||||||
int spiErrorCount0 = 0; |
|
||||||
|
|
||||||
int spiAddress1 = 0; |
|
||||||
uint16_t spiData1 = 0xDCBA; |
|
||||||
int spiErrorCount1 = 0; |
|
||||||
|
|
||||||
constexpr int mask0 = 0x5555; |
|
||||||
constexpr int mask1 = 0xaaaa; |
|
||||||
|
|
||||||
int maskPhase = 0; |
|
||||||
int loopPhase = 0; |
|
||||||
|
|
||||||
void setup() { |
|
||||||
|
|
||||||
MIDI.begin(MIDI_CHANNEL_OMNI); |
|
||||||
Serial.begin(57600); |
|
||||||
while (!Serial) { yield(); } |
|
||||||
delay(5); |
|
||||||
|
|
||||||
// Set the SPI memory sizes
|
|
||||||
SPI_MEM0_1M(); |
|
||||||
SPI_MEM1_1M(); |
|
||||||
|
|
||||||
// If the codec was already powered up (due to reboot) power itd own first
|
|
||||||
codecControl.disable(); |
|
||||||
delay(100); |
|
||||||
AudioMemory(24); |
|
||||||
|
|
||||||
Serial.println("Sketch: Enabling codec...\n"); |
|
||||||
codecControl.enable(); |
|
||||||
delay(100); |
|
||||||
|
|
||||||
Serial.println("Enabling SPI"); |
|
||||||
spiMem0.begin(); |
|
||||||
spiMem1.begin(); |
|
||||||
|
|
||||||
} |
|
||||||
|
|
||||||
int calcData(int spiAddress, int loopPhase, int maskPhase) |
|
||||||
{ |
|
||||||
int data; |
|
||||||
|
|
||||||
int phase = ((loopPhase << 1) + maskPhase) & 0x3; |
|
||||||
switch(phase) |
|
||||||
{ |
|
||||||
case 0 : |
|
||||||
data = spiAddress ^ mask0; |
|
||||||
break; |
|
||||||
case 1: |
|
||||||
data = spiAddress ^ mask1; |
|
||||||
break; |
|
||||||
case 2: |
|
||||||
data = ~spiAddress ^ mask0; |
|
||||||
break; |
|
||||||
case 3: |
|
||||||
data = ~spiAddress ^ mask1; |
|
||||||
|
|
||||||
} |
|
||||||
return (data & 0xffff); |
|
||||||
} |
|
||||||
|
|
||||||
void loop() { |
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////
|
|
||||||
// Write test data to the SPI Memory 0
|
|
||||||
//////////////////////////////////////////////////////////////////
|
|
||||||
maskPhase = 0; |
|
||||||
for (spiAddress0=0; spiAddress0 <= BAHardwareConfig.getSpiMemMaxAddr(0); spiAddress0=spiAddress0+2) { |
|
||||||
if ((spiAddress0 % 32768) == 0) { |
|
||||||
//Serial.print("Writing to ");
|
|
||||||
//Serial.println(spiAddress0, HEX);
|
|
||||||
} |
|
||||||
|
|
||||||
spiData0 = calcData(spiAddress0, loopPhase, maskPhase); |
|
||||||
spiMem0.write16(spiAddress0, spiData0); |
|
||||||
maskPhase = (maskPhase+1) % 2; |
|
||||||
} |
|
||||||
Serial.println("SPI0 writing DONE!"); |
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////
|
|
||||||
// Read back from the SPI Memory 0
|
|
||||||
///////////////////////////////////////////////////////////////////
|
|
||||||
spiErrorCount0 = 0; |
|
||||||
spiAddress0 = 0; |
|
||||||
maskPhase = 0; |
|
||||||
|
|
||||||
for (spiAddress0=0; spiAddress0 <= BAHardwareConfig.getSpiMemMaxAddr(0); spiAddress0=spiAddress0+2) { |
|
||||||
if ((spiAddress0 % 32768) == 0) { |
|
||||||
// Serial.print("Reading ");
|
|
||||||
// Serial.print(spiAddress0, HEX);
|
|
||||||
} |
|
||||||
|
|
||||||
spiData0 = calcData(spiAddress0, loopPhase, maskPhase); |
|
||||||
int data = spiMem0.read16(spiAddress0); |
|
||||||
if (data != spiData0) { |
|
||||||
spiErrorCount0++; |
|
||||||
Serial.println(""); |
|
||||||
Serial.print("ERROR MEM0: (expected) (actual):"); |
|
||||||
Serial.print(spiData0, HEX); Serial.print(":"); |
|
||||||
Serial.print(data, HEX); |
|
||||||
|
|
||||||
delay(100); |
|
||||||
} |
|
||||||
maskPhase = (maskPhase+1) % 2; |
|
||||||
|
|
||||||
if ((spiAddress0 % 32768) == 0) { |
|
||||||
// Serial.print(", data = ");
|
|
||||||
// Serial.println(data, HEX);
|
|
||||||
// Serial.println(String(" loopPhase: ") + loopPhase + String(" maskPhase: ") + maskPhase);
|
|
||||||
} |
|
||||||
|
|
||||||
// Break out of test once the error count reaches 10
|
|
||||||
if (spiErrorCount0 > 10) { break; } |
|
||||||
|
|
||||||
} |
|
||||||
|
|
||||||
if (spiErrorCount0 == 0) { Serial.println("SPI0 TEST PASSED!!!"); } |
|
||||||
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////
|
|
||||||
// Write test data to the SPI Memory 1
|
|
||||||
//////////////////////////////////////////////////////////////////
|
|
||||||
maskPhase = 0; |
|
||||||
for (spiAddress1=0; spiAddress1 <= BAHardwareConfig.getSpiMemMaxAddr(1); spiAddress1+=2) { |
|
||||||
if ((spiAddress1 % 32768) == 0) { |
|
||||||
//Serial.print("Writing to ");
|
|
||||||
//Serial.println(spiAddress1, HEX);
|
|
||||||
} |
|
||||||
|
|
||||||
spiData1 = calcData(spiAddress1, loopPhase, maskPhase); |
|
||||||
spiMem1.write16(spiAddress1, spiData1); |
|
||||||
maskPhase = (maskPhase+1) % 2; |
|
||||||
} |
|
||||||
Serial.println("SPI1 writing DONE!"); |
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////
|
|
||||||
// Read back from the SPI Memory 1
|
|
||||||
///////////////////////////////////////////////////////////////////
|
|
||||||
spiErrorCount1 = 0; |
|
||||||
spiAddress1 = 0; |
|
||||||
|
|
||||||
maskPhase = 0; |
|
||||||
for (spiAddress1=0; spiAddress1 <= BAHardwareConfig.getSpiMemMaxAddr(1); spiAddress1+=2) { |
|
||||||
if ((spiAddress1 % 32768) == 0) { |
|
||||||
//Serial.print("Reading ");
|
|
||||||
//Serial.print(spiAddress1, HEX);
|
|
||||||
} |
|
||||||
|
|
||||||
spiData1 = calcData(spiAddress1, loopPhase, maskPhase); |
|
||||||
uint16_t data = spiMem1.read16(spiAddress1); |
|
||||||
if (data != spiData1) { |
|
||||||
spiErrorCount1++; |
|
||||||
Serial.println(""); |
|
||||||
Serial.print("ERROR MEM1: (expected) (actual):"); |
|
||||||
Serial.print(spiData1, HEX); Serial.print(":"); |
|
||||||
Serial.println(data, HEX); |
|
||||||
delay(100); |
|
||||||
} |
|
||||||
maskPhase = (maskPhase+1) % 2; |
|
||||||
|
|
||||||
if ((spiAddress1 % 32768) == 0) { |
|
||||||
//Serial.print(", data = ");
|
|
||||||
//Serial.println(data, HEX);
|
|
||||||
} |
|
||||||
|
|
||||||
// Break out of test once the error count reaches 10
|
|
||||||
if (spiErrorCount1 > 10) { break; } |
|
||||||
|
|
||||||
} |
|
||||||
|
|
||||||
if (spiErrorCount1 == 0) { Serial.println("SPI1 TEST PASSED!!!"); } |
|
||||||
|
|
||||||
loopPhase = (loopPhase+1) % 2; |
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////
|
|
||||||
// MIDI TESTING
|
|
||||||
// Connect a loopback cable between the MIDI IN and MIDI OUT on the
|
|
||||||
// GTA Pro. This test code will periodically send MIDI events which
|
|
||||||
// will loop back and get printed in the Serial Monitor.
|
|
||||||
///////////////////////////////////////////////////////////////////////
|
|
||||||
DataByte note, velocity, channel, d1, d2; |
|
||||||
|
|
||||||
// Send MIDI OUT
|
|
||||||
int cc, val=0xA, channelSend = 1; |
|
||||||
for (cc=32; cc<40; cc++) { |
|
||||||
MIDI.sendControlChange(cc, val, channelSend); val++; channelSend++; |
|
||||||
delay(100); |
|
||||||
MIDI.sendNoteOn(10, 100, channelSend); |
|
||||||
delay(100); |
|
||||||
} |
|
||||||
|
|
||||||
if (MIDI.read()) { // Is there a MIDI message incoming ?
|
|
||||||
MidiType type = MIDI.getType(); |
|
||||||
Serial.println(String("MIDI IS WORKING!!!")); |
|
||||||
switch (type) { |
|
||||||
case NoteOn: |
|
||||||
note = MIDI.getData1(); |
|
||||||
velocity = MIDI.getData2(); |
|
||||||
channel = MIDI.getChannel(); |
|
||||||
if (velocity > 0) { |
|
||||||
Serial.println(String("Note On: ch=") + channel + ", note=" + note + ", velocity=" + velocity); |
|
||||||
} else { |
|
||||||
Serial.println(String("Note Off: ch=") + channel + ", note=" + note); |
|
||||||
} |
|
||||||
break; |
|
||||||
case NoteOff: |
|
||||||
note = MIDI.getData1(); |
|
||||||
velocity = MIDI.getData2(); |
|
||||||
channel = MIDI.getChannel(); |
|
||||||
Serial.println(String("Note Off: ch=") + channel + ", note=" + note + ", velocity=" + velocity); |
|
||||||
break; |
|
||||||
default: |
|
||||||
d1 = MIDI.getData1(); |
|
||||||
d2 = MIDI.getData2(); |
|
||||||
Serial.println(String("Message, type=") + type + ", data = " + d1 + " " + d2); |
|
||||||
} |
|
||||||
t = millis(); |
|
||||||
} |
|
||||||
|
|
||||||
if (millis() - t > 10000) { |
|
||||||
t += 10000; |
|
||||||
Serial.println("(no MIDI activity, check cables)"); |
|
||||||
} |
|
||||||
|
|
||||||
// Toggle the USR LED state
|
|
||||||
gpio.toggleLed(); |
|
||||||
|
|
||||||
} |
|
@ -1,76 +0,0 @@ |
|||||||
/*************************************************************************
|
|
||||||
* This demo uses the BALibrary library to provide enhanced control of |
|
||||||
* the TGA Pro board. |
|
||||||
*
|
|
||||||
* The latest copy of the BA Guitar library can be obtained from |
|
||||||
* https://github.com/Blackaddr/BALibrary
|
|
||||||
*
|
|
||||||
* This demo provides an example guitar tone consisting of some slap-back delay, |
|
||||||
* followed by a reverb and a low-pass cabinet filter. |
|
||||||
*
|
|
||||||
*/ |
|
||||||
#include <Wire.h> |
|
||||||
#include <Audio.h> |
|
||||||
#include <MIDI.h> |
|
||||||
#include "BALibrary.h" |
|
||||||
|
|
||||||
using namespace BALibrary; |
|
||||||
|
|
||||||
BAAudioControlWM8731 codecControl; |
|
||||||
|
|
||||||
AudioInputI2S i2sIn; |
|
||||||
AudioOutputI2S i2sOut; |
|
||||||
|
|
||||||
AudioMixer4 gainModule; // This will be used simply to reduce the gain before the reverb
|
|
||||||
AudioEffectDelay delayModule; // we'll add a little slapback echo
|
|
||||||
AudioEffectReverb reverb; // Add a bit of 'verb to our tone
|
|
||||||
AudioMixer4 mixer; // Used to mix the original dry with the wet (effects) path.
|
|
||||||
AudioFilterBiquad cabFilter; // We'll want something to cut out the highs and smooth the tone, just like a guitar cab.
|
|
||||||
|
|
||||||
|
|
||||||
// Audio Connections
|
|
||||||
AudioConnection patchIn(i2sIn,0, delayModule, 0); // route the input to the delay
|
|
||||||
|
|
||||||
AudioConnection patch2(delayModule,0, gainModule, 0); // send the delay to the gain module
|
|
||||||
AudioConnection patch2b(gainModule, 0, reverb, 0); // then to the reverb
|
|
||||||
|
|
||||||
|
|
||||||
AudioConnection patch1(i2sIn,0, mixer,0); // mixer input 0 is our original dry signal
|
|
||||||
AudioConnection patch3(reverb, 0, mixer, 1); // mixer input 1 is our wet
|
|
||||||
|
|
||||||
AudioConnection patch4(mixer, 0, cabFilter, 0); // mixer outpt to the cabinet filter
|
|
||||||
|
|
||||||
|
|
||||||
AudioConnection patch5(cabFilter, 0, i2sOut, 0); // connect the cab filter to the output.
|
|
||||||
AudioConnection patch5b(cabFilter, 0, i2sOut, 1); // connect the cab filter to the output.
|
|
||||||
|
|
||||||
void setup() { |
|
||||||
|
|
||||||
delay(5); // wait a few ms to make sure the GTA Pro is fully powered up
|
|
||||||
AudioMemory(48); |
|
||||||
|
|
||||||
// If the codec was already powered up (due to reboot) power itd own first
|
|
||||||
codecControl.disable(); |
|
||||||
delay(100); |
|
||||||
codecControl.enable(); |
|
||||||
delay(100); |
|
||||||
|
|
||||||
// Configure our effects
|
|
||||||
delayModule.delay(0, 50.0f); // 50 ms slapback delay
|
|
||||||
gainModule.gain(0, 0.25); // the reverb unit clips easily if the input is too high
|
|
||||||
mixer.gain(0, 1.0f); // unity gain on the dry
|
|
||||||
mixer.gain(1, 1.0f); // unity gain on the wet
|
|
||||||
|
|
||||||
// Setup 2-stages of LPF, cutoff 4500 Hz, Q-factor 0.7071 (a 'normal' Q-factor)
|
|
||||||
cabFilter.setLowpass(0, 4500, .7071); |
|
||||||
cabFilter.setLowpass(1, 4500, .7071); |
|
||||||
|
|
||||||
|
|
||||||
} |
|
||||||
|
|
||||||
void loop() {
|
|
||||||
|
|
||||||
// The audio flows automatically through the Teensy Audio Library
|
|
||||||
|
|
||||||
} |
|
||||||
|
|
@ -1,80 +0,0 @@ |
|||||||
#include "BALibrary.h" |
|
||||||
using namespace BALibrary; |
|
||||||
|
|
||||||
constexpr int potCalibMin = 8; |
|
||||||
constexpr int potCalibMax = 1016; |
|
||||||
constexpr bool potSwapDirection = true; |
|
||||||
int pot1Handle, pot2Handle, pot3Handle, sw1Handle, sw2Handle, led1Handle, led2Handle; |
|
||||||
bool mute = false; |
|
||||||
BAAudioControlWM8731 *codecPtr = nullptr; |
|
||||||
BAPhysicalControls *controlPtr = nullptr; |
|
||||||
|
|
||||||
void configPhysicalControls(BAPhysicalControls &controls, BAAudioControlWM8731 &codec) |
|
||||||
{ |
|
||||||
// Setup the controls. The return value is the handle to use when checking for control changes, etc.
|
|
||||||
|
|
||||||
// pushbuttons
|
|
||||||
sw1Handle = controls.addSwitch(BA_EXPAND_SW1_PIN); |
|
||||||
sw2Handle = controls.addSwitch(BA_EXPAND_SW2_PIN); |
|
||||||
// pots
|
|
||||||
pot1Handle = controls.addPot(BA_EXPAND_POT1_PIN, potCalibMin, potCalibMax, potSwapDirection); |
|
||||||
pot2Handle = controls.addPot(BA_EXPAND_POT2_PIN, potCalibMin, potCalibMax, potSwapDirection);
|
|
||||||
pot3Handle = controls.addPot(BA_EXPAND_POT3_PIN, potCalibMin, potCalibMax, potSwapDirection);
|
|
||||||
// leds
|
|
||||||
led1Handle = controls.addOutput(BA_EXPAND_LED1_PIN); |
|
||||||
led2Handle = controls.addOutput(BA_EXPAND_LED2_PIN); // will illuminate when pressing SW2
|
|
||||||
|
|
||||||
controlPtr = &controls; |
|
||||||
codecPtr = &codec; |
|
||||||
} |
|
||||||
|
|
||||||
void checkPot(unsigned id) |
|
||||||
{ |
|
||||||
float potValue; |
|
||||||
unsigned handle; |
|
||||||
switch(id) { |
|
||||||
case 0 : |
|
||||||
handle = pot1Handle; |
|
||||||
break; |
|
||||||
case 1 : |
|
||||||
handle = pot2Handle; |
|
||||||
break; |
|
||||||
case 2 : |
|
||||||
handle = pot3Handle; |
|
||||||
break; |
|
||||||
default : |
|
||||||
handle = pot1Handle; |
|
||||||
} |
|
||||||
|
|
||||||
if (controlPtr->checkPotValue(handle, potValue)) { |
|
||||||
// Pot has changed
|
|
||||||
codecPtr->setHeadphoneVolume(potValue); |
|
||||||
Serial.println(String("POT") + id + String(" value: ") + potValue); |
|
||||||
}
|
|
||||||
} |
|
||||||
|
|
||||||
void checkSwitch(unsigned id) |
|
||||||
{ |
|
||||||
unsigned swHandle; |
|
||||||
unsigned ledHandle; |
|
||||||
switch(id) { |
|
||||||
case 0 : |
|
||||||
swHandle = sw1Handle; |
|
||||||
ledHandle = led1Handle; |
|
||||||
break; |
|
||||||
case 1 : |
|
||||||
swHandle = sw2Handle; |
|
||||||
ledHandle = led2Handle; |
|
||||||
break; |
|
||||||
default : |
|
||||||
swHandle = sw1Handle; |
|
||||||
ledHandle = led1Handle; |
|
||||||
} |
|
||||||
|
|
||||||
if (controlPtr->isSwitchToggled(swHandle)) { |
|
||||||
Serial.println(String("Button ") + id + String(" pressed")); |
|
||||||
} |
|
||||||
|
|
||||||
bool pressed = controlPtr->isSwitchHeld(swHandle); |
|
||||||
controlPtr->setOutput(ledHandle, pressed); |
|
||||||
} |
|
@ -1,140 +0,0 @@ |
|||||||
/*************************************************************************
|
|
||||||
* This demo is used for manufacturing testing on the TGA Pro Expansion |
|
||||||
* Control Board. |
|
||||||
*
|
|
||||||
* This will test the following on the TGA Pro: |
|
||||||
*
|
|
||||||
* - Audio INPUT and OUTPUT JACKS |
|
||||||
* - Midi INPUT and Midi OUTPUT jacks |
|
||||||
* - MEM0 (if installed) |
|
||||||
* - MEM1 (if installed) |
|
||||||
* - User LED |
|
||||||
*
|
|
||||||
* This will also test the Expansion Control Board (if installed): |
|
||||||
*
|
|
||||||
* - three POT knobs |
|
||||||
* - two pushbutton SWitches |
|
||||||
* - two LEDs |
|
||||||
* - headphone output |
|
||||||
*
|
|
||||||
* SETUP INSTRUCTIONS: |
|
||||||
*
|
|
||||||
* 1) Connect an audio source to AUDIO INPUT. |
|
||||||
* 2) Connect AUDIO OUTPUT to amp, stereo, headphone amplifier, etc. |
|
||||||
* 3) if testing the MIDI ports, connect a MIDI cable between MIDI INPUT and MIDI OUTPUT |
|
||||||
* 4) comment out any tests you want to skip |
|
||||||
* 5) Compile and run the demo on your Teensy with TGA Pro. |
|
||||||
* 6) Launch the Arduino Serial Monitor to see results. |
|
||||||
*
|
|
||||||
* TESTING INSTRUCTIONS: |
|
||||||
*
|
|
||||||
* 1) Check the Serial Monitor for the results of the MIDI testing, and external memory testing. |
|
||||||
* 2) Confirm that the audio sent to the INPUT is coming out the OUTPUT. |
|
||||||
* 3) Confirm the User LED is blinking every 1 or 2 seconds |
|
||||||
*
|
|
||||||
* If using the Expansion Control Board: |
|
||||||
*
|
|
||||||
* 1) Try pushing the pushbuttons. When pushed, they should turn on their corresponding LED. |
|
||||||
* 2) Try turn each of the knobs one at a time. They should adjust the volume. |
|
||||||
*
|
|
||||||
* The latest copy of the BA Guitar library can be obtained from |
|
||||||
* https://github.com/Blackaddr/BALibrary
|
|
||||||
*
|
|
||||||
*/ |
|
||||||
|
|
||||||
#define RUN_MIDI_TEST // Uncomment this line to run the MIDI test.
|
|
||||||
#define RUN_MEMO_TEST // Uncomment this line to run the MEM0 test.
|
|
||||||
//#define RUN_MEM1_TEST // (Teensy 3.5/3/6 only!) Uncomment this line to run the MEM1 test.
|
|
||||||
#define RUN_EXP_TEST // Test the Expansion board controls
|
|
||||||
|
|
||||||
#include <Audio.h> |
|
||||||
#include "BALibrary.h" |
|
||||||
|
|
||||||
using namespace BALibrary; |
|
||||||
|
|
||||||
AudioInputI2S i2sIn; |
|
||||||
AudioOutputI2S i2sOut; |
|
||||||
|
|
||||||
// Audio Thru Connection
|
|
||||||
AudioConnection patch0(i2sIn,0, i2sOut, 0); |
|
||||||
AudioConnection patch1(i2sIn,1, i2sOut, 1); |
|
||||||
|
|
||||||
BAAudioControlWM8731 codec; |
|
||||||
BAGpio gpio; // access to User LED
|
|
||||||
|
|
||||||
#if defined(RUN_MEMO_TEST) |
|
||||||
BASpiMemoryDMA spiMem0(SpiDeviceId::SPI_DEVICE0); |
|
||||||
#endif |
|
||||||
|
|
||||||
#if defined(RUN_MEM1_TEST) && !defined(__IMXRT1062__) // SPI1 not supported on T4.0
|
|
||||||
BASpiMemoryDMA spiMem1(SpiDeviceId::SPI_DEVICE1); |
|
||||||
#endif |
|
||||||
|
|
||||||
// Create a control object using the number of switches, pots, encoders and outputs on the
|
|
||||||
// Blackaddr Audio Expansion Board.
|
|
||||||
BAPhysicalControls controls(BA_EXPAND_NUM_SW, BA_EXPAND_NUM_POT, BA_EXPAND_NUM_ENC, BA_EXPAND_NUM_LED); |
|
||||||
|
|
||||||
void configPhysicalControls(BAPhysicalControls &controls, BAAudioControlWM8731 &codec); |
|
||||||
void checkPot(unsigned id); |
|
||||||
void checkSwitch(unsigned id); |
|
||||||
bool spiTest(BASpiMemory *mem, int id); // returns true if passed
|
|
||||||
bool uartTest(); // returns true if passed
|
|
||||||
|
|
||||||
unsigned loopCounter = 0; |
|
||||||
|
|
||||||
void setup() { |
|
||||||
Serial.begin(57600); |
|
||||||
//while (!Serial) { yield(); }
|
|
||||||
delay(500); |
|
||||||
|
|
||||||
// Disable the audio codec first
|
|
||||||
codec.disable(); |
|
||||||
delay(100); |
|
||||||
AudioMemory(128); |
|
||||||
codec.enable(); |
|
||||||
codec.setHeadphoneVolume(0.8f); // Set headphone volume
|
|
||||||
configPhysicalControls(controls, codec); |
|
||||||
|
|
||||||
TGA_PRO_MKII_REV1(); |
|
||||||
TGA_PRO_EXPAND_REV3(); // Macro to declare expansion board revision
|
|
||||||
|
|
||||||
// Run the initial Midi connectivity and SPI memory tests.
|
|
||||||
#if defined(RUN_MIDI_TEST) |
|
||||||
if (uartTest()) { Serial.println("MIDI Ports testing PASSED!"); } |
|
||||||
#endif |
|
||||||
|
|
||||||
#if defined(RUN_MEMO_TEST) |
|
||||||
//SPI_MEM0_1M();
|
|
||||||
SPI_MEM0_4M(); |
|
||||||
spiMem0.begin(); delay(10); |
|
||||||
if (spiTest(&spiMem0, 0)) { Serial.println("SPI0 testing PASSED!");} |
|
||||||
#endif |
|
||||||
|
|
||||||
#if defined(RUN_MEM1_TEST) && !defined(__IMXRT1062__) |
|
||||||
SPI_MEM1_1M(); |
|
||||||
//SPI_MEM1_4M();
|
|
||||||
spiMem1.begin(); delay(10); |
|
||||||
if (spiTest(&spiMem1, 1)) { Serial.println("SPI1 testing PASSED!");} |
|
||||||
#endif |
|
||||||
|
|
||||||
#if defined(RUN_EXP_TEST) |
|
||||||
Serial.println("Now monitoring for input from Expansion Control Board"); |
|
||||||
#endif |
|
||||||
} |
|
||||||
|
|
||||||
void loop() { |
|
||||||
|
|
||||||
#if defined(RUN_EXP_TEST) |
|
||||||
checkPot(0); |
|
||||||
checkPot(1); |
|
||||||
checkPot(2); |
|
||||||
checkSwitch(0); |
|
||||||
checkSwitch(1); |
|
||||||
#endif |
|
||||||
|
|
||||||
delay(20); |
|
||||||
loopCounter++; |
|
||||||
if ((loopCounter % 100) == 0) { |
|
||||||
gpio.toggleLed(); |
|
||||||
} |
|
||||||
} |
|
@ -1,81 +0,0 @@ |
|||||||
#include "BAHardware.h" |
|
||||||
#include "BASpiMemory.h" |
|
||||||
|
|
||||||
using namespace BALibrary; |
|
||||||
|
|
||||||
constexpr unsigned MIDI_RATE = 31250; |
|
||||||
constexpr unsigned HIGH_RATE = 230400;
|
|
||||||
constexpr unsigned TEST_TIME = 5; // 5 second test each
|
|
||||||
|
|
||||||
static unsigned baudRate = MIDI_RATE; // start with low speed
|
|
||||||
static uint8_t writeData = 0; |
|
||||||
static unsigned loopCounter = 0; |
|
||||||
static unsigned errorCount = 0; |
|
||||||
static bool testFailed = false; |
|
||||||
static bool testDone = false; |
|
||||||
static unsigned testPhase = 0; // 0 for MIDI speed, 1 for high speed.
|
|
||||||
|
|
||||||
bool uartTest(void) |
|
||||||
{ |
|
||||||
Serial1.begin(baudRate, SERIAL_8N1); |
|
||||||
delay(100); |
|
||||||
while(!Serial) {} |
|
||||||
Serial.println(String("\nRunning MIDI Port speed test at ") + baudRate); |
|
||||||
|
|
||||||
// write the first data
|
|
||||||
Serial1.write(writeData); |
|
||||||
|
|
||||||
while(!testFailed && !testDone) { |
|
||||||
|
|
||||||
if (loopCounter >= (baudRate/4)) { // the divisor determines how long the test runs for
|
|
||||||
// next test
|
|
||||||
switch (testPhase) { |
|
||||||
case 0 : |
|
||||||
baudRate = HIGH_RATE; |
|
||||||
break; |
|
||||||
case 1 : |
|
||||||
testDone = true; |
|
||||||
} |
|
||||||
|
|
||||||
if (errorCount == 0) { Serial.println("TEST PASSED!"); } |
|
||||||
else {
|
|
||||||
Serial.println("MIDI PORT TEST FAILED!"); |
|
||||||
} |
|
||||||
errorCount = 0; |
|
||||||
testPhase++; |
|
||||||
loopCounter = 0; |
|
||||||
|
|
||||||
if (!testDone) { |
|
||||||
Serial.println(String("\nRunning MIDI Port speed test at ") + baudRate); |
|
||||||
Serial1.begin(baudRate, SERIAL_8N1); |
|
||||||
while (!Serial1) {} // wait for serial to be ready
|
|
||||||
} else { |
|
||||||
Serial.println("MIDI PORT TEST DONE!\n"); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
// Wait for read data
|
|
||||||
if (Serial1.available()) {
|
|
||||||
uint8_t readData= Serial1.read(); |
|
||||||
if (readData != writeData) { |
|
||||||
Serial.println(String("MIDI ERROR: readData = ") + readData + String(" writeData = ") + writeData); |
|
||||||
errorCount++; |
|
||||||
} |
|
||||||
|
|
||||||
if ((loopCounter % (baudRate/64)) == 0) { // the divisor determines how often the period is printed
|
|
||||||
Serial.print("."); Serial.flush(); |
|
||||||
} |
|
||||||
|
|
||||||
if (errorCount > 16) { |
|
||||||
Serial.println("Halting test"); |
|
||||||
testFailed = true; |
|
||||||
} |
|
||||||
|
|
||||||
loopCounter++; |
|
||||||
writeData++; |
|
||||||
Serial1.write(writeData); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
return testFailed; |
|
||||||
} |
|
@ -1,129 +0,0 @@ |
|||||||
#include <cstddef> |
|
||||||
#include <cstdint> |
|
||||||
#include "BAHardware.h" |
|
||||||
#include "BASpiMemory.h" |
|
||||||
|
|
||||||
constexpr int NUM_TESTS = 12; |
|
||||||
constexpr int NUM_BLOCK_WORDS = 128; |
|
||||||
constexpr int mask0 = 0x5555; |
|
||||||
constexpr int mask1 = 0xaaaa; |
|
||||||
|
|
||||||
//#define SANITY_CHECK
|
|
||||||
|
|
||||||
using namespace BALibrary; |
|
||||||
|
|
||||||
int SPI_MAX_ADDR = 0; |
|
||||||
|
|
||||||
int calcData(int spiAddress, int loopPhase, int maskPhase) |
|
||||||
{ |
|
||||||
int data; |
|
||||||
|
|
||||||
int phase = ((loopPhase << 1) + maskPhase) & 0x3; |
|
||||||
switch(phase) |
|
||||||
{ |
|
||||||
case 0 : |
|
||||||
data = spiAddress ^ mask0; |
|
||||||
break; |
|
||||||
case 1: |
|
||||||
data = spiAddress ^ mask1; |
|
||||||
break; |
|
||||||
case 2: |
|
||||||
data = ~spiAddress ^ mask0; |
|
||||||
break; |
|
||||||
case 3: |
|
||||||
data = ~spiAddress ^ mask1; |
|
||||||
|
|
||||||
} |
|
||||||
return (data & 0xffff); |
|
||||||
} |
|
||||||
|
|
||||||
bool spiTest(BASpiMemory *mem, int id) |
|
||||||
{ |
|
||||||
int spiAddress = 0; |
|
||||||
int spiErrorCount = 0; |
|
||||||
|
|
||||||
int maskPhase = 0; |
|
||||||
int loopPhase = 0; |
|
||||||
uint16_t memBlock[NUM_BLOCK_WORDS]; |
|
||||||
uint16_t goldData[NUM_BLOCK_WORDS]; |
|
||||||
|
|
||||||
SPI_MAX_ADDR = BAHardwareConfig.getSpiMemMaxAddr(0); // assume for this test both memories are the same size so use MEM0
|
|
||||||
const size_t SPI_MEM_SIZE_BYTES = BAHardwareConfig.getSpiMemSizeBytes(id); |
|
||||||
|
|
||||||
Serial.println(String("Starting SPI MEM Test of ") + SPI_MEM_SIZE_BYTES + String(" bytes")); |
|
||||||
|
|
||||||
for (int cnt = 0; cnt < NUM_TESTS; cnt++) { |
|
||||||
|
|
||||||
// Zero check
|
|
||||||
mem->zero16(0, SPI_MEM_SIZE_BYTES / sizeof(uint16_t));
|
|
||||||
while (mem->isWriteBusy()) {} |
|
||||||
|
|
||||||
for (spiAddress = 0; spiAddress <= SPI_MAX_ADDR; spiAddress += NUM_BLOCK_WORDS*sizeof(uint16_t)) { |
|
||||||
mem->read16(spiAddress, memBlock, NUM_BLOCK_WORDS); |
|
||||||
while (mem->isReadBusy()) {} |
|
||||||
for (int i=0; i<NUM_BLOCK_WORDS; i++) { |
|
||||||
if (memBlock[i] != 0) { |
|
||||||
spiErrorCount++; |
|
||||||
if (spiErrorCount >= 10) break; |
|
||||||
} |
|
||||||
} |
|
||||||
if (spiErrorCount >= 10) break; |
|
||||||
} |
|
||||||
|
|
||||||
//if (spiErrorCount == 0) { Serial.println(String("SPI MEMORY(") + cnt + String("): Zero test PASSED!")); }
|
|
||||||
if (spiErrorCount == 0) { Serial.print("."); Serial.flush(); } |
|
||||||
if (spiErrorCount > 0) { Serial.println(String("SPI MEMORY(") + cnt + String("): Zero test FAILED, error count = ") + spiErrorCount); return false;} |
|
||||||
|
|
||||||
|
|
||||||
// Write all test data to the memory
|
|
||||||
maskPhase = 0; |
|
||||||
for (spiAddress = 0; spiAddress <= SPI_MAX_ADDR; spiAddress += NUM_BLOCK_WORDS*sizeof(uint16_t)) {
|
|
||||||
// Calculate the data for a block
|
|
||||||
for (int i=0; i<NUM_BLOCK_WORDS; i++) { |
|
||||||
memBlock[i] = calcData(spiAddress+i, loopPhase, maskPhase); |
|
||||||
maskPhase = (maskPhase+1) % 2; |
|
||||||
} |
|
||||||
mem->write16(spiAddress, memBlock, NUM_BLOCK_WORDS); |
|
||||||
while (mem->isWriteBusy()) {} |
|
||||||
} |
|
||||||
|
|
||||||
// Read back the test data
|
|
||||||
spiErrorCount = 0; |
|
||||||
spiAddress = 0; |
|
||||||
maskPhase = 0; |
|
||||||
|
|
||||||
for (spiAddress = 0; spiAddress <= SPI_MAX_ADDR; spiAddress += NUM_BLOCK_WORDS*sizeof(uint16_t)) { |
|
||||||
|
|
||||||
mem->read16(spiAddress, memBlock, NUM_BLOCK_WORDS);
|
|
||||||
// Calculate the golden data for a block
|
|
||||||
for (int i=0; i<NUM_BLOCK_WORDS; i++) { |
|
||||||
goldData[i] = calcData(spiAddress+i, loopPhase, maskPhase); |
|
||||||
maskPhase = (maskPhase+1) % 2; |
|
||||||
} |
|
||||||
while (mem->isReadBusy()) {} // wait for the read to finish
|
|
||||||
|
|
||||||
for (int i=0; i<NUM_BLOCK_WORDS; i++) { |
|
||||||
if (goldData[i] != memBlock[i]) { |
|
||||||
Serial.println(String("ERROR@ ") + i + String(": ") + goldData[i] + String("!=") + memBlock[i]); |
|
||||||
spiErrorCount++; |
|
||||||
if (spiErrorCount >= 10) break; |
|
||||||
}
|
|
||||||
#ifdef SANITY_CHECK |
|
||||||
else { |
|
||||||
if ((spiAddress == 0) && (i<10) && (cnt == 0) ){ |
|
||||||
Serial.println(String("SHOW@ ") + i + String(": ") + goldData[i] + String("==") + memBlock[i]); |
|
||||||
} |
|
||||||
} |
|
||||||
#endif |
|
||||||
} |
|
||||||
if (spiErrorCount >= 10) break; |
|
||||||
} |
|
||||||
|
|
||||||
//if (spiErrorCount == 0) { Serial.println(String("SPI MEMORY(") + cnt + String("): Data test PASSED!")); }
|
|
||||||
if (spiErrorCount == 0) { Serial.print("."); Serial.flush(); } |
|
||||||
if (spiErrorCount > 0) { Serial.println(String("SPI MEMORY(") + cnt + String("): Data test FAILED, error count = ") + spiErrorCount); return false;} |
|
||||||
|
|
||||||
loopPhase = (loopPhase+1) % 2; |
|
||||||
} |
|
||||||
return true; |
|
||||||
} |
|
Loading…
Reference in new issue