Skip to content

Commit

Permalink
Initial support for SSD1306 128x32 or 128x64 OLED displays (#312)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
3 people authored Aug 6, 2022
1 parent 50e9b7b commit 768d763
Show file tree
Hide file tree
Showing 6 changed files with 94 additions and 16 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand Down
32 changes: 32 additions & 0 deletions src/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down
16 changes: 16 additions & 0 deletions src/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ class CConfig // Configuration for MiniDexed
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;

Expand Down Expand Up @@ -88,6 +89,14 @@ class CConfig // Configuration for MiniDexed
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;
Expand Down Expand Up @@ -142,6 +151,13 @@ class CConfig // Configuration for MiniDexed
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;
Expand Down
11 changes: 11 additions & 0 deletions src/minidexed.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
44 changes: 30 additions & 14 deletions src/userinterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,29 +56,45 @@ 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 (),
m_pConfig->GetLCDPinData7 (),
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);

Expand Down Expand Up @@ -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 (" ");
}
Expand All @@ -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 (" ");
}
Expand All @@ -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
}
Expand Down
5 changes: 4 additions & 1 deletion src/userinterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "uibuttons.h"
#include <sensor/ky040.h>
#include <display/hd44780device.h>
#include <display/ssd1306device.h>
#include <circle/gpiomanager.h>
#include <circle/writebuffer.h>
#include <circle/i2cmaster.h>
Expand Down Expand Up @@ -65,7 +66,9 @@ class CUserInterface
CI2CMaster *m_pI2CMaster;
CConfig *m_pConfig;

CHD44780Device *m_pLCD;
CCharDevice *m_pLCD;
CHD44780Device *m_pHD44780;
CSSD1306Device *m_pSSD1306;
CWriteBufferDevice *m_pLCDBuffered;

CUIButtons *m_pUIButtons;
Expand Down

0 comments on commit 768d763

Please sign in to comment.