Refactor St7789 as a generic Display class.

This commit is contained in:
Jean-François Milants 2022-12-28 18:12:32 +01:00
parent 8b2c875f02
commit 89421de606
19 changed files with 199 additions and 121 deletions

View File

@ -435,7 +435,7 @@ list(APPEND SOURCE_FILES
##
main.cpp
drivers/St7789.cpp
drivers/displays/St7789.cpp
drivers/nrf52/SpiMaster.cpp
drivers/nrf52/Spi.cpp
drivers/nrf52/TwiMaster.cpp
@ -502,7 +502,7 @@ list(APPEND RECOVERY_SOURCE_FILES
displayapp/DisplayAppRecovery.cpp
main.cpp
drivers/St7789.cpp
drivers/displays/St7789.cpp
drivers/nrf52/SpiMaster.cpp
drivers/nrf52/Spi.cpp
drivers/nrf52/TwiMaster.cpp
@ -575,7 +575,7 @@ list(APPEND RECOVERYLOADER_SOURCE_FILES
components/rle/RleDecoder.cpp
components/gfx/Gfx.cpp
drivers/St7789.cpp
drivers/displays/St7789.cpp
components/brightness/BrightnessController.cpp
recoveryLoader.cpp
@ -618,7 +618,7 @@ set(INCLUDE_FILES
displayapp/widgets/Counter.h
displayapp/widgets/PageIndicator.h
displayapp/widgets/StatusIcons.h
drivers/St7789.h
drivers/displays/St7789.h
drivers/SpiNorFlash.h
drivers/nrf52/SpiMaster.h
drivers/nrf52/Spi.h

View File

@ -1,8 +1,8 @@
#include "components/gfx/Gfx.h"
#include "drivers/St7789.h"
#include "drivers/displays/St7789.h"
using namespace Pinetime::Components;
Gfx::Gfx(Pinetime::Drivers::St7789& lcd) : lcd {lcd} {
Gfx::Gfx(Pinetime::Drivers::Displays::St7789& lcd) : lcd {lcd} {
}
void Gfx::Init() {

View File

@ -8,12 +8,14 @@
namespace Pinetime {
namespace Drivers {
class St7789;
namespace Displays {
class St7789;
}
}
namespace Components {
class Gfx : public Pinetime::Drivers::BufferProvider {
public:
explicit Gfx(Drivers::St7789& lcd);
explicit Gfx(Drivers::Displays::St7789& lcd);
void Init();
void ClearScreen();
void DrawString(uint8_t x, uint8_t y, uint16_t color, const char* text, const FONT_INFO* p_font, bool wrap);
@ -49,7 +51,7 @@ namespace Pinetime {
volatile State state;
uint16_t buffer[width]; // 1 line buffer
Drivers::St7789& lcd;
Drivers::Displays::St7789& lcd;
void SetBackgroundColor(uint16_t color);
void WaitTransferFinished() const;

View File

@ -30,8 +30,6 @@
#include "displayapp/screens/PassKey.h"
#include "displayapp/screens/Error.h"
#include "drivers/St7789.h"
#include "drivers/Watchdog.h"
#include "systemtask/SystemTask.h"
#include "systemtask/Messages.h"
@ -59,7 +57,7 @@ namespace {
}
}
DisplayApp::DisplayApp(Drivers::St7789& lcd,
DisplayApp::DisplayApp(Drivers::Display& lcd,
Components::LittleVgl& lvgl,
Pinetime::Drivers::TouchPanel& touchPanel,
Controllers::Battery& batteryController,

View File

@ -23,7 +23,6 @@
namespace Pinetime {
namespace Drivers {
class St7789;
class WatchdogView;
}
namespace Controllers {
@ -46,7 +45,7 @@ namespace Pinetime {
enum class States { Idle, Running };
enum class FullRefreshDirections { None, Up, Down, Left, Right, LeftAnim, RightAnim };
DisplayApp(Drivers::St7789& lcd,
DisplayApp(Drivers::Display& lcd,
Components::LittleVgl& lvgl,
Pinetime::Drivers::TouchPanel&,
Controllers::Battery& batteryController,
@ -73,7 +72,7 @@ namespace Pinetime {
void Register(Pinetime::System::SystemTask* systemTask);
private:
Pinetime::Drivers::St7789& lcd;
Pinetime::Drivers::Display& lcd;
Pinetime::Components::LittleVgl& lvgl;
Pinetime::Drivers::TouchPanel& touchPanel;
Pinetime::Controllers::Battery& batteryController;

View File

@ -10,7 +10,7 @@
using namespace Pinetime::Applications;
DisplayApp::DisplayApp(Drivers::St7789& lcd,
DisplayApp::DisplayApp(Drivers::Display& lcd,
Components::LittleVgl& lvgl,
Drivers::TouchPanel& touchPanel,
Controllers::Battery& batteryController,

View File

@ -1,7 +1,6 @@
#pragma once
#include <FreeRTOS.h>
#include <task.h>
#include <drivers/St7789.h>
#include <drivers/SpiMaster.h>
#include <bits/unique_ptr.h>
#include <queue.h>
@ -15,10 +14,10 @@
#include "displayapp/Messages.h"
#include "displayapp/DummyLittleVgl.h"
#include "port/TouchPanel.h"
#include "port/Display.h"
namespace Pinetime {
namespace Drivers {
class St7789;
class WatchdogView;
}
namespace Controllers {
@ -44,7 +43,7 @@ namespace Pinetime {
namespace Applications {
class DisplayApp {
public:
DisplayApp(Drivers::St7789& lcd,
DisplayApp(Drivers::Display& lcd,
Components::LittleVgl& lvgl,
Drivers::TouchPanel&,
Controllers::Battery& batteryController,
@ -75,7 +74,7 @@ namespace Pinetime {
void DisplayOtaProgress(uint8_t percent, uint16_t color);
void InitHw();
void Refresh();
Pinetime::Drivers::St7789& lcd;
Pinetime::Drivers::Display& lcd;
Controllers::Ble& bleController;
static constexpr uint8_t queueSize = 10;

View File

@ -3,15 +3,16 @@
#include <lvgl/src/lv_core/lv_style.h>
#include <lvgl/src/lv_themes/lv_theme.h>
#include <lvgl/src/lv_hal/lv_hal.h>
#include <drivers/St7789.h>
#include "port/TouchPanel.h"
#include "port/Display.h"
namespace Pinetime {
namespace Components {
class LittleVgl {
public:
enum class FullRefreshDirections { None, Up, Down };
LittleVgl(Pinetime::Drivers::St7789& lcd, Pinetime::Drivers::TouchPanel & touchPanel) {
LittleVgl(Pinetime::Drivers::Display& lcd, Pinetime::Drivers::TouchPanel & touchPanel) {
}
LittleVgl(const LittleVgl&) = delete;

View File

@ -4,7 +4,6 @@
#include <FreeRTOS.h>
#include <task.h>
//#include <projdefs.h>
#include "drivers/St7789.h"
using namespace Pinetime::Components;
@ -30,7 +29,7 @@ bool touchpad_read(lv_indev_drv_t* indev_drv, lv_indev_data_t* data) {
return lvgl->GetTouchPadInfo(data);
}
LittleVgl::LittleVgl(Pinetime::Drivers::St7789& lcd, Pinetime::Drivers::TouchPanel& touchPanel) : lcd {lcd}, touchPanel {touchPanel} {
LittleVgl::LittleVgl(Pinetime::Drivers::Display& lcd, Pinetime::Drivers::TouchPanel& touchPanel) : lcd {lcd}, touchPanel {touchPanel} {
}
void LittleVgl::Init() {

View File

@ -2,17 +2,14 @@
#include <lvgl/lvgl.h>
#include "port/TouchPanel.h"
#include "port/Display.h"
namespace Pinetime {
namespace Drivers {
class St7789;
}
namespace Components {
class LittleVgl {
public:
enum class FullRefreshDirections { None, Up, Down, Left, Right, LeftAnim, RightAnim };
LittleVgl(Pinetime::Drivers::St7789& lcd, Pinetime::Drivers::TouchPanel& touchPanel);
LittleVgl(Pinetime::Drivers::Display& lcd, Pinetime::Drivers::TouchPanel& touchPanel);
LittleVgl(const LittleVgl&) = delete;
LittleVgl& operator=(const LittleVgl&) = delete;
@ -39,7 +36,7 @@ namespace Pinetime {
void InitTouchpad();
void InitTheme();
Pinetime::Drivers::St7789& lcd;
Pinetime::Drivers::Display& lcd;
Pinetime::Drivers::TouchPanel& touchPanel;
lv_disp_buf_t disp_buf_2;

68
src/drivers/Display.h Normal file
View File

@ -0,0 +1,68 @@
#pragma once
#include <concepts>
#include <cstdint>
#include <cstddef>
namespace Pinetime {
namespace Drivers {
template <typename DisplayImpl>
concept IsDisplay = requires(DisplayImpl display, uint16_t line, uint16_t coord, uint32_t color, uint16_t dimension, const uint8_t* data, size_t size) {
{ display.Init() };
{ display.Uninit() };
{ display.DrawPixel(coord, coord, color) };
{ display.VerticalScrollDefinition(line, line, line) };
{ display.VerticalScrollStartAddress(line) };
{ display.DrawBuffer(coord, coord, dimension, dimension, data, size) };
{ display.Sleep() };
{ display.Wakeup() };
};
namespace Interface {
template <class T>
requires IsDisplay<T>
class Display {
public:
explicit Display(T& impl) : impl {impl} {}
Display(const Display&) = delete;
Display& operator=(const Display&) = delete;
Display(Display&&) = delete;
Display& operator=(Display&&) = delete;
void Init() {
impl.Init();
}
void Uninit() {
impl.Uninit();
}
void DrawPixel(uint16_t x, uint16_t y, uint32_t color) {
impl.DrawPixel(x, y, color);
}
void VerticalScrollDefinition(uint16_t topFixedLines, uint16_t scrollLines, uint16_t bottomFixedLines) {
impl.VerticalScrollDefinition(topFixedLines, scrollLines, bottomFixedLines);
}
void VerticalScrollStartAddress(uint16_t line) {
impl.VerticalScrollStartAddress(line);
}
void DrawBuffer(uint16_t x, uint16_t y, uint16_t width, uint16_t height, const uint8_t* data, size_t size) {
impl.DrawBuffer(x, y, width, height, data, size);
}
void Sleep() {
impl.Sleep();
}
void Wakeup() {
impl.Wakeup();
}
private:
T& impl;
};
}
}
}

View File

@ -1,77 +0,0 @@
#pragma once
#include "drivers/Spi.h"
#include <cstddef>
#include <cstdint>
#include "port/Spi.h"
namespace Pinetime {
namespace Drivers {
class St7789 {
public:
explicit St7789(Spi& spi, uint8_t pinDataCommand);
St7789(const St7789&) = delete;
St7789& operator=(const St7789&) = delete;
St7789(St7789&&) = delete;
St7789& operator=(St7789&&) = delete;
void Init();
void Uninit();
void DrawPixel(uint16_t x, uint16_t y, uint32_t color);
void VerticalScrollDefinition(uint16_t topFixedLines, uint16_t scrollLines, uint16_t bottomFixedLines);
void VerticalScrollStartAddress(uint16_t line);
void DrawBuffer(uint16_t x, uint16_t y, uint16_t width, uint16_t height, const uint8_t* data, size_t size);
void Sleep();
void Wakeup();
private:
Spi& spi;
uint8_t pinDataCommand;
uint8_t verticalScrollingStartAddress = 0;
void HardwareReset();
void SoftwareReset();
void SleepOut();
void SleepIn();
void ColMod();
void MemoryDataAccessControl();
void DisplayInversionOn();
void NormalModeOn();
void WriteToRam();
void DisplayOn();
void DisplayOff();
void SetAddrWindow(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1);
void SetVdv();
void WriteCommand(uint8_t cmd);
void WriteSpi(const uint8_t* data, size_t size);
enum class Commands : uint8_t {
SoftwareReset = 0x01,
SleepIn = 0x10,
SleepOut = 0x11,
NormalModeOn = 0x13,
DisplayInversionOn = 0x21,
DisplayOff = 0x28,
DisplayOn = 0x29,
ColumnAddressSet = 0x2a,
RowAddressSet = 0x2b,
WriteToRam = 0x2c,
MemoryDataAccessControl = 0x36,
VerticalScrollDefinition = 0x33,
VerticalScrollStartAddress = 0x37,
ColMod = 0x3a,
VdvSet = 0xc4,
};
void WriteData(uint8_t data);
void ColumnAddressSet();
static constexpr uint16_t Width = 240;
static constexpr uint16_t Height = 320;
void RowAddressSet();
};
}
}

View File

@ -1,10 +1,10 @@
#include "drivers/St7789.h"
#include "St7789.h"
#include <hal/nrf_gpio.h>
#include <libraries/delay/nrf_delay.h>
#include <nrfx_log.h>
#include "drivers/Spi.h"
using namespace Pinetime::Drivers;
using namespace Pinetime::Drivers::Displays;
St7789::St7789(Spi& spi, uint8_t pinDataCommand) : spi {spi}, pinDataCommand {pinDataCommand} {
}

View File

@ -0,0 +1,78 @@
#pragma once
#include "drivers/Spi.h"
#include <cstddef>
#include <cstdint>
#include "port/Spi.h"
namespace Pinetime {
namespace Drivers {
namespace Displays {
class St7789 {
public:
explicit St7789(Spi& spi, uint8_t pinDataCommand);
St7789(const St7789&) = delete;
St7789& operator=(const St7789&) = delete;
St7789(St7789&&) = delete;
St7789& operator=(St7789&&) = delete;
void Init();
void Uninit();
void DrawPixel(uint16_t x, uint16_t y, uint32_t color);
void VerticalScrollDefinition(uint16_t topFixedLines, uint16_t scrollLines, uint16_t bottomFixedLines);
void VerticalScrollStartAddress(uint16_t line);
void DrawBuffer(uint16_t x, uint16_t y, uint16_t width, uint16_t height, const uint8_t* data, size_t size);
void Sleep();
void Wakeup();
private:
Spi& spi;
uint8_t pinDataCommand;
uint8_t verticalScrollingStartAddress = 0;
void HardwareReset();
void SoftwareReset();
void SleepOut();
void SleepIn();
void ColMod();
void MemoryDataAccessControl();
void DisplayInversionOn();
void NormalModeOn();
void WriteToRam();
void DisplayOn();
void DisplayOff();
void SetAddrWindow(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1);
void SetVdv();
void WriteCommand(uint8_t cmd);
void WriteSpi(const uint8_t* data, size_t size);
enum class Commands : uint8_t {
SoftwareReset = 0x01,
SleepIn = 0x10,
SleepOut = 0x11,
NormalModeOn = 0x13,
DisplayInversionOn = 0x21,
DisplayOff = 0x28,
DisplayOn = 0x29,
ColumnAddressSet = 0x2a,
RowAddressSet = 0x2b,
WriteToRam = 0x2c,
MemoryDataAccessControl = 0x36,
VerticalScrollDefinition = 0x33,
VerticalScrollStartAddress = 0x37,
ColMod = 0x3a,
VdvSet = 0xc4,
};
void WriteData(uint8_t data);
void ColumnAddressSet();
static constexpr uint16_t Width = 240;
static constexpr uint16_t Height = 320;
void RowAddressSet();
};
}
}
}

View File

@ -40,7 +40,7 @@
#include "drivers/nrf52/Spi.h"
#include "drivers/nrf52/SpiMaster.h"
#include "drivers/SpiNorFlash.h"
#include "drivers/St7789.h"
#include "drivers/displays/St7789.h"
#include "drivers/TwiMaster.h"
#include "drivers/touchpanels/Cst816s.h"
#include "drivers/PinMap.h"
@ -63,6 +63,7 @@ Pinetime::Logging::DummyLogger logger;
#include "port/MotionSensor.h"
#include "port/HeartRateSensor.h"
#include "port/Watchdog.h"
#include "port/Display.h"
static constexpr uint8_t touchPanelTwiAddress = 0x15;
static constexpr uint8_t motionSensorTwiAddress = 0x18;
@ -80,7 +81,8 @@ Pinetime::Drivers::SpiMaster spi {spiImpl};
Pinetime::Drivers::Nrf52::Spi lcdSpiIpmpl {spiImpl, Pinetime::PinMap::SpiLcdCsn};
Pinetime::Drivers::Spi lcdSpi {lcdSpiIpmpl};
Pinetime::Drivers::St7789 lcd {lcdSpi, Pinetime::PinMap::LcdDataCommand};
Pinetime::Drivers::Displays::St7789 lcdImpl {lcdSpi, Pinetime::PinMap::LcdDataCommand};
Pinetime::Drivers::Display lcd{lcdImpl};
Pinetime::Drivers::Nrf52::Spi flashSpiImpl {spiImpl, Pinetime::PinMap::SpiFlashCsn};
Pinetime::Drivers::Spi flashSpi {flashSpiImpl};

16
src/port/Display.h Normal file
View File

@ -0,0 +1,16 @@
#pragma once
#include "drivers/Display.h"
#ifdef TARGET_DEVICE_PINETIME
#include <drivers/displays/St7789.h>
#endif
namespace Pinetime {
namespace Drivers {
#ifdef TARGET_DEVICE_PINETIME
using Display = Interface::Display<Pinetime::Drivers::Displays::St7789>;
#else
#error "No target device specified!"
#endif
}
}

View File

@ -11,7 +11,7 @@
#include <hal/nrf_wdt.h>
#include <cstring>
#include <components/gfx/Gfx.h>
#include <drivers/St7789.h>
#include <drivers/displays/St7789.h>
#include <components/brightness/BrightnessController.h>
#include <algorithm>
#include "recoveryImage.h"
@ -51,7 +51,7 @@ Pinetime::Drivers::SpiMaster spi {spiImpl};
Pinetime::Drivers::Nrf52::Spi lcdSpiIpmpl {spiImpl, Pinetime::PinMap::SpiLcdCsn};
Pinetime::Drivers::Spi lcdSpi {lcdSpiIpmpl};
Pinetime::Drivers::St7789 lcd {lcdSpi, Pinetime::PinMap::LcdDataCommand};
Pinetime::Drivers::Displays::St7789 lcd {lcdSpi, Pinetime::PinMap::LcdDataCommand};
Pinetime::Drivers::Nrf52::Spi flashSpiImpl {spiImpl, Pinetime::PinMap::SpiFlashCsn};
Pinetime::Drivers::Spi flashSpi {flashSpiImpl};

View File

@ -6,8 +6,6 @@
#include "components/battery/BatteryController.h"
#include "components/ble/BleController.h"
#include "displayapp/TouchEvents.h"
#include "drivers/St7789.h"
#include "drivers/heartRateSensors/Hrs3300.h"
#include "drivers/PinMap.h"
#include "main.h"
#include "BootErrors.h"
@ -40,7 +38,7 @@ void MeasureBatteryTimerCallback(TimerHandle_t xTimer) {
}
SystemTask::SystemTask(Drivers::SpiMaster& spi,
Drivers::St7789& lcd,
Drivers::Display& lcd,
Pinetime::Drivers::SpiNorFlash& spiNorFlash,
Drivers::TwiMaster& twiMaster,
Pinetime::Drivers::TouchPanel& touchPanel,

View File

@ -39,12 +39,10 @@
#include "port/MotionSensor.h"
#include "port/HeartRateSensor.h"
#include "port/Watchdog.h"
#include "port/Display.h"
extern std::chrono::time_point<std::chrono::system_clock, std::chrono::nanoseconds> NoInit_BackUpTime;
namespace Pinetime {
namespace Drivers {
class St7789;
}
namespace Controllers {
class Battery;
class TouchHandler;
@ -55,7 +53,7 @@ namespace Pinetime {
public:
enum class SystemTaskState { Sleeping, Running, GoingToSleep, WakingUp };
SystemTask(Drivers::SpiMaster& spi,
Drivers::St7789& lcd,
Drivers::Display& lcd,
Pinetime::Drivers::SpiNorFlash& spiNorFlash,
Drivers::TwiMaster& twiMaster,
Pinetime::Drivers::TouchPanel& touchPanel,
@ -99,7 +97,7 @@ namespace Pinetime {
TaskHandle_t taskHandle;
Pinetime::Drivers::SpiMaster& spi;
Pinetime::Drivers::St7789& lcd;
Pinetime::Drivers::Display& lcd;
Pinetime::Drivers::SpiNorFlash& spiNorFlash;
Pinetime::Drivers::TwiMaster& twiMaster;
Pinetime::Drivers::TouchPanel& touchPanel;