From 9f4b66052be15007649dc7598cecfed4e56dc31c Mon Sep 17 00:00:00 2001 From: Matthew Kennedy Date: Thu, 2 Jan 2025 21:55:04 -0800 Subject: [PATCH] we have main relay sensing! --- .../config/boards/atlas/board_configuration.cpp | 17 +++++++++++++++++ .../controllers/algo/engine_configuration.cpp | 2 ++ .../controllers/algo/engine_configuration.h | 6 ++++-- firmware/init/sensor/init_sensors.cpp | 3 +++ 4 files changed, 26 insertions(+), 2 deletions(-) diff --git a/firmware/config/boards/atlas/board_configuration.cpp b/firmware/config/boards/atlas/board_configuration.cpp index 5be9e4fb7b..93846ef93c 100644 --- a/firmware/config/boards/atlas/board_configuration.cpp +++ b/firmware/config/boards/atlas/board_configuration.cpp @@ -1,5 +1,9 @@ #include "pch.h" +#include "adc_subscription.h" +#include "functional_sensor.h" +#include "linear_func.h" + static const brain_pin_e injPins[] = { Gpio::G5, Gpio::G6, @@ -149,3 +153,16 @@ void preHalInit() { efiSetPadMode("SDMMC", Gpio::C12, PAL_MODE_ALTERNATE(0xc)); efiSetPadMode("SDMMC", Gpio::D2, PAL_MODE_ALTERNATE(0xc)); } + +void initBoardSensors() { + static LinearFunc mrSenseFunc; + static FunctionalSensor mrSenseSensor(SensorType::MainRelayVoltage, MS2NT(100)); + + // 82k high side/10k low side = 9.2 + const float mrSenseRatio = (92.0f / 10.0f); + + mrSenseFunc.configure(0, 0, 1, mrSenseRatio, 0, 50); + mrSenseSensor.setFunction(mrSenseFunc); + AdcSubscription::SubscribeSensor(mrSenseSensor, EFI_ADC_16, /*bandwidth*/ 20, /*ratio*/ 1); + mrSenseSensor.Register(); +} diff --git a/firmware/controllers/algo/engine_configuration.cpp b/firmware/controllers/algo/engine_configuration.cpp index 21b7f85451..0cb0474aaa 100644 --- a/firmware/controllers/algo/engine_configuration.cpp +++ b/firmware/controllers/algo/engine_configuration.cpp @@ -937,3 +937,5 @@ __attribute__((weak)) void setBoardConfigOverrides() { } __attribute__((weak)) int getBoardMetaOutputsCount() { return 0; } __attribute__((weak)) Gpio* getBoardMetaOutputs() { return nullptr; } + +__attribute__((weak)) void initBoardSensors() { } diff --git a/firmware/controllers/algo/engine_configuration.h b/firmware/controllers/algo/engine_configuration.h index 8a32343d9c..9ef1eed8ba 100644 --- a/firmware/controllers/algo/engine_configuration.h +++ b/firmware/controllers/algo/engine_configuration.h @@ -58,8 +58,10 @@ void resetConfigurationExt(engine_type_e engineType); void rememberCurrentConfiguration(); #endif /* __cplusplus */ -void setBoardDefaultConfiguration(void); -void setBoardConfigOverrides(void); +void setBoardDefaultConfiguration(); +void setBoardConfigOverrides(); +// Init any sensors built in to the board that don't need config +void initBoardSensors(); void boardOnConfigurationChange(engine_configuration_s *previousConfiguration); Gpio getCommsLedPin(); Gpio getWarningLedPin(); diff --git a/firmware/init/sensor/init_sensors.cpp b/firmware/init/sensor/init_sensors.cpp index 013025c1fd..60b042a975 100644 --- a/firmware/init/sensor/init_sensors.cpp +++ b/firmware/init/sensor/init_sensors.cpp @@ -25,6 +25,9 @@ static void deInitAuxDigital() { } void initNewSensors() { + // First (optionally) init any sensors built in to the board that don't need config + initBoardSensors(); + reconfigureSensors(); initBaro();