3636// This version is 4 channel I2S output. Greg Raven KF5N October, 2025
3737
3838#include " output_i2s_quad_f32.h"
39- #include " output_i2s_f32.h" // Required for 2 channel to be a "friend" so its I2S configuration method can be used.
40- #include < arm_math.h>
41- #include < utility/imxrt_hw.h> // From Teensy Audio library. For set_audioClock().
4239
4340DMAChannel AudioOutputI2SQuad_F32::dma (false );
4441DMAMEM __attribute__ ((aligned(32 ))) static float32_t i2s_tx_buffer[AUDIO_BLOCK_SAMPLES * 4]; // 4 channels 128 samples each, total = 512.
4542
46- void AudioOutputI2SQuad_F32::begin (void )
47- {
48- bool transferUsing32bit = false ;
49- begin (transferUsing32bit);
50- }
51-
52- void AudioOutputI2SQuad_F32::begin (bool transferUsing32bit)
43+ void AudioOutputI2SQuad_F32::begin ()
5344{
5445 // Configure most of the I2S.
55- AudioOutputI2S_F32::config_i2s (transferUsing32bit);
56- // Configure the rest of the I2S unique to quad output.
57- I2S1_RCSR |= I2S_RCSR_RE | I2S_RCSR_BCE;
58- I2S1_TCSR = I2S_TCSR_TE | I2S_TCSR_BCE | I2S_TCSR_FRDE;
59- I2S1_TCR3 = I2S_TCR3_TCE_2CH;
46+ AudioOutputI2SQuad_F32::config_i2s (sample_rate_Hz);
47+
48+ // Configure the I2S output pins.
6049 CORE_PIN7_CONFIG = 3 ; // Teensy pin 7 is 1st and 2nd channels of I2S (Audio Adapter on Teensy 4.1).
6150 CORE_PIN32_CONFIG = 3 ; // Teensy pin 32 is 3rd and 4th channels of I2S.
51+
52+ // Zero the transmit buffer.
6253 memset (i2s_tx_buffer, 0 , sizeof (i2s_tx_buffer));
6354
6455 // Configure the DMA channel.
@@ -81,6 +72,11 @@ void AudioOutputI2SQuad_F32::begin(bool transferUsing32bit)
8172 update_responsibility = update_setup ();
8273 dma.enable ();
8374 enabled = 1 ; // What is this?
75+
76+ // Configure the rest of the I2S unique to quad output.
77+ I2S1_RCSR |= I2S_RCSR_RE | I2S_RCSR_BCE;
78+ I2S1_TCSR = I2S_TCSR_TE | I2S_TCSR_BCE | I2S_TCSR_FRDE;
79+ I2S1_TCR3 = I2S_TCR3_TCE_2CH;
8480}
8581
8682// Interrupt service routine called twice per update by the DMA.
@@ -280,12 +276,7 @@ void AudioOutputI2SQuad_F32::update(void)
280276}
281277
282278// Configure the I2S peripheral. This is most, but not all, of the configuration. The rest is done by begin().
283- // Note that the version of this method can be called from the dual channel object via "friend".
284- void AudioOutputI2SQuad_F32::config_i2s (void ) { config_i2s (false , AudioOutputI2SQuad_F32::sample_rate_Hz); }
285- void AudioOutputI2SQuad_F32::config_i2s (bool transferUsing32bit) { config_i2s (transferUsing32bit, AudioOutputI2SQuad_F32::sample_rate_Hz); }
286- void AudioOutputI2SQuad_F32::config_i2s (float fs_Hz) { config_i2s (false , fs_Hz); }
287-
288- void AudioOutputI2SQuad_F32::config_i2s (bool transferUsing32bit, float fs_Hz)
279+ void AudioOutputI2SQuad_F32::config_i2s (int fs_Hz)
289280{
290281 CCM_CCGR5 |= CCM_CCGR5_SAI1 (CCM_CCGR_ON);
291282
0 commit comments