allow overriding configuration (#1341)
* config overrides * proteus too * comment * remove wno-error * comment
This commit is contained in:
parent
8e21951fd4
commit
83cca6ec7a
|
@ -25,10 +25,13 @@
|
|||
|
||||
EXTERN_ENGINE;
|
||||
|
||||
static const ConfigOverrides configOverrides = {
|
||||
.canTxPin = GPIOB_6,
|
||||
.canRxPin = GPIOB_12,
|
||||
};
|
||||
|
||||
static void setupCanPins() {
|
||||
engineConfiguration->canTxPin = GPIOB_6;
|
||||
engineConfiguration->canRxPin = GPIOB_12;
|
||||
const ConfigOverrides& getConfigOverrides() {
|
||||
return configOverrides;
|
||||
}
|
||||
|
||||
static void setInjectorPins() {
|
||||
|
@ -189,7 +192,6 @@ void setBoardConfigurationOverrides(void) {
|
|||
setupVbatt();
|
||||
setupTle8888();
|
||||
setupEtb();
|
||||
setupCanPins();
|
||||
|
||||
// MRE has a special main relay control low side pin
|
||||
// rusEfi firmware is totally not involved with main relay control on microRusEfi board
|
||||
|
|
|
@ -43,6 +43,15 @@ 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;
|
||||
|
@ -106,11 +115,6 @@ static void setupEtb() {
|
|||
engineConfiguration->etbFreq = 800;
|
||||
}
|
||||
|
||||
static void setupCanPins() {
|
||||
engineConfiguration->canTxPin = GPIOD_1;
|
||||
engineConfiguration->canRxPin = GPIOD_0;
|
||||
}
|
||||
|
||||
static void setupDefaultSensorInputs() {
|
||||
// trigger inputs
|
||||
// Digital channel 1 as default - others not set
|
||||
|
@ -162,7 +166,6 @@ void setBoardConfigurationOverrides(void) {
|
|||
setLedPins();
|
||||
setupVbatt();
|
||||
setupEtb();
|
||||
setupCanPins();
|
||||
|
||||
// "required" hardware is done - set some reasonable defaults
|
||||
setupDefaultSensorInputs();
|
||||
|
|
|
@ -1429,3 +1429,8 @@ void copyTimingTable(ignition_table_t const source, ignition_table_t destination
|
|||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
|
|
@ -66,3 +66,23 @@ typedef void (*configuration_callback_t)(engine_configuration_s*);
|
|||
void resetConfigurationExt(Logging * logger, configuration_callback_t boardCallback, engine_type_e engineType DECLARE_ENGINE_PARAMETER_SUFFIX);
|
||||
void resetConfigurationExt(Logging * logger, engine_type_e engineType DECLARE_ENGINE_PARAMETER_SUFFIX);
|
||||
#endif /* __cplusplus */
|
||||
|
||||
struct ConfigOverrides {
|
||||
// CAN pinout
|
||||
brain_pin_e canTxPin;
|
||||
brain_pin_e canRxPin;
|
||||
};
|
||||
|
||||
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__ ))
|
||||
|
|
|
@ -77,7 +77,7 @@ public:
|
|||
}
|
||||
|
||||
void ThreadTask() override {
|
||||
CANDriver* device = detectCanDevice(CONFIG(canRxPin), CONFIG(canTxPin));
|
||||
CANDriver* device = detectCanDevice(CONFIG_OVERRIDE(canRxPin), CONFIG_OVERRIDE(canTxPin));
|
||||
|
||||
if (!device) {
|
||||
warning(CUSTOM_ERR_CAN_CONFIGURATION, "CAN configuration issue");
|
||||
|
@ -117,8 +117,8 @@ static void canInfo(void) {
|
|||
scheduleMsg(&logger, "CAN SLAVE MODE");
|
||||
#endif
|
||||
|
||||
scheduleMsg(&logger, "CAN TX %s", hwPortname(CONFIG(canTxPin)));
|
||||
scheduleMsg(&logger, "CAN RX %s", hwPortname(CONFIG(canRxPin)));
|
||||
scheduleMsg(&logger, "CAN TX %s", hwPortname(CONFIG_OVERRIDE(canTxPin)));
|
||||
scheduleMsg(&logger, "CAN RX %s", hwPortname(CONFIG_OVERRIDE(canRxPin)));
|
||||
scheduleMsg(&logger, "type=%d canReadEnabled=%s canWriteEnabled=%s period=%d", engineConfiguration->canNbcType,
|
||||
boolToString(engineConfiguration->canReadEnabled), boolToString(engineConfiguration->canWriteEnabled),
|
||||
engineConfiguration->canSleepPeriodMs);
|
||||
|
@ -151,16 +151,16 @@ void stopCanPins(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
|
|||
}
|
||||
|
||||
void startCanPins(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
|
||||
efiSetPadMode("CAN TX", CONFIG(canTxPin), PAL_MODE_ALTERNATE(EFI_CAN_TX_AF));
|
||||
efiSetPadMode("CAN RX", CONFIG(canRxPin), PAL_MODE_ALTERNATE(EFI_CAN_RX_AF));
|
||||
efiSetPadMode("CAN TX", CONFIG_OVERRIDE(canTxPin), PAL_MODE_ALTERNATE(EFI_CAN_TX_AF));
|
||||
efiSetPadMode("CAN RX", CONFIG_OVERRIDE(canRxPin), PAL_MODE_ALTERNATE(EFI_CAN_RX_AF));
|
||||
}
|
||||
|
||||
void initCan(void) {
|
||||
addConsoleAction("caninfo", canInfo);
|
||||
|
||||
isCanEnabled =
|
||||
(CONFIG(canTxPin) != GPIO_UNASSIGNED) && // both pins are set...
|
||||
(CONFIG(canRxPin) != GPIO_UNASSIGNED) &&
|
||||
(CONFIG_OVERRIDE(canTxPin) != GPIO_UNASSIGNED) && // both pins are set...
|
||||
(CONFIG_OVERRIDE(canRxPin) != GPIO_UNASSIGNED) &&
|
||||
(CONFIG(canWriteEnabled) || CONFIG(canReadEnabled)) ; // ...and either read or write is enabled
|
||||
|
||||
// nothing to do if we aren't enabled...
|
||||
|
@ -169,13 +169,13 @@ void initCan(void) {
|
|||
}
|
||||
|
||||
// Validate pins
|
||||
if (!isValidCanTxPin(CONFIG(canTxPin))) {
|
||||
firmwareError(CUSTOM_OBD_70, "invalid CAN TX %s", hwPortname(CONFIG(canTxPin)));
|
||||
if (!isValidCanTxPin(CONFIG_OVERRIDE(canTxPin))) {
|
||||
firmwareError(CUSTOM_OBD_70, "invalid CAN TX %s", hwPortname(CONFIG_OVERRIDE(canTxPin)));
|
||||
return;
|
||||
}
|
||||
|
||||
if (!isValidCanRxPin(CONFIG(canRxPin))) {
|
||||
firmwareError(CUSTOM_OBD_70, "invalid CAN RX %s", hwPortname(CONFIG(canRxPin)));
|
||||
if (!isValidCanRxPin(CONFIG_OVERRIDE(canRxPin))) {
|
||||
firmwareError(CUSTOM_OBD_70, "invalid CAN RX %s", hwPortname(CONFIG_OVERRIDE(canRxPin)));
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -190,8 +190,8 @@ void initCan(void) {
|
|||
|
||||
// Plumb CAN device to tx system
|
||||
CanTxMessage::setDevice(detectCanDevice(
|
||||
CONFIG(canRxPin),
|
||||
CONFIG(canTxPin)
|
||||
CONFIG_OVERRIDE(canRxPin),
|
||||
CONFIG_OVERRIDE(canTxPin)
|
||||
));
|
||||
|
||||
// fire up threads, as necessary
|
||||
|
|
Loading…
Reference in New Issue