Skip to content

Commit

Permalink
damc: add micbias control
Browse files Browse the repository at this point in the history
  • Loading branch information
amurzeau committed Jun 16, 2024
1 parent a660d0d commit a6de3e2
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 1 deletion.
2 changes: 2 additions & 0 deletions damc/damc_simple_lib/AudioProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand All @@ -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() {}
Expand Down
2 changes: 2 additions & 0 deletions damc/damc_simple_lib/AudioProcessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <Osc/OscDynamicVariable.h>
#include <Osc/OscFixedArray.h>
#include <Osc/OscReadOnlyVariable.h>
#include <Osc/OscVariable.h>
#include <OscRoot.h>
#include <OscStatePersist.h>
#include <array>
Expand Down Expand Up @@ -70,6 +71,7 @@ class AudioProcessor {

OscReadOnlyVariable<int32_t> oscTimeMeasure[TMI_NUMBER];
OscReadOnlyVariable<int32_t> oscTimeMeasureMaxPerLoop[TMI_NUMBER];
OscVariable<bool> oscEnableMicBias;

OscDynamicVariable<int32_t> fastMemoryAvailable;
OscDynamicVariable<int32_t> fastMemoryUsed;
Expand Down
6 changes: 6 additions & 0 deletions damc/damc_simple_lib/CodecAudio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,9 @@ uint32_t CodecAudio::getDMAInPos() {
bool CodecAudio::onFastTimer() {
return false;
}

void CodecAudio::setMicBias(bool enable) {
if(useTlvAsMclkMaster) {
codecDamcHATInit.setMicBias(enable);
}
}
2 changes: 2 additions & 0 deletions damc/damc_simple_lib/CodecAudio.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ class CodecAudio {

bool onFastTimer();

void setMicBias(bool enable);

static CodecAudio instance;

protected:
Expand Down
22 changes: 21 additions & 1 deletion damc/damc_simple_lib/CodecDamcHATInit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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-
Expand All @@ -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
Expand Down Expand Up @@ -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);
}
}
2 changes: 2 additions & 0 deletions damc/damc_simple_lib/CodecDamcHATInit.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit a6de3e2

Please sign in to comment.