InfiniTime.git

commit 24e6a2f8abab219868cb2eb6d02b3d83504c223c

Author: mark9064 <30447455+mark9064@users.noreply.github.com>

Avoid storing lambda

 src/drivers/Spi.cpp | 4 ++--
 src/drivers/Spi.h | 2 +-
 src/drivers/SpiMaster.cpp | 16 +++-------------
 src/drivers/SpiMaster.h | 3 +--
 src/drivers/St7789.cpp | 16 ++++++----------
 src/drivers/St7789.h | 2 +-


diff --git a/src/drivers/Spi.cpp b/src/drivers/Spi.cpp
index df0187756af8b47afca89438d4742822c70a0160..a03ea3c043ba82e07f393b26b496bd64696fee99 100644
--- a/src/drivers/Spi.cpp
+++ b/src/drivers/Spi.cpp
@@ -9,8 +9,8 @@   nrf_gpio_cfg_output(pinCsn);
   nrf_gpio_pin_set(pinCsn);
 }
 
-bool Spi::Write(const uint8_t* data, size_t size, std::function<void(bool)> TransactionHook) {
-  return spiMaster.Write(pinCsn, data, size, TransactionHook);
+bool Spi::Write(const uint8_t* data, size_t size, const std::function<void()>& transactionHook) {
+  return spiMaster.Write(pinCsn, data, size, transactionHook);
 }
 
 bool Spi::Read(uint8_t* cmd, size_t cmdSize, uint8_t* data, size_t dataSize) {




diff --git a/src/drivers/Spi.h b/src/drivers/Spi.h
index 4f48fafe491ce2f76a4ef9ff15163add392c6f33..e30620cc9849a09d37fdd08776eaa279d097503f 100644
--- a/src/drivers/Spi.h
+++ b/src/drivers/Spi.h
@@ -15,7 +15,7 @@       Spi(Spi&&) = delete;
       Spi& operator=(Spi&&) = delete;
 
       bool Init();
-      bool Write(const uint8_t* data, size_t size, std::function<void(bool)> TransactionHook);
+      bool Write(const uint8_t* data, size_t size, const std::function<void()>& transactionHook);
       bool Read(uint8_t* cmd, size_t cmdSize, uint8_t* data, size_t dataSize);
       bool WriteCmdAndBuffer(const uint8_t* cmd, size_t cmdSize, const uint8_t* data, size_t dataSize);
       void Sleep();




diff --git a/src/drivers/SpiMaster.cpp b/src/drivers/SpiMaster.cpp
index 5bfbf7b4698c8134efd476761890c4ea93b6c47c..eec62cb77918de9c48ab19f0fef43f79bd9b839b 100644
--- a/src/drivers/SpiMaster.cpp
+++ b/src/drivers/SpiMaster.cpp
@@ -137,9 +137,6 @@
     spiBaseAddress->TASKS_START = 1;
   } else {
     nrf_gpio_pin_set(this->pinCsn);
-    if (this->TransactionHook != nullptr) {
-      this->TransactionHook(false);
-    }
     currentBufferAddr = 0;
     BaseType_t xHigherPriorityTaskWoken = pdFALSE;
     xSemaphoreGiveFromISR(mutex, &xHigherPriorityTaskWoken);
@@ -170,13 +167,12 @@   spiBaseAddress->RXD.LIST = 0;
   spiBaseAddress->EVENTS_END = 0;
 }
 
-bool SpiMaster::Write(uint8_t pinCsn, const uint8_t* data, size_t size, std::function<void(bool)> TransactionHook) {
+bool SpiMaster::Write(uint8_t pinCsn, const uint8_t* data, size_t size, const std::function<void()>& transactionHook) {
   if (data == nullptr)
     return false;
   auto ok = xSemaphoreTake(mutex, portMAX_DELAY);
   ASSERT(ok == true);
 
-  this->TransactionHook = TransactionHook;
   this->pinCsn = pinCsn;
 
   if (size == 1) {
@@ -185,8 +181,8 @@   } else {
     DisableWorkaroundForFtpan58(spiBaseAddress, 0, 0);
   }
 
-  if (this->TransactionHook != nullptr) {
-    this->TransactionHook(true);
+  if (transactionHook != nullptr) {
+    transactionHook();
   }
   nrf_gpio_pin_clear(this->pinCsn);
 
@@ -203,9 +199,6 @@   if (size == 1) {
     while (spiBaseAddress->EVENTS_END == 0)
       ;
     nrf_gpio_pin_set(this->pinCsn);
-    if (this->TransactionHook != nullptr) {
-      this->TransactionHook(false);
-    }
     currentBufferAddr = 0;
 
     DisableWorkaroundForFtpan58(spiBaseAddress, 0, 0);
@@ -219,7 +212,6 @@
 bool SpiMaster::Read(uint8_t pinCsn, uint8_t* cmd, size_t cmdSize, uint8_t* data, size_t dataSize) {
   xSemaphoreTake(mutex, portMAX_DELAY);
 
-  this->TransactionHook = nullptr;
   this->pinCsn = pinCsn;
   DisableWorkaroundForFtpan58(spiBaseAddress, 0, 0);
   spiBaseAddress->INTENCLR = (1 << 6);
@@ -266,8 +258,6 @@ }
 
 bool SpiMaster::WriteCmdAndBuffer(uint8_t pinCsn, const uint8_t* cmd, size_t cmdSize, const uint8_t* data, size_t dataSize) {
   xSemaphoreTake(mutex, portMAX_DELAY);
-
-  this->TransactionHook = nullptr;
 
   this->pinCsn = pinCsn;
   DisableWorkaroundForFtpan58(spiBaseAddress, 0, 0);




diff --git a/src/drivers/SpiMaster.h b/src/drivers/SpiMaster.h
index 21980f4fc6a3e8433696ee815cda3fa996dd2dc3..2f39a1b2b0ad8508ae23415a3c985ceb11524dee 100644
--- a/src/drivers/SpiMaster.h
+++ b/src/drivers/SpiMaster.h
@@ -32,7 +32,7 @@       SpiMaster(SpiMaster&&) = delete;
       SpiMaster& operator=(SpiMaster&&) = delete;
 
       bool Init();
-      bool Write(uint8_t pinCsn, const uint8_t* data, size_t size, std::function<void(bool)> TransactionHook);
+      bool Write(uint8_t pinCsn, const uint8_t* data, size_t size, const std::function<void()>& transactionHook);
       bool Read(uint8_t pinCsn, uint8_t* cmd, size_t cmdSize, uint8_t* data, size_t dataSize);
 
       bool WriteCmdAndBuffer(uint8_t pinCsn, const uint8_t* cmd, size_t cmdSize, const uint8_t* data, size_t dataSize);
@@ -51,7 +51,6 @@       void PrepareRx(const volatile uint32_t bufferAddress, const volatile size_t size);
 
       NRF_SPIM_Type* spiBaseAddress;
       uint8_t pinCsn;
-      std::function<void(bool)> TransactionHook;
 
       SpiMaster::SpiModule spi;
       SpiMaster::Parameters params;




diff --git a/src/drivers/St7789.cpp b/src/drivers/St7789.cpp
index e42592e6487ef7a5a62670a3da0a47095ec13e82..e933c3740c8d8e0b8c1873fb24a7756e80aacd24 100644
--- a/src/drivers/St7789.cpp
+++ b/src/drivers/St7789.cpp
@@ -34,10 +34,8 @@   WriteData(&data, 1);
 }
 
 void St7789::WriteData(const uint8_t* data, size_t size) {
-  WriteSpi(data, size, [pinDataCommand = pinDataCommand](bool isStart) {
-    if (isStart) {
-      nrf_gpio_pin_set(pinDataCommand);
-    }
+  WriteSpi(data, size, [pinDataCommand = pinDataCommand]() {
+    nrf_gpio_pin_set(pinDataCommand);
   });
 }
 
@@ -46,15 +44,13 @@   WriteCommand(&data, 1);
 }
 
 void St7789::WriteCommand(const uint8_t* data, size_t size) {
-  WriteSpi(data, size, [pinDataCommand = pinDataCommand](bool isStart) {
-    if (isStart) {
-      nrf_gpio_pin_clear(pinDataCommand);
-    }
+  WriteSpi(data, size, [pinDataCommand = pinDataCommand]() {
+    nrf_gpio_pin_clear(pinDataCommand);
   });
 }
 
-void St7789::WriteSpi(const uint8_t* data, size_t size, std::function<void(bool)> TransactionHook) {
-  spi.Write(data, size, TransactionHook);
+void St7789::WriteSpi(const uint8_t* data, size_t size, const std::function<void()>& transactionHook) {
+  spi.Write(data, size, transactionHook);
 }
 
 void St7789::SoftwareReset() {




diff --git a/src/drivers/St7789.h b/src/drivers/St7789.h
index 5eb60cfd9fee63d8767365084f68e1f6a3cc8767..f49ed511de0d38b803366300f7bd4d045b2b94c5 100644
--- a/src/drivers/St7789.h
+++ b/src/drivers/St7789.h
@@ -47,7 +47,7 @@       void SetAddrWindow(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1);
       void SetVdv();
       void WriteCommand(uint8_t cmd);
       void WriteCommand(const uint8_t* data, size_t size);
-      void WriteSpi(const uint8_t* data, size_t size, std::function<void(bool)> TransactionHook);
+      void WriteSpi(const uint8_t* data, size_t size, const std::function<void()>& transactionHook);
 
       enum class Commands : uint8_t {
         SoftwareReset = 0x01,