Skip to content

Commit 9fd0042

Browse files
committed
ESP32-S2 support
1 parent 2270f4c commit 9fd0042

File tree

3 files changed

+25
-9
lines changed

3 files changed

+25
-9
lines changed

Diff for: libraries/I2S/examples/SimpleTone/SimpleTone.ino

+2-2
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ const int halfWavelength = (sampleRate / frequency); // half wavelength of squar
3838
short sample = amplitude; // current sample value
3939
int count = 0;
4040

41-
//i2s_mode_t mode = I2S_PHILIPS_MODE;
42-
i2s_mode_t mode = I2S_ADC_DAC;
41+
i2s_mode_t mode = I2S_PHILIPS_MODE;
42+
//i2s_mode_t mode = I2S_ADC_DAC;
4343

4444

4545
void setup() {

Diff for: libraries/I2S/src/I2S.cpp

+18-6
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ int I2SClass::_installDriver(){
140140
// TODO there will much more work with slave mode
141141
i2s_mode = (esp_i2s::i2s_mode_t)(i2s_mode | esp_i2s::I2S_MODE_SLAVE);
142142
}
143+
#if SOC_I2S_SUPPORTS_ADC_DAC
143144
if(_mode == I2S_ADC_DAC){
144145
#if SOC_I2S_SUPPORTS_ADC_DAC
145146
if(_bitsPerSample != 16){ // ADC/DAC can only work in 16-bit sample mode
@@ -151,7 +152,9 @@ int I2SClass::_installDriver(){
151152
log_e("This chip does not support DAC / ADC");
152153
return 0; // ERR
153154
#endif
154-
}else if(_mode == I2S_PHILIPS_MODE ||
155+
}else
156+
#endif
157+
if(_mode == I2S_PHILIPS_MODE ||
155158
_mode == I2S_RIGHT_JUSTIFIED_MODE ||
156159
_mode == I2S_LEFT_JUSTIFIED_MODE){ // End of ADC/DAC mode; start of Normal mode
157160
if(_bitsPerSample != 16 && _bitsPerSample != 24 && _bitsPerSample != 32){
@@ -179,7 +182,7 @@ int I2SClass::_installDriver(){
179182
.sample_rate = _sampleRate,
180183
.bits_per_sample = (esp_i2s::i2s_bits_per_sample_t)_bitsPerSample,
181184
.channel_format = esp_i2s::I2S_CHANNEL_FMT_RIGHT_LEFT,
182-
.communication_format = (esp_i2s::i2s_comm_format_t)(esp_i2s::I2S_COMM_FORMAT_STAND_I2S | esp_i2s::I2S_COMM_FORMAT_STAND_PCM_SHORT), // 0x01 | 0x04 // default
185+
.communication_format = (esp_i2s::i2s_comm_format_t)(esp_i2s::I2S_COMM_FORMAT_STAND_I2S), // 0x01 // default
183186
.intr_alloc_flags = ESP_INTR_FLAG_LEVEL2,
184187
.dma_buf_count = _I2S_DMA_BUFFER_COUNT,
185188
.dma_buf_len = _i2s_dma_buffer_size
@@ -198,6 +201,7 @@ int I2SClass::_installDriver(){
198201
}
199202
} //try installing with increasing size
200203

204+
#if SOC_I2S_SUPPORTS_ADC_DAC
201205
if(_mode == I2S_ADC_DAC){
202206
esp_i2s::adc_unit_t adc_unit = (esp_i2s::adc_unit_t) 1;
203207
esp_i2s::adc1_channel_t adc_channel = (esp_i2s::adc1_channel_t) 6; //
@@ -212,13 +216,15 @@ int I2SClass::_installDriver(){
212216
esp_i2s::adc1_config_channel_atten(adc_channel, esp_i2s::ADC_ATTEN_DB_11);
213217
esp_i2s::i2s_adc_enable((esp_i2s::i2s_port_t) _deviceIndex);
214218
_initialized = true;
215-
}else{ // End of ADC/DAC mode; start of Normal mode
219+
}else // End of ADC/DAC mode
220+
#endif
221+
if(_mode == I2S_PHILIPS_MODE){ // if Normal mode
216222
_initialized = true;
217223
if(!_applyPinSetting()){
218224
end();
219225
return 0; // ERR
220226
}
221-
}
227+
} // if _mode == ?
222228

223229
return 1; // OK
224230
}
@@ -257,7 +263,9 @@ int I2SClass::begin(int mode, int sampleRate, int bitsPerSample, bool driveClock
257263
// TODO implement left / right justified modes
258264
switch (mode) {
259265
case I2S_PHILIPS_MODE:
266+
#if SOC_I2S_SUPPORTS_ADC_DAC
260267
case I2S_ADC_DAC:
268+
#endif
261269
case I2S_PDM:
262270
break;
263271

@@ -309,10 +317,10 @@ int I2SClass::_applyPinSetting(){
309317
pin_config.data_out_num = _outSdPin>0 ? _outSdPin : _sdPin;
310318
pin_config.data_in_num = I2S_PIN_NO_CHANGE;
311319
}else{
320+
pin_config.data_out_num = I2S_PIN_NO_CHANGE;
321+
pin_config.data_in_num = _sdPin;
312322
}
313323
}
314-
// pinMode(_inSdPin, INPUT_PULLDOWN);
315-
// TODO if there is any default pinMode - set it to old input
316324
if(ESP_OK != esp_i2s::i2s_set_pin((esp_i2s::i2s_port_t) _deviceIndex, &pin_config)){
317325
log_e("i2s_set_pin failed; attempted settings: SCK=%d; FS=%d; DIN=%d; DOUT=%d\n", _sckPin, _fsPin, pin_config.data_in_num, pin_config.data_out_num);
318326
return 0; // ERR
@@ -424,9 +432,11 @@ int I2SClass::getDataOutPin(){
424432
}
425433

426434
void I2SClass::_uninstallDriver(){
435+
#if SOC_I2S_SUPPORTS_ADC_DAC
427436
if(_mode == I2S_ADC_DAC){
428437
esp_i2s::i2s_adc_disable((esp_i2s::i2s_port_t) _deviceIndex);
429438
}
439+
#endif
430440
esp_i2s::i2s_driver_uninstall((esp_i2s::i2s_port_t) _deviceIndex);
431441

432442
if(_state != I2S_STATE_DUPLEX){
@@ -494,11 +504,13 @@ int I2SClass::read(void* buffer, size_t size){
494504
tmp_buffer = xRingbufferReceiveUpTo(_input_ring_buffer, &item_size, pdMS_TO_TICKS(1000), size);
495505
if(tmp_buffer != NULL){
496506
memcpy(buffer, tmp_buffer, item_size);
507+
#if SOC_I2S_SUPPORTS_ADC_DAC
497508
if(_mode == I2S_ADC_DAC){
498509
for(size_t i = 0; i < item_size / 2; ++i){
499510
((uint16_t*)buffer)[i] = ((uint16_t*)buffer)[i] & 0x0FFF;
500511
}
501512
} // ADC/DAC mode
513+
#endif
502514
vRingbufferReturnItem(_input_ring_buffer, tmp_buffer);
503515
return item_size;
504516
}else{

Diff for: libraries/I2S/src/I2S.h

+5-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,11 @@ namespace esp_i2s {
3232
#endif
3333

3434
#ifndef PIN_I2S_FS
35-
#define PIN_I2S_FS 25
35+
#if CONFIG_IDF_TARGET_ESP32S2
36+
#define PIN_I2S_FS 27
37+
#else
38+
#define PIN_I2S_FS 25
39+
#endif
3640
#endif
3741

3842
#ifndef PIN_I2S_SD

0 commit comments

Comments
 (0)