Audio System + Drivers (#562)

This commit is contained in:
Shadowtrance
2026-07-14 16:34:29 +10:00
committed by GitHub
parent fa4a6e255c
commit 955416dac8
137 changed files with 8847 additions and 387 deletions
@@ -19,3 +19,5 @@ display.shape=rectangle
display.dpi=165
lvgl.colorDepth=16
sdkconfig.CONFIG_CODEC_DUMMY_SUPPORT=y
@@ -1,3 +1,5 @@
dependencies:
- Platforms/platform-esp32
- Drivers/dummy-i2s-amp-module
- Drivers/audio-stream-module
dts: guition,jc3248w535c.dts
@@ -10,6 +10,7 @@
#include <tactility/bindings/esp32_uart.h>
#include <tactility/bindings/esp32_sdspi.h>
#include <tactility/bindings/display_placeholder.h>
#include <bindings/dummy_i2s_amp.h>
/ {
compatible = "root";
@@ -54,6 +55,11 @@
pin-data-out = <&gpio0 41 GPIO_FLAG_NONE>;
};
speaker0 {
compatible = "nsiway,ns4168";
i2s = <&i2s0>;
};
spi0 {
compatible = "espressif,esp32-spi";
host = <SPI2_HOST>;
@@ -19,3 +19,5 @@ display.dpi=187
lvgl.colorDepth=16
lvgl.fontSize=18
sdkconfig.CONFIG_CODEC_DUMMY_SUPPORT=y
@@ -1,3 +1,5 @@
dependencies:
- Platforms/platform-esp32
- Drivers/dummy-i2s-amp-module
- Drivers/audio-stream-module
dts: guition,jc8048w550c.dts
@@ -9,6 +9,7 @@
#include <tactility/bindings/esp32_spi.h>
#include <tactility/bindings/esp32_uart.h>
#include <tactility/bindings/esp32_sdspi.h>
#include <bindings/dummy_i2s_amp.h>
/ {
compatible = "root";
@@ -54,6 +55,11 @@
pin-data-out = <&gpio0 17 GPIO_FLAG_NONE>;
};
speaker0 {
compatible = "nsiway,ns4168";
i2s = <&i2s0>;
};
spi0 {
compatible = "espressif,esp32-spi";
host = <SPI2_HOST>;
@@ -21,3 +21,5 @@ display.dpi=143
cdn.infoMessage=To put the device into bootloader mode: <br/>1. Press the trackball and then the reset button at the same time,<br/>2. Let go of the reset button, then the trackball.<br/><br/>When this website reports that flashing is finished, you likely have to press the reset button.
lvgl.colorDepth=16
sdkconfig.CONFIG_CODEC_DUMMY_SUPPORT=y
@@ -3,4 +3,7 @@ dependencies:
- Drivers/st7789-module
- Drivers/gt911-module
- Drivers/lilygo-module
- Drivers/es7210-module
- Drivers/dummy-i2s-amp-module
- Drivers/audio-stream-module
dts: lilygo,tdeck-plus.dts
@@ -16,6 +16,8 @@
#include <bindings/gt911.h>
#include <bindings/st7789.h>
#include <bindings/es7210.h>
#include <bindings/dummy_i2s_amp.h>
#include <lilygo/bindings/tdeck_keyboard.h>
#include <lilygo/bindings/tdeck_keyboard_backlight.h>
@@ -64,6 +66,34 @@
pin-click = <&gpio0 0 GPIO_FLAG_NONE>;
};
// i2s0 and i2s1 are declared before i2c0 so i2s1 has started before the es7210 codec (below) references it.
// Speaker I2S (MAX98357A amplifier)
i2s0 {
compatible = "espressif,esp32-i2s";
port = <I2S_NUM_0>;
pin-bclk = <&gpio0 7 GPIO_FLAG_NONE>;
pin-ws = <&gpio0 5 GPIO_FLAG_NONE>;
pin-data-out = <&gpio0 6 GPIO_FLAG_NONE>;
};
// Microphone I2S (ES7210), separate port from the speaker
i2s1 {
compatible = "espressif,esp32-i2s";
port = <I2S_NUM_1>;
pin-bclk = <&gpio0 47 GPIO_FLAG_NONE>;
pin-ws = <&gpio0 21 GPIO_FLAG_NONE>;
pin-data-in = <&gpio0 14 GPIO_FLAG_NONE>;
pin-mclk = <&gpio0 48 GPIO_FLAG_NONE>;
};
// MAX98357A class-D speaker amplifier. No I2C. Per schematic, SD_MODE/GAIN_SLOT is
// tied via fixed resistors (R21/R22), not driven by an MCU GPIO -- the amp is always
// enabled when powered, so no enable-gpio is wired here.
speaker0 {
compatible = "maxim,max98357a";
i2s = <&i2s0>;
};
i2c_internal: i2c0 {
compatible = "espressif,esp32-i2c";
port = <I2C_NUM_0>;
@@ -90,14 +120,18 @@
compatible = "lilygo,tdeck-keyboard-backlight";
reg = <0x55>;
};
};
i2s0 {
compatible = "espressif,esp32-i2s";
port = <I2S_NUM_0>;
pin-bclk = <&gpio0 7 GPIO_FLAG_NONE>;
pin-ws = <&gpio0 5 GPIO_FLAG_NONE>;
pin-data-out = <&gpio0 6 GPIO_FLAG_NONE>;
// ES7210 microphone ADC. Per schematic all 4 MSM381A3729H9CP mic capsules are
// populated (MIC1-4), and AD0/AD1 are unconnected (default low -> address 0x40).
// Stock LilyGO firmware drives MIC1/MIC2 at 0dB and MIC3/MIC4 at 37.5dB gain --
// the es7210 driver here applies a single gain to all active mics, so per-pair
// gain differentiation is not yet replicated.
es7210 {
compatible = "everest,es7210";
reg = <0x40>;
i2s = <&i2s1>;
mic-mask = <15>;
};
};
display_backlight {
@@ -21,3 +21,5 @@ display.dpi=139
lvgl.colorDepth=16
lvgl.uiDensity=compact
sdkconfig.CONFIG_CODEC_DUMMY_SUPPORT=y
@@ -2,4 +2,7 @@ dependencies:
- Platforms/platform-esp32
- Drivers/st7789-module
- Drivers/m5stack-module
- Drivers/dummy-i2s-amp-module
- Drivers/pdm-mic-module
- Drivers/audio-stream-module
dts: m5stack,cardputer.dts
@@ -16,6 +16,8 @@
#include <bindings/st7789.h>
#include <bindings/cardputer_keyboard.h>
#include <bindings/dummy_i2s_amp.h>
#include <bindings/pdm_mic.h>
// Reference: https://docs.m5stack.com/en/core/Cardputer
/ {
@@ -123,8 +125,17 @@
<&gpio0 7 GPIO_FLAG_NONE>;
};
// Speaker and microphone
// TODO: Microphone I2C init code from https://github.com/m5stack/M5Unified/blob/a6256725481f1bc366655fa48cf03b6095e30ad1/src/M5Unified.cpp#L936
// Speaker (std TX) and PDM mic (RX) share this single I2S controller. PDM RX is
// hardware-restricted to I2S controller 0 on ESP32 targets, and per schematic the
// mic's PDM CLK and the speaker's LRCLK both land on GPIO43 anyway -- splitting them
// across two controllers (as M5Stack's own reference firmware does) isn't possible
// here since Tactility's GPIO ownership model is exclusive-acquire-only (no pin
// sharing), and two I2S controllers both declaring GPIO43 would have one fail to
// start. Keeping both on one controller means only one acquire of GPIO43 happens;
// audio_codec_data_if_i2s.c's data_set_fmt() already tears down and recreates the
// channel on each codec open(), so opening one direction after the other naturally
// reconfigures the shared port/pin -- speaker and mic still cannot be used
// simultaneously, which matches the hardware reality.
i2s0 {
compatible = "espressif,esp32-i2s";
port = <I2S_NUM_0>;
@@ -133,4 +144,15 @@
pin-data-out = <&gpio0 42 GPIO_FLAG_NONE>;
pin-data-in = <&gpio0 46 GPIO_FLAG_NONE>;
};
speaker0 {
compatible = "nsiway,ns4168";
i2s = <&i2s0>;
};
mic0 {
compatible = "generic,spm1423";
i2s = <&i2s0>;
channels = <1>;
};
};
+1 -1
View File
@@ -3,5 +3,5 @@ file(GLOB_RECURSE SOURCE_FILES Source/*.c*)
idf_component_register(
SRCS ${SOURCE_FILES}
INCLUDE_DIRS "Source"
REQUIRES Tactility esp_lvgl_port ILI934x FT6x36 AXP2101 AW9523 driver vfs fatfs ina226-module py32ioexpander-module
REQUIRES Tactility esp_lvgl_port ILI934x FT6x36 AXP2101 driver vfs fatfs ina226-module py32ioexpander-module
)
@@ -2,6 +2,7 @@
#include "devices/Power.h"
#include <tactility/device.h>
#include <tactility/drivers/gpio_controller.h>
#include <tactility/drivers/i2c_controller.h>
#include <tactility/log.h>
#include <drivers/py32ioexpander.h>
@@ -20,38 +21,45 @@ static const auto* TAG = "StackChan";
// I2C addresses
// ---------------------------------------------------------------------------
static constexpr uint8_t AXP2101_ADDR = 0x34;
static constexpr uint8_t AW9523B_ADDR = 0x58;
static constexpr uint8_t AW88298_ADDR = 0x36;
static constexpr uint8_t ES7210_ADDR = 0x40;
// ---------------------------------------------------------------------------
// AW9523B GPIO expander — same wiring as CoreS3
// AW9523B GPIO expander pin map — same wiring as CoreS3.
// AW88298 reset (P0_2) is driven directly by the aw88298-module driver itself
// (see m5stack,stackchan.dts pin-reset property), not from here.
// ---------------------------------------------------------------------------
// P0 pins: 0=touch reset, 1=bus out enable, 2=AW88298 reset, 4=SD card, 5=USB OTG
// P1 pins: 0=cam reset, 1=LCD reset, 7=boost enable (SY7088)
static constexpr uint8_t AW9523B_CTL_REG = 0x11; // P0 push-pull mode
static constexpr uint8_t AW9523B_P0_REG = 0x02;
static constexpr uint8_t AW9523B_P1_REG = 0x03;
constexpr auto AW9523B_PIN_TOUCH_RESET = 0; // P0_0
constexpr auto AW9523B_PIN_BUS_OUT_ENABLE = 1; // P0_1
constexpr auto AW9523B_PIN_SD_CARD_SWITCH = 4; // P0_4
constexpr auto AW9523B_PIN_LCD_RESET = 8 + 1; // P1_1
constexpr auto AW9523B_PIN_BOOST_ENABLE = 8 + 7; // P1_7 (SY7088)
static bool initGpioExpander(::Device* i2c) {
// P0: touch, bus enable, AW88298 reset, SD card switch
constexpr uint8_t p0 = (1U << 0U) | (1U << 1U) | (1U << 2U) | (1U << 4U);
// P1: LCD reset, boost enable
constexpr uint8_t p1 = (1U << 1U) | (1U << 7U);
static bool initGpioExpander(::Device* aw9523b) {
struct PinInit { uint8_t pin; bool level; };
static constexpr PinInit pins[] = {
{ AW9523B_PIN_TOUCH_RESET, true },
{ AW9523B_PIN_BUS_OUT_ENABLE, true },
{ AW9523B_PIN_SD_CARD_SWITCH, true },
{ AW9523B_PIN_LCD_RESET, true },
{ AW9523B_PIN_BOOST_ENABLE, true },
};
// Set P0 to push-pull mode
if (i2c_controller_register8_set(i2c, AW9523B_ADDR, AW9523B_CTL_REG, 0x10, pdMS_TO_TICKS(1000)) != ERROR_NONE) {
LOG_E(TAG, "AW9523B: Failed to set CTL");
return false;
}
if (i2c_controller_register8_set(i2c, AW9523B_ADDR, AW9523B_P0_REG, p0, pdMS_TO_TICKS(1000)) != ERROR_NONE) {
LOG_E(TAG, "AW9523B: Failed to set P0");
return false;
}
if (i2c_controller_register8_set(i2c, AW9523B_ADDR, AW9523B_P1_REG, p1, pdMS_TO_TICKS(1000)) != ERROR_NONE) {
LOG_E(TAG, "AW9523B: Failed to set P1");
return false;
for (const auto& pinInit : pins) {
auto* descriptor = gpio_descriptor_acquire(aw9523b, pinInit.pin, GPIO_OWNER_GPIO);
if (descriptor == nullptr) {
LOG_E(TAG, "AW9523B: Failed to acquire pin %u", pinInit.pin);
return false;
}
error_t error = gpio_descriptor_set_flags(descriptor, GPIO_FLAG_DIRECTION_OUTPUT);
if (error == ERROR_NONE) {
error = gpio_descriptor_set_level(descriptor, pinInit.level);
}
gpio_descriptor_release(descriptor);
if (error != ERROR_NONE) {
LOG_E(TAG, "AW9523B: Failed to configure pin %u", pinInit.pin);
return false;
}
}
return true;
}
@@ -80,100 +88,7 @@ static bool initPowerControl(::Device* i2c) {
}
// ---------------------------------------------------------------------------
// AW88298 speaker amplifier
// Called once in initBoot() at 16kHz. AW88298 default state after hardware reset
// is sufficient for SfxEngine. Sequence mirrors M5Unified _speaker_enabled_cb_cores3().
// NOTE: 44100Hz (AudioPlayer/MusicPlayer) needs esp_codec_dev integration — see memory notes.
// ---------------------------------------------------------------------------
static bool initSpeaker(::Device* i2c, uint32_t sample_rate_hz) {
// M5Unified rate table: (sample_rate + 1102) / 2205 steps, first entry >= result
static constexpr uint8_t rate_tbl[] = { 4, 5, 6, 8, 10, 11, 15, 20, 22, 44 };
size_t reg06_idx = 0;
size_t rate = (sample_rate_hz + 1102) / 2205;
while (rate > rate_tbl[reg06_idx] && ++reg06_idx < sizeof(rate_tbl)) {}
if (reg06_idx >= sizeof(rate_tbl)) {
reg06_idx = sizeof(rate_tbl) - 1; // clamp to max supported rate
}
// 0x14C0: M5Unified's upper byte for CoreS3, I2SBCK=0 (BCK 16*2)
const uint16_t reg06 = static_cast<uint16_t>(0x14C0U | reg06_idx);
// Hardware reset AW88298 via AW9523B P0 bit 2: pull LOW (reset), then HIGH (release).
if (i2c_controller_register8_reset_bits(i2c, AW9523B_ADDR, AW9523B_P0_REG, 0b00000100, pdMS_TO_TICKS(100)) != ERROR_NONE) {
LOG_E(TAG, "AW9523B: failed to assert AW88298 reset");
return false;
}
vTaskDelay(pdMS_TO_TICKS(10));
if (i2c_controller_register8_set_bits(i2c, AW9523B_ADDR, AW9523B_P0_REG, 0b00000100, pdMS_TO_TICKS(100)) != ERROR_NONE) {
LOG_E(TAG, "AW9523B: failed to release AW88298 reset");
return false;
}
vTaskDelay(pdMS_TO_TICKS(50));
// Exact sequence from M5Unified _speaker_enabled_cb_cores3() — no I2C software reset.
struct { uint8_t reg; uint16_t val; } regs[] = {
{ 0x61, 0x0673 }, // boost mode disabled
{ 0x04, 0x4040 }, // I2SEN=1, AMPPD=0, PWDN=0
{ 0x05, 0x0008 }, // RMSE=0, HAGCE=0, HDCCE=0, HMUTE=0
{ 0x06, reg06 }, // I2S mode + sample rate
{ 0x0C, 0x3064 }, // volume -24dB
};
for (auto& r : regs) {
if (i2c_controller_register16be_set(i2c, AW88298_ADDR, r.reg, r.val, pdMS_TO_TICKS(100)) != ERROR_NONE) {
LOG_E(TAG, "AW88298: failed reg 0x%02X", r.reg);
return false;
}
}
LOG_I(TAG, "AW88298 initialized (%luHz, reg06=0x%04X)", (unsigned long)sample_rate_hz, reg06);
return true;
}
// ---------------------------------------------------------------------------
// ES7210 microphone ADC
// Source: https://github.com/m5stack/M5Unified
// ---------------------------------------------------------------------------
static bool initMicrophone(::Device* i2c) {
static constexpr uint8_t reg_data[] = {
0x00, 0x41, // RESET_CTL
0x01, 0x1F, // CLK_ON_OFF (initial)
0x06, 0x00, // DIGITAL_PDN
0x07, 0x20, // ADC_OSR
0x08, 0x10, // MODE_CFG
0x09, 0x30, // TCT0_CHPINI
0x0A, 0x30, // TCT1_CHPINI
0x20, 0x0A, // ADC34_HPF2
0x21, 0x2A, // ADC34_HPF1
0x22, 0x0A, // ADC12_HPF2
0x23, 0x2A, // ADC12_HPF1
0x02, 0xC1,
0x04, 0x01,
0x05, 0x00,
0x11, 0x60,
0x40, 0x42, // ANALOG_SYS
0x41, 0x70, // MICBIAS12
0x42, 0x70, // MICBIAS34
0x43, 0x1B, // MIC1_GAIN
0x44, 0x1B, // MIC2_GAIN
0x45, 0x00, // MIC3_GAIN
0x46, 0x00, // MIC4_GAIN
0x47, 0x00, // MIC1_LP
0x48, 0x00, // MIC2_LP
0x49, 0x00, // MIC3_LP
0x4A, 0x00, // MIC4_LP
0x4B, 0x00, // MIC12_PDN
0x4C, 0xFF, // MIC34_PDN
0x01, 0x14, // CLK_ON_OFF (final)
};
if (i2c_controller_write_register_array(i2c, ES7210_ADDR, reg_data, sizeof(reg_data), pdMS_TO_TICKS(1000)) != ERROR_NONE) {
LOG_E(TAG, "ES7210: Failed to set registers");
return false;
}
return true;
}
// ---------------------------------------------------------------------------
// initBoot — called before device tree is started
// initBoot — called after devicetree devices are constructed/started
// ---------------------------------------------------------------------------
static std::shared_ptr<Axp2101> axp2101;
@@ -183,26 +98,22 @@ bool initBoot() {
LOG_E(TAG, "i2c_internal not found");
return false;
}
// Boost enable via AXP2101 before GPIO expander init (same as CoreS3)
// AW9523B P1 bit 7 = SY7088 boost enable — set after AXP2101 is configured
if (!initPowerControl(i2c)) {
LOG_E(TAG, "AXP2101 init failed");
return false;
}
if (!initGpioExpander(i2c)) {
LOG_E(TAG, "AW9523B init failed");
auto* aw9523b = device_find_by_name("aw9523b");
if (aw9523b == nullptr) {
LOG_E(TAG, "aw9523b not found");
return false;
}
// AW88298 default state after reset is sufficient for SfxEngine (16kHz).
// Full 44100Hz support requires esp_codec_dev integration (see memory notes).
if (!initSpeaker(i2c, 16000)) {
LOG_W(TAG, "AW88298 init failed (non-fatal)");
}
if (!initMicrophone(i2c)) {
LOG_W(TAG, "ES7210 init failed (non-fatal)");
if (!initGpioExpander(aw9523b)) {
LOG_E(TAG, "AW9523B init failed");
return false;
}
// Boot LED pattern — confirms PY32IOExpander is working.
+9 -5
View File
@@ -1,7 +1,11 @@
dependencies:
- Platforms/platform-esp32
- Drivers/bmi270-module
- Drivers/bm8563-module
- Drivers/ina226-module
- Drivers/py32ioexpander-module
- Platforms/platform-esp32
- Drivers/bmi270-module
- Drivers/bm8563-module
- Drivers/ina226-module
- Drivers/py32ioexpander-module
- Drivers/aw9523b-module
- Drivers/aw88298-module
- Drivers/es7210-module
- Drivers/audio-stream-module
dts: m5stack,stackchan.dts
+44 -14
View File
@@ -13,6 +13,9 @@
#include <bindings/bm8563.h>
#include <bindings/ina226.h>
#include <bindings/py32ioexpander.h>
#include <bindings/aw9523b.h>
#include <bindings/aw88298.h>
#include <bindings/es7210.h>
#include <tactility/bindings/esp32_sdspi.h>
#include <tactility/bindings/display_placeholder.h>
@@ -36,6 +39,17 @@
gpio-count = <49>;
};
// AW88298 speaker + ES7210 microphone
i2s0: i2s0 {
compatible = "espressif,esp32-i2s";
port = <I2S_NUM_0>;
pin-bclk = <&gpio0 34 GPIO_FLAG_NONE>;
pin-ws = <&gpio0 33 GPIO_FLAG_NONE>;
pin-data-out = <&gpio0 13 GPIO_FLAG_NONE>;
pin-data-in = <&gpio0 14 GPIO_FLAG_NONE>;
pin-mclk = <&gpio0 0 GPIO_FLAG_NONE>;
};
i2c_internal {
compatible = "espressif,esp32-i2c";
port = <I2C_NUM_0>;
@@ -65,10 +79,37 @@
shunt-milliohms = <10>;
};
// AW9523B pin map (same wiring as CoreS3):
// P0_0 = touch reset, P0_1 = bus-out enable, P0_2 = AW88298 reset,
// P0_4 = SD card switch, P1_1 = LCD reset, P1_7 = boost enable (SY7088)
aw9523b: aw9523b {
compatible = "awinic,aw9523b";
reg = <0x58>;
};
aw88298 {
compatible = "awinic,aw88298";
reg = <0x36>;
i2s = <&i2s0>;
pin-reset = <&aw9523b 2 GPIO_FLAG_NONE>;
};
es7210 {
compatible = "everest,es7210";
reg = <0x40>;
i2s = <&i2s0>;
// Only MIC1/MIC2 are wired to real capsules (see schematic); MIC3/MIC4
// slots carry AEC_P/AEC_N reference signal, not microphone audio.
mic-mask = <3>;
// M5Unified applies a 4x post-gain "magnification" for this exact mic
// wiring (see M5Unified.cpp _mic_data_cb_cores3): the ES7210's own
// hardware ADC gain (already near-max via the default 90% input volume
// setting, ~34dB of its 0-37.5dB range) still isn't enough for these
// capsules on their own.
input-gain-percent = <400>;
};
// AXP2101 PMIC @ 0x34 — initialized manually in initBoot()
// AW9523B GPIO expander @ 0x58 — initialized manually in initBoot() (same as CoreS3)
// AW88298 speaker amp @ 0x36 — initialized manually in initBoot()
// ES7210 microphone ADC @ 0x40 — initialized manually in initBoot()
// FT6336U capacitive touch @ 0x38 — used by Display driver (FT6x36 library)
// TODO: Si12T 3-zone head touch @ 0x68 — INT active-low, 10kΩ pull-up to 3.3V; driver not yet implemented
@@ -135,15 +176,4 @@
frequency-khz = <20000>;
};
};
// AW88298 speaker + ES7210 microphone
i2s0 {
compatible = "espressif,esp32-i2s";
port = <I2S_NUM_0>;
pin-bclk = <&gpio0 34 GPIO_FLAG_NONE>;
pin-ws = <&gpio0 33 GPIO_FLAG_NONE>;
pin-data-out = <&gpio0 13 GPIO_FLAG_NONE>;
pin-data-in = <&gpio0 14 GPIO_FLAG_NONE>;
pin-mclk = <&gpio0 0 GPIO_FLAG_NONE>;
};
};
+1 -1
View File
@@ -3,5 +3,5 @@ file(GLOB_RECURSE SOURCE_FILES Source/*.c*)
idf_component_register(
SRCS ${SOURCE_FILES}
INCLUDE_DIRS "Source"
REQUIRES Tactility esp_lvgl_port esp_lcd ST7789 PwmBacklight ButtonControl m5pm1-module vfs fatfs
REQUIRES Tactility esp_lvgl_port esp_lcd ST7789 PwmBacklight ButtonControl vfs fatfs m5pm1-module
)
@@ -2,7 +2,6 @@
#include "devices/Power.h"
#include <tactility/device.h>
#include <tactility/drivers/i2c_controller.h>
#include <drivers/m5pm1.h>
#include <Tactility/hal/Configuration.h>
@@ -13,87 +12,25 @@ using namespace tt::hal;
static constexpr auto* TAG = "StickS3";
static constexpr uint8_t ES8311_I2C_ADDR = 0x18;
static error_t initSound(::Device* i2c_controller) {
// Init data from M5Unified:
// https://github.com/m5stack/M5Unified/blob/master/src/M5Unified.cpp#L454
static constexpr uint8_t ENABLED_BULK_DATA[] = {
0x00, 0x80, // 0x00 RESET/ CSM POWER ON
0x01, 0x3F, // 0x01 CLOCK_MANAGER/ use MCLK pin (external), all clocks on
0x02, 0x00, // 0x02 CLOCK_MANAGER/ pre_div=1 pre_multi=1 (256x MCLK from ESP32 is correct ratio)
0x0D, 0x01, // 0x0D SYSTEM/ Power up analog circuitry
0x12, 0x00, // 0x12 SYSTEM/ power-up DAC - NOT default
0x13, 0x10, // 0x13 SYSTEM/ Enable output to HP drive - NOT default
0x32, 0xBF, // 0x32 DAC/ DAC volume (0xBF == ±0 dB )
0x37, 0x08, // 0x37 DAC/ Bypass DAC equalizer - NOT default
};
error_t error = i2c_controller_write_register_array(
i2c_controller,
ES8311_I2C_ADDR,
ENABLED_BULK_DATA,
sizeof(ENABLED_BULK_DATA),
pdMS_TO_TICKS(1000)
);
if (error != ERROR_NONE) {
LOG_E(TAG, "Failed to enable ES8311: %s", error_to_string(error));
return error;
}
// Enable speaker amp via M5PM1 driver
// Audio codec register programming is owned by the es8311-module driver (registered as an
// AUDIO_CODEC_TYPE device, see m5stack,sticks3.dts). This board still needs to drive the
// AW8737 speaker amplifier's enable line via m5pm1 (PM1_G3), which is board wiring glue
// rather than codec configuration, so it stays here.
static void enableSpeakerAmplifier() {
auto* m5pm1 = device_find_by_name("m5pm1");
if (m5pm1 != nullptr) {
m5pm1_set_speaker_enable(m5pm1, true);
} else {
LOG_W(TAG, "m5pm1 not found — speaker amp not enabled");
if (m5pm1 == nullptr) {
LOG_W(TAG, "m5pm1 not found -- speaker amp not enabled");
return;
}
return ERROR_NONE;
}
static error_t initMicrophone(::Device* i2c_controller) {
// Init data from M5Unified:
// https://github.com/m5stack/M5Unified/blob/master/src/M5Unified.cpp#L842
static constexpr uint8_t ENABLED_BULK_DATA[] = {
0x00, 0x80, // 0x00 RESET/ CSM POWER ON
0x01, 0x3F, // 0x01 CLOCK_MANAGER/ use MCLK pin (external), all clocks on
0x02, 0x00, // 0x02 CLOCK_MANAGER/ pre_div=1 pre_multi=1 (256x MCLK from ESP32 is correct ratio)
0x0D, 0x01, // 0x0D SYSTEM/ Power up analog circuitry
0x0E, 0x02, // 0x0E SYSTEM/ : Enable analog PGA, enable ADC modulator
0x14, 0x10, // ES8311_ADC_REG14 : select Mic1p-Mic1n / PGA GAIN (minimum)
0x17, 0xFF, // ES8311_ADC_REG17 : ADC_VOLUME (MAXGAIN) // (0xBF == ± 0 dB )
0x1C, 0x6A, // ES8311_ADC_REG1C : ADC Equalizer bypass, cancel DC offset in digital domain
};
error_t error = i2c_controller_write_register_array(
i2c_controller,
ES8311_I2C_ADDR,
ENABLED_BULK_DATA,
sizeof(ENABLED_BULK_DATA),
pdMS_TO_TICKS(1000)
);
error_t error = m5pm1_set_speaker_enable(m5pm1, true);
if (error != ERROR_NONE) {
LOG_E(TAG, "Failed to enable ES8311: %s", error_to_string(error));
return error;
LOG_E(TAG, "Failed to enable speaker amplifier: %s", error_to_string(error));
}
return ERROR_NONE;
}
bool initBoot() {
auto* i2c_internal = device_find_by_name("i2c_internal");
check(i2c_internal, "i2c_internal not found");
error_t error = initSound(i2c_internal);
if (error != ERROR_NONE) {
LOG_E(TAG, "Failed to enable ES8311 speaker");
}
error = initMicrophone(i2c_internal);
if (error != ERROR_NONE) {
LOG_E(TAG, "Failed to enable ES8311 microphone");
}
enableSpeakerAmplifier();
return driver::pwmbacklight::init(GPIO_NUM_38, 512);
}
+5 -3
View File
@@ -1,5 +1,7 @@
dependencies:
- Platforms/platform-esp32
- Drivers/bmi270-module
- Drivers/m5pm1-module
- Platforms/platform-esp32
- Drivers/bmi270-module
- Drivers/m5pm1-module
- Drivers/es8311-module
- Drivers/audio-stream-module
dts: m5stack,sticks3.dts
+18 -11
View File
@@ -9,6 +9,7 @@
#include <tactility/bindings/esp32_uart.h>
#include <bindings/bmi270.h>
#include <bindings/m5pm1.h>
#include <bindings/es8311.h>
#include <tactility/bindings/esp32_sdspi.h>
#include <tactility/bindings/display_placeholder.h>
@@ -31,6 +32,17 @@
gpio-count = <49>;
};
// Speaker and microphone (ES8311)
i2s0 {
compatible = "espressif,esp32-i2s";
port = <I2S_NUM_0>;
pin-bclk = <&gpio0 17 GPIO_FLAG_NONE>;
pin-ws = <&gpio0 15 GPIO_FLAG_NONE>;
pin-data-out = <&gpio0 14 GPIO_FLAG_NONE>;
pin-data-in = <&gpio0 16 GPIO_FLAG_NONE>;
pin-mclk = <&gpio0 18 GPIO_FLAG_NONE>;
};
i2c_internal {
compatible = "espressif,esp32-i2c";
port = <I2C_NUM_0>;
@@ -47,6 +59,12 @@
compatible = "bosch,bmi270";
reg = <0x68>;
};
es8311 {
compatible = "everest,es8311";
reg = <0x18>;
i2s = <&i2s0>;
};
};
i2c_grove {
@@ -69,17 +87,6 @@
};
};
// Speaker and microphone (ES8311)
i2s0 {
compatible = "espressif,esp32-i2s";
port = <I2S_NUM_0>;
pin-bclk = <&gpio0 17 GPIO_FLAG_NONE>;
pin-ws = <&gpio0 15 GPIO_FLAG_NONE>;
pin-data-out = <&gpio0 14 GPIO_FLAG_NONE>;
pin-data-in = <&gpio0 16 GPIO_FLAG_NONE>;
pin-mclk = <&gpio0 18 GPIO_FLAG_NONE>;
};
uart_grove: uart1 {
compatible = "espressif,esp32-uart";
status = "disabled";
+1 -1
View File
@@ -3,5 +3,5 @@ file(GLOB_RECURSE SOURCE_FILES Source/*.c*)
idf_component_register(
SRCS ${SOURCE_FILES}
INCLUDE_DIRS "Source"
REQUIRES Tactility esp_lvgl_port esp_lcd EspLcdCompat esp_lcd_ili9881c esp_lcd_st7123 esp_lcd_touch_st7123 GT911 PwmBacklight driver esp_driver_i2c vfs fatfs ina226-module sc2356-module
REQUIRES Tactility esp_lvgl_port esp_lcd EspLcdCompat esp_lcd_ili9881c esp_lcd_st7123 esp_lcd_touch_st7123 GT911 PwmBacklight driver esp_driver_i2c vfs fatfs ina226-module
)
+8 -109
View File
@@ -140,57 +140,14 @@ static void initExpander1(::Device* io_expander1) {
gpio_descriptor_release(ip2326_charge_enable_pin);
}
static error_t initSound(::Device* i2c_controller, ::Device* io_expander0 = nullptr) {
// Init data from M5Unified:
// https://github.com/m5stack/M5Unified/blob/master/src/M5Unified.cpp
static constexpr uint8_t ES8388_I2C_ADDR = 0x10;
static constexpr uint8_t ENABLED_BULK_DATA[] = {
0, 0x80, // RESET/ CSM POWER ON
0, 0x00,
0, 0x00,
0, 0x0E,
1, 0x00,
2, 0x0A, // CHIP POWER: power up all
3, 0xFF, // ADC POWER: power down all
4, 0x3C, // DAC POWER: power up and LOUT1/ROUT1/LOUT2/ROUT2 enable
5, 0x00, // ChipLowPower1
6, 0x00, // ChipLowPower2
7, 0x7C, // VSEL
8, 0x00, // set I2S slave mode
// reg9-22 == adc
23, 0x18, // I2S format (16bit)
24, 0x00, // I2S MCLK ratio (128)
25, 0x20, // DAC unmute
26, 0x00, // LDACVOL 0x00~0xC0
27, 0x00, // RDACVOL 0x00~0xC0
28, 0x08, // enable digital click free power up and down
29, 0x00,
38, 0x00, // DAC CTRL16
39, 0xB8, // LEFT Ch MIX
42, 0xB8, // RIGHTCh MIX
43, 0x08, // ADC and DAC separate
45, 0x00, // 0x00=1.5k VREF analog output / 0x10=40kVREF analog output
46, 0x21,
47, 0x21,
48, 0x21,
49, 0x21
};
error_t error = i2c_controller_write_register_array(
i2c_controller,
ES8388_I2C_ADDR,
ENABLED_BULK_DATA,
sizeof(ENABLED_BULK_DATA),
pdMS_TO_TICKS(1000)
);
if (error != ERROR_NONE) {
LOG_E(TAG, "Failed to enable ES8388: %s", error_to_string(error));
return error;
}
// Audio codec register programming is owned by the es8388-module/es7210-module drivers
// (registered as AUDIO_CODEC_TYPE devices, see m5stack,tab5.dts). This board still needs
// to drive the external speaker amplifier's enable line via io_expander0, which is board
// wiring glue rather than codec configuration, so it stays here.
static error_t enableSpeakerAmplifier(::Device* io_expander0) {
auto* speaker_enable_pin = gpio_descriptor_acquire(io_expander0, GPIO_EXP0_PIN_SPEAKER_ENABLE, GPIO_OWNER_GPIO);
check(speaker_enable_pin, "Failed to acquire speaker enable pin");
error = gpio_descriptor_set_level(speaker_enable_pin, true);
error_t error = gpio_descriptor_set_level(speaker_enable_pin, true);
gpio_descriptor_release(speaker_enable_pin);
if (error != ERROR_NONE) {
LOG_E(TAG, "Failed to enable amplifier: %s", error_to_string(error));
@@ -200,56 +157,6 @@ static error_t initSound(::Device* i2c_controller, ::Device* io_expander0 = null
return ERROR_NONE;
}
static error_t initMicrophone(::Device* i2c_controller) {
// ES7210 quad-channel microphone ADC at 0x40.
// Register sequence from M5Unified (M5Unified.cpp, _microphone_enabled_cb_tab5).
// Configures 4-slot TDM output at 48kHz/16-bit with MIC1+MIC2 active and MICBIAS enabled.
static constexpr uint8_t ES7210_I2C_ADDR = 0x40;
static constexpr uint8_t INIT_DATA[] = {
0x00, 0xFF, // RESET_CTL: full reset
0x00, 0x41, // RESET_CTL: release reset, keep CSM active
0x01, 0x1F, // CLK_ON_OFF: enable all clocks
0x06, 0x00, // DIGITAL_PDN: power up all digital blocks
0x07, 0x20, // ADC_OSR: OSR=256
0x08, 0x10, // MODE_CFG: I2S slave, TDM mode
0x09, 0x30, // TCT0_CHPINI: chopper init period
0x0A, 0x30, // TCT1_CHPINI
0x20, 0x0A, // ADC34_HPF2
0x21, 0x2A, // ADC34_HPF1
0x22, 0x0A, // ADC12_HPF2
0x23, 0x2A, // ADC12_HPF1
0x02, 0xC1, // CLK_CTRL: MCLK from I2S, PLL off
0x04, 0x01, // SDPOUT_CTL1: TDM output enable
0x05, 0x00, // SDPOUT_CTL0
0x11, 0x60, // DBIAS: adjust reference voltage for P4
0x40, 0x42, // ANALOG_SYS: enable analog supply
0x41, 0x70, // MICBIAS12: enable MICBIAS for MIC1+MIC2
0x42, 0x70, // MICBIAS34: enable MICBIAS for MIC3+MIC4
0x43, 0x1B, // MIC1_GAIN: +30 dB
0x44, 0x1B, // MIC2_GAIN: +30 dB
0x45, 0x00, // MIC3_GAIN: AEC ref, no gain
0x46, 0x00, // MIC4_GAIN: AEC ref, no gain
0x47, 0x00, // MIC1_LP
0x48, 0x00, // MIC2_LP
0x49, 0x00, // MIC3_LP
0x4A, 0x00, // MIC4_LP
0x4B, 0x00, // MIC12_PDN: power up MIC1+MIC2
0x4C, 0xFF, // MIC34_PDN: keep MIC3+MIC4 in power-down (AEC ref not needed)
0x01, 0x14, // CLK_ON_OFF: final clock config
};
error_t error = i2c_controller_write_register_array(
i2c_controller,
ES7210_I2C_ADDR,
INIT_DATA,
sizeof(INIT_DATA),
pdMS_TO_TICKS(1000)
);
if (error != ERROR_NONE) {
LOG_E(TAG, "Failed to init ES7210: %s", error_to_string(error));
}
return error;
}
static esp_clock_output_mapping_handle_t camera_osc_handle = nullptr;
@@ -275,9 +182,6 @@ static void initCameraOsc() {
}
static bool initBoot() {
auto* i2c0 = device_find_by_name("i2c0");
check(i2c0, "i2c0 not found");
auto* io_expander0 = device_find_by_name("io_expander0");
check(io_expander0, "io_expander0 not found");
auto* io_expander1 = device_find_by_name("io_expander1");
@@ -287,14 +191,9 @@ static bool initBoot() {
initExpander0(io_expander0);
initExpander1(io_expander1);
error_t error = initSound(i2c0, io_expander0);
error_t error = enableSpeakerAmplifier(io_expander0);
if (error != ERROR_NONE) {
LOG_E(TAG, "Failed to enable ES8388");
}
error = initMicrophone(i2c0);
if (error != ERROR_NONE) {
LOG_E(TAG, "Failed to init ES7210");
LOG_E(TAG, "Failed to enable speaker amplifier");
}
return true;
+9 -6
View File
@@ -1,8 +1,11 @@
dependencies:
- Platforms/platform-esp32
- Drivers/pi4ioe5v6408-module
- Drivers/bmi270-module
- Drivers/ina226-module
- Drivers/rx8130ce-module
- Drivers/sc2356-module
- Platforms/platform-esp32
- Drivers/pi4ioe5v6408-module
- Drivers/bmi270-module
- Drivers/es7210-module
- Drivers/es8388-module
- Drivers/audio-stream-module
- Drivers/ina226-module
- Drivers/rx8130ce-module
- Drivers/sc2356-module
dts: m5stack,tab5.dts
+32 -11
View File
@@ -11,6 +11,8 @@
#include <tactility/bindings/esp32_usbhost.h>
#include <tactility/bindings/esp32_wifi.h>
#include <bindings/bmi270.h>
#include <bindings/es7210.h>
#include <bindings/es8388.h>
#include <bindings/ina226.h>
#include <bindings/pi4ioe5v6408.h>
#include <bindings/rx8130ce.h>
@@ -35,6 +37,17 @@
gpio-count = <57>;
};
// Declared before i2c0 so it starts before the es8388/es7210 codecs that reference it
i2s0 {
compatible = "espressif,esp32-i2s";
port = <I2S_NUM_0>;
pin-bclk = <&gpio0 27 GPIO_FLAG_NONE>;
pin-ws = <&gpio0 29 GPIO_FLAG_NONE>;
pin-data-out = <&gpio0 26 GPIO_FLAG_NONE>;
pin-data-in = <&gpio0 28 GPIO_FLAG_NONE>;
pin-mclk = <&gpio0 30 GPIO_FLAG_NONE>;
};
i2c_internal: i2c0 {
compatible = "espressif,esp32-i2c-master";
port = <I2C_NUM_0>;
@@ -57,6 +70,25 @@
reg = <0x68>;
};
es8388 {
compatible = "everest,es8388";
reg = <0x10>;
i2s = <&i2s0>;
};
es7210 {
compatible = "everest,es7210";
reg = <0x40>;
i2s = <&i2s0>;
// Per schematic: MIC1/MIC2 are the two onboard capsules (U17/U16).
// MIC3 is not a microphone -- MIC3P is tapped from HPOUT_L (AEC_P) as an
// acoustic-echo-cancellation reference, MIC3N goes to AGND. MIC4 is the
// external headset-mic jack input (HPMIC), also not onboard. Select only
// the two real capsules; MIC3/MIC4 would otherwise show up as silent (or
// speaker-echoing) extra channels.
mic-mask = <3>;
};
rx8130ce {
compatible = "epson,rx8130ce";
reg = <0x32>;
@@ -107,17 +139,6 @@
on-chip-ldo-chan = <4>;
};
// ES8388 and ES7210
i2s0 {
compatible = "espressif,esp32-i2s";
port = <I2S_NUM_0>;
pin-bclk = <&gpio0 27 GPIO_FLAG_NONE>;
pin-ws = <&gpio0 29 GPIO_FLAG_NONE>;
pin-data-out = <&gpio0 26 GPIO_FLAG_NONE>;
pin-data-in = <&gpio0 28 GPIO_FLAG_NONE>;
pin-mclk = <&gpio0 30 GPIO_FLAG_NONE>;
};
usbhost0 {
compatible = "espressif,esp32-usbhost";
peripheral-map = <0>;