Add support for INMP441 MEMS microphone (#18823)

* Add INMP441 MEMS mic support

* add I2S audio defines as preview
This commit is contained in:
blakadder 2023-06-08 16:24:44 +02:00 committed by GitHub
parent 2ffd4311c3
commit ae67c6cfa1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 10 deletions

View File

@ -37,6 +37,18 @@
//#define USE_I2S_WEBRADIO // Add support for web radio
//#define USE_I2S_SAY_TIME // Add support for english speaking clock
//#define USE_I2S_RTTTL // Add support for Rtttl playback
//#define USE_LSB // Add support for LSBJ chips, e.g. TM8211/PT8211
// Microphone support
//#define USE_I2S_MIC // Add support for I2S microphone
//#define MIC_CHANNELS 1 // 1 = mono (I2S_CHANNEL_FMT_ONLY_RIGHT), 2 = stereo (I2S_CHANNEL_FMT_RIGHT_LEFT)
//#define MICSRATE 32000 // Set sample rate
//#define USE_INMP441 // Add support for INMP441 MEMS microphone
//#define MIC_PDM // Set microphone as PDM (only on ESP32)
//#define USE_SHINE // Use MP3 encoding (only on ESP32 with PSRAM)
//#define MP3_MIC_STREAM // Add support for streaming microphone via http (only on ESP32 with PSRAM)
//#define MP3_STREAM_PORT 81 // Choose MP3 stream port (default = 81)
//#define I2S_BRIDGE // Add support for UDP PCM audio bridge
//#define I2S_BRIDGE_PORT 6970 // Set bridge port (default = 6970)
#include "AudioFileSourcePROGMEM.h"
#include "AudioFileSourceID3.h"

View File

@ -21,7 +21,6 @@
#ifdef ESP32
#if ( (defined(USE_I2S_AUDIO) && defined(USE_I2S_MIC)) || defined(USE_M5STACK_CORE2) || defined(ESP32S3_BOX) )
uint32_t SpeakerMic(uint8_t spkr) {
esp_err_t err = ESP_OK;
@ -76,17 +75,27 @@ esp_err_t err = ESP_OK;
.bits_per_chan = I2S_BITS_PER_CHAN_16BIT
};
if (audio_i2s.mic_channels == 1) {
i2s_config.channel_format = I2S_CHANNEL_FMT_ONLY_RIGHT;
} else {
i2s_config.channel_format = I2S_CHANNEL_FMT_RIGHT_LEFT;
}
#ifdef USE_I2S_MIC
// mic select to GND
#ifdef MIC_PDM
// Mic L/R to GND
#ifdef USE_INMP441
i2s_config.mode = (i2s_mode_t)(I2S_MODE_MASTER | I2S_MODE_RX );
i2s_config.communication_format = I2S_COMM_FORMAT_I2S;
i2s_config.channel_format = I2S_CHANNEL_FMT_ONLY_LEFT;
#elif MIC_PDM
i2s_config.mode = (i2s_mode_t)(I2S_MODE_MASTER | I2S_MODE_RX | I2S_MODE_PDM);
#else
#else
i2s_config.mode = (i2s_mode_t)(I2S_MODE_MASTER | I2S_MODE_RX | I2S_MODE_TX);
i2s_config.communication_format = I2S_COMM_FORMAT_STAND_I2S;
#endif
#endif
#endif
#ifdef ESP32S3_BOX
i2s_config.mode = (i2s_mode_t)(I2S_MODE_MASTER | I2S_MODE_RX | I2S_MODE_TX);
i2s_config.communication_format = I2S_COMM_FORMAT_STAND_I2S;
@ -96,11 +105,6 @@ esp_err_t err = ESP_OK;
i2s_config.mode = (i2s_mode_t)(I2S_MODE_MASTER | I2S_MODE_RX | I2S_MODE_PDM);
#endif
if (audio_i2s.mic_channels == 1) {
i2s_config.channel_format = I2S_CHANNEL_FMT_ONLY_RIGHT;
} else {
i2s_config.channel_format = I2S_CHANNEL_FMT_RIGHT_LEFT;
}
err += i2s_driver_install(audio_i2s.mic_port, &i2s_config, 0, NULL);