@@ -70,9 +70,6 @@ typedef struct i2s_state {
70
70
static i2s_state_t * rx = NULL ;
71
71
static i2s_state_t * tx = NULL ;
72
72
73
- volatile uint32_t rx_irqs = 0 ;
74
- volatile uint32_t tx_irqs = 0 ;
75
-
76
73
// IOs used for I2S. Not defined in i2s.h, unfortunately.
77
74
// Note these are internal IOs numbers and not pins on an
78
75
// Arduino board. Users need to verify their particular wiring.
@@ -159,7 +156,6 @@ void ICACHE_RAM_ATTR i2s_slc_isr(void) {
159
156
uint32_t slc_intr_status = SLCIS ;
160
157
SLCIC = 0xFFFFFFFF ;
161
158
if (slc_intr_status & SLCIRXEOF ) {
162
- tx_irqs ++ ;
163
159
slc_queue_item_t * finished_item = (slc_queue_item_t * )SLCRXEDA ;
164
160
// Zero the buffer so it is mute in case of underflow
165
161
ets_memset ((void * )finished_item -> buf_ptr , 0x00 , SLC_BUF_LEN * 4 );
@@ -173,7 +169,6 @@ void ICACHE_RAM_ATTR i2s_slc_isr(void) {
173
169
}
174
170
}
175
171
if (slc_intr_status & SLCITXEOF ) {
176
- rx_irqs ++ ;
177
172
slc_queue_item_t * finished_item = (slc_queue_item_t * )SLCTXEDA ;
178
173
// Set owner back to 1 (SW) or else RX stops. TX has no such restriction.
179
174
finished_item -> owner = 1 ;
@@ -210,16 +205,6 @@ static void _alloc_channel(i2s_state_t *ch) {
210
205
}
211
206
}
212
207
213
- #if 0
214
- void dumprx ()
215
- {
216
- for (int i = 0 ; i < SLC_BUF_CNT ; i ++ ) {
217
- printf ("%d: %d %d %d %d %d %d %p %p\n" , i , 0 , rx -> slc_items [i ].owner , rx -> slc_items [i ].eof , rx -> slc_items [i ].sub_sof , rx -> slc_items [i ].datalen , rx -> slc_items [i ].blocksize ,
218
- rx -> slc_items [i ].buf_ptr , rx -> slc_items [i ].next_link_ptr );
219
- }
220
- }
221
- #endif
222
-
223
208
static void i2s_slc_begin () {
224
209
if (tx ) {
225
210
_alloc_channel (tx );
@@ -327,7 +312,7 @@ bool i2s_write_lr(int16_t left, int16_t right){
327
312
return i2s_write_sample (sample );
328
313
}
329
314
330
- bool i2s_read_sample (uint32_t * left , uint32_t * right , bool blocking ) {
315
+ bool i2s_read_sample (int16_t * left , int16_t * right , bool blocking ) {
331
316
if (rx -> curr_slc_buf_pos == SLC_BUF_LEN || rx -> curr_slc_buf == NULL ) {
332
317
if (rx -> slc_queue_len == 0 ) {
333
318
if (!blocking ) return false;
@@ -345,8 +330,9 @@ bool i2s_read_sample(uint32_t *left, uint32_t *right, bool blocking) {
345
330
rx -> curr_slc_buf_pos = 0 ;
346
331
}
347
332
348
- * left = rx -> curr_slc_buf [rx -> curr_slc_buf_pos ++ ];
349
- * right = rx -> curr_slc_buf [rx -> curr_slc_buf_pos ++ ];
333
+ uint32_t sample = rx -> curr_slc_buf [rx -> curr_slc_buf_pos ++ ];
334
+ * left = sample & 0xffff ;
335
+ * right = sample >> 16 ;
350
336
351
337
return true;
352
338
}
@@ -381,7 +367,7 @@ void i2s_set_dividers(uint8_t div1, uint8_t div2) {
381
367
div1 &= I2SBDM ;
382
368
div2 &= I2SCDM ;
383
369
384
- // ! trans master(? ), ! recv master(? ), !bits mod(==16 bits/chanel), clear clock dividers
370
+ // trans master(active low ), recv master(active_low ), !bits mod(==16 bits/chanel), clear clock dividers
385
371
I2SC &= ~(I2STSM | I2SRSM | (I2SBMM << I2SBM ) | (I2SBDM << I2SBD ) | (I2SCDM << I2SCD ));
386
372
387
373
// I2SRF = Send/recv right channel first (? may be swapped form I2S spec of WS=0 => left)
@@ -438,17 +424,17 @@ void i2s_rxtx_begin(bool enableRx, bool enableTx) {
438
424
439
425
// I2STXFMM, I2SRXFMM=0 => 16-bit, dual channel data shifted in/out
440
426
I2SFC &= ~(I2SDE | (I2STXFMM << I2STXFM ) | (I2SRXFMM << I2SRXFM )); // Set RX/TX FIFO_MOD=0 and disable DMA (FIFO only)
441
- I2SFC |= I2SDE | ( rx ? 2 /*24bpc, 2ch*/ << I2SRXFM : 0 ) ; // Enable DMA, set RX format 24(32bits), 2 channels
427
+ I2SFC |= I2SDE ; // Enable DMA
442
428
443
429
// I2STXCMM, I2SRXCMM=0 => Dual channel mode
444
430
I2SCC &= ~((I2STXCMM << I2STXCM ) | (I2SRXCMM << I2SRXCM )); // Set RX/TX CHAN_MOD=0
445
431
446
432
i2s_set_rate (44100 );
447
433
448
434
if (rx ) {
435
+ // Need to prime the # of samples to receive in the engine
449
436
I2SRXEN = SLC_BUF_LEN ;
450
437
}
451
- // I2SC |= (15<<I2SBM);
452
438
453
439
I2SC |= (rx ?I2SRXS :0 ) | (tx ?I2STXS :0 ); // Start transmission/reception
454
440
}
0 commit comments