16#define DELTA_THRESHOLD_CNT_LOW (GPT_FREQ_FAST / GPT_PERIOD_FAST / 32)
17#define DELTA_THRESHOLD_CNT_HIGH (GPT_FREQ_FAST / GPT_PERIOD_FAST / 4)
19#if HAL_USE_ADC || EFI_UNIT_TEST
20#define triggerVoltsToAdcDivided(volts) (voltsToAdc(volts) / trigAdcState.triggerInputDividerCoefficient)
24#if (EFI_SHAFT_POSITION_INPUT && HAL_TRIGGER_USE_ADC && HAL_USE_ADC) || defined(__DOXYGEN__)
28#ifndef TRIGGER_ADC_DEBUG_LED
29#define TRIGGER_ADC_DEBUG_LED FALSE
34#ifdef TRIGGER_ADC_DEBUG_LED
35#define TRIGGER_ADC_DEBUG_LED1_PORT GPIOH
36#define TRIGGER_ADC_DEBUG_LED1_PIN 9
38#ifdef TRIGGER_ADC_DUMP_BUF
46 static uint8_t st[5] = { 0 };
47 if ((st[led] == 0 && mode == 0) || mode == 1) {
48 palClearPad(TRIGGER_ADC_DEBUG_LED1_PORT, TRIGGER_ADC_DEBUG_LED1_PIN);
49#ifdef DEBUG_OUTPUT_IGN1
50 palClearPad(GPIOI, 8);
53 else if ((st[led] != 0 && mode == 0) || mode == -1) {
54 palSetPad(TRIGGER_ADC_DEBUG_LED1_PORT, TRIGGER_ADC_DEBUG_LED1_PIN);
55#ifdef DEBUG_OUTPUT_IGN1
59 st[led] = (st[led] + 1) % 2;
68#ifndef PAL_MODE_EXTINT
69#define PAL_MODE_EXTINT PAL_MODE_INPUT
77 (adcMode ==
TRIGGER_ADC_ADC) ? PAL_MODE_INPUT_ANALOG : PAL_MODE_EXTINT);
83 bool rise = (palReadLine(pal_line) == PAL_HIGH);
97#ifdef TRIGGER_ADC_DUMP_BUF
103 efiPrintf(
"[%d] %d", i, v);
119 efiPrintf(
"turnOnTriggerInputPin %s l=%ld",
hwPortname(brainPin), pal_line);
129#ifdef TRIGGER_ADC_DEBUG_LED
130 palSetPadMode(TRIGGER_ADC_DEBUG_LED1_PORT, TRIGGER_ADC_DEBUG_LED1_PIN, PAL_MODE_OUTPUT_PUSHPULL);
131#ifdef DEBUG_OUTPUT_IGN1
132 palSetPadMode(GPIOI, 8, PAL_MODE_OUTPUT_PUSHPULL);
136#ifdef TRIGGER_ADC_DUMP_BUF
166#ifdef TRIGGER_ADC_DEBUG_LED
187#if HAL_USE_ADC || EFI_UNIT_TEST
192 const int minNumAdcMeasurementsPerTooth = 10;
225#if HAL_USE_ADC || EFI_UNIT_TEST
245#if !EFI_SIMULATOR && EFI_SHAFT_POSITION_INPUT
254#if (HAL_TRIGGER_USE_ADC && HAL_USE_ADC) || EFI_UNIT_TEST
279#if ! EFI_SIMULATOR && ((HAL_TRIGGER_USE_ADC && HAL_USE_ADC) || EFI_UNIT_TEST)
284#ifdef TRIGGER_ADC_DUMP_BUF
298 int aDelta = absI(delta);
385 efitimeus_t deltaTimeUs = NT2US(stamp -
prevStamp);
386 if (deltaTimeUs > 200) {
395#ifdef EFI_SHAFT_POSITION_INPUT
429#if HAL_USE_ADC || EFI_UNIT_TEST
triggerAdcSample_t switchingThresholdHigh
int minDeltaThresholdCntPos
int analogToDigitalTransitionCnt
int minDeltaThresholdStrongSignal
int minDeltaThresholdCntNeg
float triggerAdcITermCoef
triggerAdcSample_t switchingThresholdLow
triggerAdcSample_t adcMaxThreshold
int transitionCooldownCnt
triggerAdcSample_t adcMinThreshold
float triggerInputDividerCoefficient
void analogCallback(efitick_t stamp, triggerAdcSample_t value)
triggerAdcMode_t curAdcMode
void setWeakSignal(bool isWeak)
int minDeltaThresholdWeakSignal
efidur_t stampCorrectionForAdc
efidur_t minDeltaTimeForStableAdcDetectionNt
void digitalCallback(efitick_t stamp, bool isPrimary, bool rise)
int digitalToAnalogTransitionCnt
triggerAdcSample_t adcDefaultThreshold
void addConsoleAction(const char *token, Void callback)
Register console action without parameters.
adc_channel_e getAdcChannel(brain_pin_e pin)
ioportid_t getHwPort(const char *msg, brain_pin_e brainPin)
ioportmask_t getHwPin(const char *msg, brain_pin_e brainPin)
static constexpr engine_configuration_s * engineConfiguration
uint32_t ioportmask_t
Digital I/O port sized unsigned type.
GPIO_TypeDef * ioportid_t
Port Identifier.
uint32_t ioline_t
Type of an I/O line.
UNUSED(samplingTimeSeconds)
const char * hwPortname(brain_pin_e brainPin)
bool isBrainPinValid(brain_pin_e brainPin)
brain_input_pin_e triggerInputPins[TRIGGER_INPUT_PIN_COUNT]
brain_input_pin_e camInputs[CAM_INPUTS_COUNT]
void hwHandleShaftSignal(int signalIndex, bool isRising, efitick_t timestamp)