diff --git a/damc/damc_simple_lib/AudioProcessor.cpp b/damc/damc_simple_lib/AudioProcessor.cpp index 9ccad64..0a43cac 100644 --- a/damc/damc_simple_lib/AudioProcessor.cpp +++ b/damc/damc_simple_lib/AudioProcessor.cpp @@ -55,6 +55,7 @@ AudioProcessor::AudioProcessor(uint32_t numChannels, uint32_t sampleRate, size_t {&oscRoot, "timePerLoopFastTimer"}, {&oscRoot, "timePerLoopOscInput"}, }, + oscEnableMicBias(&oscRoot, "enableMicBias", true), fastMemoryAvailable(&oscRoot, "fastMemoryAvailable"), fastMemoryUsed(&oscRoot, "fastMemoryUsed"), slowMemoryAvailable(&oscRoot, "memoryAvailable"), @@ -69,6 +70,7 @@ AudioProcessor::AudioProcessor(uint32_t numChannels, uint32_t sampleRate, size_t serialClient.init(); controls.init(); oscStatePersist.init(); + oscEnableMicBias.addChangeCallback([](bool enable) { CodecAudio::instance.setMicBias(enable); }); } AudioProcessor::~AudioProcessor() {} diff --git a/damc/damc_simple_lib/AudioProcessor.h b/damc/damc_simple_lib/AudioProcessor.h index 1bdfbca..5a533bf 100644 --- a/damc/damc_simple_lib/AudioProcessor.h +++ b/damc/damc_simple_lib/AudioProcessor.h @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include @@ -70,6 +71,7 @@ class AudioProcessor { OscReadOnlyVariable oscTimeMeasure[TMI_NUMBER]; OscReadOnlyVariable oscTimeMeasureMaxPerLoop[TMI_NUMBER]; + OscVariable oscEnableMicBias; OscDynamicVariable fastMemoryAvailable; OscDynamicVariable fastMemoryUsed; diff --git a/damc/damc_simple_lib/CodecAudio.cpp b/damc/damc_simple_lib/CodecAudio.cpp index 024b043..a18d221 100644 --- a/damc/damc_simple_lib/CodecAudio.cpp +++ b/damc/damc_simple_lib/CodecAudio.cpp @@ -72,3 +72,9 @@ uint32_t CodecAudio::getDMAInPos() { bool CodecAudio::onFastTimer() { return false; } + +void CodecAudio::setMicBias(bool enable) { + if(useTlvAsMclkMaster) { + codecDamcHATInit.setMicBias(enable); + } +} \ No newline at end of file diff --git a/damc/damc_simple_lib/CodecAudio.h b/damc/damc_simple_lib/CodecAudio.h index 767253c..350fb03 100644 --- a/damc/damc_simple_lib/CodecAudio.h +++ b/damc/damc_simple_lib/CodecAudio.h @@ -25,6 +25,8 @@ class CodecAudio { bool onFastTimer(); + void setMicBias(bool enable); + static CodecAudio instance; protected: diff --git a/damc/damc_simple_lib/CodecDamcHATInit.cpp b/damc/damc_simple_lib/CodecDamcHATInit.cpp index ad32cdb..cd79857 100644 --- a/damc/damc_simple_lib/CodecDamcHATInit.cpp +++ b/damc/damc_simple_lib/CodecDamcHATInit.cpp @@ -364,7 +364,7 @@ void CodecDamcHATInit::init_codec() { writeI2c(55, 0b00000001); // Right MICPGA Positive Terminal Input Routing Configuration Register // IN1L (SGND) to Right MICPGA- writeI2c(57, 0b00010000); // Right MICPGA Negative Terminal Input Routing Configuration Register - } else { + } else if(0) { // IN2L to Left MICPGA+ writeI2c(52, 0b00010000); // Left MICPGA Positive Terminal Input Routing Configuration Register // CM (GND) to Left MICPGA- @@ -374,6 +374,16 @@ void CodecDamcHATInit::init_codec() { writeI2c(55, 0b00000001); // Right MICPGA Positive Terminal Input Routing Configuration Register // CM (GND) to Right MICPGA- writeI2c(57, 0b01000000); // Right MICPGA Negative Terminal Input Routing Configuration Register + } else { + // IN1L (SGND) to Left MICPGA+ + writeI2c(52, 0b01000000); // Left MICPGA Positive Terminal Input Routing Configuration Register + // CM (GND) to Left MICPGA- + writeI2c(54, 0b01000000); // Left MICPGA Negative Terminal Input Routing Configuration Register + + // IN2R (SGND) to Right MICPGA+ + writeI2c(55, 0b00010000); // Right MICPGA Positive Terminal Input Routing Configuration Register + // CM (GND) to Right MICPGA- + writeI2c(57, 0b01000000); // Right MICPGA Negative Terminal Input Routing Configuration Register } writeI2c(58, 0b00001100); // Floating Input Configuration Register, IN3 weakly driven @@ -458,4 +468,14 @@ void CodecDamcHATInit::setReset(bool value) { void CodecDamcHATInit::setTpaEn(bool value) { GPIO_PinState gpio_value = value ? GPIO_PIN_SET : GPIO_PIN_RESET; HAL_GPIO_WritePin(GPIOB, GPIO_PIN_0, gpio_value); +} + +void CodecDamcHATInit::setMicBias(bool enable) { + // Select page 1 + writeI2c(0, 1); + if(enable) { + writeI2c(51, 0b01010000); + } else { + writeI2c(51, 0b00010000); + } } \ No newline at end of file diff --git a/damc/damc_simple_lib/CodecDamcHATInit.h b/damc/damc_simple_lib/CodecDamcHATInit.h index e2ec58c..cad82c0 100644 --- a/damc/damc_simple_lib/CodecDamcHATInit.h +++ b/damc/damc_simple_lib/CodecDamcHATInit.h @@ -25,6 +25,8 @@ class CodecDamcHATInit { uint16_t getTxRemainingCount(); uint16_t getRxRemainingCount(); + void setMicBias(bool enable); + private: void writeI2c(uint8_t address, uint8_t value); uint8_t readI2c(uint8_t address);