diff --git a/firmware/config/engines/toyota_jzs147.cpp b/firmware/config/engines/toyota_jzs147.cpp index fe0385ea19..0401b6e0c5 100644 --- a/firmware/config/engines/toyota_jzs147.cpp +++ b/firmware/config/engines/toyota_jzs147.cpp @@ -14,10 +14,12 @@ */ #include "toyota_jzs147.h" +#include "custom_engine.h" EXTERN_ENGINE; void setToyota_jzs147EngineConfiguration(DECLARE_ENGINE_PARAMETER_F) { + setCustomEngineConfiguration(PASS_ENGINE_PARAMETER_F); // default pinout engineConfiguration->specs.displacement = 3.0; engineConfiguration->specs.cylindersCount = 6; @@ -26,6 +28,13 @@ void setToyota_jzs147EngineConfiguration(DECLARE_ENGINE_PARAMETER_F) { setOperationMode(engineConfiguration, FOUR_STROKE_CAM_SENSOR); engineConfiguration->trigger.type = TT_2JZ; + boardConfiguration->ignitionPins[0] = GPIOE_14; + boardConfiguration->ignitionPins[1] = GPIOC_7; + boardConfiguration->ignitionPins[2] = GPIOC_9; + boardConfiguration->ignitionPins[3] = GPIOE_10; + boardConfiguration->ignitionPins[3] = GPIOE_10; + boardConfiguration->ignitionPins[3] = GPIOE_10; + } diff --git a/firmware/controllers/algo/engine.cpp b/firmware/controllers/algo/engine.cpp index f0f231ae57..9548ead540 100644 --- a/firmware/controllers/algo/engine.cpp +++ b/firmware/controllers/algo/engine.cpp @@ -20,11 +20,11 @@ #include "speed_density.h" #include "advance_map.h" -#if EFI_PROD_CODE +#if EFI_PROD_CODE || defined(__DOXYGEN__) #include "injector_central.h" #else #define isRunningBenchTest() true -#endif +#endif /* EFI_PROD_CODE */ static LoggingWithStorage logger("engine"); @@ -36,6 +36,25 @@ extern fuel_Map3D_t afrMap; EXTERN_ENGINE ; +MockAdcState::MockAdcState() { + memset(hasMockAdc, 0, sizeof(hasMockAdc)); +} + +#if EFI_ENABLE_MOCK_ADC || EFI_SIMULATOR +void MockAdcState::setMockVoltage(int hwChannel, float voltage) { + scheduleMsg(&logger, "fake voltage: channel %d value %f", hwChannel, voltage); + + fakeAdcValues[hwChannel] = voltsToAdc(voltage); + hasMockAdc[hwChannel] = true; +} +#endif /* EFI_ENABLE_MOCK_ADC */ + +int MockAdcState::getMockAdcValue(int hwChannel) { + return fakeAdcValues[hwChannel]; +} + + + /** * We are executing these heavy (logarithm) methods from outside the trigger callbacks for performance reasons. * See also periodicFastCallback diff --git a/firmware/controllers/algo/engine.h b/firmware/controllers/algo/engine.h index 680d6f0d24..b35afa2b1a 100644 --- a/firmware/controllers/algo/engine.h +++ b/firmware/controllers/algo/engine.h @@ -20,6 +20,18 @@ #include "accel_enrichment.h" #include "trigger_central.h" +#define MOCK_ADC_SIZE 16 + +class MockAdcState { +public: + MockAdcState(); + bool hasMockAdc[MOCK_ADC_SIZE]; + int fakeAdcValues[MOCK_ADC_SIZE]; + + void setMockVoltage(int hwChannel, float voltage); + int getMockAdcValue(int hwChannel); +}; + /** * This class knows about when to inject fuel */ @@ -149,6 +161,9 @@ public: floatms_t tpsAccelEnrich; angle_t injectionOffset; + +// todo: surround with EFI_ENABLE_MOCK_ADC checks + MockAdcState mockAdcState; }; class RpmCalculator; diff --git a/firmware/controllers/engine_controller.cpp b/firmware/controllers/engine_controller.cpp index 3022790328..32838291a9 100644 --- a/firmware/controllers/engine_controller.cpp +++ b/firmware/controllers/engine_controller.cpp @@ -443,6 +443,52 @@ static void setFloat(const char *offsetStr, const char *valueStr) { getFloat(offset); } +#if EFI_ENABLE_MOCK_ADC || EFI_SIMULATOR + +static void setMockVoltage(int hwChannel, float voltage) { + engine->engineState.mockAdcState.setMockVoltage(hwChannel, voltage); +} + +static void setCltVoltage(float voltage) { + setMockVoltage(engineConfiguration->clt.adcChannel, voltage); +} + +static void setIatVoltage(float voltage) { + setMockVoltage(engineConfiguration->iat.adcChannel, voltage); +} + +static void setMafVoltage(float voltage) { + setMockVoltage(engineConfiguration->mafAdcChannel, voltage); +} + +static void setAfrVoltage(float voltage) { + setMockVoltage(engineConfiguration->afr.hwChannel, voltage); +} + +static void setTpsVoltage(float voltage) { + setMockVoltage(engineConfiguration->tpsAdcChannel, voltage); +} + +static void setMapVoltage(float voltage) { + setMockVoltage(engineConfiguration->map.sensor.hwChannel, voltage); +} + +static void setVBattVoltage(float voltage) { + setMockVoltage(engineConfiguration->vbattAdcChannel, voltage); +} + +static void initMockVoltage(void) { + addConsoleActionF("set_mock_clt_voltage", setCltVoltage); + addConsoleActionF("set_mock_iat_voltage", setIatVoltage); + addConsoleActionF("set_mock_maf_voltage", setMafVoltage); + addConsoleActionF("set_mock_afr_voltage", setAfrVoltage); + addConsoleActionF("set_mock_tps_voltage", setTpsVoltage); + addConsoleActionF("set_mock_map_voltage", setMapVoltage); + addConsoleActionF("set_mock_vbatt_voltage", setVBattVoltage); +} + +#endif /* EFI_ENABLE_MOCK_ADC */ + static void initConfigActions(void) { addConsoleActionSS("set_float", (VoidCharPtrCharPtr) setFloat); addConsoleActionII("set_int", (VoidIntInt) setInt); @@ -465,12 +511,13 @@ static void getKnockInfo(void) { // this method is used by real firmware and simulator void commonInitEngineController(Logging *sharedLogger DECLARE_ENGINE_PARAMETER_S) { initConfigActions(); + initMockVoltage(); #if EFI_PROD_CODE || EFI_SIMULATOR initSignalExecutor(); #endif -#if EFI_PROD_CODE +#if EFI_PROD_CODE || EFI_SIMULATOR // todo: this is a mess, remove code duplication with simulator initSettings(engineConfiguration); #endif diff --git a/firmware/development/engine_sniffer.cpp b/firmware/development/engine_sniffer.cpp index ea49ff6aa4..7c2342aebc 100644 --- a/firmware/development/engine_sniffer.cpp +++ b/firmware/development/engine_sniffer.cpp @@ -28,20 +28,6 @@ #include "engine_sniffer.h" #include "adc_math.h" -MockAdcState::MockAdcState() { - memset(hasMockAdc, 0, sizeof(hasMockAdc)); -} - -void MockAdcState::setMockVoltage(int hwChannel, float voltage) { - fakeAdcValues[hwChannel] = voltsToAdc(voltage); - hasMockAdc[hwChannel] = true; -} - -int MockAdcState::getMockAdcValue(int hwChannel) { - return fakeAdcValues[hwChannel]; -} - - #if EFI_ENGINE_SNIFFER || defined(__DOXYGEN__) #include "engine_configuration.h" diff --git a/firmware/development/engine_sniffer.h b/firmware/development/engine_sniffer.h index 0fcef43c5b..2678629ed7 100644 --- a/firmware/development/engine_sniffer.h +++ b/firmware/development/engine_sniffer.h @@ -11,19 +11,6 @@ #include "global.h" -#define MOCK_ADC_SIZE 16 - -class MockAdcState { -public: - MockAdcState(); - bool hasMockAdc[MOCK_ADC_SIZE]; - int fakeAdcValues[MOCK_ADC_SIZE]; - - void setMockVoltage(int hwChannel, float voltage); - int getMockAdcValue(int hwChannel); -}; - - #if EFI_ENGINE_SNIFFER || defined(__DOXYGEN__) #include "datalogging.h"