From 3ee457830b0bbc9e1c8b0f150e65d07f23b86c53 Mon Sep 17 00:00:00 2001 From: Jonathan Naylor Date: Wed, 6 Apr 2016 17:43:20 +0100 Subject: [PATCH] Allow for the configuration of the HD44780 pins. --- Conf.cpp | 16 +++++++++++++++- Conf.h | 2 ++ HD44780.cpp | 10 ++++++++-- HD44780.h | 9 ++++++++- MMDVM.ini | 2 ++ MMDVMHost.cpp | 10 +++++++--- 6 files changed, 42 insertions(+), 7 deletions(-) diff --git a/Conf.cpp b/Conf.cpp index a9261e8..51d9b1d 100644 --- a/Conf.cpp +++ b/Conf.cpp @@ -102,7 +102,8 @@ m_fusionNetworkDebug(false), m_tftSerialPort(), m_tftSerialBrightness(50U), m_hd44780Rows(2U), -m_hd44780Columns(16U) +m_hd44780Columns(16U), +m_hd44780Pins() { } @@ -300,6 +301,14 @@ bool CConf::read() m_hd44780Rows = (unsigned int)::atoi(value); else if (::strcmp(key, "Columns") == 0) 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; } + +std::vector CConf::getHD44780Pins() const +{ + return m_hd44780Pins; +} diff --git a/Conf.h b/Conf.h index 83c5469..f76fef7 100644 --- a/Conf.h +++ b/Conf.h @@ -113,6 +113,7 @@ public: // The HD44780 section unsigned int getHD44780Rows() const; unsigned int getHD44780Columns() const; + std::vector getHD44780Pins() const; private: std::string m_file; @@ -187,6 +188,7 @@ private: unsigned int m_hd44780Rows; unsigned int m_hd44780Columns; + std::vector m_hd44780Pins; }; #endif diff --git a/HD44780.cpp b/HD44780.cpp index 060fdc9..0a4aa52 100644 --- a/HD44780.cpp +++ b/HD44780.cpp @@ -27,9 +27,15 @@ const char* LISTENING = "Listening "; -CHD44780::CHD44780(unsigned int rows, unsigned int cols) : +CHD44780::CHD44780(unsigned int rows, unsigned int cols, const std::vector& pins) : m_rows(rows), 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) { assert(rows > 1U); @@ -44,7 +50,7 @@ bool CHD44780::open() { ::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) { LogError("Unable to open the HD44780"); return false; diff --git a/HD44780.h b/HD44780.h index a5b1cc5..07d3564 100644 --- a/HD44780.h +++ b/HD44780.h @@ -22,11 +22,12 @@ #include "Display.h" #include +#include class CHD44780 : public IDisplay { public: - CHD44780(unsigned int rows, unsigned int cols); + CHD44780(unsigned int rows, unsigned int cols, const std::vector& pins); virtual ~CHD44780(); virtual bool open(); @@ -53,6 +54,12 @@ public: private: unsigned int m_rows; 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; }; diff --git a/MMDVM.ini b/MMDVM.ini index ff71c54..54d908e 100644 --- a/MMDVM.ini +++ b/MMDVM.ini @@ -83,3 +83,5 @@ Brightness=50 [HD44780] Rows=2 Columns=16 +# rs, strb, d0, d1, d2, d3 +Pins=11,10,0,1,2,3 diff --git a/MMDVMHost.cpp b/MMDVMHost.cpp index d7d4579..9a4ad53 100644 --- a/MMDVMHost.cpp +++ b/MMDVMHost.cpp @@ -577,11 +577,15 @@ void CMMDVMHost::createDisplay() } else if (type == "HD44780") { unsigned int rows = m_conf.getHD44780Rows(); unsigned int columns = m_conf.getHD44780Columns(); + std::vector pins = m_conf.getHD44780Pins(); - LogInfo(" Rows: %u", rows); - LogInfo(" Columns: %u", columns); + if (pins.size() == 6U) { + 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 } else { m_display = new CNullDisplay;