Skip to content

Commit

Permalink
More attempted SPI fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
geekbozu committed Oct 18, 2021
1 parent d1e40cb commit bed7e73
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/drivers/Spi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand All @@ -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")
}
1 change: 1 addition & 0 deletions src/drivers/Spi.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ namespace Pinetime {
private:
SpiMaster& spiMaster;
uint8_t pinCsn;
bool active;
};
}
}

0 comments on commit bed7e73

Please sign in to comment.