@@ -134,7 +134,7 @@ void I2SClass::destroyCallbackTask()
134
134
}
135
135
}
136
136
137
- int I2SClass::_install_driver (){
137
+ int I2SClass::_installDriver (){
138
138
esp_i2s::i2s_mode_t i2s_mode = (esp_i2s::i2s_mode_t )(esp_i2s::I2S_MODE_RX | esp_i2s::I2S_MODE_TX);
139
139
140
140
if (_driveClock){
@@ -144,12 +144,19 @@ int I2SClass::_install_driver(){
144
144
i2s_mode = (esp_i2s::i2s_mode_t )(i2s_mode | esp_i2s::I2S_MODE_SLAVE);
145
145
}
146
146
if (_mode == I2S_ADC_DAC){
147
- if (_bitsPerSample != 16 ){ // ADC/DAC can only work in 16-bit sample mode
148
- log_e (" ERROR I2SClass::begin invalid bps for ADC/DAC" );
147
+ #if SOC_I2S_SUPPORTS_ADC_DAC
148
+ if (_bitsPerSample != 16 ){ // ADC/DAC can only work in 16-bit sample mode
149
+ log_e (" ERROR I2SClass::begin invalid bps for ADC/DAC" );
150
+ return 0 ; // ERR
151
+ }
152
+ i2s_mode = (esp_i2s::i2s_mode_t )(i2s_mode | esp_i2s::I2S_MODE_DAC_BUILT_IN | esp_i2s::I2S_MODE_ADC_BUILT_IN);
153
+ #else
154
+ log_e (" This chip does not support DAC / ADC" );
149
155
return 0 ; // ERR
150
- }
151
- i2s_mode = (esp_i2s::i2s_mode_t )(i2s_mode | esp_i2s::I2S_MODE_DAC_BUILT_IN | esp_i2s::I2S_MODE_ADC_BUILT_IN);
152
- }else { // End of ADC/DAC mode; start of Normal mode
156
+ #endif
157
+ }else if (_mode == I2S_PHILIPS_MODE ||
158
+ _mode == I2S_RIGHT_JUSTIFIED_MODE ||
159
+ _mode == I2S_LEFT_JUSTIFIED_MODE){ // End of ADC/DAC mode; start of Normal mode
153
160
if (_bitsPerSample != 16 && _bitsPerSample != 24 && _bitsPerSample != 32 ){
154
161
if (_bitsPerSample == 8 ){
155
162
log_e (" ESP unfortunately does not support 8 bits per sample" );
@@ -162,7 +169,14 @@ int I2SClass::_install_driver(){
162
169
log_w (" Original Arduino library does not support 24 bits per sample - keep that in mind if you should switch back" );
163
170
}
164
171
165
- } // Normal mode
172
+ }else if (_mode == I2S_PDM){
173
+ #if SOC_I2S_SUPPORTS_PDM
174
+ i2s_mode = (esp_i2s::i2s_mode_t )(i2s_mode | esp_i2s::I2S_MODE_PDM);
175
+ #else
176
+ log_e (" This chip does not support PDM" );
177
+ return 0 ; // ERR
178
+ #endif
179
+ } // Mode
166
180
esp_i2s::i2s_config_t i2s_config = {
167
181
.mode = i2s_mode,
168
182
.sample_rate = _sampleRate,
@@ -174,10 +188,16 @@ int I2SClass::_install_driver(){
174
188
.dma_buf_len = _i2s_dma_buffer_size
175
189
};
176
190
177
- if (ESP_OK != esp_i2s::i2s_driver_install ((esp_i2s::i2s_port_t ) _deviceIndex, &i2s_config, _I2S_EVENT_QUEUE_LENGTH, &_i2sEventQueue)){ // Install and start i2s driver
191
+ if (ESP_OK != esp_i2s::i2s_driver_install ((esp_i2s::i2s_port_t ) _deviceIndex, &i2s_config, _I2S_EVENT_QUEUE_LENGTH, &_i2sEventQueue)){ // Install and start i2s driver
178
192
log_e (" ERROR could not install i2s driver" );
179
193
return 0 ; // ERR
180
194
}
195
+ if (_i2sEventQueue == NULL ){
196
+ log_e (" ERROR i2s driver did not create event queue" );
197
+ // return 0; // ERR
198
+ }else {
199
+ log_d (" DEBUG MSG i2s event queue exists" );
200
+ }
181
201
182
202
if (_mode == I2S_ADC_DAC){
183
203
esp_i2s::adc_unit_t adc_unit = (esp_i2s::adc_unit_t ) 1 ;
@@ -239,6 +259,7 @@ int I2SClass::begin(int mode, long sampleRate, int bitsPerSample, bool driveCloc
239
259
switch (mode) {
240
260
case I2S_PHILIPS_MODE:
241
261
case I2S_ADC_DAC:
262
+ case I2S_PDM:
242
263
break ;
243
264
244
265
case I2S_RIGHT_JUSTIFIED_MODE: // normally this should work, but i don't how to set it up for ESP
@@ -257,7 +278,7 @@ int I2SClass::begin(int mode, long sampleRate, int bitsPerSample, bool driveCloc
257
278
return 0 ; // ERR
258
279
}
259
280
260
- if (!_install_driver ()){
281
+ if (!_installDriver ()){
261
282
return 0 ; // ERR
262
283
}
263
284
@@ -411,7 +432,7 @@ int I2SClass::getDataOutPin(){
411
432
return _outSdPin;
412
433
}
413
434
414
- int I2SClass::_uninstall_driver (){
435
+ int I2SClass::_uninstallDriver (){
415
436
// TODO
416
437
return 1 ; // Ok
417
438
}
@@ -624,6 +645,7 @@ void I2SClass::onTransferComplete()
624
645
625
646
xQueueSet = xQueueCreateSet (sizeof (i2s_event)*_I2S_EVENT_QUEUE_LENGTH + 1 );
626
647
configASSERT (xQueueSet);
648
+ configASSERT (_i2sEventQueue);
627
649
xQueueAddToSet (_i2sEventQueue, xQueueSet);
628
650
xQueueAddToSet (_task_kill_cmd_semaphore_handle, xQueueSet);
629
651
0 commit comments