Avoid storing lambda
This commit is contained in:
parent
9a7ba405e1
commit
24e6a2f8ab
|
@ -9,8 +9,8 @@ Spi::Spi(SpiMaster& spiMaster, uint8_t pinCsn) : spiMaster {spiMaster}, 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) {
|
||||
|
|
|
@ -15,7 +15,7 @@ namespace Pinetime {
|
|||
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();
|
||||
|
|
|
@ -137,9 +137,6 @@ void SpiMaster::OnEndEvent() {
|
|||
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 @@ 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, 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 @@ bool SpiMaster::Write(uint8_t pinCsn, const uint8_t* data, size_t size, std::fun
|
|||
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 @@ bool SpiMaster::Write(uint8_t pinCsn, const uint8_t* data, size_t size, std::fun
|
|||
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::Write(uint8_t pinCsn, const uint8_t* data, size_t size, std::fun
|
|||
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);
|
||||
|
@ -267,8 +259,6 @@ void SpiMaster::Wakeup() {
|
|||
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);
|
||||
spiBaseAddress->INTENCLR = (1 << 6);
|
||||
|
|
|
@ -32,7 +32,7 @@ namespace Pinetime {
|
|||
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 @@ namespace Pinetime {
|
|||
|
||||
NRF_SPIM_Type* spiBaseAddress;
|
||||
uint8_t pinCsn;
|
||||
std::function<void(bool)> TransactionHook;
|
||||
|
||||
SpiMaster::SpiModule spi;
|
||||
SpiMaster::Parameters params;
|
||||
|
|
|
@ -34,10 +34,8 @@ void St7789::WriteData(uint8_t data) {
|
|||
}
|
||||
|
||||
void St7789::WriteData(const uint8_t* data, size_t size) {
|
||||
WriteSpi(data, size, [pinDataCommand = pinDataCommand](bool isStart) {
|
||||
if (isStart) {
|
||||
WriteSpi(data, size, [pinDataCommand = pinDataCommand]() {
|
||||
nrf_gpio_pin_set(pinDataCommand);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -46,15 +44,13 @@ void St7789::WriteCommand(uint8_t data) {
|
|||
}
|
||||
|
||||
void St7789::WriteCommand(const uint8_t* data, size_t size) {
|
||||
WriteSpi(data, size, [pinDataCommand = pinDataCommand](bool isStart) {
|
||||
if (isStart) {
|
||||
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() {
|
||||
|
|
|
@ -47,7 +47,7 @@ namespace Pinetime {
|
|||
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,
|
||||
|
|
Loading…
Reference in a new issue