From 1b4b422ab6d7588e21e58fcf1d2ba04470abc611 Mon Sep 17 00:00:00 2001 From: Tim Keller Date: Mon, 18 Oct 2021 04:20:11 +0000 Subject: [PATCH] More attempted SPI fixes --- src/drivers/Spi.cpp | 14 ++++++++++++++ src/drivers/Spi.h | 1 + 2 files changed, 15 insertions(+) diff --git a/src/drivers/Spi.cpp b/src/drivers/Spi.cpp index e477622b..46552437 100644 --- a/src/drivers/Spi.cpp +++ b/src/drivers/Spi.cpp @@ -10,14 +10,24 @@ Spi::Spi(SpiMaster& spiMaster, uint8_t pinCsn) : spiMaster {spiMaster}, pinCsn { } bool Spi::Write(const uint8_t* data, size_t size) { + if(!active){ + Wakeup(); + } return spiMaster.Write(pinCsn, data, size); } bool Spi::Read(uint8_t* cmd, size_t cmdSize, uint8_t* data, size_t dataSize) { + if(!active){ + Wakeup(); + } return spiMaster.Read(pinCsn, cmd, cmdSize, data, dataSize); } void Spi::Sleep() { + if(!active){ + return; + } + active = false; nrf_gpio_cfg_default(pinCsn); NRF_LOG_INFO("[SPI] Sleep") } @@ -32,7 +42,11 @@ bool Spi::Init() { } void Spi::Wakeup() { + if(active){ + return; + } nrf_gpio_cfg_output(pinCsn); nrf_gpio_pin_set(pinCsn); + active=true; NRF_LOG_INFO("[SPI] Wakeup") } diff --git a/src/drivers/Spi.h b/src/drivers/Spi.h index 9b6a30f4..51de2b34 100644 --- a/src/drivers/Spi.h +++ b/src/drivers/Spi.h @@ -23,6 +23,7 @@ namespace Pinetime { private: SpiMaster& spiMaster; uint8_t pinCsn; + bool active; }; } }