Merge pull request #11821 from gemu2015/mdisp

multi display support
This commit is contained in:
Theo Arends 2021-04-21 11:56:20 +02:00 committed by GitHub
commit 108383e04b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
26 changed files with 452 additions and 277 deletions

View File

@ -220,7 +220,7 @@ virtual void
uint16_t uint16_t
textcolor, ///< 16-bit background color for print() textcolor, ///< 16-bit background color for print()
textbgcolor; ///< 16-bit text color for print() textbgcolor; ///< 16-bit text color for print()
uint8_t *framebuffer;
protected: protected:
void void
charBounds(char c, int16_t *x, int16_t *y, charBounds(char c, int16_t *x, int16_t *y,

View File

@ -38,7 +38,8 @@ However, SH1106 driver don't provide several functions such as scroll commands.
#define DISPLAY_INIT_MODE 0 #define DISPLAY_INIT_MODE 0
// the memory buffer for the LCD // the memory buffer for the LCD
extern uint8_t *buffer;
uint8_t *dbuff;
Adafruit_SH1106::Adafruit_SH1106(int16_t width, int16_t height) : Adafruit_SH1106::Adafruit_SH1106(int16_t width, int16_t height) :
Renderer(width,height) { Renderer(width,height) {
@ -59,14 +60,16 @@ void Adafruit_SH1106::Updateframe() {
void Adafruit_SH1106::DisplayInit(int8_t p,int8_t size,int8_t rot,int8_t font) { void Adafruit_SH1106::DisplayInit(int8_t p,int8_t size,int8_t rot,int8_t font) {
// ignore update mode // ignore update mode
//if (p==DISPLAY_INIT_MODE) { //if (p==DISPLAY_INIT_MODE) {
// allocate screen buffer
setRotation(rot); setRotation(rot);
invertDisplay(false); invertDisplay(false);
setTextWrap(false); // Allow text to run off edges setTextWrap(false); // Allow text to run off edges
cp437(true); cp437(true);
setTextFont(font); setTextFont(font);
setTextSize(size); setTextSize(size);
setTextColor(WHITE,BLACK); setTextColor(WHITE, BLACK);
setCursor(0,0); setCursor(0,0);
//fillScreen(BLACK);
fillScreen(BLACK); fillScreen(BLACK);
Updateframe(); Updateframe();
//} //}
@ -77,9 +80,13 @@ void Adafruit_SH1106::Begin(int16_t p1,int16_t p2,int16_t p3) {
} }
void Adafruit_SH1106::begin(uint8_t vccstate, uint8_t i2caddr, bool reset) { boolean Adafruit_SH1106::begin(uint8_t vccstate, uint8_t i2caddr, bool reset) {
_vccstate = vccstate; _vccstate = vccstate;
_i2caddr = i2caddr; _i2caddr = i2caddr;
framebuffer = (uint8_t *)malloc(WIDTH * ((HEIGHT + 7) / 8));
if (!framebuffer) return false;
// I2C Init // I2C Init
Wire.begin(); Wire.begin();
@ -193,6 +200,9 @@ void Adafruit_SH1106::begin(uint8_t vccstate, uint8_t i2caddr, bool reset) {
#endif #endif
SH1106_command(SH1106_DISPLAYON);//--turn on oled panel SH1106_command(SH1106_DISPLAYON);//--turn on oled panel
return true;
} }
@ -274,18 +284,18 @@ void Adafruit_SH1106::display(void) {
SH1106_command(0x10 | (m_col >> 4));//set higher column address SH1106_command(0x10 | (m_col >> 4));//set higher column address
for( j = 0; j < 8; j++){ for( j = 0; j < 8; j++){
Wire.beginTransmission(_i2caddr); Wire.beginTransmission(_i2caddr);
Wire.write(0x40); Wire.write(0x40);
for ( k = 0; k < width; k++, p++) { for ( k = 0; k < width; k++, p++) {
Wire.write(buffer[p]); Wire.write(framebuffer[p]);
} }
Wire.endTransmission(); Wire.endTransmission();
} }
} }
} }
// clear everything // clear everything
void Adafruit_SH1106::clearDisplay(void) { void Adafruit_SH1106::clearDisplay(void) {
memset(buffer, 0, (SH1106_LCDWIDTH*SH1106_LCDHEIGHT/8)); memset(framebuffer, 0, (SH1106_LCDWIDTH*SH1106_LCDHEIGHT/8));
} }

View File

@ -133,7 +133,7 @@ class Adafruit_SH1106 : public Renderer {
public: public:
Adafruit_SH1106(int16_t width, int16_t height); Adafruit_SH1106(int16_t width, int16_t height);
void begin(uint8_t switchvcc = SH1106_SWITCHCAPVCC, uint8_t i2caddr = SH1106_I2C_ADDRESS, bool reset=true); boolean begin(uint8_t switchvcc = SH1106_SWITCHCAPVCC, uint8_t i2caddr = SH1106_I2C_ADDRESS, bool reset=true);
void SH1106_command(uint8_t c); void SH1106_command(uint8_t c);
void SH1106_data(uint8_t c); void SH1106_data(uint8_t c);

View File

@ -326,9 +326,9 @@ Adafruit_SSD1306::Adafruit_SSD1306(int8_t rst_pin) :
@brief Destructor for Adafruit_SSD1306 object. @brief Destructor for Adafruit_SSD1306 object.
*/ */
Adafruit_SSD1306::~Adafruit_SSD1306(void) { Adafruit_SSD1306::~Adafruit_SSD1306(void) {
if(buffer) { if (framebuffer) {
free(buffer); free (framebuffer);
buffer = NULL; framebuffer = NULL;
} }
} }
@ -451,8 +451,8 @@ void Adafruit_SSD1306::ssd1306_command(uint8_t c) {
boolean Adafruit_SSD1306::begin(uint8_t vcs, uint8_t addr, boolean reset, boolean Adafruit_SSD1306::begin(uint8_t vcs, uint8_t addr, boolean reset,
boolean periphBegin) { boolean periphBegin) {
// if((!buffer) && !(buffer = (uint8_t *)malloc(WIDTH * ((HEIGHT + 7) / 8)))) framebuffer = (uint8_t *)malloc(WIDTH * ((HEIGHT + 7) / 8));
// return false; if (!framebuffer) return false;
clearDisplay(); clearDisplay();
@ -627,6 +627,10 @@ void Adafruit_SSD1306::DisplayInit(int8_t p,int8_t size,int8_t rot,int8_t font)
commands as needed by one's own application. commands as needed by one's own application.
*/ */
void Adafruit_SSD1306::drawPixel(int16_t x, int16_t y, uint16_t color) { void Adafruit_SSD1306::drawPixel(int16_t x, int16_t y, uint16_t color) {
if (!framebuffer) return;
if((x >= 0) && (x < width()) && (y >= 0) && (y < height())) { if((x >= 0) && (x < width()) && (y >= 0) && (y < height())) {
// Pixel is in-bounds. Rotate coordinates if needed. // Pixel is in-bounds. Rotate coordinates if needed.
switch(getRotation()) { switch(getRotation()) {
@ -644,9 +648,9 @@ void Adafruit_SSD1306::drawPixel(int16_t x, int16_t y, uint16_t color) {
break; break;
} }
switch(color) { switch(color) {
case WHITE: buffer[x + (y/8)*WIDTH] |= (1 << (y&7)); break; case WHITE: framebuffer[x + (y/8)*WIDTH] |= (1 << (y&7)); break;
case BLACK: buffer[x + (y/8)*WIDTH] &= ~(1 << (y&7)); break; case BLACK: framebuffer[x + (y/8)*WIDTH] &= ~(1 << (y&7)); break;
case INVERSE: buffer[x + (y/8)*WIDTH] ^= (1 << (y&7)); break; case INVERSE: framebuffer[x + (y/8)*WIDTH] ^= (1 << (y&7)); break;
} }
} }
} }
@ -659,7 +663,8 @@ void Adafruit_SSD1306::drawPixel(int16_t x, int16_t y, uint16_t color) {
commands as needed by one's own application. commands as needed by one's own application.
*/ */
void Adafruit_SSD1306::clearDisplay(void) { void Adafruit_SSD1306::clearDisplay(void) {
memset(buffer, 0, WIDTH * ((HEIGHT + 7) / 8)); if (!framebuffer) return;
memset(framebuffer, 0, WIDTH * ((HEIGHT + 7) / 8));
} }
/*! /*!
@ -757,9 +762,9 @@ void Adafruit_SSD1306::drawFastVLine(
} }
#endif #endif
void Adafruit_SSD1306::drawFastHLineInternal( void Adafruit_SSD1306::drawFastHLineInternal (
int16_t x, int16_t y, int16_t w, uint16_t color) { int16_t x, int16_t y, int16_t w, uint16_t color) {
if (!framebuffer) return;
if((y >= 0) && (y < HEIGHT)) { // Y coord in bounds? if((y >= 0) && (y < HEIGHT)) { // Y coord in bounds?
if(x < 0) { // Clip left if(x < 0) { // Clip left
w += x; w += x;
@ -769,7 +774,7 @@ void Adafruit_SSD1306::drawFastHLineInternal(
w = (WIDTH - x); w = (WIDTH - x);
} }
if(w > 0) { // Proceed only if width is positive if(w > 0) { // Proceed only if width is positive
uint8_t *pBuf = &buffer[(y / 8) * WIDTH + x], uint8_t *pBuf = &framebuffer[(y / 8) * WIDTH + x],
mask = 1 << (y & 7); mask = 1 << (y & 7);
switch(color) { switch(color) {
case WHITE: while(w--) { *pBuf++ |= mask; }; break; case WHITE: while(w--) { *pBuf++ |= mask; }; break;
@ -782,7 +787,7 @@ void Adafruit_SSD1306::drawFastHLineInternal(
void Adafruit_SSD1306::drawFastVLineInternal( void Adafruit_SSD1306::drawFastVLineInternal(
int16_t x, int16_t __y, int16_t __h, uint16_t color) { int16_t x, int16_t __y, int16_t __h, uint16_t color) {
if (!framebuffer) return;
if((x >= 0) && (x < WIDTH)) { // X coord in bounds? if((x >= 0) && (x < WIDTH)) { // X coord in bounds?
if(__y < 0) { // Clip top if(__y < 0) { // Clip top
__h += __y; __h += __y;
@ -795,7 +800,7 @@ void Adafruit_SSD1306::drawFastVLineInternal(
// this display doesn't need ints for coordinates, // this display doesn't need ints for coordinates,
// use local byte registers for faster juggling // use local byte registers for faster juggling
uint8_t y = __y, h = __h; uint8_t y = __y, h = __h;
uint8_t *pBuf = &buffer[(y / 8) * WIDTH + x]; uint8_t *pBuf = &framebuffer[(y / 8) * WIDTH + x];
// do the first partial byte, if necessary - this requires some masking // do the first partial byte, if necessary - this requires some masking
uint8_t mod = (y & 7); uint8_t mod = (y & 7);
@ -875,6 +880,8 @@ void Adafruit_SSD1306::drawFastVLineInternal(
screen if display() has not been called. screen if display() has not been called.
*/ */
boolean Adafruit_SSD1306::getPixel(int16_t x, int16_t y) { boolean Adafruit_SSD1306::getPixel(int16_t x, int16_t y) {
if (!framebuffer) return 0;
if((x >= 0) && (x < width()) && (y >= 0) && (y < height())) { if((x >= 0) && (x < width()) && (y >= 0) && (y < height())) {
// Pixel is in-bounds. Rotate coordinates if needed. // Pixel is in-bounds. Rotate coordinates if needed.
switch(getRotation()) { switch(getRotation()) {
@ -891,7 +898,7 @@ boolean Adafruit_SSD1306::getPixel(int16_t x, int16_t y) {
y = HEIGHT - y - 1; y = HEIGHT - y - 1;
break; break;
} }
return (buffer[x + (y / 8) * WIDTH] & (1 << (y & 7))); return (framebuffer[x + (y / 8) * WIDTH] & (1 << (y & 7)));
} }
return false; // Pixel out of bounds return false; // Pixel out of bounds
} }
@ -902,7 +909,7 @@ boolean Adafruit_SSD1306::getPixel(int16_t x, int16_t y) {
to full byte boundary if needed. to full byte boundary if needed.
*/ */
uint8_t *Adafruit_SSD1306::getBuffer(void) { uint8_t *Adafruit_SSD1306::getBuffer(void) {
return xbuffer; return framebuffer;
} }
@ -916,6 +923,7 @@ uint8_t *Adafruit_SSD1306::getBuffer(void) {
of graphics commands, as best needed by one's own application. of graphics commands, as best needed by one's own application.
*/ */
void Adafruit_SSD1306::display(void) { void Adafruit_SSD1306::display(void) {
if (!framebuffer) return;
int16_t col_start = 0; int16_t col_start = 0;
int16_t col_end = WIDTH - 1; int16_t col_end = WIDTH - 1;
if ((64 == WIDTH) && (48 == HEIGHT)) { // for 64x48, we need to shift by 32 in both directions if ((64 == WIDTH) && (48 == HEIGHT)) { // for 64x48, we need to shift by 32 in both directions
@ -943,7 +951,7 @@ void Adafruit_SSD1306::display(void) {
yield(); yield();
#endif #endif
uint16_t count = WIDTH * ((HEIGHT + 7) / 8); uint16_t count = WIDTH * ((HEIGHT + 7) / 8);
uint8_t *ptr = buffer; uint8_t *ptr = framebuffer;
if(wire) { // I2C if(wire) { // I2C
wire->beginTransmission(i2caddr); wire->beginTransmission(i2caddr);
WIRE_WRITE((uint8_t)0x40); WIRE_WRITE((uint8_t)0x40);

View File

@ -27,8 +27,6 @@
#include <pgmspace.h> #include <pgmspace.h>
#include "epdpaint.h" #include "epdpaint.h"
extern uint8_t *buffer;
Paint::Paint(int16_t width, int16_t height) : Paint::Paint(int16_t width, int16_t height) :
Renderer(width,height) { Renderer(width,height) {
} }
@ -66,15 +64,15 @@ void Paint::DrawAbsolutePixel(int x, int y, int16_t color) {
} }
if (IF_INVERT_COLOR) { if (IF_INVERT_COLOR) {
if (color) { if (color) {
buffer[(x + y * w) / 8] |= 0x80 >> (x % 8); framebuffer[(x + y * w) / 8] |= 0x80 >> (x % 8);
} else { } else {
buffer[(x + y * w) / 8] &= ~(0x80 >> (x % 8)); framebuffer[(x + y * w) / 8] &= ~(0x80 >> (x % 8));
} }
} else { } else {
if (color) { if (color) {
buffer[(x + y * w) / 8] &= ~(0x80 >> (x % 8)); framebuffer[(x + y * w) / 8] &= ~(0x80 >> (x % 8));
} else { } else {
buffer[(x + y * w) / 8] |= 0x80 >> (x % 8); framebuffer[(x + y * w) / 8] |= 0x80 >> (x % 8);
} }
} }
} }
@ -120,7 +118,7 @@ void Paint::drawPixel(int16_t x, int16_t y, uint16_t color) {
void Paint::drawPixel(int16_t x, int16_t y, uint16_t color) { void Paint::drawPixel(int16_t x, int16_t y, uint16_t color) {
if (!buffer) return; if (!framebuffer) return;
if ((x < 0) || (x >= width()) || (y < 0) || (y >= height())) if ((x < 0) || (x >= width()) || (y < 0) || (y >= height()))
return; return;

View File

@ -35,8 +35,6 @@
uint8_t wr_redir=0; uint8_t wr_redir=0;
uint8_t *buffer;
#define register #define register
#define SPRINT(A) char str[32];sprintf(str,"val: %d ",A);Serial.println((char*)str); #define SPRINT(A) char str[32];sprintf(str,"val: %d ",A);Serial.println((char*)str);
@ -87,6 +85,17 @@ void Renderer::Updateframe() {
} }
void Renderer::TS_RotConvert(int16_t *x, int16_t *y) {
}
uint8_t *Renderer::allocate_framebuffer(uint32_t size) {
if (framebuffer) free(framebuffer);
framebuffer = (unsigned char*)calloc(size, 1);
if (!framebuffer) return 0;
return framebuffer;
}
void Renderer::setTextSize(uint8_t sf) { void Renderer::setTextSize(uint8_t sf) {
if (sf < 1) sf = 1; if (sf < 1) sf = 1;
@ -306,7 +315,7 @@ void Renderer::clearDisplay(void) {
void Renderer::drawFastHLine(int16_t x, int16_t y, int16_t w, uint16_t color) { void Renderer::drawFastHLine(int16_t x, int16_t y, int16_t w, uint16_t color) {
boolean bSwap = false; boolean bSwap = false;
if (!buffer) return; if (!framebuffer) return;
switch(getRotation()) { switch(getRotation()) {
case 0: case 0:
// 0 degree rotation, do nothing // 0 degree rotation, do nothing
@ -358,7 +367,7 @@ void Renderer::drawFastHLineInternal(int16_t x, int16_t y, int16_t w, uint16_t c
if(w <= 0) { return; } if(w <= 0) { return; }
// set up the pointer for movement through the buffer // set up the pointer for movement through the buffer
register uint8_t *pBuf = buffer; register uint8_t *pBuf = framebuffer;
// adjust the buffer pointer for the current row // adjust the buffer pointer for the current row
pBuf += ((y/8) * WIDTH); pBuf += ((y/8) * WIDTH);
// and offset x columns in // and offset x columns in
@ -375,7 +384,7 @@ void Renderer::drawFastHLineInternal(int16_t x, int16_t y, int16_t w, uint16_t c
} }
void Renderer::drawFastVLine(int16_t x, int16_t y, int16_t h, uint16_t color) { void Renderer::drawFastVLine(int16_t x, int16_t y, int16_t h, uint16_t color) {
if (!buffer) return; if (!framebuffer) return;
bool bSwap = false; bool bSwap = false;
switch(getRotation()) { switch(getRotation()) {
case 0: case 0:
@ -410,7 +419,7 @@ void Renderer::drawFastVLine(int16_t x, int16_t y, int16_t h, uint16_t color) {
void Renderer::drawFastVLineInternal(int16_t x, int16_t __y, int16_t __h, uint16_t color) { void Renderer::drawFastVLineInternal(int16_t x, int16_t __y, int16_t __h, uint16_t color) {
if (!framebuffer) return;
// do nothing if we're off the left or right side of the screen // do nothing if we're off the left or right side of the screen
if(x < 0 || x >= WIDTH) { return; } if(x < 0 || x >= WIDTH) { return; }
@ -438,7 +447,7 @@ void Renderer::drawFastVLineInternal(int16_t x, int16_t __y, int16_t __h, uint16
// set up the pointer for fast movement through the buffer // set up the pointer for fast movement through the buffer
register uint8_t *pBuf = buffer; register uint8_t *pBuf = framebuffer;
// adjust the buffer pointer for the current row // adjust the buffer pointer for the current row
pBuf += ((y/8) * WIDTH); pBuf += ((y/8) * WIDTH);
// and offset x columns in // and offset x columns in
@ -530,7 +539,7 @@ void Renderer::drawPixel(int16_t x, int16_t y, uint16_t color) {
// the most basic function, set a single pixel // the most basic function, set a single pixel
void Renderer::drawPixel(int16_t x, int16_t y, uint16_t color) { void Renderer::drawPixel(int16_t x, int16_t y, uint16_t color) {
if (!buffer) return; if (!framebuffer) return;
if ((x < 0) || (x >= width()) || (y < 0) || (y >= height())) if ((x < 0) || (x >= width()) || (y < 0) || (y >= height()))
return; return;
@ -553,9 +562,9 @@ void Renderer::drawPixel(int16_t x, int16_t y, uint16_t color) {
// x is which column // x is which column
switch (color) switch (color)
{ {
case WHITE: buffer[x+ (y/8)*WIDTH] |= (1 << (y&7)); break; case WHITE: framebuffer[x+ (y/8)*WIDTH] |= (1 << (y&7)); break;
case BLACK: buffer[x+ (y/8)*WIDTH] &= ~(1 << (y&7)); break; case BLACK: framebuffer[x+ (y/8)*WIDTH] &= ~(1 << (y&7)); break;
case INVERSE: buffer[x+ (y/8)*WIDTH] ^= (1 << (y&7)); break; case INVERSE: framebuffer[x+ (y/8)*WIDTH] ^= (1 << (y&7)); break;
} }
} }

View File

@ -41,10 +41,13 @@ public:
virtual void reverseDisplay(boolean i); virtual void reverseDisplay(boolean i);
virtual void setScrollMargins(uint16_t top, uint16_t bottom); virtual void setScrollMargins(uint16_t top, uint16_t bottom);
virtual void scrollTo(uint16_t y); virtual void scrollTo(uint16_t y);
virtual void TS_RotConvert(int16_t *x, int16_t *y);
void setDrawMode(uint8_t mode); void setDrawMode(uint8_t mode);
uint8_t drawmode; uint8_t drawmode;
virtual void FastString(uint16_t x,uint16_t y,uint16_t tcolor, const char* str); virtual void FastString(uint16_t x,uint16_t y,uint16_t tcolor, const char* str);
void setTextSize(uint8_t s); void setTextSize(uint8_t s);
virtual uint8_t *allocate_framebuffer(uint32_t size);
private: private:
void DrawCharAt(int16_t x, int16_t y, char ascii_char,int16_t colored); void DrawCharAt(int16_t x, int16_t y, char ascii_char,int16_t colored);
inline void drawFastVLineInternal(int16_t x, int16_t y, int16_t h, uint16_t color) __attribute__((always_inline)); inline void drawFastVLineInternal(int16_t x, int16_t y, int16_t h, uint16_t color) __attribute__((always_inline));

View File

@ -27,7 +27,6 @@
#include <stdlib.h> #include <stdlib.h>
#include "epd2in9.h" #include "epd2in9.h"
extern uint8_t *buffer;
Epd::Epd(int16_t width, int16_t height) : Epd::Epd(int16_t width, int16_t height) :
Paint(width,height) { Paint(width,height) {
@ -37,7 +36,7 @@ void Epd::DisplayOnff(int8_t on) {
} }
void Epd::Updateframe() { void Epd::Updateframe() {
SetFrameMemory(buffer, 0, 0, EPD_WIDTH,EPD_HEIGHT); SetFrameMemory(framebuffer, 0, 0, EPD_WIDTH,EPD_HEIGHT);
DisplayFrame(); DisplayFrame();
//Serial.printf("update\n"); //Serial.printf("update\n");
} }
@ -110,6 +109,10 @@ int Epd::Init(const unsigned char* lut) {
mosi_pin=pin[GPIO_SSPI_MOSI]; mosi_pin=pin[GPIO_SSPI_MOSI];
sclk_pin=pin[GPIO_SSPI_SCLK]; sclk_pin=pin[GPIO_SSPI_SCLK];
*/ */
framebuffer = (uint8_t*)malloc(EPD_WIDTH * EPD_HEIGHT / 8);
if (!framebuffer) return -1;
pinMode(cs_pin, OUTPUT); pinMode(cs_pin, OUTPUT);
pinMode(mosi_pin, OUTPUT); pinMode(mosi_pin, OUTPUT);
pinMode(sclk_pin, OUTPUT); pinMode(sclk_pin, OUTPUT);

View File

@ -29,8 +29,6 @@
//#define SSPI_USEANYPIN //#define SSPI_USEANYPIN
extern uint8_t *buffer;
uint8_t epd42_mode; uint8_t epd42_mode;
Epd42::Epd42(int16_t width, int16_t height) : Epd42::Epd42(int16_t width, int16_t height) :
@ -47,7 +45,7 @@ void Epd42::DisplayOnff(int8_t on) {
void Epd42::Updateframe() { void Epd42::Updateframe() {
//SetFrameMemory(buffer, 0, 0, EPD_WIDTH,EPD_HEIGHT); //SetFrameMemory(buffer, 0, 0, EPD_WIDTH,EPD_HEIGHT);
SetPartialWindow(buffer, 0, 0, width,height,2); SetPartialWindow(framebuffer, 0, 0, width,height,2);
if (epd42_mode==DISPLAY_INIT_PARTIAL) { if (epd42_mode==DISPLAY_INIT_PARTIAL) {
DisplayFrameQuick(); DisplayFrameQuick();
} else { } else {
@ -103,6 +101,10 @@ void Epd42::Init(int8_t p) {
} }
int Epd42::Init(void) { int Epd42::Init(void) {
framebuffer = (uint8_t*)malloc(EPD_WIDTH42 * EPD_HEIGHT42 / 8);
if (!framebuffer) return -1;
pinMode(cs_pin, OUTPUT); pinMode(cs_pin, OUTPUT);
pinMode(mosi_pin, OUTPUT); pinMode(mosi_pin, OUTPUT);
pinMode(sclk_pin, OUTPUT); pinMode(sclk_pin, OUTPUT);
@ -115,19 +117,19 @@ int Epd42::Init(void) {
height = EPD_HEIGHT42; height = EPD_HEIGHT42;
Reset(); Reset();
SendCommand(EPD_42_POWER_SETTING); SendCommand(EPD_42_POWER_SETTING); // 0xa1
SendData(0x03); // VDS_EN, VDG_EN SendData(0x03); // VDS_EN, VDG_EN
SendData(0x00); // VCOM_HV, VGHL_LV[1], VGHL_LV[0] SendData(0x00); // VCOM_HV, VGHL_LV[1], VGHL_LV[0]
SendData(0x2b); // VDH SendData(0x2b); // VDH
SendData(0x2b); // VDL SendData(0x2b); // VDL
SendData(0xff); // VDHR SendData(0xff); // VDHR
SendCommand(EPD_42_BOOSTER_SOFT_START); SendCommand(EPD_42_BOOSTER_SOFT_START); // axa6
SendData(0x17); SendData(0x17);
SendData(0x17); SendData(0x17);
SendData(0x17); //07 0f 17 1f 27 2F 37 2f SendData(0x17); //07 0f 17 1f 27 2F 37 2f
SendCommand(EPD_42_POWER_ON); SendCommand(EPD_42_POWER_ON); // 04
WaitUntilIdle(); WaitUntilIdle();
SendCommand(EPD_42_PANEL_SETTING); SendCommand(EPD_42_PANEL_SETTING); //0x00
// SendData(0xbf); // KW-BF KWR-AF BWROTP 0f // SendData(0xbf); // KW-BF KWR-AF BWROTP 0f
// SendData(0x0b); // SendData(0x0b);
// SendData(0x0F); //300x400 Red mode, LUT from OTP // SendData(0x0F); //300x400 Red mode, LUT from OTP
@ -135,7 +137,7 @@ int Epd42::Init(void) {
SendData(0x3F); //300x400 B/W mode, LUT set by register SendData(0x3F); //300x400 B/W mode, LUT set by register
// SendData(0x2F); //300x400 Red mode, LUT set by register // SendData(0x2F); //300x400 Red mode, LUT set by register
SendCommand(EPD_42_PLL_CONTROL); SendCommand(EPD_42_PLL_CONTROL); // 0x30
SendData(0x3C); // 3A 100Hz 29 150Hz 39 200Hz 31 171Hz 3C 50Hz (default) 0B 10Hz SendData(0x3C); // 3A 100Hz 29 150Hz 39 200Hz 31 171Hz 3C 50Hz (default) 0B 10Hz
//SendData(0x0B); //0B is 10Hz //SendData(0x0B); //0B is 10Hz
/* EPD hardware init end */ /* EPD hardware init end */

View File

@ -193,6 +193,8 @@ void ILI9341_2::init(uint16_t width, uint16_t height) {
if (_hwspi > 2) { if (_hwspi > 2) {
spi2->begin(_sclk, _miso, _mosi, -1); spi2->begin(_sclk, _miso, _mosi, -1);
} }
#else
SPI.begin();
#endif // ESP32 #endif // ESP32
} else { } else {
#ifdef ESP32 #ifdef ESP32

View File

@ -465,7 +465,6 @@ void ILI9488::begin(void) {
writedata(0x02); //2-dot writedata(0x02); //2-dot
writecommand(0XB6); //Display Function Control RGB/MCU Interface Control writecommand(0XB6); //Display Function Control RGB/MCU Interface Control
writedata(0x02); //MCU writedata(0x02); //MCU
writedata(0x02); //Source,Gate scan dieection writedata(0x02); //Source,Gate scan dieection

0
lib/lib_display/UDisplay/keywords.txt Normal file → Executable file
View File

0
lib/lib_display/UDisplay/library.properties Normal file → Executable file
View File

64
lib/lib_display/UDisplay/uDisplay.cpp Normal file → Executable file
View File

@ -20,7 +20,7 @@
#include <Arduino.h> #include <Arduino.h>
#include "uDisplay.h" #include "uDisplay.h"
//#define UDSP_DEBUG #define UDSP_DEBUG
const uint16_t udisp_colors[]={UDISP_BLACK,UDISP_WHITE,UDISP_RED,UDISP_GREEN,UDISP_BLUE,UDISP_CYAN,UDISP_MAGENTA,\ const uint16_t udisp_colors[]={UDISP_BLACK,UDISP_WHITE,UDISP_RED,UDISP_GREEN,UDISP_BLUE,UDISP_CYAN,UDISP_MAGENTA,\
UDISP_YELLOW,UDISP_NAVY,UDISP_DARKGREEN,UDISP_DARKCYAN,UDISP_MAROON,UDISP_PURPLE,UDISP_OLIVE,\ UDISP_YELLOW,UDISP_NAVY,UDISP_DARKGREEN,UDISP_DARKCYAN,UDISP_MAROON,UDISP_PURPLE,UDISP_OLIVE,\
@ -31,11 +31,16 @@ uint16_t uDisplay::GetColorFromIndex(uint8_t index) {
return udisp_colors[index]; return udisp_colors[index];
} }
extern uint8_t *buffer;
extern uint8_t color_type; uDisplay::~uDisplay(void) {
if (framebuffer) {
free(framebuffer);
}
}
uDisplay::uDisplay(char *lp) : Renderer(800, 600) { uDisplay::uDisplay(char *lp) : Renderer(800, 600) {
// analyse decriptor // analyse decriptor
framebuffer = 0;
col_mode = 16; col_mode = 16;
sa_mode = 16; sa_mode = 16;
saw_3 = 0xff; saw_3 = 0xff;
@ -103,13 +108,17 @@ uDisplay::uDisplay(char *lp) : Renderer(800, 600) {
setheight(gys); setheight(gys);
bpp = next_val(&lp1); bpp = next_val(&lp1);
if (bpp == 1) { if (bpp == 1) {
color_type = uCOLOR_BW; col_type = uCOLOR_BW;
} else { } else {
color_type = uCOLOR_COLOR; col_type = uCOLOR_COLOR;
} }
str2c(&lp1, ibuff, sizeof(ibuff)); str2c(&lp1, ibuff, sizeof(ibuff));
if (!strncmp(ibuff, "I2C", 3)) { if (!strncmp(ibuff, "I2C", 3)) {
interface = _UDSP_I2C; interface = _UDSP_I2C;
wire_n = 0;
if (!strncmp(ibuff, "I2C2", 4)) {
wire_n = 1;
}
i2caddr = next_hex(&lp1); i2caddr = next_hex(&lp1);
i2c_scl = next_val(&lp1); i2c_scl = next_val(&lp1);
i2c_sda = next_val(&lp1); i2c_sda = next_val(&lp1);
@ -350,17 +359,24 @@ Renderer *uDisplay::Init(void) {
} }
if (interface == _UDSP_I2C) { if (interface == _UDSP_I2C) {
wire = &Wire; if (wire_n == 0) {
wire = &Wire;
}
#ifdef ESP32
if (wire_n == 1) {
wire = &Wire1;
}
#endif
wire->begin(i2c_sda, i2c_scl); wire->begin(i2c_sda, i2c_scl);
if (bpp < 16) { if (bpp < 16) {
if (buffer) free(buffer); if (framebuffer) free(framebuffer);
#ifdef ESP8266 #ifdef ESP8266
buffer = (uint8_t*)calloc((gxs * gys * bpp) / 8, 1); framebuffer = (uint8_t*)calloc((gxs * gys * bpp) / 8, 1);
#else #else
if (psramFound()) { if (psramFound()) {
buffer = (uint8_t*)heap_caps_malloc((gxs * gys * bpp) / 8, MALLOC_CAP_SPIRAM | MALLOC_CAP_8BIT); framebuffer = (uint8_t*)heap_caps_malloc((gxs * gys * bpp) / 8, MALLOC_CAP_SPIRAM | MALLOC_CAP_8BIT);
} else { } else {
buffer = (uint8_t*)calloc((gxs * gys * bpp) / 8, 1); framebuffer = (uint8_t*)calloc((gxs * gys * bpp) / 8, 1);
} }
#endif #endif
} }
@ -380,12 +396,12 @@ Renderer *uDisplay::Init(void) {
if (ep_mode) { if (ep_mode) {
#ifdef ESP8266 #ifdef ESP8266
buffer = (uint8_t*)calloc((gxs * gys * bpp) / 8, 1); framebuffer = (uint8_t*)calloc((gxs * gys * bpp) / 8, 1);
#else #else
if (psramFound()) { if (psramFound()) {
buffer = (uint8_t*)heap_caps_malloc((gxs * gys * bpp) / 8, MALLOC_CAP_SPIRAM | MALLOC_CAP_8BIT); framebuffer = (uint8_t*)heap_caps_malloc((gxs * gys * bpp) / 8, MALLOC_CAP_SPIRAM | MALLOC_CAP_8BIT);
} else { } else {
buffer = (uint8_t*)calloc((gxs * gys * bpp) / 8, 1); framebuffer = (uint8_t*)calloc((gxs * gys * bpp) / 8, 1);
} }
#endif #endif
} }
@ -654,7 +670,7 @@ void uDisplay::Updateframe(void) {
i2c_command(i2c_col_end); i2c_command(i2c_col_end);
uint16_t count = gxs * ((gys + 7) / 8); uint16_t count = gxs * ((gys + 7) / 8);
uint8_t *ptr = buffer; uint8_t *ptr = framebuffer;
wire->beginTransmission(i2caddr); wire->beginTransmission(i2caddr);
i2c_command(saw_3); i2c_command(saw_3);
uint8_t bytesOut = 1; uint8_t bytesOut = 1;
@ -695,7 +711,7 @@ void uDisplay::Updateframe(void) {
wire->beginTransmission(i2caddr); wire->beginTransmission(i2caddr);
wire->write(0x40); wire->write(0x40);
for ( k = 0; k < xs; k++, p++) { for ( k = 0; k < xs; k++, p++) {
wire->write(buffer[p]); wire->write(framebuffer[p]);
} }
wire->endTransmission(); wire->endTransmission();
} }
@ -1453,12 +1469,12 @@ void uDisplay::DisplayFrame_42(void) {
spi_command_EPD(saw_2); spi_command_EPD(saw_2);
for (uint16_t j = 0; j < Height; j++) { for (uint16_t j = 0; j < Height; j++) {
for (uint16_t i = 0; i < Width; i++) { for (uint16_t i = 0; i < Width; i++) {
spi_data8_EPD(buffer[i + j * Width] ^ 0xff); spi_data8_EPD(framebuffer[i + j * Width] ^ 0xff);
} }
} }
spi_command_EPD(saw_3); spi_command_EPD(saw_3);
delay(100); delay(100);
//Serial.printf("EPD Diplayframe\n"); Serial.printf("EPD Diplayframe\n");
} }
@ -1483,7 +1499,7 @@ void uDisplay::ClearFrame_42(void) {
spi_command_EPD(saw_3); spi_command_EPD(saw_3);
delay(100); delay(100);
//Serial.printf("EPD Clearframe\n"); Serial.printf("EPD Clearframe\n");
} }
@ -1497,7 +1513,7 @@ void uDisplay::SetLut(const unsigned char* lut) {
void uDisplay::Updateframe_EPD(void) { void uDisplay::Updateframe_EPD(void) {
if (ep_mode == 1) { if (ep_mode == 1) {
SetFrameMemory(buffer, 0, 0, gxs, gys); SetFrameMemory(framebuffer, 0, 0, gxs, gys);
DisplayFrame_29(); DisplayFrame_29();
} else { } else {
DisplayFrame_42(); DisplayFrame_42();
@ -1609,21 +1625,21 @@ void uDisplay::DrawAbsolutePixel(int x, int y, int16_t color) {
} }
if (IF_INVERT_COLOR) { if (IF_INVERT_COLOR) {
if (color) { if (color) {
buffer[(x + y * w) / 8] |= 0x80 >> (x % 8); framebuffer[(x + y * w) / 8] |= 0x80 >> (x % 8);
} else { } else {
buffer[(x + y * w) / 8] &= ~(0x80 >> (x % 8)); framebuffer[(x + y * w) / 8] &= ~(0x80 >> (x % 8));
} }
} else { } else {
if (color) { if (color) {
buffer[(x + y * w) / 8] &= ~(0x80 >> (x % 8)); framebuffer[(x + y * w) / 8] &= ~(0x80 >> (x % 8));
} else { } else {
buffer[(x + y * w) / 8] |= 0x80 >> (x % 8); framebuffer[(x + y * w) / 8] |= 0x80 >> (x % 8);
} }
} }
} }
void uDisplay::drawPixel_EPD(int16_t x, int16_t y, uint16_t color) { void uDisplay::drawPixel_EPD(int16_t x, int16_t y, uint16_t color) {
if (!buffer) return; if (!framebuffer) return;
if ((x < 0) || (x >= width()) || (y < 0) || (y >= height())) if ((x < 0) || (x >= width()) || (y < 0) || (y >= height()))
return; return;

4
lib/lib_display/UDisplay/uDisplay.h Normal file → Executable file
View File

@ -72,6 +72,7 @@ enum uColorType { uCOLOR_BW, uCOLOR_COLOR };
class uDisplay : public Renderer { class uDisplay : public Renderer {
public: public:
uDisplay(char *); uDisplay(char *);
~uDisplay(void);
Renderer *Init(void); Renderer *Init(void);
void DisplayInit(int8_t p,int8_t size,int8_t rot,int8_t font); void DisplayInit(int8_t p,int8_t size,int8_t rot,int8_t font);
void Updateframe(); void Updateframe();
@ -80,6 +81,7 @@ class uDisplay : public Renderer {
char *devname(void); char *devname(void);
uint16_t fgcol(void) const { return fg_col; }; uint16_t fgcol(void) const { return fg_col; };
uint16_t bgcol(void) const { return bg_col; }; uint16_t bgcol(void) const { return bg_col; };
int8_t color_type(void) const { return col_type; };
void dim(uint8_t dim); void dim(uint8_t dim);
uint16_t GetColorFromIndex(uint8_t index); uint16_t GetColorFromIndex(uint8_t index);
void setRotation(uint8_t m); void setRotation(uint8_t m);
@ -137,10 +139,12 @@ class uDisplay : public Renderer {
void setAddrWindow_int(uint16_t x, uint16_t y, uint16_t w, uint16_t h); void setAddrWindow_int(uint16_t x, uint16_t y, uint16_t w, uint16_t h);
char dname[16]; char dname[16];
int8_t bpp; int8_t bpp;
uint8_t col_type;
uint8_t interface; uint8_t interface;
uint8_t i2caddr; uint8_t i2caddr;
int8_t i2c_scl; int8_t i2c_scl;
TwoWire *wire; TwoWire *wire;
int8_t wire_n;
int8_t i2c_sda; int8_t i2c_sda;
uint8_t i2c_col_start; uint8_t i2c_col_start;
uint8_t i2c_col_end; uint8_t i2c_col_end;

View File

@ -31,6 +31,11 @@ enum ColorType { COLOR_BW, COLOR_COLOR };
#define MAX_TOUCH_BUTTONS 16 #define MAX_TOUCH_BUTTONS 16
#endif #endif
#ifdef USE_UFILESYS
extern FS *ufsp;
extern FS *ffsp;
#endif
#ifdef USE_TOUCH_BUTTONS #ifdef USE_TOUCH_BUTTONS
VButton *buttons[MAX_TOUCH_BUTTONS]; VButton *buttons[MAX_TOUCH_BUTTONS];
#endif #endif
@ -41,6 +46,45 @@ uint16_t fg_color = 1;
uint16_t bg_color = 0; uint16_t bg_color = 0;
uint8_t color_type = COLOR_BW; uint8_t color_type = COLOR_BW;
uint8_t auto_draw = 1; uint8_t auto_draw = 1;
int16_t disp_xpos = 0;
int16_t disp_ypos = 0;
#ifdef USE_MULTI_DISPLAY
struct MULTI_DISP {
Renderer *display;
uint16_t fg_color;
uint16_t bg_color;
int16_t disp_xpos;
int16_t disp_ypos;
uint8_t color_type;
uint8_t auto_draw;
} displays[3];
uint8_t cur_display;
Renderer *Init_uDisplay(const char *desc);
void Set_display(uint8_t index) {
displays[index].display = renderer;
displays[index].fg_color = fg_color;
displays[index].bg_color = bg_color;
displays[index].color_type = color_type;
displays[index].auto_draw = auto_draw;
displays[index].disp_xpos = disp_xpos;
displays[index].disp_ypos = disp_ypos;
cur_display = index;
}
void Get_display(uint8_t index) {
renderer = displays[index].display;
fg_color = displays[index].fg_color;
bg_color = displays[index].bg_color;
color_type = displays[index].color_type;
auto_draw = displays[index].auto_draw;
disp_xpos = displays[index].disp_xpos;
disp_ypos = displays[index].disp_ypos;
if (renderer) renderer->setDrawMode(auto_draw >> 1);
cur_display = index;
}
#endif // USE_MULTI_DISPLAY
const uint8_t DISPLAY_MAX_DRIVERS = 32; // Max number of display drivers/models supported by xdsp_interface.ino const uint8_t DISPLAY_MAX_DRIVERS = 32; // Max number of display drivers/models supported by xdsp_interface.ino
const uint8_t DISPLAY_MAX_COLS = 64; // Max number of columns allowed with command DisplayCols const uint8_t DISPLAY_MAX_COLS = 64; // Max number of columns allowed with command DisplayCols
@ -175,8 +219,6 @@ uint16_t dsp_y2;
uint16_t dsp_rad; uint16_t dsp_rad;
uint16_t dsp_color; uint16_t dsp_color;
int16_t dsp_len; int16_t dsp_len;
int16_t disp_xpos = 0;
int16_t disp_ypos = 0;
uint8_t disp_power = 0; uint8_t disp_power = 0;
uint8_t disp_device = 0; uint8_t disp_device = 0;
@ -512,6 +554,49 @@ void DisplayText(void)
} }
} }
break; break;
#ifdef USE_MULTI_DISPLAY
case 'S':
{
var = atoiv(cp, &temp);
cp += var;
if (temp < 1 || temp > 3) {
temp = 1;
}
temp--;
if (*cp == ':') {
cp++;
if (displays[temp].display) {
Set_display(cur_display);
Get_display(temp);
}
} else {
char *ep=strchr(cp,':');
if (ep) {
*ep=0;
ep++;
File fp;
if (ffsp) {
AddLog(LOG_LEVEL_INFO, PSTR("DSP: File: %s"),cp);
fp = ffsp->open(cp, "r");
if (fp > 0) {
uint32_t size = fp.size();
char *fdesc = (char *)calloc(size + 4, 1);
if (fdesc) {
fp.read((uint8_t*)fdesc, size);
fp.close();
Get_display(temp);
renderer = Init_uDisplay(fdesc);
Set_display(temp);
AddLog(LOG_LEVEL_INFO, PSTR("DSP: File descriptor loaded %x"),renderer);
}
}
}
}
cp = ep;
}
}
break;
#endif // USE_MULTI_DISPLAY
#endif // USE_UFILESYS #endif // USE_UFILESYS
case 'h': case 'h':
// hor line to // hor line to
@ -736,7 +821,7 @@ extern FS *ffsp;
{ char *ep = strchr(cp,':'); { char *ep = strchr(cp,':');
if (ep) { if (ep) {
static uint8_t *ram_font; static uint8_t *ram_font;
char fname[24]; char fname[32];
*ep = 0; *ep = 0;
ep++; ep++;
if (*cp != '/') { if (*cp != '/') {
@ -1024,7 +1109,6 @@ extern FS *ffsp;
} }
#ifdef USE_UFILESYS #ifdef USE_UFILESYS
extern FS *ufsp;
void Display_Text_From_File(const char *file) { void Display_Text_From_File(const char *file) {
File fp; File fp;
if (!ufsp) return; if (!ufsp) return;
@ -1188,7 +1272,7 @@ void draw_dt_vars(void) {
// restore display vars // restore display vars
renderer->setTextColor(fg_color, bg_color); renderer->setTextColor(fg_color, bg_color);
renderer->setDrawMode(auto_draw); renderer->setDrawMode(auto_draw>>1);
} }
} }
} }
@ -1657,6 +1741,10 @@ void DisplayInitDriver(void)
{ {
XdspCall(FUNC_DISPLAY_INIT_DRIVER); XdspCall(FUNC_DISPLAY_INIT_DRIVER);
#ifdef USE_MULTI_DISPLAY
Set_display(0);
#endif // USE_MULTI_DISPLAY
if (renderer) { if (renderer) {
renderer->setTextFont(Settings.display_font); renderer->setTextFont(Settings.display_font);
renderer->setTextSize(Settings.display_size); renderer->setTextSize(Settings.display_size);
@ -2043,6 +2131,9 @@ void CmndDisplayScrollText(void) {
void DisplayReInitDriver(void) { void DisplayReInitDriver(void) {
XdspCall(FUNC_DISPLAY_INIT_DRIVER); XdspCall(FUNC_DISPLAY_INIT_DRIVER);
#ifdef USE_MULTI_DISPLAY
Set_display(0);
#endif // USE_MULTI_DISPLAY
ResponseCmndDone(); ResponseCmndDone();
} }
@ -2578,70 +2669,84 @@ void AddValue(uint8_t num,float fval) {
\*********************************************************************************************/ \*********************************************************************************************/
#if defined(USE_FT5206) || defined(USE_XPT2046) #if defined(USE_FT5206) || defined(USE_XPT2046)
bool FT5206_found = false;
bool XPT2046_found = false;
int16_t touch_xp;
int16_t touch_yp;
bool touched;
#ifdef USE_M5STACK_CORE2
uint8_t tbstate[3];
#endif // USE_M5STACK_CORE2
#ifdef USE_FT5206 #ifdef USE_FT5206
#include <FT5206.h> #include <FT5206.h>
// touch panel controller // touch panel controller
#undef FT5206_address #undef FT5206_address
#define FT5206_address 0x38 #define FT5206_address 0x38
FT5206_Class *touchp; FT5206_Class *FT5206_touchp;
TP_Point pLoc;
bool FT5206_found;
bool Touch_Init(TwoWire &i2c) {
bool FT5206_Touch_Init(TwoWire &i2c) {
FT5206_found = false; FT5206_found = false;
touchp = new FT5206_Class(); FT5206_touchp = new FT5206_Class();
if (touchp->begin(i2c, FT5206_address)) { if (FT5206_touchp->begin(i2c, FT5206_address)) {
I2cSetActiveFound(FT5206_address, "FT5206"); I2cSetActiveFound(FT5206_address, "FT5206");
FT5206_found = true; FT5206_found = true;
} }
return FT5206_found; return FT5206_found;
} }
uint32_t Touch_Status(uint32_t sel) { bool FT5206_touched() {
if (FT5206_found) { return FT5206_touchp->touched();
switch (sel) { }
case 0: int16_t FT5206_x() {
return touchp->touched(); TP_Point pLoc = FT5206_touchp->getPoint(0);
case 1: return pLoc.x;
return pLoc.x; }
case 2: int16_t FT5206_y() {
return pLoc.y; TP_Point pLoc = FT5206_touchp->getPoint(0);
} return pLoc.y;
return 0;
} else {
return 0;
}
} }
#endif // USE_FT5206 #endif // USE_FT5206
#if defined(USE_XPT2046) && defined(USE_DISPLAY_ILI9341) #ifdef USE_XPT2046
#include <XPT2046_Touchscreen.h> #include <XPT2046_Touchscreen.h>
XPT2046_Touchscreen *XPT2046_touchp;
XPT2046_Touchscreen *touchp;
TS_Point pLoc;
bool XPT2046_found;
bool Touch_Init(uint16_t CS) { bool XPT2046_Touch_Init(uint16_t CS) {
touchp = new XPT2046_Touchscreen(CS); XPT2046_touchp = new XPT2046_Touchscreen(CS);
XPT2046_found = touchp->begin(); XPT2046_found = XPT2046_touchp->begin();
if (XPT2046_found) { if (XPT2046_found) {
AddLog(LOG_LEVEL_INFO, PSTR("TS: XPT2046")); AddLog(LOG_LEVEL_INFO, PSTR("TS: XPT2046"));
} }
return XPT2046_found; return XPT2046_found;
} }
bool XPT2046_touched() {
return XPT2046_touchp->touched();
}
int16_t XPT2046_x() {
TS_Point pLoc = XPT2046_touchp->getPoint();
return pLoc.x;
}
int16_t XPT2046_y() {
TS_Point pLoc = XPT2046_touchp->getPoint();
return pLoc.y;
}
#endif // USE_XPT2046
uint32_t Touch_Status(uint32_t sel) { uint32_t Touch_Status(uint32_t sel) {
if (XPT2046_found) { if (FT5206_found || XPT2046_found) {
switch (sel) { switch (sel) {
case 0: case 0:
return touchp->touched(); return touched;
case 1: case 1:
return pLoc.x; return touch_xp;
case 2: case 2:
return pLoc.y; return touch_yp;
} }
return 0; return 0;
} else { } else {
@ -2649,14 +2754,80 @@ uint32_t Touch_Status(uint32_t sel) {
} }
} }
#endif // USE_XPT2046 && USE_DISPLAY_ILI9341 void Touch_Check(void(*rotconvert)(int16_t *x, int16_t *y)) {
#ifdef USE_FT5206
if (FT5206_found) {
touch_xp = FT5206_x();
touch_yp = FT5206_y();
touched = FT5206_touched();
}
#endif // USE_FT5206
#ifdef USE_XPT2046
if (XPT2046_found) {
touch_xp = XPT2046_x();
touch_yp = XPT2046_y();
touched = XPT2046_touched();
}
#endif // USE_XPT2046
if (touched) {
#ifdef USE_TOUCH_BUTTONS
#ifdef USE_M5STACK_CORE2
// handle 3 built in touch buttons
uint16_t xcenter = 80;
#define TDELTA 30
#define TYPOS 275
for (uint32_t tbut = 0; tbut < 3; tbut++) {
if (touch_xp > (xcenter - TDELTA) && touch_xp < (xcenter + TDELTA) && touch_yp > (TYPOS - TDELTA) && touch_yp < (TYPOS + TDELTA)) {
// hit a button
if (!(tbstate[tbut] & 1)) {
// pressed
tbstate[tbut] |= 1;
//AddLog(LOG_LEVEL_INFO, PSTR("tbut: %d pressed"), tbut);
Touch_MQTT(tbut, "BIB", tbstate[tbut] & 1);
}
}
xcenter += 100;
}
#endif // USE_M5STACK_CORE2
#endif // USE_TOUCH_BUTTONS
rotconvert(&touch_xp, &touch_yp);
#ifdef USE_TOUCH_BUTTONS
CheckTouchButtons(touched, touch_xp, touch_yp);
#endif // USE_TOUCH_BUTTONS
} else {
#ifdef USE_M5STACK_CORE2
for (uint32_t tbut = 0; tbut < 3; tbut++) {
if (tbstate[tbut] & 1) {
// released
tbstate[tbut] &= 0xfe;
Touch_MQTT(tbut, "BIB", tbstate[tbut] & 1);
//AddLog(LOG_LEVEL_INFO, PSTR("tbut: %d released"), tbut);
}
}
#endif // USE_M5STACK_CORE2
#ifdef USE_TOUCH_BUTTONS
CheckTouchButtons(touched, touch_xp, touch_yp);
#endif // USE_TOUCH_BUTTONS
}
}
#endif
#ifdef USE_TOUCH_BUTTONS #ifdef USE_TOUCH_BUTTONS
void Touch_MQTT(uint8_t index, const char *cp, uint32_t val) { void Touch_MQTT(uint8_t index, const char *cp, uint32_t val) {
#if defined(USE_FT5206) #ifdef USE_FT5206
ResponseTime_P(PSTR(",\"FT5206\":{\"%s%d\":\"%d\"}}"), cp, index+1, val); if (FT5206_found) ResponseTime_P(PSTR(",\"FT5206\":{\"%s%d\":\"%d\"}}"), cp, index+1, val);
#elif defined(USE_XPT2046) #endif
ResponseTime_P(PSTR(",\"XPT2046\":{\"%s%d\":\"%d\"}}"), cp, index+1, val); #ifdef USE_XPT2046
if (XPT2046_found) ResponseTime_P(PSTR(",\"XPT2046\":{\"%s%d\":\"%d\"}}"), cp, index+1, val);
#endif // USE_XPT2046 #endif // USE_XPT2046
MqttPublishTeleSensor(); MqttPublishTeleSensor();
} }
@ -2667,54 +2838,22 @@ void Touch_RDW_BUTT(uint32_t count, uint32_t pwr) {
else buttons[count]->vpower.on_off = 0; else buttons[count]->vpower.on_off = 0;
} }
#ifdef USE_M5STACK_CORE2
uint8_t tbstate[3];
#endif
// check digitizer hit
void Touch_Check(void(*rotconvert)(int16_t *x, int16_t *y)) { void CheckTouchButtons(bool touched, int16_t touch_x, int16_t touch_y) {
uint16_t temp; uint16_t temp;
uint8_t rbutt=0; uint8_t rbutt=0;
uint8_t vbutt=0; uint8_t vbutt=0;
if (touchp->touched()) { if (!renderer) return;
// did find a hit if (touched) {
#if defined(USE_FT5206)
pLoc = touchp->getPoint(0);
#elif defined(USE_XPT2046)
pLoc = touchp->getPoint();
#endif // USE_XPT2046
if (renderer) {
#ifdef USE_M5STACK_CORE2
// handle 3 built in touch buttons
uint16_t xcenter = 80;
#define TDELTA 30
#define TYPOS 275
for (uint32_t tbut = 0; tbut < 3; tbut++) {
if (pLoc.x>(xcenter-TDELTA) && pLoc.x<(xcenter+TDELTA) && pLoc.y>(TYPOS-TDELTA) && pLoc.y<(TYPOS+TDELTA)) {
// hit a button
if (!(tbstate[tbut] & 1)) {
// pressed
tbstate[tbut] |= 1;
//AddLog(LOG_LEVEL_INFO, PSTR("tbut: %d pressed"), tbut);
Touch_MQTT(tbut, "BIB", tbstate[tbut] & 1);
}
}
xcenter += 100;
}
#endif // USE_M5STACK_CORE2
rotconvert(&pLoc.x, &pLoc.y);
// AddLog(LOG_LEVEL_DEBUG_MORE, PSTR("touch after convert %d - %d"), pLoc.x, pLoc.y); // AddLog(LOG_LEVEL_DEBUG_MORE, PSTR("touch after convert %d - %d"), pLoc.x, pLoc.y);
// now must compare with defined buttons // now must compare with defined buttons
for (uint8_t count = 0; count < MAX_TOUCH_BUTTONS; count++) { for (uint8_t count = 0; count < MAX_TOUCH_BUTTONS; count++) {
if (buttons[count]) { if (buttons[count]) {
if (!buttons[count]->vpower.slider) { if (!buttons[count]->vpower.slider) {
if (!buttons[count]->vpower.disable) { if (!buttons[count]->vpower.disable) {
if (buttons[count]->contains(pLoc.x, pLoc.y)) { if (buttons[count]->contains(touch_x, touch_y)) {
// did hit // did hit
buttons[count]->press(true); buttons[count]->press(true);
if (buttons[count]->justPressed()) { if (buttons[count]->justPressed()) {
@ -2749,26 +2888,16 @@ void Touch_Check(void(*rotconvert)(int16_t *x, int16_t *y)) {
} }
} else { } else {
// slider // slider
if (buttons[count]->didhit(pLoc.x, pLoc.y)) { if (buttons[count]->didhit(touch_x, touch_y)) {
uint16_t value = buttons[count]->UpdateSlider(pLoc.x, pLoc.y); uint16_t value = buttons[count]->UpdateSlider(touch_x, touch_y);
Touch_MQTT(count, "SLD", value); Touch_MQTT(count, "SLD", value);
} }
} }
} }
} }
}
} else { } else {
// no hit // no hit
#ifdef USE_M5STACK_CORE2
for (uint32_t tbut = 0; tbut < 3; tbut++) {
if (tbstate[tbut] & 1) {
// released
tbstate[tbut] &= 0xfe;
Touch_MQTT(tbut, "BIB", tbstate[tbut] & 1);
//AddLog(LOG_LEVEL_INFO, PSTR("tbut: %d released"), tbut);
}
}
#endif // USE_M5STACK_CORE2
for (uint8_t count = 0; count < MAX_TOUCH_BUTTONS; count++) { for (uint8_t count = 0; count < MAX_TOUCH_BUTTONS; count++) {
if (buttons[count]) { if (buttons[count]) {
if (!buttons[count]->vpower.slider) { if (!buttons[count]->vpower.slider) {
@ -2795,13 +2924,12 @@ void Touch_Check(void(*rotconvert)(int16_t *x, int16_t *y)) {
} }
} }
} }
pLoc.x = 0; touch_xp = 0;
pLoc.y = 0; touch_yp = 0;
} }
} }
#endif // USE_TOUCH_BUTTONS #endif // USE_TOUCH_BUTTONS
#endif // USE_FT5206 || USE_XPT2046
/*********************************************************************************************\ /*********************************************************************************************\
* Interface * Interface

View File

@ -71,11 +71,6 @@ void SSD1306InitDriver(void) {
Settings.display_height = 64; Settings.display_height = 64;
} }
// allocate screen buffer
if (buffer) { free(buffer); }
buffer = (unsigned char*)calloc((Settings.display_width * Settings.display_height) / 8,1);
if (!buffer) { return; }
// init renderer // init renderer
// oled1306 = new Adafruit_SSD1306(SSD1306_LCDWIDTH,SSD1306_LCDHEIGHT); // oled1306 = new Adafruit_SSD1306(SSD1306_LCDWIDTH,SSD1306_LCDHEIGHT);
oled1306 = new Adafruit_SSD1306(Settings.display_width, Settings.display_height, &Wire, Pin(GPIO_OLED_RESET)); oled1306 = new Adafruit_SSD1306(Settings.display_width, Settings.display_height, &Wire, Pin(GPIO_OLED_RESET));
@ -93,6 +88,7 @@ void SSD1306InitDriver(void) {
renderer->DisplayOnff(1); renderer->DisplayOnff(1);
#endif #endif
AddLog(LOG_LEVEL_INFO, PSTR("DSP: SD1306"));
} }
} }

View File

@ -27,7 +27,6 @@ enum IliModes { ILIMODE_9341 = 1, ILIMODE_9342, ILIMODE_MAX };
#include <ILI9341_2.h> #include <ILI9341_2.h>
extern uint8_t *buffer;
extern uint8_t color_type; extern uint8_t color_type;
ILI9341_2 *ili9341_2; ILI9341_2 *ili9341_2;
@ -62,9 +61,6 @@ void ILI9341_InitDriver()
Settings.display_height = ILI9341_TFTHEIGHT; Settings.display_height = ILI9341_TFTHEIGHT;
} }
// disable screen buffer
buffer = NULL;
if (!Settings.display_options.type || (Settings.display_options.type >= ILIMODE_MAX)) { if (!Settings.display_options.type || (Settings.display_options.type >= ILIMODE_MAX)) {
Settings.display_options.type = ILIMODE_9341; Settings.display_options.type = ILIMODE_9341;
} }
@ -122,12 +118,12 @@ void ILI9341_InitDriver()
#undef SCL_2 #undef SCL_2
#define SCL_2 22 #define SCL_2 22
Wire1.begin(SDA_2, SCL_2, 400000); Wire1.begin(SDA_2, SCL_2, 400000);
Touch_Init(Wire1); FT5206_Touch_Init(Wire1);
#endif // USE_FT5206 #endif // USE_FT5206
#endif // ESP32 #endif // ESP32
#ifdef USE_XPT2046 #ifdef USE_XPT2046
Touch_Init(Pin(GPIO_XPT2046_CS)); XPT2046_Touch_Init(Pin(GPIO_XPT2046_CS));
#endif #endif
tft_init_done = true; tft_init_done = true;
@ -154,8 +150,8 @@ void ili9342_dimm(uint8_t dim) {
#if defined(USE_FT5206) || defined(USE_XPT2046) #if defined(USE_FT5206) || defined(USE_XPT2046)
#ifdef USE_TOUCH_BUTTONS #ifdef USE_TOUCH_BUTTONS
#if defined(USE_FT5206) #ifdef USE_FT5206
void TS_RotConvert(int16_t *x, int16_t *y) { void FT5206_TS_RotConvert(int16_t *x, int16_t *y) {
int16_t temp; int16_t temp;
if (renderer) { if (renderer) {
@ -180,8 +176,10 @@ int16_t temp;
} }
} }
} }
#elif defined(USE_XPT2046) #endif // USE_FT5206
void TS_RotConvert(int16_t *x, int16_t *y) {
#ifdef USE_XPT2046
void XPT2046_TS_RotConvert(int16_t *x, int16_t *y) {
int16_t temp; int16_t temp;
if (renderer) { if (renderer) {
@ -219,7 +217,12 @@ ili9342_ctouch_counter++;
if (2 == ili9342_ctouch_counter) { if (2 == ili9342_ctouch_counter) {
// every 100 ms should be enough // every 100 ms should be enough
ili9342_ctouch_counter = 0; ili9342_ctouch_counter = 0;
Touch_Check(TS_RotConvert); if (FT5206_found) {
Touch_Check(FT5206_TS_RotConvert);
}
if (XPT2046_found) {
Touch_Check(XPT2046_TS_RotConvert);
}
} }
} }
#endif // USE_TOUCH_BUTTONS #endif // USE_TOUCH_BUTTONS

View File

@ -37,7 +37,6 @@
#include <epdpaint.h> #include <epdpaint.h>
//unsigned char image[(EPD_HEIGHT * EPD_WIDTH) / 8]; //unsigned char image[(EPD_HEIGHT * EPD_WIDTH) / 8];
extern uint8_t *buffer;
uint16_t epd_scroll; uint16_t epd_scroll;
bool epd_init_done = false; bool epd_init_done = false;
@ -58,11 +57,6 @@ void EpdInitDriver29(void) {
Settings.display_height = EPD_HEIGHT; Settings.display_height = EPD_HEIGHT;
} }
// allocate screen buffer
if (buffer) free(buffer);
buffer=(unsigned char*)calloc((EPD_WIDTH * EPD_HEIGHT) / 8,1);
if (!buffer) return;
// init renderer // init renderer
epd = new Epd(EPD_WIDTH, EPD_HEIGHT); epd = new Epd(EPD_WIDTH, EPD_HEIGHT);
@ -75,6 +69,7 @@ void EpdInitDriver29(void) {
} }
renderer = epd; renderer = epd;
epd->Init(DISPLAY_INIT_FULL); epd->Init(DISPLAY_INIT_FULL);
epd->Init(DISPLAY_INIT_PARTIAL); epd->Init(DISPLAY_INIT_PARTIAL);
renderer->DisplayInit(DISPLAY_INIT_MODE,Settings.display_size,Settings.display_rotate,Settings.display_font); renderer->DisplayInit(DISPLAY_INIT_MODE,Settings.display_size,Settings.display_rotate,Settings.display_font);

View File

@ -34,7 +34,6 @@
#include <epd4in2.h> #include <epd4in2.h>
#include <epdpaint.h> #include <epdpaint.h>
extern uint8_t *buffer;
bool epd42_init_done = false; bool epd42_init_done = false;
Epd42 *epd42; Epd42 *epd42;
@ -55,11 +54,6 @@ void EpdInitDriver42() {
Settings.display_height = EPD_HEIGHT42; Settings.display_height = EPD_HEIGHT42;
} }
// allocate screen buffer
if (buffer) free(buffer);
buffer=(unsigned char*)calloc((EPD_WIDTH42 * EPD_HEIGHT42) / 8,1);
if (!buffer) return;
// init renderer // init renderer
epd42 = new Epd42(EPD_WIDTH42, EPD_HEIGHT42); epd42 = new Epd42(EPD_WIDTH42, EPD_HEIGHT42);

View File

@ -25,7 +25,6 @@
#define SPRINT(A) char str[32];sprintf(str,"val: %d ",A);Serial.println((char*)str); #define SPRINT(A) char str[32];sprintf(str,"val: %d ",A);Serial.println((char*)str);
extern uint8_t *buffer;
#define XDSP_07 7 #define XDSP_07 7
#define XI2C_06 6 // See I2CDEVICES.md #define XI2C_06 6 // See I2CDEVICES.md
@ -71,15 +70,9 @@ void SH1106InitDriver() {
if (Settings.display_height != SH1106_LCDHEIGHT) { if (Settings.display_height != SH1106_LCDHEIGHT) {
Settings.display_height = SH1106_LCDHEIGHT; Settings.display_height = SH1106_LCDHEIGHT;
} }
// allocate screen buffer
if (buffer) free(buffer);
buffer=(unsigned char*)calloc((SH1106_LCDWIDTH * SH1106_LCDHEIGHT) / 8,1);
if (!buffer) return;
// init renderer // init renderer
oled1106 = new Adafruit_SH1106(SH1106_LCDWIDTH,SH1106_LCDHEIGHT); oled1106 = new Adafruit_SH1106(SH1106_LCDWIDTH,SH1106_LCDHEIGHT);
renderer=oled1106; renderer = oled1106;
renderer->Begin(SH1106_SWITCHCAPVCC, Settings.display_address[0],0); renderer->Begin(SH1106_SWITCHCAPVCC, Settings.display_address[0],0);
renderer->DisplayInit(DISPLAY_INIT_MODE,Settings.display_size,Settings.display_rotate,Settings.display_font); renderer->DisplayInit(DISPLAY_INIT_MODE,Settings.display_size,Settings.display_rotate,Settings.display_font);
renderer->setTextColor(1,0); renderer->setTextColor(1,0);
@ -93,6 +86,8 @@ void SH1106InitDriver() {
renderer->DisplayOnff(1); renderer->DisplayOnff(1);
#endif #endif
} }
AddLog(LOG_LEVEL_INFO, PSTR("DSP: SH1106"));
} }

View File

@ -39,7 +39,6 @@ bool ili9488_init_done = false;
// currently fixed // currently fixed
#define BACKPLANE_PIN 2 #define BACKPLANE_PIN 2
extern uint8_t *buffer;
extern uint8_t color_type; extern uint8_t color_type;
ILI9488 *ili9488; ILI9488 *ili9488;
extern const uint16_t picture[]; extern const uint16_t picture[];
@ -58,9 +57,6 @@ void ILI9488_InitDriver(void) {
Settings.display_height = ILI9488_TFTHEIGHT; Settings.display_height = ILI9488_TFTHEIGHT;
} }
// disable screen buffer
buffer = NULL;
// default colors // default colors
fg_color = ILI9488_WHITE; fg_color = ILI9488_WHITE;
bg_color = ILI9488_BLACK; bg_color = ILI9488_BLACK;
@ -91,7 +87,7 @@ void ILI9488_InitDriver(void) {
color_type = COLOR_COLOR; color_type = COLOR_COLOR;
// start digitizer // start digitizer
#ifdef USE_FT5206 #ifdef USE_FT5206
Touch_Init(Wire); FT5206_Touch_Init(Wire);
#endif #endif
ili9488_init_done = true; ili9488_init_done = true;

View File

@ -34,7 +34,6 @@
#include <SSD1351.h> #include <SSD1351.h>
bool ssd1351_init_done = false; bool ssd1351_init_done = false;
extern uint8_t *buffer;
extern uint8_t color_type; extern uint8_t color_type;
SSD1351 *ssd1351; SSD1351 *ssd1351;
@ -53,8 +52,6 @@ void SSD1351_InitDriver() {
Settings.display_height = SSD1351_HEIGHT; Settings.display_height = SSD1351_HEIGHT;
} }
buffer = 0;
// default colors // default colors
fg_color = SSD1351_WHITE; fg_color = SSD1351_WHITE;
bg_color = SSD1351_BLACK; bg_color = SSD1351_BLACK;

View File

@ -35,7 +35,6 @@
bool ra8876_init_done = false; bool ra8876_init_done = false;
uint8_t ra8876_ctouch_counter = 0; uint8_t ra8876_ctouch_counter = 0;
extern uint8_t *buffer;
extern uint8_t color_type; extern uint8_t color_type;
RA8876 *ra8876; RA8876 *ra8876;
@ -52,8 +51,6 @@ void RA8876_InitDriver(void) {
Settings.display_height = RA8876_TFTHEIGHT; Settings.display_height = RA8876_TFTHEIGHT;
} }
buffer = 0;
// default colors // default colors
fg_color = RA8876_WHITE; fg_color = RA8876_WHITE;
bg_color = RA8876_BLACK; bg_color = RA8876_BLACK;
@ -78,7 +75,7 @@ void RA8876_InitDriver(void) {
color_type = COLOR_COLOR; color_type = COLOR_COLOR;
#ifdef USE_FT5206 #ifdef USE_FT5206
Touch_Init(Wire); FT5206_Touch_Init(Wire);
#endif #endif
ra8876_init_done = true; ra8876_init_done = true;

View File

@ -50,7 +50,6 @@
#define BACKPLANE_PIN 5 #define BACKPLANE_PIN 5
#endif // USE_LANBON_L8 #endif // USE_LANBON_L8
extern uint8_t *buffer;
extern uint8_t color_type; extern uint8_t color_type;
Arduino_ST7789 *st7789; Arduino_ST7789 *st7789;
@ -74,9 +73,6 @@ void ST7789_InitDriver(void) {
Settings.display_height = 240; Settings.display_height = 240;
} }
// disable screen buffer
buffer = NULL;
// default colors // default colors
fg_color = ST7789_WHITE; fg_color = ST7789_WHITE;
bg_color = ST7789_BLACK; bg_color = ST7789_BLACK;
@ -112,6 +108,8 @@ void ST7789_InitDriver(void) {
#ifdef ESP32 #ifdef ESP32
#ifdef USE_FT5206 #ifdef USE_FT5206
// start digitizer with fixed adress and pins for esp32 // start digitizer with fixed adress and pins for esp32
#undef SDA_2
#undef SCL_2
#define SDA_2 23 #define SDA_2 23
#define SCL_2 32 #define SCL_2 32
#ifdef USE_LANBON_L8 #ifdef USE_LANBON_L8
@ -121,7 +119,7 @@ void ST7789_InitDriver(void) {
#define SCL_2 0 #define SCL_2 0
#endif // USE_LANBON_L8 #endif // USE_LANBON_L8
Wire1.begin(SDA_2, SCL_2, 400000); Wire1.begin(SDA_2, SCL_2, 400000);
Touch_Init(Wire1); FT5206_Touch_Init(Wire1);
#endif // USE_FT5206 #endif // USE_FT5206
#endif // ESP32 #endif // ESP32

View File

@ -25,7 +25,6 @@
#include <uDisplay.h> #include <uDisplay.h>
uDisplay *udisp;
bool udisp_init_done = false; bool udisp_init_done = false;
uint8_t ctouch_counter; uint8_t ctouch_counter;
extern uint8_t color_type; extern uint8_t color_type;
@ -41,15 +40,12 @@ extern FS *ffsp;
//#define DSP_ROM_DESC //#define DSP_ROM_DESC
/*********************************************************************************************/ /*********************************************************************************************/
#ifdef DSP_ROM_DESC //#ifdef DSP_ROM_DESC
#if 1
/* sample descriptor */ /* sample descriptor */
const char DSP_SAMPLE_DESC[] PROGMEM = const char DSP_SAMPLE_DESC[] PROGMEM =
// name,xs,ys,bpp,interface, (HEX) address, scl,sda,reset
// '*' means take pin number from tasmota
":H,SH1106,128,64,1,I2C,3c,*,*,*\n" ":H,SH1106,128,64,1,I2C,3c,*,*,*\n"
// splash settings, font, size, fgcol, bgcol, x,y
":S,0,1,1,0,40,20\n" ":S,0,1,1,0,40,20\n"
// init register settings, must be in HEX
":I\n" ":I\n"
"AE\n" "AE\n"
"D5,80\n" "D5,80\n"
@ -67,9 +63,7 @@ const char DSP_SAMPLE_DESC[] PROGMEM =
"A4\n" "A4\n"
"A6\n" "A6\n"
"AF\n" "AF\n"
// switch display off
":o,AE\n" ":o,AE\n"
// switch display on
":O,AF\n" ":O,AF\n"
":A,00,10,40,00,02\n" ":A,00,10,40,00,02\n"
":i,A6,A7\n" ":i,A6,A7\n"
@ -77,21 +71,26 @@ const char DSP_SAMPLE_DESC[] PROGMEM =
#endif // DSP_ROM_DESC #endif // DSP_ROM_DESC
/*********************************************************************************************/ /*********************************************************************************************/
Renderer *Init_uDisplay(const char *desc) {
void Init_uDisp(void) {
char *ddesc = 0; char *ddesc = 0;
char *fbuff; char *fbuff;
uDisplay *udisp;
if (TasmotaGlobal.gpio_optiona.udisplay_driver) { if (TasmotaGlobal.gpio_optiona.udisplay_driver) {
Settings.display_model = XDSP_17; Settings.display_model = XDSP_17;
color_type = COLOR_BW;
fbuff = (char*)calloc(DISPDESC_SIZE, 1); fbuff = (char*)calloc(DISPDESC_SIZE, 1);
if (!fbuff) return; if (!fbuff) return 0;
if (desc) {
memcpy(fbuff, desc, DISPDESC_SIZE - 1);
ddesc = fbuff;
AddLog(LOG_LEVEL_INFO, PSTR("DSP: const char descriptor used"));
}
#ifdef USE_UFILESYS #ifdef USE_UFILESYS
if (ffsp && !TasmotaGlobal.no_autoexec) { if (ffsp && !TasmotaGlobal.no_autoexec && !ddesc) {
File fp; File fp;
fp = ffsp->open("/dispdesc.txt", "r"); fp = ffsp->open("/dispdesc.txt", "r");
if (fp > 0) { if (fp > 0) {
@ -148,24 +147,44 @@ char *fbuff;
if (!ddesc) { if (!ddesc) {
AddLog(LOG_LEVEL_INFO, PSTR("DSP: No valid descriptor found")); AddLog(LOG_LEVEL_INFO, PSTR("DSP: No valid descriptor found"));
if (fbuff) free(fbuff); if (fbuff) free(fbuff);
return; return 0;
} }
// now replace tasmota vars before passing to driver // now replace tasmota vars before passing to driver
char *cp = strstr(ddesc, "I2C,"); char *cp = strstr(ddesc, "I2C");
if (cp) { if (cp) {
cp += 4; cp += 3;
uint8_t wire_n = 1;
if (*cp == '1' || *cp == '2') {
wire_n = *cp & 3;
cp += 2;
} else {
cp++;
}
//,3c,22,21,-1 //,3c,22,21,-1
uint8_t i2caddr = strtol(cp, &cp, 16); uint8_t i2caddr = strtol(cp, &cp, 16);
int8_t scl, sda; int8_t scl, sda;
scl = replacepin(&cp, Pin(GPIO_I2C_SCL)); scl = replacepin(&cp, Pin(GPIO_I2C_SCL, wire_n - 1));
sda = replacepin(&cp, Pin(GPIO_I2C_SDA)); sda = replacepin(&cp, Pin(GPIO_I2C_SDA, wire_n - 1));
replacepin(&cp, Pin(GPIO_OLED_RESET)); replacepin(&cp, Pin(GPIO_OLED_RESET));
Wire.begin(sda, scl); if (wire_n == 1) {
Wire.begin(sda, scl);
}
#ifdef ESP32
if (wire_n == 2) {
Wire1.begin(sda, scl);
}
if (I2cSetDevice(i2caddr, wire_n - 1)) {
I2cSetActiveFound(i2caddr, "DSP-I2C", wire_n - 1);
}
#endif // ESP32
#ifdef ESP8266
if (I2cSetDevice(i2caddr)) { if (I2cSetDevice(i2caddr)) {
I2cSetActiveFound(i2caddr, "DSP-I2C"); I2cSetActiveFound(i2caddr, "DSP-I2C");
} }
#endif // ESP8266
//AddLog(LOG_LEVEL_INFO, PSTR("DSP: i2c %x, %d, %d, %d!"), i2caddr, wire_n, scl, sda);
} }
cp = strstr(ddesc, "SPI,"); cp = strstr(ddesc, "SPI,");
@ -212,7 +231,10 @@ char *fbuff;
*/ */
// init renderer // init renderer
if (udisp) delete udisp; if (renderer) {
delete renderer;
AddLog(LOG_LEVEL_INFO, PSTR("DSP: reinit"));
}
udisp = new uDisplay(ddesc); udisp = new uDisplay(ddesc);
// checck for touch option TI1 or TI2 // checck for touch option TI1 or TI2
@ -226,29 +248,33 @@ char *fbuff;
uint8_t i2caddr = strtol(cp, &cp, 16); uint8_t i2caddr = strtol(cp, &cp, 16);
int8_t scl, sda; int8_t scl, sda;
scl = replacepin(&cp, Pin(GPIO_I2C_SCL, wire_n));
sda = replacepin(&cp, Pin(GPIO_I2C_SDA, wire_n));
if (wire_n == 0) { if (wire_n == 0) {
scl = replacepin(&cp, Pin(GPIO_I2C_SCL));
sda = replacepin(&cp, Pin(GPIO_I2C_SDA));
Wire.begin(sda, scl); Wire.begin(sda, scl);
} }
#ifdef ESP32 #ifdef ESP32
if (wire_n == 1) { if (wire_n == 1) {
scl = replacepin(&cp, Pin(GPIO_I2C_SCL, 1));
sda = replacepin(&cp, Pin(GPIO_I2C_SDA, 1));
Wire1.begin(sda, scl, 400000); Wire1.begin(sda, scl, 400000);
} }
#endif
//AddLog(LOG_LEVEL_INFO, PSTR("DSP: touch %x, %d, %d, %d!"), i2caddr, wire_n, scl, sda);
if (I2cSetDevice(i2caddr, wire_n)) { if (I2cSetDevice(i2caddr, wire_n)) {
I2cSetActiveFound(i2caddr, "FT5206", wire_n); I2cSetActiveFound(i2caddr, "FT5206", wire_n);
} }
#endif // ESP32
#ifdef ESP8266
//AddLog(LOG_LEVEL_INFO, PSTR("DSP: touch %x, %d, %d, %d!"), i2caddr, wire_n, scl, sda);
if (I2cSetDevice(i2caddr)) {
I2cSetActiveFound(i2caddr, "FT5206");
}
#endif // ESP8266
// start digitizer // start digitizer
#ifdef ESP32 #ifdef ESP32
if (!wire_n) Touch_Init(Wire); if (!wire_n) FT5206_Touch_Init(Wire);
else Touch_Init(Wire1); else FT5206_Touch_Init(Wire1);
#else #else
if (!wire_n) Touch_Init(Wire); if (!wire_n) FT5206_Touch_Init(Wire);
#endif #endif
} }
#endif #endif
@ -258,7 +284,7 @@ char *fbuff;
if (cp) { if (cp) {
cp+=4; cp+=4;
uint8_t touch_cs = replacepin(&cp, Pin(GPIO_XPT2046_CS)); uint8_t touch_cs = replacepin(&cp, Pin(GPIO_XPT2046_CS));
Touch_Init(touch_cs); XPT2046_Touch_Init(touch_cs);
} }
#endif #endif
@ -266,12 +292,13 @@ char *fbuff;
if (fbuff) free(fbuff); if (fbuff) free(fbuff);
renderer = udisp->Init(); renderer = udisp->Init();
if (!renderer) return; if (!renderer) return 0;
Settings.display_width = renderer->width(); Settings.display_width = renderer->width();
Settings.display_height = renderer->height(); Settings.display_height = renderer->height();
fg_color = udisp->fgcol(); fg_color = udisp->fgcol();
bg_color = udisp->bgcol(); bg_color = udisp->bgcol();
color_type = udisp->color_type();
renderer->DisplayInit(DISPLAY_INIT_MODE, Settings.display_size, Settings.display_rotate, Settings.display_font); renderer->DisplayInit(DISPLAY_INIT_MODE, Settings.display_size, Settings.display_rotate, Settings.display_font);
renderer->dim(Settings.display_dimmer); renderer->dim(Settings.display_dimmer);
@ -282,10 +309,11 @@ char *fbuff;
udisp_init_done = true; udisp_init_done = true;
AddLog(LOG_LEVEL_INFO, PSTR("DSP: %s!"), udisp->devname()); AddLog(LOG_LEVEL_INFO, PSTR("DSP: %s!"), udisp->devname());
return renderer;
} }
return 0;
} }
/*********************************************************************************************/ /*********************************************************************************************/
@ -305,7 +333,7 @@ void udisp_dimm(uint8_t dim) {
} }
void TS_RotConvert(int16_t *x, int16_t *y) { void TS_RotConvert(int16_t *x, int16_t *y) {
if (udisp) udisp->TS_RotConvert(x, y); if (renderer) renderer->TS_RotConvert(x, y);
} }
#if defined(USE_FT5206) || defined(USE_XPT2046) #if defined(USE_FT5206) || defined(USE_XPT2046)
@ -415,7 +443,7 @@ bool Xdsp17(uint8_t function)
bool result = false; bool result = false;
if (FUNC_DISPLAY_INIT_DRIVER == function) { if (FUNC_DISPLAY_INIT_DRIVER == function) {
Init_uDisp(); Init_uDisplay(0);
} }
else if (udisp_init_done && (XDSP_17 == Settings.display_model)) { else if (udisp_init_done && (XDSP_17 == Settings.display_model)) {
switch (function) { switch (function) {
@ -430,17 +458,11 @@ bool Xdsp17(uint8_t function)
#endif // USE_DISPLAY_MODES1TO5 #endif // USE_DISPLAY_MODES1TO5
#if defined(USE_FT5206) || defined(USE_XPT2046) #if defined(USE_FT5206) || defined(USE_XPT2046)
#ifdef USE_TOUCH_BUTTONS
case FUNC_DISPLAY_EVERY_50_MSECOND: case FUNC_DISPLAY_EVERY_50_MSECOND:
#if defined(USE_FT5206) if (FT5206_found || XPT2046_found) {
if (FT5206_found) {
#elif defined(USE_XPT2046)
if (XPT2046_found) {
#endif
udisp_CheckTouch(); udisp_CheckTouch();
} }
break; break;
#endif // USE_TOUCH_BUTTONS
#endif // USE_FT5206 #endif // USE_FT5206
} }