This commit is contained in:
rusefi 2017-08-28 20:11:32 -04:00
parent cad09b732f
commit c153e9a1dd
4 changed files with 77 additions and 32 deletions

View File

@ -51,6 +51,7 @@
#include "fuel_math.h"
#include "settings.h"
#include "aux_pid.h"
#include "accelerometer.h"
#if HAL_USE_ADC || defined(__DOXYGEN__)
#include "AdcConfiguration.h"
@ -95,7 +96,6 @@ static msg_t csThread(void) {
chRegSetThreadName("status");
#if EFI_SHAFT_POSITION_INPUT || defined(__DOXYGEN__)
while (true) {
int rpm = getRpmE(engine);
int is_cranking = ENGINE(rpmCalculator).isCranking(PASS_ENGINE_PARAMETER_SIGNATURE);
bool is_running = ENGINE(rpmCalculator).isRunning(PASS_ENGINE_PARAMETER_SIGNATURE);
if (is_running) {
@ -279,6 +279,10 @@ static void periodicSlowCallback(Engine *engine) {
cylinderCleanupControl(engine);
#if EFI_MEMS || defined(__DOXYGEN__)
accelerometerPeriodicCallback(PASS_ENGINE_PARAMETER_SIGNATURE);
#endif /* EFI_MEMS */
scheduleNextSlowInvocation();
}

View File

@ -19,9 +19,28 @@
#include "accelerometer.h"
#include "lis302dl.h"
#include "hardware.h"
#include "mpu_util.h"
EXTERN_ENGINE;
#if EFI_MEMS || defined(__DOXYGEN__)
static SPIDriver *driver = &SPID1; // todo: make this configurable
static spi_device_e device = SPI_DEVICE_1;
/*
* SPI1 configuration structure.
* Speed 5.25MHz, CPHA=1, CPOL=1, 8bits frames, MSb transmitted first.
* The slave select line is the pin GPIOE_CS_SPI on the port GPIOE.
*/
static const SPIConfig accelerometerCfg = {
NULL,
/* HW dependent part.*/
GPIOE,
GPIOE_PIN3,
SPI_CR1_BR_0 | SPI_CR1_BR_1 | SPI_CR1_CPOL | SPI_CR1_CPHA
};
#endif /* EFI_MEMS */
void configureAccelerometerPins(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
engineConfiguration->LIS302DLCsPin = GPIOE_3;
// boardConfiguration->is_enabled_spi_1 = true; // we have a conflict with PA5 input pin
@ -33,6 +52,42 @@ void configureAccelerometerPins(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
}
#if EFI_MEMS || defined(__DOXYGEN__)
void accelerometerPeriodicCallback(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
// int8_t x = (int8_t)lis302dlReadRegister(driver, LIS302DL_OUTX);
// int8_t y = (int8_t)lis302dlReadRegister(driver, LIS302DL_OUTY);
}
void initMems(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
if (engineConfiguration->LIS302DLCsPin == GPIOA_0)
return; // temporary code to handle old configurations
if (engineConfiguration->LIS302DLCsPin == GPIO_UNASSIGNED)
return; // not used
// todo: driver = getSpiDevice(device);
turnOnSpi(device);
spiStart(driver, &accelerometerCfg);
initSpiCs((SPIConfig *)driver->config, engineConfiguration->LIS302DLCsPin);
// memsCs.initPin("LIS302 CS", engineConfiguration->LIS302DLCsPin);
// memsCfg.ssport = getHwPort("mmc", boardConfiguration->sdCardCsPin);
// memsCfg.sspad = getHwPin("mmc", boardConfiguration->sdCardCsPin);
/* LIS302DL initialization.*/
lis302dlWriteRegister(driver, LIS302DL_CTRL_REG1, 0x47); // enable device, enable XYZ
lis302dlWriteRegister(driver, LIS302DL_CTRL_REG2, 0x00); // 4 wire mode
lis302dlWriteRegister(driver, LIS302DL_CTRL_REG3, 0x00);
}
#endif /* EFI_MEMS */
void initAccelerometer(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
}
@ -44,32 +99,3 @@ float getLongitudinalAcceleration(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
float getTransverseAcceleration(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
return 0;
}
#if EFI_MEMS || defined(__DOXYGEN__)
static SPIDriver *spip = &SPID1; // todo: make this configurable
static spi_device_e device = SPI_DEVICE_1;
static OutputPin memsCs;
void initMems(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
if (engineConfiguration->LIS302DLCsPin == GPIOA_0)
return; // temporary code to handle old configurations
if (engineConfiguration->LIS302DLCsPin == GPIO_UNASSIGNED)
return; // not used
turnOnSpi(device);
memsCs.initPin("LIS302 CS", engineConfiguration->LIS302DLCsPin);
/* LIS302DL initialization.*/
lis302dlWriteRegister(spip, LIS302DL_CTRL_REG1, 0x47); // enable device, enable XYZ
lis302dlWriteRegister(spip, LIS302DL_CTRL_REG2, 0x00); // 4 wire mode
lis302dlWriteRegister(spip, LIS302DL_CTRL_REG3, 0x00);
int8_t x = (int8_t)lis302dlReadRegister(spip, LIS302DL_OUTX);
int8_t y = (int8_t)lis302dlReadRegister(spip, LIS302DL_OUTY);
}
#endif /* EFI_MEMS */

View File

@ -63,7 +63,7 @@ enable2ndByteCanID = false
; see PAGE_0_SIZE in C source code
; CONFIG_DEFINITION_START
; this section was generated automatically by ConfigDefinition.jar based on rusefi_config.txt Thu Aug 17 01:11:45 EDT 2017
; this section was generated automatically by ConfigDefinition.jar based on rusefi_config.txt Mon Aug 28 20:07:18 EDT 2017
pageSize = 16376
page = 1
@ -581,7 +581,8 @@ page = 1
unusedShortHere = scalar, S16, 2170, "seconds", 1, 0, 0, 6000, 0
iacByTpsTaper = scalar, S16, 2172, "percent", 1, 0, 0, 500, 0
;skipping unusedShort offset 2174
;skipping unusedalternatorControl offset 2176
LIS302DLCsPin = bits, U32, 2176, [0:6], "PA0", "PA1", "PA2", "PA3", "PA4", "PA5", "PA6", "PA7", "PA8", "PA9", "PA10", "PA11", "PA12", "PA13", "PA14", "PA15", "PB0", "PB1", "PB2", "PB3", "PB4", "PB5", "PB6", "PB7", "PB8", "PB9", "PB10", "PB11", "PB12", "PB13", "PB14", "PB15", "PC0", "PC1", "PC2", "PC3", "PC4", "PC5", "PC6", "PC7", "PC8", "PC9", "PC10", "PC11", "PC12", "PC13", "PC14", "PC15", "PD0", "PD1", "PD2", "PD3", "PD4", "PD5", "PD6", "PD7", "PD8", "PD9", "PD10", "PD11", "PD12", "PD13", "PD14", "PD15", "PE0", "PE1", "PE2", "PE3", "PE4", "PE5", "PE6", "PE7", "PE8", "PE9", "PE10", "PE11", "PE12", "PE13", "PE14", "PE15", "NONE", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID"
;skipping unusedalternatorControl offset 2180
tpsAccelLength = scalar, S32, 2184, "cycles", 1, 0, 1, 200, 0
tpsAccelEnrichmentThreshold = scalar, F32, 2188, "roc", 1, 0, 0, 200, 3
vvtOffset = scalar, F32, 2192, "value", 1, 0, -720, 1000, 1
@ -1024,6 +1025,8 @@ fileVersion = { 20161225 }
firmwareVersion = scalar,U32, 264, "version_f", 1, 0
fuelPidCorrection = scalar, F32, 268, "ms", 1, 0
coilDutyCycle = scalar, F32, 272, "perc", 1, 0
accelerationX = scalar, S16, 276, "acc", 100, 0
accelerationY = scalar, S16, 276, "acc", 100, 0
; todo: generate this section programatically
LM_PLAIN_MAF = {0},
@ -1349,6 +1352,8 @@ gaugeCategory = Sensors
internalMcuTemperatureGauge = internalMcuTemperature, "internal temperature", "C", 0, 100, 0, 0, 100, 100, 0, 0
VSSGauge = vehicleSpeedKph, "Speed", "kmh", 0, 200, 0, 1, 3, 4, 1, 1
pedalPositionGauge = pedalPosition,"Throttle Pedal Position", "%", 0, 120, 10, 10, 100, 100, 1, 1
accelerationXGauge = accelerationX, "accel X", "acc", -11, 11, 1.0, 1.2, 100, 100, 3, 1
accelerationYGauge = accelerationY, "accel Y", "acc", -11, 11, 1.0, 1.2, 100, 100, 3, 1
gaugeCategory = Spark Data
ignadvGauge = ignitionAdvance, "Ignition Advance 1", "degrees", -100, 100, -999, -999, 999, 999, 1, 1
@ -1458,6 +1463,9 @@ gaugeCategory = Fuel Data
entry = coilDutyCycle, "dwell: coil duty cycle", float,"%.3f"
entry = currentTargetAfr,"fuel: target AFR", float,"%.3f"
entry = accelerationX, "acc X", float,"%.2f"
entry = accelerationY, "acc Y", float,"%.2f"
entry = engineLoadAccelExtra, "fuel: engine load acceleration extra fuel",float, "%.3f"
entry = engineLoadDelta, "fuel: load change",float, "%.3f"

View File

@ -253,6 +253,8 @@ fileVersion = { 20161225 }
firmwareVersion = scalar,U32, 264, "version_f", 1, 0
fuelPidCorrection = scalar, F32, 268, "ms", 1, 0
coilDutyCycle = scalar, F32, 272, "perc", 1, 0
accelerationX = scalar, S16, 276, "acc", 100, 0
accelerationY = scalar, S16, 276, "acc", 100, 0
; todo: generate this section programatically
LM_PLAIN_MAF = {0},
@ -578,6 +580,8 @@ gaugeCategory = Sensors
internalMcuTemperatureGauge = internalMcuTemperature, "internal temperature", "C", 0, 100, 0, 0, 100, 100, 0, 0
VSSGauge = vehicleSpeedKph, "Speed", "kmh", 0, 200, 0, 1, 3, 4, 1, 1
pedalPositionGauge = pedalPosition,"Throttle Pedal Position", "%", 0, 120, 10, 10, 100, 100, 1, 1
accelerationXGauge = accelerationX, "accel X", "acc", -11, 11, 1.0, 1.2, 100, 100, 3, 1
accelerationYGauge = accelerationY, "accel Y", "acc", -11, 11, 1.0, 1.2, 100, 100, 3, 1
gaugeCategory = Spark Data
ignadvGauge = ignitionAdvance, "Ignition Advance 1", "degrees", -100, 100, -999, -999, 999, 999, 1, 1
@ -687,6 +691,9 @@ gaugeCategory = Fuel Data
entry = coilDutyCycle, @@GAUGE_NAME_DWELL_DUTY@@, float,"%.3f"
entry = currentTargetAfr,@@GAUGE_NAME_TARGET_AFR@@, float,"%.3f"
entry = accelerationX, "acc X", float,"%.2f"
entry = accelerationY, "acc Y", float,"%.2f"
entry = engineLoadAccelExtra, @@GAUGE_NAME_FUEL_EL_EXTRA@@,float, "%.3f"
entry = engineLoadDelta, "fuel: load change",float, "%.3f"