diff --git a/firmware/controllers/alternatorController.cpp b/firmware/controllers/alternatorController.cpp index f4d4449bfb..7068c94366 100644 --- a/firmware/controllers/alternatorController.cpp +++ b/firmware/controllers/alternatorController.cpp @@ -128,7 +128,7 @@ static void applyAlternatorPinState(PwmConfig *state, int stateIndex) { efiAssertVoid(CUSTOM_ERR_6643, stateIndex < PWM_PHASE_MAX_COUNT, "invalid stateIndex"); efiAssertVoid(CUSTOM_IDLE_WAVE_CNT, state->multiWave.waveCount == 1, "invalid idle waveCount"); OutputPin *output = state->outputPins[0]; - int value = state->multiWave.waves[0].pinStates[stateIndex]; + int value = state->multiWave.waves[0].getState(stateIndex); /** * 'engine->isAlternatorControlEnabled' would be false is RPM is too low */ diff --git a/firmware/controllers/core/EfiWave.cpp b/firmware/controllers/core/EfiWave.cpp index 77ea24a186..688d27f57b 100644 --- a/firmware/controllers/core/EfiWave.cpp +++ b/firmware/controllers/core/EfiWave.cpp @@ -21,6 +21,14 @@ void single_wave_s::init(pin_state_t *pinStates) { this->pinStates = pinStates; } +int single_wave_s::getState(int index) { + return pinStates[index]; +} + +void single_wave_s::setState(int index, int state) { + pinStates[index] = state; +} + void MultiWave::baseConstructor() { waves = NULL; switchTimes = NULL; diff --git a/firmware/controllers/core/EfiWave.h b/firmware/controllers/core/EfiWave.h index 9b5c72df1a..fd98ee43ee 100644 --- a/firmware/controllers/core/EfiWave.h +++ b/firmware/controllers/core/EfiWave.h @@ -7,7 +7,7 @@ #ifndef EFI_WAVE_H_ #define EFI_WAVE_H_ -#include "engine_configuration.h" +#include "global.h" #define PWM_PHASE_MAX_COUNT 252 #define PWM_PHASE_MAX_WAVE_PER_PWM 3 @@ -22,6 +22,12 @@ typedef int8_t pin_state_t; /** + * This class represents one channel of a digital signal state sequence + * Each element represents either a HIGH or LOW state - while at the moment this + * is not implemented using a bit array, it could absolutely be a bit array + * + * This sequence does not know anything about signal lengths - only signal state at a given index + * * @brief PWM configuration for the specific output pin */ class single_wave_s { @@ -29,11 +35,17 @@ public: single_wave_s(); single_wave_s(pin_state_t *pinStates); void init(pin_state_t *pinStates); + /** + * todo: confirm that we only deal with two states here, no magic '-1'? + * @return HIGH or LOW state at given index + */ + int getState(int index); + void setState(int index, int state); + + // todo: make this private pin_state_t *pinStates; }; -class TriggerShape; - class MultiWave { public: void baseConstructor(); diff --git a/firmware/controllers/trigger/trigger_structure.cpp b/firmware/controllers/trigger/trigger_structure.cpp index e976e410eb..7cdb757ba8 100644 --- a/firmware/controllers/trigger/trigger_structure.cpp +++ b/firmware/controllers/trigger/trigger_structure.cpp @@ -352,7 +352,7 @@ void TriggerShape::addEvent2(angle_t angle, trigger_wheel_e const waveIndex, tri isFrontEvent[0] = TV_RISE == stateParam; wave.setSwitchTime(0, angle); - wave.waves[waveIndex].pinStates[0] = state; + wave.waves[waveIndex].setState(0, state); return; } @@ -390,7 +390,7 @@ void TriggerShape::addEvent2(angle_t angle, trigger_wheel_e const waveIndex, tri wave.waves[i].pinStates[index] = wave.getChannelState(i, index - 1); } wave.setSwitchTime(index, angle); - wave.waves[waveIndex].pinStates[index] = state; + wave.waves[waveIndex].setState(index, state); } angle_t TriggerShape::getSwitchAngle(int index) const { diff --git a/firmware/controllers/trigger/trigger_structure.h b/firmware/controllers/trigger/trigger_structure.h index 119b323ecd..8caf8cbb20 100644 --- a/firmware/controllers/trigger/trigger_structure.h +++ b/firmware/controllers/trigger/trigger_structure.h @@ -10,7 +10,6 @@ #include "global.h" -#include "rusefi_enums.h" #include "EfiWave.h" #include "engine_configuration.h"