diff --git a/src/omv/py/py_lcd.c b/src/omv/py/py_lcd.c index 5c18b2d4e..ca13fe40e 100644 --- a/src/omv/py/py_lcd.c +++ b/src/omv/py/py_lcd.c @@ -80,6 +80,17 @@ static void spi_config_deinit() } spi_deinit(OMV_SPI_LCD_CONTROLLER); + + // Do not put in HAL_SPI_MspDeinit as other modules share the SPI2 bus. + + HAL_GPIO_DeInit(OMV_SPI_LCD_MOSI_PORT, OMV_SPI_LCD_MOSI_PIN); + HAL_GPIO_DeInit(OMV_SPI_LCD_SCLK_PORT, OMV_SPI_LCD_SCLK_PIN); + + HAL_GPIO_DeInit(OMV_SPI_LCD_RST_PORT, OMV_SPI_LCD_RST_PIN); + HAL_GPIO_DeInit(OMV_SPI_LCD_RS_PORT, OMV_SPI_LCD_RS_PIN); + HAL_GPIO_DeInit(OMV_SPI_LCD_CS_PORT, OMV_SPI_LCD_CS_PIN); + + /////////////////////////////////////////////////////////////////////// } static void spi_config_init(int w, int h, int refresh_rate, bool triple_buffer, bool bgr) @@ -92,6 +103,38 @@ static void spi_config_init(int w, int h, int refresh_rate, bool triple_buffer, spi_set_params(OMV_SPI_LCD_CONTROLLER, 0xffffffff, w * h * refresh_rate * 16, 0, 0, 8, 0); spi_init(OMV_SPI_LCD_CONTROLLER, true); + // Do not put in HAL_SPI_MspInit as other modules share the SPI2 bus. + + GPIO_InitTypeDef GPIO_InitStructure; + GPIO_InitStructure.Pull = GPIO_NOPULL; + GPIO_InitStructure.Mode = GPIO_MODE_AF_PP; + GPIO_InitStructure.Speed = GPIO_SPEED_FREQ_MEDIUM; + + GPIO_InitStructure.Alternate = OMV_SPI_LCD_MOSI_ALT; + GPIO_InitStructure.Pin = OMV_SPI_LCD_MOSI_PIN; + HAL_GPIO_Init(OMV_SPI_LCD_MOSI_PORT, &GPIO_InitStructure); + + GPIO_InitStructure.Alternate = OMV_SPI_LCD_SCLK_ALT; + GPIO_InitStructure.Pin = OMV_SPI_LCD_SCLK_PIN; + HAL_GPIO_Init(OMV_SPI_LCD_SCLK_PORT, &GPIO_InitStructure); + + GPIO_InitStructure.Mode = GPIO_MODE_OUTPUT_PP; + GPIO_InitStructure.Speed = GPIO_SPEED_FREQ_LOW; + + GPIO_InitStructure.Pin = OMV_SPI_LCD_RST_PIN; + HAL_GPIO_Init(OMV_SPI_LCD_RST_PORT, &GPIO_InitStructure); + OMV_SPI_LCD_RST_OFF(); + + GPIO_InitStructure.Pin = OMV_SPI_LCD_RS_PIN; + HAL_GPIO_Init(OMV_SPI_LCD_RS_PORT, &GPIO_InitStructure); + OMV_SPI_LCD_RS_OFF(); + + GPIO_InitStructure.Pin = OMV_SPI_LCD_CS_PIN; + HAL_GPIO_Init(OMV_SPI_LCD_CS_PORT, &GPIO_InitStructure); + OMV_SPI_LCD_CS_HIGH(); + + ///////////////////////////////////////////////////////////////////// + OMV_SPI_LCD_RST_ON(); HAL_Delay(100); diff --git a/src/omv/stm32fxxx_hal_msp.c b/src/omv/stm32fxxx_hal_msp.c index 7f35bc5fe..876b36816 100644 --- a/src/omv/stm32fxxx_hal_msp.c +++ b/src/omv/stm32fxxx_hal_msp.c @@ -326,51 +326,11 @@ void HAL_SPI_MspInit(SPI_HandleTypeDef *hspi) HAL_GPIO_Init(LEPTON_SPI_SSEL_PORT, &GPIO_InitStructure); } #endif - - #if defined(OMV_SPI_LCD_CONTROLLER) - if (hspi->Instance == OMV_SPI_LCD_CONTROLLER_INSTANCE) { - GPIO_InitTypeDef GPIO_InitStructure; - GPIO_InitStructure.Pull = GPIO_NOPULL; - GPIO_InitStructure.Mode = GPIO_MODE_AF_PP; - GPIO_InitStructure.Speed = GPIO_SPEED_FREQ_MEDIUM; - - GPIO_InitStructure.Alternate = OMV_SPI_LCD_MOSI_ALT; - GPIO_InitStructure.Pin = OMV_SPI_LCD_MOSI_PIN; - HAL_GPIO_Init(OMV_SPI_LCD_MOSI_PORT, &GPIO_InitStructure); - - GPIO_InitStructure.Alternate = OMV_SPI_LCD_SCLK_ALT; - GPIO_InitStructure.Pin = OMV_SPI_LCD_SCLK_PIN; - HAL_GPIO_Init(OMV_SPI_LCD_SCLK_PORT, &GPIO_InitStructure); - - GPIO_InitStructure.Mode = GPIO_MODE_OUTPUT_PP; - GPIO_InitStructure.Speed = GPIO_SPEED_FREQ_LOW; - - GPIO_InitStructure.Pin = OMV_SPI_LCD_RST_PIN; - HAL_GPIO_Init(OMV_SPI_LCD_RST_PORT, &GPIO_InitStructure); - OMV_SPI_LCD_RST_OFF(); - - GPIO_InitStructure.Pin = OMV_SPI_LCD_RS_PIN; - HAL_GPIO_Init(OMV_SPI_LCD_RS_PORT, &GPIO_InitStructure); - OMV_SPI_LCD_RS_OFF(); - - GPIO_InitStructure.Pin = OMV_SPI_LCD_CS_PIN; - HAL_GPIO_Init(OMV_SPI_LCD_CS_PORT, &GPIO_InitStructure); - OMV_SPI_LCD_CS_HIGH(); - } - #endif } void HAL_SPI_MspDeinit(SPI_HandleTypeDef *hspi) { - #if defined(OMV_SPI_LCD_CONTROLLER) - if (hspi->Instance == OMV_SPI_LCD_CONTROLLER_INSTANCE) { - HAL_GPIO_DeInit(OMV_SPI_LCD_MOSI_PORT, OMV_SPI_LCD_MOSI_PIN); - HAL_GPIO_DeInit(OMV_SPI_LCD_SCLK_PORT, OMV_SPI_LCD_SCLK_PIN); - HAL_GPIO_DeInit(OMV_SPI_LCD_RST_PORT, OMV_SPI_LCD_RST_PIN); - HAL_GPIO_DeInit(OMV_SPI_LCD_RS_PORT, OMV_SPI_LCD_RS_PIN); - HAL_GPIO_DeInit(OMV_SPI_LCD_CS_PORT, OMV_SPI_LCD_CS_PIN); - } - #endif + } #if defined(AUDIO_SAI)