Skip to content

Commit 4c0f897

Browse files
committed
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.
1 parent 2fa3aaa commit 4c0f897

4 files changed

Lines changed: 11 additions & 1 deletion

File tree

src/drivers/Spi.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ bool Spi::WriteCmdAndBuffer(const uint8_t* cmd, size_t cmdSize, const uint8_t* d
2727
}
2828

2929
bool Spi::Init() {
30-
nrf_gpio_pin_set(pinCsn); /* disable Set slave select (inactive high) */
30+
nrf_gpio_cfg_output(pinCsn);
31+
nrf_gpio_pin_set(pinCsn);
3132
return true;
3233
}
3334

src/drivers/SpiMaster.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,9 @@ bool SpiMaster::Write(uint8_t pinCsn, const uint8_t* data, size_t size) {
204204
;
205205
nrf_gpio_pin_set(this->pinCsn);
206206
currentBufferAddr = 0;
207+
208+
DisableWorkaroundForFtpan58(spiBaseAddress, 0, 0);
209+
207210
xSemaphoreGive(mutex);
208211
}
209212

src/drivers/SpiNorFlash.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ SpiNorFlash::SpiNorFlash(Spi& spi) : spi {spi} {
1010
}
1111

1212
void SpiNorFlash::Init() {
13+
spi.Init();
1314
device_id = ReadIdentificaion();
1415
NRF_LOG_INFO("[SpiNorFlash] Manufacturer : %d, Memory type : %d, memory density : %d",
1516
device_id.manufacturer,
@@ -23,10 +24,12 @@ void SpiNorFlash::Uninit() {
2324
void SpiNorFlash::Sleep() {
2425
auto cmd = static_cast<uint8_t>(Commands::DeepPowerDown);
2526
spi.Write(&cmd, sizeof(uint8_t));
27+
spi.Sleep();
2628
NRF_LOG_INFO("[SpiNorFlash] Sleep")
2729
}
2830

2931
void SpiNorFlash::Wakeup() {
32+
spi.Wakeup();
3033
// send Commands::ReleaseFromDeepPowerDown then 3 dummy bytes before reading Device ID
3134
static constexpr uint8_t cmdSize = 4;
3235
uint8_t cmd[cmdSize] = {static_cast<uint8_t>(Commands::ReleaseFromDeepPowerDown), 0x01, 0x02, 0x03};

src/drivers/St7789.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,10 +187,13 @@ void St7789::HardwareReset() {
187187
void St7789::Sleep() {
188188
SleepIn();
189189
nrf_gpio_cfg_default(pinDataCommand);
190+
nrf_gpio_cfg_default(26);
191+
spi.Sleep();
190192
NRF_LOG_INFO("[LCD] Sleep");
191193
}
192194

193195
void St7789::Wakeup() {
196+
spi.Wakeup();
194197
nrf_gpio_cfg_output(pinDataCommand);
195198
SleepOut();
196199
VerticalScrollStartAddress(verticalScrollingStartAddress);

0 commit comments

Comments
 (0)