From a829357bd5ff34411bed3d49ed0650bdf5be6dec Mon Sep 17 00:00:00 2001 From: Alex Duchesne Date: Thu, 19 Dec 2024 00:51:14 -0500 Subject: [PATCH] rg_display: Fixed occasional crash in spi_deinit --- components/retro-go/config.h | 8 -------- components/retro-go/drivers/display/ili9341.h | 8 ++++++-- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/components/retro-go/config.h b/components/retro-go/config.h index a0e6d56f5..988de055f 100644 --- a/components/retro-go/config.h +++ b/components/retro-go/config.h @@ -66,14 +66,6 @@ #define RG_BUILD_DATE __DATE__ " " __TIME__ #endif -// #ifndef RG_ENABLE_NETPLAY -// #define RG_ENABLE_NETPLAY 0 -// #endif - -// #ifndef RG_ENABLE_PROFILING -// #define RG_ENABLE_PROFILING 0 -// #endif - #ifndef RG_APP_LAUNCHER #define RG_APP_LAUNCHER "launcher" #endif diff --git a/components/retro-go/drivers/display/ili9341.h b/components/retro-go/drivers/display/ili9341.h index 2277954e8..c766226c4 100644 --- a/components/retro-go/drivers/display/ili9341.h +++ b/components/retro-go/drivers/display/ili9341.h @@ -129,8 +129,12 @@ static void spi_init(void) static void spi_deinit(void) { - spi_bus_remove_device(spi_dev); - spi_bus_free(RG_SCREEN_HOST); + // When transactions are still in flight, spi_bus_remove_device fails and spi_bus_free then crashes. + // The real solution would be to wait for transactions to be done, but this is simpler for now... + if (spi_bus_remove_device(spi_dev) == ESP_OK) + spi_bus_free(RG_SCREEN_HOST); + else + RG_LOGE("Failed to properly terminate SPI driver!"); } #define ILI9341_CMD(cmd, data...) \