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

Added audioio to espressif #9995

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

MarshallMiller
Copy link

@MarshallMiller MarshallMiller commented Jan 25, 2025

Added audioio support for the one esp32 board that I have (adafruit_feather_esp32_v2) but I believe it will work with other espressif boards. This is my first contribution to CircuitPython so I'm sure there will be lots of little things that I did wrong. Resolves #3898.

Copy link
Member

@jepler jepler left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! This looks amazing for a first submission. I took a look at the code, but didn't test anything. I have a few small comments.

ports/espressif/common-hal/audioio/AudioOut.c Outdated Show resolved Hide resolved
@@ -10,3 +10,5 @@ CIRCUITPY_ESP_FLASH_SIZE = 8MB
CIRCUITPY_ESP_PSRAM_SIZE = 2MB
CIRCUITPY_ESP_PSRAM_MODE = qio
CIRCUITPY_ESP_PSRAM_FREQ = 40m

CIRCUITPY_AUDIOIO = 1
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we'll probably want to default enable this on any supported mcu, but that's fine to do as a subsequent PR.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i couldn't figure out where to make that change. could you point me in the right direction?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in ports/espressif/mpconfigport.h there's a section for each different IDF_TARGET. So the needed change might be

diff --git a/ports/espressif/mpconfigport.mk b/ports/espressif/mpconfigport.mk
index 06f8c87c57..310558b867 100644
--- a/ports/espressif/mpconfigport.mk
+++ b/ports/espressif/mpconfigport.mk
@@ -85,6 +85,7 @@ CIRCUITPY__EVE ?= 1
 ifeq ($(IDF_TARGET),esp32)
 # Modules
 CIRCUITPY_ALARM_TOUCH = 1
+CIRCUITPY_AUDIOIO = 1
 CIRCUITPY_RGBMATRIX = 0
 
 # SDMMC not supported yet
@@ -244,6 +245,7 @@ CIRCUITPY_ESPCAMERA = 0
 else ifeq ($(IDF_TARGET),esp32s2)
 # Modules
 CIRCUITPY_ALARM_TOUCH = 1
+CIRCUITPY_AUDIOIO = 1
 # No BLE in hw
 CIRCUITPY_BLEIO = 0
 

If you want to leave this PR as enabling the module on just a single board, that's fine too.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm OK with enabling it for all of the esp32 and esp32s2 boards. Hopefully it will get more use/testing/fixes that way. Oh that reminds me, these patches are on top of the 9.2.1 tag because I was unable to get a build from main (without my patches) to work on my board.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you are testing with the tip of main, make sure all the submodules are up to date including esp-idf. Is this a custom board or something we could try building. Does a tip-of-main build work for your board without your commits (e.g., just a clean clone of adafruit/circuitpython checked out to main). If that works try your fork brought up to main as well.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A clean clone did not work when I tried it a few weeks ago, but I'll give it another go. The board I have is the stock feather esp32 v2.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As a marker: I just did a clean build for ESP32 V2 with the current tip of main, erased the flash, and loaded it, and it worked.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It also works for me now. Would you rather me rebase this branch on top of main or do a merge?

self->channel_mode = DAC_CHANNEL_MODE_ALTER;
} else if ((left_channel_pin == &pin_CHANNEL_0 ||
left_channel_pin == &pin_CHANNEL_1) &&
right_channel_pin == left_channel_pin) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can this case actually happen? I'm surprised, but maybe it can.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are you asking if someone can someone pass the same pin to the left and right channel arguments? if so, the answer is yes.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you are asking if it makes sense to support the dual mono mode by supplying the same pin (or at all) i'm not entirely sure. i couldn't think of a better way to support it and i'm not even sure how useful this mode would be. i know it isn't exactly intuitive.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tannewt is passing the same pin as left & right channel supposed to be allowed? or is this something we just forgot to check in shared-bindings?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it doesn't appear to be checked because i tested it and it worked 🤷

Copy link
Member

@jepler jepler left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for addressing the changes I requested.

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.

Implement DAC-based audio (audioio) on Espressif
3 participants