support multiple VVT sensors #885
This commit is contained in:
parent
04bc1128df
commit
1282a22134
|
@ -647,7 +647,13 @@ static void resetRunningTriggerCounters() {
|
|||
#define COMPARE_CONFIG_PARAMS(param) (engineConfiguration->param != previousConfiguration->param)
|
||||
|
||||
void onConfigurationChangeTriggerCallback(engine_configuration_s *previousConfiguration DECLARE_ENGINE_PARAMETER_SUFFIX) {
|
||||
bool changed = COMPARE_CONFIG_PARAMS(trigger.type) ||
|
||||
bool changed = false;
|
||||
for (int i = 0; i < CAM_INPUTS_COUNT; i++) {
|
||||
changed |= COMPARE_CONFIG_PARAMS(camInputs[i]);
|
||||
}
|
||||
|
||||
changed |=
|
||||
COMPARE_CONFIG_PARAMS(trigger.type) ||
|
||||
COMPARE_CONFIG_PARAMS(operationMode) ||
|
||||
COMPARE_CONFIG_PARAMS(useOnlyRisingEdgeForTrigger) ||
|
||||
COMPARE_CONFIG_PARAMS(globalTriggerAngleOffset) ||
|
||||
|
@ -656,7 +662,6 @@ void onConfigurationChangeTriggerCallback(engine_configuration_s *previousConfig
|
|||
COMPARE_CONFIG_PARAMS(bc.triggerInputPins[0]) ||
|
||||
COMPARE_CONFIG_PARAMS(bc.triggerInputPins[1]) ||
|
||||
COMPARE_CONFIG_PARAMS(bc.triggerInputPins[2]) ||
|
||||
COMPARE_CONFIG_PARAMS(camInputs[0]) ||
|
||||
COMPARE_CONFIG_PARAMS(vvtMode) ||
|
||||
COMPARE_CONFIG_PARAMS(bc.vvtCamSensorUseRise) ||
|
||||
COMPARE_CONFIG_PARAMS(vvtOffset) ||
|
||||
|
|
|
@ -44,27 +44,23 @@ int vvtEventFallCounter = 0;
|
|||
/* PAL based implementation */
|
||||
#if (HAL_TRIGGER_USE_PAL == TRUE) && (PAL_USE_CALLBACKS == TRUE)
|
||||
|
||||
/* static vars for PAL implementation */
|
||||
/* static variables for PAL implementation */
|
||||
static ioline_t primary_line;
|
||||
|
||||
static void shaft_callback(void *arg) {
|
||||
bool rise;
|
||||
bool isPrimary;
|
||||
ioline_t pal_line;
|
||||
trigger_event_e signal;
|
||||
|
||||
pal_line = (ioline_t)arg;
|
||||
ioline_t pal_line = (ioline_t)arg;
|
||||
// todo: support for 3rd trigger input channel
|
||||
// todo: start using real event time from HW event, not just software timer?
|
||||
if (hasFirmwareErrorFlag)
|
||||
return;
|
||||
|
||||
isPrimary = pal_line == primary_line;
|
||||
bool isPrimary = pal_line == primary_line;
|
||||
if (!isPrimary && !TRIGGER_SHAPE(needSecondTriggerInput)) {
|
||||
return;
|
||||
}
|
||||
|
||||
rise = (palReadLine(pal_line) == PAL_HIGH);
|
||||
bool rise = (palReadLine(pal_line) == PAL_HIGH);
|
||||
trigger_event_e signal;
|
||||
// todo: add support for 3rd channel
|
||||
if (rise) {
|
||||
signal = isPrimary ?
|
||||
|
@ -77,14 +73,12 @@ static void shaft_callback(void *arg) {
|
|||
}
|
||||
|
||||
hwHandleShaftSignal(signal);
|
||||
|
||||
}
|
||||
|
||||
static void cam_callback(void *arg) {
|
||||
bool rise;
|
||||
ioline_t pal_line = (ioline_t)arg;
|
||||
|
||||
rise = (palReadLine(pal_line) == PAL_HIGH);
|
||||
bool rise = (palReadLine(pal_line) == PAL_HIGH);
|
||||
|
||||
if (rise) {
|
||||
vvtEventRiseCounter++;
|
||||
|
@ -96,14 +90,12 @@ static void cam_callback(void *arg) {
|
|||
}
|
||||
|
||||
static int turnOnTriggerInputPin(const char *msg, brain_pin_e brainPin, bool is_shaft) {
|
||||
ioline_t pal_line;
|
||||
|
||||
scheduleMsg(logger, "turnOnTriggerInputPin(PAL) %s %s", msg, hwPortname(brainPin));
|
||||
|
||||
/* TODO:
|
||||
* * do not set to both edges if we need only one
|
||||
* * simplify callback in case of one edge */
|
||||
pal_line = PAL_LINE(getHwPort("trg", brainPin), getHwPin("trg", brainPin));
|
||||
ioline_t pal_line = PAL_LINE(getHwPort("trg", brainPin), getHwPin("trg", brainPin));
|
||||
return efiExtiEnablePin(msg, brainPin, PAL_EVENT_MODE_BOTH_EDGES, is_shaft ? shaft_callback : cam_callback, (void *)pal_line);
|
||||
}
|
||||
|
||||
|
@ -266,8 +258,10 @@ void stopTriggerInputPins(void) {
|
|||
turnOffTriggerInputPin(activeConfiguration.bc.triggerInputPins[i]);
|
||||
}
|
||||
}
|
||||
if (engineConfiguration->camInputs[0] != activeConfiguration.camInputs[0]) {
|
||||
turnOffTriggerInputPin(activeConfiguration.camInputs[0]);
|
||||
for (int i = 0; i < CAM_INPUTS_COUNT; i++) {
|
||||
if (engineConfiguration->camInputs[i] != activeConfiguration.camInputs[i]) {
|
||||
turnOffTriggerInputPin(activeConfiguration.camInputs[i]);
|
||||
}
|
||||
}
|
||||
#endif /* EFI_PROD_CODE */
|
||||
}
|
||||
|
@ -282,8 +276,10 @@ void startTriggerInputPins(void) {
|
|||
}
|
||||
}
|
||||
|
||||
if (engineConfiguration->camInputs[0] != activeConfiguration.camInputs[0]) {
|
||||
turnOnTriggerInputPin("cam", engineConfiguration->camInputs[0], false);
|
||||
for (int i = 0; i < CAM_INPUTS_COUNT; i++) {
|
||||
if (engineConfiguration->camInputs[i] != activeConfiguration.camInputs[i]) {
|
||||
turnOnTriggerInputPin("cam", engineConfiguration->camInputs[i], false);
|
||||
}
|
||||
}
|
||||
|
||||
setPrimaryChannel(CONFIGB(triggerInputPins)[0]);
|
||||
|
|
Loading…
Reference in New Issue