Skip to content

Commit 0478d47

Browse files
Add simple I2S input example code
1 parent de42ee8 commit 0478d47

File tree

2 files changed

+58
-10
lines changed

2 files changed

+58
-10
lines changed

cores/esp8266/core_esp8266_i2s.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -45,16 +45,16 @@ extern void ets_wdt_disable(void);
4545
// placed onto the list when they're filled by DMA
4646

4747
typedef struct slc_queue_item {
48-
uint32_t blocksize : 12;
49-
uint32_t datalen : 12;
50-
uint32_t unused : 5;
51-
uint32_t sub_sof : 1;
52-
volatile uint32_t eof : 1;
53-
volatile uint32_t owner : 1;
54-
uint32_t *buf_ptr;
55-
uint32_t *next_link_ptr;
48+
uint32_t blocksize : 12;
49+
uint32_t datalen : 12;
50+
uint32_t unused : 5;
51+
uint32_t sub_sof : 1;
52+
uint32_t eof : 1;
53+
volatile uint32_t owner : 1; // DMA can change this value
54+
uint32_t * buf_ptr;
55+
struct slc_queue_item * next_link_ptr;
5656
// This is my own way of tracking item ID
57-
volatile uint32_t myid;
57+
volatile uint32_t myid;
5858
} slc_queue_item_t;
5959

6060
typedef struct i2s_state {
@@ -210,7 +210,7 @@ static void ICACHE_FLASH_ATTR _alloc_channel(i2s_state_t *ch) {
210210
ch->slc_items[x].datalen = SLC_BUF_LEN * 4;
211211
ch->slc_items[x].blocksize = SLC_BUF_LEN * 4;
212212
ch->slc_items[x].buf_ptr = (uint32_t*)&ch->slc_buf_pntr[x][0];
213-
ch->slc_items[x].next_link_ptr = (uint32_t*)((x<(SLC_BUF_CNT-1))?(&ch->slc_items[x+1]):(&ch->slc_items[0]));
213+
ch->slc_items[x].next_link_ptr = (x<(SLC_BUF_CNT-1))?(&ch->slc_items[x+1]):(&ch->slc_items[0]);
214214
ch->slc_items[x].myid = 0;
215215
}
216216
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
I2S stereo microphone (input) example
3+
Run using the Arduion Serial Plotter to see waveform.
4+
Released to the Public Domain by Earle F. Philhower, III
5+
*/
6+
7+
#include <ESP8266WiFi.h>
8+
#include <i2s.h>
9+
10+
void dump()
11+
{
12+
Serial.printf("I2SC: %08x\n", I2SC);
13+
Serial.printf("I2SFC: %08x\n", I2SFC);
14+
Serial.printf("I2SCC: %08x\n", I2SCC);
15+
Serial.printf("I2SRXEN: %08x\n", I2SRXEN);
16+
Serial.printf("SLCC0: %08x\n", SLCC0);
17+
Serial.printf("SLCRXDC: %08x\n", SLCRXDC);
18+
Serial.printf("SLCTXL: %08x\n", SLCTXL);
19+
Serial.printf("SLCIE: %08x\n", SLCIE);
20+
}
21+
22+
void setup() {
23+
Serial.begin(115200);
24+
WiFi.forceSleepBegin();
25+
delay(500);
26+
27+
i2s_rxtx_begin(true, false); // Enable I2S RX
28+
i2s_set_rate(11025);
29+
dump();
30+
31+
delay(1000);
32+
33+
while (1) {
34+
uint32_t l, r;
35+
i2s_read_sample(&l, &r, true);
36+
int16_t lh = l>>16;
37+
int16_t rh = r>>16;
38+
char withScale[256];
39+
sprintf(withScale, "%d %d", lh, rh);
40+
Serial.println(withScale);
41+
yield();
42+
}
43+
}
44+
45+
void loop() {
46+
}
47+
48+

0 commit comments

Comments
 (0)