Workaround for SPI bus being asleep.

This needs to get cherrypicked to another PR as SPI Sleep needs to use a semaphore or something
This commit is contained in:
Tim Keller 2021-10-17 21:33:01 +00:00
parent 1dd7174480
commit 2690c274af
2 changed files with 15 additions and 3 deletions

View file

@ -179,6 +179,10 @@ void SpiMaster::PrepareRx(const volatile uint32_t cmdAddress,
bool SpiMaster::Write(uint8_t pinCsn, const uint8_t* data, size_t size) { bool SpiMaster::Write(uint8_t pinCsn, const uint8_t* data, size_t size) {
if (data == nullptr) if (data == nullptr)
return false; return false;
if (!active) {
Wakeup();
}
auto ok = xSemaphoreTake(mutex, portMAX_DELAY); auto ok = xSemaphoreTake(mutex, portMAX_DELAY);
ASSERT(ok == true); ASSERT(ok == true);
taskToNotify = xTaskGetCurrentTaskHandle(); taskToNotify = xTaskGetCurrentTaskHandle();
@ -215,7 +219,9 @@ bool SpiMaster::Write(uint8_t pinCsn, const uint8_t* data, size_t size) {
bool SpiMaster::Read(uint8_t pinCsn, uint8_t* cmd, size_t cmdSize, uint8_t* data, size_t dataSize) { bool SpiMaster::Read(uint8_t pinCsn, uint8_t* cmd, size_t cmdSize, uint8_t* data, size_t dataSize) {
xSemaphoreTake(mutex, portMAX_DELAY); xSemaphoreTake(mutex, portMAX_DELAY);
if (!active) {
Wakeup();
}
taskToNotify = nullptr; taskToNotify = nullptr;
this->pinCsn = pinCsn; this->pinCsn = pinCsn;
@ -253,12 +259,16 @@ void SpiMaster::Sleep() {
nrf_gpio_cfg_default(params.pinSCK); nrf_gpio_cfg_default(params.pinSCK);
nrf_gpio_cfg_default(params.pinMOSI); nrf_gpio_cfg_default(params.pinMOSI);
nrf_gpio_cfg_default(params.pinMISO); nrf_gpio_cfg_default(params.pinMISO);
active = false;
NRF_LOG_INFO("[SPIMASTER] sleep") NRF_LOG_INFO("[SPIMASTER] sleep")
} }
void SpiMaster::Wakeup() { void SpiMaster::Wakeup() {
if (active) {
return;
}
Init(); Init();
active = true;
NRF_LOG_INFO("[SPIMASTER] Wakeup"); NRF_LOG_INFO("[SPIMASTER] Wakeup");
} }

View file

@ -60,6 +60,8 @@ namespace Pinetime {
volatile size_t currentBufferSize = 0; volatile size_t currentBufferSize = 0;
volatile TaskHandle_t taskToNotify; volatile TaskHandle_t taskToNotify;
SemaphoreHandle_t mutex = nullptr; SemaphoreHandle_t mutex = nullptr;
bool active;
}; };
} }
} }