Skip to content

Commit c1be134

Browse files
committedApr 4, 2016
CurieI2S - minor fixes/improvements
-prevent buffer overflow in I2S_RxCallback example -calculate delay for any sample rate
1 parent 89dd228 commit c1be134

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed
 

‎libraries/CurieI2S/examples/I2S_RxCallback/I2S_RxCallback.ino

+1
Original file line numberDiff line numberDiff line change
@@ -49,5 +49,6 @@ void rxDataReceived()
4949
while(CurieI2S.available())
5050
{
5151
dataBuff[count++] = CurieI2S.requestdword();
52+
count %= 256; //prevent buffer overflow and just write data in front of the buffer.
5253
}
5354
}

‎libraries/CurieI2S/src/CurieI2S.cpp

+10-1
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,8 @@ static void i2sInterruptHandler(void)
222222
//TXFIFO and tx buffer empty
223223

224224
//last frame delay
225-
delayTicks(960);
225+
//delayTicks(960);
226+
CurieI2S.lastFrameDelay();
226227
//stop transmission
227228
*I2S_CTRL = *I2S_CTRL & 0xFDFFFFFE;
228229

@@ -357,6 +358,9 @@ void Curie_I2S::setSampleRate(uint32_t dividerValue)
357358
i2s_srr &= I2S_SAMPLERATE_MASK;
358359
i2s_srr |= dividerValue;
359360
*I2S_SRR = i2s_srr;
361+
362+
//set frameDelay value.
363+
frameDelay = (dividerValue&0x000000FF)*32*2;
360364
}
361365

362366
void Curie_I2S::setResolution(uint32_t resolution)
@@ -632,6 +636,11 @@ uint8_t Curie_I2S::getRxFIFOLength()
632636
return fifolength;
633637
}
634638

639+
void Curie_I2S::lastFrameDelay()
640+
{
641+
delayTicks(frameDelay);
642+
}
643+
635644
void Curie_I2S::attachRxInterrupt(void (*userCallBack)())
636645
{
637646
i2s_rxCB = userCallBack;

‎libraries/CurieI2S/src/CurieI2S.h

+5
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,9 @@ class Curie_I2S
9696
{
9797
private:
9898
uint32_t clock;
99+
100+
int frameDelay = 0;
101+
99102
bool useDMA;
100103

101104
// initializes i2s interface
@@ -202,6 +205,8 @@ class Curie_I2S
202205

203206
uint8_t getRxFIFOLength();
204207

208+
void lastFrameDelay();
209+
205210
// Attach user callback that is triggered when there is data pushed into the rx buffer from the RX_FIFO
206211
void attachRxInterrupt(void (*userCallBack)());
207212

0 commit comments

Comments
 (0)
Please sign in to comment.