Allow for the configuration of the HD44780 pins.

This commit is contained in:
Jonathan Naylor 2016-04-06 17:43:20 +01:00
parent f7e2cff004
commit 3ee457830b
6 changed files with 42 additions and 7 deletions

View file

@ -102,7 +102,8 @@ m_fusionNetworkDebug(false),
m_tftSerialPort(), m_tftSerialPort(),
m_tftSerialBrightness(50U), m_tftSerialBrightness(50U),
m_hd44780Rows(2U), m_hd44780Rows(2U),
m_hd44780Columns(16U) m_hd44780Columns(16U),
m_hd44780Pins()
{ {
} }
@ -300,6 +301,14 @@ bool CConf::read()
m_hd44780Rows = (unsigned int)::atoi(value); m_hd44780Rows = (unsigned int)::atoi(value);
else if (::strcmp(key, "Columns") == 0) else if (::strcmp(key, "Columns") == 0)
m_hd44780Columns = (unsigned int)::atoi(value); m_hd44780Columns = (unsigned int)::atoi(value);
else if (::strcmp(key, "Pins") == 0) {
char* p = ::strtok(value, ",\r\n");
while (p != NULL) {
unsigned int pin = (unsigned int)::atoi(p);
m_hd44780Pins.push_back(pin);
p = ::strtok(NULL, ",\r\n");
}
}
} }
} }
@ -607,3 +616,8 @@ unsigned int CConf::getHD44780Columns() const
{ {
return m_hd44780Columns; return m_hd44780Columns;
} }
std::vector<unsigned int> CConf::getHD44780Pins() const
{
return m_hd44780Pins;
}

2
Conf.h
View file

@ -113,6 +113,7 @@ public:
// The HD44780 section // The HD44780 section
unsigned int getHD44780Rows() const; unsigned int getHD44780Rows() const;
unsigned int getHD44780Columns() const; unsigned int getHD44780Columns() const;
std::vector<unsigned int> getHD44780Pins() const;
private: private:
std::string m_file; std::string m_file;
@ -187,6 +188,7 @@ private:
unsigned int m_hd44780Rows; unsigned int m_hd44780Rows;
unsigned int m_hd44780Columns; unsigned int m_hd44780Columns;
std::vector<unsigned int> m_hd44780Pins;
}; };
#endif #endif

View file

@ -27,9 +27,15 @@
const char* LISTENING = "Listening "; const char* LISTENING = "Listening ";
CHD44780::CHD44780(unsigned int rows, unsigned int cols) : CHD44780::CHD44780(unsigned int rows, unsigned int cols, const std::vector<unsigned int>& pins) :
m_rows(rows), m_rows(rows),
m_cols(cols), m_cols(cols),
m_rb(pins.at(0U)),
m_strb(pins.at(1U)),
m_d0(pins.at(2U)),
m_d1(pins.at(3U)),
m_d2(pins.at(4U)),
m_d3(pins.at(5U)),
m_fd(-1) m_fd(-1)
{ {
assert(rows > 1U); assert(rows > 1U);
@ -44,7 +50,7 @@ bool CHD44780::open()
{ {
::wiringPiSetup(); ::wiringPiSetup();
m_fd = ::lcdInit(m_rows, m_cols, 4, 11, 10, 0, 1, 2, 3, 0, 0, 0, 0); m_fd = ::lcdInit(m_rows, m_cols, 4, m_rb, m_strb, m_d0, m_d1, m_d2, m_d3, 0, 0, 0, 0);
if (m_fd == -1) { if (m_fd == -1) {
LogError("Unable to open the HD44780"); LogError("Unable to open the HD44780");
return false; return false;

View file

@ -22,11 +22,12 @@
#include "Display.h" #include "Display.h"
#include <string> #include <string>
#include <vector>
class CHD44780 : public IDisplay class CHD44780 : public IDisplay
{ {
public: public:
CHD44780(unsigned int rows, unsigned int cols); CHD44780(unsigned int rows, unsigned int cols, const std::vector<unsigned int>& pins);
virtual ~CHD44780(); virtual ~CHD44780();
virtual bool open(); virtual bool open();
@ -53,6 +54,12 @@ public:
private: private:
unsigned int m_rows; unsigned int m_rows;
unsigned int m_cols; unsigned int m_cols;
unsigned int m_rb;
unsigned int m_strb;
unsigned int m_d0;
unsigned int m_d1;
unsigned int m_d2;
unsigned int m_d3;
int m_fd; int m_fd;
}; };

View file

@ -83,3 +83,5 @@ Brightness=50
[HD44780] [HD44780]
Rows=2 Rows=2
Columns=16 Columns=16
# rs, strb, d0, d1, d2, d3
Pins=11,10,0,1,2,3

View file

@ -577,11 +577,15 @@ void CMMDVMHost::createDisplay()
} else if (type == "HD44780") { } else if (type == "HD44780") {
unsigned int rows = m_conf.getHD44780Rows(); unsigned int rows = m_conf.getHD44780Rows();
unsigned int columns = m_conf.getHD44780Columns(); unsigned int columns = m_conf.getHD44780Columns();
std::vector<unsigned int> pins = m_conf.getHD44780Pins();
LogInfo(" Rows: %u", rows); if (pins.size() == 6U) {
LogInfo(" Columns: %u", columns); LogInfo(" Rows: %u", rows);
LogInfo(" Columns: %u", columns);
LogInfo(" Pins: %u,%u,%u,%u,%u,%u", pins.at(0U), pins.at(1U), pins.at(2U), pins.at(3U), pins.at(4U), pins.at(5U));
m_display = new CHD44780(rows, columns); m_display = new CHD44780(rows, columns, pins);
}
#endif #endif
} else { } else {
m_display = new CNullDisplay; m_display = new CNullDisplay;