2022-02-09 16:57:02 -08:00
|
|
|
/**
|
2022-12-01 19:51:51 -08:00
|
|
|
* @file board_configuration.cpp
|
2022-02-09 16:57:02 -08:00
|
|
|
*
|
|
|
|
*
|
2022-12-01 19:51:51 -08:00
|
|
|
* @brief Configuration defaults for the 4chan board
|
2022-02-09 16:57:02 -08:00
|
|
|
*
|
|
|
|
* @author andreika <prometheus.pcb@gmail.com>
|
|
|
|
* @author Andrey Belomutskiy, (c) 2012-2020
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "pch.h"
|
|
|
|
#include "hellen_meta.h"
|
2022-10-29 20:46:54 -07:00
|
|
|
#include "defaults.h"
|
2022-02-09 16:57:02 -08:00
|
|
|
|
|
|
|
static OutputPin alphaTachPullUp;
|
|
|
|
static OutputPin alphaTempPullUp;
|
|
|
|
static OutputPin alphaCrankPPullUp;
|
|
|
|
static OutputPin alphaCrankNPullUp;
|
2022-04-03 06:02:30 -07:00
|
|
|
static OutputPin alpha2stepPullDown;
|
|
|
|
static OutputPin alphaCamPullDown;
|
|
|
|
static OutputPin alphaCamVrPullUp;
|
|
|
|
static OutputPin alphaD2PullDown;
|
|
|
|
static OutputPin alphaD3PullDown;
|
|
|
|
static OutputPin alphaD4PullDown;
|
|
|
|
static OutputPin alphaD5PullDown;
|
2022-02-09 16:57:02 -08:00
|
|
|
|
|
|
|
static void setInjectorPins() {
|
2023-08-27 18:55:55 -07:00
|
|
|
engineConfiguration->injectionPins[0] = Gpio::H144_LS_1;
|
|
|
|
engineConfiguration->injectionPins[1] = Gpio::H144_LS_2;
|
|
|
|
engineConfiguration->injectionPins[2] = Gpio::H144_LS_3;
|
|
|
|
engineConfiguration->injectionPins[3] = Gpio::H144_LS_4;
|
2022-02-09 16:57:02 -08:00
|
|
|
|
2022-04-28 14:32:39 -07:00
|
|
|
engineConfiguration->clutchDownPin = Gpio::Unassigned;
|
2022-02-09 16:57:02 -08:00
|
|
|
engineConfiguration->clutchDownPinMode = PI_PULLDOWN;
|
|
|
|
engineConfiguration->launchActivationMode = CLUTCH_INPUT_LAUNCH;
|
2022-04-28 14:32:39 -07:00
|
|
|
engineConfiguration->malfunctionIndicatorPin = Gpio::Unassigned;
|
2022-02-09 16:57:02 -08:00
|
|
|
}
|
|
|
|
|
2022-03-29 17:49:23 -07:00
|
|
|
static void setupEtb() {
|
|
|
|
// TLE9201 driver
|
|
|
|
// This chip has three control pins:
|
|
|
|
// DIR - sets direction of the motor
|
|
|
|
// PWM - pwm control (enable high, coast low)
|
|
|
|
// DIS - disables motor (enable low)
|
|
|
|
|
|
|
|
// PWM pin
|
2023-08-27 20:10:13 -07:00
|
|
|
engineConfiguration->etbIo[0].controlPin = Gpio::H144_OUT_PWM2;
|
2022-03-29 17:49:23 -07:00
|
|
|
// DIR pin
|
2022-03-30 12:55:42 -07:00
|
|
|
engineConfiguration->etbIo[0].directionPin1 = H144_GP1;
|
2022-03-29 17:49:23 -07:00
|
|
|
// Disable pin
|
2022-03-30 12:55:42 -07:00
|
|
|
engineConfiguration->etbIo[0].disablePin = H144_GP2;
|
2022-03-29 17:49:23 -07:00
|
|
|
// Unused
|
2022-04-28 14:32:39 -07:00
|
|
|
engineConfiguration->etbIo[0].directionPin2 = Gpio::Unassigned;
|
2022-03-29 17:49:23 -07:00
|
|
|
|
|
|
|
// we only have pwm/dir, no dira/dirb
|
|
|
|
engineConfiguration->etb_use_two_wires = false;
|
|
|
|
}
|
|
|
|
|
2022-02-09 16:57:02 -08:00
|
|
|
static void setIgnitionPins() {
|
2023-08-27 18:55:55 -07:00
|
|
|
engineConfiguration->ignitionPins[0] = Gpio::H144_IGN_1;
|
|
|
|
engineConfiguration->ignitionPins[1] = Gpio::H144_IGN_2;
|
|
|
|
engineConfiguration->ignitionPins[2] = Gpio::H144_IGN_3;
|
|
|
|
engineConfiguration->ignitionPins[3] = Gpio::H144_IGN_4;
|
2022-02-09 16:57:02 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void setupVbatt() {
|
|
|
|
// 4.7k high side/4.7k low side = 2.0 ratio divider
|
|
|
|
engineConfiguration->analogInputDividerCoefficient = 2.0f;
|
|
|
|
|
|
|
|
// set vbatt_divider 5.835
|
|
|
|
// 33k / 6.8k
|
|
|
|
engineConfiguration->vbattDividerCoeff = (33 + 6.8) / 6.8; // 5.835
|
|
|
|
|
|
|
|
engineConfiguration->vbattAdcChannel = H144_IN_VBATT;
|
|
|
|
|
|
|
|
engineConfiguration->adcVcc = 3.29f;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void setupDefaultSensorInputs() {
|
|
|
|
// trigger inputs, hall
|
|
|
|
engineConfiguration->triggerInputPins[0] = H144_IN_CRANK;
|
|
|
|
engineConfiguration->triggerInputPins[1] = H144_IN_CAM;
|
2022-04-28 14:32:39 -07:00
|
|
|
engineConfiguration->camInputs[0] = Gpio::Unassigned;
|
2022-02-09 16:57:02 -08:00
|
|
|
|
2022-10-29 21:20:15 -07:00
|
|
|
setTPS1Inputs(H144_IN_TPS, H144_IN_AUX1);
|
2022-03-30 11:57:45 -07:00
|
|
|
|
2022-10-29 20:46:54 -07:00
|
|
|
setPPSInputs(H144_IN_PPS, H144_IN_AUX2);
|
2022-02-09 16:57:02 -08:00
|
|
|
|
2022-06-26 20:47:42 -07:00
|
|
|
// random values to have valid config
|
|
|
|
engineConfiguration->tps1SecondaryMin = 1000;
|
|
|
|
engineConfiguration->tps1SecondaryMax = 0;
|
|
|
|
|
2022-03-11 09:41:12 -08:00
|
|
|
engineConfiguration->mafAdcChannel = EFI_ADC_NONE;
|
2022-02-09 16:57:02 -08:00
|
|
|
|
|
|
|
engineConfiguration->afr.hwChannel = EFI_ADC_1;
|
|
|
|
|
|
|
|
engineConfiguration->clt.adcChannel = H144_IN_CLT;
|
|
|
|
|
|
|
|
engineConfiguration->iat.adcChannel = H144_IN_IAT;
|
|
|
|
}
|
|
|
|
|
2023-07-27 19:18:29 -07:00
|
|
|
static bool is_F_OrOlder() {
|
|
|
|
int16_t hellenBoardId = engine->engineState.hellenBoardId;
|
|
|
|
return hellenBoardId == BOARD_ID_4chan_d || hellenBoardId == BOARD_ID_4chan_e || hellenBoardId == BOARD_ID_4chan_f;
|
|
|
|
}
|
|
|
|
|
2022-02-09 16:57:02 -08:00
|
|
|
void boardInitHardware() {
|
2023-08-27 20:10:13 -07:00
|
|
|
alphaTachPullUp.initPin("a-tach", Gpio::H144_OUT_IO1);
|
|
|
|
alphaTempPullUp.initPin("a-temp", Gpio::H144_OUT_IO4);
|
|
|
|
alphaCrankPPullUp.initPin("a-crank-p", Gpio::H144_OUT_IO2);
|
|
|
|
alphaCrankNPullUp.initPin("a-crank-n", Gpio::H144_OUT_IO5);
|
|
|
|
alpha2stepPullDown.initPin("a-2step", Gpio::H144_OUT_IO7);
|
|
|
|
alphaCamVrPullUp.initPin("a-cam-vr", Gpio::H144_OUT_IO9);
|
2023-07-27 19:18:29 -07:00
|
|
|
if (is_F_OrOlder()) {
|
2023-08-27 20:10:13 -07:00
|
|
|
alphaD2PullDown.initPin("a-d2", Gpio::H144_LS_5);
|
|
|
|
alphaCamPullDown.initPin("a-cam", Gpio::H144_OUT_IO8);
|
|
|
|
alphaD3PullDown.initPin("a-d3", Gpio::H144_LS_6);
|
2023-07-27 19:18:29 -07:00
|
|
|
} else {
|
2023-08-27 20:10:13 -07:00
|
|
|
alphaD2PullDown.initPin("a-d2", Gpio::H144_OUT_IO13);
|
2023-07-28 16:08:04 -07:00
|
|
|
alphaCamPullDown.initPin("a-cam", H144_GP4);
|
2023-08-27 20:10:13 -07:00
|
|
|
alphaD3PullDown.initPin("a-d3", Gpio::H144_OUT_IO8);
|
2023-07-27 19:18:29 -07:00
|
|
|
}
|
2023-07-28 16:08:04 -07:00
|
|
|
|
2023-08-27 18:55:55 -07:00
|
|
|
alphaD4PullDown.initPin("a-d4", Gpio::H144_LS_7);
|
2023-08-27 20:10:13 -07:00
|
|
|
alphaD5PullDown.initPin("a-d5", Gpio::H144_LS_8);
|
2022-02-09 16:57:02 -08:00
|
|
|
boardOnConfigurationChange(nullptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
void boardOnConfigurationChange(engine_configuration_s * /*previousConfiguration*/) {
|
|
|
|
alphaTachPullUp.setValue(engineConfiguration->boardUseTachPullUp);
|
|
|
|
alphaTempPullUp.setValue(engineConfiguration->boardUseTempPullUp);
|
|
|
|
alphaCrankPPullUp.setValue(engineConfiguration->boardUseCrankPullUp);
|
|
|
|
alphaCrankNPullUp.setValue(engineConfiguration->boardUseCrankPullUp);
|
2022-04-03 06:02:30 -07:00
|
|
|
alpha2stepPullDown.setValue(engineConfiguration->boardUse2stepPullDown);
|
|
|
|
alphaCamPullDown.setValue(engineConfiguration->boardUseCamPullDown);
|
|
|
|
alphaCamVrPullUp.setValue(engineConfiguration->boardUseCamVrPullUp);
|
|
|
|
|
|
|
|
alphaD2PullDown.setValue(engineConfiguration->boardUseD2PullDown);
|
|
|
|
alphaD3PullDown.setValue(engineConfiguration->boardUseD3PullDown);
|
|
|
|
alphaD4PullDown.setValue(engineConfiguration->boardUseD4PullDown);
|
|
|
|
alphaD5PullDown.setValue(engineConfiguration->boardUseD5PullDown);
|
2022-02-09 16:57:02 -08:00
|
|
|
}
|
|
|
|
|
2023-06-05 00:01:37 -07:00
|
|
|
#include "hellen_leds_144.cpp"
|
|
|
|
|
2022-02-09 16:57:02 -08:00
|
|
|
void setBoardConfigOverrides() {
|
|
|
|
setupVbatt();
|
2022-06-23 06:15:51 -07:00
|
|
|
|
2023-07-27 19:18:29 -07:00
|
|
|
if (is_F_OrOlder()) {
|
2023-08-27 20:10:13 -07:00
|
|
|
setHellenEnPin(Gpio::H144_OUT_IO3);
|
2023-05-07 06:59:52 -07:00
|
|
|
setHellenSdCardSpi2();
|
|
|
|
} else {
|
2023-07-28 21:02:05 -07:00
|
|
|
setHellenMegaEnPin();
|
2023-05-07 06:59:52 -07:00
|
|
|
// rev G and newer uses hellen mega-module
|
|
|
|
setHellenSdCardSpi1();
|
2023-05-07 08:23:26 -07:00
|
|
|
configureHellenMegaAccCS2Pin();
|
2023-05-07 06:59:52 -07:00
|
|
|
}
|
2022-02-09 16:57:02 -08:00
|
|
|
|
2023-02-15 12:01:41 -08:00
|
|
|
setDefaultHellenAtPullUps();
|
2022-02-09 16:57:02 -08:00
|
|
|
|
2022-09-29 21:37:56 -07:00
|
|
|
setHellenCan();
|
2022-02-09 16:57:02 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Board-specific configuration defaults.
|
|
|
|
*
|
|
|
|
* See also setDefaultEngineConfiguration
|
|
|
|
*
|
|
|
|
* @todo Add your board-specific code, if any.
|
|
|
|
*/
|
|
|
|
void setBoardDefaultConfiguration() {
|
|
|
|
setInjectorPins();
|
|
|
|
setIgnitionPins();
|
2022-03-29 17:49:23 -07:00
|
|
|
setupEtb();
|
2023-07-28 16:08:04 -07:00
|
|
|
if (is_F_OrOlder()) {
|
2023-08-29 16:43:27 -07:00
|
|
|
engineConfiguration->tachOutputPin = Gpio::H144_OUT_IO13;
|
2023-08-27 20:10:13 -07:00
|
|
|
engineConfiguration->vvtPins[0] = Gpio::H144_OUT_PWM7;
|
|
|
|
engineConfiguration->vvtPins[1] = Gpio::H144_OUT_PWM8;
|
2023-07-28 16:08:04 -07:00
|
|
|
} else {
|
2023-08-27 18:55:55 -07:00
|
|
|
engineConfiguration->vvtPins[0] = Gpio::H144_IGN_7;
|
|
|
|
engineConfiguration->vvtPins[1] = Gpio::H144_IGN_8;
|
|
|
|
engineConfiguration->tachOutputPin = Gpio::H144_GP3;
|
2023-07-28 16:08:04 -07:00
|
|
|
}
|
|
|
|
|
2022-02-09 16:57:02 -08:00
|
|
|
|
2023-06-29 16:04:37 -07:00
|
|
|
// todo: should be conditional? currently set best for newest boards based on MegaModule
|
2023-04-30 16:16:29 -07:00
|
|
|
setHellenMMbaro();
|
2023-08-27 20:10:13 -07:00
|
|
|
engineConfiguration->map.sensor.hwChannel = H144_IN_MAP3; // On-board MAP
|
2023-06-29 16:33:36 -07:00
|
|
|
engineConfiguration->map.sensor.type = MT_MPXH6400;
|
2023-06-29 16:04:37 -07:00
|
|
|
// engineConfiguration->baroSensor.type = MT_MPXH6400;
|
2023-08-27 20:10:13 -07:00
|
|
|
// engineConfiguration->baroSensor.hwChannel = H144_IN_MAP3; // On-board MAP
|
2023-06-29 16:04:37 -07:00
|
|
|
|
2022-03-13 08:54:17 -07:00
|
|
|
engineConfiguration->boardUseTempPullUp = true;
|
|
|
|
|
2022-04-28 14:32:39 -07:00
|
|
|
engineConfiguration->acSwitch = Gpio::Unassigned;
|
2023-08-27 18:55:55 -07:00
|
|
|
engineConfiguration->fuelPumpPin = Gpio::H144_OUT_IO12;
|
|
|
|
engineConfiguration->fanPin = Gpio::H144_OUT_IO11;
|
|
|
|
engineConfiguration->mainRelayPin = Gpio::H144_OUT_IO10;
|
|
|
|
engineConfiguration->boostControlPin = Gpio::H144_OUT_PWM3;
|
2022-02-09 16:57:02 -08:00
|
|
|
|
|
|
|
// "required" hardware is done - set some reasonable defaults
|
|
|
|
setupDefaultSensorInputs();
|
|
|
|
|
2023-03-27 00:58:18 -07:00
|
|
|
engineConfiguration->cylindersCount = 4;
|
|
|
|
engineConfiguration->firingOrder = FO_1_3_4_2;
|
2022-02-09 16:57:02 -08:00
|
|
|
|
|
|
|
engineConfiguration->ignitionMode = IM_INDIVIDUAL_COILS; // IM_WASTED_SPARK
|
2023-01-21 05:08:52 -08:00
|
|
|
|
|
|
|
|
2022-02-09 16:57:02 -08:00
|
|
|
|
|
|
|
engineConfiguration->launchActivationMode = CLUTCH_INPUT_LAUNCH;
|
2022-04-28 14:32:39 -07:00
|
|
|
// ? engineConfiguration->malfunctionIndicatorPin = Gpio::G4; //1E - Check Engine Light
|
2023-08-27 20:10:13 -07:00
|
|
|
engineConfiguration->vrThreshold[0].pin = Gpio::H144_OUT_PWM6;
|
|
|
|
engineConfiguration->vrThreshold[1].pin = Gpio::H144_OUT_PWM4;
|
2022-02-09 16:57:02 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
void boardPrepareForStop() {
|
|
|
|
// Wake on the CAN RX pin
|
|
|
|
palEnableLineEvent(PAL_LINE(GPIOD, 0), PAL_EVENT_MODE_RISING_EDGE);
|
|
|
|
}
|
2022-09-29 21:37:56 -07:00
|
|
|
|
|
|
|
static Gpio OUTPUTS[] = {
|
2023-08-27 18:55:55 -07:00
|
|
|
Gpio::H144_LS_1,
|
|
|
|
Gpio::H144_LS_2,
|
|
|
|
Gpio::H144_LS_3,
|
|
|
|
Gpio::H144_LS_4,
|
2023-08-29 18:23:30 -07:00
|
|
|
// vvt1
|
|
|
|
Gpio::H144_IGN_7,
|
|
|
|
// vvt2
|
|
|
|
Gpio::H144_IGN_8,
|
2022-09-29 21:37:56 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
int getBoardMetaOutputsCount() {
|
|
|
|
return efi::size(OUTPUTS);
|
|
|
|
}
|
|
|
|
|
|
|
|
Gpio* getBoardMetaOutputs() {
|
|
|
|
return OUTPUTS;
|
|
|
|
}
|