No pins should be restarted for no reason during config change #3151

This commit is contained in:
rusefillc 2021-08-14 04:35:43 -04:00
parent 81c9726ae0
commit bd410d0c1b
2 changed files with 33 additions and 29 deletions

View File

@ -196,33 +196,18 @@ void enableFrankensoCan(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
engineConfiguration->canReadEnabled = false;
}
// todo: we usually use 'activeConfiguration' for 'stopPin' why this unusual code here?
// this is related to #1375
static brain_pin_e currentTxPin = GPIO_UNASSIGNED;
static brain_pin_e currentRxPin = GPIO_UNASSIGNED;
void stopCanPins(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
efiSetPadUnused(currentTxPin);
efiSetPadUnused(currentRxPin);
if (isConfigurationChanged(canTxPin)) {
efiSetPadUnused(activeConfiguration.canTxPin);
}
if (isConfigurationChanged(canRxPin)) {
efiSetPadUnused(activeConfiguration.canRxPin);
}
}
// at the moment we support only very limited runtime configuration change, still not supporting online CAN toggle
void startCanPins(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
// Store pins so we can disable later
currentTxPin = CONFIG(canTxPin);
currentRxPin = CONFIG(canRxPin);
efiSetPadMode("CAN TX", currentTxPin, PAL_MODE_ALTERNATE(EFI_CAN_TX_AF));
efiSetPadMode("CAN RX", currentRxPin, PAL_MODE_ALTERNATE(EFI_CAN_RX_AF));
}
void initCan(void) {
addConsoleAction("caninfo", canInfo);
isCanEnabled =
(isBrainPinValid(CONFIG(canTxPin))) && // both pins are set...
(isBrainPinValid(CONFIG(canRxPin))) &&
(CONFIG(canWriteEnabled) || CONFIG(canReadEnabled)) ; // ...and either read or write is enabled
// nothing to do if we aren't enabled...
if (!isCanEnabled) {
return;
@ -239,6 +224,27 @@ void initCan(void) {
return;
}
if (isConfigurationChanged(canTxPin)) {
efiSetPadMode("CAN TX", CONFIG(canTxPin), PAL_MODE_ALTERNATE(EFI_CAN_TX_AF));
}
if (isConfigurationChanged(canRxPin)) {
efiSetPadMode("CAN RX", CONFIG(canRxPin), PAL_MODE_ALTERNATE(EFI_CAN_RX_AF));
}
}
void initCan(void) {
addConsoleAction("caninfo", canInfo);
isCanEnabled =
(isBrainPinValid(CONFIG(canTxPin))) && // both pins are set...
(isBrainPinValid(CONFIG(canRxPin))) &&
(CONFIG(canWriteEnabled) || CONFIG(canReadEnabled)) ; // ...and either read or write is enabled
// nothing to do if we aren't enabled...
if (!isCanEnabled) {
return;
}
switch (CONFIG(canBaudRate)) {
case B100KBPS:
canConfig = &canConfig100;
@ -256,8 +262,6 @@ void initCan(void) {
break;
}
startCanPins();
// Initialize hardware
#if STM32_CAN_USE_CAN2
// CAN1 is required for CAN2

View File

@ -375,10 +375,6 @@ void applyNewHardwareSettings(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
enginePins.startPins();
#if EFI_CAN_SUPPORT
startCanPins();
#endif /* EFI_CAN_SUPPORT */
#if EFI_AUX_SERIAL
startAuxSerialPins();
#endif /* EFI_AUX_SERIAL */
@ -508,6 +504,10 @@ void startHardware(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
startTriggerDebugPins(PASS_ENGINE_PARAMETER_SIGNATURE);
startPedalPins(PASS_ENGINE_PARAMETER_SIGNATURE);
#if EFI_CAN_SUPPORT
startCanPins();
#endif /* EFI_CAN_SUPPORT */
}
void initHardware(DECLARE_ENGINE_PARAMETER_SIGNATURE) {