Skip to content

Add I2S mclk support to audiobusio.I2SOut for the Espressif port #8570

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

Closed
lookfwd opened this issue Nov 9, 2023 · 5 comments · Fixed by #8571
Closed

Add I2S mclk support to audiobusio.I2SOut for the Espressif port #8570

lookfwd opened this issue Nov 9, 2023 · 5 comments · Fixed by #8571
Labels
audio enhancement espressif applies to multiple Espressif chips
Milestone

Comments

@lookfwd
Copy link

lookfwd commented Nov 9, 2023

CircuitPython version

CircuitPython 9.0.0-alpha.2 on Adafruit Feather ESP32-S3 4MB Flash 2MB PSRAM (and I guess everything on the espressif port

Code/REPL

import audiobusio
with audiobusio.I2SOut(bit_clock=board.A0,
                       word_select=board.A1,
                       data=board.A2,
                       main_clock=board.A3
                      ) as audio:
    pass

Behavior

I'm get NotImplementedError: main_clock

Description

I attempt to use ESP32-S3 with SGTL5000. I get NotImplementedError: main_clock when I try to use the I2SOut. An implementation similar to mimxrt10xx's must get ported for espressif here and the common_hal_audiobusio_i2sout_deinit function in the same file. The relevant ESP32-S3 library is here.

Additional information

No response

@lookfwd lookfwd added the bug label Nov 9, 2023
@dhalbert
Copy link
Collaborator

dhalbert commented Nov 9, 2023

Note that for the SGTL5000 the MCLK input has a PLL that allows you to use any convenient clock signal that is 8-27 MHz. So for now maybe you could hook up the MCLK input to a PWM output, assuming it will run that high for Espressif.

CLOCKING
Clocking for the SGTL5000 is provided by a system
master clock input (SYS_MCLK). SYS_MCLK should be
synchronous to the sampling rate (Fs) of the I2S port.
Alternatively any clock between 8.0 and 27 MHz can be
provided on SYS_MCLK and the SGTL5000 can use an
internal PLL to derive all internal and I2S clocks. This allows
the system to use an available clock such as 12 MHz
(common USB clock) for SYS_MCLK to reduce overall
system costs.

@dhalbert dhalbert changed the title NotImplementedError: main_clock for espressif port Espressif: I2S mclk support Nov 9, 2023
@dhalbert dhalbert added enhancement audio espressif applies to multiple Espressif chips and removed bug labels Nov 9, 2023
@dhalbert dhalbert added this to the Long term milestone Nov 9, 2023
@lookfwd
Copy link
Author

lookfwd commented Nov 9, 2023

Great idea! I used a signal generator to give it 12MHz and SGTL5000 "woke up" and started to respond in I2C, but I2S wasn't working. Turning the PLL on and doing lots of configuration is a nice interim solution.

lookfwd added a commit to lookfwd/circuitpython that referenced this issue Nov 9, 2023
@dhalbert
Copy link
Collaborator

dhalbert commented Nov 9, 2023

Looks like PWM will do 12MHz:

import pwmio
p = pwmio.PWMOut(board.IO6, duty_cycle=32768, frequency=12000000)

@lookfwd
Copy link
Author

lookfwd commented Nov 9, 2023

That's great! If only it was in sync with SCLK and LRCLK, it could save us from the extra configuration and the power consumption of the PLL.

@lookfwd lookfwd changed the title Espressif: I2S mclk support Espressif: I2S mclk support [don't merge - pending test] Nov 9, 2023
@lookfwd
Copy link
Author

lookfwd commented Nov 9, 2023

I used the Teensy Audio Adaptor Board with SGTL5000 and it beeps nicely! It even plays MIDI 🎉

with audiobusio.I2SOut(bit_clock=board.A0, word_select=board.A1, data=board.A2, main_clock=board.A3) as audio:
    init_sgtl5000()
    melody = synthio.MidiTrack(b"\0\x90H\0*\x80H\0\6\x90J\0*\x80J\0\6\x90L\0*\x80L\0\6\x90J\0" +
                       b"*\x80J\0\6\x90H\0*\x80H\0\6\x90J\0*\x80J\0\6\x90L\0T\x80L\0" +
                       b"\x0c\x90H\0T\x80H\0\x0c\x90H\0T\x80H\0", tempo=640)
    audio.play(melody)

53ABC13D-DB99-4F2C-A602-CB213F1D7698

@lookfwd lookfwd changed the title Espressif: I2S mclk support [don't merge - pending test] Espressif: I2S mclk support Nov 9, 2023
@lookfwd lookfwd changed the title Espressif: I2S mclk support Adds I2S mclk support to audiobusio.I2SOut for the Espressif port Nov 9, 2023
@lookfwd lookfwd changed the title Adds I2S mclk support to audiobusio.I2SOut for the Espressif port Add I2S mclk support to audiobusio.I2SOut for the Espressif port Nov 9, 2023
dhalbert added a commit that referenced this issue Nov 9, 2023
Adds I2S mclk support to audiobusio.I2SOut for the Espressif port #8570
lookfwd added a commit to lookfwd/circuitpython that referenced this issue Nov 11, 2023
lookfwd added a commit to lookfwd/circuitpython that referenced this issue Nov 11, 2023
lookfwd added a commit to lookfwd/circuitpython that referenced this issue Nov 11, 2023
dhalbert added a commit that referenced this issue Nov 11, 2023
Consistency improvement on I2S mclk support for Espressif port #8570
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
audio enhancement espressif applies to multiple Espressif chips
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants