From 1dce4908b8e89711d2a70a98f081a2bda8939ee4 Mon Sep 17 00:00:00 2001 From: xdrm-brackets Date: Sat, 30 May 2020 19:29:36 +0200 Subject: [PATCH] add clear() method with no need to apply afterwards - it would be bufferred if the cost is low later if it brings flicker, but for now let's consider that it will be fast enough and if we can avoid buffering, we would --- twinmax/display.cpp | 33 +++++++++++++++++++++++++++++++++ twinmax/display.h | 1 + 2 files changed, 34 insertions(+) diff --git a/twinmax/display.cpp b/twinmax/display.cpp index caef060..e1b14ec 100644 --- a/twinmax/display.cpp +++ b/twinmax/display.cpp @@ -21,10 +21,12 @@ void temporary(){ display.begin(); // display.clearDisplay(); + display.clear(true); // no need to call display() after to apply // display.drawPixel(x, y, SSD1306_WHITE) // display.drawPixel(x, y, SSD1306_BLACK) + // display.display() } void Display::send_command(const uint8_t c){ @@ -121,4 +123,35 @@ void Display::begin(){ TRANSACTION_END return; +} + +void Display::clear(){ + TRANSACTION_START + + static const uint8_t PROGMEM dlist1[] = { + DSP_PAGEADDR, + 0, // Page start address + 0xFF, // Page end (not really, but works here) + DSP_COLUMNADDR, + 0 // Column start address + }; + send_commands(dlist1, sizeof(dlist1)); + send_command(_width - 1); // Column end address + + _wire->beginTransmission(_i2caddr); + _wire->write((uint8_t) 0x40); + uint16_t count = _width * ((_height + 7) / 8); + uint8_t written = 1; + while(count--){ + if( written >= WIRE_MAX ){ + _wire->endTransmission(); + _wire->beginTransmission(_i2caddr); + _wire->write((uint8_t) 0x40); + written = 1; + } + _wire->write(0); + } + _wire->endTransmission(); + + TRANSACTION_END } \ No newline at end of file diff --git a/twinmax/display.h b/twinmax/display.h index 768e85b..dee7f42 100644 --- a/twinmax/display.h +++ b/twinmax/display.h @@ -41,6 +41,7 @@ public: void Display(const uint8_t width=128, const uint8_t height=32, const resetPin=-1); void begin(); + void clear(); protected: void send_command(const uint8_t c);