-
Notifications
You must be signed in to change notification settings - Fork 30
Port M5StickC Plus to M5Unified library stack with corrected Plus2 inheritance #237
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
Draft
Copilot
wants to merge
3
commits into
master
Choose a base branch
from
copilot/port-m5stickc-plus-support
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| m5stickc_mic | ||
| ============ | ||
|
|
||
| **Available on M5StickC Plus and M5StickC Plus2** | ||
|
|
||
| .. code-block:: cpp | ||
|
|
||
| m5stickc_mic(name); | ||
|
|
||
| **other names:** ``m5stickc_microphone`` | ||
|
|
||
| Captures audio from the built-in PDM microphone on M5StickC Plus and M5StickC | ||
| Plus2 devices, and publishes raw 16-bit PCM audio buffers over MQTT. | ||
|
|
||
| Parameters | ||
| ---------- | ||
|
|
||
| - ``name``: the name it can be addressed via MQTT in the network. Inside the code | ||
| it can be addressed via IN(name). | ||
|
|
||
| MQTT Interface | ||
| -------------- | ||
|
|
||
| The microphone device creates the following MQTT topics: | ||
|
|
||
| - ``<node>/name/audio`` → Binary payload: raw 16-bit signed PCM samples at | ||
| 16 kHz mono, 1024 samples (2048 bytes) per publish. | ||
|
|
||
| The audio topic publishes binary data whenever a complete buffer of 1024 samples | ||
| has been recorded. Only one buffer is queued at a time; if the previous buffer | ||
| has not yet been published, the new recording is skipped to avoid back-pressure. | ||
|
|
||
| Recording Details | ||
| ----------------- | ||
|
|
||
| .. list-table:: | ||
| :header-rows: 1 | ||
|
|
||
| * - Parameter | ||
| - Value | ||
| * - Sample rate | ||
| - 16 000 Hz | ||
| * - Bit depth | ||
| - 16-bit signed integer (int16_t) | ||
| * - Channels | ||
| - Mono | ||
| * - Buffer size | ||
| - 1024 samples (64 ms audio) | ||
| * - Encoding | ||
| - Raw PCM (little-endian) | ||
|
|
||
| Example | ||
| ------- | ||
|
|
||
| **node name:** ``living_room/stick1`` | ||
|
|
||
| .. code-block:: cpp | ||
|
|
||
| m5stickc_mic(mic); | ||
|
|
||
| Subscribe to the audio stream: | ||
|
|
||
| .. code-block:: bash | ||
|
|
||
| mosquitto_sub -t "living_room/stick1/mic/audio" | \ | ||
| aplay -f S16_LE -r 16000 -c 1 | ||
|
|
||
| Decode in Python using NumPy: | ||
|
|
||
| .. code-block:: python | ||
|
|
||
| import numpy as np | ||
|
|
||
| def on_audio(client, userdata, msg): | ||
| samples = np.frombuffer(msg.payload, dtype=np.int16) | ||
| # samples is a 1-D array of 1024 int16 values at 16 kHz | ||
|
|
||
| Notes | ||
| ----- | ||
|
|
||
| - The microphone shares the I2S peripheral with the built-in speaker. | ||
| The device automatically disables the speaker (``StickCP2.Speaker.end()``) during | ||
| initialization so that the microphone can use I2S. | ||
| - On M5StickC Plus, ``M5Unified`` is used; on M5StickC Plus2, ``M5StickCPlus2`` | ||
| is used. The device source is shared between the two boards via the | ||
| ``m5stickc_plus`` node-type inheritance. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| ../m5stickc | ||
| ../m5stickc_plus2 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| #ifndef _PLATFORM_EXTRAS_H_ | ||
| #define _PLATFORM_EXTRAS_H_ | ||
|
|
||
| #include <M5Unified.h> | ||
| #include "toolbox.h" | ||
|
|
||
| // M5StickC Plus compatibility layer: | ||
| // Map the Plus2-style StickCP2 singleton to the M5Unified M5 object so that | ||
| // device source files shared between Plus and Plus2 can use StickCP2.* uniformly. | ||
| #define StickCP2 M5 | ||
|
|
||
| /** | ||
| * @brief M5StickC Plus specific early initialization | ||
| * | ||
| * CRITICAL: This function MUST be called at the very beginning of setup() | ||
| * to ensure that the M5StickC Plus is properly powered on. | ||
| */ | ||
| inline void iotempower_platform_early_init() { | ||
| // Initialize M5 system first, to make sure power is held | ||
| auto cfg = M5.config(); | ||
| M5.begin(cfg); | ||
| } | ||
|
|
||
| #endif // _PLATFORM_EXTRAS_H_ | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Creating this file in m5stickc_plus and relinking the base from m5tickc_plus2 here will make this file show up in teh platformio-build directory for the m5stickc_plus2. This will break its built. So if we implement it like this m5stickc_plus2 would need to be the base for m5stickc_plus
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in commit
Fix inheritance chain: Plus2 as base for Plus. The chain is now reversed as suggested:m5stickc_plus2/base→../m5stickc(restored to original)m5stickc_plus/base→../m5stickc_plus2(new)Full chain:
m5stickc_plus → m5stickc_plus2 → m5stickc → esp32All device source files (
dev_display,dev_imu,dev_mic,dev_sleep_mgr) now live inm5stickc_plus2/src/where they belong.m5stickc_plus/src/contains only the board-specific overrides:pins.handplatform_extras.h(the M5Unified compatibility layer that mapsStickCP2 → M5). Plus2'splatform_extras.hwill never see Plus's M5Unified header.