From a294dfeadd6bae8afe2372a6b7056dd3cab4e9ac Mon Sep 17 00:00:00 2001 From: Matthew Kennedy Date: Sat, 16 Jan 2021 18:22:30 -0800 Subject: [PATCH] save 1440 bytes (#2226) --- .../trigger/decoders/trigger_structure.cpp | 14 ++++++++------ .../trigger/decoders/trigger_structure.h | 4 ++-- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/firmware/controllers/trigger/decoders/trigger_structure.cpp b/firmware/controllers/trigger/decoders/trigger_structure.cpp index 1e78814811..67517ed250 100644 --- a/firmware/controllers/trigger/decoders/trigger_structure.cpp +++ b/firmware/controllers/trigger/decoders/trigger_structure.cpp @@ -361,10 +361,10 @@ void TriggerWaveform::setTriggerSynchronizationGap3(int gapIndex, float syncRati /** * this method is only used on initialization */ -int TriggerWaveform::findAngleIndex(TriggerFormDetails *details, float target) const { - int engineCycleEventCount = getLength(); +uint16_t TriggerWaveform::findAngleIndex(TriggerFormDetails *details, float target) const { + size_t engineCycleEventCount = getLength(); - efiAssert(CUSTOM_ERR_ASSERT, engineCycleEventCount > 0, "engineCycleEventCount", 0); + efiAssert(CUSTOM_ERR_ASSERT, engineCycleEventCount <= 0xFFFF, "engineCycleEventCount", 0); uint32_t left = 0; uint32_t right = engineCycleEventCount - 1; @@ -433,11 +433,13 @@ void TriggerWaveform::prepareShape(TriggerFormDetails *details DECLARE_ENGINE_PA int engineCycleInt = (int) getEngineCycle(operationMode); for (int angle = 0; angle < engineCycleInt; angle++) { - int triggerShapeIndex = findAngleIndex(details, angle); + uint16_t triggerShapeIndex = findAngleIndex(details, angle); + if (useOnlyRisingEdgeForTriggerTemp) { - // we need even index for front_only mode - so if odd indexes are rounded down - triggerShapeIndex = triggerShapeIndex & 0xFFFFFFFE; + // we need even index for front_only mode - so if odd indexes are rounded down by clearing the low bit + triggerShapeIndex &= 0xFFFE; } + details->triggerIndexByAngle[angle] = triggerShapeIndex; } #endif diff --git a/firmware/controllers/trigger/decoders/trigger_structure.h b/firmware/controllers/trigger/decoders/trigger_structure.h index 947ce13697..5e59ae30bf 100644 --- a/firmware/controllers/trigger/decoders/trigger_structure.h +++ b/firmware/controllers/trigger/decoders/trigger_structure.h @@ -275,7 +275,7 @@ public: private: trigger_shape_helper h; - int findAngleIndex(TriggerFormDetails *details, float angle) const; + uint16_t findAngleIndex(TriggerFormDetails *details, float angle) const; /** * Working buffer for 'wave' instance @@ -313,7 +313,7 @@ public: * this cache allows us to find a close-enough (with one degree precision) trigger wheel index by * given angle with fast constant speed. That's a performance optimization for event scheduling. */ - int triggerIndexByAngle[720]; + uint16_t triggerIndexByAngle[720]; }; void findTriggerPosition(