Separate oled hardware init routine from open

add LCD ClearInit which also re-inits the hardware

workaround for display corruption on startup
This commit is contained in:
penfold42 2018-07-06 23:35:17 +10:00
parent 0bcd9de494
commit 12eeeea575
8 changed files with 24 additions and 9 deletions

View file

@ -32,16 +32,18 @@ SSD1306::SSD1306(int BSCMaster, u8 address, int flip, int type)
, address(address) , address(address)
, type(type) , type(type)
, flip(flip) , flip(flip)
, contrast(127)
{ {
RPI_I2CInit(BSCMaster, 1); RPI_I2CInit(BSCMaster, 1);
SetupScreen(); InitHardware();
} }
void SSD1306::SetupScreen() void SSD1306::InitHardware()
{ {
// SSD1306 data sheet configuration flow // SSD1306 data sheet configuration flow
SendCommand(SSD1306_CMD_DISPLAY_OFF); // 0xAE SendCommand(SSD1306_CMD_DISPLAY_OFF); // 0xAE
SendCommand(SSD1306_CMD_MULTIPLEX_RATIO); // 0xA8 SendCommand(SSD1306_CMD_MULTIPLEX_RATIO); // 0xA8
SendCommand(0x3F); // SSD1306_LCDHEIGHT - 1 SendCommand(0x3F); // SSD1306_LCDHEIGHT - 1
@ -61,8 +63,7 @@ void SSD1306::SetupScreen()
SendCommand(SSD1306_CMD_SET_COM_PINS); // 0xDA Layout and direction SendCommand(SSD1306_CMD_SET_COM_PINS); // 0xDA Layout and direction
SendCommand(0x12); SendCommand(0x12);
SendCommand(SSD1306_CMD_SET_CONTRAST_CONTROL); SetContrast(GetContrast());
SendCommand(0x7F);
SendCommand(SSD1306_CMD_ENTIRE_DISPLAY_ON); SendCommand(SSD1306_CMD_ENTIRE_DISPLAY_ON);
@ -176,6 +177,7 @@ void SSD1306::DisplayOff()
void SSD1306::SetContrast(u8 value) void SSD1306::SetContrast(u8 value)
{ {
contrast = value;
SendCommand(SSD1306_CMD_SET_CONTRAST_CONTROL); SendCommand(SSD1306_CMD_SET_CONTRAST_CONTROL);
SendCommand(value); SendCommand(value);
SetVCOMDeselect( value >> 5); SetVCOMDeselect( value >> 5);

View file

@ -81,10 +81,11 @@ public:
void PlotCharacter(int x, int y, char ascii, bool inverse); void PlotCharacter(int x, int y, char ascii, bool inverse);
void Plottext(int x, int y, char* str, bool inverse); void Plottext(int x, int y, char* str, bool inverse);
void SetupScreen(); void InitHardware();
void DisplayOn(); void DisplayOn();
void DisplayOff(); void DisplayOff();
void SetContrast(u8 value); void SetContrast(u8 value);
u8 GetContrast() { return contrast; }
void SetVCOMDeselect(u8 value); void SetVCOMDeselect(u8 value);
void ClearScreen(); void ClearScreen();
@ -108,6 +109,7 @@ protected:
u8 address; u8 address;
int type; int type;
int flip; int flip;
int contrast;
}; };
#endif #endif

View file

@ -337,3 +337,4 @@ void Screen::PlotImage(u32* image, int x, int y, int w, int h)
} }
} }
} }

View file

@ -61,6 +61,14 @@ void ScreenLCD::Clear(RGBA colour)
ssd1306->ClearScreen(); ssd1306->ClearScreen();
} }
void ScreenLCD::ClearInit(RGBA colour)
{
ssd1306->InitHardware();
ssd1306->ClearScreen();
ssd1306->SetContrast(ssd1306->GetContrast());
ssd1306->DisplayOn();
}
void ScreenLCD::SetContrast(u8 value) void ScreenLCD::SetContrast(u8 value)
{ {
ssd1306->SetContrast(value); ssd1306->SetContrast(value);

View file

@ -36,6 +36,7 @@ public:
void ClearArea(u32 x1, u32 y1, u32 x2, u32 y2, RGBA colour); void ClearArea(u32 x1, u32 y1, u32 x2, u32 y2, RGBA colour);
void Clear(RGBA colour); void Clear(RGBA colour);
void ClearInit(RGBA colour);
void SetContrast(u8 value); void SetContrast(u8 value);

View file

@ -364,6 +364,7 @@ void InitialiseLCD()
{ {
screenLCD = new ScreenLCD(); screenLCD = new ScreenLCD();
screenLCD->Open(128, 64, 1, i2cBusMaster, i2cLcdAddress, i2cLcdFlip, i2cLcdModel); screenLCD->Open(128, 64, 1, i2cBusMaster, i2cLcdAddress, i2cLcdFlip, i2cLcdModel);
screenLCD->SetContrast(i2cLcdOnContrast);
bool logo_done = false; bool logo_done = false;
if (strcasecmp(options.GetLcdLogoName(), "1541ii") == 0) if (strcasecmp(options.GetLcdLogoName(), "1541ii") == 0)
@ -402,8 +403,6 @@ void InitialiseLCD()
screenLCD->PrintText(0, x, y, tempBuffer, 0x0); screenLCD->PrintText(0, x, y, tempBuffer, 0x0);
} }
screenLCD->RefreshScreen(); screenLCD->RefreshScreen();
screenLCD->SetContrast(i2cLcdOnContrast);
} }
} }
@ -1283,6 +1282,8 @@ extern "C"
IEC_Bus::Initialise(); IEC_Bus::Initialise();
screenLCD->ClearInit(0);
#ifdef HAS_MULTICORE #ifdef HAS_MULTICORE
start_core(3, _spin_core); start_core(3, _spin_core);
start_core(2, _spin_core); start_core(2, _spin_core);