From b9546e3596e6cc1c4b8d2580e5ab873d9821b8c9 Mon Sep 17 00:00:00 2001 From: rusefi Date: Thu, 17 Aug 2017 02:49:07 -0400 Subject: [PATCH] #473 --- firmware/config/stm32f4ems/efifeatures.h | 4 ++++ firmware/hw_layer/mems.cpp | 27 +++++++++++++++++++++++- firmware/hw_layer/mems.h | 2 +- 3 files changed, 31 insertions(+), 2 deletions(-) diff --git a/firmware/config/stm32f4ems/efifeatures.h b/firmware/config/stm32f4ems/efifeatures.h index 89fdd81984..9d2b1e56ed 100644 --- a/firmware/config/stm32f4ems/efifeatures.h +++ b/firmware/config/stm32f4ems/efifeatures.h @@ -116,6 +116,10 @@ #define EFI_CJ125 TRUE +#if !defined(EFI_MEMS) || defined(__DOXYGEN__) + #define EFI_MEMS TRUE +#endif + #define EFI_INTERNAL_ADC TRUE #define EFI_DENSO_ADC FALSE diff --git a/firmware/hw_layer/mems.cpp b/firmware/hw_layer/mems.cpp index 5aa7ab407b..42eb20afbf 100644 --- a/firmware/hw_layer/mems.cpp +++ b/firmware/hw_layer/mems.cpp @@ -14,10 +14,35 @@ */ #include "mems.h" +#include "lis302dl.h" +EXTERN_ENGINE; void initMemsPins(DECLARE_ENGINE_PARAMETER_SIGNATURE) { + engineConfiguration->LIS302DLCsPin = GPIOE_3; + boardConfiguration->is_enabled_spi_1 = true; +} + +#if EFI_MEMS || defined(__DOXYGEN__) + +static SPIDriver *spip = &SPID1; // todo: make this configurable +static OutputPin memsCs; + +void initMems(DECLARE_ENGINE_PARAMETER_SIGNATURE) { + + engineConfiguration->LIS302DLCsPin = GPIOE_3; // temporary code + + memsCs.initPin("LIS302 CS", engineConfiguration->LIS302DLCsPin); + + + /* LIS302DL initialization.*/ + lis302dlWriteRegister(spip, LIS302DL_CTRL_REG1, 0x43); + lis302dlWriteRegister(spip, LIS302DL_CTRL_REG2, 0x00); + 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 */ diff --git a/firmware/hw_layer/mems.h b/firmware/hw_layer/mems.h index 8c81b98292..c552f0e735 100644 --- a/firmware/hw_layer/mems.h +++ b/firmware/hw_layer/mems.h @@ -9,7 +9,7 @@ #define HW_LAYER_MEMS_H_ #include "main.h" -#include "engine_configuration.h" +#include "engine.h" void initMemsPins(DECLARE_ENGINE_PARAMETER_SIGNATURE);