diff --git a/firmware/controllers/core/state_sequence.h b/firmware/controllers/core/state_sequence.h index 685a95f479..d78a0ba77a 100644 --- a/firmware/controllers/core/state_sequence.h +++ b/firmware/controllers/core/state_sequence.h @@ -40,8 +40,6 @@ typedef enum { #endif /* PWM_PHASE_MAX_COUNT */ #define PWM_PHASE_MAX_WAVE_PER_PWM 2 -typedef TriggerValue pin_state_t; - /** * This class represents multi-channel logical signals with shared time axis * @@ -56,7 +54,7 @@ public: * that would give us a 70% duty cycle PWM */ virtual float getSwitchTime(int phaseIndex) const = 0; - virtual pin_state_t getChannelState(int channelIndex, int phaseIndex) const = 0; + virtual bool getChannelState(int channelIndex, int phaseIndex) const = 0; // Make sure the switch times are in order and end at the very end. void checkSwitchTimes(float scale) const; @@ -78,12 +76,12 @@ public: return switchTimes[phaseIndex]; } - pin_state_t getChannelState(int channelIndex, int phaseIndex) const override { + bool getChannelState(int channelIndex, int phaseIndex) const override { if (channelIndex >= waveCount) { // todo: would be nice to get this asserting working //firmwareError(OBD_PCM_Processor_Fault, "channel index %d/%d", channelIndex, waveCount); } - return ((waveForm[phaseIndex] >> channelIndex) & 1) ? TriggerValue::RISE : TriggerValue::FALL; + return (waveForm[phaseIndex] >> channelIndex) & 1; } void reset() { @@ -94,13 +92,13 @@ public: switchTimes[phaseIndex] = value; } - void setChannelState(const int channelIndex, const int phaseIndex, pin_state_t state) { + void setChannelState(const int channelIndex, const int phaseIndex, bool state) { if (channelIndex >= waveCount) { // todo: would be nice to get this asserting working //firmwareError(OBD_PCM_Processor_Fault, "channel index %d/%d", channelIndex, waveCount); } uint8_t & ref = waveForm[phaseIndex]; - ref = (ref & ~(1U << channelIndex)) | ((state == TriggerValue::RISE ? 1 : 0) << channelIndex); + ref = (ref & ~(1U << channelIndex)) | ((state ? 1 : 0) << channelIndex); } private: diff --git a/firmware/controllers/system/timer/pwm_generator_logic.cpp b/firmware/controllers/system/timer/pwm_generator_logic.cpp index f1292f470b..2ac4b650ba 100644 --- a/firmware/controllers/system/timer/pwm_generator_logic.cpp +++ b/firmware/controllers/system/timer/pwm_generator_logic.cpp @@ -323,8 +323,8 @@ void startSimplePwm(SimplePwm *state, const char *msg, ExecutorInterface *execut state->seq.setSwitchTime(0, dutyCycle); state->seq.setSwitchTime(1, 1); - state->seq.setChannelState(0, 0, TriggerValue::FALL); - state->seq.setChannelState(0, 1, TriggerValue::RISE); + state->seq.setChannelState(0, 0, false); + state->seq.setChannelState(0, 1, true); state->outputPins[0] = output; @@ -383,7 +383,7 @@ void applyPinState(int stateIndex, PwmConfig *state) /* pwm_gen_callback */ { efiAssertVoid(CUSTOM_ERR_6664, state->multiChannelStateSequence->waveCount <= PWM_PHASE_MAX_WAVE_PER_PWM, "invalid waveCount"); for (int channelIndex = 0; channelIndex < state->multiChannelStateSequence->waveCount; channelIndex++) { OutputPin *output = state->outputPins[channelIndex]; - TriggerValue value = state->multiChannelStateSequence->getChannelState(channelIndex, stateIndex); - output->setValue(value == TriggerValue::RISE); + bool value = state->multiChannelStateSequence->getChannelState(channelIndex, stateIndex); + output->setValue(value); } } diff --git a/firmware/controllers/trigger/decoders/trigger_structure.cpp b/firmware/controllers/trigger/decoders/trigger_structure.cpp index a6b5c685e2..95438634f0 100644 --- a/firmware/controllers/trigger/decoders/trigger_structure.cpp +++ b/firmware/controllers/trigger/decoders/trigger_structure.cpp @@ -230,7 +230,10 @@ void TriggerWaveform::addEventAngle(angle_t angle, TriggerValue const state, Tri addEvent(angle / getCycleDuration(), state, channelIndex); } -void TriggerWaveform::addEvent(angle_t angle, TriggerValue const state, TriggerWheel const channelIndex) { +void TriggerWaveform::addEvent(angle_t angle, TriggerValue const stateTv, TriggerWheel const channelIndex) { + // TODO: #55 + bool state = stateTv == TriggerValue::RISE; + efiAssertVoid(CUSTOM_OMODE_UNDEF, operationMode != OM_NONE, "operationMode not set"); if (channelIndex == TriggerWheel:: T_SECONDARY) { @@ -246,14 +249,14 @@ void TriggerWaveform::addEvent(angle_t angle, TriggerValue const state, TriggerW #if EFI_UNIT_TEST assertIsInBounds(wave.phaseCount, triggerSignalIndeces, "trigger shape overflow"); triggerSignalIndeces[wave.phaseCount] = channelIndex; - triggerSignalStates[wave.phaseCount] = state; + triggerSignalStates[wave.phaseCount] = state ? TriggerValue::RISE : TriggerValue::FALL; #endif // EFI_UNIT_TEST // todo: the whole 'useOnlyRisingEdgeForTrigger' parameter and logic should not be here // todo: see calculateExpectedEventCounts // related calculation should be done once trigger is initialized outside of trigger shape scope - if (!useOnlyRisingEdges || state == TriggerValue::RISE) { + if (!useOnlyRisingEdges || state) { expectedEventCount[(int)channelIndex]++; } @@ -275,10 +278,10 @@ void TriggerWaveform::addEvent(angle_t angle, TriggerValue const state, TriggerW if (wave.phaseCount == 0) { wave.phaseCount = 1; for (int i = 0; i < PWM_PHASE_MAX_WAVE_PER_PWM; i++) { - wave.setChannelState(i, /* switchIndex */ 0, /* value */ initialState[i]); + wave.setChannelState(i, /* switchIndex */ 0, /* value */ initialState[i] == TriggerValue::RISE); } - isRiseEvent[0] = TriggerValue::RISE == state; + isRiseEvent[0] = state; wave.setSwitchTime(0, angle); wave.setChannelState((int)channelIndex, /* channelIndex */ 0, /* value */ state); return; @@ -305,7 +308,7 @@ void TriggerWaveform::addEvent(angle_t angle, TriggerValue const state, TriggerW wave.setSwitchTime(i + 1, wave.getSwitchTime(i)); } */ - isRiseEvent[index] = TriggerValue::RISE == state; + isRiseEvent[index] = state; if ((unsigned)index != wave.phaseCount) { firmwareError(ERROR_TRIGGER_DRAMA, "are we ever here?"); @@ -314,7 +317,7 @@ void TriggerWaveform::addEvent(angle_t angle, TriggerValue const state, TriggerW wave.phaseCount++; for (int i = 0; i < PWM_PHASE_MAX_WAVE_PER_PWM; i++) { - pin_state_t value = wave.getChannelState(/* channelIndex */i, index - 1); + bool value = wave.getChannelState(/* channelIndex */i, index - 1); wave.setChannelState(i, index, value); } wave.setSwitchTime(index, angle); diff --git a/firmware/controllers/trigger/decoders/trigger_structure.h b/firmware/controllers/trigger/decoders/trigger_structure.h index 8ad35c3f01..b7b424fa99 100644 --- a/firmware/controllers/trigger/decoders/trigger_structure.h +++ b/firmware/controllers/trigger/decoders/trigger_structure.h @@ -166,7 +166,7 @@ public: // todo: add a runtime validation which would verify that this field was set properly // todo: maybe even automate this flag calculation? - pin_state_t initialState[PWM_PHASE_MAX_WAVE_PER_PWM]; + TriggerValue initialState[PWM_PHASE_MAX_WAVE_PER_PWM]; bool isRiseEvent[PWM_PHASE_MAX_COUNT]; diff --git a/firmware/controllers/trigger/trigger_emulator_algo.cpp b/firmware/controllers/trigger/trigger_emulator_algo.cpp index f78e0b2098..7b30738600 100644 --- a/firmware/controllers/trigger/trigger_emulator_algo.cpp +++ b/firmware/controllers/trigger/trigger_emulator_algo.cpp @@ -22,8 +22,8 @@ int getPreviousIndex(const int currentIndex, const int size) { bool needEvent(const int currentIndex, const MultiChannelStateSequence & mcss, int channelIndex) { int prevIndex = getPreviousIndex(currentIndex, mcss.phaseCount); - pin_state_t previousValue = mcss.getChannelState(channelIndex, /*phaseIndex*/prevIndex); - pin_state_t currentValue = mcss.getChannelState(channelIndex, /*phaseIndex*/currentIndex); + bool previousValue = mcss.getChannelState(channelIndex, /*phaseIndex*/prevIndex); + bool currentValue = mcss.getChannelState(channelIndex, /*phaseIndex*/currentIndex); return previousValue != currentValue; } @@ -46,7 +46,7 @@ void TriggerEmulatorHelper::handleEmulatorCallback(const MultiChannelStateSequen #if EFI_SHAFT_POSITION_INPUT for (size_t i = 0; i < PWM_PHASE_MAX_WAVE_PER_PWM; i++) { if (needEvent(stateIndex, multiChannelStateSequence, i)) { - bool isRise = TriggerValue::RISE == multiChannelStateSequence.getChannelState(/*phaseIndex*/i, stateIndex); + bool isRise = multiChannelStateSequence.getChannelState(/*phaseIndex*/i, stateIndex); isRise ^= (i == 0 && engineConfiguration->invertPrimaryTriggerSignal); isRise ^= (i == 1 && engineConfiguration->invertSecondaryTriggerSignal); diff --git a/firmware/controllers/trigger/trigger_simulator.cpp b/firmware/controllers/trigger/trigger_simulator.cpp index 4806e9035c..ec3036b2cd 100644 --- a/firmware/controllers/trigger/trigger_simulator.cpp +++ b/firmware/controllers/trigger/trigger_simulator.cpp @@ -52,14 +52,11 @@ void TriggerStimulatorHelper::feedSimulatedEvent( #if EFI_UNIT_TEST int prevIndex = getPreviousIndex(stateIndex, shape.getSize()); - pin_state_t primaryWheelState = multiChannelStateSequence.getChannelState(0, prevIndex); - pin_state_t newPrimaryWheelState = multiChannelStateSequence.getChannelState(0, stateIndex); + bool primaryWheelState = multiChannelStateSequence.getChannelState(0, prevIndex); + bool newPrimaryWheelState = multiChannelStateSequence.getChannelState(0, stateIndex); - pin_state_t secondaryWheelState = multiChannelStateSequence.getChannelState(1, prevIndex); - pin_state_t newSecondaryWheelState = multiChannelStateSequence.getChannelState(1, stateIndex); - -// pin_state_t thirdWheelState = multiChannelStateSequence->getChannelState(2, prevIndex); -// pin_state_t new3rdWheelState = multiChannelStateSequence->getChannelState(2, stateIndex); + bool secondaryWheelState = multiChannelStateSequence.getChannelState(1, prevIndex); + bool newSecondaryWheelState = multiChannelStateSequence.getChannelState(1, stateIndex); if (printTriggerDebug) { printf("TriggerStimulator: simulatedEvent: %d>%d primary %d>%d secondary %d>%d\r\n", prevIndex, stateIndex, primaryWheelState, newPrimaryWheelState, @@ -75,8 +72,8 @@ void TriggerStimulatorHelper::feedSimulatedEvent( for (size_t i = 0; i < PWM_PHASE_MAX_WAVE_PER_PWM; i++) { if (needEvent(stateIndex, multiChannelStateSequence, i)) { - pin_state_t currentValue = multiChannelStateSequence.getChannelState(/*phaseIndex*/i, stateIndex); - trigger_event_e event = (currentValue == TriggerValue::RISE ? riseEvents : fallEvents)[i]; + bool currentValue = multiChannelStateSequence.getChannelState(/*phaseIndex*/i, stateIndex); + trigger_event_e event = (currentValue ? riseEvents : fallEvents)[i]; if (isUsefulSignal(event, shape)) { state.decodeTriggerEvent( "sim", diff --git a/unit_tests/tests/ignition_injection/test_fuel_map.cpp b/unit_tests/tests/ignition_injection/test_fuel_map.cpp index afef6309ad..de0c638e2d 100644 --- a/unit_tests/tests/ignition_injection/test_fuel_map.cpp +++ b/unit_tests/tests/ignition_injection/test_fuel_map.cpp @@ -100,21 +100,21 @@ static void configureFordAspireTriggerWaveform(TriggerWaveform * s) { s->addEvent720(720, TriggerValue::FALL, TriggerWheel::T_PRIMARY); ASSERT_FLOAT_EQ(53.747 / 720, s->wave.getSwitchTime(0)); - ASSERT_EQ( TriggerValue::RISE, s->wave.getChannelState(1, 0)) << "@0"; - ASSERT_EQ( TriggerValue::RISE, s->wave.getChannelState(1, 0)) << "@0"; + ASSERT_EQ(true, s->wave.getChannelState(1, 0)) << "@0"; + ASSERT_EQ(true, s->wave.getChannelState(1, 0)) << "@0"; - ASSERT_EQ( TriggerValue::FALL, s->wave.getChannelState(0, 1)) << "@1"; - ASSERT_EQ( TriggerValue::FALL, s->wave.getChannelState(1, 1)) << "@1"; + ASSERT_EQ(false, s->wave.getChannelState(0, 1)) << "@1"; + ASSERT_EQ(false, s->wave.getChannelState(1, 1)) << "@1"; - ASSERT_EQ( TriggerValue::FALL, s->wave.getChannelState(0, 2)) << "@2"; - ASSERT_EQ( TriggerValue::RISE, s->wave.getChannelState(1, 2)) << "@2"; + ASSERT_EQ(false, s->wave.getChannelState(0, 2)) << "@2"; + ASSERT_EQ(true, s->wave.getChannelState(1, 2)) << "@2"; - ASSERT_EQ( TriggerValue::FALL, s->wave.getChannelState(0, 3)) << "@3"; - ASSERT_EQ( TriggerValue::FALL, s->wave.getChannelState(1, 3)) << "@3"; + ASSERT_EQ(false, s->wave.getChannelState(0, 3)) << "@3"; + ASSERT_EQ(false, s->wave.getChannelState(1, 3)) << "@3"; - ASSERT_EQ( TriggerValue::RISE, s->wave.getChannelState(0, 4)) << "@4"; - ASSERT_EQ( TriggerValue::RISE, s->wave.getChannelState(1, 5)) << "@5"; - ASSERT_EQ( TriggerValue::FALL, s->wave.getChannelState(1, 8)) << "@8"; + ASSERT_EQ(true, s->wave.getChannelState(0, 4)) << "@4"; + ASSERT_EQ(true, s->wave.getChannelState(1, 5)) << "@5"; + ASSERT_EQ(false, s->wave.getChannelState(1, 8)) << "@8"; ASSERT_FLOAT_EQ(121.90 / 720, s->wave.getSwitchTime(1)); ASSERT_FLOAT_EQ(657.03 / 720, s->wave.getSwitchTime(8)); diff --git a/unit_tests/tests/trigger/test_nissan_vq_vvt.cpp b/unit_tests/tests/trigger/test_nissan_vq_vvt.cpp index fd5a3cbc82..b31931301c 100644 --- a/unit_tests/tests/trigger/test_nissan_vq_vvt.cpp +++ b/unit_tests/tests/trigger/test_nissan_vq_vvt.cpp @@ -23,8 +23,8 @@ static void func(TriggerCallback *callback) { int formIndex = callback->toothIndex % callback->form->getSize(); Engine *engine = callback->engine; + bool value = callback->form->wave.getChannelState(0, formIndex); - bool value = callback->form->wave.getChannelState(0, formIndex) == TriggerValue::RISE; efitick_t nowNt = getTimeNowNt(); if (callback->isVvt) { hwHandleVvtCamSignal(value, nowNt, callback->vvtBankIndex * CAMS_PER_BANK);