wideband/firmware/boards/port.h

90 lines
1.9 KiB
C
Raw Normal View History

2020-09-19 21:39:29 -07:00
#pragma once
2023-08-09 13:24:21 -07:00
#include <cstdint>
#include <cstddef>
#include "port_shared.h"
#include "wideband_config.h"
2021-02-25 22:57:44 -08:00
2023-06-20 16:58:47 -07:00
struct AnalogChannelResult
{
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;
};
2020-09-19 21:39:29 -07:00
struct AnalogResult
{
2023-06-20 16:58:47 -07:00
AnalogChannelResult ch[AFR_CHANNELS];
2020-12-11 00:25:50 -08:00
float VirtualGroundVoltageInt;
2020-09-19 21:39:29 -07:00
};
AnalogResult AnalogSample();
2021-02-25 22:57:44 -08:00
2022-12-02 23:31:07 -08:00
enum class SensorType : uint8_t {
LSU49 = 0,
LSU42 = 1,
LSUADV = 2,
};
2022-12-06 16:46:07 -08:00
enum class AuxOutputMode : uint8_t {
Afr0 = 0,
Afr1 = 1,
Lambda0 = 2,
Lambda1 = 3,
Egt0 = 4,
Egt1 = 5,
};
2021-03-14 00:22:58 -08:00
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();
2021-03-14 00:22:58 -08:00
// Actual configuration data
2022-12-01 15:40:36 -08:00
union {
struct {
uint8_t CanIndexOffset = 0;
// AUX0 and AUX1 curves
float auxOutBins[2][8];
float auxOutValues[2][8];
2022-12-06 16:46:07 -08:00
AuxOutputMode auxOutputSource[2];
2022-12-02 23:31:07 -08:00
SensorType sensorType;
2022-12-01 15:40:36 -08:00
} __attribute__((packed));
// pad to 256 bytes including tag
2023-03-27 23:08:05 -07:00
uint8_t pad[256 - sizeof(Tag)];
2022-12-01 15:40:36 -08:00
};
2021-03-14 00:22:58 -08:00
};
int InitConfiguration();
Configuration* GetConfiguration();
void SetConfiguration();
2021-03-14 00:22:58 -08:00
/* TS stuff */
2023-11-13 02:21:58 -08:00
uint8_t *GetConfigurationPtr();
2022-12-06 15:53:36 -08:00
size_t GetConfigurationSize();
int SaveConfiguration();
const char *getTsSignature();
void rebootNow();
void rebootToOpenblt();
// LSU4.2, LSU4.9 or LSU_ADV
SensorType GetSensorType();
void SetupESRDriver(SensorType sensor);
void ToggleESRDriver(SensorType sensor);
int GetESRSupplyR();