DAC with Lua #5601
This commit is contained in:
parent
64989643ac
commit
215284c7bc
|
@ -25,6 +25,8 @@ DDEFS += -DEFI_KLINE=TRUE
|
|||
DDEFS += -DKLINE_SERIAL_DEVICE_RX=Gpio::C11 -DKLINE_SERIAL_DEVICE_TX=Gpio::C10
|
||||
DDEFS += -DKLINE_SERIAL_DEVICE=SD3
|
||||
|
||||
DDEFS += -DEFI_DAC=TRUE -DHAL_USE_DAC=TRUE -DSTM32_DAC_USE_DAC1_CH1=TRUE
|
||||
|
||||
DDEFS += -DBOARD_TLE9104_COUNT=2
|
||||
|
||||
# We are running on Frankenso hardware!
|
||||
|
|
|
@ -19,6 +19,10 @@
|
|||
#define EFI_BOOST_CONTROL TRUE
|
||||
#endif
|
||||
|
||||
#ifndef EFI_DAC
|
||||
#define EFI_DAC FALSE
|
||||
#endif
|
||||
|
||||
#ifndef EFI_LAUNCH_CONTROL
|
||||
#define EFI_LAUNCH_CONTROL TRUE
|
||||
#endif
|
||||
|
|
|
@ -0,0 +1,41 @@
|
|||
#include "dac.h"
|
||||
|
||||
#include <rusefi/math.h>
|
||||
|
||||
#if EFI_DAC
|
||||
|
||||
static DACConfig dacConfig = {
|
||||
.init = 4095U, /* full VCC */
|
||||
.datamode = DAC_DHRM_12BIT_RIGHT,
|
||||
.cr = 0
|
||||
};
|
||||
|
||||
Dac::Dac(DACDriver& driver)
|
||||
: m_driver(&driver)
|
||||
{
|
||||
}
|
||||
|
||||
void Dac::Start(DACConfig& config)
|
||||
{
|
||||
dacStart(m_driver, &config);
|
||||
}
|
||||
|
||||
void Dac::SetVoltage(int channel, float voltage) {
|
||||
voltage = clampF(0, voltage, engineConfiguration->adcVcc);
|
||||
m_voltageFloat[channel] = voltage;
|
||||
|
||||
dacPutChannelX(m_driver, channel, voltage / engineConfiguration->adcVcc * ((1 << 12) - 1));
|
||||
}
|
||||
|
||||
float Dac::GetLastVoltage(int channel)
|
||||
{
|
||||
return m_voltageFloat[channel];
|
||||
}
|
||||
|
||||
static Dac dac(DACD1);
|
||||
|
||||
void initDac() {
|
||||
dac.Start(dacConfig);
|
||||
}
|
||||
|
||||
#endif // EFI_DAC
|
|
@ -0,0 +1,25 @@
|
|||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
#include "pch.h"
|
||||
|
||||
#if EFI_DAC
|
||||
|
||||
class Dac
|
||||
{
|
||||
public:
|
||||
Dac(DACDriver& driver);
|
||||
|
||||
void Start(DACConfig& config);
|
||||
void SetVoltage(int channel, float volage);
|
||||
float GetLastVoltage(int channel);
|
||||
|
||||
private:
|
||||
DACDriver* const m_driver;
|
||||
float m_voltageFloat[2];
|
||||
};
|
||||
|
||||
void initDac();
|
||||
|
||||
#endif
|
|
@ -12,6 +12,7 @@ HW_LAYER_DRIVERS_INC = \
|
|||
HW_LAYER_DRIVERS_CORE = \
|
||||
|
||||
HW_LAYER_DRIVERS_CORE_CPP = \
|
||||
$(DRIVERS_DIR)/dac.cpp \
|
||||
$(DRIVERS_DIR)/gpio/core.cpp \
|
||||
$(DRIVERS_DIR)/sent/sent.cpp \
|
||||
$(DRIVERS_DIR)/i2c/i2c_bb.cpp \
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
#include "idle_thread.h"
|
||||
#include "odometer.h"
|
||||
#include "kline.h"
|
||||
#include "dac.h"
|
||||
|
||||
#if EFI_PROD_CODE
|
||||
#include "mpu_util.h"
|
||||
|
@ -579,6 +580,10 @@ void initHardware() {
|
|||
|
||||
initKLine();
|
||||
|
||||
#if EFI_DAC
|
||||
initDac();
|
||||
#endif
|
||||
|
||||
calcFastAdcIndexes();
|
||||
|
||||
startHardware();
|
||||
|
|
|
@ -77,8 +77,12 @@
|
|||
* DAC driver system settings.
|
||||
*/
|
||||
#define STM32_DAC_DUAL_MODE FALSE
|
||||
#ifndef STM32_DAC_USE_DAC1_CH1
|
||||
#define STM32_DAC_USE_DAC1_CH1 FALSE
|
||||
#endif
|
||||
#ifndef STM32_DAC_USE_DAC1_CH2
|
||||
#define STM32_DAC_USE_DAC1_CH2 FALSE
|
||||
#endif
|
||||
#define STM32_DAC_DAC1_CH1_IRQ_PRIORITY PRECISE_SCHEDULING_TIMER_PRIORITY + 6
|
||||
#define STM32_DAC_DAC1_CH2_IRQ_PRIORITY PRECISE_SCHEDULING_TIMER_PRIORITY + 6
|
||||
#define STM32_DAC_DAC1_CH1_DMA_PRIORITY 2
|
||||
|
|
|
@ -1558,7 +1558,9 @@ pin_input_mode_e[LUA_DIGITAL_INPUT_COUNT iterate] luaDigitalInputPinModes;
|
|||
adc_channel_e throttleInletPressureChannel;Place the sensor before the throttle, but after any turbocharger/supercharger and intercoolers if fitted. Uses the same calibration as the MAP sensor.
|
||||
adc_channel_e compressorDischargePressureChannel;Place the sensor after the turbocharger/supercharger, but before any intercoolers if fitted. Uses the same calibration as the MAP sensor.
|
||||
|
||||
uint8_t[254] mainUnusedEnd;;"units", 1, 0, 0, 1, 0
|
||||
Gpio[2 iterate] dacOutputPins;
|
||||
|
||||
uint8_t[250] mainUnusedEnd;;"units", 1, 0, 0, 1, 0
|
||||
|
||||
! end of engine_configuration_s
|
||||
end_struct
|
||||
|
|
|
@ -2024,6 +2024,7 @@ menuDialog = main
|
|||
|
||||
subMenu = std_separator
|
||||
subMenu = parkingLot, "Experimental/Broken"
|
||||
subMenu = parkingLot2, "Experimental 2"
|
||||
subMenu = antiLagDialog, "Anti-Lag ALS"
|
||||
subMenu = rotaryDialog, "Rotary"
|
||||
subMenu = throttleEffectiveArea, "Throttle effective area"
|
||||
|
@ -4576,6 +4577,10 @@ dialog = tcuControls, "Transmission Settings"
|
|||
field = "etbDutyThreshold", etbDutyThreshold
|
||||
field = "etbDutyShutdownThreshold", etbDutyShutdownThreshold
|
||||
|
||||
dialog = parkingLot2, "Experimental 2"
|
||||
field = dacOutputPins1, dacOutputPins1
|
||||
field = dacOutputPins2, dacOutputPins2
|
||||
|
||||
dialog = parkingLot, "Experimental/Broken"
|
||||
; field = uiMode, uiMode
|
||||
field = kLineBaudRate, kLineBaudRate
|
||||
|
|
Loading…
Reference in New Issue