Author: Jean-François Milants <jf@codingfield.com>
Power optimization - Improve SPI sleep mode Ensure that all pins are set to their default configuration during sleep mode. Disable the workaround for FTPAN58 (SPI freezes when transfering a single byte) at the end of the transfer. This disables the resources needed for the workaround. Those changes reduce the power usage by 430-490µA.
src/drivers/Spi.cpp | 3 ++- src/drivers/SpiMaster.cpp | 3 +++ src/drivers/SpiNorFlash.cpp | 3 +++ src/drivers/St7789.cpp | 3 +++
diff --git a/src/drivers/Spi.cpp b/src/drivers/Spi.cpp index e477622b6f56ac9b27a390f71da400d7402946dd..c85b90c17c568a88341ecc8d8cd2cb4452cac04a 100644 --- a/src/drivers/Spi.cpp +++ b/src/drivers/Spi.cpp @@ -27,7 +27,8 @@ return spiMaster.WriteCmdAndBuffer(pinCsn, cmd, cmdSize, data, dataSize); } bool Spi::Init() { - nrf_gpio_pin_set(pinCsn); /* disable Set slave select (inactive high) */ + nrf_gpio_cfg_output(pinCsn); + nrf_gpio_pin_set(pinCsn); return true; } diff --git a/src/drivers/SpiMaster.cpp b/src/drivers/SpiMaster.cpp index 234884ab53276748e29806323ae241648f89d917..1a2fab9c27a721cdcbf15c31f86f1943a6c89282 100644 --- a/src/drivers/SpiMaster.cpp +++ b/src/drivers/SpiMaster.cpp @@ -204,6 +204,9 @@ while (spiBaseAddress->EVENTS_END == 0) ; nrf_gpio_pin_set(this->pinCsn); currentBufferAddr = 0; + + DisableWorkaroundForFtpan58(spiBaseAddress, 0, 0); + xSemaphoreGive(mutex); } diff --git a/src/drivers/SpiNorFlash.cpp b/src/drivers/SpiNorFlash.cpp index 28f82fe6c4bdcc27249ff45f539cd7ac20cfc249..525b812c2521327c671304e140ff7030715a52f1 100644 --- a/src/drivers/SpiNorFlash.cpp +++ b/src/drivers/SpiNorFlash.cpp @@ -10,6 +10,7 @@ SpiNorFlash::SpiNorFlash(Spi& spi) : spi {spi} { } void SpiNorFlash::Init() { + spi.Init(); device_id = ReadIdentificaion(); NRF_LOG_INFO("[SpiNorFlash] Manufacturer : %d, Memory type : %d, memory density : %d", device_id.manufacturer, @@ -23,10 +24,12 @@ void SpiNorFlash::Sleep() { auto cmd = static_cast<uint8_t>(Commands::DeepPowerDown); spi.Write(&cmd, sizeof(uint8_t)); + spi.Sleep(); NRF_LOG_INFO("[SpiNorFlash] Sleep") } void SpiNorFlash::Wakeup() { + spi.Wakeup(); // send Commands::ReleaseFromDeepPowerDown then 3 dummy bytes before reading Device ID static constexpr uint8_t cmdSize = 4; uint8_t cmd[cmdSize] = {static_cast<uint8_t>(Commands::ReleaseFromDeepPowerDown), 0x01, 0x02, 0x03}; diff --git a/src/drivers/St7789.cpp b/src/drivers/St7789.cpp index cfd5bd2ce4b8b42a0d93c3cbecc3a0c5dce17e58..ed98c06da8d28e2358f3390c10115005264540a0 100644 --- a/src/drivers/St7789.cpp +++ b/src/drivers/St7789.cpp @@ -187,10 +187,13 @@ void St7789::Sleep() { SleepIn(); nrf_gpio_cfg_default(pinDataCommand); + nrf_gpio_cfg_default(26); + spi.Sleep(); NRF_LOG_INFO("[LCD] Sleep"); } void St7789::Wakeup() { + spi.Wakeup(); nrf_gpio_cfg_output(pinDataCommand); SleepOut(); VerticalScrollStartAddress(verticalScrollingStartAddress);