diff --git a/firmware/controllers/algo/engine_configuration.cpp b/firmware/controllers/algo/engine_configuration.cpp index b7ce034d98..f166a044b5 100644 --- a/firmware/controllers/algo/engine_configuration.cpp +++ b/firmware/controllers/algo/engine_configuration.cpp @@ -336,6 +336,9 @@ void setDefaultConfiguration(engine_configuration_s *engineConfiguration, board_ boardConfiguration->logicAnalyzerPins[0] = GPIOA_8; boardConfiguration->logicAnalyzerPins[1] = GPIOE_7; // todo: E7 is not timer input, that's a bug! + boardConfiguration->logicAnalyzerMode[0] = false; + boardConfiguration->logicAnalyzerMode[1] = false; + boardConfiguration->idleThreadPeriod = 100; boardConfiguration->consoleLoopPeriod = 200; boardConfiguration->lcdThreadPeriod = 300; diff --git a/firmware/controllers/algo/engine_configuration.h b/firmware/controllers/algo/engine_configuration.h index cf8fbdd943..2b8d4ca993 100644 --- a/firmware/controllers/algo/engine_configuration.h +++ b/firmware/controllers/algo/engine_configuration.h @@ -159,8 +159,10 @@ typedef struct { adc_channel_mode_e adcHwChannelEnabled[HW_MAX_ADC_INDEX]; + // todo: we should have up to three trigger input channels brain_pin_e triggerInputPins[2]; - brain_pin_e logicAnalyzerPins[2]; + // todo: we should have up to four login input channels + brain_pin_e logicAnalyzerPins[LOGIC_ANALYZER_CHANNEL_COUNT]; int idleThreadPeriod; int consoleLoopPeriod; @@ -186,7 +188,9 @@ typedef struct { unsigned int is_enabled_spi_2 : 1; unsigned int is_enabled_spi_3 : 1; - int unused2[7]; + int unused2[6]; + + uint8_t logicAnalyzerMode[4]; } board_configuration_s; diff --git a/firmware/controllers/algo/rusefi_enums.h b/firmware/controllers/algo/rusefi_enums.h index 4695f5a47f..04a2124dbf 100644 --- a/firmware/controllers/algo/rusefi_enums.h +++ b/firmware/controllers/algo/rusefi_enums.h @@ -19,6 +19,8 @@ #define DIGIPOT_COUNT 4 +#define LOGIC_ANALYZER_CHANNEL_COUNT 2 + typedef enum { AUDI_AAN = 1, #if EFI_SUPPORT_DODGE_NEON diff --git a/firmware/emulation/wave_analyzer.cpp b/firmware/emulation/wave_analyzer.cpp index a1c35998f5..937daef4f3 100644 --- a/firmware/emulation/wave_analyzer.cpp +++ b/firmware/emulation/wave_analyzer.cpp @@ -115,7 +115,15 @@ int getEventCounter(int index) { return reader->eventCounter; } -static void initWave(const char *name, int index, ICUDriver *driver, ioportid_t port, ioportmask_t pin, int mode) { +static void initWave(const char *name, int index) { + brain_pin_e brainPin = boardConfiguration->logicAnalyzerPins[index]; + + ioportid_t port = getHwPort(brainPin); + ioportmask_t pin = getHwPin(brainPin); + ICUDriver *driver = getInputCaptureDriver(brainPin); + + bool mode = boardConfiguration->logicAnalyzerMode[index]; + waveReaderCount++; efiAssertVoid(index < MAX_ICU_COUNT, "too many ICUs"); WaveReader *reader = &readers[index]; @@ -246,13 +254,12 @@ void initWaveAnalyzer(void) { #if EFI_WAVE_ANALYZER || defined(__DOXYGEN__) initLogging(&logger, "wave"); - initWave(WA_CHANNEL_1, 0, getInputCaptureDriver(boardConfiguration->logicAnalyzerPins[0]), getHwPort(boardConfiguration->logicAnalyzerPins[0]), getHwPin(boardConfiguration->logicAnalyzerPins[0]), 1); - initWave(WA_CHANNEL_2, 1, getInputCaptureDriver(boardConfiguration->logicAnalyzerPins[1]), getHwPort(boardConfiguration->logicAnalyzerPins[1]), getHwPin(boardConfiguration->logicAnalyzerPins[1]), 1); - // initWave("input0 C6", 2, &WAVE_TIMER, WAVE_INPUT_PORT, WAVE_INPUT_PIN, 0); + initWave(WA_CHANNEL_1, 0); + initWave(WA_CHANNEL_2, 1); addTriggerEventListener(&onWaveShaftSignal, "wave analyzer", (void*)NULL); - addConsoleActionII("wm", setWaveModeSilent); + addConsoleActionII("set_logic_input_mode", setWaveModeSilent); chThdCreateStatic(waThreadStack, sizeof(waThreadStack), NORMALPRIO, waThread, (void*)NULL); diff --git a/firmware/emulation/wave_analyzer.h b/firmware/emulation/wave_analyzer.h index 23aaeef23d..af5534b45c 100644 --- a/firmware/emulation/wave_analyzer.h +++ b/firmware/emulation/wave_analyzer.h @@ -17,6 +17,8 @@ #define WA_CHANNEL_1 "input1" #define WA_CHANNEL_2 "input2" +#define WA_CHANNEL_3 "input3" +#define WA_CHANNEL_4 "input4" typedef struct { WaveReaderHw hw; diff --git a/firmware/hw_layer/wave_analyzer_hw.c b/firmware/hw_layer/wave_analyzer_hw.c index 795580d500..af7761567c 100644 --- a/firmware/hw_layer/wave_analyzer_hw.c +++ b/firmware/hw_layer/wave_analyzer_hw.c @@ -150,7 +150,7 @@ void initWaveAnalyzerDriver(WaveReaderHw *hw, ICUDriver *driver, ioportid_t port } } -void setWaveReaderMode(WaveReaderHw *hw, int mode) { +void setWaveReaderMode(WaveReaderHw *hw, bool mode) { hw->activeMode = mode; if (hw->activeMode) { wave_icucfg.mode = ICU_INPUT_ACTIVE_HIGH; diff --git a/firmware/hw_layer/wave_analyzer_hw.h b/firmware/hw_layer/wave_analyzer_hw.h index 6e54769bfd..a39d28d3bf 100644 --- a/firmware/hw_layer/wave_analyzer_hw.h +++ b/firmware/hw_layer/wave_analyzer_hw.h @@ -29,7 +29,7 @@ extern "C" void initWaveAnalyzerDriver(WaveReaderHw *hw, ICUDriver *driver, ioportid_t port, ioportmask_t pin); -void setWaveReaderMode(WaveReaderHw *hw, int mode); +void setWaveReaderMode(WaveReaderHw *hw, bool mode); ICUDriver * getInputCaptureDriver(brain_pin_e hwPin); #ifdef __cplusplus