Work in progress

master
Steve Lascos 6 years ago
parent 1c153eae69
commit f0c0dbb197
  1. 12
      README.md
  2. 2
      doc/doxygen.cfg
  3. 10
      examples/BA0_TGA_Pro_TRY_FIRST/BA0_TGA_Pro_TRY_FIRST.ino
  4. 6
      examples/BA1_TGA_Pro_demo/BA1_TGA_Pro_demo.ino
  5. 6
      examples/BA2_TGA_Pro_1MEM/BA2_TGA_Pro_1MEM.ino
  6. 6
      examples/BA3_TGA_Pro_2MEM/BA3_TGA_Pro_2MEM.ino
  7. 6
      examples/BA4_TGA_Pro_delay_reverb/BA4_TGA_Pro_delay_reverb.ino
  8. 6
      examples/BA5_TGA_Pro_ExternalDelay_demo/BA5_TGA_Pro_ExternalDelay_demo.ino
  9. 2
      examples/BAExpansionCalibrate/BAExpansionCalibrate.ino
  10. 2
      examples/Delay/AnalogDelayDemo/AnalogDelayDemo.ino
  11. 8
      examples/Delay/AnalogDelayDemoExpansion/AnalogDelayDemoExpansion.ino
  12. 6
      examples/Delay/SoundOnSoundDemo/SoundOnSoundDemo.ino
  13. 6
      examples/Delay/SoundOnSoundExpansionDemo/SoundOnSoundExpansionDemo.ino
  14. 94
      examples/Tests/BaudrateTest/BaudrateTest.ino
  15. 14
      examples/Tests/DMA_MEM0_test/DMA_MEM0_test.ino
  16. 15
      examples/Tests/DMA_MEM1_test/DMA_MEM1_test.ino
  17. 86
      examples/Tests/TGA_PRO_MEM2/PhysicalControls.cpp
  18. 59
      examples/Tests/TGA_PRO_MEM2/TGA_PRO_MEM2.ino
  19. 86
      examples/Tests/TGA_PRO_MEM2/UartTest.cpp
  20. 125
      examples/Tests/TGA_PRO_MEM2/spiTest.cpp
  21. 4
      library.properties
  22. 4
      src/BAHardware.h
  23. 12
      src/BALibrary.h
  24. 5
      src/BAPhysicalControls.h
  25. 3
      src/BATypes.h
  26. 6
      src/peripherals/BAPhysicalControls.cpp

@ -1,4 +1,4 @@
## BAGuitar Library ## BALibrary Library
This library is under active development as of 2018. This library is under active development as of 2018.
**REQUIREMENTS** **REQUIREMENTS**
@ -17,18 +17,18 @@ This open-source library is designed to extend the capabilities of Teensyduino,
Teensyduino provides a realtime Audio library that makes it very easy for musicians and audio enthusiasts to start experimenting with and writing their own audio processors and effects, without the need for a lot of programming experience. This is accomplished by handling the complex topics (like using DMA to move audio blocks around) so you can focus on how you want to process the audio content itself. Teensyduino provides a realtime Audio library that makes it very easy for musicians and audio enthusiasts to start experimenting with and writing their own audio processors and effects, without the need for a lot of programming experience. This is accomplished by handling the complex topics (like using DMA to move audio blocks around) so you can focus on how you want to process the audio content itself.
BAGuitar adds to this by providing features and building blocks that are of particular interest to guitarists. In a nutshell, guitarists want digital audio to work similar to their guitar pedals and amps. Basically, a chain of self-contained audio processors with switches and knobs to control them. The good news is we can do this digitally with virtual patch cables (called AudioConnections) and MIDI control. BALibrary adds to this by providing features and building blocks that are of particular interest to guitarists. In a nutshell, guitarists want digital audio to work similar to their guitar pedals and amps. Basically, a chain of self-contained audio processors with switches and knobs to control them. The good news is we can do this digitally with virtual patch cables (called AudioConnections) and MIDI control.
**INSTALLATION** **INSTALLATION**
In order to use BAGuitar, you should: In order to use BALibrary, you should:
1. Install the Arduino IDE. This is where you write and compile your software, called 'sketches'. See [here](https://www.arduino.cc/en/Main/Software). 1. Install the Arduino IDE. This is where you write and compile your software, called 'sketches'. See [here](https://www.arduino.cc/en/Main/Software).
2. Install the Teensyduino plugin for the Arduino IDE. This provides support for programming Teensy boards over USB, as well as access to the plethora of helpful libraries and examples it provides. See [here](https://www.pjrc.com/teensy/td_download.html). 2. Install the Teensyduino plugin for the Arduino IDE. This provides support for programming Teensy boards over USB, as well as access to the plethora of helpful libraries and examples it provides. See [here](https://www.pjrc.com/teensy/td_download.html).
3. Download the BAGuitar library, and use the Library Manager in the Arduino IDE to install it. See [here](https://www.arduino.cc/en/Guide/Libraries) for details.. 3. Download the BALibrary library, and use the Library Manager in the Arduino IDE to install it. See [here](https://www.arduino.cc/en/Guide/Libraries) for details..
4. Include "BAGuitar.h" in your sketch. 4. Include "BALibrary.h" in your sketch.
**HARDWARE** **HARDWARE**
The audio primitives and effects provided in the BAGuitar library require no special hardware other than a Teensy 3.x series board. However, in order to use the external RAM features provided in some effects, the SPI pins used must be the same as those used on the Blackaddr [TGA-Pro audio shield](http://blackaddr.com/products/). The audio primitives and effects provided in the BALibrary library require no special hardware other than a Teensy 3.x series board. However, in order to use the external RAM features provided in some effects, the SPI pins used must be the same as those used on the Blackaddr [TGA-Pro audio shield](http://blackaddr.com/products/).
**BAGUITAR CONTENTS** **BAGUITAR CONTENTS**
- WM871 advanced codec control - WM871 advanced codec control

@ -4,7 +4,7 @@
# Project related configuration options # Project related configuration options
#--------------------------------------------------------------------------- #---------------------------------------------------------------------------
DOXYFILE_ENCODING = UTF-8 DOXYFILE_ENCODING = UTF-8
PROJECT_NAME = "Blackaddr Audio BAGuitar Library" PROJECT_NAME = "Blackaddr Audio BALibrary Library"
PROJECT_NUMBER = PROJECT_NUMBER =
PROJECT_BRIEF = PROJECT_BRIEF =
PROJECT_LOGO = PROJECT_LOGO =

@ -2,20 +2,20 @@
* This demo uses only the built-in libraries provided with the Arudino * This demo uses only the built-in libraries provided with the Arudino
* Teensy libraries. * Teensy libraries.
* *
* IT IS STRONGLY RECOMMENDED to use the BAGuitar Library located at * IT IS STRONGLY RECOMMENDED to use the BALibrary Library located at
* https://github.com/Blackaddr/BAGuitar * https://github.com/Blackaddr/BALibrary
* The BAGuitar library will made it easier to use the features of your * The BALibrary library will made it easier to use the features of your
* GTA Pro board, as well and configure it correctly to eliminate * GTA Pro board, as well and configure it correctly to eliminate
* unneccesary noise. * unneccesary noise.
* *
* The built-in support for the WM8731 codec in the Teensy Library is very * The built-in support for the WM8731 codec in the Teensy Library is very
* limited. Without proper configuration, the codec will produce a noisy * limited. Without proper configuration, the codec will produce a noisy
* output. This is caused by the default configuration the WM8731 powers * output. This is caused by the default configuration the WM8731 powers
* up in. This can easily be corrected by installing the BAGuitar library * up in. This can easily be corrected by installing the BALibrary library
* *
* For instructions on installing additional libraries follow the * For instructions on installing additional libraries follow the
* instructions at https://www.arduino.cc/en/Guide/Libraries after downloading * instructions at https://www.arduino.cc/en/Guide/Libraries after downloading
* the BAGuitar repo from github as a zip file. * the BALibrary repo from github as a zip file.
* *
*/ */

@ -1,9 +1,9 @@
/************************************************************************* /*************************************************************************
* This demo uses the BAGuitar library to provide enhanced control of * This demo uses the BALibrary library to provide enhanced control of
* the TGA Pro board. * the TGA Pro board.
* *
* The latest copy of the BA Guitar library can be obtained from * The latest copy of the BA Guitar library can be obtained from
* https://github.com/Blackaddr/BAGuitar * https://github.com/Blackaddr/BALibrary
* *
* This demo will provide an audio passthrough, as well as exercise the * This demo will provide an audio passthrough, as well as exercise the
* MIDI interface. * MIDI interface.
@ -14,7 +14,7 @@
#include <Wire.h> #include <Wire.h>
#include <Audio.h> #include <Audio.h>
#include <MIDI.h> #include <MIDI.h>
#include "BAGuitar.h" #include "BALibrary.h"
MIDI_CREATE_DEFAULT_INSTANCE(); MIDI_CREATE_DEFAULT_INSTANCE();
using namespace midi; using namespace midi;

@ -1,9 +1,9 @@
/************************************************************************* /*************************************************************************
* This demo uses the BAGuitar library to provide enhanced control of * This demo uses the BALibrary library to provide enhanced control of
* the TGA Pro board. * the TGA Pro board.
* *
* The latest copy of the BA Guitar library can be obtained from * The latest copy of the BA Guitar library can be obtained from
* https://github.com/Blackaddr/BAGuitar * https://github.com/Blackaddr/BALibrary
* *
* This demo will provide an audio passthrough, as well as exercise the * This demo will provide an audio passthrough, as well as exercise the
* MIDI interface. * MIDI interface.
@ -18,7 +18,7 @@
#include <Wire.h> #include <Wire.h>
#include <Audio.h> #include <Audio.h>
#include <MIDI.h> #include <MIDI.h>
#include "BAGuitar.h" #include "BALibrary.h"
MIDI_CREATE_DEFAULT_INSTANCE(); MIDI_CREATE_DEFAULT_INSTANCE();
using namespace midi; using namespace midi;

@ -1,9 +1,9 @@
/************************************************************************* /*************************************************************************
* This demo uses the BAGuitar library to provide enhanced control of * This demo uses the BALibrary library to provide enhanced control of
* the TGA Pro board. * the TGA Pro board.
* *
* The latest copy of the BA Guitar library can be obtained from * The latest copy of the BA Guitar library can be obtained from
* https://github.com/Blackaddr/BAGuitar * https://github.com/Blackaddr/BALibrary
* *
* This demo will provide an audio passthrough, as well as exercise the * This demo will provide an audio passthrough, as well as exercise the
* MIDI interface. * MIDI interface.
@ -19,7 +19,7 @@
#include <Wire.h> #include <Wire.h>
#include <Audio.h> #include <Audio.h>
#include <MIDI.h> #include <MIDI.h>
#include "BAGuitar.h" #include "BALibrary.h"
MIDI_CREATE_DEFAULT_INSTANCE(); MIDI_CREATE_DEFAULT_INSTANCE();
using namespace midi; using namespace midi;

@ -1,9 +1,9 @@
/************************************************************************* /*************************************************************************
* This demo uses the BAGuitar library to provide enhanced control of * This demo uses the BALibrary library to provide enhanced control of
* the TGA Pro board. * the TGA Pro board.
* *
* The latest copy of the BA Guitar library can be obtained from * The latest copy of the BA Guitar library can be obtained from
* https://github.com/Blackaddr/BAGuitar * https://github.com/Blackaddr/BALibrary
* *
* This demo provides an example guitar tone consisting of some slap-back delay, * This demo provides an example guitar tone consisting of some slap-back delay,
* followed by a reverb and a low-pass cabinet filter. * followed by a reverb and a low-pass cabinet filter.
@ -12,7 +12,7 @@
#include <Wire.h> #include <Wire.h>
#include <Audio.h> #include <Audio.h>
#include <MIDI.h> #include <MIDI.h>
#include "BAGuitar.h" #include "BALibrary.h"
using namespace BAEffects; using namespace BAEffects;
using namespace BALibrary; using namespace BALibrary;

@ -1,9 +1,9 @@
/************************************************************************* /*************************************************************************
* This demo uses the BAGuitar library to provide enhanced control of * This demo uses the BALibrary library to provide enhanced control of
* the TGA Pro board. * the TGA Pro board.
* *
* The latest copy of the BA Guitar library can be obtained from * The latest copy of the BA Guitar library can be obtained from
* https://github.com/Blackaddr/BAGuitar * https://github.com/Blackaddr/BALibrary
* *
* This demo shows to use the BAAudioEffectDelayExternal audio class * This demo shows to use the BAAudioEffectDelayExternal audio class
* to create long delays using external SPI RAM. * to create long delays using external SPI RAM.
@ -12,7 +12,7 @@
* *
*/ */
#include "BAGuitar.h" #include "BALibrary.h"
using namespace BAEffects; using namespace BAEffects;
using namespace BALibrary; using namespace BALibrary;

@ -1,7 +1,7 @@
#define TGA_PRO_REVB #define TGA_PRO_REVB
#define TGA_PRO_EXPAND_REV2 #define TGA_PRO_EXPAND_REV2
#include "BAGuitar.h" #include "BALibrary.h"
using namespace BALibrary; using namespace BALibrary;

@ -1,5 +1,5 @@
#include <MIDI.h> #include <MIDI.h>
#include "BAGuitar.h" #include "BALibrary.h"
using namespace midi; using namespace midi;
using namespace BAEffects; using namespace BAEffects;

@ -1,9 +1,9 @@
/************************************************************************* /*************************************************************************
* This demo uses the BAGuitar library to provide enhanced control of * This demo uses the BALibrary library to provide enhanced control of
* the TGA Pro board. * the TGA Pro board.
* *
* The latest copy of the BA Guitar library can be obtained from * The latest copy of the BA Guitar library can be obtained from
* https://github.com/Blackaddr/BAGuitar * https://github.com/Blackaddr/BALibrary
* *
* This demo combines the Blackaddr Audio Expansion board to add physical controls * This demo combines the Blackaddr Audio Expansion board to add physical controls
* to the BAAudioEffectAnalogDelay. * to the BAAudioEffectAnalogDelay.
@ -15,7 +15,7 @@
#define TGA_PRO_REVB // Set which hardware revision of the TGA Pro we're using #define TGA_PRO_REVB // Set which hardware revision of the TGA Pro we're using
#define TGA_PRO_EXPAND_REV2 // pull in the pin definitions for the Blackaddr Audio Expansion Board. #define TGA_PRO_EXPAND_REV2 // pull in the pin definitions for the Blackaddr Audio Expansion Board.
#include "BAGuitar.h" #include "BALibrary.h"
using namespace BAEffects; using namespace BAEffects;
using namespace BALibrary; using namespace BALibrary;
@ -154,7 +154,7 @@ void loop() {
} }
// Use SW2 to cycle through the filters // Use SW2 to cycle through the filters
controls.setOutput(led2Handle, controls.getSwitchValue(led2Handle)); controls.setOutput(led2Handle, !controls.getSwitchValue(led2Handle));
if (controls.isSwitchToggled(filterHandle)) { if (controls.isSwitchToggled(filterHandle)) {
filterIndex = (filterIndex + 1) % 3; // update and potentionall roll the counter 0, 1, 2, 0, 1, 2, ... filterIndex = (filterIndex + 1) % 3; // update and potentionall roll the counter 0, 1, 2, 0, 1, 2, ...
// cast the index between 0 to 2 to the enum class AudioEffectAnalogDelay::Filter // cast the index between 0 to 2 to the enum class AudioEffectAnalogDelay::Filter

@ -1,9 +1,9 @@
/************************************************************************* /*************************************************************************
* This demo uses the BAGuitar library to provide enhanced control of * This demo uses the BALibrary library to provide enhanced control of
* the TGA Pro board. * the TGA Pro board.
* *
* The latest copy of the BA Guitar library can be obtained from * The latest copy of the BA Guitar library can be obtained from
* https://github.com/Blackaddr/BAGuitar * https://github.com/Blackaddr/BALibrary
* *
* This demo will provide an audio passthrough, as well as exercise the * This demo will provide an audio passthrough, as well as exercise the
* MIDI interface. * MIDI interface.
@ -15,7 +15,7 @@
#include <Audio.h> #include <Audio.h>
#include <MIDI.h> #include <MIDI.h>
#include <SPI.h> #include <SPI.h>
#include "BAGuitar.h" #include "BALibrary.h"
#include <midi_UsbTransport.h> #include <midi_UsbTransport.h>
static const unsigned sUsbTransportBufferSize = 16; static const unsigned sUsbTransportBufferSize = 16;

@ -1,9 +1,9 @@
/************************************************************************* /*************************************************************************
* This demo uses the BAGuitar library to provide enhanced control of * This demo uses the BALibrary library to provide enhanced control of
* the TGA Pro board. * the TGA Pro board.
* *
* The latest copy of the BA Guitar library can be obtained from * The latest copy of the BA Guitar library can be obtained from
* https://github.com/Blackaddr/BAGuitar * https://github.com/Blackaddr/BALibrary
* *
* THIS DEMO REQUIRES BOTH THE EXTERNAL SRAM AND EXPANSION BOARD ADD-ONS * THIS DEMO REQUIRES BOTH THE EXTERNAL SRAM AND EXPANSION BOARD ADD-ONS
* *
@ -17,7 +17,7 @@
#define TGA_PRO_REVB // Set which hardware revision of the TGA Pro we're using #define TGA_PRO_REVB // Set which hardware revision of the TGA Pro we're using
#define TGA_PRO_EXPAND_REV2 // pull in the pin definitions for the Blackaddr Audio Expansion Board. #define TGA_PRO_EXPAND_REV2 // pull in the pin definitions for the Blackaddr Audio Expansion Board.
#include "BAGuitar.h" #include "BALibrary.h"
using namespace BAEffects; using namespace BAEffects;
using namespace BALibrary; using namespace BALibrary;

@ -0,0 +1,94 @@
/*************************************************************************
* This demo does high speed testing of the Serial1 hardware port. On
* The TGA Pro, this is used for MIDI. MIDI is essentially a Serial protocol
* running 31250 baud with port configuration 8N1.
*
* Despite there being MIDI physical circuitry on the TGA Pro, we can still
* run a serial protocol at different rates to ensure a robust design.
*
* CONNECT A MIDI CABLE FROM MIDI_INPUT TO MIDI_OUTPUT AS A LOOPBACK.
*/
constexpr unsigned LOW_RATE = 2400;
constexpr unsigned MIDI_RATE = 31250;
constexpr unsigned HIGH_RATE = 250000;
constexpr unsigned TEST_TIME = 5; // 5 second test each
unsigned baudRate = LOW_RATE; // start with low speed
uint8_t writeData = 0;
unsigned loopCounter = 0;
unsigned errorCount = 0;
bool testFailed = false;
bool testDone = false;
unsigned testPhase = 0; // 0 for low speed, 1 for MIDI speed, 2 for high speed.
void setup() {
// put your setup code here, to run once:
Serial.begin(57600);
Serial1.begin(baudRate, SERIAL_8N1);
delay(100);
while(!Serial) {}
Serial.println(String("\nRunning speed test at ") + baudRate);
// write the first data
Serial1.write(writeData);
}
void loop() {
if ((!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("TEST FAILED!");
}
errorCount = 0;
testPhase++;
loopCounter = 0;
if (!testDone) {
Serial.println(String("\nRunning speed test at ") + baudRate);
Serial1.begin(baudRate, SERIAL_8N1);
while (!Serial1) {} // wait for serial to be ready
} else {
Serial.println("\nTEST DONE!");
}
}
// 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);
}
}
}

@ -1,9 +1,9 @@
/************************************************************************* /*************************************************************************
* This demo uses the BAGuitar library to provide enhanced control of * This demo uses the BALibrary to provide enhanced control of
* the TGA Pro board. * the TGA Pro board.
* *
* The latest copy of the BA Guitar library can be obtained from * The latest copy of BALibrary can be obtained from
* https://github.com/Blackaddr/BAGuitar * https://github.com/Blackaddr/BALibrary
* *
* This demo will perform a DMA memory test on MEM0 attached * This demo will perform a DMA memory test on MEM0 attached
* to SPI. * to SPI.
@ -13,9 +13,9 @@
* *
*/ */
#include <Wire.h> #include <Wire.h>
#include "BAGuitar.h" #include "BALibrary.h"
using namespace BAGuitar; using namespace BALibrary;
//#define SANITY //#define SANITY
#define DMA_SIZE 256 #define DMA_SIZE 256
@ -34,7 +34,6 @@ BAGpio gpio; // access to User LED
BASpiMemoryDMA spiMem0(SpiDeviceId::SPI_DEVICE0); BASpiMemoryDMA spiMem0(SpiDeviceId::SPI_DEVICE0);
bool compareBuffers(uint8_t *a, uint8_t *b, size_t numBytes) bool compareBuffers(uint8_t *a, uint8_t *b, size_t numBytes)
{ {
bool pass=true; bool pass=true;
@ -64,7 +63,7 @@ void setup() {
while (!Serial) {} while (!Serial) {}
delay(5); delay(5);
Serial.println("Enabling SPI"); Serial.println("Enabling SPI, testing MEM0");
spiMem0.begin(); spiMem0.begin();
} }
@ -310,6 +309,7 @@ void loop() {
spi8BitTest(); spi8BitTest();
spi16BitTest(); spi16BitTest();
Serial.println("\nTEST DONE!");
while(true) {} while(true) {}
} }

@ -1,9 +1,9 @@
/************************************************************************* /*************************************************************************
* This demo uses the BAGuitar library to provide enhanced control of * This demo uses the BALibrary to provide enhanced control of
* the TGA Pro board. * the TGA Pro board.
* *
* The latest copy of the BA Guitar library can be obtained from * The latest copy of the BALibrary can be obtained from
* https://github.com/Blackaddr/BAGuitar * https://github.com/Blackaddr/BALibrary
* *
* This demo will perform a DMA memory test on MEM1 attached * This demo will perform a DMA memory test on MEM1 attached
* to SPI1. * to SPI1.
@ -13,9 +13,9 @@
* *
*/ */
#include <Wire.h> #include <Wire.h>
#include "BAGuitar.h" #include "BALibrary.h"
using namespace BAGuitar; using namespace BALibrary;
//#define SANITY //#define SANITY
#define DMA_SIZE 256 #define DMA_SIZE 256
@ -33,8 +33,6 @@ const int cs0pin = 15;
BAGpio gpio; // access to User LED BAGpio gpio; // access to User LED
BASpiMemoryDMA spiMem1(SpiDeviceId::SPI_DEVICE1); BASpiMemoryDMA spiMem1(SpiDeviceId::SPI_DEVICE1);
bool compareBuffers(uint8_t *a, uint8_t *b, size_t numBytes) bool compareBuffers(uint8_t *a, uint8_t *b, size_t numBytes)
{ {
bool pass=true; bool pass=true;
@ -64,7 +62,7 @@ void setup() {
while (!Serial) {} while (!Serial) {}
delay(5); delay(5);
Serial.println("Enabling SPI"); Serial.println("Enabling SPI, testing MEM1");
spiMem1.begin(); spiMem1.begin();
} }
@ -310,6 +308,7 @@ void loop() {
spi8BitTest(); spi8BitTest();
spi16BitTest(); spi16BitTest();
Serial.println("\nTEST DONE!");
while(true) {} while(true) {}
} }

@ -0,0 +1,86 @@
#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;
}
if (controlPtr->isSwitchToggled(swHandle)) {
Serial.println(String("SW ") + swHandle + String("Pushed"));
mute = !mute;
if (mute) { codecPtr->setHeadphoneVolume(0.0f); }
else { codecPtr->setHeadphoneVolume(0.8f); }
}
bool pressed = controlPtr->isSwitchHeld(swHandle);
controlPtr->setOutput(ledHandle, pressed);
}

@ -0,0 +1,59 @@
#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();
AudioMemory(128);
codec.enable();
codec.setHeadphoneVolume(0.8f); // Set headphone volume
configPhysicalControls(controls, codec);
// 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);
}

@ -0,0 +1,86 @@
#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;
}

@ -0,0 +1,125 @@
#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;
}

@ -1,4 +1,4 @@
name=BAGuitar name=BALibrary
version=0.1 version=0.1
author=Steve Lascos <steve@blackaddr.com> author=Steve Lascos <steve@blackaddr.com>
maintainer=Steve Lascos <steve@blackaddr.com> maintainer=Steve Lascos <steve@blackaddr.com>
@ -7,4 +7,4 @@ paragraph=Extends the Teensy Audio Library.
category=Communication category=Communication
url=www.blackaddr.com url=www.blackaddr.com
architectures=avr architectures=avr
includes=BAGuitar.h includes=BALibrary.h

@ -23,10 +23,12 @@
#ifndef __BALIBRARY_BAHARDWARE_H #ifndef __BALIBRARY_BAHARDWARE_H
#define __BALIBRARY_BAHARDWARE_H #define __BALIBRARY_BAHARDWARE_H
#include <Arduino.h>
#include <cstdint> #include <cstdint>
#include <cstddef>
/**************************************************************************//** /**************************************************************************//**
* BAGuitar is a namespace/Library for Guitar processing from Blackaddr Audio. * BALibrary is a namespace/Library for Guitar processing from Blackaddr Audio.
*****************************************************************************/ *****************************************************************************/
namespace BALibrary { namespace BALibrary {

@ -1,5 +1,5 @@
/* /*
* BAGuitar.h * BALibrary.h
* *
* Created on: May 22, 2017 * Created on: May 22, 2017
* Author: slascos * Author: slascos
@ -17,9 +17,8 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef __BALIBRARY_H
#ifndef __BATGUITAR_H #define __BALIBRARY_H
#define __BATGUITAR_H
#include "BAHardware.h" // contains the Blackaddr hardware board definitions #include "BAHardware.h" // contains the Blackaddr hardware board definitions
@ -27,11 +26,8 @@
#include "BAAudioControlWM8731.h" // Codec Control #include "BAAudioControlWM8731.h" // Codec Control
#include "BASpiMemory.h" #include "BASpiMemory.h"
#include "BAGpio.h" #include "BAGpio.h"
#include "BAAudioEffectDelayExternal.h"
#include "AudioEffectAnalogDelay.h"
#include "AudioEffectSOS.h"
#include "LibBasicFunctions.h" #include "LibBasicFunctions.h"
#include "LibMemoryManagement.h" #include "LibMemoryManagement.h"
#include "BAPhysicalControls.h" #include "BAPhysicalControls.h"
#endif /* __BATGUITAR_H */ #endif /* __BALIBRARY_H */

@ -200,6 +200,11 @@ public:
/// @param val the value to set the output. 0 is low, not zero is high. /// @param val the value to set the output. 0 is low, not zero is high.
void setOutput(unsigned handle, int val); void setOutput(unsigned handle, int val);
/// Set the output specified by the provided handle
/// @param handle the handle that was provided previously by calling addOutput()
/// @param val the value to set the output. True is high, false is low.
void setOutput(unsigned handle, bool val);
/// Toggle the output specified by the provided handle /// Toggle the output specified by the provided handle
/// @param handle the handle that was provided previously by calling addOutput() /// @param handle the handle that was provided previously by calling addOutput()
void toggleOutput(unsigned handle); void toggleOutput(unsigned handle);

@ -3,7 +3,7 @@
* @author Steve Lascos * @author Steve Lascos
* @company Blackaddr Audio * @company Blackaddr Audio
* *
* This file contains some custom types used by the rest of the BAGuitar library. * This file contains some custom types used by the rest of the BALibrary library.
* *
* @copyright This program is free software: you can redistribute it and/or modify * @copyright 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 * it under the terms of the GNU General Public License as published by
@ -18,6 +18,7 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*****************************************************************************/ *****************************************************************************/
#include <Arduino.h>
#ifndef __BALIBRARY_BATYPES_H #ifndef __BALIBRARY_BATYPES_H
#define __BALIBRARY_BATYPES_H #define __BALIBRARY_BATYPES_H

@ -85,6 +85,12 @@ void BAPhysicalControls::setOutput(unsigned handle, int val) {
m_outputs[handle].set(val); m_outputs[handle].set(val);
} }
void BAPhysicalControls::setOutput(unsigned handle, bool val) {
if (handle >= m_outputs.size()) { return; }
unsigned value = val ? true : false;
m_outputs[handle].set(value);
}
void BAPhysicalControls::toggleOutput(unsigned handle) { void BAPhysicalControls::toggleOutput(unsigned handle) {
if (handle >= m_outputs.size()) { return; } if (handle >= m_outputs.size()) { return; }
m_outputs[handle].toggle(); m_outputs[handle].toggle();

Loading…
Cancel
Save