From 9a7ba405e1384510f92f68e75b4bb54218f637c3 Mon Sep 17 00:00:00 2001 From: mark9064 <30447455+mark9064@users.noreply.github.com> Date: Tue, 2 Apr 2024 11:14:45 +0100 Subject: [PATCH] Refactor lambdas --- src/drivers/St7789.cpp | 38 ++++++++++++++++++-------------------- src/drivers/St7789.h | 4 ++-- 2 files changed, 20 insertions(+), 22 deletions(-) diff --git a/src/drivers/St7789.cpp b/src/drivers/St7789.cpp index 6e5d13b1..e42592e6 100644 --- a/src/drivers/St7789.cpp +++ b/src/drivers/St7789.cpp @@ -29,27 +29,27 @@ void St7789::Init() { DisplayOn(); } -void St7789::EnableDataMode(bool isStart) { - if (isStart) { - nrf_gpio_pin_set(pinDataCommand); - } -} - -void St7789::EnableCommandMode(bool isStart) { - if (isStart) { - nrf_gpio_pin_clear(pinDataCommand); - } -} - void St7789::WriteData(uint8_t data) { - WriteSpi(&data, 1, [this](bool isStart) { - EnableDataMode(isStart); + 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); + } }); } -void St7789::WriteCommand(uint8_t cmd) { - WriteSpi(&cmd, 1, [this](bool isStart) { - EnableCommandMode(isStart); +void St7789::WriteCommand(uint8_t data) { + 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); + } }); } @@ -138,9 +138,7 @@ void St7789::SetAddrWindow(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1) { void St7789::WriteToRam(const uint8_t* data, size_t size) { WriteCommand(static_cast(Commands::WriteToRam)); - WriteSpi(data, size, [this](bool isStart) { - EnableDataMode(isStart); - }); + WriteData(data, size); } void St7789::SetVdv() { diff --git a/src/drivers/St7789.h b/src/drivers/St7789.h index 0c73f77e..5eb60cfd 100644 --- a/src/drivers/St7789.h +++ b/src/drivers/St7789.h @@ -46,9 +46,8 @@ namespace Pinetime { 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 TransactionHook); - void EnableDataMode(bool isStart); - void EnableCommandMode(bool isStart); enum class Commands : uint8_t { SoftwareReset = 0x01, @@ -68,6 +67,7 @@ namespace Pinetime { VdvSet = 0xc4, }; void WriteData(uint8_t data); + void WriteData(const uint8_t* data, size_t size); void ColumnAddressSet(); static constexpr uint16_t Width = 240;