From 37cd9266d3b1ae7af8d6086ac3ab9c99dedb5bf5 Mon Sep 17 00:00:00 2001 From: Andrey G Date: Wed, 6 Jan 2021 16:59:13 +0300 Subject: [PATCH] Call startSmartCsPins when applying new settings (#2194) Only stopSmartCsPins was called from applyNewHardwareSettings. This cause lost of CS pins for external gpio chips --- firmware/hw_layer/hardware.cpp | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/firmware/hw_layer/hardware.cpp b/firmware/hw_layer/hardware.cpp index 8f89c338e4..8b4330f10b 100644 --- a/firmware/hw_layer/hardware.cpp +++ b/firmware/hw_layer/hardware.cpp @@ -339,9 +339,9 @@ void applyNewHardwareSettings(void) { } #endif -#if (BOARD_TLE6240_COUNT > 0) || (BOARD_DRV8860_COUNT > 0) +#if (BOARD_EXT_GPIOCHIPS > 0) stopSmartCsPins(); -#endif /* (BOARD_MC33972_COUNT > 0) */ +#endif /* (BOARD_EXT_GPIOCHIPS > 0) */ #if EFI_VEHICLE_SPEED stopVSSPins(); @@ -390,7 +390,9 @@ void applyNewHardwareSettings(void) { ButtonDebounce::startConfigurationList(); - + /******************************************* + * Start everything back with new settings * + ******************************************/ #if EFI_SHAFT_POSITION_INPUT startTriggerInputPins(); @@ -404,6 +406,21 @@ void applyNewHardwareSettings(void) { startHD44780_pins(); #endif /* #if EFI_HD44780_LCD */ +#if (BOARD_EXT_GPIOCHIPS > 0) + /* TODO: properly restart gpio chips... + * This is only workaround for "CS pin lost" bug + * see: https://github.com/rusefi/rusefi/issues/2107 + * We should provide better way to gracefully stop all + * gpio chips: set outputs to safe state, release all + * on-chip resources (gpios, SPIs, etc) and then restart + * with updated settings. + * Following code just re-inits CS pins for all external + * gpio chips, but does not update CS pin definition in + * gpio chips private data/settings. So changing CS pin + * on-fly does not work */ + startSmartCsPins(); +#endif /* (BOARD_EXT_GPIOCHIPS > 0) */ + enginePins.startPins(); #if EFI_CAN_SUPPORT