rusEFI
The most advanced open source ECU
hellen_common.cpp
Go to the documentation of this file.
1 #include "pch.h"
2 #include "hellen_meta.h"
3 #include "adc_subscription.h"
4 
5 void hellenWbo() {
7 }
8 
9 // same for MM100, 144 and 176
10 void setHellenCan() {
11  engineConfiguration->canTxPin = H176_CAN_TX;
12  engineConfiguration->canRxPin = H176_CAN_RX;
13 }
14 
15 static void init5vpDiag() {
16 #ifdef DIAG_5VP_PIN
17 static bool is5vpInit = false;
18  if (!is5vpInit) {
19  efiSetPadMode("5VP_STATE", DIAG_5VP_PIN, PAL_MODE_INPUT);
20  is5vpInit = true;
21  }
22 #endif // DIAG_5VP_PIN
23 }
24 
26  // 4.7k high side/4.7k low side = 2.0 ratio divider
28 
29  // set vbatt_divider 5.835
30  // 33k / 6.8k
31  engineConfiguration->vbattDividerCoeff = (33 + 6.8) / 6.8; // 5.835
32 
33  engineConfiguration->vbattAdcChannel = H144_IN_VBATT;
34 
35  engineConfiguration->adcVcc = 3.29f;
36 
37  init5vpDiag(); // piggy back on popular 'setHellenVbatt' method
38 }
39 
43 }
44 
46 
47 // newer Hellen boards with megamodule have power management for SD cards etc, older Hellen board do not have that
48 PUBLIC_API_WEAK bool isBoardWithPowerManagement() {
49  return false;
50 }
51 
54 }
55 
57  // when board is powered down we should be more CANbus silent
58  return getHellenBoardEnabled();
59 }
60 
61 static bool hellenEnPinInitialized = false;
62 
63 /*PUBLIC_API_WEAK*/ bool fansDisabledByBoardStatus() {
64  return !getHellenBoardEnabled();
65 }
66 
67 void hellenEnableEn(const char *msg) {
68  efiPrintf("Turning board ON [%s]", msg);
69  megaEn.setValue(1, /*isForce*/ true);
71 }
72 
73 void hellenDisableEn(const char *msg) {
74  efiPrintf("Turning board off [%s]", msg);
75  megaEn.setValue(0, /*isForce*/ true);
77 }
78 
79 void setHellenEnPin(Gpio pin, bool enableBoardOnStartUp) {
82  megaEn.initPin("EN", pin);
83  if (enableBoardOnStartUp) {
84  hellenEnableEn("start-up");
85  }
86  }
87 }
88 
89 void setHellenMegaEnPin(bool enableBoardOnStartUp) {
90  // H144_GP8 matches MM100_GP8 which is used as PWR_EN on early mm100
91  setHellenEnPin(H144_GP8, enableBoardOnStartUp); // OUT_PWR_EN
92 }
93 
95  setHellenEnPin(Gpio::MM64_GP1); // OUT_PWR_EN
96 }
97 
99  // 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
100  hellenDisableEn();
101  // todo: 200ms is totally random what's the science for this sleep duration?
102  chThdSleepMilliseconds(200);
103 }
104 
105 /**
106  * We need to make sure that accelerometer device which physically exists does not conflict with SD card
107  * in case of shared SPI.
108  * We reply on specific order of execution here:
109  * 1) accelerometer pre-initialization into safe CS pin state
110  * 2) SD card initialization
111  * 3) accelerometer main initialization if accelerometer feature is desired
112  */
114 
117  // weird order of operations? i guess it does not really matter
119 }
120 
122 #if EFI_ONBOARD_MEMS
124  accelerometerChipSelect.initPin("mm-CS2", Gpio::H_SPI1_CS2);
126  }
127 #endif // EFI_ONBOARD_MEMS
128 }
129 
131  static bool initialized = false;
132  static OutputPin terminatorControlPin;
133  if (!initialized) {
134  initialized = true;
135  terminatorControlPin.initPin("CAN-term", H_SPI3_CS); // todo: make this pin configurable
136  terminatorControlPin.setValue(engineConfiguration->boardUseCanTerminator);
137  }
138 }
139 
141 #ifndef EFI_BOOTLOADER
143 #endif /* EFI_BOOTLOADER */
144 }
void efiSetPadMode(const char *msg, brain_pin_e brainPin, iomode_t mode)
static void ResetFilters()
EngineState engineState
Definition: engine.h:312
Single output pin reference and state.
Definition: efi_output.h:50
void initPin(const char *msg, brain_pin_e brainPin, pin_output_mode_e outputMode, bool forceInitWithFatalError=false)
Definition: efi_gpio.cpp:689
bool getLogicValue() const
Definition: efi_gpio.cpp:645
void setValue(const char *msg, int logicValue, bool isForce=false)
Definition: efi_gpio.cpp:581
bool isInitialized() const
Definition: efi_gpio.cpp:536
Gpio
Engine * engine
int hackHellenBoardId(int detectedId)
int detectHellenBoardId()
void hellenBoardStandBy()
void setHellen64MegaEnPin()
PUBLIC_API_WEAK bool isBoardWithPowerManagement()
void configureHellenCanTerminator()
void hellenMegaSdWithAccelerometer()
void hellenEnableEn(const char *msg)
static void init5vpDiag()
void setHellenCan()
void hellenMegaAccelerometerPreInitCS2Pin()
OutputPin accelerometerChipSelect
void hellenWbo()
bool boardEnableSendWidebandInfo()
bool getHellenBoardEnabled()
void setHellen64Can()
void hellenDisableEn(const char *msg)
void detectHellenBoardType()
void setHellenVbatt()
void setHellenEnPin(Gpio pin, bool enableBoardOnStartUp)
void setHellenMegaEnPin(bool enableBoardOnStartUp)
static bool hellenEnPinInitialized
bool fansDisabledByBoardStatus()
static OutputPin megaEn
static void setHellenSdCardSpi1()
Definition: hellen_meta.h:277
engine_configuration_s * engineConfiguration
static int initialized
brain_pin_e pin
Definition: stm32_adc.cpp:15