diff --git a/firmware/controllers/algo/obd_error_codes.h b/firmware/controllers/algo/obd_error_codes.h index 23dcf229cf..239273637c 100644 --- a/firmware/controllers/algo/obd_error_codes.h +++ b/firmware/controllers/algo/obd_error_codes.h @@ -1932,7 +1932,7 @@ typedef enum { CUSTOM_ERR_6570 = 6570, CUSTOM_ERR_6571 = 6571, - CUSTOM_ERR_6572 = 6572, + CUSTOM_ERR_ARRAY_REMOVE = 6572, CUSTOM_ERR_6573 = 6573, CUSTOM_ERR_6574 = 6574, CUSTOM_ERR_6575 = 6575, @@ -2070,9 +2070,9 @@ typedef enum { CUSTOM_ERR_6695 = 6695, CUSTOM_ERR_6696 = 6696, CUSTOM_ERR_6697 = 6697, - CUSTOM_ERR_6698 = 6698, - CUSTOM_ERR_6699 = 6699, - CUSTOM_ERR_6700 = 6700, + CUSTOM_ERR_ARRAY_IS_FULL = 6698, + CUSTOM_ERR_ARRAY_REMOVE_ERROR = 6699, + CUSTOM_ERR_INVALID_INPUT_ICU_PIN = 6700, // this is needed for proper enum size, this matters for malfunction_central Internal_ForceMyEnumIntSize_cranking_obd_code = ENUM_32_BITS, diff --git a/firmware/controllers/core/fl_stack.h b/firmware/controllers/core/fl_stack.h index 58b8d37b88..273c0828d1 100644 --- a/firmware/controllers/core/fl_stack.h +++ b/firmware/controllers/core/fl_stack.h @@ -107,7 +107,7 @@ ArrayList::ArrayList(void) { template void ArrayList::removeAt(int index) { - efiAssertVoid(CUSTOM_ERR_6572, index < size, "index greater then size"); + efiAssertVoid(CUSTOM_ERR_ARRAY_REMOVE, index >= 0 && index < size, "invalid index"); memcpy(&elements[index], &elements[size - 1], sizeof(Type)); memset(&elements[size - 1], 0, sizeof(Type)); size--; diff --git a/firmware/development/wave_analyzer.cpp b/firmware/development/wave_analyzer.cpp index ad570f8ac8..31e8c9e563 100644 --- a/firmware/development/wave_analyzer.cpp +++ b/firmware/development/wave_analyzer.cpp @@ -127,12 +127,11 @@ static void initWave(const char *name, int index) { reader->name = name; reader->hw = addWaveAnalyzerDriver("wave input", brainPin); + if (reader->hw != NULL) { + reader->hw->widthListeners.registerCallback((VoidInt)(void*) waAnaWidthCallback, (void*) reader); - - reader->hw->widthListeners.registerCallback((VoidInt)(void*) waAnaWidthCallback, (void*) reader); - - reader->hw->periodListeners.registerCallback((VoidInt)(void*) waIcuPeriodCallback, (void*) reader); - + reader->hw->periodListeners.registerCallback((VoidInt)(void*) waIcuPeriodCallback, (void*) reader); + } print("wave%d input on %s\r\n", index, hwPortname(brainPin)); startInputDriver(reader->hw, mode); diff --git a/firmware/hw_layer/digital_input_hw.cpp b/firmware/hw_layer/digital_input_hw.cpp index 3fc5ccc196..447a87829d 100644 --- a/firmware/hw_layer/digital_input_hw.cpp +++ b/firmware/hw_layer/digital_input_hw.cpp @@ -46,6 +46,7 @@ static ICUConfig wave_icucfg = { ICU_INPUT_ACTIVE_LOW, CORE_CLOCK / 100, icuWidt static ArrayList registeredIcus; +//Nullable static digital_input_s * finddigital_input_s(ICUDriver *driver) { for (int i = 0; i < registeredIcus.size; i++) { if (registeredIcus.elements[i].driver == driver) { @@ -145,8 +146,9 @@ icuchannel_t getInputCaptureChannel(brain_pin_e hwPin) { * * TODO: migrate slow ADC to software timer so that TIM8 is also available for input capture * todo: https://github.com/rusefi/rusefi/issues/630 ? - * + * @return NULL if pin could not be used for ICU */ +//Nullable ICUDriver * getInputCaptureDriver(const char *msg, brain_pin_e hwPin) { if (hwPin == GPIO_UNASSIGNED || hwPin == GPIO_INVALID) { return NULL; @@ -208,6 +210,10 @@ void turnOnCapturePin(const char *msg, brain_pin_e brainPin) { */ digital_input_s * addWaveAnalyzerDriver(const char *msg, brain_pin_e brainPin) { ICUDriver *driver = getInputCaptureDriver(msg, brainPin); + if (driver == NULL) { + warning(CUSTOM_ERR_INVALID_INPUT_ICU_PIN, "not input pin"); + return NULL; + } digital_input_s *hw = registeredIcus.add(); hw->widthListeners.clear(); @@ -247,7 +253,13 @@ void removeWaveAnalyzerDriver(const char *msg, brain_pin_e brainPin) { } } -void startInputDriver(digital_input_s *hw, bool isActiveHigh) { +void startInputDriver(/*nullable*/digital_input_s *hw, bool isActiveHigh) { + if (hw == NULL) { + // we can get NULL driver if user somehow has invalid pin in his configuration + warning(CUSTOM_ERR_INVALID_INPUT_ICU_PIN, "not input pin"); + return; + } + hw->isActiveHigh = isActiveHigh; if (hw->isActiveHigh) { wave_icucfg.mode = ICU_INPUT_ACTIVE_HIGH; diff --git a/firmware/hw_layer/digital_input_hw.h b/firmware/hw_layer/digital_input_hw.h index 808083e964..384d77a71c 100644 --- a/firmware/hw_layer/digital_input_hw.h +++ b/firmware/hw_layer/digital_input_hw.h @@ -26,10 +26,12 @@ typedef struct { void turnOnCapturePin(const char *msg, brain_pin_e brainPin); digital_input_s *addWaveAnalyzerDriver(const char *msg, brain_pin_e brainPin); -void startInputDriver(digital_input_s *hw, bool isActiveHigh); +void startInputDriver(/*nullable*/digital_input_s *hw, bool isActiveHigh); void removeWaveAnalyzerDriver(const char *msg, brain_pin_e brainPin); +//Nullable ICUDriver * getInputCaptureDriver(const char *msg, brain_pin_e hwPin); +//Nullable icuchannel_t getInputCaptureChannel(brain_pin_e hwPin); #endif /* HAL_USE_ICU */