1
0
mirror of https://github.com/jscrane/r65emu.git synced 2024-12-21 12:29:51 +00:00

support TFT_eSPI

This commit is contained in:
Stephen Crane 2018-11-03 13:30:49 +00:00
parent 96a74645a2
commit 1a36940324
7 changed files with 168 additions and 84 deletions

View File

@ -10,8 +10,6 @@
#include <SPIFFS.h>
#endif
#include <UTFT.h>
#include "memory.h"
#include "ps2drv.h"
#include "CPU.h"
@ -25,7 +23,6 @@ spiram sram(SPIRAM_SIZE);
Memory memory;
PS2Driver ps2;
UTFT utft(TFT_MODEL, TFT_RS, TFT_WR, TFT_CS, TFT_RST);
static CPU *_cpu;
bool hardware_reset() {

View File

@ -6,6 +6,10 @@
#define __HARDWARE_H__
// TFT display...
//#define USE_UTFT
#define USE_ESPI
#if defined(USE_UTFT)
#undef TFT_BACKLIGHT
#define TFT_MODEL ILI9325C
#define TFT_RS 32
@ -13,16 +17,28 @@
#define TFT_CS 27
#define TFT_RST 26
#elif defined(USE_ESPI)
#define USER_SETUP_LOADED
#define ILI9341_DRIVER
#define TFT_CS PIN_D6
#define TFT_DC PIN_D8
#define TFT_RST -1
#define SPI_FREQUENCY 40000000
#define LOAD_GLCD
#endif
// PS/2 keyboard
#define KBD_DATA 14
#define KBD_IRQ 0
//#define KBD_DATA 14
//#define KBD_IRQ 0
#define KBD_DATA 34
#define KBD_IRQ 35
// SPI-RAM
#undef SPIRAM_CS
// "tape" storage...
#undef SD_CS
#define USE_SPIFFS 1
#define USE_SPIFFS
// sound
#define DAC_SOUND 25
@ -40,9 +56,6 @@ extern class PS2Driver ps2;
#if defined(__SPIRAM_H__) && defined(SPIRAM_CS)
extern class spiram sram;
#endif
#ifdef UTFT_h
extern class UTFT utft;
#endif
#ifdef __MEMORY_H__
extern class Memory memory;
#endif

View File

@ -7,7 +7,7 @@
#include "spiram.h"
#include "prom.h"
#include "ps2drv.h"
#include "utftdisplay.h"
#include "tftdisplay.h"
#include "keyboard.h"
#include "sdtape.h"
#include "timed.h"

105
tftdisplay.cpp Normal file
View File

@ -0,0 +1,105 @@
#include <stdint.h>
#include "hardware.h"
#include "memory.h"
#include "tftdisplay.h"
#if defined(USE_UTFT)
#include <UTFT.h>
#include "TinyFont.h"
static UTFT utft(TFT_MODEL, TFT_RS, TFT_WR, TFT_CS, TFT_RST);
#elif defined(USE_ESPI)
#include <TFT_eSPI.h>
static TFT_eSPI espi;
#endif
static inline void setColor(colour_t c) {
#if defined(USE_UTFT)
utft.setColor(c);
#elif defined(USE_ESPI)
espi.setTextColor(c);
#endif
}
void TFTDisplay::begin(unsigned bg, unsigned fg, orientation_t orient) {
_bg = bg;
_fg = fg;
#if defined(USE_UTFT)
utft.InitLCD(orient);
_dx = utft.getDisplayXSize();
_dy = utft.getDisplayYSize();
utft.setFont((uint8_t *)TinyFont);
_cx = utft.getFontXsize();
_cy = utft.getFontYsize();
#elif defined(USE_ESPI)
espi.init();
espi.setRotation(orient);
_dx = espi.width();
_dy = espi.height();
_cy = espi.fontHeight();
#endif
setColor(fg);
_oxs = _dx;
}
void TFTDisplay::clear() {
#if defined(USE_UTFT)
utft.fillScr(_bg);
#elif defined(USE_ESPI)
espi.fillScreen(_bg);
#endif
}
void TFTDisplay::error(char *s) {
setColor(_fg);
char *lines[5];
int l = 0;
for (char *p = s, *q = s; *p; p++)
if (*p == '\n') {
*p++ = 0;
lines[l++] = q;
q = p;
}
unsigned y = (_dy - l*_cy)/2;
for (int i = 0; i < l; i++) {
char *p = lines[i];
#if defined(USE_UTFT)
unsigned x = (_dx - strlen(p)*_cx)/2;
utft.print(p, x, y);
#elif defined(USE_ESPI)
unsigned x = (_dx - espi.textWidth(p))/2;
espi.drawCentreString(p, x, y, 0);
#endif
y += _cy;
}
}
void TFTDisplay::status(const char *s) {
setColor(_fg);
#if defined(USE_UTFT)
unsigned y = _dy - _cy, n = strlen(s), xs = _dx - n*_cx;
for (unsigned x = _oxs; x < xs; x += _cx)
utft.print(" ", x, y);
utft.print(s, xs, y);
_oxs = xs;
#elif defined(USE_ESPI)
espi.fillRect(_oxs, _dx, _dy - _cy, _dy, _bg);
_oxs = espi.textWidth(s);
espi.drawRightString(s, _oxs, _dy - _cy, 0);
#endif
}
void TFTDisplay::drawPixel(unsigned x, unsigned y, colour_t col) {
#if defined(USE_UTFT)
utft.setColor(col);
utft.drawPixel(x, y);
#elif defined(USE_ESPI)
espi.drawPixel(x, y, col);
#endif
}

43
tftdisplay.h Normal file
View File

@ -0,0 +1,43 @@
#ifndef __TFTDISPLAY_H__
#define __TFTDISPLAY_H__
typedef enum {
portrait, landscape
} orientation_t;
typedef unsigned colour_t;
const colour_t BLACK = 0x0000;
const colour_t NAVY = 0x000F;
const colour_t DARKGREEN = 0x03E0;
const colour_t DARKCYAN = 0x03EF;
const colour_t MAROON = 0x7800;
const colour_t PURPLE = 0x780F;
const colour_t OLIVE = 0x7BE0;
const colour_t LIGHTGREY = 0xC618;
const colour_t DARKGREY = 0x7BEF;
const colour_t BLUE = 0x001F;
const colour_t GREEN = 0x07E0;
const colour_t CYAN = 0x07FF;
const colour_t RED = 0xF800;
const colour_t MAGENTA = 0xF81F;
const colour_t YELLOW = 0xFFE0;
const colour_t WHITE = 0xFFFF;
const colour_t ORANGE = 0xFDA0;
const colour_t GREENYELLOW = 0xB7E0;
const colour_t PINK = 0xFC9F;
class TFTDisplay {
public:
void begin(colour_t bg, colour_t fg, orientation_t o = landscape);
void clear();
void error(char *);
void status(const char *);
void drawPixel(unsigned x, unsigned y, colour_t col);
protected:
unsigned _bg, _fg, _cx, _cy, _dx, _dy, _oxs;
};
#endif

View File

@ -1,55 +0,0 @@
#include <UTFT.h>
#include "memory.h"
#include "utftdisplay.h"
#include "TinyFont.h"
extern UTFT utft;
void UTFTDisplay::begin(unsigned bg, unsigned fg, orientation_t orient) {
_bg = bg;
_fg = fg;
utft.InitLCD(orient);
_dx = utft.getDisplayXSize();
_dy = utft.getDisplayYSize();
utft.setFont((uint8_t *)TinyFont);
utft.setColor(fg);
_cx = utft.getFontXsize();
_cy = utft.getFontYsize();
_oxs = _dx;
}
void UTFTDisplay::clear() {
utft.fillScr(_bg);
}
void UTFTDisplay::error(char *s)
{
utft.setColor(_fg);
char *lines[5];
int l = 0;
for (char *p = s, *q = s; *p; p++)
if (*p == '\n') {
*p++ = 0;
lines[l++] = q;
q = p;
}
unsigned y = (_dy - l*_cy)/2;
for (int i = 0; i < l; i++) {
char *p = lines[i];
unsigned x = (_dx - strlen(p)*_cx)/2;
utft.print(p, x, y);
y += _cy;
}
}
void UTFTDisplay::status(const char *s)
{
utft.setColor(_fg);
unsigned y = _dy - _cy, n = strlen(s), xs = _dx - n*_cx;
for (unsigned x = _oxs; x < xs; x += _cx)
utft.print(" ", x, y);
utft.print(s, xs, y);
_oxs = xs;
}

View File

@ -1,19 +0,0 @@
#ifndef __UTFT_DISPLAY_H__
#define __UTFT_DISPLAY_H__
typedef enum {
portrait, landscape
} orientation_t;
class UTFTDisplay {
public:
void begin(unsigned bg, unsigned fg, orientation_t o = landscape);
void clear();
void error(char *);
void status(const char *);
protected:
unsigned _bg, _fg, _cx, _cy, _dx, _dy, _oxs;
};
#endif