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 <diyelectromusic@gmail.com>
Co-authored-by: probonopd <probonopd@users.noreply.github.com>
pull/267/head^2
Kevin 2 years ago committed by GitHub
parent 50e9b7b8e0
commit 768d763f73
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      .github/workflows/build.yml
  2. 32
      src/config.cpp
  3. 16
      src/config.h
  4. 11
      src/minidexed.ini
  5. 42
      src/userinterface.cpp
  6. 5
      src/userinterface.h

@ -24,7 +24,7 @@ jobs:
run: | run: |
set -ex set -ex
cd circle-stdlib/libs/circle cd circle-stdlib/libs/circle
git checkout c9a4815 # develop git checkout a8e8c9f # develop
cd - cd -
- name: Install toolchains - name: Install toolchains
run: | run: |

@ -81,6 +81,13 @@ void CConfig::Load (void)
m_nLCDPinData7 = m_Properties.GetNumber ("LCDPinData7", 25); m_nLCDPinData7 = m_Properties.GetNumber ("LCDPinData7", 25);
m_nLCDI2CAddress = m_Properties.GetNumber ("LCDI2CAddress", 0); 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_nButtonPinPrev = m_Properties.GetNumber ("ButtonPinPrev", 0);
m_nButtonPinNext = m_Properties.GetNumber ("ButtonPinNext", 0); m_nButtonPinNext = m_Properties.GetNumber ("ButtonPinNext", 0);
m_nButtonPinBack = m_Properties.GetNumber ("ButtonPinBack", 11); m_nButtonPinBack = m_Properties.GetNumber ("ButtonPinBack", 11);
@ -195,6 +202,31 @@ unsigned CConfig::GetLCDI2CAddress (void) const
return m_nLCDI2CAddress; 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 unsigned CConfig::GetButtonPinPrev (void) const
{ {
return m_nButtonPinPrev; return m_nButtonPinPrev;

@ -53,6 +53,7 @@ public:
static const unsigned MaxUSBMIDIDevices = 4; static const unsigned MaxUSBMIDIDevices = 4;
#endif #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 LCDColumns = 16; // HD44780 LCD
static const unsigned LCDRows = 2; static const unsigned LCDRows = 2;
@ -88,6 +89,14 @@ public:
unsigned GetLCDPinData7 (void) const; unsigned GetLCDPinData7 (void) const;
unsigned GetLCDI2CAddress (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 Button Navigation
// GPIO pin numbers are chip numbers, not header positions // GPIO pin numbers are chip numbers, not header positions
unsigned GetButtonPinPrev (void) const; unsigned GetButtonPinPrev (void) const;
@ -142,6 +151,13 @@ private:
unsigned m_nLCDPinData7; unsigned m_nLCDPinData7;
unsigned m_nLCDI2CAddress; unsigned m_nLCDI2CAddress;
unsigned m_nSSD1306LCDI2CAddress;
unsigned m_nSSD1306LCDWidth;
unsigned m_nSSD1306LCDHeight;
unsigned m_nLCDColumns;
unsigned m_nLCDRows;
unsigned m_nButtonPinPrev; unsigned m_nButtonPinPrev;
unsigned m_nButtonPinNext; unsigned m_nButtonPinNext;
unsigned m_nButtonPinBack; unsigned m_nButtonPinBack;

@ -27,6 +27,17 @@ LCDPinData6=24
LCDPinData7=25 LCDPinData7=25
LCDI2CAddress=0x00 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 # GPIO Button Navigation
# Any buttons set to 0 will be ignored # Any buttons set to 0 will be ignored
ButtonPinPrev=0 ButtonPinPrev=0

@ -56,9 +56,18 @@ bool CUserInterface::Initialize (void)
if (m_pConfig->GetLCDEnabled ()) if (m_pConfig->GetLCDEnabled ())
{ {
unsigned i2caddr = m_pConfig->GetLCDI2CAddress (); 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 ())
{ {
m_pLCD = new CHD44780Device (CConfig::LCDColumns, CConfig::LCDRows, return false;
}
m_pLCD = m_pSSD1306;
} else if (i2caddr == 0)
{
m_pHD44780 = new CHD44780Device (m_pConfig->GetLCDColumns (), m_pConfig->GetLCDRows (),
m_pConfig->GetLCDPinData4 (), m_pConfig->GetLCDPinData4 (),
m_pConfig->GetLCDPinData5 (), m_pConfig->GetLCDPinData5 (),
m_pConfig->GetLCDPinData6 (), m_pConfig->GetLCDPinData6 (),
@ -66,18 +75,25 @@ bool CUserInterface::Initialize (void)
m_pConfig->GetLCDPinEnable (), m_pConfig->GetLCDPinEnable (),
m_pConfig->GetLCDPinRegisterSelect (), m_pConfig->GetLCDPinRegisterSelect (),
m_pConfig->GetLCDPinReadWrite ()); m_pConfig->GetLCDPinReadWrite ());
LOGDBG ("LCD: HD44780");
if (!m_pHD44780->Initialize ())
{
return false;
}
m_pLCD = m_pHD44780;
} }
else else
{ {
m_pLCD = new CHD44780Device (m_pI2CMaster, i2caddr, m_pHD44780 = new CHD44780Device (m_pI2CMaster, i2caddr,
CConfig::LCDColumns, CConfig::LCDRows); m_pConfig->GetLCDColumns (), m_pConfig->GetLCDRows ());
} LOGDBG ("LCD: HD44780 I2C");
assert (m_pLCD); if (!m_pHD44780->Initialize ())
if (!m_pLCD->Initialize ())
{ {
return false; return false;
} }
m_pLCD = m_pHD44780;
}
assert (m_pLCD);
m_pLCDBuffered = new CWriteBufferDevice (m_pLCD); m_pLCDBuffered = new CWriteBufferDevice (m_pLCD);
assert (m_pLCDBuffered); assert (m_pLCDBuffered);
@ -163,9 +179,9 @@ void CUserInterface::DisplayWrite (const char *pMenu, const char *pParam, const
Msg.Append (pParam); Msg.Append (pParam);
size_t nLen = strlen (pParam) + strlen (pMenu); 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 (" "); Msg.Append (" ");
} }
@ -184,9 +200,9 @@ void CUserInterface::DisplayWrite (const char *pMenu, const char *pParam, const
if (bArrowUp) 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 (" "); Value.Append (" ");
} }
@ -197,7 +213,7 @@ void CUserInterface::DisplayWrite (const char *pMenu, const char *pParam, const
Msg.Append (Value); Msg.Append (Value);
if (Value.GetLength () < CConfig::LCDColumns) if (Value.GetLength () < m_pConfig->GetLCDColumns ())
{ {
Msg.Append ("\x1B[K"); // clear end of line Msg.Append ("\x1B[K"); // clear end of line
} }

@ -25,6 +25,7 @@
#include "uibuttons.h" #include "uibuttons.h"
#include <sensor/ky040.h> #include <sensor/ky040.h>
#include <display/hd44780device.h> #include <display/hd44780device.h>
#include <display/ssd1306device.h>
#include <circle/gpiomanager.h> #include <circle/gpiomanager.h>
#include <circle/writebuffer.h> #include <circle/writebuffer.h>
#include <circle/i2cmaster.h> #include <circle/i2cmaster.h>
@ -65,7 +66,9 @@ private:
CI2CMaster *m_pI2CMaster; CI2CMaster *m_pI2CMaster;
CConfig *m_pConfig; CConfig *m_pConfig;
CHD44780Device *m_pLCD; CCharDevice *m_pLCD;
CHD44780Device *m_pHD44780;
CSSD1306Device *m_pSSD1306;
CWriteBufferDevice *m_pLCDBuffered; CWriteBufferDevice *m_pLCDBuffered;
CUIButtons *m_pUIButtons; CUIButtons *m_pUIButtons;

Loading…
Cancel
Save