rusEFI
The most advanced open source ECU
Loading...
Searching...
No Matches
Functions
custom_engine.h File Reference

Detailed Description

Date
Jan 18, 2015
Author
Andrey Belomutskiy, (c) 2012-2020

Definition in file custom_engine.h.

Functions

void setFrankensoConfiguration ()
 
void setDiscoveryPdm ()
 
void setDiscovery33810Test ()
 
void setEtbTestConfiguration ()
 
void setL9779TestConfiguration ()
 
void setEepromTestConfiguration ()
 
void mreSecondaryCan ()
 
void mreBCM ()
 
void setBodyControlUnit ()
 
void fuelBenchMode ()
 
void proteusLuaDemo ()
 
void proteusStimQc ()
 
void proteusDcWastegateTest ()
 
void setTest33816EngineConfiguration ()
 
void setBoschHDEV_5_injectors ()
 
void setRotary ()
 
void setVrThresholdTest ()
 
void detectBoardType ()
 
void testEngine6451 ()
 

Function Documentation

◆ detectBoardType()

void detectBoardType ( )

Definition at line 612 of file custom_engine.cpp.

612 {
613#if HW_HELLEN && EFI_PROD_CODE
615#endif //HW_HELLEN EFI_PROD_CODE
616 // todo: add board ID detection?
617 // see hellen128 which has/had alternative i2c board id?
618}
void detectHellenBoardType()

Referenced by runRusEfi().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ fuelBenchMode()

void fuelBenchMode ( )

Definition at line 621 of file custom_engine.cpp.

621 {
623#if EFI_ENGINE_CONTROL
625#endif // EFI_ENGINE_CONTROL
630}
static void setBasicNotECUmode()
static constexpr persistent_config_s * config
static constexpr engine_configuration_s * engineConfiguration
void setFlatInjectorLag(float value)
float crankingCycleBaseFuel[CRANKING_CYCLE_CLT_SIZE][CRANKING_CURVE_SIZE]
float postCrankingFactor[CRANKING_ENRICH_CLT_COUNT][CRANKING_ENRICH_COUNT]
constexpr void setTable(TElement(&dest)[N][M], const VElement value)
void setArrayValues(TValue(&array)[TSize], float value)

Referenced by applyEngineType().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ mreBCM()

void mreBCM ( )

Definition at line 381 of file custom_engine.cpp.

381 {
383 // maybe time to kill this feature is pretty soon?
385}
void mreSecondaryCan()

Referenced by applyEngineType().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ mreSecondaryCan()

void mreSecondaryCan ( )

Definition at line 344 of file custom_engine.cpp.

344 {
346
347 engineConfiguration->auxAnalogInputs[0] = MRE_IN_TPS;
348 engineConfiguration->auxAnalogInputs[1] = MRE_IN_MAP;
349 engineConfiguration->auxAnalogInputs[2] = MRE_IN_CLT;
350 engineConfiguration->auxAnalogInputs[3] = MRE_IN_IAT;
351 // engineConfiguration->auxAnalogInputs[0] =
352
353
354 // EFI_ADC_14: "32 - AN volt 6"
355// engineConfiguration->afr.hwChannel = EFI_ADC_14;
356
357
358 strncpy(config->luaScript, R"(
359txPayload = {}
360function onTick()
361 auxV = getAuxAnalog(0)
362 print('Hello analog ' .. auxV )
363 -- first byte: integer part, would be autoboxed to int
364 txPayload[1] = auxV
365 -- second byte: fractional part, would be autoboxed to int, overflow would be ignored
366 txPayload[2] = auxV * 256;
367 auxV = getAuxAnalog(1)
368 print('Hello analog ' .. auxV )
369 txPayload[3] = auxV
370 txPayload[4] = auxV * 256;
371 auxV = getAuxAnalog(2)
372 print('Hello analog ' .. auxV )
373 txPayload[5] = auxV
374 txPayload[6] = auxV * 256;
375 txCan(1, 0x600, 1, txPayload)
376end
377)", efi::size(config->luaScript));
378
379}
void setBodyControlUnit()

Referenced by applyEngineType(), and mreBCM().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ proteusDcWastegateTest()

void proteusDcWastegateTest ( )

Definition at line 286 of file custom_engine.cpp.

286 {
288 engineConfiguration->etbFunctions[0] = DC_Wastegate;
289 engineConfiguration->etbFunctions[1] = DC_None;
290 engineConfiguration->map.sensor.hwChannel = EFI_ADC_NONE;
291
293 setTPS1Calibration(98, 926, 891, 69);
294
298
299 strncpy(config->luaScript, R"(
300
301mapSensor = Sensor.new("map")
302mapSensor : setTimeout(3000)
303
304function onTick()
305 local tps = getSensor("TPS1")
306 tps = (tps == nil and 0 or tps)
307 mapSensor : set(tps)
308end
309
310 )", efi::size(config->luaScript));
311}
void setTPS1Calibration(uint16_t tpsMin, uint16_t tpsMax)

Referenced by applyEngineType().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ proteusLuaDemo()

void proteusLuaDemo ( )

for this demo I use ETB just a sample object to control with PID. No reasonable person should consider actually using Lua for actual intake ETB control while driving around the racing track - hard-coded ETB control is way smarter!

controlIndex = 0 directionIndex = 1

print('pid output ' .. output) print('')

local duty = (bias + output) / 100

– isPositive = duty > 0; – pwmValue = isPositive and duty or -duty – setPwmDuty(controlIndex, pwmValue)

– dirValue = isPositive and 1 or 0; – setPwmDuty(directionIndex, dirValue)

– print('pwm ' .. pwmValue .. ' dir ' .. dirValue)

Definition at line 489 of file custom_engine.cpp.

489 {
490#if HW_PROTEUS
493
496
497 strcpy(engineConfiguration->scriptCurveName[2 - 1], "rateofchange");
498
499 strcpy(engineConfiguration->scriptCurveName[3 - 1], "bias");
500
501 /**
502 * for this demo I use ETB just a sample object to control with PID. No reasonable person should consider actually using
503 * Lua for actual intake ETB control while driving around the racing track - hard-coded ETB control is way smarter!
504 */
505 static const float defaultBiasBins[] = {
506 0, 1, 2, 4, 7, 98, 99, 100
507 };
508 static const float defaultBiasValues[] = {
509 -20, -18, -17, 0, 20, 21, 22, 25
510 };
511
515
518
521
522 engineConfiguration->auxAnalogInputs[0] = PROTEUS_IN_ANALOG_VOLT_10;
523 engineConfiguration->afr.hwChannel = EFI_ADC_NONE;
524
525
526 // ETB direction #1 PD10
528 // ETB control PD12
530 // ETB disable PD11
532
533/**
534controlIndex = 0
535directionIndex = 1
536
537 print('pid output ' .. output)
538 print('')
539
540
541
542 local duty = (bias + output) / 100
543
544-- isPositive = duty > 0;
545-- pwmValue = isPositive and duty or -duty
546-- setPwmDuty(controlIndex, pwmValue)
547
548-- dirValue = isPositive and 1 or 0;
549-- setPwmDuty(directionIndex, dirValue)
550
551-- print('pwm ' .. pwmValue .. ' dir ' .. dirValue)
552
553 *
554 */
555
556 auto script = R"(
557
558startPwm(0, 800, 0.1)
559-- direction
560startPwm(1, 80, 1.0)
561-- disable
562startPwm(2, 80, 0.0)
563
564pid = Pid.new(2, 0, 0, -100, 100)
565
566biasCurveIndex = findCurveIndex("bias")
567
568voltageFromCan = nil
569canRxAdd(0x600)
570
571function onCanRx(bus, id, dlc, data)
572 print('got CAN id=' .. id .. ' dlc=' .. dlc)
573 voltageFromCan = data[2] / 256.0 + data[1]
574end
575
576function onTick()
577 local targetVoltage = getAuxAnalog(0)
578
579-- local target = interpolate(1, 0, 3.5, 100, targetVoltage)
580 local target = interpolate(1, 0, 3.5, 100, voltageFromCan)
581-- clamp 0 to 100
582 target = math.max(0, target)
583 target = math.min(100, target)
584
585 print('Decoded target: ' .. target)
586
587 local tps = getSensor("TPS1")
588 tps = (tps == nil and 'invalid TPS' or tps)
589 print('Tps ' .. tps)
590
591 local output = pid:get(target, tps)
592
593 local bias = curve(biasCurveIndex, target)
594 print('bias ' .. bias)
595
596 local duty = (bias + output) / 100
597 isPositive = duty > 0;
598 pwmValue = isPositive and duty or -duty
599 setPwmDuty(0, pwmValue)
600
601 dirValue = isPositive and 1 or 0;
602 setPwmDuty(1, dirValue)
603
604 print('pwm ' .. pwmValue .. ' dir ' .. dirValue)
605 print('')
606end
607 )";
608 strncpy(config->luaScript, script, efi::size(config->luaScript));
609#endif
610}
@ Unassigned
static const float defaultBiasValues[]
static const float defaultBiasBins[]
void setLinearCurve(TValue(&array)[TSize], float from, float to, float precision=0.01f)

Referenced by applyEngineType().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ proteusStimQc()

void proteusStimQc ( )

Definition at line 635 of file custom_engine.cpp.

635 {
637 engineConfiguration->vvtMode[0] = VVT_SINGLE_TOOTH;
638 engineConfiguration->vvtMode[1] = VVT_SINGLE_TOOTH;
639
640 engineConfiguration->triggerInputPins[0] = PROTEUS_DIGITAL_1;
641 engineConfiguration->triggerInputPins[1] = PROTEUS_DIGITAL_2;
642 engineConfiguration->camInputs[0] = PROTEUS_DIGITAL_3;
643 engineConfiguration->camInputs[1] = PROTEUS_DIGITAL_4;
645 engineConfiguration->brakePedalPin = PROTEUS_DIGITAL_6;
646
648 // EFI_ADC_13: "Analog Volt 4"
649 engineConfiguration->tps2_1AdcChannel = PROTEUS_IN_TPS2_1;
650 // EFI_ADC_0: "Analog Volt 5"
651 engineConfiguration->tps2_2AdcChannel = PROTEUS_IN_ANALOG_VOLT_5;
652 engineConfiguration->oilPressure.hwChannel = PROTEUS_IN_ANALOG_VOLT_6;
653 // pps2 volt 7
654
655 // pps1 volt 9
656 // afr volt 10
657 engineConfiguration->oilTempSensor.adcChannel = PROTEUS_IN_ANALOG_VOLT_11;
659
660
661 engineConfiguration->auxLinear1.hwChannel = PROTEUS_IN_ANALOG_TEMP_1;
662 engineConfiguration->auxLinear2.hwChannel = PROTEUS_IN_ANALOG_TEMP_4;
663
664// engineConfiguration->fan2Pin = Gpio::PROTEUS_LS_9;
665// engineConfiguration->malfunctionIndicatorPin = Gpio::PROTEUS_LS_13;
666// engineConfiguration->tachOutputPin = Gpio::PROTEUS_LS_14;
667//
668// engineConfiguration->vvtPins[0] = Gpio::PROTEUS_LS_15;
669// engineConfiguration->vvtPins[1] = Gpio::PROTEUS_LS_16;
670}
void setProteusEtbIO()
brain_input_pin_e triggerInputPins[TRIGGER_INPUT_PIN_COUNT]
void setCommonNTCSensor(ThermistorConf *thermistorConf, float pullup)

Referenced by applyEngineType().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setBodyControlUnit()

void setBodyControlUnit ( )

Definition at line 336 of file custom_engine.cpp.

336 {
337 for (int i = 0; i < MAX_CYLINDER_COUNT;i++) {
340 }
342}

Referenced by mreSecondaryCan(), and setHondaCivicBcm().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setBoschHDEV_5_injectors()

void setBoschHDEV_5_injectors ( )

Definition at line 387 of file custom_engine.cpp.

387 {
388#if HPFP_LOBE_PROFILE_SIZE == 16
389static const float hardCodedHpfpLobeProfileQuantityBins[16] = {0.0, 1.0, 4.5, 9.5,
39016.5, 25.0, 34.5, 45.0 ,
39155.0, 65.5, 75.0, 83.5,
39290.5, 95.5, 99.0, 100.0};
393 copyArray(config->hpfpLobeProfileQuantityBins, hardCodedHpfpLobeProfileQuantityBins);
394#endif // HPFP_LOBE_PROFILE_SIZE
397
399 setLinearCurve(config->hpfpCompensationLoadBins, 0.005, 0.120, 0.001);
400
401 // This is the configuration for bosch HDEV 5 injectors
402 // all times in microseconds/us
414
415 engineConfiguration->mc33_hpfp_i_peak = 5; // A not mA like above
418 engineConfiguration->mc33_hpfp_max_hold = 10; // this value in ms not us
419
420}
void setHpfpLobeProfileAngle(int lobes)
scaled_channel< uint8_t, 2, 1 > hpfpLobeProfileQuantityBins[HPFP_LOBE_PROFILE_SIZE]
scaled_channel< uint16_t, 1000, 1 > hpfpCompensationLoadBins[HPFP_COMPENSATION_SIZE]
scaled_channel< uint8_t, 1, 50 > hpfpCompensationRpmBins[HPFP_COMPENSATION_SIZE]
void setRpmTableBin(TValue(&array)[TSize])

Referenced by setDefaultEngineConfiguration().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setDiscovery33810Test()

void setDiscovery33810Test ( )

set engine_type 59

Definition at line 43 of file custom_engine.cpp.

43 {
44// spi3mosiPin = Gpio::B5 grey
45// spi3misoPin = Gpio::B4; vio
46// spi3sckPin = Gpio::B3; blue
47// CS PC5 white
48// EN PA6 yellow
49
51 engineConfiguration->clt.adcChannel = EFI_ADC_NONE;
54
56
61
66
69}
@ MC33810_0_GD_3
@ MC33810_0_OUT_0
@ MC33810_0_GD_2
@ MC33810_0_OUT_1
@ MC33810_0_GD_1
@ MC33810_0_GD_0

Referenced by applyEngineType().

Here is the caller graph for this function:

◆ setDiscoveryPdm()

void setDiscoveryPdm ( )

Definition at line 35 of file custom_engine.cpp.

35 {
36}

◆ setEepromTestConfiguration()

void setEepromTestConfiguration ( )

set engine_type 61

Definition at line 234 of file custom_engine.cpp.

234 {
237 // dirty hack
239 efiSetPadMode("I2C", Gpio::A8, PAL_MODE_ALTERNATE(4));
240 efiSetPadMode("I2C", Gpio::C9, PAL_MODE_ALTERNATE(4));
241
242
243 addConsoleActionI("ee_read",
244 [](int value) {
245 if (ifile.vmt != eepdev_24xx.efsvmt) {
246 EepromFileOpen((EepromFileStream *)&ifile, (EepromFileConfig *)&i2cee, &eepdev_24xx);
247 }
248
249 ifile.vmt->setposition(&ifile, 0);
250// chFileStreamSeek(&ifile, 0);
251 int v2;
252 streamRead(&ifile, (uint8_t *)&v2, 4);
253 efiPrintf("EE has %d", v2);
254
255 v2 += 3;
256 ifile.vmt->setposition(&ifile, 0);
257 streamWrite(&ifile, (uint8_t *)&v2, 4);
258
259
260 });
261}
void efiSetPadMode(const char *msg, brain_pin_e brainPin, iomode_t mode)
void addConsoleActionI(const char *token, VoidInt callback)
Register a console command with one Integer parameter.
EepromDevice eepdev_24xx
static I2CEepromFileStream ifile
void brain_pin_markUnused(brain_pin_e brainPin)

Referenced by applyEngineType().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setEtbTestConfiguration()

void setEtbTestConfiguration ( )

remember that some H-bridges require 5v control lines, not just 3v logic outputs we have on stm32

Definition at line 160 of file custom_engine.cpp.

160 {
161 // VAG test ETB
163 // by the way this ETB has default position of ADC=74 which is about 4%
165
166 // yes, 30K - that's a test configuration
168
171
172
177 /**
178 * remember that some H-bridges require 5v control lines, not just 3v logic outputs we have on stm32
179 */
180 engineConfiguration->etbIo[0].directionPin1 = Gpio::C7; // Frankenso high-side in order to get 5v control
183
184#if EFI_ELECTRONIC_THROTTLE_BODY
186#endif /* EFI_ELECTRONIC_THROTTLE_BODY */
187
188 engineConfiguration->tps1_1AdcChannel = EFI_ADC_2; // PA2
190
191 // turning off other PWMs to simplify debugging
197
198 // no analog dividers - all sensors with 3v supply, naked discovery bench setup
200
201 // see also setDefaultEtbBiasCurve
202}
void setBoschVNH2SP30Curve()
void setCrankOperationMode()

Referenced by applyEngineType().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setFrankensoConfiguration()

void setFrankensoConfiguration ( )

Frankenso analog #1 PC2 ADC12 CLT Frankenso analog #2 PC1 ADC11 IAT Frankenso analog #3 PA0 ADC0 MAP Frankenso analog #4 PC3 ADC13 WBO / O2 Frankenso analog #5 PA2 ADC2 TPS Frankenso analog #6 PA1 ADC1 Frankenso analog #7 PA4 ADC4 Frankenso analog #8 PA3 ADC3 Frankenso analog #9 PA7 ADC7 Frankenso analog #10 PA6 ADC6 Frankenso analog #11 PC5 ADC15 Frankenso analog #12 PC4 ADC14 VBatt

http://rusefi.com/wiki/index.php?title=Manual:Hardware_Frankenso_board

Definition at line 73 of file custom_engine.cpp.

73 {
74#ifdef HW_FRANKENSO
76
78
79 /**
80 * Frankenso analog #1 PC2 ADC12 CLT
81 * Frankenso analog #2 PC1 ADC11 IAT
82 * Frankenso analog #3 PA0 ADC0 MAP
83 * Frankenso analog #4 PC3 ADC13 WBO / O2
84 * Frankenso analog #5 PA2 ADC2 TPS
85 * Frankenso analog #6 PA1 ADC1
86 * Frankenso analog #7 PA4 ADC4
87 * Frankenso analog #8 PA3 ADC3
88 * Frankenso analog #9 PA7 ADC7
89 * Frankenso analog #10 PA6 ADC6
90 * Frankenso analog #11 PC5 ADC15
91 * Frankenso analog #12 PC4 ADC14 VBatt
92 */
93 engineConfiguration->tps1_1AdcChannel = EFI_ADC_2; // PA2
94
96
99 engineConfiguration->afr.hwChannel = EFI_ADC_13;
100
101 // Frankenso hardware
104
105 /**
106 * http://rusefi.com/wiki/index.php?title=Manual:Hardware_Frankenso_board
107 */
108 // Frankenso low out #1: PE6
109 // Frankenso low out #2: PE5
110 // Frankenso low out #3: PD7 Main Relay
111 // Frankenso low out #4: PC13 Idle valve solenoid
112 // Frankenso low out #5: PE3
113 // Frankenso low out #6: PE4 fuel pump relay
114 // Frankenso low out #7: PE1 (do not use with discovery!)
115 // Frankenso low out #8: PE2 injector #2
116 // Frankenso low out #9: PB9 injector #1
117 // Frankenso low out #10: PE0 (do not use with discovery!)
118 // Frankenso low out #11: PB8 injector #3
119 // Frankenso low out #12: PB7 injector #4
120
124
126
130#ifndef EFI_INJECTOR_PIN3
132#else /* EFI_INJECTOR_PIN3 */
133 engineConfiguration->injectionPins[3] = EFI_INJECTOR_PIN3; // #4
134#endif /* EFI_INJECTOR_PIN3 */
135
136 setAlgorithm(engine_load_mode_e::LM_SPEED_DENSITY);
137
146
150 // set_ignition_pin 4 PE10
152
153 // todo: 8.2 or 10k?
154 engineConfiguration->vbattDividerCoeff = ((float) (10 + 33)) / 10 * 2;
155#endif // HW_FRANKENSO
156}
void commonFrankensoAnalogInputs()
void setAlgorithm(engine_load_mode_e algo)

Referenced by applyEngineType(), setDodgeRam1996(), setMiataNA6_MAP_Frankenso(), setVwAba(), and testEngine6451().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setL9779TestConfiguration()

void setL9779TestConfiguration ( )

◆ setRotary()

void setRotary ( )

set engine_type 107

Definition at line 425 of file custom_engine.cpp.

425 {
428
431
432 strcpy(engineConfiguration->engineMake, ENGINE_MAKE_MAZDA);
433 strcpy(engineConfiguration->engineCode, "13B");
434 strcpy(engineConfiguration->vehicleName, "test");
435
436 engineConfiguration->ignitionMode = IM_INDIVIDUAL_COILS;
437 engineConfiguration->injectionPins[2] = Gpio::Unassigned; // injector in default pinout
439
443}

Referenced by applyEngineType().

Here is the caller graph for this function:

◆ setTest33816EngineConfiguration()

void setTest33816EngineConfiguration ( )

set engine_type 103

Definition at line 448 of file custom_engine.cpp.

448 {
449
450 // grey
451 // default spi3mosiPin PB5
452 // white
453 // default spi3misoPin PB4
454 // violet
455 // default spi3sckPin PB3
456
457
460
465
466
467 // blue
469 // green
472 // yellow
474
476
477 // enable_spi 3
479 // Wire up spi3
483
485
487}

Referenced by applyEngineType().

Here is the caller graph for this function:

◆ setVrThresholdTest()

void setVrThresholdTest ( )

◆ testEngine6451()

void testEngine6451 ( )

Definition at line 674 of file custom_engine.cpp.

674 {
675#ifdef HW_FRANKENSO
677#endif
679
683 engineConfiguration->firingOrder = FO_1_5_3_6_2_4;
684 engineConfiguration->ignitionMode = IM_INDIVIDUAL_COILS;
686}
void setFrankensoConfiguration()
void setWholeTimingTable(angle_t value)
scaled_channel< int16_t, 10, 1 > ignitionIatCorrTable[IAT_IGN_CORR_LOAD_COUNT][IAT_IGN_CORR_COUNT]

Referenced by applyEngineType().

Here is the call graph for this function:
Here is the caller graph for this function:

Go to the source code of this file.