mirror of
https://github.com/letscontrolit/ESPEasy.git
synced 2026-07-28 04:07:47 +00:00
[P096] Enable support for configurable SPI bus
This commit is contained in:
@@ -16,7 +16,7 @@
|
||||
#include "Adafruit_GFX.h"
|
||||
#include "LOLIN_EPD.h"
|
||||
|
||||
LOLIN_EPD::LOLIN_EPD(int width, int height, int8_t spi_mosi, int8_t spi_clock, int8_t DC, int8_t RST, int8_t CS, int8_t BUSY):Adafruit_GFX(width, height)
|
||||
LOLIN_EPD::LOLIN_EPD(int width, int height, int8_t spi_mosi, int8_t spi_clock, int8_t DC, int8_t RST, int8_t CS, int8_t BUSY, SPIClass& spi):Adafruit_GFX(width, height)
|
||||
{
|
||||
cs = CS;
|
||||
rst = RST;
|
||||
@@ -26,9 +26,10 @@ LOLIN_EPD::LOLIN_EPD(int width, int height, int8_t spi_mosi, int8_t spi_clock, i
|
||||
busy = BUSY;
|
||||
hwSPI = false;
|
||||
singleByteTxns = false;
|
||||
_spi = spi;
|
||||
}
|
||||
|
||||
LOLIN_EPD::LOLIN_EPD(int width, int height, int8_t DC, int8_t RST, int8_t CS, int8_t BUSY):Adafruit_GFX(width, height)
|
||||
LOLIN_EPD::LOLIN_EPD(int width, int height, int8_t DC, int8_t RST, int8_t CS, int8_t BUSY, SPIClass& spi):Adafruit_GFX(width, height)
|
||||
{
|
||||
|
||||
dc = DC;
|
||||
@@ -37,6 +38,7 @@ LOLIN_EPD::LOLIN_EPD(int width, int height, int8_t DC, int8_t RST, int8_t CS, in
|
||||
busy = BUSY;
|
||||
hwSPI = true;
|
||||
singleByteTxns = false;
|
||||
_spi = spi;
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
@@ -90,9 +92,9 @@ void LOLIN_EPD::begin(bool reset)
|
||||
}
|
||||
else
|
||||
{
|
||||
SPI.begin();
|
||||
// _spi.begin(); // Already done by ESPEasy
|
||||
#ifndef SPI_HAS_TRANSACTION
|
||||
SPI.setClockDivider(4);
|
||||
_spi.setClockDivider(4);
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -194,12 +196,12 @@ uint8_t LOLIN_EPD::fastSPIwrite(uint8_t d)
|
||||
{
|
||||
uint8_t b;
|
||||
csLow();
|
||||
b = SPI.transfer(d);
|
||||
b = _spi.transfer(d);
|
||||
csHigh();
|
||||
return b;
|
||||
}
|
||||
else
|
||||
return SPI.transfer(d);
|
||||
return _spi.transfer(d);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -234,7 +236,7 @@ uint8_t LOLIN_EPD::fastSPIwrite(uint8_t d)
|
||||
void LOLIN_EPD::csHigh()
|
||||
{
|
||||
#ifdef SPI_HAS_TRANSACTION
|
||||
SPI.endTransaction();
|
||||
_spi.endTransaction();
|
||||
#endif
|
||||
#ifdef HAVE_PORTREG
|
||||
*csport |= cspinmask;
|
||||
@@ -251,7 +253,7 @@ void LOLIN_EPD::csHigh()
|
||||
void LOLIN_EPD::csLow()
|
||||
{
|
||||
#ifdef SPI_HAS_TRANSACTION
|
||||
SPI.beginTransaction(SPISettings(4000000, MSBFIRST, SPI_MODE0));
|
||||
_spi.beginTransaction(SPISettings(4000000, MSBFIRST, SPI_MODE0));
|
||||
#endif
|
||||
#ifdef HAVE_PORTREG
|
||||
*csport &= ~cspinmask;
|
||||
|
||||
@@ -60,8 +60,8 @@ enum
|
||||
class LOLIN_EPD: public Adafruit_GFX
|
||||
{
|
||||
public:
|
||||
LOLIN_EPD(int width, int height, int8_t SID, int8_t SCLK, int8_t DC, int8_t RST, int8_t CS, int8_t BUSY = -1);
|
||||
LOLIN_EPD(int width, int height, int8_t DC, int8_t RST, int8_t CS, int8_t BUSY = -1);
|
||||
LOLIN_EPD(int width, int height, int8_t SID, int8_t SCLK, int8_t DC, int8_t RST, int8_t CS, int8_t BUSY = -1, SPIClass& spi = SPI);
|
||||
LOLIN_EPD(int width, int height, int8_t DC, int8_t RST, int8_t CS, int8_t BUSY = -1, SPIClass& spi = SPI);
|
||||
|
||||
virtual ~LOLIN_EPD();
|
||||
virtual void begin(bool reset = true);
|
||||
@@ -111,6 +111,7 @@ protected:
|
||||
void dcLow();
|
||||
|
||||
private:
|
||||
SPIClass& _spi = SPI;
|
||||
};
|
||||
|
||||
#include "LOLIN_IL3897.h"
|
||||
|
||||
@@ -184,7 +184,7 @@ const unsigned char LUT_DATA_part[] PROGMEM = {
|
||||
@param BUSY the busy pin to use
|
||||
*/
|
||||
/**************************************************************************/
|
||||
LOLIN_IL3897::LOLIN_IL3897(int width, int height, int8_t SID, int8_t SCLK, int8_t DC, int8_t RST, int8_t CS, int8_t BUSY) : LOLIN_EPD(width, height, SID, SCLK, DC, RST, CS, BUSY)
|
||||
LOLIN_IL3897::LOLIN_IL3897(int width, int height, int8_t SID, int8_t SCLK, int8_t DC, int8_t RST, int8_t CS, int8_t BUSY, SPIClass& spi) : LOLIN_EPD(width, height, SID, SCLK, DC, RST, CS, BUSY, spi)
|
||||
{
|
||||
|
||||
if ((height % 8) > 0)
|
||||
@@ -202,7 +202,7 @@ LOLIN_IL3897::LOLIN_IL3897(int width, int height, int8_t SID, int8_t SCLK, int8_
|
||||
red_bufsize = bw_bufsize;
|
||||
}
|
||||
|
||||
LOLIN_IL3897::LOLIN_IL3897(int width, int height, int8_t DC, int8_t RST, int8_t CS, int8_t BUSY) : LOLIN_EPD(width, height, DC, RST, CS, BUSY)
|
||||
LOLIN_IL3897::LOLIN_IL3897(int width, int height, int8_t DC, int8_t RST, int8_t CS, int8_t BUSY, SPIClass& spi) : LOLIN_EPD(width, height, DC, RST, CS, BUSY, spi)
|
||||
{
|
||||
|
||||
if ((height % 8) > 0)
|
||||
|
||||
@@ -20,8 +20,8 @@
|
||||
class LOLIN_IL3897 : public LOLIN_EPD {
|
||||
public:
|
||||
|
||||
LOLIN_IL3897(int width, int height, int8_t SID, int8_t SCLK, int8_t DC, int8_t RST, int8_t CS, int8_t BUSY = -1);
|
||||
LOLIN_IL3897(int width, int height, int8_t DC, int8_t RST, int8_t CS, int8_t BUSY = -1);
|
||||
LOLIN_IL3897(int width, int height, int8_t SID, int8_t SCLK, int8_t DC, int8_t RST, int8_t CS, int8_t BUSY = -1, SPIClass& spi = SPI);
|
||||
LOLIN_IL3897(int width, int height, int8_t DC, int8_t RST, int8_t CS, int8_t BUSY = -1, SPIClass& spi = SPI);
|
||||
|
||||
void begin(bool reset=true);
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
@param BUSY the busy pin to use
|
||||
*/
|
||||
/**************************************************************************/
|
||||
LOLIN_SSD1680::LOLIN_SSD1680(int width, int height, int8_t SID, int8_t SCLK, int8_t DC, int8_t RST, int8_t CS, int8_t BUSY) : LOLIN_EPD(width, height, SID, SCLK, DC, RST, CS, BUSY)
|
||||
LOLIN_SSD1680::LOLIN_SSD1680(int width, int height, int8_t SID, int8_t SCLK, int8_t DC, int8_t RST, int8_t CS, int8_t BUSY, SPIClass& spi) : LOLIN_EPD(width, height, SID, SCLK, DC, RST, CS, BUSY, spi)
|
||||
{
|
||||
|
||||
if ((height % 8) > 0)
|
||||
@@ -39,7 +39,7 @@ LOLIN_SSD1680::LOLIN_SSD1680(int width, int height, int8_t SID, int8_t SCLK, int
|
||||
red_bufsize = bw_bufsize;
|
||||
}
|
||||
|
||||
LOLIN_SSD1680::LOLIN_SSD1680(int width, int height, int8_t DC, int8_t RST, int8_t CS, int8_t BUSY) : LOLIN_EPD(width, height, DC, RST, CS, BUSY)
|
||||
LOLIN_SSD1680::LOLIN_SSD1680(int width, int height, int8_t DC, int8_t RST, int8_t CS, int8_t BUSY, SPIClass& spi) : LOLIN_EPD(width, height, DC, RST, CS, BUSY, spi)
|
||||
{
|
||||
|
||||
if ((height % 8) > 0)
|
||||
|
||||
@@ -19,8 +19,8 @@
|
||||
class LOLIN_SSD1680 : public LOLIN_EPD
|
||||
{
|
||||
public:
|
||||
LOLIN_SSD1680(int width, int height, int8_t SID, int8_t SCLK, int8_t DC, int8_t RST, int8_t CS, int8_t BUSY = -1);
|
||||
LOLIN_SSD1680(int width, int height, int8_t DC, int8_t RST, int8_t CS, int8_t BUSY = -1);
|
||||
LOLIN_SSD1680(int width, int height, int8_t SID, int8_t SCLK, int8_t DC, int8_t RST, int8_t CS, int8_t BUSY = -1, SPIClass& spi = SPI);
|
||||
LOLIN_SSD1680(int width, int height, int8_t DC, int8_t RST, int8_t CS, int8_t BUSY = -1, SPIClass& spi = SPI);
|
||||
|
||||
void begin(bool reset = true);
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
@param BUSY the busy pin to use
|
||||
*/
|
||||
/**************************************************************************/
|
||||
LOLIN_UC8151D::LOLIN_UC8151D(int width, int height, int8_t SID, int8_t SCLK, int8_t DC, int8_t RST, int8_t CS, int8_t BUSY) : LOLIN_EPD(width, height, SID, SCLK, DC, RST, CS, BUSY)
|
||||
LOLIN_UC8151D::LOLIN_UC8151D(int width, int height, int8_t SID, int8_t SCLK, int8_t DC, int8_t RST, int8_t CS, int8_t BUSY, SPIClass& spi) : LOLIN_EPD(width, height, SID, SCLK, DC, RST, CS, BUSY, spi)
|
||||
{
|
||||
|
||||
if ((height % 8) > 0)
|
||||
@@ -39,7 +39,7 @@ LOLIN_UC8151D::LOLIN_UC8151D(int width, int height, int8_t SID, int8_t SCLK, int
|
||||
red_bufsize = bw_bufsize;
|
||||
}
|
||||
|
||||
LOLIN_UC8151D::LOLIN_UC8151D(int width, int height, int8_t DC, int8_t RST, int8_t CS, int8_t BUSY) : LOLIN_EPD(width, height, DC, RST, CS, BUSY)
|
||||
LOLIN_UC8151D::LOLIN_UC8151D(int width, int height, int8_t DC, int8_t RST, int8_t CS, int8_t BUSY, SPIClass& spi) : LOLIN_EPD(width, height, DC, RST, CS, BUSY, spi)
|
||||
{
|
||||
|
||||
if ((height % 8) > 0)
|
||||
|
||||
@@ -19,8 +19,8 @@
|
||||
class LOLIN_UC8151D : public LOLIN_EPD
|
||||
{
|
||||
public:
|
||||
LOLIN_UC8151D(int width, int height, int8_t SID, int8_t SCLK, int8_t DC, int8_t RST, int8_t CS, int8_t BUSY = -1);
|
||||
LOLIN_UC8151D(int width, int height, int8_t DC, int8_t RST, int8_t CS, int8_t BUSY = -1);
|
||||
LOLIN_UC8151D(int width, int height, int8_t SID, int8_t SCLK, int8_t DC, int8_t RST, int8_t CS, int8_t BUSY = -1, SPIClass& spi = SPI);
|
||||
LOLIN_UC8151D(int width, int height, int8_t DC, int8_t RST, int8_t CS, int8_t BUSY = -1, SPIClass& spi = SPI);
|
||||
|
||||
void begin(bool reset = true);
|
||||
|
||||
|
||||
@@ -76,8 +76,8 @@ static const unsigned char EPD_2in7_gray_lut_bb[] = {
|
||||
@param BUSY the busy pin to use
|
||||
*/
|
||||
|
||||
Waveshare_2in7::Waveshare_2in7(int width, int height, int8_t DC, int8_t RST, int8_t CS, int8_t BUSY)
|
||||
: LOLIN_EPD(width, height, DC, RST, CS, BUSY) {
|
||||
Waveshare_2in7::Waveshare_2in7(int width, int height, int8_t DC, int8_t RST, int8_t CS, int8_t BUSY, SPIClass& spi)
|
||||
: LOLIN_EPD(width, height, DC, RST, CS, BUSY, spi) {
|
||||
if ((height % 8) > 0) {
|
||||
_height_8bit = (height / 8 + 1) * 8;
|
||||
} else {
|
||||
@@ -247,7 +247,7 @@ void Waveshare_2in7::drawPixel(int16_t x, int16_t y, uint16_t color) {
|
||||
if ((x < 0) || (x >= width()) || (y < 0) || (y >= height())) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// Corrections by @kretzp (Peter Kretz) 2022-03-27
|
||||
// check rotation, move pixel around if necessary
|
||||
switch (getRotation()) {
|
||||
|
||||
@@ -24,10 +24,10 @@
|
||||
#define WS2IN7_DATA_STOP 0x11
|
||||
#define WS2IN7_DISPLAY_REFRESH 0x12
|
||||
#define WS2IN7_DATA_START_TRANSMISSION_2 0x13
|
||||
#define WS2IN7_PARTIAL_DATA_START_TRANSMISSION_1 0x14
|
||||
#define WS2IN7_PARTIAL_DATA_START_TRANSMISSION_2 0x15
|
||||
#define WS2IN7_PARTIAL_DATA_START_TRANSMISSION_1 0x14
|
||||
#define WS2IN7_PARTIAL_DATA_START_TRANSMISSION_2 0x15
|
||||
#define WS2IN7_PARTIAL_DISPLAY_REFRESH 0x16
|
||||
#define WS2IN7_LUT_FOR_VCOM 0x20
|
||||
#define WS2IN7_LUT_FOR_VCOM 0x20
|
||||
#define WS2IN7_LUT_WHITE_TO_WHITE 0x21
|
||||
#define WS2IN7_LUT_BLACK_TO_WHITE 0x22
|
||||
#define WS2IN7_LUT_WHITE_TO_BLACK 0x23
|
||||
@@ -67,12 +67,13 @@ extern const unsigned char lut_wb[];
|
||||
class Waveshare_2in7 : public LOLIN_EPD {
|
||||
public:
|
||||
|
||||
Waveshare_2in7(int width,
|
||||
int height,
|
||||
int8_t DC,
|
||||
int8_t RST,
|
||||
int8_t CS,
|
||||
int8_t BUSY = -1);
|
||||
Waveshare_2in7(int width,
|
||||
int height,
|
||||
int8_t DC,
|
||||
int8_t RST,
|
||||
int8_t CS,
|
||||
int8_t BUSY = -1,
|
||||
SPIClass& spi = SPI);
|
||||
|
||||
void begin(bool reset = true);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user