diff --git a/firmware/pump_dac.cpp b/firmware/pump_dac.cpp index 4241321..792aa80 100644 --- a/firmware/pump_dac.cpp +++ b/firmware/pump_dac.cpp @@ -7,17 +7,41 @@ #include "hal.h" // 48MHz / 1024 = 46.8khz PWM -static Pwm pumpDac(PUMP_DAC_PWM_DEVICE, PUMP_DAC_PWM_CHANNEL, 48'000'000, 1024); +PWMConfig pumpDacConfig = { + 48'000'000, + 1024, + nullptr, + { + {PWM_OUTPUT_ACTIVE_HIGH, nullptr}, + {PWM_OUTPUT_ACTIVE_HIGH, nullptr}, + {PWM_OUTPUT_ACTIVE_HIGH, nullptr}, + {PWM_OUTPUT_ACTIVE_HIGH, nullptr} + }, + 0, + 0, +#if STM32_PWM_USE_ADVANCED + 0 +#endif +}; + +static Pwm pumpDac(PUMP_DAC_PWM_DEVICE); struct pump_dac_state { int32_t curIpump; }; +static const uint8_t pumpDacPwmCh[] = { + PUMP_DAC_PWM_CHANNEL_0, +#if (AFR_CHANNELS > 1) + PUMP_DAC_PWM_CHANNEL_1, +#endif +}; + static struct pump_dac_state state[AFR_CHANNELS]; void InitPumpDac() { - pumpDac.Start(); + pumpDac.Start(&pumpDacConfig); for (int ch = 0; ch < AFR_CHANNELS; ch++) { @@ -45,12 +69,12 @@ void SetPumpCurrentTarget(int ch, int32_t microampere) // offset by half vcc volts += HALF_VCC; - pumpDac.SetDuty(volts / VCC_VOLTS); + pumpDac.SetDuty(pumpDacPwmCh[ch], volts / VCC_VOLTS); } float GetPumpOutputDuty(int ch) { - return pumpDac.GetLastDuty(); + return pumpDac.GetLastDuty(ch); } float GetPumpCurrent(int ch)