speeduino
speeduino copied to clipboard
Deduplicate ignition scheduler code
- Refactor IgnitionSchedule1-8 variables into IgnitionSchedule[] array.
- Add compare, counter, timerEnable, timerDisable, startAngle, endAngle, degreesAfterTDC1 (previously channelXIgnDegrees) and channel to Schedule struct.
- The changes to the Schedule struct has the benefit of deduplicating multiple functions/code segments:
-
- refreshIgnitionTiming
-
- setIgnitionSchedule
-
- ignitionScheduleInterrupt
-
- checkIgnitionSchedule
-
- calculateIgnitionAngle
This is a direct continuation of #648 and that pull request is used as base. It is also related to #578.
This change more or less only refactors code. The logic changes are that the scheduler callbacks are only set once in initialiseAll and a small optimization into calculateIgnitionAngleWithSpecificEndAngle for rotary.
ignitionSchedule[i].member calls seem to be slowed than ignitionSchedule->member calls. This is why most functions pass a pointer to the array member rather than the number of the ignition channel.
Tested on mega2560. Loops/sec reduced by 0,5% (from Tunerstudio). Size reduced by 1,8% and memory by 0,72% (PlatformIO compile info). I've done some basic testing on the bench and the ignition events appear to happen at the correct time (scope tested).
There are other areas where code can be deduplicated as a continuation of this change.
Fixed the decoder and scheduler tests. Both are successful.