add udisp

This commit is contained in:
gemu2015 2021-04-21 11:10:59 +02:00
parent 95a29d7e61
commit 3b4ce6053c
4 changed files with 44 additions and 24 deletions

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;