2015-07-10 06:01:56 -07:00
|
|
|
/**
|
|
|
|
* @file trigger_emulator.cpp
|
|
|
|
* @brief Position sensor(s) emulation code
|
|
|
|
*
|
|
|
|
* This file is mostly about initialization, the configuration is
|
|
|
|
* provided by the configureShaftPositionEmulatorShape method
|
|
|
|
*
|
|
|
|
* @date Dec 9, 2012
|
2018-01-20 17:55:31 -08:00
|
|
|
* @author Andrey Belomutskiy, (c) 2012-2018
|
2015-07-10 06:01:56 -07:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "trigger_emulator.h"
|
|
|
|
#include "eficonsole.h"
|
|
|
|
#include "main_trigger_callback.h"
|
|
|
|
#include "io_pins.h"
|
|
|
|
#include "trigger_emulator_algo.h"
|
|
|
|
#include "trigger_central.h"
|
|
|
|
#include "settings.h"
|
|
|
|
|
2017-12-03 12:31:11 -08:00
|
|
|
#if EFI_PROD_CODE || defined(__DOXYGEN__)
|
|
|
|
#include "pwm_generator.h"
|
|
|
|
#include "pin_repository.h"
|
|
|
|
#endif /* EFI_PROD_CODE */
|
|
|
|
|
2015-07-10 06:01:56 -07:00
|
|
|
extern PwmConfig triggerSignal;
|
|
|
|
|
|
|
|
static OutputPin emulatorOutputs[3];
|
|
|
|
|
2017-04-21 11:03:08 -07:00
|
|
|
EXTERN_ENGINE;
|
|
|
|
|
2017-12-17 12:41:58 -08:00
|
|
|
void onConfigurationChangeRpmEmulatorCallback(engine_configuration_s *previousConfiguration) {
|
|
|
|
if (engineConfiguration->bc.triggerSimulatorFrequency ==
|
|
|
|
previousConfiguration->bc.triggerSimulatorFrequency) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
setTriggerEmulatorRPM(engineConfiguration->bc.triggerSimulatorFrequency);
|
|
|
|
}
|
|
|
|
|
2017-05-15 20:33:22 -07:00
|
|
|
void initTriggerEmulator(Logging *sharedLogger DECLARE_ENGINE_PARAMETER_SUFFIX) {
|
2015-07-10 06:01:56 -07:00
|
|
|
|
|
|
|
|
|
|
|
#if EFI_EMULATE_POSITION_SENSORS || defined(__DOXYGEN__)
|
|
|
|
print("Emulating %s\r\n", getConfigurationName(engineConfiguration->engineType));
|
|
|
|
|
|
|
|
triggerSignal.outputPins[0] = &emulatorOutputs[0];
|
|
|
|
triggerSignal.outputPins[1] = &emulatorOutputs[1];
|
|
|
|
triggerSignal.outputPins[2] = &emulatorOutputs[2];
|
|
|
|
|
2017-12-03 12:31:11 -08:00
|
|
|
#if EFI_PROD_CODE || defined(__DOXYGEN__)
|
2015-07-10 06:01:56 -07:00
|
|
|
// todo: refactor, make this a loop
|
2017-04-21 15:11:36 -07:00
|
|
|
triggerSignal.outputPins[0]->initPin("trg emulator ch1", boardConfiguration->triggerSimulatorPins[0],
|
2015-07-10 06:01:56 -07:00
|
|
|
&boardConfiguration->triggerSimulatorPinModes[0]);
|
|
|
|
|
2017-04-21 15:11:36 -07:00
|
|
|
triggerSignal.outputPins[1]->initPin("trg emulator ch2", boardConfiguration->triggerSimulatorPins[1],
|
2015-07-10 06:01:56 -07:00
|
|
|
&boardConfiguration->triggerSimulatorPinModes[1]);
|
|
|
|
|
2017-04-21 15:11:36 -07:00
|
|
|
triggerSignal.outputPins[2]->initPin("trg emulator ch3", boardConfiguration->triggerSimulatorPins[2],
|
2015-07-10 06:01:56 -07:00
|
|
|
&boardConfiguration->triggerSimulatorPinModes[2]);
|
|
|
|
#endif /* EFI_PROD_CODE */
|
|
|
|
|
2017-05-15 05:51:40 -07:00
|
|
|
initTriggerEmulatorLogic(sharedLogger);
|
2015-07-10 06:01:56 -07:00
|
|
|
#else
|
|
|
|
print("No position sensor(s) emulation\r\n");
|
|
|
|
#endif /* EFI_EMULATE_POSITION_SENSORS */
|
|
|
|
}
|