diff options
author | David Crocker <dcrocker@eschertech.com> | 2020-07-15 21:51:55 +0300 |
---|---|---|
committer | David Crocker <dcrocker@eschertech.com> | 2020-07-15 21:51:55 +0300 |
commit | 9146d4a77fe81b52545c18e5541061190f311a6a (patch) | |
tree | 265db7d8c783fbdd946c65a494569f6094509a38 /src/Display/Display.cpp | |
parent | 89e757ff204628e40891c0f220e061b6d13af5dd (diff) |
Refactored 12864 display code in preparation for ST7567 support
Also allow driver numbers of the form 0.# on boards that do not support
CAN expansion
Diffstat (limited to 'src/Display/Display.cpp')
-rw-r--r-- | src/Display/Display.cpp | 55 |
1 files changed, 32 insertions, 23 deletions
diff --git a/src/Display/Display.cpp b/src/Display/Display.cpp index 2b7a1350..3e80de22 100644 --- a/src/Display/Display.cpp +++ b/src/Display/Display.cpp @@ -9,6 +9,8 @@ #if SUPPORT_12864_LCD +#include "Lcd/ST7920/Lcd7920.h" +#include "Lcd/ST7567/Lcd7567.h" #include "GCodes/GCodes.h" #include "GCodes/GCodeBuffer/GCodeBuffer.h" #include "Hardware/IoPorts.h" @@ -144,38 +146,45 @@ void Display::ErrorBeep() noexcept Beep(500, 1000); } -GCodeResult Display::Configure(GCodeBuffer& gb, const StringRef& reply) noexcept +void Display::InitDisplay(GCodeBuffer& gb, Lcd *newLcd, bool defaultCsPolarity) THROWS(GCodeException) +{ + newLcd->Init(LcdCSPin, LcdA0Pin, defaultCsPolarity, (gb.Seen('F')) ? gb.GetUIValue() : LcdSpiClockFrequency); + IoPort::SetPinMode(LcdBeepPin, OUTPUT_PWM_LOW); + newLcd->SetFont(SmallFontNumber); + IoPort::SetPinMode(LcdBeepPin, OUTPUT_PWM_LOW); + newLcd->SetFont(SmallFontNumber); + + if (encoder == nullptr) + { + encoder = new RotaryEncoder(EncoderPinA, EncoderPinB, EncoderPinSw); + encoder->Init(DefaultPulsesPerClick); + } + menu = new Menu(*newLcd); + menu->Load("main"); + lcd = newLcd; +} + +GCodeResult Display::Configure(GCodeBuffer& gb, const StringRef& reply) THROWS(GCodeException) { bool seen = false; if (gb.Seen('P')) { + Lcd *tempLcd = nullptr; + std::swap(lcd, tempLcd); + delete tempLcd; + delete menu; + menu = nullptr; + seen = true; - const unsigned int displayType = gb.GetUIValue(); - switch (displayType) + switch (gb.GetUIValue()) { case 1: // 12864 display, ST7920 controller - case 2: // 12864 display, ST7567 controller - if (lcd == nullptr) - { - lcd = new Lcd7920(fonts, ARRAY_SIZE(fonts)); - } - lcd->Init(displayType - 1, LcdCSPin, LcdA0Pin, (gb.Seen('F')) ? gb.GetUIValue() : LcdSpiClockFrequency); - IoPort::SetPinMode(LcdBeepPin, OUTPUT_PWM_LOW); - lcd->SetFont(SmallFontNumber); - IoPort::SetPinMode(LcdBeepPin, OUTPUT_PWM_LOW); - lcd->SetFont(SmallFontNumber); + InitDisplay(gb, new Lcd7920(fonts, ARRAY_SIZE(fonts)), true); + break; - if (encoder == nullptr) - { - encoder = new RotaryEncoder(EncoderPinA, EncoderPinB, EncoderPinSw); - encoder->Init(DefaultPulsesPerClick); - } - if (menu == nullptr) - { - menu = new Menu(*lcd); - } - menu->Load("main"); + case 2: // 12864 display, ST7567 controller + InitDisplay(gb, new Lcd7567(fonts, ARRAY_SIZE(fonts)), false); break; default: |