Skip to content

Add public initDisplay #41

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions keywords.txt
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ scrollVertLeft KEYWORD2
scrollStop KEYWORD2
flipVertical KEYWORD2
flipHorizontal KEYWORD2
initDisplay KEYWORD2

getX KEYWORD2
getY KEYWORD2
Expand Down
34 changes: 24 additions & 10 deletions src/SFE_MicroOLED.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ boolean MicroOLED::begin(uint8_t deviceAddress, TwoWire &wirePort)
return (true);
}

/** \brief Initialisation of MicroOLED Library - common to all begin methods. PRIVATE.
/** \brief Initialisation of MicroOLED Library - common to all begin methods.

Setup IO pins for the chosen interface then send initialisation commands to the SSD1306 controller inside the OLED.
*/
Expand All @@ -318,17 +318,31 @@ void MicroOLED::beginCommon()
setDrawMode(NORM);
setCursor(0, 0);

// Display reset routine
pinMode(rstPin, OUTPUT); // Set RST pin as OUTPUT
digitalWrite(rstPin, HIGH); // Initially set RST HIGH
delay(5); // VDD (3.3V) goes high at start, lets just chill for 5 ms
digitalWrite(rstPin, LOW); // Bring RST low, reset the display
delay(10); // wait 10ms
digitalWrite(rstPin, HIGH); // Set RST HIGH, bring out of reset
if(rstPin != 255)
{
// Display reset routine
pinMode(rstPin, OUTPUT); // Set RST pin as OUTPUT
digitalWrite(rstPin, HIGH); // Initially set RST HIGH
delay(5); // VDD (3.3V) goes high at start, lets just chill for 5 ms
digitalWrite(rstPin, LOW); // Bring RST low, reset the display
delay(10); // wait 10ms
digitalWrite(rstPin, HIGH); // Set RST HIGH, bring out of reset
}

// Display Init sequence for 64x48 OLED module
command(DISPLAYOFF); // 0xAE

initDisplay();

command(DISPLAYON); //--turn on oled panel
}

/** \brief Set CGRAM and display settings

Set the unique SSD1306 settings for the MicroOLED setup.
*/
void MicroOLED::initDisplay(bool clearDisplay)
{
command(SETDISPLAYCLOCKDIV); // 0xD5
command(0x80); // the suggested ratio 0x80

Expand Down Expand Up @@ -361,8 +375,8 @@ void MicroOLED::beginCommon()
command(SETVCOMDESELECT); // 0xDB
command(0x40);

command(DISPLAYON); //--turn on oled panel
clear(ALL); // Erase hardware memory inside the OLED controller to avoid random data in memory.
if(clearDisplay)
clear(ALL); // Erase hardware memory inside the OLED controller to avoid random data in memory.
}

//Calling this function with nothing sets the debug port to Serial
Expand Down
4 changes: 3 additions & 1 deletion src/SFE_MicroOLED.h
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ class MicroOLED : public Print
{
public:
// Constructor(s)
MicroOLED(uint8_t rst); // I2C - leaving the address currently undefined
MicroOLED(uint8_t rst = 255); // I2C - leaving the address currently undefined
MicroOLED(uint8_t rst, uint8_t dc); // I2C
MicroOLED(uint8_t rst, uint8_t dc, uint8_t cs); // SPI
MicroOLED(uint8_t rst, uint8_t dc, uint8_t cs, uint8_t wr, uint8_t rd,
Expand Down Expand Up @@ -232,6 +232,8 @@ class MicroOLED : public Print
//Set the max number of bytes set in a given I2C transaction
uint8_t i2cTransactionSize = 32; //Default to ATmega328 limit

void initDisplay(bool clearDisplay = true); //Set CGRAM settings. Useful if display gets corrupt.

private:
uint8_t csPin, dcPin, rstPin;
uint8_t wrPin, rdPin, dPins[8];
Expand Down