Deduplicate mpu_util headers (#1187)

* this flag did nothing

* header dedupe

* mre fix again

* get all dependencies in mpu_util.h

* guard can/spi

* more dedupe

* pragma once

Co-authored-by: Matthew Kennedy <makenne@microsoft.com>
This commit is contained in:
Matthew Kennedy 2020-03-13 15:48:22 -07:00 committed by GitHub
parent fc051fd2ca
commit bb9c851a07
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 196 additions and 322 deletions

View File

@ -1,7 +1,8 @@
HW_LAYER_EGT = $(PROJECT_DIR)/hw_layer/serial_over_usb/usbcfg.c \
$(PROJECT_DIR)/hw_layer/serial_over_usb/usbconsole.c
HW_INC = hw_layer/$(CPU_HWLAYER)
HW_INC = hw_layer/$(CPU_HWLAYER) \
$(PROJECT_DIR)/hw_layer/ports
HW_LAYER_EGT_CPP = \
$(PROJECT_DIR)/hw_layer/max31855.cpp

View File

@ -1,92 +0,0 @@
/**
* @file mpu_util.h
*
* @date Jul 27, 2014
* @author Andrey Belomutskiy, (c) 2012-2020
* @author andreika <prometheus.pcb@gmail.com>
*/
#ifndef MPU_UTIL_H_
#define MPU_UTIL_H_
// we are lucky - all CAN pins use the same AF
#define EFI_CAN_RX_AF 9
#define EFI_CAN_TX_AF 9
// burnout or 'Burn Out'
typedef enum {
BOR_Level_None = 0,
BOR_Level_1 = 1,
BOR_Level_2 = 2,
BOR_Level_3 = 3
} BOR_Level_t;
typedef enum {
BOR_Result_Ok = 0x00,
BOR_Result_Error
} BOR_Result_t;
BOR_Level_t BOR_Get(void);
BOR_Result_t BOR_Set(BOR_Level_t BORValue);
#ifndef ADC_TwoSamplingDelay_5Cycles
#define ADC_TwoSamplingDelay_5Cycles ((uint32_t)0x00000000)
#endif
#ifndef ADC_TwoSamplingDelay_20Cycles
#define ADC_TwoSamplingDelay_20Cycles ((uint32_t)0x00000F00)
#endif
#ifndef ADC_CR2_SWSTART
#define ADC_CR2_SWSTART ((uint32_t)0x40000000)
#endif
#define SPI_CR1_8BIT_MODE 0
#define SPI_CR2_8BIT_MODE 0
#define SPI_CR1_16BIT_MODE SPI_CR1_DFF
#define SPI_CR2_16BIT_MODE 0
// TODO
#define SPI_CR1_24BIT_MODE 0
#define SPI_CR2_24BIT_MODE 0
void baseMCUInit(void);
void turnOnSpi(spi_device_e device);
void jump_to_bootloader();
#ifdef __cplusplus
extern "C"
{
#endif /* __cplusplus */
// these need to be declared C style for the linker magic to work
void DebugMonitorVector(void);
void UsageFaultVector(void);
void BusFaultVector(void);
void HardFaultVector(void);
#ifdef __cplusplus
}
#endif /* __cplusplus */
#if HAL_USE_SPI
void initSpiModule(SPIDriver *driver, brain_pin_e sck, brain_pin_e miso,
brain_pin_e mosi,
int sckMode,
int mosiMode,
int misoMode);
/**
* @see getSpiDevice
*/
void initSpiCs(SPIConfig *spiConfig, brain_pin_e csPin);
#endif /* HAL_USE_SPI */
bool isValidCanTxPin(brain_pin_e pin);
bool isValidCanRxPin(brain_pin_e pin);
#if HAL_USE_CAN
CANDriver * detectCanDevice(brain_pin_e pinRx, brain_pin_e pinTx);
#endif /* HAL_USE_CAN */
#endif /* MPU_UTIL_H_ */

View File

@ -0,0 +1,38 @@
/**
* @file mpu_util.h
*
* @date Jul 27, 2014
* @author Andrey Belomutskiy, (c) 2012-2020
* @author andreika <prometheus.pcb@gmail.com>
*/
#pragma once
typedef enum {
BOR_Level_None = 0,
BOR_Level_1 = 1,
BOR_Level_2 = 2,
BOR_Level_3 = 3
} BOR_Level_t;
#ifndef ADC_TwoSamplingDelay_5Cycles
#define ADC_TwoSamplingDelay_5Cycles ((uint32_t)0x00000000)
#endif
#ifndef ADC_TwoSamplingDelay_20Cycles
#define ADC_TwoSamplingDelay_20Cycles ((uint32_t)0x00000F00)
#endif
#ifndef ADC_CR2_SWSTART
#define ADC_CR2_SWSTART ((uint32_t)0x40000000)
#endif
#define SPI_CR1_8BIT_MODE 0
#define SPI_CR2_8BIT_MODE 0
#define SPI_CR1_16BIT_MODE SPI_CR1_DFF
#define SPI_CR2_16BIT_MODE 0
// TODO
#define SPI_CR1_24BIT_MODE 0
#define SPI_CR2_24BIT_MODE 0

View File

@ -0,0 +1,52 @@
#pragma once
#include "rusefi_enums.h"
#include "port_mpu_util.h"
// Base MCU
void baseMCUInit(void);
void jump_to_bootloader();
// CAN bus
#if HAL_USE_CAN
bool isValidCanTxPin(brain_pin_e pin);
bool isValidCanRxPin(brain_pin_e pin);
CANDriver * detectCanDevice(brain_pin_e pinRx, brain_pin_e pinTx);
#endif // HAL_USE_CAN
// SPI
#if HAL_USE_SPI
void initSpiModule(SPIDriver *driver, brain_pin_e sck, brain_pin_e miso,
brain_pin_e mosi,
int sckMode,
int mosiMode,
int misoMode);
void initSpiCs(SPIConfig *spiConfig, brain_pin_e csPin);
void turnOnSpi(spi_device_e device);
#endif // HAL_USE_SPI
// Brownout Reset
typedef enum {
BOR_Result_Ok = 0x00,
BOR_Result_Error
} BOR_Result_t;
BOR_Level_t BOR_Get(void);
BOR_Result_t BOR_Set(BOR_Level_t BORValue);
#ifdef __cplusplus
extern "C"
{
#endif /* __cplusplus */
// these need to be declared with C linkage - they're called from C and asm files
void DebugMonitorVector(void);
void UsageFaultVector(void);
void BusFaultVector(void);
void HardFaultVector(void);
#ifdef __cplusplus
}
#endif /* __cplusplus */

View File

@ -0,0 +1,63 @@
/**
* @file stm32_common_mpu_util.h
* @brief Low level common STM32 header
*
* @date Aug 3, 2019
* @author Andrey Belomutskiy, (c) 2012-2020
*/
#pragma once
#include "device_mpu_util.h"
typedef enum {
BOR_Level_None = OB_BOR_OFF, // 0x0C=12 Supply voltage ranges from 1.62 to 2.10 V
BOR_Level_1 = OB_BOR_LEVEL1, // 0x08 Supply voltage ranges from 2.10 to 2.40 V
BOR_Level_2 = OB_BOR_LEVEL2, // 0x04 Supply voltage ranges from 2.40 to 2.70 V
BOR_Level_3 = OB_BOR_LEVEL3 // 0x00 Supply voltage ranges from 2.70 to 3.60 V
} BOR_Level_t;
// we are lucky - all CAN pins use the same AF
#define EFI_CAN_RX_AF 9
#define EFI_CAN_TX_AF 9
#ifndef GPIO_AF_TIM1
#define GPIO_AF_TIM1 1
#endif
#ifndef GPIO_AF_TIM2
#define GPIO_AF_TIM2 1
#endif
#ifndef GPIO_AF_TIM3
#define GPIO_AF_TIM3 2
#endif
#ifndef GPIO_AF_TIM4
#define GPIO_AF_TIM4 2
#endif
#ifndef GPIO_AF_TIM5
#define GPIO_AF_TIM5 2
#endif
#ifndef GPIO_AF_TIM8
#define GPIO_AF_TIM8 3
#endif
#ifndef GPIO_AF_TIM9
#define GPIO_AF_TIM9 3
#endif
// F4/F7 have the same ADC peripheral
#ifndef ADC_TwoSamplingDelay_5Cycles
#define ADC_TwoSamplingDelay_5Cycles ((uint32_t)0x00000000)
#endif
#ifndef ADC_TwoSamplingDelay_20Cycles
#define ADC_TwoSamplingDelay_20Cycles ((uint32_t)0x00000F00)
#endif
#ifndef ADC_CR2_SWSTART
#define ADC_CR2_SWSTART ((uint32_t)0x40000000)
#endif

View File

@ -1,36 +0,0 @@
/**
* @file stm32_common_mpu_util.h
* @brief Low level common STM32 header
*
* @date Aug 3, 2019
* @author Andrey Belomutskiy, (c) 2012-2020
*/
// burnout or 'Burn Out'
#include "rusefi_enums.h"
typedef enum {
BOR_Level_None = OB_BOR_OFF, // 0x0C=12 Supply voltage ranges from 1.62 to 2.10 V
BOR_Level_1 = OB_BOR_LEVEL1, // 0x08 Supply voltage ranges from 2.10 to 2.40 V
BOR_Level_2 = OB_BOR_LEVEL2, // 0x04 Supply voltage ranges from 2.40 to 2.70 V
BOR_Level_3 = OB_BOR_LEVEL3 // 0x00 Supply voltage ranges from 2.70 to 3.60 V
} BOR_Level_t;
typedef enum {
BOR_Result_Ok = 0x00,
BOR_Result_Error
} BOR_Result_t;
BOR_Level_t BOR_Get(void);
BOR_Result_t BOR_Set(BOR_Level_t BORValue);
void baseMCUInit(void);
void turnOnSpi(spi_device_e device);
void jump_to_bootloader();
#if HAL_USE_CAN
bool isValidCanTxPin(brain_pin_e pin);
bool isValidCanRxPin(brain_pin_e pin);
CANDriver * detectCanDevice(brain_pin_e pinRx, brain_pin_e pinTx);
#endif /* HAL_USE_CAN */

View File

@ -0,0 +1,21 @@
/**
* @file mpu_util.h
*
* @date Jul 27, 2014
* @author Andrey Belomutskiy, (c) 2012-2020
*/
#pragma once
#include "stm32f4xx_hal_flash_ex.h"
#define SPI_CR1_8BIT_MODE 0
#define SPI_CR2_8BIT_MODE 0
#define SPI_CR1_16BIT_MODE SPI_CR1_DFF
#define SPI_CR2_16BIT_MODE 0
// TODO
#define SPI_CR1_24BIT_MODE 0
#define SPI_CR2_24BIT_MODE 0

View File

@ -1,95 +0,0 @@
/**
* @file mpu_util.h
*
* @date Jul 27, 2014
* @author Andrey Belomutskiy, (c) 2012-2020
*/
#pragma once
#include "stm32f4xx_hal_flash_ex.h"
#include "stm32_common_mpu_util.h"
// we are lucky - all CAN pins use the same AF
#define EFI_CAN_RX_AF 9
#define EFI_CAN_TX_AF 9
#ifndef GPIO_AF_TIM1
#define GPIO_AF_TIM1 1
#endif
#ifndef GPIO_AF_TIM2
#define GPIO_AF_TIM2 1
#endif
#ifndef GPIO_AF_TIM3
#define GPIO_AF_TIM3 2
#endif
#ifndef GPIO_AF_TIM4
#define GPIO_AF_TIM4 2
#endif
#ifndef GPIO_AF_TIM5
#define GPIO_AF_TIM5 2
#endif
#ifndef GPIO_AF_TIM8
#define GPIO_AF_TIM8 3
#endif
#ifndef GPIO_AF_TIM9
#define GPIO_AF_TIM9 3
#endif
#ifndef ADC_TwoSamplingDelay_5Cycles
#define ADC_TwoSamplingDelay_5Cycles ((uint32_t)0x00000000)
#endif
#ifndef ADC_TwoSamplingDelay_20Cycles
#define ADC_TwoSamplingDelay_20Cycles ((uint32_t)0x00000F00)
#endif
#ifndef ADC_CR2_SWSTART
#define ADC_CR2_SWSTART ((uint32_t)0x40000000)
#endif
#define SPI_CR1_8BIT_MODE 0
#define SPI_CR2_8BIT_MODE 0
#define SPI_CR1_16BIT_MODE SPI_CR1_DFF
#define SPI_CR2_16BIT_MODE 0
// TODO
#define SPI_CR1_24BIT_MODE 0
#define SPI_CR2_24BIT_MODE 0
#ifdef __cplusplus
extern "C"
{
#endif /* __cplusplus */
// these need to be declared C style for the linker magic to work
void DebugMonitorVector(void);
void UsageFaultVector(void);
void BusFaultVector(void);
void HardFaultVector(void);
#ifdef __cplusplus
}
#endif /* __cplusplus */
#if HAL_USE_SPI
void initSpiModule(SPIDriver *driver, brain_pin_e sck, brain_pin_e miso,
brain_pin_e mosi,
int sckMode,
int mosiMode,
int misoMode);
/**
* @see getSpiDevice
*/
void initSpiCs(SPIConfig *spiConfig, brain_pin_e csPin);
#endif /* HAL_USE_SPI */

View File

@ -0,0 +1,20 @@
/**
* @file mpu_util.h
*
* @date Jul 27, 2014
* @author Andrey Belomutskiy, (c) 2012-2020
*/
#pragma once
#include "stm32f7xx_hal_flash_ex.h"
#define SPI_CR1_8BIT_MODE 0
#define SPI_CR2_8BIT_MODE (SPI_CR2_DS_2 | SPI_CR2_DS_1 | SPI_CR2_DS_0)
#define SPI_CR1_16BIT_MODE 0
#define SPI_CR2_16BIT_MODE SPI_CR2_DS_3 | SPI_CR2_DS_2 | SPI_CR2_DS_1 | SPI_CR2_DS_0
/* 3 x 8-bit transfer */
#define SPI_CR1_24BIT_MODE 0
#define SPI_CR2_24BIT_MODE SPI_CR2_DS_2 | SPI_CR2_DS_1 | SPI_CR2_DS_0

View File

@ -1,98 +0,0 @@
/**
* @file mpu_util.h
*
* @date Jul 27, 2014
* @author Andrey Belomutskiy, (c) 2012-2020
*/
#pragma once
#include "stm32f7xx_hal_flash_ex.h"
#include "stm32_common_mpu_util.h"
// we are lucky - all CAN pins use the same AF
#define EFI_CAN_RX_AF 9
#define EFI_CAN_TX_AF 9
#ifndef GPIO_AF_TIM1
#define GPIO_AF_TIM1 1
#endif
#ifndef GPIO_AF_TIM2
#define GPIO_AF_TIM2 1
#endif
#ifndef GPIO_AF_TIM3
#define GPIO_AF_TIM3 2
#endif
#ifndef GPIO_AF_TIM4
#define GPIO_AF_TIM4 2
#endif
#ifndef GPIO_AF_TIM5
#define GPIO_AF_TIM5 2
#endif
#ifndef GPIO_AF_TIM8
#define GPIO_AF_TIM8 3
#endif
#ifndef GPIO_AF_TIM9
#define GPIO_AF_TIM9 3
#endif
#ifndef ADC_TwoSamplingDelay_5Cycles
#define ADC_TwoSamplingDelay_5Cycles ((uint32_t)0x00000000)
#endif
#ifndef ADC_TwoSamplingDelay_20Cycles
#define ADC_TwoSamplingDelay_20Cycles ((uint32_t)0x00000F00)
#endif
#ifndef ADC_CR2_SWSTART
#define ADC_CR2_SWSTART ((uint32_t)0x40000000)
#endif
#define SPI_CR1_8BIT_MODE 0
#define SPI_CR2_8BIT_MODE (SPI_CR2_DS_2 | SPI_CR2_DS_1 | SPI_CR2_DS_0)
#define SPI_CR1_16BIT_MODE 0
#define SPI_CR2_16BIT_MODE SPI_CR2_DS_3 | SPI_CR2_DS_2 | SPI_CR2_DS_1 | SPI_CR2_DS_0
/* 3 x 8-bit transfer */
#define SPI_CR1_24BIT_MODE 0
#define SPI_CR2_24BIT_MODE SPI_CR2_DS_2 | SPI_CR2_DS_1 | SPI_CR2_DS_0
#ifdef __cplusplus
extern "C"
{
#endif /* __cplusplus */
// these need to be declared C style for the linker magic to work
void DebugMonitorVector(void);
void UsageFaultVector(void);
void BusFaultVector(void);
void HardFaultVector(void);
#ifdef __cplusplus
}
#endif /* __cplusplus */
#if HAL_USE_SPI
void initSpiModule(SPIDriver *driver, brain_pin_e sck, brain_pin_e miso,
brain_pin_e mosi,
int sckMode,
int mosiMode,
int misoMode);
/**
* @see getSpiDevice
*/
void initSpiCs(SPIConfig *spiConfig, brain_pin_e csPin);
#endif /* HAL_USE_SPI */