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 support for m5stick C plus 2 #4415

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

added support for m5stick C plus 2 #4415

wants to merge 6 commits into from

Conversation

huuck
Copy link

@huuck huuck commented Dec 22, 2024

As mentioned above, I added a new target, the M5Stick C PLUS2 with a simple FFT visualiser as a usermod that's enabled by default for it. You can drive the LEDs from any of the data pins with an external power source (haven't tested the Stick's one but I don't recommend it).

Summary by CodeRabbit

  • New Features
    • Introduced an audio-reactive visualizer for M5Stick2, delivering dynamic display animations and enhanced backlight control.
  • Documentation
    • Updated setup instructions and configuration guidelines to support the new M5Stick2 integration and ensure a seamless user experience.

@netmindz netmindz added enhancement usermod usermod related labels Dec 22, 2024
@netmindz
Copy link
Member

Hi @huuck

Thanks for your contribution. As the M5 is just a regular esp32 build there is no need to for a change to platformio.ini, please move the examples of how to build your usermod into the readme file of your usermod.

With regards to the usermod itself, it doesn't appear to actually be M5 specific, so it might be better to rename this to be more generic

@huuck
Copy link
Author

huuck commented Dec 22, 2024

Hmm... I'm not sure I get it. While it is a regular ESP32, it comes with 2 peripherals attached (the display and mic). Should I move all of the defines for the pins inside the usermod header?

@netmindz
Copy link
Member

No keep as platformio build flags, but just say in your readme what env to add.

We just don't add every combination of board and usermod to the main platformio.ini file or it would be massive

@huuck
Copy link
Author

huuck commented Dec 22, 2024

Ah, amazing. Thanks for explaining, I'll move everything to the usermod and resubmit!

@huuck
Copy link
Author

huuck commented Dec 22, 2024

@netmindz Fixed, can you re verify, please? ty!

@netmindz
Copy link
Member

Yeah, that fixes the issue with platformio.ini

I wonder though if this kinda overlaps with #4072

tft.setTextFont(1);
tft.setCursor(100, 100);

for(int i = 0; i < 16; i++) {
Copy link
Member

Choose a reason for hiding this comment

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

Try to avoid magic numbers, e.g 16, use NUM_GEQ_CHANNELS

Copy link
Author

Choose a reason for hiding this comment

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

good catch, ty

@huuck
Copy link
Author

huuck commented Dec 22, 2024

Hm, did not know about that PR, should I wait until the merge is live and push again? I've been having some issues with the eTFT driver, maybe this refactor will clear it up.

@softhack007 softhack007 self-requested a review December 22, 2024 20:33
-D TFT_CS=5
-D SPI_FREQUENCY=20000000
-D USER_SETUP_LOADED
-D USERMOD_AUDIOREACTIVE -D UM_AUDIOREACTIVE_USE_NEW_FFT
Copy link
Collaborator

@softhack007 softhack007 Dec 22, 2024

Choose a reason for hiding this comment

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

Hi, this is the "old way" for activating the audioreactive usermod. It's better if you use references to standard flags. Also you may want to to add flags for the onboard mic pins.

  ${esp32.AR_build_flags} ;; default flags required to properly configure ArduinoFFT
  -D I2S_SDPIN=34 -D I2S_WSPIN=0 -D I2S_CKPIN=-1 -D MCLK_PIN=-1  ;; PDM microphone pins
  -D DMTYPE=5 -D SR_SQUELCH=5 -D SR_GAIN=75    ;; SPM1423 specific sound settings
  -D I2S_USE_RIGHT_CHANNEL                        ;; might be needed, if your microphone uses the right channel instead of left
  -D UM_AUDIOREACTIVE_ENABLE ;; enable AR by default

The example is actually from the M5StickC, so your pins might be different.

For your info, the full buildenv is from here: https://github.com/atuline/WLED/blob/ce6b9d80273575419fecf2a752162f08e28361e0/platformio.ini#L545

I also remember that some M5 boards needed a special library and call M5.begin() to power on microphone and other build-in devices. Is this the case for your board, too?

https://github.com/atuline/WLED/blob/ce6b9d80273575419fecf2a752162f08e28361e0/wled00/wled.cpp#L360-L365

Copy link
Author

Choose a reason for hiding this comment

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

No, both the tft and the mic worked without the M5 library. I wanted to avoid it as it would add too much bloat.

Copy link
Collaborator

@softhack007 softhack007 Jan 4, 2025

Choose a reason for hiding this comment

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

Ok, so please use ${esp32.AR_build_flags}, instead of -D USERMOD_AUDIOREACTIVE -D UM_AUDIOREACTIVE_USE_NEW_FFT

Copy link
Author

Choose a reason for hiding this comment

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

Added, my bad.

lib_deps =
${esp32.lib_deps}
TFT_eSPI @ ^2.3.70
https://github.com/kosme/arduinoFFT#419d7b0
Copy link
Collaborator

@softhack007 softhack007 Dec 22, 2024

Choose a reason for hiding this comment

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

Same here - you need to use ${esp32.AR_lib_deps} , instead of referencing a commit tag in ArduinoFFT

   ${esp32.AR_lib_deps}       ;; needed for USERMOD_AUDIOREACTIVE


for(int i = 0; i < 16; i++) {
tft.fillRect(fftResult[i] / 2, i*15 + 3, 135 - (fftResult[i] / 2), 10, TFT_BLACK);
tft.fillRect(0, i*15 + 3, fftResult[i] / 2, 10, TFT_GOLD);
Copy link
Collaborator

@softhack007 softhack007 Dec 22, 2024

Choose a reason for hiding this comment

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

This way of referencing a variable inside the audioreactive usermod may not work in the future, when each usermod will have it's own namespace. The safer way is to use a local pointer to array

  um_data_t *um_data = getAudioData();
  uint8_t *fftChannels = (uint8_t*)um_data->u_data[2];

Then you can simply use fftChannels[i] to access the data. If audioreactive is disabled, you will automatically get "soundsim" like in any other effect.

@softhack007
Copy link
Collaborator

softhack007 commented Dec 22, 2024

I wonder though if this kinda overlaps with #4072

Good point - I think the display content is really not specific to the M5StickC2 board, just TFT dimensions might be different for others. The visualizer code might also be added to the generic TFT usermod.

Copy link

coderabbitai bot commented Feb 13, 2025

Walkthrough

The pull request introduces a new usermod for the M5Stick2 Visualiser. A header file is added, defining the M5Stick2Visualiser class with methods for TFT display initialization, audio visualization, and JSON-based configuration. The README is updated with detailed hardware setup instructions and PlatformIO configuration for the M5Stick C Plus2. Additionally, the new usermod is registered in the system by updating the usermods list.

Changes

File(s) Change Summary
usermods/.../M5Stick2_Visualiser.h Added a new header defining the M5Stick2Visualiser class (inheriting from Usermod) with methods for setup, connectivity, looping, JSON integration, and audio visualization.
usermods/.../README.md Updated documentation with hardware setup, library dependencies, and PlatformIO configuration instructions for the M5Stick C Plus2 implementation.
wled00/.../usermods_list.cpp Registered the new usermod by including the M5Stick2_Visualiser.h header and adding an instantiation in the usermod manager.
✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

🪧 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.
    • Generate unit testing code for this file.
    • 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 generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • 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 generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

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. (Beta)
  • @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.

@huuck
Copy link
Author

huuck commented Feb 13, 2025

Hi! I addressed all of the comments, would it be possible to have another go?

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

♻️ Duplicate comments (2)
usermods/M5Stick2_Visualiser/M5Stick2_Visualiser.h (1)

160-167: 🛠️ Refactor suggestion

Use local pointer for safer audio data access.

Based on past review comments, accessing audio reactive usermod data should be done using a local pointer to handle future namespace changes.

Apply this diff to improve the audio data access:

-        um_data_t *um_data;
-        if (!usermods.getUMData(&um_data, USERMOD_ID_AUDIOREACTIVE)) {
-          // add support for no audio                                                                                                                           
-          um_data = simulateSound(SEGMENT.soundSim);
-        }
-
-        uint8_t *fftChannels = (uint8_t*)um_data->u_data[2];
+        um_data_t *um_data = getAudioData();
+        uint8_t *fftChannels = (uint8_t*)um_data->u_data[2];
usermods/M5Stick2_Visualiser/README.md (1)

55-55: 🛠️ Refactor suggestion

Use AR_lib_deps variable for ArduinoFFT dependency.

Based on past review comments, use the standard AR_lib_deps variable instead of direct GitHub commit reference.

Apply this diff:

-  https://github.com/kosme/arduinoFFT#419d7b0
🧹 Nitpick comments (2)
usermods/M5Stick2_Visualiser/M5Stick2_Visualiser.h (1)

168-171: Replace magic number with TFT_WIDTH constant.

Use the defined TFT_WIDTH constant instead of the magic number 135 for better maintainability.

Apply this diff:

-            tft.fillRect(fftChannels[i] / 2, chan_width * i, 135 - (fftChannels[i] / 2), chan_width - 1, TFT_BLACK);
+            tft.fillRect(fftChannels[i] / 2, chan_width * i, TFT_WIDTH - (fftChannels[i] / 2), chan_width - 1, TFT_BLACK);
usermods/M5Stick2_Visualiser/README.md (1)

21-21: Add language specifiers to code blocks.

Add language specifiers to fenced code blocks for better syntax highlighting.

Apply these changes:

  • Line 21: Change ``` to ```ini
  • Line 62: Change ``` to ```ini

Also applies to: 62-62

🧰 Tools
🪛 markdownlint-cli2 (0.17.2)

21-21: Fenced code blocks should have a language specified
null

(MD040, fenced-code-language)

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between a0c55c6 and 4c2bfab.

⛔ Files ignored due to path filters (2)
  • usermods/M5Stick2_Visualiser/images/display.jpg is excluded by !**/*.jpg
  • usermods/M5Stick2_Visualiser/images/mic.jpg is excluded by !**/*.jpg
📒 Files selected for processing (3)
  • usermods/M5Stick2_Visualiser/M5Stick2_Visualiser.h (1 hunks)
  • usermods/M5Stick2_Visualiser/README.md (1 hunks)
  • wled00/usermods_list.cpp (2 hunks)
🧰 Additional context used
🪛 markdownlint-cli2 (0.17.2)
usermods/M5Stick2_Visualiser/README.md

21-21: Fenced code blocks should have a language specified
null

(MD040, fenced-code-language)


62-62: Fenced code blocks should have a language specified
null

(MD040, fenced-code-language)

🔇 Additional comments (3)
usermods/M5Stick2_Visualiser/M5Stick2_Visualiser.h (2)

83-107: LGTM! Robust pin initialization and error handling.

The setup function properly allocates pins using pinManager and handles failures gracefully. The backlight pin initialization is also handled correctly.


10-32: LGTM! Thorough configuration validation.

The preprocessor directives ensure all required display parameters are defined at compile time, with proper error messages.

wled00/usermods_list.cpp (1)

245-247: LGTM! Proper usermod registration.

The usermod is correctly included and registered following the established pattern in the file.

Also applies to: 490-492

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement usermod usermod related
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants