From 768d763f73e6864309b1debf2cd47951a216e09d Mon Sep 17 00:00:00 2001 From: Kevin <68612569+diyelectromusic@users.noreply.github.com> Date: Sat, 6 Aug 2022 11:07:32 +0100 Subject: [PATCH] Initial support for SSD1306 128x32 or 128x64 OLED displays (#312) * Initial support for SSD1306 128x32 or 128x64 OLED displays * Update circle Co-authored-by: Kevin Co-authored-by: probonopd --- .github/workflows/build.yml | 2 +- src/config.cpp | 32 +++++++++++++++++++++++++++ src/config.h | 16 ++++++++++++++ src/minidexed.ini | 11 ++++++++++ src/userinterface.cpp | 44 +++++++++++++++++++++++++------------ src/userinterface.h | 5 ++++- 6 files changed, 94 insertions(+), 16 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 1bd04dd..ef8d1be 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -24,7 +24,7 @@ jobs: run: | set -ex cd circle-stdlib/libs/circle - git checkout c9a4815 # develop + git checkout a8e8c9f # develop cd - - name: Install toolchains run: | diff --git a/src/config.cpp b/src/config.cpp index e808459..3c237fa 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -81,6 +81,13 @@ void CConfig::Load (void) m_nLCDPinData7 = m_Properties.GetNumber ("LCDPinData7", 25); m_nLCDI2CAddress = m_Properties.GetNumber ("LCDI2CAddress", 0); + m_nSSD1306LCDI2CAddress = m_Properties.GetNumber ("SSD1306LCDI2CAddress", 0); + m_nSSD1306LCDWidth = m_Properties.GetNumber ("SSD1306LCDWidth", 128); + m_nSSD1306LCDHeight = m_Properties.GetNumber ("SSD1306LCDHeight", 32); + + m_nLCDColumns = m_Properties.GetNumber ("LCDColumns", 16); + m_nLCDRows = m_Properties.GetNumber ("LCDRows", 2); + m_nButtonPinPrev = m_Properties.GetNumber ("ButtonPinPrev", 0); m_nButtonPinNext = m_Properties.GetNumber ("ButtonPinNext", 0); m_nButtonPinBack = m_Properties.GetNumber ("ButtonPinBack", 11); @@ -195,6 +202,31 @@ unsigned CConfig::GetLCDI2CAddress (void) const return m_nLCDI2CAddress; } +unsigned CConfig::GetSSD1306LCDI2CAddress (void) const +{ + return m_nSSD1306LCDI2CAddress; +} + +unsigned CConfig::GetSSD1306LCDWidth (void) const +{ + return m_nSSD1306LCDWidth; +} + +unsigned CConfig::GetSSD1306LCDHeight (void) const +{ + return m_nSSD1306LCDHeight; +} + +unsigned CConfig::GetLCDColumns (void) const +{ + return m_nLCDColumns; +} + +unsigned CConfig::GetLCDRows (void) const +{ + return m_nLCDRows; +} + unsigned CConfig::GetButtonPinPrev (void) const { return m_nButtonPinPrev; diff --git a/src/config.h b/src/config.h index 53c8e2e..76382b1 100644 --- a/src/config.h +++ b/src/config.h @@ -53,6 +53,7 @@ public: static const unsigned MaxUSBMIDIDevices = 4; #endif + // TODO - Leave this for uimenu.cpp for now, but it will need to be dynamic at some point... static const unsigned LCDColumns = 16; // HD44780 LCD static const unsigned LCDRows = 2; @@ -88,6 +89,14 @@ public: unsigned GetLCDPinData7 (void) const; unsigned GetLCDI2CAddress (void) const; + // SSD1306 LCD + unsigned GetSSD1306LCDI2CAddress (void) const; + unsigned GetSSD1306LCDWidth (void) const; + unsigned GetSSD1306LCDHeight (void) const; + + unsigned GetLCDColumns (void) const; + unsigned GetLCDRows (void) const; + // GPIO Button Navigation // GPIO pin numbers are chip numbers, not header positions unsigned GetButtonPinPrev (void) const; @@ -142,6 +151,13 @@ private: unsigned m_nLCDPinData7; unsigned m_nLCDI2CAddress; + unsigned m_nSSD1306LCDI2CAddress; + unsigned m_nSSD1306LCDWidth; + unsigned m_nSSD1306LCDHeight; + + unsigned m_nLCDColumns; + unsigned m_nLCDRows; + unsigned m_nButtonPinPrev; unsigned m_nButtonPinNext; unsigned m_nButtonPinBack; diff --git a/src/minidexed.ini b/src/minidexed.ini index 6eeb07d..a2cc2df 100644 --- a/src/minidexed.ini +++ b/src/minidexed.ini @@ -27,6 +27,17 @@ LCDPinData6=24 LCDPinData7=25 LCDI2CAddress=0x00 +# SSD1306 LCD +# For a 128x32 display, set LCDColumns=20; LCDRows=2 +# For a 128x64 display, set LCDColumns=20; LCDRows=4 +SSD1306LCDI2CAddress=0x0 +SSD1306LCDWidth=128 +SSD1306LCDHeight=32 + +# Default is 16x2 display (e.g. HD44780) +LCDColumns=16 +LCDRows=2 + # GPIO Button Navigation # Any buttons set to 0 will be ignored ButtonPinPrev=0 diff --git a/src/userinterface.cpp b/src/userinterface.cpp index 799b386..e013779 100644 --- a/src/userinterface.cpp +++ b/src/userinterface.cpp @@ -56,9 +56,18 @@ bool CUserInterface::Initialize (void) if (m_pConfig->GetLCDEnabled ()) { unsigned i2caddr = m_pConfig->GetLCDI2CAddress (); - if (i2caddr == 0) + unsigned ssd1306addr = m_pConfig->GetSSD1306LCDI2CAddress (); + if (ssd1306addr != 0) { + m_pSSD1306 = new CSSD1306Device (m_pConfig->GetSSD1306LCDWidth (), m_pConfig->GetSSD1306LCDHeight (), m_pI2CMaster, ssd1306addr); + LOGDBG ("LCD: SSD1306"); + if (!m_pSSD1306->Initialize ()) + { + return false; + } + m_pLCD = m_pSSD1306; + } else if (i2caddr == 0) { - m_pLCD = new CHD44780Device (CConfig::LCDColumns, CConfig::LCDRows, + m_pHD44780 = new CHD44780Device (m_pConfig->GetLCDColumns (), m_pConfig->GetLCDRows (), m_pConfig->GetLCDPinData4 (), m_pConfig->GetLCDPinData5 (), m_pConfig->GetLCDPinData6 (), @@ -66,19 +75,26 @@ bool CUserInterface::Initialize (void) m_pConfig->GetLCDPinEnable (), m_pConfig->GetLCDPinRegisterSelect (), m_pConfig->GetLCDPinReadWrite ()); + LOGDBG ("LCD: HD44780"); + if (!m_pHD44780->Initialize ()) + { + return false; + } + m_pLCD = m_pHD44780; } else { - m_pLCD = new CHD44780Device (m_pI2CMaster, i2caddr, - CConfig::LCDColumns, CConfig::LCDRows); + m_pHD44780 = new CHD44780Device (m_pI2CMaster, i2caddr, + m_pConfig->GetLCDColumns (), m_pConfig->GetLCDRows ()); + LOGDBG ("LCD: HD44780 I2C"); + if (!m_pHD44780->Initialize ()) + { + return false; + } + m_pLCD = m_pHD44780; } assert (m_pLCD); - if (!m_pLCD->Initialize ()) - { - return false; - } - m_pLCDBuffered = new CWriteBufferDevice (m_pLCD); assert (m_pLCDBuffered); @@ -163,9 +179,9 @@ void CUserInterface::DisplayWrite (const char *pMenu, const char *pParam, const Msg.Append (pParam); size_t nLen = strlen (pParam) + strlen (pMenu); - if (nLen < CConfig::LCDColumns) + if (nLen < m_pConfig->GetLCDColumns ()) { - for (unsigned i = CConfig::LCDColumns-nLen; i > 0; i--) + for (unsigned i = m_pConfig->GetLCDColumns ()-nLen; i > 0; i--) { Msg.Append (" "); } @@ -184,9 +200,9 @@ void CUserInterface::DisplayWrite (const char *pMenu, const char *pParam, const if (bArrowUp) { - if (Value.GetLength () < CConfig::LCDColumns-1) + if (Value.GetLength () < m_pConfig->GetLCDColumns ()-1) { - for (unsigned i = CConfig::LCDColumns-Value.GetLength ()-1; i > 0; i--) + for (unsigned i = m_pConfig->GetLCDColumns ()-Value.GetLength ()-1; i > 0; i--) { Value.Append (" "); } @@ -197,7 +213,7 @@ void CUserInterface::DisplayWrite (const char *pMenu, const char *pParam, const Msg.Append (Value); - if (Value.GetLength () < CConfig::LCDColumns) + if (Value.GetLength () < m_pConfig->GetLCDColumns ()) { Msg.Append ("\x1B[K"); // clear end of line } diff --git a/src/userinterface.h b/src/userinterface.h index 202872a..8d03503 100644 --- a/src/userinterface.h +++ b/src/userinterface.h @@ -25,6 +25,7 @@ #include "uibuttons.h" #include #include +#include #include #include #include @@ -65,7 +66,9 @@ private: CI2CMaster *m_pI2CMaster; CConfig *m_pConfig; - CHD44780Device *m_pLCD; + CCharDevice *m_pLCD; + CHD44780Device *m_pHD44780; + CSSD1306Device *m_pSSD1306; CWriteBufferDevice *m_pLCDBuffered; CUIButtons *m_pUIButtons;