From 278a9c52a64d979ec99adc0535378d492f7b338e Mon Sep 17 00:00:00 2001 From: Neil McKechnie Date: Tue, 7 Feb 2023 15:07:29 +0000 Subject: [PATCH] Refactor SSD1306 initialisation to support different initialisation sequences. To support a HAL Display driver, the SSD1306 driver can be created (new) and then the I2C address assigned explicitly in the begin() call. The original approach of looking for the I2C device address has also been retained in a different constructor. --- SSD1306Ascii.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/SSD1306Ascii.cpp b/SSD1306Ascii.cpp index 7373a74..f57252f 100644 --- a/SSD1306Ascii.cpp +++ b/SSD1306Ascii.cpp @@ -144,7 +144,10 @@ const uint8_t FLASH SSD1306AsciiWire::SH1106_132x64init[] = { //------------------------------------------------------------------------------ // Constructor -SSD1306AsciiWire::SSD1306AsciiWire() {} +SSD1306AsciiWire::SSD1306AsciiWire() { + I2CManager.begin(); + I2CManager.setClock(400000L); // Set max supported I2C speed +} // CS auto-detect and configure constructor SSD1306AsciiWire::SSD1306AsciiWire(int width, int height) { @@ -193,7 +196,7 @@ bool SSD1306AsciiWire::begin(I2CAddress address, int width, int height) { return false; } // Device found - DIAG(F("%dx%d OLED display configured on I2C:x%x"), m_displayWidth, m_displayHeight, (uint8_t)m_i2cAddr); + DIAG(F("%dx%d OLED display configured on I2C:x%x"), m_displayWidth, m_displayHeight, (int)m_i2cAddr); clear(); return true; } @@ -203,8 +206,9 @@ void SSD1306AsciiWire::clearNative() { const int maxBytes = sizeof(blankPixels); // max number of bytes sendable over Wire for (uint8_t r = 0; r <= m_displayHeight/8 - 1; r++) { setRowNative(r); // Position at start of row to be erased - for (uint8_t c = 0; c <= m_displayWidth - 1; c += maxBytes-1) { - uint8_t len = min(m_displayWidth-c, maxBytes-1) + 1; + for (uint8_t c = 0; c <= m_displayWidth - 1; c += maxBytes) { + uint8_t len = m_displayWidth-c; + if (len > maxBytes) len = maxBytes; I2CManager.write_P(m_i2cAddr, blankPixels, len); // Write a number of blank columns } }