diff --git a/src/SSD1306.cpp b/src/SSD1306.cpp index 10e9394..6b32147 100644 --- a/src/SSD1306.cpp +++ b/src/SSD1306.cpp @@ -32,16 +32,18 @@ SSD1306::SSD1306(int BSCMaster, u8 address, int flip, int type) , address(address) , type(type) , flip(flip) + , contrast(127) { RPI_I2CInit(BSCMaster, 1); - SetupScreen(); + InitHardware(); } -void SSD1306::SetupScreen() +void SSD1306::InitHardware() { // SSD1306 data sheet configuration flow SendCommand(SSD1306_CMD_DISPLAY_OFF); // 0xAE + SendCommand(SSD1306_CMD_MULTIPLEX_RATIO); // 0xA8 SendCommand(0x3F); // SSD1306_LCDHEIGHT - 1 @@ -61,8 +63,7 @@ void SSD1306::SetupScreen() SendCommand(SSD1306_CMD_SET_COM_PINS); // 0xDA Layout and direction SendCommand(0x12); - SendCommand(SSD1306_CMD_SET_CONTRAST_CONTROL); - SendCommand(0x7F); + SetContrast(GetContrast()); SendCommand(SSD1306_CMD_ENTIRE_DISPLAY_ON); @@ -176,6 +177,7 @@ void SSD1306::DisplayOff() void SSD1306::SetContrast(u8 value) { + contrast = value; SendCommand(SSD1306_CMD_SET_CONTRAST_CONTROL); SendCommand(value); SetVCOMDeselect( value >> 5); diff --git a/src/SSD1306.h b/src/SSD1306.h index 78a7dc6..d02d112 100644 --- a/src/SSD1306.h +++ b/src/SSD1306.h @@ -81,10 +81,11 @@ public: void PlotCharacter(int x, int y, char ascii, bool inverse); void Plottext(int x, int y, char* str, bool inverse); - void SetupScreen(); + void InitHardware(); void DisplayOn(); void DisplayOff(); void SetContrast(u8 value); + u8 GetContrast() { return contrast; } void SetVCOMDeselect(u8 value); void ClearScreen(); @@ -108,6 +109,7 @@ protected: u8 address; int type; int flip; + int contrast; }; #endif diff --git a/src/Screen.cpp b/src/Screen.cpp index b1c6314..00f07e6 100644 --- a/src/Screen.cpp +++ b/src/Screen.cpp @@ -337,3 +337,4 @@ void Screen::PlotImage(u32* image, int x, int y, int w, int h) } } } + diff --git a/src/Screen.h b/src/Screen.h index f5ceee7..78be877 100644 --- a/src/Screen.h +++ b/src/Screen.h @@ -71,4 +71,4 @@ private: float scaleY; }; -#endif \ No newline at end of file +#endif diff --git a/src/ScreenBase.h b/src/ScreenBase.h index a6c7a60..b62d57a 100644 --- a/src/ScreenBase.h +++ b/src/ScreenBase.h @@ -94,4 +94,4 @@ protected: u8* framebuffer; }; -#endif \ No newline at end of file +#endif diff --git a/src/ScreenLCD.cpp b/src/ScreenLCD.cpp index 9fffb54..3eae5ed 100644 --- a/src/ScreenLCD.cpp +++ b/src/ScreenLCD.cpp @@ -61,6 +61,14 @@ void ScreenLCD::Clear(RGBA colour) ssd1306->ClearScreen(); } +void ScreenLCD::ClearInit(RGBA colour) +{ + ssd1306->InitHardware(); + ssd1306->ClearScreen(); + ssd1306->SetContrast(ssd1306->GetContrast()); + ssd1306->DisplayOn(); +} + void ScreenLCD::SetContrast(u8 value) { ssd1306->SetContrast(value); diff --git a/src/ScreenLCD.h b/src/ScreenLCD.h index c99237f..4e8f3bd 100644 --- a/src/ScreenLCD.h +++ b/src/ScreenLCD.h @@ -36,6 +36,7 @@ public: void ClearArea(u32 x1, u32 y1, u32 x2, u32 y2, RGBA colour); void Clear(RGBA colour); + void ClearInit(RGBA colour); void SetContrast(u8 value); diff --git a/src/main.cpp b/src/main.cpp index cd9d991..107e629 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -364,6 +364,7 @@ void InitialiseLCD() { screenLCD = new ScreenLCD(); screenLCD->Open(128, 64, 1, i2cBusMaster, i2cLcdAddress, i2cLcdFlip, i2cLcdModel); + screenLCD->SetContrast(i2cLcdOnContrast); bool logo_done = false; if (strcasecmp(options.GetLcdLogoName(), "1541ii") == 0) @@ -402,8 +403,6 @@ void InitialiseLCD() screenLCD->PrintText(0, x, y, tempBuffer, 0x0); } screenLCD->RefreshScreen(); - - screenLCD->SetContrast(i2cLcdOnContrast); } } @@ -1283,6 +1282,8 @@ extern "C" IEC_Bus::Initialise(); + screenLCD->ClearInit(0); + #ifdef HAS_MULTICORE start_core(3, _spin_core); start_core(2, _spin_core);