2022-01-08 17:13:15 -08:00
|
|
|
#include "pch.h"
|
2022-01-09 14:40:08 -08:00
|
|
|
#include "hellen_meta.h"
|
2022-01-08 17:13:15 -08:00
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2023-06-10 19:02:04 -07:00
|
|
|
void setHellen64Can() {
|
|
|
|
engineConfiguration->canTxPin = Gpio::B9;
|
|
|
|
engineConfiguration->canRxPin = Gpio::B8;
|
|
|
|
}
|
|
|
|
|
2023-06-08 15:42:42 -07:00
|
|
|
static OutputPin megaEn;
|
|
|
|
|
2023-07-28 21:02:05 -07:00
|
|
|
void setHellenEnPin(Gpio pin) {
|
2023-02-13 17:37:21 -08:00
|
|
|
static bool initialized = false;
|
2023-02-13 17:20:25 -08:00
|
|
|
if (!initialized) {
|
|
|
|
initialized = true;
|
2023-08-08 16:48:52 -07:00
|
|
|
megaEn.initPin("EN", pin);
|
2023-02-13 17:20:25 -08:00
|
|
|
megaEn.setValue(1);
|
|
|
|
}
|
2023-02-13 10:16:52 -08:00
|
|
|
}
|
|
|
|
|
2023-06-10 19:02:04 -07:00
|
|
|
void setHellenMegaEnPin() {
|
2023-09-17 10:53:15 -07:00
|
|
|
// H144_GP8 matches MM100_GP8 is used as PWR_EN on early mm100
|
2023-07-28 21:02:05 -07:00
|
|
|
setHellenEnPin(H144_GP8); // 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() {
|
2023-06-08 15:42:42 -07:00
|
|
|
// 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
|
|
|
|
megaEn.setValue(0);
|
|
|
|
// todo: 200ms is totally random what's the science for this sleep duration?
|
|
|
|
chThdSleepMilliseconds(200);
|
2023-05-13 14:08:55 -07:00
|
|
|
}
|
|
|
|
|
2023-02-27 09:43:47 -08: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
|
2023-02-27 09:43:47 -08:00
|
|
|
*/
|
2024-02-12 06:59:47 -08:00
|
|
|
extern OutputPin accelerometerChipSelect;
|
|
|
|
|
2024-02-12 06:55:04 -08:00
|
|
|
void hellenMegaAccelerometerPreInitCS2Pin() {
|
2024-02-12 06:59:47 -08:00
|
|
|
if (!accelerometerChipSelect.isInitialized()) {
|
|
|
|
accelerometerChipSelect.initPin("mm-CS2", Gpio::H_SPI1_CS2);
|
|
|
|
accelerometerChipSelect.setValue(1);
|
2023-02-27 09:43:47 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-05-09 16:33:47 -07:00
|
|
|
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);
|
2023-05-09 16:33:47 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-03 08:24:31 -08:00
|
|
|
void detectHellenBoardType() {
|
2024-02-01 04:46:16 -08:00
|
|
|
#ifndef EFI_BOOTLOADER
|
2023-12-14 13:43:25 -08:00
|
|
|
engine->engineState.hellenBoardId = hackHellenBoardId(detectHellenBoardId());
|
2024-02-01 04:46:16 -08:00
|
|
|
#endif /* EFI_BOOTLOADER */
|
2022-02-03 08:24:31 -08:00
|
|
|
}
|