arendst / Tasmota

Alternative firmware for ESP8266 and ESP32 based devices with easy configuration using webUI, OTA updates, automation using timers or rules, expandability and entirely local control over MQTT, HTTP, Serial or KNX. Full documentation at
https://tasmota.github.io/docs
GNU General Public License v3.0
22.04k stars 4.78k forks source link

I2S changes for Core 3 #21291

Closed Staars closed 5 months ago

Staars commented 5 months ago

Description:

This should fix the crashes for configurations with an input/microphone only (no output device) and can handle the widespread INMP441.

The new driver concept is all about runtime configuration with a new command i2sconfig that prints a (pretty big) JSON like that:

19:09:36.370 MQT: stat/tasmota_4359CC/RESULT = 
{"I2SConfig":{"Sys":{"Version":2,"Duplex":0,"Tx":0,"Rx":1,"Exclusive":0,"MclkInv0":0,"MclkInv1":0,"BclkInv0":0,"BclkInv1":0,"WsInv0":0,
"WsInv1":0,"Mp3Preallocate":1},
"Tx":{"SampleRate":16000,"Gain":10,"Mode":0,"SlotMask":3,"SlotConfig":0,"Channels":2,"APLL":1},"
Rx":{"SampleRate":48000,"Gain":30,"Mode":1,"SlotMask":1,"SlotWidth":32,"Channels":1,"DCFilterAlpha":32511,
"LowpassAlpha":17719,"APLL":1,"WsWidth":32,"WsPol":0,"BitShift":1,"LeftAlign":1,"BigEndian":0,"LsbOrder":0,
"DMAFrame":768,"DMADesc":5}}}

This looks a bit wild at first glance, but will be explained soon in the docs. For instance changing from default (which is PDM mode for the microphone) to the INMP441 in left channel configuration is only: i2sconfig {"Rx":{"Mode":0}}

Using MP3 encoding would need PSRAM allocation: i2sconfig {"Sys":{"Mp3Preallocate":1}}

Changing the sample rate: i2sconfig {"Rx":{"SampleRate":48000}}

The latter would need a larger DMA buffer: i2sconfig {"Rx":{"DMAFrame":768}}

More on this later ...

There are still a few glitches and probably some bugs, that will be addressed in separate PR's. The vast majority of changes in comparison to the old driver is about configuration and setup. All time critical parts did not really change that much.

Checklist:

NOTE: The code change must pass CI tests. Your PR cannot be merged unless tests pass