make board config override actually usable (#2508)
* new function * hellen * MRE * proteus * put those function declarations in a reasonable place * put the comment back * weak * move that to a reasonable place Co-authored-by: Matthew Kennedy <makenne@microsoft.com>
This commit is contained in:
parent
27d2e42543
commit
1dffcf5729
|
@ -24,7 +24,6 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
void boardInit(void);
|
||||
void setBoardDefaultConfiguration(void);
|
||||
void setPinConfigurationOverrides(void);
|
||||
void setSerialConfigurationOverrides(void);
|
||||
void setSdCardConfigurationOverrides(void);
|
||||
|
|
|
@ -19,15 +19,6 @@
|
|||
|
||||
EXTERN_ENGINE;
|
||||
|
||||
static const ConfigOverrides configOverrides = {
|
||||
.canTxPin = GPIOD_1,
|
||||
.canRxPin = GPIOD_0,
|
||||
};
|
||||
|
||||
const ConfigOverrides& getConfigOverrides() {
|
||||
return configOverrides;
|
||||
}
|
||||
|
||||
static void setInjectorPins() {
|
||||
engineConfiguration->injectionPins[0] = GPIOG_7;
|
||||
engineConfiguration->injectionPins[1] = GPIOG_8;
|
||||
|
@ -107,15 +98,25 @@ static void setupDefaultSensorInputs() {
|
|||
engineConfiguration->afr.hwChannel = EFI_ADC_1;
|
||||
|
||||
engineConfiguration->clt.adcChannel = EFI_ADC_12;
|
||||
engineConfiguration->clt.config.bias_resistor = 4700;
|
||||
|
||||
engineConfiguration->iat.adcChannel = EFI_ADC_13;
|
||||
engineConfiguration->iat.config.bias_resistor = 4700;
|
||||
|
||||
engineConfiguration->auxTempSensor1.adcChannel = EFI_ADC_NONE;
|
||||
engineConfiguration->auxTempSensor2.adcChannel = EFI_ADC_NONE;
|
||||
}
|
||||
|
||||
void setBoardConfigOverrides(void) {
|
||||
setLedPins();
|
||||
setupVbatt();
|
||||
setSdCardConfigurationOverrides();
|
||||
|
||||
engineConfiguration->clt.config.bias_resistor = 4700;
|
||||
engineConfiguration->iat.config.bias_resistor = 4700;
|
||||
|
||||
engineConfiguration->canTxPin = GPIOD_1;
|
||||
engineConfiguration->canRxPin = GPIOD_0;
|
||||
}
|
||||
|
||||
void setPinConfigurationOverrides(void) {
|
||||
}
|
||||
|
||||
|
@ -138,9 +139,8 @@ void setSerialConfigurationOverrides(void) {
|
|||
void setBoardDefaultConfiguration(void) {
|
||||
setInjectorPins();
|
||||
setIgnitionPins();
|
||||
setLedPins();
|
||||
setupVbatt();
|
||||
setSdCardConfigurationOverrides();
|
||||
|
||||
engineConfiguration->isSdCardEnabled = true;
|
||||
|
||||
CONFIG(enableSoftwareKnock) = true;
|
||||
|
||||
|
@ -180,5 +180,4 @@ void setSdCardConfigurationOverrides(void) {
|
|||
engineConfiguration->spi2sckPin = GPIOB_13;
|
||||
engineConfiguration->sdCardCsPin = GPIOB_12;
|
||||
CONFIG(is_enabled_spi_2) = true;
|
||||
engineConfiguration->isSdCardEnabled = true;
|
||||
}
|
||||
|
|
|
@ -24,7 +24,6 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
void boardInit(void);
|
||||
void setBoardDefaultConfiguration(void);
|
||||
void setPinConfigurationOverrides(void);
|
||||
void setSerialConfigurationOverrides(void);
|
||||
void setSdCardConfigurationOverrides(void);
|
||||
|
|
|
@ -27,15 +27,6 @@
|
|||
|
||||
EXTERN_ENGINE;
|
||||
|
||||
static const ConfigOverrides configOverrides = {
|
||||
.canTxPin = GPIOB_6,
|
||||
.canRxPin = GPIOB_12,
|
||||
};
|
||||
|
||||
const ConfigOverrides& getConfigOverrides() {
|
||||
return configOverrides;
|
||||
}
|
||||
|
||||
static void setInjectorPins() {
|
||||
engineConfiguration->injectionPins[0] = TLE8888_PIN_1;
|
||||
engineConfiguration->injectionPins[1] = TLE8888_PIN_2;
|
||||
|
@ -161,11 +152,9 @@ static void setupDefaultSensorInputs() {
|
|||
|
||||
// clt = "18 - AN temp 1"
|
||||
engineConfiguration->clt.adcChannel = EFI_ADC_0;
|
||||
engineConfiguration->clt.config.bias_resistor = 2700;
|
||||
|
||||
// iat = "23 - AN temp 2"
|
||||
engineConfiguration->iat.adcChannel = EFI_ADC_1;
|
||||
engineConfiguration->iat.config.bias_resistor = 2700;
|
||||
|
||||
setCommonNTCSensor(&engineConfiguration->auxTempSensor1, 2700);
|
||||
setCommonNTCSensor(&engineConfiguration->auxTempSensor2, 2700);
|
||||
|
@ -176,6 +165,28 @@ static void setupDefaultSensorInputs() {
|
|||
#endif // HW_CHECK_MODE
|
||||
}
|
||||
|
||||
void setBoardConfigOverrides(void) {
|
||||
setLedPins();
|
||||
setupVbatt();
|
||||
setupTle8888();
|
||||
setupEtb();
|
||||
|
||||
engineConfiguration->clt.config.bias_resistor = 2700;
|
||||
engineConfiguration->iat.config.bias_resistor = 2700;
|
||||
|
||||
engineConfiguration->canTxPin = GPIOB_6;
|
||||
engineConfiguration->canRxPin = GPIOB_12;
|
||||
|
||||
// SPI for SD card
|
||||
CONFIG(is_enabled_spi_3) = true;
|
||||
engineConfiguration->sdCardSpiDevice = SPI_DEVICE_3;
|
||||
engineConfiguration->sdCardCsPin = GPIOB_9;
|
||||
|
||||
engineConfiguration->spi3mosiPin = GPIOC_12;
|
||||
engineConfiguration->spi3misoPin = GPIOC_11;
|
||||
engineConfiguration->spi3sckPin = GPIOC_10;
|
||||
}
|
||||
|
||||
void setPinConfigurationOverrides(void) {
|
||||
}
|
||||
|
||||
|
@ -199,13 +210,6 @@ void setSerialConfigurationOverrides(void) {
|
|||
void setBoardDefaultConfiguration(void) {
|
||||
setInjectorPins();
|
||||
setIgnitionPins();
|
||||
setLedPins();
|
||||
setupVbatt();
|
||||
setupTle8888();
|
||||
setupEtb();
|
||||
|
||||
engineConfiguration->canTxPin = GPIOB_6;
|
||||
engineConfiguration->canRxPin = GPIOB_12;
|
||||
|
||||
// MRE has a special main relay control low side pin
|
||||
// rusEfi firmware is totally not involved with main relay control on microRusEfi board
|
||||
|
@ -214,15 +218,8 @@ void setBoardDefaultConfiguration(void) {
|
|||
// TLE8888_PIN_21: "35 - GP Out 1"
|
||||
engineConfiguration->fuelPumpPin = TLE8888_PIN_21;
|
||||
|
||||
engineConfiguration->sdCardSpiDevice = SPI_DEVICE_3;
|
||||
engineConfiguration->spi3mosiPin = GPIOC_12;
|
||||
engineConfiguration->spi3misoPin = GPIOC_11;
|
||||
engineConfiguration->spi3sckPin = GPIOC_10;
|
||||
engineConfiguration->sdCardCsPin = GPIOB_9;
|
||||
CONFIG(is_enabled_spi_3) = true;
|
||||
// engineConfiguration->isSdCardEnabled = true;
|
||||
|
||||
|
||||
// TLE8888 high current low side: VVT2 IN9 / OUT5
|
||||
// GPIOE_10: "3 - Lowside 2"
|
||||
engineConfiguration->idle.solenoidPin = TLE8888_PIN_5;
|
||||
|
|
|
@ -1,12 +1,5 @@
|
|||
#include "adc_inputs.h"
|
||||
|
||||
/**
|
||||
* @brief Board-specific configuration defaults.
|
||||
* @todo Add your board-specific code, if any.
|
||||
*/
|
||||
void setBoardDefaultConfiguration(void) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Board-specific pin configuration code overrides. Needed by bootloader code.
|
||||
* @todo Add your board-specific code, if any.
|
||||
|
|
|
@ -43,15 +43,6 @@ static const brain_pin_e ignPins[] = {
|
|||
GPIOG_2,
|
||||
};
|
||||
|
||||
static const ConfigOverrides configOverrides = {
|
||||
.canTxPin = GPIOD_1,
|
||||
.canRxPin = GPIOD_0,
|
||||
};
|
||||
|
||||
const ConfigOverrides& getConfigOverrides() {
|
||||
return configOverrides;
|
||||
}
|
||||
|
||||
static void setInjectorPins() {
|
||||
copyArray(engineConfiguration->injectionPins, injPins);
|
||||
engineConfiguration->injectionPinMode = OM_DEFAULT;
|
||||
|
@ -135,11 +126,9 @@ static void setupDefaultSensorInputs() {
|
|||
|
||||
// CLT = Analog Temp 3 = PB0
|
||||
engineConfiguration->clt.adcChannel = EFI_ADC_8;
|
||||
engineConfiguration->clt.config.bias_resistor = 2700;
|
||||
|
||||
// IAT = Analog Temp 2 = PC5
|
||||
engineConfiguration->iat.adcChannel = EFI_ADC_15;
|
||||
engineConfiguration->iat.config.bias_resistor = 2700;
|
||||
|
||||
// TPS = Analog volt 2 = PC1
|
||||
engineConfiguration->tps1_1AdcChannel = EFI_ADC_11;
|
||||
|
@ -152,7 +141,6 @@ static void setupDefaultSensorInputs() {
|
|||
}
|
||||
|
||||
static void setupSdCard() {
|
||||
engineConfiguration->isSdCardEnabled = true;
|
||||
|
||||
engineConfiguration->sdCardSpiDevice = SPI_DEVICE_3;
|
||||
engineConfiguration->sdCardCsPin = GPIOD_2;
|
||||
|
@ -163,6 +151,19 @@ static void setupSdCard() {
|
|||
engineConfiguration->spi3mosiPin = GPIOC_12;
|
||||
}
|
||||
|
||||
void setBoardConfigOverrides(void) {
|
||||
setupSdCard();
|
||||
setupEtb();
|
||||
setLedPins();
|
||||
setupVbatt();
|
||||
|
||||
engineConfiguration->clt.config.bias_resistor = 2700;
|
||||
engineConfiguration->iat.config.bias_resistor = 2700;
|
||||
|
||||
engineConfiguration->canTxPin = GPIOD_1;
|
||||
engineConfiguration->canRxPin = GPIOD_0;
|
||||
}
|
||||
|
||||
void setPinConfigurationOverrides(void) {
|
||||
}
|
||||
|
||||
|
@ -185,10 +186,8 @@ void setSerialConfigurationOverrides(void) {
|
|||
void setBoardDefaultConfiguration(void) {
|
||||
setInjectorPins();
|
||||
setIgnitionPins();
|
||||
setLedPins();
|
||||
setupVbatt();
|
||||
setupEtb();
|
||||
setupSdCard();
|
||||
|
||||
engineConfiguration->isSdCardEnabled = true;
|
||||
|
||||
// "required" hardware is done - set some reasonable defaults
|
||||
setupDefaultSensorInputs();
|
||||
|
|
|
@ -4,13 +4,6 @@
|
|||
|
||||
#include "chconf_common.h"
|
||||
|
||||
/**
|
||||
* @brief Board-specific configuration defaults.
|
||||
* @todo Add your board-specific code, if any.
|
||||
*/
|
||||
void setBoardDefaultConfiguration(void) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Board-specific pin configuration code overrides. Needed by bootloader code.
|
||||
* @todo Add your board-specific code, if any.
|
||||
|
|
|
@ -670,6 +670,42 @@ void setDefaultEngineNoiseTable(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
|
|||
engineConfiguration->knockNoise[7] = 2; // 7000
|
||||
}
|
||||
|
||||
static void setHip9011FrankensoPinout() {
|
||||
/**
|
||||
* SPI on PB13/14/15
|
||||
*/
|
||||
// CONFIG(hip9011CsPin) = GPIOD_0; // rev 0.1
|
||||
|
||||
CONFIG(isHip9011Enabled) = true;
|
||||
engineConfiguration->hip9011PrescalerAndSDO = HIP_8MHZ_PRESCALER; // 8MHz chip
|
||||
CONFIG(is_enabled_spi_2) = true;
|
||||
// todo: convert this to rusEfi, hardware-independent enum
|
||||
#if EFI_PROD_CODE
|
||||
#ifdef EFI_HIP_CS_PIN
|
||||
CONFIG(hip9011CsPin) = EFI_HIP_CS_PIN;
|
||||
#else
|
||||
CONFIG(hip9011CsPin) = GPIOB_0; // rev 0.4
|
||||
#endif
|
||||
CONFIG(hip9011CsPinMode) = OM_OPENDRAIN;
|
||||
|
||||
CONFIG(hip9011IntHoldPin) = GPIOB_11;
|
||||
CONFIG(hip9011IntHoldPinMode) = OM_OPENDRAIN;
|
||||
|
||||
engineConfiguration->spi2SckMode = PO_OPENDRAIN; // 4
|
||||
engineConfiguration->spi2MosiMode = PO_OPENDRAIN; // 4
|
||||
engineConfiguration->spi2MisoMode = PO_PULLUP; // 32
|
||||
#endif /* EFI_PROD_CODE */
|
||||
|
||||
engineConfiguration->hip9011Gain = 1;
|
||||
engineConfiguration->knockVThreshold = 4;
|
||||
engineConfiguration->maxKnockSubDeg = 20;
|
||||
|
||||
|
||||
if (!CONFIG(useTpicAdvancedMode)) {
|
||||
engineConfiguration->hipOutputChannel = EFI_ADC_10; // PC0
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Global default engine configuration
|
||||
* This method sets the global engine configuration defaults. These default values are then
|
||||
|
@ -1175,6 +1211,9 @@ void loadConfiguration(Logging* logger DECLARE_ENGINE_PARAMETER_SUFFIX) {
|
|||
engineConfiguration->engineType = DEFAULT_ENGINE_TYPE;
|
||||
resetConfigurationExt(logger, engineConfiguration->engineType PASS_ENGINE_PARAMETER_SUFFIX);
|
||||
#endif /* EFI_INTERNAL_FLASH */
|
||||
|
||||
// Force any board configuration options that humans shouldn't be able to change
|
||||
setBoardConfigOverrides();
|
||||
}
|
||||
|
||||
void resetConfigurationExt(Logging * logger, configuration_callback_t boardCallback, engine_type_e engineType DECLARE_ENGINE_PARAMETER_SUFFIX) {
|
||||
|
@ -1194,6 +1233,7 @@ void resetConfigurationExt(Logging * logger, configuration_callback_t boardCallb
|
|||
#if EFI_PROD_CODE
|
||||
// call overrided board-specific configuration setup, if needed (for custom boards only)
|
||||
setBoardDefaultConfiguration();
|
||||
setBoardConfigOverrides();
|
||||
#endif
|
||||
|
||||
engineConfiguration->engineType = engineType;
|
||||
|
@ -1519,8 +1559,6 @@ void setFrankenso0_1_joystick(engine_configuration_s *engineConfiguration) {
|
|||
engineConfiguration->joystickDPin = GPIOD_11;
|
||||
}
|
||||
|
||||
static const ConfigOverrides defaultConfigOverrides{};
|
||||
// This symbol is weak so that a board_configuration.cpp file can override it
|
||||
__attribute__((weak)) const ConfigOverrides& getConfigOverrides() {
|
||||
return defaultConfigOverrides;
|
||||
}
|
||||
// These symbols are weak so that a board_configuration.cpp file can override them
|
||||
__attribute__((weak)) void setBoardDefaultConfiguration(void) { }
|
||||
__attribute__((weak)) void setBoardConfigOverrides(void) { }
|
||||
|
|
|
@ -65,22 +65,8 @@ void resetConfigurationExt(Logging * logger, engine_type_e engineType DECLARE_EN
|
|||
void rememberCurrentConfiguration(DECLARE_ENGINE_PARAMETER_SIGNATURE);
|
||||
#endif /* __cplusplus */
|
||||
|
||||
struct ConfigOverrides {
|
||||
// CAN pinout
|
||||
brain_pin_e canTxPin;
|
||||
brain_pin_e canRxPin;
|
||||
};
|
||||
void setBoardDefaultConfiguration(void);
|
||||
void setBoardConfigOverrides(void);
|
||||
|
||||
const ConfigOverrides& getConfigOverrides();
|
||||
|
||||
// If the overide value is default initialized
|
||||
// Use the value from config if not overriden
|
||||
// Otherwise use the override
|
||||
// the == decltype(CONFIG(__x__)){} part means
|
||||
// - take the type of the corresponding config field
|
||||
// - default construct (ie, 0) an object of the corresponding type
|
||||
// - check if the override value matches that (GPIO_UNASSIGNED, SPI_NONE, etc)
|
||||
// If it matches, that field hasn't been overridden, so read from the config.
|
||||
#define CONFIG_OVERRIDE(__x__) ( \
|
||||
(( getConfigOverrides().__x__ ) == decltype(CONFIG(__x__)){}) \
|
||||
? (CONFIG( __x__ )) : ( getConfigOverrides().__x__ ))
|
||||
// TODO: remove me
|
||||
#define CONFIG_OVERRIDE(__x__) CONFIG(__x__)
|
||||
|
|
|
@ -50,7 +50,6 @@ extern "C"
|
|||
extern "C" {
|
||||
#endif
|
||||
void boardInit(void);
|
||||
void setBoardDefaultConfiguration(void);
|
||||
void setPinConfigurationOverrides(void);
|
||||
void setSerialConfigurationOverrides(void);
|
||||
void setSdCardConfigurationOverrides(void);
|
||||
|
|
|
@ -463,44 +463,4 @@ static void hip_addconsoleActions(void) {
|
|||
addConsoleActionI("set_max_knock_sub_deg", setMaxKnockSubDeg);
|
||||
}
|
||||
|
||||
/*==========================================================================*/
|
||||
/* Boards specific functions. */
|
||||
/*==========================================================================*/
|
||||
/* TODO: move out oif here */
|
||||
void setHip9011FrankensoPinout(void) {
|
||||
/**
|
||||
* SPI on PB13/14/15
|
||||
*/
|
||||
// CONFIG(hip9011CsPin) = GPIOD_0; // rev 0.1
|
||||
|
||||
CONFIG(isHip9011Enabled) = true;
|
||||
engineConfiguration->hip9011PrescalerAndSDO = HIP_8MHZ_PRESCALER; // 8MHz chip
|
||||
CONFIG(is_enabled_spi_2) = true;
|
||||
// todo: convert this to rusEfi, hardware-independent enum
|
||||
#if EFI_PROD_CODE
|
||||
#ifdef EFI_HIP_CS_PIN
|
||||
CONFIG(hip9011CsPin) = EFI_HIP_CS_PIN;
|
||||
#else
|
||||
CONFIG(hip9011CsPin) = GPIOB_0; // rev 0.4
|
||||
#endif
|
||||
CONFIG(hip9011CsPinMode) = OM_OPENDRAIN;
|
||||
|
||||
CONFIG(hip9011IntHoldPin) = GPIOB_11;
|
||||
CONFIG(hip9011IntHoldPinMode) = OM_OPENDRAIN;
|
||||
|
||||
engineConfiguration->spi2SckMode = PO_OPENDRAIN; // 4
|
||||
engineConfiguration->spi2MosiMode = PO_OPENDRAIN; // 4
|
||||
engineConfiguration->spi2MisoMode = PO_PULLUP; // 32
|
||||
#endif /* EFI_PROD_CODE */
|
||||
|
||||
engineConfiguration->hip9011Gain = 1;
|
||||
engineConfiguration->knockVThreshold = 4;
|
||||
engineConfiguration->maxKnockSubDeg = 20;
|
||||
|
||||
|
||||
if (!CONFIG(useTpicAdvancedMode)) {
|
||||
engineConfiguration->hipOutputChannel = EFI_ADC_10; // PC0
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* EFI_HIP_9011 */
|
||||
|
|
|
@ -18,5 +18,3 @@ void hipAdcCallback(adcsample_t value);
|
|||
#endif /* HAL_USE_ADC */
|
||||
|
||||
void hip9011_startKnockSampling(uint8_t cylinderNumber, efitick_t nowNt);
|
||||
|
||||
void setHip9011FrankensoPinout(void);
|
||||
|
|
Loading…
Reference in New Issue