refactoring
This commit is contained in:
parent
f9ee71d87c
commit
16fec68cf2
|
@ -1,5 +1,16 @@
|
||||||
/*
|
/*
|
||||||
* accelerometer.cpp
|
* @file accelerometer.cpp
|
||||||
|
*
|
||||||
|
* stm32f4discovery has MEMS LIS302DL
|
||||||
|
* www.st.com/resource/en/datasheet/lis302dl.pdf
|
||||||
|
*
|
||||||
|
* SPI1
|
||||||
|
* LIS302DL_SPI_SCK PA5
|
||||||
|
* LIS302DL_SPI_MISO PA6
|
||||||
|
* LIS302DL_SPI_MOSI PA7
|
||||||
|
* LIS302DL_SPI_CS_PIN PE3
|
||||||
|
*
|
||||||
|
*
|
||||||
*
|
*
|
||||||
* @date May 19, 2016
|
* @date May 19, 2016
|
||||||
* @author Andrey Belomutskiy, (c) 2012-2017
|
* @author Andrey Belomutskiy, (c) 2012-2017
|
||||||
|
@ -33,3 +44,32 @@ float getLongitudinalAcceleration(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
|
||||||
float getTransverseAcceleration(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
|
float getTransverseAcceleration(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
|
||||||
return 0;
|
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 */
|
||||||
|
|
|
@ -11,13 +11,13 @@ HW_LAYER_EMS = $(HW_LAYER_EGT) \
|
||||||
$(PROJECT_DIR)/hw_layer/stm32f4/stm32f4xx_hal_flash_ex.c
|
$(PROJECT_DIR)/hw_layer/stm32f4/stm32f4xx_hal_flash_ex.c
|
||||||
|
|
||||||
HW_LAYER_EMS_CPP = $(HW_LAYER_EGT_CPP) \
|
HW_LAYER_EMS_CPP = $(HW_LAYER_EGT_CPP) \
|
||||||
|
$(PROJECT_DIR)/hw_layer/accelerometer.cpp \
|
||||||
$(PROJECT_DIR)/hw_layer/pin_repository.cpp \
|
$(PROJECT_DIR)/hw_layer/pin_repository.cpp \
|
||||||
$(PROJECT_DIR)/hw_layer/microsecond_timer.cpp \
|
$(PROJECT_DIR)/hw_layer/microsecond_timer.cpp \
|
||||||
$(PROJECT_DIR)/hw_layer/digital_input_hw.cpp \
|
$(PROJECT_DIR)/hw_layer/digital_input_hw.cpp \
|
||||||
$(PROJECT_DIR)/hw_layer/hardware.cpp \
|
$(PROJECT_DIR)/hw_layer/hardware.cpp \
|
||||||
$(PROJECT_DIR)/hw_layer/neo6m.cpp \
|
$(PROJECT_DIR)/hw_layer/neo6m.cpp \
|
||||||
$(PROJECT_DIR)/hw_layer/mmc_card.cpp \
|
$(PROJECT_DIR)/hw_layer/mmc_card.cpp \
|
||||||
$(PROJECT_DIR)/hw_layer/mems.cpp \
|
|
||||||
$(PROJECT_DIR)/hw_layer/lcd/lcd_HD44780.cpp \
|
$(PROJECT_DIR)/hw_layer/lcd/lcd_HD44780.cpp \
|
||||||
$(PROJECT_DIR)/hw_layer/adc_inputs.cpp \
|
$(PROJECT_DIR)/hw_layer/adc_inputs.cpp \
|
||||||
$(PROJECT_DIR)/hw_layer/board_test.cpp \
|
$(PROJECT_DIR)/hw_layer/board_test.cpp \
|
||||||
|
@ -30,6 +30,5 @@ HW_LAYER_EMS_CPP = $(HW_LAYER_EGT_CPP) \
|
||||||
$(PROJECT_DIR)/hw_layer/servo.cpp \
|
$(PROJECT_DIR)/hw_layer/servo.cpp \
|
||||||
$(PROJECT_DIR)/hw_layer/io_pins.cpp \
|
$(PROJECT_DIR)/hw_layer/io_pins.cpp \
|
||||||
$(PROJECT_DIR)/hw_layer/stm32f4/mpu_util.cpp \
|
$(PROJECT_DIR)/hw_layer/stm32f4/mpu_util.cpp \
|
||||||
$(PROJECT_DIR)/hw_layer/rtc_helper.cpp \
|
$(PROJECT_DIR)/hw_layer/rtc_helper.cpp
|
||||||
$(PROJECT_DIR)/hw_layer/accelerometer.cpp
|
|
||||||
|
|
|
@ -1,14 +1,6 @@
|
||||||
/*
|
/*
|
||||||
* @file mems.cpp
|
* @file mems.cpp
|
||||||
*
|
*
|
||||||
* stm32f4discovery has MEMS LIS302DL
|
|
||||||
* www.st.com/resource/en/datasheet/lis302dl.pdf
|
|
||||||
*
|
|
||||||
* SPI1
|
|
||||||
* LIS302DL_SPI_SCK PA5
|
|
||||||
* LIS302DL_SPI_MISO PA6
|
|
||||||
* LIS302DL_SPI_MOSI PA7
|
|
||||||
* LIS302DL_SPI_CS_PIN PE3
|
|
||||||
*
|
*
|
||||||
* @date Aug 17, 2017
|
* @date Aug 17, 2017
|
||||||
* @author Andrey Belomutskiy, (c) 2012-2017
|
* @author Andrey Belomutskiy, (c) 2012-2017
|
||||||
|
@ -20,31 +12,3 @@
|
||||||
|
|
||||||
EXTERN_ENGINE;
|
EXTERN_ENGINE;
|
||||||
|
|
||||||
#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 */
|
|
||||||
|
|
Loading…
Reference in New Issue