Skip to content

Conversation

@troyhacks
Copy link
Collaborator

@troyhacks troyhacks commented Aug 9, 2025

ES8311 Fix - works 100% of the time now. Thanks ESPHome for the hint!

Summary by CodeRabbit

  • Documentation

    • Improved comments to clarify the initialization sequence and register settings for the ES8311 I2S microphone driver, including guidance on powering off the board before making changes.
  • Refactor

    • Updated and reordered hardware register values for the ES8311 microphone, enhancing power management, ADC settings, and clock management for more reliable operation.

ES8311 Fix - works 100% of the time now. Thanks ESPHome for the hint!
@coderabbitai
Copy link

coderabbitai bot commented Aug 9, 2025

Walkthrough

The initialization sequence for the ES8311Source I2S microphone driver was updated. Register writes in the _es8311InitAdc() method were reordered, with several register values and associated comments revised for clarity. A new comment advises powering off the board before changes. No changes were made to control flow or public interfaces.

Changes

Cohort / File(s) Change Summary
ES8311 ADC Initialization Sequence
usermods/audioreactive/audio_source.h
Reordered and updated I2C register writes in the ES8311 ADC initialization, revised comments, changed register values, and added a note on powering off the board before making changes. No interface or control flow changes.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~2 minutes

Poem

In circuits where the audio flows,
A rabbit tweaks what hardware knows.
Registers set, with comments anew,
Power off first—wise advice for you!
With every bit and byte aligned,
The sound is crisp, the code refined.
🐇🎶

Note

🔌 MCP (Model Context Protocol) integration is now available in Early Access!

Pro users can now connect to remote MCP servers under the Integrations page to get reviews and chat conversations that understand additional development context.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@troyhacks troyhacks changed the title Update audio_source.h ES8311 Fix Aug 9, 2025
@troyhacks troyhacks changed the title ES8311 Fix ES8311 Init Fix Aug 9, 2025
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (3)
usermods/audioreactive/audio_source.h (3)

682-682: Good reliability note; consider surfacing at runtime when init fails.

The “fully power off the board” comment is helpful. Consider adding a one-time WARN log or retry hint when ES8311 init fails so users see this tip without reading code.


688-688: Clarify CLOCK MANAGER bitfields and replace magic value.

0x01 = 0b00111010 is critical. Please document exact bits (MCLK enable, dividers, sources) per ES8311 datasheet, or use named bit masks to improve maintainability.


697-714: Validate final-reset behavior, align word-length with I2S config, and add small delays.

  • Final reset (Line 714): If 0x00=0x80 performs a full reset, it may wipe prior config. If it’s a “start/apply” reset (per ESPHome hint), it’s fine. Please read back one or two registers (e.g., 0x0A, 0x17) after this write to confirm settings persist.
  • Word length (Line 705): You force 32-bit on ES8311, but the driver sometimes runs 16-bit when HUB75 is enabled. Mismatch can break the bus. Ensure 0x0A is set to match I2S_SAMPLE_RESOLUTION or enforce 32-bit on the I2S side for this codec.
  • Duplicate 0x01 write (Lines 688 and 703): If not required by sequencing, drop one to reduce churn.
  • Timing: Add short delays around reset/power transitions to increase bring-up reliability.

Minimal diff to add a safety delay before the final reset:

 _es8311I2cWrite(0x19, 0b11110000); // ADC ALC max (-6dB) and min (-30dB)
+delay(2); // Give time for internal state machines before issuing reset
 _es8311I2cWrite(0x00, 0b10000000); // *** RESET (This is very required! Thanks to ESPHome for the hint!)

Also, please verify:

  • 0x1B “soft-mute enabled” doesn’t mute the path unintentionally in steady state.
  • 0x17 value really corresponds to the intended 0 dB gain to avoid clipping.
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between daa8103 and 598e9aa.

📒 Files selected for processing (1)
  • usermods/audioreactive/audio_source.h (2 hunks)
🧰 Additional context used
🧠 Learnings (2)
📓 Common learnings
Learnt from: DedeHai
PR: MoonModules/WLED-MM#253
File: usermods/audioreactive/audio_source.h:1256-1261
Timestamp: 2025-07-12T04:20:14.546Z
Learning: In WLED AudioReactive usermod, DC offset removal optimization in DMAadcSource::getSamples() should be implemented after PR #248 merges, which will change the sample buffer from float to int16. This eliminates the need for temporary integer buffers and allows direct integer arithmetic on the native buffer type for better memory efficiency on resource-constrained MCUs like C3 and S2.
📚 Learning: 2025-07-12T04:20:14.546Z
Learnt from: DedeHai
PR: MoonModules/WLED-MM#253
File: usermods/audioreactive/audio_source.h:1256-1261
Timestamp: 2025-07-12T04:20:14.546Z
Learning: In WLED AudioReactive usermod, DC offset removal optimization in DMAadcSource::getSamples() should be implemented after PR #248 merges, which will change the sample buffer from float to int16. This eliminates the need for temporary integer buffers and allows direct integer arithmetic on the native buffer type for better memory efficiency on resource-constrained MCUs like C3 and S2.

Applied to files:

  • usermods/audioreactive/audio_source.h
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (20)
  • GitHub Check: Builds (esp8266pro_16MB_M)
  • GitHub Check: Builds (esp8266_4MB_M)
  • GitHub Check: Builds (esp8266_4MB_S)
  • GitHub Check: Builds (esp01_1MB_S)
  • GitHub Check: Builds (esp32S3_4MB_PSRAM_S)
  • GitHub Check: Builds (esp32S3_16MB_PSRAM_M_HUB75)
  • GitHub Check: Builds (adafruit_matrixportal_esp32s3_tinyUF2)
  • GitHub Check: Builds (esp32s2_PSRAM_M)
  • GitHub Check: Builds (esp32S3_WROOM-2_M)
  • GitHub Check: Builds (esp32c3dev_2MB_M)
  • GitHub Check: Builds (esp32S3_4MB_PSRAM_M)
  • GitHub Check: Builds (esp32c3mini_dio_4MB_M)
  • GitHub Check: Builds (esp8266_2MB_S)
  • GitHub Check: Builds (esp32S3_8MB_M)
  • GitHub Check: Builds (esp32S3_4MB_S)
  • GitHub Check: Builds (esp32S3_8MB_S)
  • GitHub Check: Builds (esp32_16MB_V4_M)
  • GitHub Check: Builds (esp32_4MB_V4_S)
  • GitHub Check: Builds (esp32_16MB_V4_S)
  • GitHub Check: Builds (esp32_4MB_V4_HUB75_forum)

@troyhacks troyhacks merged commit 898861b into MoonModules:mdev Aug 9, 2025
29 checks passed
@softhack007 softhack007 added this to the 14.7.1 milestone Dec 23, 2025
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