Skip to content

Commit

Permalink
Fixed to minor 12864 display create/destroy issues (3.4beta4.1)
Browse files Browse the repository at this point in the history
M918 P0 deletes any existing display and no longer reports an error
When a display is deleted, set the CS and A0 pins back to inputs
  • Loading branch information
dc42 committed Dec 2, 2020
1 parent 51926a0 commit a8d6c52
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 5 deletions.
15 changes: 13 additions & 2 deletions src/Display/Display.cpp
Expand Up @@ -194,15 +194,26 @@ GCodeResult Display::Configure(GCodeBuffer& gb, const StringRef& reply) THROWS(G

if (gb.Seen('P'))
{
// Delete any existing LCD, menu and encoder
Lcd *tempLcd = nullptr;
std::swap(lcd, tempLcd);
delete tempLcd;
delete menu;
menu = nullptr;

Menu *tempMenu = nullptr;
std::swap(menu, tempMenu);
delete tempMenu;

RotaryEncoder *tempEncoder = nullptr;
std::swap(encoder, tempEncoder);
delete tempEncoder;

seen = true;
switch (gb.GetUIValue())
{
case 0: // no display
// We have already deleted the display, menu buffer and encoder, so nothing to do here
break;

case 1: // 12864 display, ST7920 controller
#ifdef DUET3MINI
// On the Duet 3 Mini we use the A0 pin as CS because it more nearly matches the pinout of the display (with the connectors reversed)
Expand Down
5 changes: 4 additions & 1 deletion src/Display/Lcd/Lcd.cpp
Expand Up @@ -20,13 +20,16 @@ Lcd::Lcd(PixelNumber nr, PixelNumber nc, const LcdFont * const fnts[], size_t nF
Lcd::~Lcd()
{
delete image;
pinMode(csPin, INPUT_PULLUP);
pinMode(a0Pin, INPUT_PULLUP);
}

// Initialise. a0Pin is only used by the ST7567.
void Lcd::Init(Pin csPin, Pin p_a0Pin, bool csPolarity, uint32_t freq, uint8_t p_contrastRatio, uint8_t p_resistorRatio) noexcept
void Lcd::Init(Pin p_csPin, Pin p_a0Pin, bool csPolarity, uint32_t freq, uint8_t p_contrastRatio, uint8_t p_resistorRatio) noexcept
{
// All this is SPI-display specific hardware initialisation, which prohibits I2C-display or UART-display support.
// NOTE: https://github.com/SchmartMaker/RepRapFirmware/tree/ST7565/src/Display did contain this abstraction
csPin = p_csPin;
a0Pin = p_a0Pin;
contrastRatio = p_contrastRatio;
resistorRatio = p_resistorRatio;
Expand Down
3 changes: 2 additions & 1 deletion src/Display/Lcd/Lcd.h
Expand Up @@ -41,7 +41,7 @@ class Lcd
uint32_t GetSpiFrequency() const noexcept { return device.GetFrequency(); }

// Initialize the display
void Init(Pin csPin, Pin p_a0Pin, bool csPolarity, uint32_t freq, uint8_t p_contrastRatio, uint8_t p_resistorRatio) noexcept;
void Init(Pin p_csPin, Pin p_a0Pin, bool csPolarity, uint32_t freq, uint8_t p_contrastRatio, uint8_t p_resistorRatio) noexcept;

// Select the font to use for subsequent calls to write() in graphics mode
void SetFont(size_t newFont) noexcept;
Expand Down Expand Up @@ -155,6 +155,7 @@ class Lcd
uint8_t *image; // image buffer
SharedSpiClient device;
const PixelNumber numRows, numCols;
Pin csPin;
Pin a0Pin;
uint8_t contrastRatio;
uint8_t resistorRatio;
Expand Down
2 changes: 1 addition & 1 deletion src/Version.h
Expand Up @@ -9,7 +9,7 @@
#define SRC_VERSION_H_

#ifndef VERSION
# define MAIN_VERSION "3.2-beta4+4"
# define MAIN_VERSION "3.2-beta4.1"
# ifdef USE_CAN0
# define VERSION_SUFFIX " (CAN0)"
# else
Expand Down

0 comments on commit a8d6c52

Please sign in to comment.