| // 2015/08/23: (FB) added mute_PCM() - sets or unsets VALID in VUCP (and adjusts PARITY) | // 2015/08/23: (FB) added mute_PCM() - sets or unsets VALID in VUCP (and adjusts PARITY) | ||||
| #if defined(__IMXRT1052__) || defined(__IMXRT1062__) | |||||
| #include <Arduino.h> | #include <Arduino.h> | ||||
| #include "output_spdif2.h" | #include "output_spdif2.h" | ||||
| #include "utility/imxrt_hw.h" | #include "utility/imxrt_hw.h" | ||||
| uint16_t AudioOutputSPDIF2::block_right_offset = 0; | uint16_t AudioOutputSPDIF2::block_right_offset = 0; | ||||
| bool AudioOutputSPDIF2::update_responsibility = false; | bool AudioOutputSPDIF2::update_responsibility = false; | ||||
| /* DMAMEM */ static uint32_t SPDIF_tx_buffer[AUDIO_BLOCK_SAMPLES * 4]; //2 KB | |||||
| DMAMEM __attribute__((aligned(32))) | |||||
| static uint32_t SPDIF_tx_buffer[AUDIO_BLOCK_SAMPLES * 4]; //2 KB | |||||
| DMAChannel AudioOutputSPDIF2::dma(false); | DMAChannel AudioOutputSPDIF2::dma(false); | ||||
| #if defined(__IMXRT1052__) || defined(__IMXRT1062__) | |||||
| #define PREAMBLE_B (0xE8) //11101000 | #define PREAMBLE_B (0xE8) //11101000 | ||||
| #define PREAMBLE_M (0xE2) //11100010 | #define PREAMBLE_M (0xE2) //11100010 | ||||
| #define PREAMBLE_W (0xE4) //11100100 | #define PREAMBLE_W (0xE4) //11100100 | ||||
| 0x32aa, 0xb2aa, 0xd2aa, 0x52aa, 0xcaaa, 0x4aaa, 0x2aaa, 0xaaaa | 0x32aa, 0xb2aa, 0xd2aa, 0x52aa, 0xcaaa, 0x4aaa, 0x2aaa, 0xaaaa | ||||
| }; | }; | ||||
| PROGMEM | |||||
| void AudioOutputSPDIF2::begin(void) | void AudioOutputSPDIF2::begin(void) | ||||
| { | { | ||||
| end = (int32_t *)&SPDIF_tx_buffer[AUDIO_BLOCK_SAMPLES * 4/2]; | end = (int32_t *)&SPDIF_tx_buffer[AUDIO_BLOCK_SAMPLES * 4/2]; | ||||
| } | } | ||||
| block = AudioOutputSPDIF2::block_left_1st; | block = AudioOutputSPDIF2::block_left_1st; | ||||
| if (block) { | if (block) { | ||||
| offset = AudioOutputSPDIF2::block_left_offset; | offset = AudioOutputSPDIF2::block_left_offset; | ||||
| } while (dest < end); | } while (dest < end); | ||||
| } | } | ||||
| #if IMXRT_CACHE_ENABLED >= 2 | |||||
| dest -= AUDIO_BLOCK_SAMPLES * 4/2 + 4/2; | |||||
| arm_dcache_flush_delete(dest, sizeof(SPDIF_tx_buffer) / 2 ); | |||||
| #endif | |||||
| } | } | ||||
| void AudioOutputSPDIF2::mute_PCM(const bool mute) | void AudioOutputSPDIF2::mute_PCM(const bool mute) | ||||
| } | } | ||||
| PROGMEM | |||||
| void AudioOutputSPDIF2::config_SPDIF(void) | void AudioOutputSPDIF2::config_SPDIF(void) | ||||
| { | { | ||||
| CCM_CCGR5 |= CCM_CCGR5_SAI2(CCM_CCGR_ON); | CCM_CCGR5 |= CCM_CCGR5_SAI2(CCM_CCGR_ON); |