Skip to content

Add ES8311 audio-reactive support for the Waveshare ESP32-P4-ETH - #128

Closed
TouchMyLight wants to merge 1 commit into
MoonModules:mainfrom
TouchMyLight:es8311
Closed

TouchMyLight wants to merge 1 commit into
MoonModules:mainfrom
TouchMyLight:es8311

Conversation

@TouchMyLight

Copy link
Copy Markdown

New firmware variant (esp32p4rev1-eth-es8311), board definition, and Ethernet/I2C/I2S pins for the Waveshare ESP32-P4-ETH's onboard ES8311 codec, selectable from the web installer. Bench-verified end to end: Ethernet link + DHCP, codec ACK at 0x18, and live mic data (level, onsets, peak Hz) flowing through AudioService.

Core:

  • New CONFIG_MM_P4_ES8311 Kconfig option gates the esp_codec_dev managed-component dependency and the P4's AudioCodecPins, since most other P4 boards share this chip target but have no onboard codec.
  • Two codec bring-up bugs fixed in platform_esp32_es8311.cpp, both shared with the S31's codec path (not P4-ETH-specific): esp_codec_dev's I2C layer right-shifts the address it's given (the bare 7-bit 0x18 silently targeted 0x0C, so every register write NACK'd despite a scan at 0x18 ACKing cleanly), and esp_codec_dev_new requires a non-null data_if that was never set.
  • New "ESP32-P4-ETH" Ethernet preset in NetworkModule.h (IP101, same pins as the P4-NANO, independently confirmed rather than aliased).

Scripts/MoonDeck:

  • New esp32p4rev1-eth-es8311 entry in build_esp32.py's FIRMWARES dict; regenerated mooninstaller/firmwares.json.

Docs/CI:

  • New esp32-p4-eth.md hardware reference (pins, bench findings).
  • Device catalog entry, cross-reference updates (gpio-usage.md, firmware-variants.md, the S31 doc's shared-bug note), mkdocs nav.

New firmware variant (esp32p4rev1-eth-es8311), board definition, and
Ethernet/I2C/I2S pins for the Waveshare ESP32-P4-ETH's onboard ES8311
codec, selectable from the web installer. Bench-verified end to end:
Ethernet link + DHCP, codec ACK at 0x18, and live mic data (level,
onsets, peak Hz) flowing through AudioService.

Core:
- New CONFIG_MM_P4_ES8311 Kconfig option gates the esp_codec_dev
  managed-component dependency and the P4's AudioCodecPins, since most
  other P4 boards share this chip target but have no onboard codec.
- Two codec bring-up bugs fixed in platform_esp32_es8311.cpp, both
  shared with the S31's codec path (not P4-ETH-specific): esp_codec_dev's
  I2C layer right-shifts the address it's given (the bare 7-bit 0x18
  silently targeted 0x0C, so every register write NACK'd despite a scan
  at 0x18 ACKing cleanly), and esp_codec_dev_new requires a non-null
  data_if that was never set.
- New "ESP32-P4-ETH" Ethernet preset in NetworkModule.h (IP101, same
  pins as the P4-NANO, independently confirmed rather than aliased).

Scripts/MoonDeck:
- New esp32p4rev1-eth-es8311 entry in build_esp32.py's FIRMWARES dict;
  regenerated mooninstaller/firmwares.json.

Docs/CI:
- New esp32-p4-eth.md hardware reference (pins, bench findings).
- Device catalog entry, cross-reference updates (gpio-usage.md,
  firmware-variants.md, the S31 doc's shared-bug note), mkdocs nav.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Oct 5, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration
  • Configuration used: Repository: MoonModules/MoonLight/.coderabbit.yaml
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: e70965ef-2abd-4abc-9ffa-a06db1d2e1e9

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@ewowi

ewowi commented Oct 5, 2026

Copy link
Copy Markdown
Collaborator

Thanks for this, and for bench-verifying it end to end.

The ES8311 driver already exists: src/platform/esp32/platform_esp32_es8311.cpp, used by the ESP32-S31. Today it is built only for the S31 (esp_codec_dev is gated to target == esp32s31) and the codec type and pins are compile-time constants in platform_config.h, which is why a new firmware variant looked necessary. We would rather not add a firmware per board, so our next commit makes the codec runtime configuration:

  1. build esp_codec_dev for the P4 as well;
  2. make the codec and its I2C pins and address AudioService controls, with no codec as the default so other P4 boards are unaffected;
  3. a board is then one deviceModels.json entry on the existing esp32p4rev1-eth firmware.

Your two codec fixes are real bugs that hit the S31 too: the address esp_codec_dev wants pre-shifted, and the missing data_if. We will take those in that commit, credited to you.

PR #55 adds the Guition JC-ESP32P4-M3-DEV the same way, and its codec wiring is identical to this board's. The proposed entry for this board, with the codec control names still to be settled (pins from the Waveshare wiki and your bench test):

{
  "name": "Waveshare ESP32-P4-ETH",
  "chip": "ESP32-P4",
  "firmwares": ["esp32p4rev1-eth"],
  "url": "https://www.waveshare.com/wiki/ESP32-P4-ETH",
  "supported": ["LEDs", "Ethernet", "Audio"],
  "modules": [
    { "type": "System", "id": "System", "controls": { "deviceModel": "Waveshare ESP32-P4-ETH" } },
    { "type": "EthernetModule", "id": "Ethernet", "parent_id": "Network", "controls": { "ethBoard": "P4-NANO" } },
    { "type": "AudioService", "id": "Audio", "parent_id": "Services",
      "controls": { "mode": 2, "codec": "ES8311", "codecSda": 7, "codecScl": 8, "codecAddr": 24,
                    "mclkPin": 13, "sckPin": 12, "wsPin": 10, "sdPin": 11 } },
    { "type": "ParallelLedDriver", "id": "ParallelLed", "parent_id": "Drivers",
      "controls": { "peripheral": "Parlio", "pins": "20,21,22,23,24,25,26,27" } }
  ]
}

Once that lands, would you rebase this onto it, keeping the board documentation and the catalog entry and dropping the firmware variant?

@TouchMyLight

Copy link
Copy Markdown
Author

I agree that a new firmware variant is not necessary. I'll rebase once the coded becomes a runtime config.

@ewowi

ewowi commented Oct 6, 2026

Copy link
Copy Markdown
Collaborator

An update: the ES8311 support this PR asked for is built, in a slightly different shape, and goes into main as the latest release in the coming days.

What is built

  • The codec is runtime configuration rather than a firmware variant. AudioService has a codec select (none / ES8311) and a codecAddr (0x18), and the codec ships in every ESP32-P4 and S31 firmware, so esp32p4rev1-eth drives the P4-ETH as it is.
  • The I2C pins live on one shared bus module (System, I2cBus, sda 7 / scl 8), which a scan also uses. It now names what it finds, as 0x18 Audio (ES8311).
  • Both of your codec fixes are in: the address handed to esp_codec_dev pre-shifted, and a data interface for esp_codec_dev_new (a no-op one, since linking the I2S data module boot-looped the S31).
  • The Waveshare ESP32-P4-ETH has a device catalog entry with these settings: Parlio LEDs, Ethernet, the I2C bus and the mic (MCLK 13, BCLK 12, LRCK 10, data 11).
  • Ethernet uses the existing P4-NANO preset: the P4-ETH schematic shows the same IP101 wiring (MDC 31, MDIO 52, reset 51, clock 50).

Verified on a P4-ETH here: Ethernet with DHCP, the codec found at 0x18, and the mic level following sound.

Thanks for the bring-up work and for finding the two codec bugs, which the S31 shared. Once the release is out, a test from your side on the latest build would be welcome.

@ewowi

ewowi commented Oct 6, 2026

Copy link
Copy Markdown
Collaborator

Thank you @TouchMyLight. This is merged in #129 in a different shape: the ES8311 codec became runtime configuration (AudioService codec and codecAddr on a shared I2C bus) rather than a firmware variant, so the Waveshare ESP32-P4-ETH runs its microphone on the standard P4 firmware through its deviceModels.json entry. Your two codec fixes are in, credited to you: the address pre-shifted for esp_codec_dev, and the data interface for esp_codec_dev_new. Verified on the bench with an ESP32-P4-ETH: Ethernet with DHCP, the codec at 0x18 and the mic level following sound. Closing in favor of #129; please reopen or open an issue if anything on your board behaves differently.

@ewowi ewowi closed this Oct 6, 2026
ewowi pushed a commit that referenced this pull request Oct 7, 2026
…2-P4-ETH

Writes the hardware reference page for the Waveshare ESP32-P4-ETH's onboard ES8311 codec and Ethernet wiring, which PR #128's firmware-variant approach never landed on main after PR #129 made the codec runtime configuration. Also renames the shared P4 Ethernet preset to "P4-NANO/ETH" so its UI label doesn't imply it's NANO-only.

**Core**
- `EthernetModule.h`: `kEthPresets`' shared P4 RMII row renamed `"P4-NANO"` → `"P4-NANO/ETH"`, naming both boards that use it; doc comment updated to match.

**Scripts/MoonDeck**
- `check_devices.py`: its own restatement of the preset label (cross-checked against `platform_config.h`'s chip default) updated to match the rename — this is the check that caught the miss on the first pass.

**Docs/CI**
- New `docs/reference/hardware/esp32-p4-eth.md`: audio (ES8311) and Ethernet pin tables, free-GPIO table, bench-verification notes, written against the current runtime-codec architecture (`AudioService`/`I2cBusModule`), not copied from the closed PR #128.
- `firmware-variants.md`, `gpio-usage.md`: P4-ETH named alongside the P4-NANO as sharing `esp32p4rev1-eth`.
- `mkdocs.yml`: nav entry for the new page.
- `mooninstaller/deviceModels.json`: the renamed preset label carried into all 5 P4-family catalog entries that reference it.

Bench-verified on the Waveshare ESP32-P4-ETH (plain `esp32p4rev1-eth` firmware, no new variant): I2C bus scan ACKs the codec at 0x18, `AudioService` reports live mic data, Ethernet link + DHCP hold, and the renamed preset round-trips cleanly on an already-provisioned board (auto-resolves to the new label, same pins, no reseed to Custom).

Reviews
- Pre-existing, unrelated to this diff (confirmed by reproducing on a clean `main`): `check_docgen` carries 1 pre-existing error (`Hub75Slots.h`) and `check_code` a 4-finding drift, both from commits already on `main` before this branch started — named here rather than fixed, since neither file is touched by this change.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
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