diff --git a/firmware/controllers/core/EfiWave.cpp b/firmware/controllers/core/EfiWave.cpp index 58502f1bea..77ea24a186 100644 --- a/firmware/controllers/core/EfiWave.cpp +++ b/firmware/controllers/core/EfiWave.cpp @@ -21,35 +21,35 @@ void single_wave_s::init(pin_state_t *pinStates) { this->pinStates = pinStates; } -void multi_wave_s::baseConstructor() { +void MultiWave::baseConstructor() { waves = NULL; switchTimes = NULL; reset(); } -multi_wave_s::multi_wave_s() { +MultiWave::MultiWave() { baseConstructor(); } -multi_wave_s::multi_wave_s(float *switchTimes, single_wave_s *waves) { +MultiWave::MultiWave(float *switchTimes, single_wave_s *waves) { baseConstructor(); init(switchTimes, waves); } -void multi_wave_s::init(float *switchTimes, single_wave_s *waves) { +void MultiWave::init(float *switchTimes, single_wave_s *waves) { this->switchTimes = switchTimes; this->waves = waves; } -void multi_wave_s::reset(void) { +void MultiWave::reset(void) { waveCount = 0; } -float multi_wave_s::getSwitchTime(int index) const { +float MultiWave::getSwitchTime(int index) const { return switchTimes[index]; } -void checkSwitchTimes2(int size, float *switchTimes) { +void MultiWave::checkSwitchTimes(int size) { if (switchTimes[size - 1] != 1) { firmwareError(CUSTOM_ERR_WAVE_1, "last switch time has to be 1 not %.2f", switchTimes[size - 1]); return; @@ -61,14 +61,14 @@ void checkSwitchTimes2(int size, float *switchTimes) { } } -int multi_wave_s::getChannelState(int channelIndex, int phaseIndex) const { +int MultiWave::getChannelState(int channelIndex, int phaseIndex) const { return waves[channelIndex].pinStates[phaseIndex]; } /** * returns the index at which given value would need to be inserted into sorted array */ -int multi_wave_s::findInsertionAngle(float angle, int size) const { +int MultiWave::findInsertionAngle(float angle, int size) const { for (int i = size - 1; i >= 0; i--) { if (angle > switchTimes[i]) return i + 1; @@ -76,7 +76,7 @@ int multi_wave_s::findInsertionAngle(float angle, int size) const { return 0; } -int multi_wave_s::findAngleMatch(float angle, int size) const { +int MultiWave::findAngleMatch(float angle, int size) const { for (int i = 0; i < size; i++) { if (isSameF(switchTimes[i], angle)) return i; @@ -84,8 +84,7 @@ int multi_wave_s::findAngleMatch(float angle, int size) const { return EFI_ERROR_CODE; } -void multi_wave_s::setSwitchTime(int index, float value) { +void MultiWave::setSwitchTime(int index, float value) { efiAssertVoid(CUSTOM_ERR_6690, switchTimes != NULL, "switchTimes"); switchTimes[index] = value; } - diff --git a/firmware/controllers/core/EfiWave.h b/firmware/controllers/core/EfiWave.h index d22e5f59d6..9b5c72df1a 100644 --- a/firmware/controllers/core/EfiWave.h +++ b/firmware/controllers/core/EfiWave.h @@ -34,11 +34,11 @@ public: class TriggerShape; -class multi_wave_s { +class MultiWave { public: void baseConstructor(); - multi_wave_s(); - multi_wave_s(float *st, single_wave_s *waves); + MultiWave(); + MultiWave(float *st, single_wave_s *waves); void init(float *st, single_wave_s *waves); void reset(void); float getSwitchTime(int phaseIndex) const; @@ -62,6 +62,4 @@ public: float *switchTimes; }; -void checkSwitchTimes2(int size, float *switchTimes); - #endif /* EFI_WAVE_H_ */ diff --git a/firmware/controllers/system/pwm_generator_logic.cpp b/firmware/controllers/system/pwm_generator_logic.cpp index ead8444fc8..fb643be35b 100644 --- a/firmware/controllers/system/pwm_generator_logic.cpp +++ b/firmware/controllers/system/pwm_generator_logic.cpp @@ -199,6 +199,7 @@ void copyPwmParameters(PwmConfig *state, int phaseCount, float *switchTimes, int state->multiWave.waves[waveIndex].pinStates[phaseIndex] = pinStates[waveIndex][phaseIndex]; } } + state->multiWave.checkSwitchTimes(phaseCount); } /** @@ -218,7 +219,6 @@ void PwmConfig::weComplexInit(const char *msg, int phaseCount, float *switchTime return; } efiAssertVoid(CUSTOM_ERR_6583, waveCount > 0, "waveCount should be positive"); - checkSwitchTimes2(phaseCount, switchTimes); this->pwmCycleCallback = pwmCycleCallback; this->stateChangeCallback = stateChangeCallback; diff --git a/firmware/controllers/system/pwm_generator_logic.h b/firmware/controllers/system/pwm_generator_logic.h index 344670e064..bb54cf2975 100644 --- a/firmware/controllers/system/pwm_generator_logic.h +++ b/firmware/controllers/system/pwm_generator_logic.h @@ -59,7 +59,7 @@ public: OutputPin *outputPins[PWM_PHASE_MAX_WAVE_PER_PWM]; - multi_wave_s multiWave; + MultiWave multiWave; efitimeus_t togglePwmState(); int dbgNestingLevel; diff --git a/firmware/controllers/trigger/trigger_structure.cpp b/firmware/controllers/trigger/trigger_structure.cpp index 1e9fc89c76..e976e410eb 100644 --- a/firmware/controllers/trigger/trigger_structure.cpp +++ b/firmware/controllers/trigger/trigger_structure.cpp @@ -397,10 +397,6 @@ angle_t TriggerShape::getSwitchAngle(int index) const { return getCycleDuration() * wave.getSwitchTime(index); } -void multi_wave_s::checkSwitchTimes(int size) { - checkSwitchTimes2(size, switchTimes); -} - void setToothedWheelConfiguration(TriggerShape *s, int total, int skipped, operation_mode_e operationMode DECLARE_ENGINE_PARAMETER_SUFFIX) { #if EFI_ENGINE_CONTROL || defined(__DOXYGEN__) diff --git a/firmware/controllers/trigger/trigger_structure.h b/firmware/controllers/trigger/trigger_structure.h index 61858b93e4..119b323ecd 100644 --- a/firmware/controllers/trigger/trigger_structure.h +++ b/firmware/controllers/trigger/trigger_structure.h @@ -147,7 +147,7 @@ public: int triggerSignals[PWM_PHASE_MAX_COUNT]; #endif - multi_wave_s wave; + MultiWave wave; // todo: add a runtime validation which would verify that this field was set properly // tood: maybe even automate this flag calculation?