#pragma once #include "hal.h" #include "port_shared.h" #include "wideband_config.h" struct AnalogResult { struct { float NernstVoltage; float PumpCurrentVoltage; /* for dual version - this is voltage on Heater-, switches between zero and Vbatt with heater PWM, * used for both Vbatt measurement and Heater diagnostic */ float BatteryVoltage; } ch[AFR_CHANNELS]; float VirtualGroundVoltageInt; }; AnalogResult AnalogSample(); enum class SensorType : uint8_t { LSU49 = 0, LSU42 = 1, LSUADV = 2, }; enum class AuxOutputMode : uint8_t { Afr0 = 0, Afr1 = 1, Lambda0 = 2, Lambda1 = 3, Egt0 = 4, Egt1 = 5, }; class Configuration { private: // Increment this any time the configuration format changes // It is stored along with the data to ensure that it has been written before static constexpr uint32_t ExpectedTag = 0xDEADBE01; uint32_t Tag = ExpectedTag; public: bool IsValid() const { return this->Tag == ExpectedTag; } void LoadDefaults(); // Actual configuration data union { struct { uint8_t CanIndexOffset = 0; // AUX0 and AUX1 curves float auxOutBins[2][8]; float auxOutValues[2][8]; AuxOutputMode auxOutputSource[2]; SensorType sensorType; } __attribute__((packed)); // pad to 256 bytes including tag uint8_t pad[256 - sizeof(Tag)]; }; }; int InitConfiguration(); Configuration* GetConfiguration(); void SetConfiguration(); /* TS stuff */ uint8_t *GetConfiguratiuonPtr(); size_t GetConfigurationSize(); void SaveConfiguration(); const char *getTsSignature(); // LSU4.2, LSU4.9 or LSU_ADV SensorType GetSensorType(); void SetupESRDriver(SensorType sensor); void ToggleESRDriver(SensorType sensor); int GetESRSupplyR();