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 
4 void hellenWbo() {
6 }
7 
8 // same for MM100, 144 and 176
9 void setHellenCan() {
10  engineConfiguration->canTxPin = H176_CAN_TX;
11  engineConfiguration->canRxPin = H176_CAN_RX;
12 }
13 
14 static void init5vpDiag() {
15 #ifdef DIAG_5VP_PIN
16 static bool is5vpInit = false;
17  if (!is5vpInit) {
18  efiSetPadMode("5VP_STATE", DIAG_5VP_PIN, PAL_MODE_INPUT);
19  is5vpInit = true;
20  }
21 #endif // DIAG_5VP_PIN
22 }
23 
25  // 4.7k high side/4.7k low side = 2.0 ratio divider
27 
28  // set vbatt_divider 5.835
29  // 33k / 6.8k
30  engineConfiguration->vbattDividerCoeff = (33 + 6.8) / 6.8; // 5.835
31 
32  engineConfiguration->vbattAdcChannel = H144_IN_VBATT;
33 
34  engineConfiguration->adcVcc = 3.29f;
35 
36  init5vpDiag(); // piggy back on popular 'setHellenVbatt' method
37 }
38 
42 }
43 
45 
46 // newer Hellen boards with megamodule have power management for SD cards etc, older Hellen board do not have that
47 PUBLIC_API_WEAK bool isBoardWithPowerManagement() {
48  return false;
49 }
50 
53 }
54 
56  // when board is powered down we should be more CANbus silent
57  return getHellenBoardEnabled();
58 }
59 
60 static bool hellenEnPinInitialized = false;
61 
62 /*PUBLIC_API_WEAK*/ bool fansDisabledByBoardStatus() {
63  return !getHellenBoardEnabled();
64 }
65 
66 void hellenEnableEn(const char *msg) {
67  efiPrintf("Turning board ON [%s]", msg);
68  megaEn.setValue(1, /*isForce*/ true);
69 }
70 
71 void hellenDisableEn(const char *msg) {
72  efiPrintf("Turning board off [%s]", msg);
73  megaEn.setValue(0, /*isForce*/ true);
74 }
75 
76 void setHellenEnPin(Gpio pin, bool enableBoardOnStartUp) {
79  megaEn.initPin("EN", pin);
80  if (enableBoardOnStartUp) {
81  hellenEnableEn("start-up");
82  }
83  }
84 }
85 
86 void setHellenMegaEnPin(bool enableBoardOnStartUp) {
87  // H144_GP8 matches MM100_GP8 which is used as PWR_EN on early mm100
88  setHellenEnPin(H144_GP8, enableBoardOnStartUp); // OUT_PWR_EN
89 }
90 
92  setHellenEnPin(Gpio::MM64_GP1); // OUT_PWR_EN
93 }
94 
96  // 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
98  // todo: 200ms is totally random what's the science for this sleep duration?
99  chThdSleepMilliseconds(200);
100 }
101 
102 /**
103  * We need to make sure that accelerometer device which physically exists does not conflict with SD card
104  * in case of shared SPI.
105  * We reply on specific order of execution here:
106  * 1) accelerometer pre-initialization into safe CS pin state
107  * 2) SD card initialization
108  * 3) accelerometer main initialization if accelerometer feature is desired
109  */
111 
114  // weird order of operations? i guess it does not really matter
116 }
117 
119 #if EFI_ONBOARD_MEMS
121  accelerometerChipSelect.initPin("mm-CS2", Gpio::H_SPI1_CS2);
123  }
124 #endif // EFI_ONBOARD_MEMS
125 }
126 
128  static bool initialized = false;
129  static OutputPin terminatorControlPin;
130  if (!initialized) {
131  initialized = true;
132  terminatorControlPin.initPin("CAN-term", H_SPI3_CS); // todo: make this pin configurable
133  terminatorControlPin.setValue(engineConfiguration->boardUseCanTerminator);
134  }
135 }
136 
138 #ifndef EFI_BOOTLOADER
140 #endif /* EFI_BOOTLOADER */
141 }
void efiSetPadMode(const char *msg, brain_pin_e brainPin, iomode_t mode)
EngineState engineState
Definition: engine.h:315
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:690
bool getLogicValue() const
Definition: efi_gpio.cpp:646
void setValue(const char *msg, int logicValue, bool isForce=false)
Definition: efi_gpio.cpp:583
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