MCPcopy Create free account
hub / github.com/TactilityProject/Tactility / initSound

Function initSound

Devices/m5stack-sticks3/Source/Configuration.cpp:18–53  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

16static constexpr uint8_t ES8311_I2C_ADDR = 0x18;
17
18static error_t initSound(::Device* i2c_controller) {
19 // Init data from M5Unified:
20 // https://github.com/m5stack/M5Unified/blob/master/src/M5Unified.cpp#L454
21 static constexpr uint8_t ENABLED_BULK_DATA[] = {
22 0x00, 0x80, // 0x00 RESET/ CSM POWER ON
23 0x01, 0x3F, // 0x01 CLOCK_MANAGER/ use MCLK pin (external), all clocks on
24 0x02, 0x00, // 0x02 CLOCK_MANAGER/ pre_div=1 pre_multi=1 (256x MCLK from ESP32 is correct ratio)
25 0x0D, 0x01, // 0x0D SYSTEM/ Power up analog circuitry
26 0x12, 0x00, // 0x12 SYSTEM/ power-up DAC - NOT default
27 0x13, 0x10, // 0x13 SYSTEM/ Enable output to HP drive - NOT default
28 0x32, 0xBF, // 0x32 DAC/ DAC volume (0xBF == ±0 dB )
29 0x37, 0x08, // 0x37 DAC/ Bypass DAC equalizer - NOT default
30 };
31
32 error_t error = i2c_controller_write_register_array(
33 i2c_controller,
34 ES8311_I2C_ADDR,
35 ENABLED_BULK_DATA,
36 sizeof(ENABLED_BULK_DATA),
37 pdMS_TO_TICKS(1000)
38 );
39 if (error != ERROR_NONE) {
40 LOG_E(TAG, "Failed to enable ES8311: %s", error_to_string(error));
41 return error;
42 }
43
44 // Enable speaker amp via M5PM1 driver
45 auto* m5pm1 = device_find_by_name("m5pm1");
46 if (m5pm1 != nullptr) {
47 m5pm1_set_speaker_enable(m5pm1, true);
48 } else {
49 LOG_W(TAG, "m5pm1 not found — speaker amp not enabled");
50 }
51
52 return ERROR_NONE;
53}
54
55static error_t initMicrophone(::Device* i2c_controller) {
56 // Init data from M5Unified:

Callers 1

initBootFunction · 0.70

Calls 4

error_to_stringFunction · 0.85
device_find_by_nameFunction · 0.85
m5pm1_set_speaker_enableFunction · 0.85

Tested by

no test coverage detected