From f0c0dbb1978875f1d02572344dd327cfcae04efc Mon Sep 17 00:00:00 2001 From: Steve Lascos Date: Mon, 10 Sep 2018 21:07:21 -0400 Subject: [PATCH] Work in progress --- README.md | 12 +- doc/doxygen.cfg | 2 +- .../BA0_TGA_Pro_TRY_FIRST.ino | 10 +- .../BA1_TGA_Pro_demo/BA1_TGA_Pro_demo.ino | 6 +- .../BA2_TGA_Pro_1MEM/BA2_TGA_Pro_1MEM.ino | 6 +- .../BA3_TGA_Pro_2MEM/BA3_TGA_Pro_2MEM.ino | 6 +- .../BA4_TGA_Pro_delay_reverb.ino | 6 +- .../BA5_TGA_Pro_ExternalDelay_demo.ino | 6 +- .../BAExpansionCalibrate.ino | 2 +- .../Delay/AnalogDelayDemo/AnalogDelayDemo.ino | 2 +- .../AnalogDelayDemoExpansion.ino | 8 +- .../SoundOnSoundDemo/SoundOnSoundDemo.ino | 6 +- .../SoundOnSoundExpansionDemo.ino | 6 +- examples/Tests/BaudrateTest/BaudrateTest.ino | 94 +++++++++++++ .../Tests/DMA_MEM0_test/DMA_MEM0_test.ino | 18 +-- .../Tests/DMA_MEM1_test/DMA_MEM1_test.ino | 19 ++- .../Tests/TGA_PRO_MEM2/PhysicalControls.cpp | 86 ++++++++++++ examples/Tests/TGA_PRO_MEM2/TGA_PRO_MEM2.ino | 59 +++++++++ examples/Tests/TGA_PRO_MEM2/UartTest.cpp | 86 ++++++++++++ examples/Tests/TGA_PRO_MEM2/spiTest.cpp | 125 ++++++++++++++++++ library.properties | 4 +- src/BAHardware.h | 4 +- src/{BAGuitar.h => BALibrary.h} | 12 +- src/BAPhysicalControls.h | 5 + src/BATypes.h | 3 +- src/peripherals/BAPhysicalControls.cpp | 6 + 26 files changed, 529 insertions(+), 70 deletions(-) create mode 100644 examples/Tests/BaudrateTest/BaudrateTest.ino create mode 100644 examples/Tests/TGA_PRO_MEM2/PhysicalControls.cpp create mode 100644 examples/Tests/TGA_PRO_MEM2/TGA_PRO_MEM2.ino create mode 100644 examples/Tests/TGA_PRO_MEM2/UartTest.cpp create mode 100644 examples/Tests/TGA_PRO_MEM2/spiTest.cpp rename src/{BAGuitar.h => BALibrary.h} (84%) diff --git a/README.md b/README.md index 144991b..0653042 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -## BAGuitar Library +## BALibrary Library This library is under active development as of 2018. **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. -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** -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). 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.. - 4. Include "BAGuitar.h" in your sketch. + 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 "BALibrary.h" in your sketch. **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** - WM871 advanced codec control diff --git a/doc/doxygen.cfg b/doc/doxygen.cfg index 69efe81..c80d175 100644 --- a/doc/doxygen.cfg +++ b/doc/doxygen.cfg @@ -4,7 +4,7 @@ # Project related configuration options #--------------------------------------------------------------------------- DOXYFILE_ENCODING = UTF-8 -PROJECT_NAME = "Blackaddr Audio BAGuitar Library" +PROJECT_NAME = "Blackaddr Audio BALibrary Library" PROJECT_NUMBER = PROJECT_BRIEF = PROJECT_LOGO = diff --git a/examples/BA0_TGA_Pro_TRY_FIRST/BA0_TGA_Pro_TRY_FIRST.ino b/examples/BA0_TGA_Pro_TRY_FIRST/BA0_TGA_Pro_TRY_FIRST.ino index 207678f..820f046 100644 --- a/examples/BA0_TGA_Pro_TRY_FIRST/BA0_TGA_Pro_TRY_FIRST.ino +++ b/examples/BA0_TGA_Pro_TRY_FIRST/BA0_TGA_Pro_TRY_FIRST.ino @@ -2,20 +2,20 @@ * This demo uses only the built-in libraries provided with the Arudino * Teensy libraries. * - * IT IS STRONGLY RECOMMENDED to use the BAGuitar Library located at - * https://github.com/Blackaddr/BAGuitar - * The BAGuitar library will made it easier to use the features of your + * 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 BAGuitar library + * 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 BAGuitar repo from github as a zip file. + * the BALibrary repo from github as a zip file. * */ diff --git a/examples/BA1_TGA_Pro_demo/BA1_TGA_Pro_demo.ino b/examples/BA1_TGA_Pro_demo/BA1_TGA_Pro_demo.ino index c66cf6c..36b3506 100644 --- a/examples/BA1_TGA_Pro_demo/BA1_TGA_Pro_demo.ino +++ b/examples/BA1_TGA_Pro_demo/BA1_TGA_Pro_demo.ino @@ -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 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 * MIDI interface. @@ -14,7 +14,7 @@ #include #include #include -#include "BAGuitar.h" +#include "BALibrary.h" MIDI_CREATE_DEFAULT_INSTANCE(); using namespace midi; diff --git a/examples/BA2_TGA_Pro_1MEM/BA2_TGA_Pro_1MEM.ino b/examples/BA2_TGA_Pro_1MEM/BA2_TGA_Pro_1MEM.ino index 8e1211f..fc1d1ef 100644 --- a/examples/BA2_TGA_Pro_1MEM/BA2_TGA_Pro_1MEM.ino +++ b/examples/BA2_TGA_Pro_1MEM/BA2_TGA_Pro_1MEM.ino @@ -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 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 * MIDI interface. @@ -18,7 +18,7 @@ #include #include #include -#include "BAGuitar.h" +#include "BALibrary.h" MIDI_CREATE_DEFAULT_INSTANCE(); using namespace midi; diff --git a/examples/BA3_TGA_Pro_2MEM/BA3_TGA_Pro_2MEM.ino b/examples/BA3_TGA_Pro_2MEM/BA3_TGA_Pro_2MEM.ino index 40f0adb..9e38753 100644 --- a/examples/BA3_TGA_Pro_2MEM/BA3_TGA_Pro_2MEM.ino +++ b/examples/BA3_TGA_Pro_2MEM/BA3_TGA_Pro_2MEM.ino @@ -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 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 * MIDI interface. @@ -19,7 +19,7 @@ #include #include #include -#include "BAGuitar.h" +#include "BALibrary.h" MIDI_CREATE_DEFAULT_INSTANCE(); using namespace midi; diff --git a/examples/BA4_TGA_Pro_delay_reverb/BA4_TGA_Pro_delay_reverb.ino b/examples/BA4_TGA_Pro_delay_reverb/BA4_TGA_Pro_delay_reverb.ino index 0eb2353..00cf62f 100644 --- a/examples/BA4_TGA_Pro_delay_reverb/BA4_TGA_Pro_delay_reverb.ino +++ b/examples/BA4_TGA_Pro_delay_reverb/BA4_TGA_Pro_delay_reverb.ino @@ -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 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, * followed by a reverb and a low-pass cabinet filter. @@ -12,7 +12,7 @@ #include #include #include -#include "BAGuitar.h" +#include "BALibrary.h" using namespace BAEffects; using namespace BALibrary; diff --git a/examples/BA5_TGA_Pro_ExternalDelay_demo/BA5_TGA_Pro_ExternalDelay_demo.ino b/examples/BA5_TGA_Pro_ExternalDelay_demo/BA5_TGA_Pro_ExternalDelay_demo.ino index 1f3618f..e67658d 100644 --- a/examples/BA5_TGA_Pro_ExternalDelay_demo/BA5_TGA_Pro_ExternalDelay_demo.ino +++ b/examples/BA5_TGA_Pro_ExternalDelay_demo/BA5_TGA_Pro_ExternalDelay_demo.ino @@ -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 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 * to create long delays using external SPI RAM. @@ -12,7 +12,7 @@ * */ -#include "BAGuitar.h" +#include "BALibrary.h" using namespace BAEffects; using namespace BALibrary; diff --git a/examples/BAExpansionCalibrate/BAExpansionCalibrate.ino b/examples/BAExpansionCalibrate/BAExpansionCalibrate.ino index 1429183..aaed076 100644 --- a/examples/BAExpansionCalibrate/BAExpansionCalibrate.ino +++ b/examples/BAExpansionCalibrate/BAExpansionCalibrate.ino @@ -1,7 +1,7 @@ #define TGA_PRO_REVB #define TGA_PRO_EXPAND_REV2 -#include "BAGuitar.h" +#include "BALibrary.h" using namespace BALibrary; diff --git a/examples/Delay/AnalogDelayDemo/AnalogDelayDemo.ino b/examples/Delay/AnalogDelayDemo/AnalogDelayDemo.ino index d057c5a..d41781b 100644 --- a/examples/Delay/AnalogDelayDemo/AnalogDelayDemo.ino +++ b/examples/Delay/AnalogDelayDemo/AnalogDelayDemo.ino @@ -1,5 +1,5 @@ #include -#include "BAGuitar.h" +#include "BALibrary.h" using namespace midi; using namespace BAEffects; diff --git a/examples/Delay/AnalogDelayDemoExpansion/AnalogDelayDemoExpansion.ino b/examples/Delay/AnalogDelayDemoExpansion/AnalogDelayDemoExpansion.ino index 5fcff26..4b8f892 100644 --- a/examples/Delay/AnalogDelayDemoExpansion/AnalogDelayDemoExpansion.ino +++ b/examples/Delay/AnalogDelayDemoExpansion/AnalogDelayDemoExpansion.ino @@ -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 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 * 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_EXPAND_REV2 // pull in the pin definitions for the Blackaddr Audio Expansion Board. -#include "BAGuitar.h" +#include "BALibrary.h" using namespace BAEffects; using namespace BALibrary; @@ -154,7 +154,7 @@ void loop() { } // Use SW2 to cycle through the filters - controls.setOutput(led2Handle, controls.getSwitchValue(led2Handle)); + controls.setOutput(led2Handle, !controls.getSwitchValue(led2Handle)); if (controls.isSwitchToggled(filterHandle)) { 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 diff --git a/examples/Delay/SoundOnSoundDemo/SoundOnSoundDemo.ino b/examples/Delay/SoundOnSoundDemo/SoundOnSoundDemo.ino index ec22c9a..d23cb65 100644 --- a/examples/Delay/SoundOnSoundDemo/SoundOnSoundDemo.ino +++ b/examples/Delay/SoundOnSoundDemo/SoundOnSoundDemo.ino @@ -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 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 * MIDI interface. @@ -15,7 +15,7 @@ #include #include #include -#include "BAGuitar.h" +#include "BALibrary.h" #include static const unsigned sUsbTransportBufferSize = 16; diff --git a/examples/Delay/SoundOnSoundExpansionDemo/SoundOnSoundExpansionDemo.ino b/examples/Delay/SoundOnSoundExpansionDemo/SoundOnSoundExpansionDemo.ino index 85a8d88..cc04a54 100644 --- a/examples/Delay/SoundOnSoundExpansionDemo/SoundOnSoundExpansionDemo.ino +++ b/examples/Delay/SoundOnSoundExpansionDemo/SoundOnSoundExpansionDemo.ino @@ -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 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 * @@ -17,7 +17,7 @@ #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. -#include "BAGuitar.h" +#include "BALibrary.h" using namespace BAEffects; using namespace BALibrary; diff --git a/examples/Tests/BaudrateTest/BaudrateTest.ino b/examples/Tests/BaudrateTest/BaudrateTest.ino new file mode 100644 index 0000000..6bf83c0 --- /dev/null +++ b/examples/Tests/BaudrateTest/BaudrateTest.ino @@ -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); + } + } +} diff --git a/examples/Tests/DMA_MEM0_test/DMA_MEM0_test.ino b/examples/Tests/DMA_MEM0_test/DMA_MEM0_test.ino index 8eb5859..cedb884 100644 --- a/examples/Tests/DMA_MEM0_test/DMA_MEM0_test.ino +++ b/examples/Tests/DMA_MEM0_test/DMA_MEM0_test.ino @@ -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 latest copy of the BA Guitar library can be obtained from - * https://github.com/Blackaddr/BAGuitar + * The latest copy of BALibrary can be obtained from + * https://github.com/Blackaddr/BALibrary * * This demo will perform a DMA memory test on MEM0 attached * to SPI. @@ -13,9 +13,9 @@ * */ #include -#include "BAGuitar.h" +#include "BALibrary.h" -using namespace BAGuitar; +using namespace BALibrary; //#define SANITY #define DMA_SIZE 256 @@ -30,9 +30,8 @@ using namespace BAGuitar; SPISettings memSettings(20000000, MSBFIRST, SPI_MODE0); const int cs0pin = 15; -BAGpio gpio; // access to User LED -BASpiMemoryDMA spiMem0(SpiDeviceId::SPI_DEVICE0); - +BAGpio gpio; // access to User LED +BASpiMemoryDMA spiMem0(SpiDeviceId::SPI_DEVICE0); bool compareBuffers(uint8_t *a, uint8_t *b, size_t numBytes) @@ -64,7 +63,7 @@ void setup() { while (!Serial) {} delay(5); - Serial.println("Enabling SPI"); + Serial.println("Enabling SPI, testing MEM0"); spiMem0.begin(); } @@ -310,6 +309,7 @@ void loop() { spi8BitTest(); spi16BitTest(); + Serial.println("\nTEST DONE!"); while(true) {} } diff --git a/examples/Tests/DMA_MEM1_test/DMA_MEM1_test.ino b/examples/Tests/DMA_MEM1_test/DMA_MEM1_test.ino index 9fca064..a895cfa 100644 --- a/examples/Tests/DMA_MEM1_test/DMA_MEM1_test.ino +++ b/examples/Tests/DMA_MEM1_test/DMA_MEM1_test.ino @@ -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 latest copy of the BA Guitar library can be obtained from - * https://github.com/Blackaddr/BAGuitar + * The latest copy of the BALibrary can be obtained from + * https://github.com/Blackaddr/BALibrary * * This demo will perform a DMA memory test on MEM1 attached * to SPI1. @@ -13,9 +13,9 @@ * */ #include -#include "BAGuitar.h" +#include "BALibrary.h" -using namespace BAGuitar; +using namespace BALibrary; //#define SANITY #define DMA_SIZE 256 @@ -30,10 +30,8 @@ using namespace BAGuitar; SPISettings memSettings(20000000, MSBFIRST, SPI_MODE0); const int cs0pin = 15; -BAGpio gpio; // access to User LED -BASpiMemoryDMA spiMem1(SpiDeviceId::SPI_DEVICE1); - - +BAGpio gpio; // access to User LED +BASpiMemoryDMA spiMem1(SpiDeviceId::SPI_DEVICE1); bool compareBuffers(uint8_t *a, uint8_t *b, size_t numBytes) { @@ -64,7 +62,7 @@ void setup() { while (!Serial) {} delay(5); - Serial.println("Enabling SPI"); + Serial.println("Enabling SPI, testing MEM1"); spiMem1.begin(); } @@ -310,6 +308,7 @@ void loop() { spi8BitTest(); spi16BitTest(); + Serial.println("\nTEST DONE!"); while(true) {} } diff --git a/examples/Tests/TGA_PRO_MEM2/PhysicalControls.cpp b/examples/Tests/TGA_PRO_MEM2/PhysicalControls.cpp new file mode 100644 index 0000000..f61fc16 --- /dev/null +++ b/examples/Tests/TGA_PRO_MEM2/PhysicalControls.cpp @@ -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); +} + + diff --git a/examples/Tests/TGA_PRO_MEM2/TGA_PRO_MEM2.ino b/examples/Tests/TGA_PRO_MEM2/TGA_PRO_MEM2.ino new file mode 100644 index 0000000..6ca392b --- /dev/null +++ b/examples/Tests/TGA_PRO_MEM2/TGA_PRO_MEM2.ino @@ -0,0 +1,59 @@ +#include +#include +#include + +#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); +} diff --git a/examples/Tests/TGA_PRO_MEM2/UartTest.cpp b/examples/Tests/TGA_PRO_MEM2/UartTest.cpp new file mode 100644 index 0000000..0fb866b --- /dev/null +++ b/examples/Tests/TGA_PRO_MEM2/UartTest.cpp @@ -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; +} + diff --git a/examples/Tests/TGA_PRO_MEM2/spiTest.cpp b/examples/Tests/TGA_PRO_MEM2/spiTest.cpp new file mode 100644 index 0000000..fce9b22 --- /dev/null +++ b/examples/Tests/TGA_PRO_MEM2/spiTest.cpp @@ -0,0 +1,125 @@ +#include +#include +#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= 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; iwrite16(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; iisReadBusy()) {} // wait for the read to finish + + for (int i=0; i= 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; +} + diff --git a/library.properties b/library.properties index 4dd2d8b..c8a6a0a 100644 --- a/library.properties +++ b/library.properties @@ -1,4 +1,4 @@ -name=BAGuitar +name=BALibrary version=0.1 author=Steve Lascos maintainer=Steve Lascos @@ -7,4 +7,4 @@ paragraph=Extends the Teensy Audio Library. category=Communication url=www.blackaddr.com architectures=avr -includes=BAGuitar.h \ No newline at end of file +includes=BALibrary.h \ No newline at end of file diff --git a/src/BAHardware.h b/src/BAHardware.h index 232f0dc..68e77db 100644 --- a/src/BAHardware.h +++ b/src/BAHardware.h @@ -23,10 +23,12 @@ #ifndef __BALIBRARY_BAHARDWARE_H #define __BALIBRARY_BAHARDWARE_H +#include #include +#include /**************************************************************************//** - * BAGuitar is a namespace/Library for Guitar processing from Blackaddr Audio. + * BALibrary is a namespace/Library for Guitar processing from Blackaddr Audio. *****************************************************************************/ namespace BALibrary { diff --git a/src/BAGuitar.h b/src/BALibrary.h similarity index 84% rename from src/BAGuitar.h rename to src/BALibrary.h index 1abaff0..c04b0b8 100644 --- a/src/BAGuitar.h +++ b/src/BALibrary.h @@ -1,5 +1,5 @@ /* - * BAGuitar.h + * BALibrary.h * * Created on: May 22, 2017 * Author: slascos @@ -17,9 +17,8 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - -#ifndef __BATGUITAR_H -#define __BATGUITAR_H +#ifndef __BALIBRARY_H +#define __BALIBRARY_H #include "BAHardware.h" // contains the Blackaddr hardware board definitions @@ -27,11 +26,8 @@ #include "BAAudioControlWM8731.h" // Codec Control #include "BASpiMemory.h" #include "BAGpio.h" -#include "BAAudioEffectDelayExternal.h" -#include "AudioEffectAnalogDelay.h" -#include "AudioEffectSOS.h" #include "LibBasicFunctions.h" #include "LibMemoryManagement.h" #include "BAPhysicalControls.h" -#endif /* __BATGUITAR_H */ +#endif /* __BALIBRARY_H */ diff --git a/src/BAPhysicalControls.h b/src/BAPhysicalControls.h index 86abcb4..c436958 100644 --- a/src/BAPhysicalControls.h +++ b/src/BAPhysicalControls.h @@ -200,6 +200,11 @@ public: /// @param val the value to set the output. 0 is low, not zero is high. 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 /// @param handle the handle that was provided previously by calling addOutput() void toggleOutput(unsigned handle); diff --git a/src/BATypes.h b/src/BATypes.h index 01bdc1f..27b34aa 100644 --- a/src/BATypes.h +++ b/src/BATypes.h @@ -3,7 +3,7 @@ * @author Steve Lascos * @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 * 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 * along with this program. If not, see . *****************************************************************************/ +#include #ifndef __BALIBRARY_BATYPES_H #define __BALIBRARY_BATYPES_H diff --git a/src/peripherals/BAPhysicalControls.cpp b/src/peripherals/BAPhysicalControls.cpp index ade567e..c9f2eb2 100644 --- a/src/peripherals/BAPhysicalControls.cpp +++ b/src/peripherals/BAPhysicalControls.cpp @@ -85,6 +85,12 @@ void BAPhysicalControls::setOutput(unsigned handle, int 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) { if (handle >= m_outputs.size()) { return; } m_outputs[handle].toggle();