Skip to content

Commit

Permalink
nRF52: Fix for I2S input double buffering
Browse files Browse the repository at this point in the history
- Change the I2S RXD pointer & set everything before copying data into memory
  • Loading branch information
TMRh20 committed Nov 4, 2024
1 parent 6285868 commit 142dcaa
Showing 1 changed file with 24 additions and 18 deletions.
42 changes: 24 additions & 18 deletions src/NRF52840/AutoAnalogAudio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -268,8 +268,31 @@ void AutoAnalog::getADC(uint32_t samples){
started = true;
}else{
while(NRF_I2S->EVENTS_RXPTRUPD == 0){}
}

if(adcWhichBuf == 0){
NRF_I2S->RXD.PTR = (uint32_t)&adcBuf0[0];
}else{
NRF_I2S->RXD.PTR = (uint32_t)&adcBuf1[0];
}
uint8_t divider = 2;
if(adcBitsPerSample == 24){
divider = 1;
}else
if(adcBitsPerSample == 8){
divider = 4;
}

if(useI2S == 2 || useI2S == 3){
NRF_I2S->RXTXD.MAXCNT = samples / divider;
}

NRF_I2S->EVENTS_RXPTRUPD = 0;
if(started){
NRF_I2S->TASKS_START = 1;
}


if(adcBitsPerSample == 24){
if( NRF_I2S->CONFIG.SWIDTH != I2S_CONFIG_SWIDTH_SWIDTH_24BIT << I2S_CONFIG_SWIDTH_SWIDTH_Pos){
NRF_I2S->CONFIG.SWIDTH = I2S_CONFIG_SWIDTH_SWIDTH_24BIT << I2S_CONFIG_SWIDTH_SWIDTH_Pos;
Expand All @@ -279,7 +302,6 @@ void AutoAnalog::getADC(uint32_t samples){
}else{
memcpy(adcBuffer16, adcBuf1, samples * 4);
}
divider = 1;
}else
if(adcBitsPerSample == 16){
if(adcWhichBuf == 0){
Expand All @@ -294,25 +316,9 @@ void AutoAnalog::getADC(uint32_t samples){
}else{
memcpy(adcBuffer, adcBuf1, samples);
}
divider = 4;
}
if(adcWhichBuf == 0){
NRF_I2S->RXD.PTR = (uint32_t)&adcBuf0[0];
}else{
NRF_I2S->RXD.PTR = (uint32_t)&adcBuf1[0];
}
adcWhichBuf = !adcWhichBuf;



if(useI2S == 2 || useI2S == 3){
NRF_I2S->RXTXD.MAXCNT = samples / divider;
}

NRF_I2S->EVENTS_RXPTRUPD = 0;
if(started){
NRF_I2S->TASKS_START = 1;
}
adcWhichBuf = !adcWhichBuf;

}else
if(useI2S == 0){
Expand Down

0 comments on commit 142dcaa

Please sign in to comment.