rusefi/firmware/config/boards/hellen/hellen_common.cpp

136 lines
3.7 KiB
C++
Raw Normal View History

#include "pch.h"
#include "hellen_meta.h"
void hellenWbo() {
engineConfiguration->enableAemXSeries = true;
}
2023-09-17 10:53:15 -07:00
// same for MM100, 144 and 176
2022-09-29 21:37:05 -07:00
void setHellenCan() {
2023-09-17 10:48:36 -07:00
engineConfiguration->canTxPin = H176_CAN_TX;
engineConfiguration->canRxPin = H176_CAN_RX;
2022-09-29 21:37:05 -07:00
}
2024-02-18 17:24:25 -08:00
static void init5vpDiag() {
#ifdef DIAG_5VP_PIN
2024-02-26 05:44:23 -08:00
static bool is5vpInit = false;
if (!is5vpInit) {
efiSetPadMode("5VP_STATE", DIAG_5VP_PIN, PAL_MODE_INPUT);
is5vpInit = true;
}
2024-02-18 17:24:25 -08:00
#endif // DIAG_5VP_PIN
}
2023-12-02 10:43:21 -08:00
void setHellenVbatt() {
// 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;
2024-02-18 17:44:26 -08:00
init5vpDiag(); // piggy back on popular 'setHellenVbatt' method
2023-12-02 10:43:21 -08:00
}
2023-06-10 19:02:04 -07:00
void setHellen64Can() {
engineConfiguration->canTxPin = Gpio::B9;
engineConfiguration->canRxPin = Gpio::B8;
}
static OutputPin megaEn;
// newer Hellen boards with megamodule have power management for SD cards etc, older Hellen board do not have that
PUBLIC_API_WEAK bool isBoardWithPowerManagement() {
return false;
}
2024-03-29 12:58:19 -07:00
bool getHellenBoardEnabled() {
return !isBoardWithPowerManagement() || megaEn.getLogicValue();
2024-03-29 12:58:19 -07:00
}
bool boardEnableSendWidebandInfo() {
// when board is powered down we should be more CANbus silent
2024-03-29 12:58:19 -07:00
return getHellenBoardEnabled();
}
static bool hellenEnPinInitialized = false;
/*PUBLIC_API_WEAK*/ bool fansDisabledByBoardStatus() {
return !getHellenBoardEnabled();
2024-03-24 10:28:56 -07:00
}
2024-04-23 13:42:47 -07:00
void hellenEnableEn(const char *msg) {
efiPrintf("Turning board ON [%s]", msg);
megaEn.setValue(1, /*isForce*/ true);
2024-03-23 12:39:13 -07:00
}
2024-04-23 13:42:47 -07:00
void hellenDisableEn(const char *msg) {
efiPrintf("Turning board off [%s]", msg);
megaEn.setValue(0, /*isForce*/ true);
2024-03-23 12:39:13 -07:00
}
2024-04-01 18:33:05 -07:00
void setHellenEnPin(Gpio pin, bool enableBoardOnStartUp) {
if (!hellenEnPinInitialized) {
hellenEnPinInitialized = true;
megaEn.initPin("EN", pin);
2024-04-01 18:33:05 -07:00
if (enableBoardOnStartUp) {
2024-04-23 13:42:47 -07:00
hellenEnableEn("start-up");
2024-04-01 18:33:05 -07:00
}
2023-02-13 17:20:25 -08:00
}
2023-02-13 10:16:52 -08:00
}
2024-04-01 18:33:05 -07:00
void setHellenMegaEnPin(bool enableBoardOnStartUp) {
2023-09-17 10:53:15 -07:00
// H144_GP8 matches MM100_GP8 is used as PWR_EN on early mm100
2024-04-01 18:33:05 -07:00
setHellenEnPin(H144_GP8, enableBoardOnStartUp); // OUT_PWR_EN
2023-06-10 19:02:04 -07:00
}
void setHellen64MegaEnPin() {
2023-10-11 09:13:04 -07:00
setHellenEnPin(Gpio::MM64_GP1); // OUT_PWR_EN
2023-06-10 19:02:04 -07:00
}
2023-05-13 14:08:55 -07:00
void hellenBoardStandBy() {
// we need to turn 'megaEn' and pause for a bit to make sure that WBO is off and does not wake main firmware right away
2024-03-23 12:39:13 -07:00
hellenDisableEn();
// todo: 200ms is totally random what's the science for this sleep duration?
chThdSleepMilliseconds(200);
2023-05-13 14:08:55 -07:00
}
/**
2024-02-12 06:55:04 -08:00
* We need to make sure that accelerometer device which physically exists does not conflict with SD card
* in case of shared SPI.
* We reply on specific order of execution here:
* 1) accelerometer pre-initialization into safe CS pin state
* 2) SD card initialization
* 3) accelerometer main initialization if accelerometer feature is desired
*/
extern OutputPin accelerometerChipSelect;
2024-02-12 06:55:04 -08:00
void hellenMegaAccelerometerPreInitCS2Pin() {
2024-02-26 09:25:21 -08:00
#if EFI_ONBOARD_MEMS
if (!accelerometerChipSelect.isInitialized()) {
accelerometerChipSelect.initPin("mm-CS2", Gpio::H_SPI1_CS2);
accelerometerChipSelect.setValue(1);
}
2024-02-26 09:25:21 -08:00
#endif // EFI_ONBOARD_MEMS
}
void configureHellenCanTerminator() {
static bool initialized = false;
static OutputPin terminatorControlPin;
if (!initialized) {
initialized = true;
2023-05-09 16:45:43 -07:00
terminatorControlPin.initPin("CAN-term", H_SPI3_CS); // todo: make this pin configurable
terminatorControlPin.setValue(engineConfiguration->boardUseCanTerminator);
}
}
void detectHellenBoardType() {
#ifndef EFI_BOOTLOADER
engine->engineState.hellenBoardId = hackHellenBoardId(detectHellenBoardId());
#endif /* EFI_BOOTLOADER */
}