forked from wirtz/BALibrary
parent
86e764eba3
commit
492659ddb2
@ -1,124 +0,0 @@ |
||||
/*************************************************************************
|
||||
* This demo uses only the built-in libraries provided with the Arudino |
||||
* Teensy libraries.
|
||||
*
|
||||
* IT IS STRONGLY RECOMMENDED to use the BALibrary Library located at |
||||
* https://github.com/Blackaddr/BALibrary
|
||||
* The BALibrary library will made it easier to use the features of your |
||||
* GTA Pro board, as well and configure it correctly to eliminate |
||||
* unneccesary noise. |
||||
*
|
||||
* The built-in support for the WM8731 codec in the Teensy Library is very |
||||
* limited. Without proper configuration, the codec will produce a noisy |
||||
* output. This is caused by the default configuration the WM8731 powers |
||||
* up in. This can easily be corrected by installing the BALibrary library |
||||
*
|
||||
* For instructions on installing additional libraries follow the |
||||
* instructions at https://www.arduino.cc/en/Guide/Libraries after downloading
|
||||
* the BALibrary repo from github as a zip file. |
||||
*
|
||||
*/ |
||||
|
||||
#include <Wire.h> |
||||
#include <Audio.h> |
||||
#include <MIDI.h> |
||||
|
||||
MIDI_CREATE_DEFAULT_INSTANCE(); |
||||
using namespace midi; |
||||
|
||||
AudioInputI2S i2sIn; |
||||
AudioOutputI2S i2sOut; |
||||
|
||||
// Audio connections, just connect the I2S input directly to the I2S output.
|
||||
AudioConnection patch0(i2sIn,0, i2sOut, 0); |
||||
AudioConnection patch1(i2sIn,1, i2sOut, 1); |
||||
|
||||
AudioControlWM8731 codecControl; // needed to enable the codec
|
||||
|
||||
unsigned long t=0; |
||||
const int usrLED = 16; // the location of the GTA Pro user LED (not the LED on the Teensy itself)
|
||||
int usrLEDState = 0; |
||||
|
||||
void setup() { |
||||
|
||||
// Configure the user LED pin as output
|
||||
pinMode(usrLED, OUTPUT); |
||||
digitalWrite(usrLED, usrLEDState); |
||||
|
||||
// Enable the MIDI to listen on all channels
|
||||
MIDI.begin(MIDI_CHANNEL_OMNI);
|
||||
Serial.begin(57600); // Enable the serial monitor
|
||||
Wire.begin(); // Enable the I2C bus for controlling the codec
|
||||
delay(5); |
||||
|
||||
delay(100); |
||||
codecControl.disable(); // Turn off the codec first (in case it was in an unknown state)
|
||||
delay(100); |
||||
AudioMemory(24); |
||||
|
||||
Serial.println("Enabling codec...\n"); |
||||
codecControl.enable(); // Enable the codec
|
||||
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 no MIDI IN activity, print a message every 10 seconds
|
||||
if (millis() - t > 10000) { |
||||
t += 10000; |
||||
Serial.println("(no MIDI activity, check cables)"); |
||||
} |
||||
|
||||
// Toggle the USR LED state
|
||||
usrLEDState = ~usrLEDState; |
||||
digitalWrite(usrLED, usrLEDState); |
||||
|
||||
} |
||||
|
@ -1,51 +0,0 @@ |
||||
SPI writing DONE! |
||||
SPI TEST PASSED!!! |
||||
SPI writing DONE! |
||||
SPI TEST PASSED!!! |
||||
SPI writing DONE! |
||||
SPI TEST PASSED!!! |
||||
MIDI IS WORKING!!! |
||||
Message, type=176, data = 32 10 |
||||
SPI writing DONE! |
||||
SPI TEST PASSED!!! |
||||
SPI writing DONE! |
||||
SPI TEST PASSED!!! |
||||
SPI writing DONE! |
||||
SPI TEST PASSED!!! |
||||
MIDI IS WORKING!!! |
||||
Note On: ch=2, note=10, velocity=100 |
||||
SPI writing DONE! |
||||
SPI TEST PASSED!!! |
||||
SPI writing DONE! |
||||
SPI TEST PASSED!!! |
||||
SPI writing DONE! |
||||
SPI TEST PASSED!!! |
||||
MIDI IS WORKING!!! |
||||
Message, type=176, data = 33 11 |
||||
SPI writing DONE! |
||||
SPI TEST PASSED!!! |
||||
SPI writing DONE! |
||||
SPI TEST PASSED!!! |
||||
SPI writing DONE! |
||||
SPI TEST PASSED!!! |
||||
MIDI IS WORKING!!! |
||||
Note On: ch=3, note=10, velocity=100 |
||||
SPI writing DONE! |
||||
SPI TEST PASSED!!! |
||||
SPI writing DONE! |
||||
SPI TEST PASSED!!! |
||||
SPI writing DONE! |
||||
SPI TEST PASSED!!! |
||||
MIDI IS WORKING!!! |
||||
Message, type=176, data = 34 12 |
||||
SPI writing DONE! |
||||
SPI TEST PASSED!!! |
||||
SPI writing DONE! |
||||
SPI TEST PASSED!!! |
||||
SPI writing DONE! |
||||
SPI TEST PASSED!!! |
||||
MIDI IS WORKING!!! |
||||
Note On: ch=4, note=10, velocity=100 |
||||
SPI writing DONE! |
||||
SPI TEST PASSED!!! |
||||
|
@ -0,0 +1,6 @@ |
||||
If you've never used the the library examples before, start with the "Basic" ones. |
||||
|
||||
Pick the correct one based on how many SPI SRAMs you have. (0, 1 or 2 SRAMs). |
||||
|
||||
Use BAExpansionCalibrate to test our the Blackaddr Audio Expanson Control Board if |
||||
you purchased one. |
@ -1,79 +0,0 @@ |
||||
#define TGA_PRO_EXPAND_REV2 |
||||
|
||||
#include "BALibrary.h" |
||||
using namespace BALibrary; |
||||
|
||||
constexpr int potCalibMin = 1; |
||||
constexpr int potCalibMax = 1018; |
||||
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); |
||||
}
|
||||
} |
||||
|
||||
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; |
||||
} |
||||
|
||||
bool pressed = controlPtr->isSwitchHeld(swHandle); |
||||
controlPtr->setOutput(ledHandle, pressed); |
||||
} |
||||
|
||||
|
@ -1,71 +0,0 @@ |
||||
/*************************************************************************
|
||||
* This demo is used for manufacturing tests on the TGA Pro Expansion |
||||
* Control Board. Pushing the buttons turns on the LEDs. Adjusting |
||||
* any know will adjust the volume. |
||||
*
|
||||
* The latest copy of the BA Guitar library can be obtained from |
||||
* https://github.com/Blackaddr/BALibrary
|
||||
*
|
||||
*/ |
||||
#include <Wire.h> |
||||
#include <Audio.h> |
||||
#include <SPI.h> |
||||
|
||||
#define TGA_PRO_EXPAND_REV2 |
||||
#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
|
||||
|
||||
BASpiMemoryDMA spiMem0(SpiDeviceId::SPI_DEVICE0); |
||||
BASpiMemoryDMA spiMem1(SpiDeviceId::SPI_DEVICE1); |
||||
|
||||
// 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(BASpiMemoryDMA *mem); // returns true if passed
|
||||
bool uartTest(); // returns true if passed
|
||||
|
||||
void setup() { |
||||
Serial.begin(57600); |
||||
|
||||
spiMem0.begin(); |
||||
spiMem1.begin(); |
||||
|
||||
// Disable the audio codec first
|
||||
codec.disable(); |
||||
delay(100); |
||||
AudioMemory(128); |
||||
codec.enable(); |
||||
codec.setHeadphoneVolume(0.8f); // Set headphone volume
|
||||
configPhysicalControls(controls, codec); |
||||
|
||||
// Run the initial Midi connectivity and SPI memory tests.
|
||||
if (uartTest()) { Serial.println("MIDI Ports testing PASSED!"); } |
||||
if (spiTest(&spiMem0)) { Serial.println("SPI0 testing PASSED!");} |
||||
if (spiTest(&spiMem1)) { Serial.println("SPI1 testing PASSED!");} |
||||
} |
||||
|
||||
void loop() { |
||||
// put your main code here, to run repeatedly:
|
||||
checkPot(0); |
||||
checkPot(1); |
||||
checkPot(2); |
||||
checkSwitch(0); |
||||
checkSwitch(1); |
||||
|
||||
delay(10); |
||||
} |
@ -1,86 +0,0 @@ |
||||
#include "BAHardware.h" |
||||
#include "BASpiMemory.h" |
||||
|
||||
using namespace BALibrary; |
||||
|
||||
constexpr unsigned LOW_RATE = 2400; |
||||
constexpr unsigned MIDI_RATE = 31250; |
||||
constexpr unsigned HIGH_RATE = 250000;
|
||||
constexpr unsigned TEST_TIME = 5; // 5 second test each
|
||||
|
||||
static unsigned baudRate = LOW_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 low speed, 1 for MIDI speed, 2 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 = MIDI_RATE; |
||||
break; |
||||
case 1 : |
||||
baudRate = HIGH_RATE; |
||||
break; |
||||
case 2 : |
||||
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("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,125 +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 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(BASpiMemoryDMA *mem) |
||||
{ |
||||
int spiAddress = 0; |
||||
int spiErrorCount = 0; |
||||
|
||||
int maskPhase = 0; |
||||
int loopPhase = 0; |
||||
uint16_t memBlock[NUM_BLOCK_WORDS]; |
||||
uint16_t goldData[NUM_BLOCK_WORDS]; |
||||
|
||||
Serial.println("Starting SPI MEM Test"); |
||||
|
||||
for (int cnt = 0; cnt < NUM_TESTS; cnt++) { |
||||
|
||||
// Zero check
|
||||
mem->zero16(0, SPI_MEM0_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; |
||||
} |
||||
|
@ -0,0 +1,29 @@ |
||||
/*
|
||||
* BAEffects.h |
||||
* |
||||
* Created on: May 22, 2017 |
||||
* Author: slascos |
||||
* |
||||
* This program is free software: you can redistribute it and/or modify |
||||
* it under the terms of the GNU General Public License as published by |
||||
* the Free Software Foundation, either version 3 of the License, or |
||||
* (at your option) any later version.* |
||||
* |
||||
* This program is distributed in the hope that it will be useful, |
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
* GNU General Public License for more details. |
||||
* |
||||
* You should have received a copy of the GNU General Public License |
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/ |
||||
#ifndef __BAEFFECTS_H |
||||
#define __BAEFFECTS_H |
||||
|
||||
#include "BALibrary.h" // contains the Blackaddr hardware board definitions |
||||
|
||||
#include "BAAudioEffectDelayExternal.h" |
||||
#include "AudioEffectAnalogDelay.h" |
||||
#include "AudioEffectSOS.h" |
||||
|
||||
#endif /* __BAEFFECTS_H */ |
Loading…
Reference in new issue