Allow setting of more advanced SPI parameters: mode and clock.

pull/652/head
Kevin 11 months ago
parent 120d1bd579
commit 425b191bdc
  1. 13
      src/config.cpp
  2. 15
      src/config.h
  3. 6
      src/kernel.cpp
  4. 7
      src/userinterface.cpp

@ -103,6 +103,9 @@ void CConfig::Load (void)
m_bSSD1306LCDMirror = m_Properties.GetNumber ("SSD1306LCDMirror", 0) != 0;
m_nSPIBus = m_Properties.GetNumber ("SPIBus", SPI_INACTIVE); // Disabled by default
m_nSPIMode = m_Properties.GetNumber ("SPIMode", SPI_DEF_MODE);
m_nSPIClockKHz = m_Properties.GetNumber ("SPIClockKHz", SPI_DEF_CLOCK);
m_bST7789Enabled = m_Properties.GetNumber ("ST7789Enabled", 0) != 0;
m_nST7789Data = m_Properties.GetNumber ("ST7789Data", 0);
m_nST7789Select = m_Properties.GetNumber ("ST7789Select", 0);
@ -314,6 +317,16 @@ unsigned CConfig::GetSPIBus (void) const
return m_nSPIBus;
}
unsigned CConfig::GetSPIMode (void) const
{
return m_nSPIMode;
}
unsigned CConfig::GetSPIClockKHz (void) const
{
return m_nSPIClockKHz;
}
bool CConfig::GetST7789Enabled (void) const
{
return m_bST7789Enabled;

@ -29,10 +29,8 @@
#include <string>
#define SPI_INACTIVE 255
#define SPI_CLOCK_SPEED 15000000 // Hz
#define SPI_CPOL 0 // Taken from circle sample application
#define SPI_CPHA 0 // Apparently Mode 0 (0,0) is common...?
#define SPI_DEF_CLOCK 15000 // kHz
#define SPI_DEF_MODE 0 // Default mode (0,1,2,3)
class CConfig // Configuration for MiniDexed
{
@ -109,8 +107,12 @@ public:
bool GetSSD1306LCDRotate (void) const;
bool GetSSD1306LCDMirror (void) const;
// ST7789 LCD
// SPI support
unsigned GetSPIBus (void) const;
unsigned GetSPIMode (void) const;
unsigned GetSPIClockKHz (void) const;
// ST7789 LCD
bool GetST7789Enabled (void) const;
unsigned GetST7789Data (void) const;
unsigned GetST7789Select (void) const;
@ -223,6 +225,9 @@ private:
bool m_bSSD1306LCDMirror;
unsigned m_nSPIBus;
unsigned m_nSPIMode;
unsigned m_nSPIClockKHz;
bool m_bST7789Enabled;
unsigned m_nST7789Data;
unsigned m_nST7789Select;

@ -68,6 +68,8 @@ bool CKernel::Initialize (void)
m_Config.Load ();
unsigned nSPIMaster = m_Config.GetSPIBus();
unsigned nSPIMode = m_Config.GetSPIMode();
unsigned long nSPIClock = 1000 * m_Config.GetSPIClockKHz();
#if RASPPI<4
// By default older RPI versions use SPI 0.
// It is possible to build circle to support SPI 1 for
@ -81,7 +83,9 @@ bool CKernel::Initialize (void)
if (nSPIMaster == 0 || nSPIMaster == 3 || nSPIMaster == 4 || nSPIMaster == 5 || nSPIMaster == 6)
#endif
{
m_pSPIMaster = new CSPIMaster (SPI_CLOCK_SPEED, SPI_CPOL, SPI_CPHA, nSPIMaster);
unsigned nCPHA = (nSPIMode & 1) ? 1 : 0;
unsigned nCPOL = (nSPIMode & 2) ? 1 : 0;
m_pSPIMaster = new CSPIMaster (nSPIClock, nCPOL, nCPHA, nSPIMaster);
if (!m_pSPIMaster->Initialize())
{
delete (m_pSPIMaster);

@ -79,13 +79,18 @@ bool CUserInterface::Initialize (void)
return false;
}
unsigned long nSPIClock = 1000 * m_pConfig->GetSPIClockKHz();
unsigned nSPIMode = m_pConfig->GetSPIMode();
unsigned nCPHA = (nSPIMode & 1) ? 1 : 0;
unsigned nCPOL = (nSPIMode & 2) ? 1 : 0;
LOGDBG("SPI: CPOL=%u; CPHA=%u; CLK=%u",nCPOL,nCPHA,nSPIClock);
m_pST7789Display = new CST7789Display (m_pSPIMaster,
m_pConfig->GetST7789Data(),
m_pConfig->GetST7789Reset(),
m_pConfig->GetST7789Backlight(),
m_pConfig->GetST7789Width(),
m_pConfig->GetST7789Height(),
SPI_CPOL, SPI_CPHA, SPI_CLOCK_SPEED,
nCPOL, nCPHA, nSPIClock,
m_pConfig->GetST7789Select());
if (m_pST7789Display->Initialize())
{

Loading…
Cancel
Save