-
Notifications
You must be signed in to change notification settings - Fork 4
Enable M5Stack CoreS3 microphone via ES7210 ADC driver #61
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
6
commits into
dev/translate-jp
Choose a base branch
from
copilot/enable-microphone-for-m5stack
base: dev/translate-jp
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.
+130
−5
Draft
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
0572a61
Initial plan
Copilot 11d990d
Add ES7210 microphone support for M5Stack CoreS3
Copilot ab8bb3a
Fix I2S slot configuration for stereo microphone input
Copilot fa47850
Use explicit slot mask for stereo I2S configuration
Copilot d4ab9af
Improve code formatting in audioin.c
Copilot 1a2605f
Add error handling for ES7210 initialization
Copilot 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
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 |
|---|---|---|
| @@ -0,0 +1,102 @@ | ||
| /* | ||
| * Copyright (c) 2024 Moddable Tech, Inc. | ||
| * | ||
| * This file is part of the Moddable SDK Runtime. | ||
| * | ||
| * The Moddable SDK Runtime is free software: you can redistribute it and/or modify | ||
| * it under the terms of the GNU Lesser General Public License as published by | ||
| * the Free Software Foundation, either version 3 of the License, or | ||
| * (at your option) any later version. | ||
| * | ||
| * The Moddable SDK Runtime is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| * GNU Lesser General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU Lesser General Public License | ||
| * along with the Moddable SDK Runtime. If not, see <http://www.gnu.org/licenses/>. | ||
| * | ||
| */ | ||
|
|
||
| /** | ||
| * ES7210 ADC driver for M5Stack CoreS3 microphone | ||
| * Based on M5Unified implementation | ||
| */ | ||
| class ES7210 { | ||
| #io; | ||
|
|
||
| constructor(options) { | ||
| this.#io = new options.sensor.io({ | ||
| hz: 400_000, | ||
| address: 0x40, | ||
| ...options.sensor | ||
| }); | ||
| } | ||
|
|
||
| readByte(address) { | ||
| return this.#io.readUint8(address); | ||
| } | ||
|
|
||
| writeByte(address, value) { | ||
| return this.#io.writeUint8(address, value); | ||
| } | ||
|
|
||
| /** | ||
| * Initialize ES7210 for M5Stack CoreS3 | ||
| * Configuration based on M5Unified _microphone_enabled_cb_cores3 | ||
| */ | ||
| initialize() { | ||
| // Reset | ||
| try { | ||
| this.writeByte(0x00, 0xFF); // RESET_CTL | ||
| } catch (e) { | ||
| throw new Error("ES7210 not responding on I2C"); | ||
| } | ||
|
|
||
| // ES7210 register initialization sequence from M5Unified | ||
| const initSequence = [ | ||
| { reg: 0x00, value: 0x41 }, // RESET_CTL | ||
| { reg: 0x01, value: 0x1f }, // CLK_ON_OFF | ||
| { reg: 0x06, value: 0x00 }, // DIGITAL_PDN | ||
| { reg: 0x07, value: 0x20 }, // ADC_OSR | ||
| { reg: 0x08, value: 0x10 }, // MODE_CFG | ||
| { reg: 0x09, value: 0x30 }, // TCT0_CHPINI | ||
| { reg: 0x0A, value: 0x30 }, // TCT1_CHPINI | ||
| { reg: 0x20, value: 0x0a }, // ADC34_HPF2 | ||
| { reg: 0x21, value: 0x2a }, // ADC34_HPF1 | ||
| { reg: 0x22, value: 0x0a }, // ADC12_HPF2 | ||
| { reg: 0x23, value: 0x2a }, // ADC12_HPF1 | ||
| { reg: 0x02, value: 0xC1 }, | ||
| { reg: 0x04, value: 0x01 }, | ||
| { reg: 0x05, value: 0x00 }, | ||
| { reg: 0x11, value: 0x60 }, | ||
| { reg: 0x40, value: 0x42 }, // ANALOG_SYS | ||
| { reg: 0x41, value: 0x70 }, // MICBIAS12 | ||
| { reg: 0x42, value: 0x70 }, // MICBIAS34 | ||
| { reg: 0x43, value: 0x1B }, // MIC1_GAIN | ||
| { reg: 0x44, value: 0x1B }, // MIC2_GAIN | ||
| { reg: 0x45, value: 0x00 }, // MIC3_GAIN | ||
| { reg: 0x46, value: 0x00 }, // MIC4_GAIN | ||
| { reg: 0x47, value: 0x00 }, // MIC1_LP | ||
| { reg: 0x48, value: 0x00 }, // MIC2_LP | ||
| { reg: 0x49, value: 0x00 }, // MIC3_LP | ||
| { reg: 0x4A, value: 0x00 }, // MIC4_LP | ||
| { reg: 0x4B, value: 0x00 }, // MIC12_PDN | ||
| { reg: 0x4C, value: 0xFF }, // MIC34_PDN | ||
| { reg: 0x01, value: 0x14 }, // CLK_ON_OFF | ||
| ]; | ||
|
|
||
| for (const {reg, value} of initSequence) { | ||
| this.writeByte(reg, value); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Power down ES7210 | ||
| */ | ||
| powerDown() { | ||
| this.writeByte(0x00, 0xFF); // RESET_CTL | ||
| } | ||
| } | ||
|
|
||
| export default ES7210; |
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,8 @@ | ||
| { | ||
| "modules": { | ||
| "embedded:peripheral/Audio/es7210": "./es7210" | ||
| }, | ||
| "preload": [ | ||
| "embedded:peripheral/Audio/es7210" | ||
| ] | ||
| } |
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.
使い方が間違っています。configはランタイムの設定です。マクロを設定するにはdefineセクションを使います。