1
0
mirror of https://github.com/DCC-EX/CommandStation-EX.git synced 2024-11-26 09:36:13 +01:00

Add support for Arduino LiquidCrystal LED displays (Hitachi HD44780)

This commit is contained in:
Oskar Senft 2024-07-25 18:02:19 -04:00 committed by Oskar Senft
parent f39fd89fbd
commit cc759e3d55
4 changed files with 127 additions and 0 deletions

View File

@ -30,6 +30,7 @@
#include "DisplayInterface.h"
#include "SSD1306Ascii.h"
#include "LiquidCrystal_I2C.h"
#include "LiquidCrystal_Parallel.h"
// Implement the Display shim class as a singleton.
@ -38,6 +39,7 @@
// Then Display class talks to the specific device type classes:
// SSD1306AsciiWire for I2C OLED driver with SSD1306 or SH1106 controllers;
// LiquidCrystal_I2C for I2C LCD driver for HD44780 with PCF8574 'backpack'.
// LiquidCrystal_Parallel for HD44780 in parallel mode.
#if defined(OLED_DRIVER)
#define DISPLAY_START(xxx) { \
@ -53,6 +55,14 @@
t->begin(); \
xxx; \
t->refresh();}
#elif defined(PARALLEL_LCD_DRIVER)
#define DISPLAY_START(xxx) { \
DisplayInterface *t = new Display( \
new LiquidCrystal_Parallel(PARALLEL_LCD_DRIVER)); \
t->begin(); \
xxx; \
t->refresh();}
#else
#define DISPLAY_START(xxx) { \
xxx; \

View File

@ -0,0 +1,61 @@
/*
* © 2024, Oskar Senft. All rights reserved.
*
* This file is part of CommandStation-EX
*
* This is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* It is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with CommandStation-EX. If not, see <https://www.gnu.org/licenses/>.
*/
#include <Arduino.h>
#include "LiquidCrystal_Parallel.h"
#include "DIAG.h"
LiquidCrystal_Parallel::LiquidCrystal_Parallel(
uint16_t cols, uint16_t rows,
uint8_t rs, uint8_t rw, uint8_t enable,
uint8_t d4, uint8_t d5, uint8_t d6, uint8_t d7)
: _cols(cols), _rows(rows), lcd(rs, rw, enable, d4, d5, d6, d7)
{
}
bool LiquidCrystal_Parallel::begin()
{
lcd.begin(getNumCols(), getNumRows());
lcd.noCursor();
return true;
}
void LiquidCrystal_Parallel::clearNative()
{
lcd.clear();
}
void LiquidCrystal_Parallel::setRowNative(byte row)
{
if (row >= getNumRows())
{
row = getNumRows() - 1; // we count rows starting w/0
}
lcd.setCursor(0, row);
}
size_t LiquidCrystal_Parallel::writeNative(uint8_t value)
{
return lcd.write(value);
}
bool LiquidCrystal_Parallel::isBusy()
{
return false;
}

52
LiquidCrystal_Parallel.h Normal file
View File

@ -0,0 +1,52 @@
/*
* © 2024, Oskar Senft. All rights reserved.
*
* This file is part of CommandStation-EX
*
* This is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* It is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with CommandStation. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef LiquidCrystal_Parallel_h
#define LiquidCrystal_Parallel_h
#include <Arduino.h>
#include <LiquidCrystal.h>
#include "Display.h"
// Support for an LCD based on the Hitachi HD44780 (or a compatible) chipset
// as supported by Arduino's LiquidCrystal library.
class LiquidCrystal_Parallel : public DisplayDevice
{
public:
// Specify the display's number of columns and rows as well
// as Arduino pins numbers for the display's pins (4-bit mode)
LiquidCrystal_Parallel(uint16_t cols, uint16_t rows,
uint8_t rs, uint8_t rw, uint8_t enable,
uint8_t d4, uint8_t d5, uint8_t d6, uint8_t d7);
bool begin() override;
void clearNative() override;
void setRowNative(byte line) override;
size_t writeNative(uint8_t c) override;
bool isBusy() override;
uint16_t getNumCols() override { return _cols; }
uint16_t getNumRows() override { return _rows; }
private:
LiquidCrystal lcd;
const uint16_t _cols;
const uint16_t _rows;
};
#endif

View File

@ -161,6 +161,10 @@ The configuration file for DCC-EX Command Station
// Use 132,64 for a SH1106-based I2C device with a 128x64 display.
// #define OLED_DRIVER 0x3c,128,32
//OR define PARALLEL_LCD_DRIVER COLS,ROWS,RS,RW,ENABLE,D4,D5,D6,D7
// using Arduino pin numbers for RS,RW,ENABLE,D4,D5,D6,D7
// #define PARALLEL_LCD_DRIVER 20, 4, 26, 27, 28, 22, 23, 24, 25
// Define scroll mode as 0, 1 or 2
// * #define SCROLLMODE 0 is scroll continuous (fill screen if poss),
// * #define SCROLLMODE 1 is by page (alternate between pages),