Skip to content

Commit

Permalink
Merge pull request g4klx#788 from jg1uaa/master
Browse files Browse the repository at this point in the history
TFTSurenoo: add 240x320 panel support
  • Loading branch information
g4klx authored Dec 30, 2023
2 parents f02cbcb + 8928636 commit 4ec4400
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 17 deletions.
8 changes: 8 additions & 0 deletions Conf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,7 @@ m_ax25NetworkSpeed(9600U),
m_ax25NetworkDebug(false),
m_tftSerialPort("/dev/ttyAMA0"),
m_tftSerialBrightness(50U),
m_tftSerialScreenLayout(0U),
m_hd44780Rows(2U),
m_hd44780Columns(16U),
m_hd44780Pins(),
Expand Down Expand Up @@ -1073,6 +1074,8 @@ bool CConf::read()
m_tftSerialPort = value;
else if (::strcmp(key, "Brightness") == 0)
m_tftSerialBrightness = (unsigned int)::atoi(value);
else if (::strcmp(key, "ScreenLayout") == 0)
m_tftSerialScreenLayout = (unsigned int)::atoi(value);
} else if (section == SECTION_HD44780) {
if (::strcmp(key, "Rows") == 0)
m_hd44780Rows = (unsigned int)::atoi(value);
Expand Down Expand Up @@ -2369,6 +2372,11 @@ unsigned int CConf::getTFTSerialBrightness() const
return m_tftSerialBrightness;
}

unsigned int CConf::getTFTSerialScreenLayout() const
{
return m_tftSerialScreenLayout;
}

unsigned int CConf::getHD44780Rows() const
{
return m_hd44780Rows;
Expand Down
2 changes: 2 additions & 0 deletions Conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,7 @@ class CConf
// The TFTSERIAL section
std::string getTFTSerialPort() const;
unsigned int getTFTSerialBrightness() const;
unsigned int getTFTSerialScreenLayout() const;

// The HD44780 section
unsigned int getHD44780Rows() const;
Expand Down Expand Up @@ -642,6 +643,7 @@ class CConf

std::string m_tftSerialPort;
unsigned int m_tftSerialBrightness;
unsigned int m_tftSerialScreenLayout;

unsigned int m_hd44780Rows;
unsigned int m_hd44780Columns;
Expand Down
4 changes: 3 additions & 1 deletion Display.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -553,17 +553,19 @@ CDisplay* CDisplay::createDisplay(const CConf& conf, CModem* modem)
if (type == "TFT Surenoo") {
std::string port = conf.getTFTSerialPort();
unsigned int brightness = conf.getTFTSerialBrightness();
unsigned int screenLayout = conf.getTFTSerialScreenLayout();

LogInfo(" Port: %s", port.c_str());
LogInfo(" Brightness: %u", brightness);
LogInfo(" Screen Layout: %u", screenLayout);

ISerialPort* serial = NULL;
if (port == "modem")
serial = new IModemSerialPort(modem);
else
serial = new CUARTController(port, 115200U);

display = new CTFTSurenoo(conf.getCallsign(), dmrid, serial, brightness, conf.getDuplex());
display = new CTFTSurenoo(conf.getCallsign(), dmrid, serial, brightness, conf.getDuplex(), screenLayout);
} else if (type == "Nextion") {
std::string port = conf.getNextionPort();
unsigned int brightness = conf.getNextionBrightness();
Expand Down
1 change: 1 addition & 0 deletions MMDVM.ini
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,7 @@ Debug=0
# Port=modem
Port=/dev/ttyAMA0
Brightness=50
ScreenLayout=0

[HD44780]
Rows=2
Expand Down
45 changes: 30 additions & 15 deletions TFTSurenoo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,37 +29,51 @@
* other Surenoo UART-LCD will be work, but display area is still 160x128
* (tested with JC028-V03 240x320 module)
*/

// x = 0 to 159, y = 0 to 127 - Landscape
// x = 0 to 127, y = 0 to 159 - Portrait
#define X_WIDTH 160
#define Y_WIDTH 128
struct layoutdef {
int x_width;
int y_width;
int rotation;
int mode_font_size;
int status_font_size;
int status_margin;
};

#define ROTATION_PORTRAIT 0
#define ROTATION_LANDSCAPE 1

#define FONT_SMALL 16 // 8x16
#define FONT_MEDIUM 24 // 12x24
#define FONT_LARGE 32 // 16x32

static const struct layoutdef Layout[] = {
{160, 128, ROTATION_LANDSCAPE, FONT_MEDIUM, FONT_SMALL, 32},
{128, 160, ROTATION_PORTRAIT, FONT_MEDIUM, FONT_SMALL, 32},
{320, 240, ROTATION_LANDSCAPE, FONT_LARGE, FONT_MEDIUM, 48},
{240, 320, ROTATION_PORTRAIT, FONT_LARGE, FONT_MEDIUM, 48},
};

#define X_WIDTH Layout[m_screenLayout].x_width
#define Y_WIDTH Layout[m_screenLayout].y_width
#define ROTATION Layout[m_screenLayout].rotation

enum LcdColour {
COLOUR_BLACK, COLOUR_RED, COLOUR_GREEN, COLOUR_BLUE,
COLOUR_YELLOW, COLOUR_CYAN, COLOUR_MAGENTA, COLOUR_GREY,
COLOUR_DARK_GREY, COLOUR_DARK_RED, COLOUR_DARK_GREEN, COLOUR_DARK_BLUE,
COLOUR_DARK_YELLOW, COLOUR_DARK_CYAN, COLOUR_DARK_MAGENTA, COLOUR_WHITE
};

#define FONT_SMALL 16 // 8x16
#define FONT_MEDIUM 24 // 12x24
#define FONT_LARGE 32 // 16x32

#define INFO_COLOUR COLOUR_CYAN
#define EXT_COLOUR COLOUR_DARK_GREEN
#define BG_COLOUR COLOUR_BLACK
#define ERROR_COLOUR COLOUR_DARK_RED
#define MODE_COLOUR COLOUR_YELLOW

// MODE_FONT_SIZE should be equal or larger than STATUS_FONT_SIZE
#define MODE_FONT_SIZE FONT_MEDIUM
#define STATUS_FONT_SIZE FONT_SMALL
#define MODE_FONT_SIZE Layout[m_screenLayout].mode_font_size
#define STATUS_FONT_SIZE Layout[m_screenLayout].status_font_size

#define STATUS_MARGIN 32 // pixel
#define STATUS_MARGIN Layout[m_screenLayout].status_margin

#define MODE_CHARS (X_WIDTH / (MODE_FONT_SIZE / 2))
#define STATUS_CHARS (X_WIDTH / (STATUS_FONT_SIZE / 2))
Expand All @@ -81,7 +95,7 @@ enum LcdColour {
#define STR_P25 "P25"
#define STR_YSF "SystemFusion"

CTFTSurenoo::CTFTSurenoo(const std::string& callsign, unsigned int dmrid, ISerialPort* serial, unsigned int brightness, bool duplex) :
CTFTSurenoo::CTFTSurenoo(const std::string& callsign, unsigned int dmrid, ISerialPort* serial, unsigned int brightness, bool duplex, unsigned int screenLayout) :
CDisplay(),
m_callsign(callsign),
m_dmrid(dmrid),
Expand All @@ -92,7 +106,8 @@ m_duplex(duplex),
//m_duplex(true), // uncomment to force duplex display for testing!
m_refresh(false),
m_refreshTimer(1000U, 0U, REFRESH_PERIOD),
m_lineBuf(NULL)
m_lineBuf(NULL),
m_screenLayout(screenLayout)
{
assert(serial != NULL);
assert(brightness >= 0U && brightness <= 255U);
Expand Down Expand Up @@ -453,7 +468,7 @@ void CTFTSurenoo::refreshDisplay(void)
m_serial->write((unsigned char*)m_temp, (unsigned int)::strlen(m_temp));

// config display
setRotation(ROTATION_LANDSCAPE);
setRotation(ROTATION);
setBrightness(m_brightness);
setBackground(BG_COLOUR);
m_serial->write((unsigned char*)m_temp, (unsigned int)::strlen(m_temp));
Expand Down
3 changes: 2 additions & 1 deletion TFTSurenoo.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
class CTFTSurenoo : public CDisplay
{
public:
CTFTSurenoo(const std::string& callsign, unsigned int dmrid, ISerialPort* serial, unsigned int brightness, bool duplex);
CTFTSurenoo(const std::string& callsign, unsigned int dmrid, ISerialPort* serial, unsigned int brightness, bool duplex, unsigned int screenLayout);
virtual ~CTFTSurenoo();

virtual bool open();
Expand Down Expand Up @@ -83,6 +83,7 @@ class CTFTSurenoo : public CDisplay
CTimer m_refreshTimer;
char* m_lineBuf;
char m_temp[128];
unsigned int m_screenLayout;

void setLineBuffer(char *buf, const char *text, int maxchar);
void setModeLine(const char *text);
Expand Down

0 comments on commit 4ec4400

Please sign in to comment.