fix removeApbChangeCallback() error in spiStopBus() (#3675)

* fix removeApbChangeCallback() error in spiStopBus()

spiStartBus() was using spiStopBus() to init the hardware, one of spiStopBus() functions is to unregister the runtime CPU clock speed change callback. But, spiStartBus() only wanted to init the hardware.  This patch separates the hardware init into a standalone function spiInitBus() that both spiStartBus() and spiStopBus() call.

* Update esp32-hal-spi.c

capitalization problem
This commit is contained in:
chuck todd 2020-01-26 15:20:19 -07:00 committed by Me No Dev
parent b50a1755c8
commit 80f9f9aeec

View File

@ -384,12 +384,8 @@ static void _on_apb_change(void * arg, apb_change_ev_t ev_type, uint32_t old_apb
} }
} }
void spiStopBus(spi_t * spi) static void spiInitBus(spi_t * spi)
{ {
if(!spi) {
return;
}
SPI_MUTEX_LOCK();
spi->dev->slave.trans_done = 0; spi->dev->slave.trans_done = 0;
spi->dev->slave.slave_mode = 0; spi->dev->slave.slave_mode = 0;
spi->dev->pin.val = 0; spi->dev->pin.val = 0;
@ -399,8 +395,19 @@ void spiStopBus(spi_t * spi)
spi->dev->ctrl1.val = 0; spi->dev->ctrl1.val = 0;
spi->dev->ctrl2.val = 0; spi->dev->ctrl2.val = 0;
spi->dev->clock.val = 0; spi->dev->clock.val = 0;
SPI_MUTEX_UNLOCK(); }
void spiStopBus(spi_t * spi)
{
if(!spi) {
return;
}
removeApbChangeCallback(spi, _on_apb_change); removeApbChangeCallback(spi, _on_apb_change);
SPI_MUTEX_LOCK();
spiInitBus(spi);
SPI_MUTEX_UNLOCK();
} }
spi_t * spiStartBus(uint8_t spi_num, uint32_t clockDiv, uint8_t dataMode, uint8_t bitOrder) spi_t * spiStartBus(uint8_t spi_num, uint32_t clockDiv, uint8_t dataMode, uint8_t bitOrder)
@ -431,12 +438,8 @@ spi_t * spiStartBus(uint8_t spi_num, uint32_t clockDiv, uint8_t dataMode, uint8_
DPORT_CLEAR_PERI_REG_MASK(DPORT_PERIP_RST_EN_REG, DPORT_SPI_RST_1); DPORT_CLEAR_PERI_REG_MASK(DPORT_PERIP_RST_EN_REG, DPORT_SPI_RST_1);
} }
spiStopBus(spi);
spiSetDataMode(spi, dataMode);
spiSetBitOrder(spi, bitOrder);
spiSetClockDiv(spi, clockDiv);
SPI_MUTEX_LOCK(); SPI_MUTEX_LOCK();
spiInitBus(spi);
spi->dev->user.usr_mosi = 1; spi->dev->user.usr_mosi = 1;
spi->dev->user.usr_miso = 1; spi->dev->user.usr_miso = 1;
spi->dev->user.doutdin = 1; spi->dev->user.doutdin = 1;
@ -447,6 +450,10 @@ spi_t * spiStartBus(uint8_t spi_num, uint32_t clockDiv, uint8_t dataMode, uint8_
} }
SPI_MUTEX_UNLOCK(); SPI_MUTEX_UNLOCK();
spiSetDataMode(spi, dataMode);
spiSetBitOrder(spi, bitOrder);
spiSetClockDiv(spi, clockDiv);
addApbChangeCallback(spi, _on_apb_change); addApbChangeCallback(spi, _on_apb_change);
return spi; return spi;
} }