Audio System + Drivers (#562)
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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";
|
||||
|
||||
Reference in New Issue
Block a user