From 0f536925bce8d5b55c40c2fd00c1988bd3ab2238 Mon Sep 17 00:00:00 2001 From: penfold42 Date: Sat, 16 Jun 2018 00:01:02 +1000 Subject: [PATCH] Added i2cLcdFlip = 0/1 to flip display 180 deg --- src/SSD1306.cpp | 12 ++++++++---- src/SSD1306.h | 2 +- src/ScreenLCD.cpp | 4 ++-- src/ScreenLCD.h | 2 +- src/main.cpp | 7 +++++-- src/options.cpp | 2 ++ src/options.h | 2 ++ 7 files changed, 21 insertions(+), 10 deletions(-) diff --git a/src/SSD1306.cpp b/src/SSD1306.cpp index d1106b9..40377a0 100644 --- a/src/SSD1306.cpp +++ b/src/SSD1306.cpp @@ -57,7 +57,7 @@ extern "C" unsigned char frame[SSD1306_128x64_BYTES]; -SSD1306::SSD1306(int BSCMaster, u8 address) +SSD1306::SSD1306(int BSCMaster, u8 address, int flip) : BSCMaster(BSCMaster) , address(address) { @@ -73,9 +73,13 @@ SSD1306::SSD1306(int BSCMaster, u8 address) SendCommand(SSD1306_CMD_SET_START_LINE | 0x0); - SendCommand(0xA1); // Set Segment Re-Map - - SendCommand(0xC8); // Set COM Output Scan Direction + if (flip) { + SendCommand(0xA0); // No Segment Re-Map + SendCommand(0xC0); // No COM Output Scan Direction + } else { + SendCommand(0xA1); // Set Segment Re-Map + SendCommand(0xC8); // Set COM Output Scan Direction + } SendCommand(SSD1306_CMD_SET_COM_PINS); // Layout and direction SendCommand(0x12); diff --git a/src/SSD1306.h b/src/SSD1306.h index 99fec95..165d72f 100644 --- a/src/SSD1306.h +++ b/src/SSD1306.h @@ -72,7 +72,7 @@ class SSD1306 public: // 128x32 0x3C // 128x64 0x3D or 0x3C (if SA0 is grounded) - SSD1306(int BSCMaster = 1, u8 address = 0x3C); + SSD1306(int BSCMaster = 1, u8 address = 0x3C, int flip = 0); void PlotCharacter(int x, int y, char ascii, bool inverse); void Plottext(int x, int y, char* str, bool inverse); diff --git a/src/ScreenLCD.cpp b/src/ScreenLCD.cpp index 2874d56..89b215b 100644 --- a/src/ScreenLCD.cpp +++ b/src/ScreenLCD.cpp @@ -22,7 +22,7 @@ #include #include "debug.h" -void ScreenLCD::Open(u32 widthDesired, u32 heightDesired, u32 colourDepth, int BSCMaster, int LCDAddress) +void ScreenLCD::Open(u32 widthDesired, u32 heightDesired, u32 colourDepth, int BSCMaster, int LCDAddress, int LCDFlip) { bpp = 1; @@ -38,7 +38,7 @@ void ScreenLCD::Open(u32 widthDesired, u32 heightDesired, u32 colourDepth, int B width = widthDesired; height = heightDesired; - ssd1306 = new SSD1306(BSCMaster, LCDAddress); + ssd1306 = new SSD1306(BSCMaster, LCDAddress, LCDFlip); ssd1306->DisplayOn(); ssd1306->Plottext(5, 1, "Pi1541", false); ssd1306->RefreshScreen(); diff --git a/src/ScreenLCD.h b/src/ScreenLCD.h index 1f9e144..4a17572 100644 --- a/src/ScreenLCD.h +++ b/src/ScreenLCD.h @@ -32,7 +32,7 @@ public: { } - void Open(u32 width, u32 height, u32 colourDepth, int BSCMaster, int LCDAddress); + void Open(u32 width, u32 height, u32 colourDepth, int BSCMaster, int LCDAddress, int LCDFlip); void ClearArea(u32 x1, u32 y1, u32 x2, u32 y2, RGBA colour); void Clear(RGBA colour); diff --git a/src/main.cpp b/src/main.cpp index 23c6084..d00f820 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1025,7 +1025,9 @@ static void CheckOptions() screen.PrintText(false, 0, y_pos+=16, tempBuffer, COLOUR_WHITE, COLOUR_BLACK); snprintf(tempBuffer, tempBufferSize, "invertIECOutputs = %d\r\n", options.InvertIECOutputs()); screen.PrintText(false, 0, y_pos+=16, tempBuffer, COLOUR_WHITE, COLOUR_BLACK); - snprintf(tempBuffer, tempBufferSize, "i2cBusAddress = %d\r\n", options.I2CLcdAddress()); + snprintf(tempBuffer, tempBufferSize, "i2cLcdAddress = %d\r\n", options.I2CLcdAddress()); + screen.PrintText(false, 0, y_pos+=16, tempBuffer, COLOUR_WHITE, COLOUR_BLACK); + snprintf(tempBuffer, tempBufferSize, "i2cLcdFlip = %d\r\n", options.I2CLcdFlip()); screen.PrintText(false, 0, y_pos+=16, tempBuffer, COLOUR_WHITE, COLOUR_BLACK); IEC_Bus::WaitMicroSeconds(5 * 1000000); } @@ -1166,10 +1168,11 @@ extern "C" int i2cBusMaster = options.I2CBusMaster(); int i2cLcdAddress = options.I2CLcdAddress(); + int i2cLcdFlip = options.I2CLcdFlip(); if (strcasecmp(options.GetLCDName(), "ssd1306_128x64") == 0) { screenLCD = new ScreenLCD(); - screenLCD->Open(128, 64, 1, i2cBusMaster, i2cLcdAddress); + screenLCD->Open(128, 64, 1, i2cBusMaster, i2cLcdAddress, i2cLcdFlip); } else { diff --git a/src/options.cpp b/src/options.cpp index 64c9ff4..97c5a9c 100644 --- a/src/options.cpp +++ b/src/options.cpp @@ -141,6 +141,7 @@ Options::Options(void) , screenHeight(768) , i2cBusMaster(1) , i2cLcdAddress(0x3C) + , i2cLcdFlip(0) , keyboardBrowseLCDScreen(0) { strcpy(ROMFontName, "chargen"); @@ -204,6 +205,7 @@ void Options::Process(char* buffer) ELSE_CHECK_DECIMAL_OPTION(screenHeight) ELSE_CHECK_DECIMAL_OPTION(i2cBusMaster) ELSE_CHECK_DECIMAL_OPTION(i2cLcdAddress) + ELSE_CHECK_DECIMAL_OPTION(i2cLcdFlip) ELSE_CHECK_DECIMAL_OPTION(keyboardBrowseLCDScreen) else if ((strcasecmp(pOption, "StarFileName") == 0)) { diff --git a/src/options.h b/src/options.h index c51760c..283d773 100644 --- a/src/options.h +++ b/src/options.h @@ -70,6 +70,7 @@ public: inline unsigned int I2CBusMaster() const { return i2cBusMaster; } inline unsigned int I2CLcdAddress() const { return i2cLcdAddress; } + inline unsigned int I2CLcdFlip() const { return i2cLcdFlip; } // Page up and down will jump a different amount based on the maximum number rows displayed. // Perhaps we should use some keyboard modifier to the the other screen? @@ -103,6 +104,7 @@ private: unsigned int i2cBusMaster; unsigned int i2cLcdAddress; + unsigned int i2cLcdFlip; unsigned int keyboardBrowseLCDScreen;