summaryrefslogtreecommitdiff
path: root/src/drivers/SpiNorFlash.cpp
diff options
context:
space:
mode:
authorJF <jf@codingfield.com>2020-08-22 17:59:59 +0200
committerJF <jf@codingfield.com>2020-08-22 17:59:59 +0200
commitf7e40b1b5879242b4ce59854dbbadb44fe5f75e4 (patch)
treec90d927a985d1b13f48af1d6e9aeb6d4c0e7cc0f /src/drivers/SpiNorFlash.cpp
parentecbbeb6283178696ae36891225e086d3154e8a8a (diff)
Re-implement sleep/wakeup for touch panel, display, NOR Flash, SPI and TWI.
Diffstat (limited to 'src/drivers/SpiNorFlash.cpp')
-rw-r--r--src/drivers/SpiNorFlash.cpp22
1 files changed, 18 insertions, 4 deletions
diff --git a/src/drivers/SpiNorFlash.cpp b/src/drivers/SpiNorFlash.cpp
index 7e4da1ca..351a9dfc 100644
--- a/src/drivers/SpiNorFlash.cpp
+++ b/src/drivers/SpiNorFlash.cpp
@@ -11,8 +11,8 @@ SpiNorFlash::SpiNorFlash(Spi& spi) : spi{spi} {
}
void SpiNorFlash::Init() {
- auto id = ReadIdentificaion();
- NRF_LOG_INFO("[SPI FLASH] Manufacturer : %d, Memory type : %d, memory density : %d", id.manufacturer, id.type, id.density);
+ device_id = ReadIdentificaion();
+ NRF_LOG_INFO("[SPI FLASH] Manufacturer : %d, Memory type : %d, memory density : %d", device_id.manufacturer, device_id.type, device_id.density);
}
void SpiNorFlash::Uninit() {
@@ -20,11 +20,25 @@ void SpiNorFlash::Uninit() {
}
void SpiNorFlash::Sleep() {
-
+ auto cmd = static_cast<uint8_t>(Commands::DeepPowerDown);
+ spi.Write(&cmd, sizeof(uint8_t));
+ NRF_LOG_INFO("[FLASH] Sleep")
}
void SpiNorFlash::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};
+ uint8_t id = 0;
+ spi.Read(reinterpret_cast<uint8_t *>(&cmd), cmdSize, &id, 1);
+ auto devId = device_id = ReadIdentificaion();
+ if(devId.type != device_id.type) {
+ NRF_LOG_INFO("[SpiNorFlash] ID on Wakeup: Failed");
+ }
+ else {
+ NRF_LOG_INFO("[SpiNorFlash] ID on Wakeup: %d", id);
+ }
+ NRF_LOG_INFO("[FLASH] Wakeup")
}
SpiNorFlash::Identification SpiNorFlash::ReadIdentificaion() {