2015-08-18 12:03:44 -07:00
|
|
|
/*
|
|
|
|
* @file tachometer.cpp
|
2015-08-18 14:01:49 -07:00
|
|
|
* @brief This is about driving external analog tachometers
|
2015-08-18 12:03:44 -07:00
|
|
|
*
|
2016-08-16 19:05:36 -07:00
|
|
|
* This implementation produces one pulse per engine cycle
|
|
|
|
*
|
2016-05-24 19:02:13 -07:00
|
|
|
* todo: these is a bit of duplication with dizzySparkOutputPin
|
|
|
|
*
|
2015-08-18 12:03:44 -07:00
|
|
|
* @date Aug 18, 2015
|
2020-01-13 18:57:43 -08:00
|
|
|
* @author Andrey Belomutskiy, (c) 2012-2020
|
2015-08-18 12:03:44 -07:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "tachometer.h"
|
2015-08-18 14:01:49 -07:00
|
|
|
#include "trigger_central.h"
|
2015-08-18 12:03:44 -07:00
|
|
|
|
2019-04-09 19:52:03 -07:00
|
|
|
|
2015-08-18 12:03:44 -07:00
|
|
|
EXTERN_ENGINE;
|
|
|
|
|
2015-08-19 13:01:36 -07:00
|
|
|
static scheduling_s tachTurnSignalOff;
|
|
|
|
|
2020-01-06 21:41:18 -08:00
|
|
|
static void turnTachPinLow(void *) {
|
2017-04-21 16:23:20 -07:00
|
|
|
enginePins.tachOut.setLow();
|
2015-08-19 13:01:36 -07:00
|
|
|
}
|
2015-08-18 14:01:49 -07:00
|
|
|
|
|
|
|
static void tachSignalCallback(trigger_event_e ckpSignalType,
|
2020-01-09 12:45:13 -08:00
|
|
|
uint32_t index, efitick_t edgeTimestamp DECLARE_ENGINE_PARAMETER_SUFFIX) {
|
2019-11-05 17:07:55 -08:00
|
|
|
UNUSED(ckpSignalType);
|
|
|
|
if (index != (uint32_t)engineConfiguration->tachPulseTriggerIndex) {
|
2015-08-18 21:03:11 -07:00
|
|
|
return;
|
|
|
|
}
|
2017-04-21 16:23:20 -07:00
|
|
|
enginePins.tachOut.setHigh();
|
2017-08-28 18:00:36 -07:00
|
|
|
float durationMs;
|
|
|
|
if (engineConfiguration->tachPulseDurationAsDutyCycle) {
|
|
|
|
// todo: implement tachPulseDurationAsDutyCycle
|
|
|
|
durationMs = engineConfiguration->tachPulseDuractionMs;
|
|
|
|
} else {
|
|
|
|
durationMs = engineConfiguration->tachPulseDuractionMs;
|
|
|
|
}
|
2020-01-06 21:41:18 -08:00
|
|
|
engine->executor.scheduleForLater(&tachTurnSignalOff, (int)MS2US(durationMs), &turnTachPinLow);
|
2015-08-18 14:01:49 -07:00
|
|
|
}
|
|
|
|
|
2020-04-01 16:00:56 -07:00
|
|
|
void initTachometer(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
|
2019-12-11 14:48:55 -08:00
|
|
|
if (CONFIG(tachOutputPin) == GPIO_UNASSIGNED) {
|
2015-08-18 12:03:44 -07:00
|
|
|
return;
|
2015-08-18 21:03:11 -07:00
|
|
|
}
|
2015-08-18 12:03:44 -07:00
|
|
|
|
2020-03-29 16:07:07 -07:00
|
|
|
enginePins.tachOut.initPin("Tachometer", CONFIG(tachOutputPin), &CONFIG(tachOutputPinMode));
|
2015-08-18 14:01:49 -07:00
|
|
|
|
2019-04-12 19:07:03 -07:00
|
|
|
#if EFI_SHAFT_POSITION_INPUT
|
2015-08-18 14:01:49 -07:00
|
|
|
addTriggerEventListener(tachSignalCallback, "tach", engine);
|
2019-01-31 08:57:15 -08:00
|
|
|
#endif /* EFI_SHAFT_POSITION_INPUT */
|
2015-08-18 12:03:44 -07:00
|
|
|
}
|
2019-04-09 19:52:03 -07:00
|
|
|
|
2020-04-01 16:12:34 -07:00
|
|
|
|