Skip to content

Commit

Permalink
First pass at Teensy 3.x compatibility
Browse files Browse the repository at this point in the history
A number of objects had conditional compilation which was untested when compiling for Teensy 4.x, and didn't work. These now compile OK, though aren't tested at the time of this commit.

Also some fixes related to the OSCAudio library, which needed to be made aware of which objects aren't implemented in Teensy 3.x. in general these consist of ensuring the .h files don't define their guard macros, which in turn leads to the OSCAudio library omitting the objects from its lists. A bit fragile and tricksy, but there you go....
  • Loading branch information
h4yn0nnym0u5e committed Jan 14, 2022
1 parent c0ea2f1 commit d568cec
Show file tree
Hide file tree
Showing 18 changed files with 90 additions and 61 deletions.
4 changes: 4 additions & 0 deletions effect_granular.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
* SOFTWARE.
*/

#ifndef _effect_granular_h_
#define _effect_granular_h_

#include "AudioStream.h"

class AudioEffectGranular : public AudioStream
Expand Down Expand Up @@ -64,3 +67,4 @@ class AudioEffectGranular : public AudioStream
bool sample_req;
};

#endif // _effect_granular_h_
2 changes: 1 addition & 1 deletion input_adc.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class AudioInputAnalog : public AudioStream
static dmaState_t dmaState;
static DMAChannel dma;
static void isr(void);
static void init(uint8_t pin);
void init(uint8_t pin);

};

Expand Down
2 changes: 1 addition & 1 deletion input_adcs.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class AudioInputAnalogStereo : public AudioStream
static DMAChannel dma1;
static void isr0(void);
static void isr1(void);
static void init(uint8_t pin0, uint8_t pin1);
void init(uint8_t pin0, uint8_t pin1);
};

#endif
5 changes: 3 additions & 2 deletions input_i2s_hex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
* THE SOFTWARE.
*/

#if defined(__IMXRT1062__)

#include <Arduino.h>
#include "input_i2s_hex.h"
#include "output_i2s.h"
Expand All @@ -40,7 +42,6 @@ bool AudioInputI2SHex::update_responsibility = false;
AudioInputI2SHex::dmaState_t AudioInputI2SHex::dmaState = AOI2S_Stop;
DMAChannel AudioInputI2SHex::dma(false);

#if defined(__IMXRT1062__)

void AudioInputI2SHex::begin(void)
{
Expand Down Expand Up @@ -279,7 +280,7 @@ void AudioInputI2SHex::update(void)
}
}

#else // not supported
#elif 0 // #else // not supported

void AudioInputI2SHex::begin(void)
{
Expand Down
5 changes: 4 additions & 1 deletion input_i2s_hex.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
* THE SOFTWARE.
*/

#if defined(__IMXRT1062__)

#ifndef _input_i2s_hex_h_
#define _input_i2s_hex_h_

Expand Down Expand Up @@ -58,4 +60,5 @@ class AudioInputI2SHex : public AudioStream
};


#endif
#endif // _input_i2s_hex_h_
#endif // hardware capability
6 changes: 3 additions & 3 deletions input_i2s_oct.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
* THE SOFTWARE.
*/

#if defined(__IMXRT1062__)

#include <Arduino.h>
#include "input_i2s_oct.h"
#include "output_i2s.h"
Expand All @@ -42,8 +44,6 @@ bool AudioInputI2SOct::update_responsibility = false;
AudioInputI2SOct::dmaState_t AudioInputI2SOct::dmaState = AOI2S_Stop;
DMAChannel AudioInputI2SOct::dma(false);

#if defined(__IMXRT1062__)

void AudioInputI2SOct::begin(void)
{
if (AOI2S_Stop == dmaState)
Expand Down Expand Up @@ -309,7 +309,7 @@ void AudioInputI2SOct::update(void)
}
}

#else // not supported
#elif 0 // #else // not supported

void AudioInputI2SOct::begin(void)
{
Expand Down
5 changes: 4 additions & 1 deletion input_i2s_oct.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
* THE SOFTWARE.
*/

#if defined(__IMXRT1062__)

#ifndef _input_i2s_oct_h_
#define _input_i2s_oct_h_

Expand Down Expand Up @@ -60,4 +62,5 @@ class AudioInputI2SOct : public AudioStream
};


#endif
#endif // _input_i2s_oct_h_
#endif // hardware capability
9 changes: 3 additions & 6 deletions input_i2s_quad.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,8 @@ void AudioInputI2SQuad::begin(void)

I2S1_RCSR = I2S_RCSR_RE | I2S_RCSR_BCE | I2S_RCSR_FRDE | I2S_RCSR_FR;
dma.enable();
}
#endif
}
update_responsibility = update_setup();
dma.attachInterrupt(isr);
dmaState = AOI2S_Running;
Expand Down Expand Up @@ -283,11 +283,8 @@ void AudioInputI2SQuad::update(void)

#else // not __MK20DX256__

void AudioInputI2SQuad::begin(void)
{
}


void AudioInputI2SQuad::begin(void) {}
AudioInputI2SQuad::~AudioInputI2SQuad() {}

#endif

7 changes: 6 additions & 1 deletion input_pdm_i2s2.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
* THE SOFTWARE.
*/

#if defined(__IMXRT1052__) || defined(__IMXRT1062__)

#ifndef _input_pdm_i2s2_h_
#define _input_pdm_i2s2_h_

Expand Down Expand Up @@ -53,4 +55,7 @@ class AudioInputPDM2 : public AudioStream
static audio_block_t *block_left; // released in destructor
};

#endif
#endif // _input_pdm_i2s2_h_
#endif // defined(__IMXRT1052__) || defined(__IMXRT1062__)


2 changes: 1 addition & 1 deletion output_adat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ void AudioOutputADAT::begin(void)
}


void AudioOutputADAT::~AudioOutputADAT(void)
AudioOutputADAT::~AudioOutputADAT()
{
SAFE_RELEASE_INPUTS();
SAFE_RELEASE_MANY(16,block_ch1_1st,block_ch2_1st,block_ch3_1st,block_ch4_1st,
Expand Down
4 changes: 2 additions & 2 deletions output_dac.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ AudioOutputAnalog::~AudioOutputAnalog()
block_left_1st = NULL;
block_left_2nd = NULL;
update_responsibility = false;
dmaState = AOI2S_paused;
dmaState = AOI2S_Paused;
}

void AudioOutputAnalog::analogReference(int ref)
Expand Down Expand Up @@ -225,7 +225,7 @@ AudioOutputAnalog::~AudioOutputAnalog()
SAFE_RELEASE_MANY(2,block_left_1st,block_left_2nd);
block_left_1st = NULL;
block_left_2nd = NULL;
dmaState = AOI2S_paused;
dmaState = AOI2S_Paused;
}


Expand Down
75 changes: 38 additions & 37 deletions output_dacs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,47 +43,48 @@ void AudioOutputAnalogStereo::begin(void)
{
if (AOI2S_Stop == dmaState)
{
dma.begin(true); // Allocate the DMA channel first
dma.begin(true); // Allocate the DMA channel first

SIM_SCGC2 |= SIM_SCGC2_DAC0 | SIM_SCGC2_DAC1;
DAC0_C0 = DAC_C0_DACEN; // 1.2V VDDA is DACREF_2
DAC1_C0 = DAC_C0_DACEN;
SIM_SCGC2 |= SIM_SCGC2_DAC0 | SIM_SCGC2_DAC1;
DAC0_C0 = DAC_C0_DACEN; // 1.2V VDDA is DACREF_2
DAC1_C0 = DAC_C0_DACEN;

// slowly ramp up to DC voltage, approx 1/4 second
for (int16_t i=0; i<=2048; i+=8) {
*(int16_t *)&(DAC0_DAT0L) = i;
*(int16_t *)&(DAC1_DAT0L) = i;
delay(1);
}
// slowly ramp up to DC voltage, approx 1/4 second
for (int16_t i=0; i<=2048; i+=8) {
*(int16_t *)&(DAC0_DAT0L) = i;
*(int16_t *)&(DAC1_DAT0L) = i;
delay(1);
}

// set the programmable delay block to trigger DMA requests
if (!(SIM_SCGC6 & SIM_SCGC6_PDB)
|| (PDB0_SC & PDB_CONFIG) != PDB_CONFIG
|| PDB0_MOD != PDB_PERIOD
|| PDB0_IDLY != 1
|| PDB0_CH0C1 != 0x0101) {
SIM_SCGC6 |= SIM_SCGC6_PDB;
PDB0_IDLY = 1;
PDB0_MOD = PDB_PERIOD;
PDB0_SC = PDB_CONFIG | PDB_SC_LDOK;
PDB0_SC = PDB_CONFIG | PDB_SC_SWTRIG;
PDB0_CH0C1 = 0x0101;
}
// set the programmable delay block to trigger DMA requests
if (!(SIM_SCGC6 & SIM_SCGC6_PDB)
|| (PDB0_SC & PDB_CONFIG) != PDB_CONFIG
|| PDB0_MOD != PDB_PERIOD
|| PDB0_IDLY != 1
|| PDB0_CH0C1 != 0x0101) {
SIM_SCGC6 |= SIM_SCGC6_PDB;
PDB0_IDLY = 1;
PDB0_MOD = PDB_PERIOD;
PDB0_SC = PDB_CONFIG | PDB_SC_LDOK;
PDB0_SC = PDB_CONFIG | PDB_SC_SWTRIG;
PDB0_CH0C1 = 0x0101;
}

dma.TCD->SADDR = dac_buffer;
dma.TCD->SOFF = 4;
dma.TCD->ATTR = DMA_TCD_ATTR_SSIZE(DMA_TCD_ATTR_SIZE_32BIT) |
DMA_TCD_ATTR_DSIZE(DMA_TCD_ATTR_SIZE_16BIT);
dma.TCD->NBYTES_MLNO = DMA_TCD_NBYTES_MLOFFYES_NBYTES(4) | DMA_TCD_NBYTES_DMLOE |
DMA_TCD_NBYTES_MLOFFYES_MLOFF((&DAC0_DAT0L - &DAC1_DAT0L) * 2);
dma.TCD->SLAST = -sizeof(dac_buffer);
dma.TCD->DADDR = &DAC0_DAT0L;
dma.TCD->DOFF = &DAC1_DAT0L - &DAC0_DAT0L;
dma.TCD->CITER_ELINKNO = sizeof(dac_buffer) / 4;
dma.TCD->DLASTSGA = (&DAC0_DAT0L - &DAC1_DAT0L) * 2;
dma.TCD->BITER_ELINKNO = sizeof(dac_buffer) / 4;
dma.TCD->CSR = DMA_TCD_CSR_INTHALF | DMA_TCD_CSR_INTMAJOR;
dma.triggerAtHardwareEvent(DMAMUX_SOURCE_PDB);
dma.TCD->SADDR = dac_buffer;
dma.TCD->SOFF = 4;
dma.TCD->ATTR = DMA_TCD_ATTR_SSIZE(DMA_TCD_ATTR_SIZE_32BIT) |
DMA_TCD_ATTR_DSIZE(DMA_TCD_ATTR_SIZE_16BIT);
dma.TCD->NBYTES_MLNO = DMA_TCD_NBYTES_MLOFFYES_NBYTES(4) | DMA_TCD_NBYTES_DMLOE |
DMA_TCD_NBYTES_MLOFFYES_MLOFF((&DAC0_DAT0L - &DAC1_DAT0L) * 2);
dma.TCD->SLAST = -sizeof(dac_buffer);
dma.TCD->DADDR = &DAC0_DAT0L;
dma.TCD->DOFF = &DAC1_DAT0L - &DAC0_DAT0L;
dma.TCD->CITER_ELINKNO = sizeof(dac_buffer) / 4;
dma.TCD->DLASTSGA = (&DAC0_DAT0L - &DAC1_DAT0L) * 2;
dma.TCD->BITER_ELINKNO = sizeof(dac_buffer) / 4;
dma.TCD->CSR = DMA_TCD_CSR_INTHALF | DMA_TCD_CSR_INTMAJOR;
dma.triggerAtHardwareEvent(DMAMUX_SOURCE_PDB);
}
update_responsibility = update_setup();
dma.enable();
dma.attachInterrupt(isr);
Expand Down
5 changes: 4 additions & 1 deletion output_pt8211_2.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@

//Frank Bösing, Ben-Rheinland

#if defined(__IMXRT1052__) || defined(__IMXRT1062__)

#ifndef output_pt8211_2_h_
#define output_pt8211_2_h_

Expand Down Expand Up @@ -67,4 +69,5 @@ class AudioOutputPT8211_2 : public AudioStream
audio_block_t *inputQueueArray[2];
};

#endif
#endif // output_pt8211_2_h_
#endif // hardware capability
2 changes: 1 addition & 1 deletion output_pwm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ void AudioOutputPWM::begin(void)
AudioOutputPWM::~AudioOutputPWM(void)
{
SAFE_RELEASE_INPUTS();
SAFE_RELEASE(block);
SAFE_RELEASE_MANY(2,block_1st,block_2nd);
block_1st = NULL;
block_1st = NULL;
update_responsibility = false;
Expand Down
7 changes: 6 additions & 1 deletion output_spdif2.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
* THE SOFTWARE.
*/

#if defined(__IMXRT1052__) || defined(__IMXRT1062__)

#ifndef output_SPDIF2_h_
#define output_SPDIF2_h_

Expand Down Expand Up @@ -57,4 +59,7 @@ class AudioOutputSPDIF2 : public AudioStream
};


#endif
#endif // output_SPDIF2_h_
#endif // defined(__IMXRT1052__) || defined(__IMXRT1062__)


2 changes: 2 additions & 0 deletions output_spdif3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -307,9 +307,11 @@ void AudioOutputSPDIF3::config_spdif3(void)
#if defined(__MK66FX1M0__) || defined(__MK64FX512__) || defined(__MK20DX256__) || defined(__MKL26Z64__)
// empty code to allow compile (but no sound output) on other Teensy models

#if 0 // not needed - .h file excluded and compile will NOT fail silently and puzzle the user!
void AudioOutputSPDIF3::update(void) { }
void AudioOutputSPDIF3::begin(void) { }
void AudioOutputSPDIF3::mute_PCM(const bool mute) { }
bool AudioOutputSPDIF3::pll_locked(void) { return false; }
#endif

#endif
5 changes: 4 additions & 1 deletion output_spdif3.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
* THE SOFTWARE.
*/

#if defined(__IMXRT1062__)

#ifndef output_SPDIF3_h_
#define output_SPDIF3_h_

Expand Down Expand Up @@ -57,4 +59,5 @@ class AudioOutputSPDIF3 : public AudioStream
};


#endif
#endif // output_SPDIF3_h_
#endif // defined(__IMXRT1062__)
4 changes: 3 additions & 1 deletion synth_wavetable.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
* THE SOFTWARE.
*/

#pragma once
#ifndef _synth_wavetable_h_
#define _synth_wavetable_h_

#include "Arduino.h"
#include "AudioStream.h"
Expand Down Expand Up @@ -205,3 +206,4 @@ class AudioSynthWavetable : public AudioStream
volatile int32_t mod_pitch_offset_scnd = 0;
};

#endif // _synth_wavetable_h_

0 comments on commit d568cec

Please sign in to comment.