hook up lps25 on proteus (#2418)
* hook up lps25 * it would help to include all the files * unguard some stuff * unguard more * guarding * s * guard * only register if init worked Co-authored-by: Matthew Kennedy <makenne@microsoft.com>
This commit is contained in:
parent
f0098d8bc1
commit
6aaf02be15
|
@ -236,6 +236,11 @@ void Engine::periodicSlowCallback(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
|
|||
|
||||
slowCallBackWasInvoked = true;
|
||||
|
||||
#if HW_PROTEUS
|
||||
void baroUpdate();
|
||||
baroUpdate();
|
||||
#endif
|
||||
|
||||
#if ANALOG_HW_CHECK_MODE
|
||||
efiAssertVoid(OBD_PCM_Processor_Fault, isAdcChannelValid(CONFIG(clt).adcChannel), "No CLT setting");
|
||||
efitimesec_t secondsNow = getTimeNowSeconds();
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
#include "Lps25Sensor.h"
|
||||
#include "global.h"
|
||||
|
||||
Lps25Sensor::Lps25Sensor(Lps25& sensor)
|
||||
: StoredValueSensor(SensorType::BarometricPressure, MS2NT(1000))
|
||||
, m_sensor(&sensor)
|
||||
{
|
||||
}
|
||||
|
||||
void Lps25Sensor::update() {
|
||||
auto result = m_sensor->readPressureKpa();
|
||||
|
||||
if (result) {
|
||||
setValidValue(result.Value, getTimeNowNt());
|
||||
} else {
|
||||
invalidate();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
#pragma once
|
||||
|
||||
#include "stored_value_sensor.h"
|
||||
#include "lps25.h"
|
||||
|
||||
class Lps25Sensor : public StoredValueSensor {
|
||||
public:
|
||||
explicit Lps25Sensor(Lps25& sensor);
|
||||
void update();
|
||||
|
||||
void showInfo(Logging* logger, const char* sensorName) const override;
|
||||
|
||||
private:
|
||||
Lps25* m_sensor;
|
||||
};
|
|
@ -3,6 +3,7 @@
|
|||
#include "functional_sensor.h"
|
||||
#include "redundant_sensor.h"
|
||||
#include "rpm_calculator.h"
|
||||
#include "Lps25Sensor.h"
|
||||
#include "linear_func.h"
|
||||
#include "resistance_func.h"
|
||||
#include "thermistor_func.h"
|
||||
|
@ -46,6 +47,10 @@ void RpmCalculator::showInfo(Logging* logger, const char* /*sensorName*/) const
|
|||
);
|
||||
}
|
||||
|
||||
void Lps25Sensor::showInfo(Logging* logger, const char* sensorName) const {
|
||||
// TODO
|
||||
}
|
||||
|
||||
void LinearFunc::showInfo(Logging* logger, float testRawValue) const {
|
||||
scheduleMsg(logger, " Linear function slope: %.2f offset: %.2f min: %.1f max: %.1f", m_a, m_b, m_minOutput, m_maxOutput);
|
||||
const auto [valid, value] = convert(testRawValue);
|
||||
|
|
|
@ -16,6 +16,7 @@ CONTROLLERS_SENSORS_SRC_CPP = $(PROJECT_DIR)/controllers/sensors/thermistors.cp
|
|||
$(PROJECT_DIR)/controllers/sensors/AemXSeriesLambda.cpp \
|
||||
$(PROJECT_DIR)/cotnrollers/sensors/flex_sensor.cpp \
|
||||
$(PROJECT_DIR)/controllers/sensors/software_knock.cpp \
|
||||
$(PROJECT_DIR)/controllers/sensors/Lps25Sensor.cpp \
|
||||
$(PROJECT_DIR)/controllers/sensors/converters/linear_func.cpp \
|
||||
$(PROJECT_DIR)/controllers/sensors/converters/resistance_func.cpp \
|
||||
$(PROJECT_DIR)/controllers/sensors/converters/thermistor_func.cpp
|
||||
|
|
|
@ -8,28 +8,35 @@
|
|||
|
||||
#include "i2c_bb.h"
|
||||
|
||||
#if EFI_PROD_CODE
|
||||
|
||||
#include "io_pins.h"
|
||||
#include "efi_gpio.h"
|
||||
|
||||
void BitbangI2c::sda_high() {
|
||||
#if EFI_PROD_CODE
|
||||
palSetPad(m_sdaPort, m_sdaPin);
|
||||
#endif
|
||||
}
|
||||
|
||||
void BitbangI2c::sda_low() {
|
||||
#if EFI_PROD_CODE
|
||||
palClearPad(m_sdaPort, m_sdaPin);
|
||||
#endif
|
||||
}
|
||||
|
||||
void BitbangI2c::scl_high() {
|
||||
#if EFI_PROD_CODE
|
||||
palSetPad(m_sclPort, m_sclPin);
|
||||
#endif
|
||||
}
|
||||
|
||||
void BitbangI2c::scl_low() {
|
||||
#if EFI_PROD_CODE
|
||||
palClearPad(m_sclPort, m_sclPin);
|
||||
#endif
|
||||
}
|
||||
|
||||
void BitbangI2c::init(brain_pin_e scl, brain_pin_e sda) {
|
||||
#if EFI_PROD_CODE
|
||||
if (m_sdaPort) return;
|
||||
|
||||
efiSetPadMode("i2c", scl, PAL_MODE_OUTPUT_OPENDRAIN); //PAL_STM32_OTYPE_OPENDRAIN
|
||||
|
@ -40,6 +47,7 @@ void BitbangI2c::init(brain_pin_e scl, brain_pin_e sda) {
|
|||
|
||||
m_sdaPort = getHwPort("i2c", sda);
|
||||
m_sdaPin = getHwPin("i2c", sda);
|
||||
#endif
|
||||
|
||||
// Both lines idle high
|
||||
scl_high();
|
||||
|
@ -99,8 +107,12 @@ bool BitbangI2c::readBit() {
|
|||
waitQuarterBit();
|
||||
waitQuarterBit();
|
||||
|
||||
#if EFI_PROD_CODE
|
||||
// Read just before we set the clock low (ie, as late as possible)
|
||||
bool val = palReadPad(m_sdaPort, m_sdaPin);
|
||||
#else
|
||||
bool val = false;
|
||||
#endif
|
||||
|
||||
scl_low();
|
||||
waitQuarterBit();
|
||||
|
@ -209,5 +221,3 @@ void BitbangI2c::writeRegister(uint8_t addr, uint8_t reg, uint8_t val) {
|
|||
|
||||
write(addr, buf, 2);
|
||||
}
|
||||
|
||||
#endif // EFI_PROD_CODE
|
||||
|
|
|
@ -9,8 +9,9 @@
|
|||
#pragma once
|
||||
|
||||
#if EFI_PROD_CODE
|
||||
|
||||
#include "hal.h"
|
||||
#endif
|
||||
|
||||
#include "rusefi_hw_enums.h"
|
||||
#include <cstdint>
|
||||
#include <cstddef>
|
||||
|
@ -53,10 +54,10 @@ private:
|
|||
// Wait for 1/4 of a bit time
|
||||
void waitQuarterBit();
|
||||
|
||||
#if EFI_PROD_CODE
|
||||
ioportid_t m_sclPort = 0;
|
||||
ioportmask_t m_sclPin = 0;
|
||||
ioportid_t m_sdaPort = 0;
|
||||
ioportmask_t m_sdaPin = 0;
|
||||
#endif
|
||||
};
|
||||
|
||||
#endif // EFI_PROD_CODE
|
||||
|
|
|
@ -6,8 +6,6 @@
|
|||
* @author Matthew Kennedy, (c) 2020
|
||||
*/
|
||||
|
||||
#if EFI_PROD_CODE
|
||||
|
||||
#include "lps25.h"
|
||||
|
||||
static constexpr uint8_t addr = 0x5C;
|
||||
|
@ -51,6 +49,10 @@ bool Lps25::init(brain_pin_e scl, brain_pin_e sda) {
|
|||
}
|
||||
|
||||
expected<float> Lps25::readPressureKpa() {
|
||||
if (!m_hasInit) {
|
||||
return unexpected;
|
||||
}
|
||||
|
||||
// First read the status reg to check if there are data available
|
||||
uint8_t sr = m_i2c.readRegister(addr, REG_Status);
|
||||
|
||||
|
@ -99,5 +101,3 @@ expected<float> Lps25::readPressureKpa() {
|
|||
|
||||
return kilopascal;
|
||||
}
|
||||
|
||||
#endif // EFI_PROD_CODE
|
||||
|
|
|
@ -8,8 +8,6 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#if EFI_PROD_CODE
|
||||
|
||||
#include "i2c_bb.h"
|
||||
|
||||
#include "expected.h"
|
||||
|
@ -25,5 +23,3 @@ private:
|
|||
BitbangI2c m_i2c;
|
||||
bool m_hasInit = false;
|
||||
};
|
||||
|
||||
#endif // EFI_PROD_CODE
|
||||
|
|
|
@ -27,6 +27,7 @@ void initThermistors(DECLARE_CONFIG_PARAMETER_SIGNATURE);
|
|||
void initCanSensors();
|
||||
void initLambda(DECLARE_ENGINE_PARAMETER_SIGNATURE);
|
||||
void initFlexSensor(DECLARE_CONFIG_PARAMETER_SIGNATURE);
|
||||
void initBaro();
|
||||
|
||||
// Sensor reconfiguration
|
||||
void reconfigureVbatt(DECLARE_CONFIG_PARAMETER_SIGNATURE);
|
||||
|
|
|
@ -8,3 +8,4 @@ INIT_SRC_CPP = $(PROJECT_DIR)/init/sensor/init_sensors.cpp \
|
|||
$(PROJECT_DIR)/init/sensor/init_map.cpp \
|
||||
$(PROJECT_DIR)/init/sensor/init_flex.cpp \
|
||||
$(PROJECT_DIR)/init/sensor/init_vbatt.cpp \
|
||||
$(PROJECT_DIR)/init/sensor/init_baro.cpp \
|
||||
|
|
|
@ -0,0 +1,27 @@
|
|||
#include "engine.h"
|
||||
#include "Lps25Sensor.h"
|
||||
|
||||
#include "rusefi_hw_enums.h"
|
||||
|
||||
static Lps25 device;
|
||||
static Lps25Sensor sensor(device);
|
||||
|
||||
void initBaro() {
|
||||
// If there's already an external (analog) baro sensor configured,
|
||||
// don't configure the internal one.
|
||||
if (Sensor::hasSensor(SensorType::BarometricPressure)) {
|
||||
return;
|
||||
}
|
||||
|
||||
#if HW_PROTEUS
|
||||
if (device.init(GPIOB_10, GPIOB_11)) {
|
||||
sensor.Register();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void baroUpdate() {
|
||||
#if EFI_PROD_CODE
|
||||
sensor.update();
|
||||
#endif
|
||||
}
|
|
@ -20,6 +20,7 @@ void initNewSensors(Logging* logger DECLARE_ENGINE_PARAMETER_SUFFIX) {
|
|||
initThermistors(PASS_CONFIG_PARAMETER_SIGNATURE);
|
||||
initLambda(PASS_ENGINE_PARAMETER_SIGNATURE);
|
||||
initFlexSensor(PASS_CONFIG_PARAMETER_SIGNATURE);
|
||||
initBaro();
|
||||
|
||||
// Init CLI functionality for sensors (mocking)
|
||||
initSensorCli(logger);
|
||||
|
|
Loading…
Reference in New Issue