From 15514adf8bfae386e09bffe3207993cd86f1541e Mon Sep 17 00:00:00 2001 From: TMRh20 Date: Sat, 2 Nov 2024 03:41:46 -0600 Subject: [PATCH] nRF52: Smooth transition between tracks - When calling getADC or feedDAC functions, only enable the I2S interface, then load the buffers, then start the I2S interface instead of Enabling & Starting off the beginning - Now users can call disableDAC() and then start feeding the DAC again, and it should provide a smoother transition --- src/NRF52840/AutoAnalogAudio.cpp | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/src/NRF52840/AutoAnalogAudio.cpp b/src/NRF52840/AutoAnalogAudio.cpp index d5968bb..8469d9a 100644 --- a/src/NRF52840/AutoAnalogAudio.cpp +++ b/src/NRF52840/AutoAnalogAudio.cpp @@ -258,13 +258,14 @@ void AutoAnalog::getADC(uint32_t samples){ if(useI2S == 2 || useI2S == 3){ + + bool started = false; if(NRF_I2S->ENABLE == 0){ NRF_I2S->ENABLE = 1; - NRF_I2S->TASKS_START = 1; + started = true; + }else{ + while(NRF_I2S->EVENTS_RXPTRUPD == 0){} } - - while(NRF_I2S->EVENTS_RXPTRUPD == 0){} - uint8_t divider = 2; if(adcBitsPerSample == 24){ if( NRF_I2S->CONFIG.SWIDTH != I2S_CONFIG_SWIDTH_SWIDTH_24BIT << I2S_CONFIG_SWIDTH_SWIDTH_Pos){ @@ -304,8 +305,12 @@ void AutoAnalog::getADC(uint32_t samples){ if(useI2S == 2 || useI2S == 3){ NRF_I2S->RXTXD.MAXCNT = samples / divider; } - NRF_I2S->EVENTS_RXPTRUPD = 0; - + + NRF_I2S->EVENTS_RXPTRUPD = 0; + if(started){ + NRF_I2S->TASKS_START = 1; + } + }else{ while(!adcReady){__WFE();}; aSize = samples; @@ -321,12 +326,14 @@ void AutoAnalog::feedDAC(uint8_t dacChannel, uint32_t samples, bool startInterru if(useI2S == 1 || useI2S == 3){ + bool started = false; if(NRF_I2S->ENABLE == 0){ NRF_I2S->ENABLE = 1; - NRF_I2S->TASKS_START = 1; + started = true; + }else{ + while(NRF_I2S->EVENTS_TXPTRUPD == 0){} } - while(NRF_I2S->EVENTS_TXPTRUPD == 0){} if(dacBitsPerSample == 8){ if(whichBuf){ for(uint32_t i=0; i< samples; i++){ @@ -375,7 +382,11 @@ void AutoAnalog::feedDAC(uint8_t dacChannel, uint32_t samples, bool startInterru NRF_I2S->RXTXD.MAXCNT = samples / divider; NRF_I2S->EVENTS_TXPTRUPD = 0; - + + if(started){ + NRF_I2S->TASKS_START = 1; + } + }else{ uint32_t timer = millis() + 1000; while(NRF_PWM0->EVENTS_SEQEND[0] == 0){