diff options
| author | mark9064 <30447455+mark9064@users.noreply.github.com> | 2024-02-11 00:44:06 +0000 |
|---|---|---|
| committer | JF <JF002@users.noreply.github.com> | 2024-05-01 16:13:47 +0200 |
| commit | 079e676baf70a943d31317afde47b759ca69ca2d (patch) | |
| tree | 9768d7347ba10ed2e05753e8752f0969967f7075 /src/drivers/SpiMaster.cpp | |
| parent | 6b5235c3013bf8ecbd1568669f48efce3508e8c0 (diff) | |
SPI transaction hooks
Diffstat (limited to 'src/drivers/SpiMaster.cpp')
| -rw-r--r-- | src/drivers/SpiMaster.cpp | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/src/drivers/SpiMaster.cpp b/src/drivers/SpiMaster.cpp index 3446d639..4c2bc940 100644 --- a/src/drivers/SpiMaster.cpp +++ b/src/drivers/SpiMaster.cpp @@ -143,6 +143,9 @@ void SpiMaster::OnEndEvent() { } nrf_gpio_pin_set(this->pinCsn); + if (this->TransactionHook != nullptr) { + this->TransactionHook(false); + } currentBufferAddr = 0; BaseType_t xHigherPriorityTaskWoken2 = pdFALSE; xSemaphoreGiveFromISR(mutex, &xHigherPriorityTaskWoken2); @@ -173,13 +176,14 @@ void SpiMaster::PrepareRx(const uint32_t bufferAddress, const size_t size) { spiBaseAddress->EVENTS_END = 0; } -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, void (*TransactionHook)(bool)) { if (data == nullptr) return false; auto ok = xSemaphoreTake(mutex, portMAX_DELAY); ASSERT(ok == true); taskToNotify = xTaskGetCurrentTaskHandle(); + this->TransactionHook = TransactionHook; this->pinCsn = pinCsn; if (size == 1) { @@ -188,6 +192,9 @@ bool SpiMaster::Write(uint8_t pinCsn, const uint8_t* data, size_t size) { DisableWorkaroundForFtpan58(spiBaseAddress, 0, 0); } + if (this->TransactionHook != nullptr) { + this->TransactionHook(true); + } nrf_gpio_pin_clear(this->pinCsn); currentBufferAddr = (uint32_t) data; @@ -203,6 +210,9 @@ bool SpiMaster::Write(uint8_t pinCsn, const uint8_t* data, size_t size) { while (spiBaseAddress->EVENTS_END == 0) ; nrf_gpio_pin_set(this->pinCsn); + if (this->TransactionHook != nullptr) { + this->TransactionHook(false); + } currentBufferAddr = 0; DisableWorkaroundForFtpan58(spiBaseAddress, 0, 0); @@ -217,7 +227,7 @@ bool SpiMaster::Read(uint8_t pinCsn, uint8_t* cmd, size_t cmdSize, uint8_t* data xSemaphoreTake(mutex, portMAX_DELAY); taskToNotify = nullptr; - + this->TransactionHook = nullptr; this->pinCsn = pinCsn; DisableWorkaroundForFtpan58(spiBaseAddress, 0, 0); spiBaseAddress->INTENCLR = (1 << 6); @@ -267,6 +277,8 @@ bool SpiMaster::WriteCmdAndBuffer(uint8_t pinCsn, const uint8_t* cmd, size_t cmd taskToNotify = nullptr; + this->TransactionHook = nullptr; + this->pinCsn = pinCsn; DisableWorkaroundForFtpan58(spiBaseAddress, 0, 0); spiBaseAddress->INTENCLR = (1 << 6); |
