Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I2S changes for Core 3 #21291

Merged
merged 2 commits into from
Apr 27, 2024
Merged

I2S changes for Core 3 #21291

merged 2 commits into from
Apr 27, 2024

Conversation

Staars
Copy link
Contributor

@Staars Staars commented Apr 27, 2024

Description:

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

  • fix: use input and not output instance for microphone recording
  • expose more low level properties of the I2S framework in the driver setting, which is needed for the INMP441 and should be future proof for all kinds of I2S microphones in standard mode
  • expose DMA buffer settings - needed for higher sampling rates (i.e. 48000 Hz can work)
  • change some defaults so that MP3 recording/streaming will work without setting a compatible sampling rate first
  • turn off automatic start of streaming server if enabled in firmware, because that does not resonate well with the new flexible driver concept. Would need something like i2sstream 1 in autoexec.bat or with another autostart method.
  • attempt to give Free-RTOS more info about the timing requirements of the microphone task
  • more internal refactoring

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:

  • The pull request is done against the latest development branch
  • Only relevant files were touched
  • Only one feature/fix was added per PR and the code change compiles without warnings
  • The code change is tested and works with Tasmota core ESP8266 V.2.7.6
  • The code change is tested and works with Tasmota core ESP32 V.3.0.0
  • I accept the CLA.

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

@Jason2866 Jason2866 merged commit b3c075c into arendst:development Apr 27, 2024
59 checks passed
@Staars Staars deleted the i2s branch May 1, 2024 19:53
hawa-lc4 pushed a commit to hawa-lc4/Tasmota-dev that referenced this pull request May 7, 2024
* i2s fixes and refactoring

* DMA setting added, more refactoring
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants