Skip to content

Commit

Permalink
Merge pull request #60 from sidoh/feature/waveshare_driver_spi_setting
Browse files Browse the repository at this point in the history
Add setting to use custom Waveshare ESP32 driver pins
  • Loading branch information
sidoh authored Dec 23, 2020
2 parents 60b3b49 + e77a11e commit 74ebd29
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 37 deletions.
11 changes: 11 additions & 0 deletions lib/Display/DisplayTemplateDriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,17 @@ DisplayTemplateDriver::DisplayTemplateDriver(
void DisplayTemplateDriver::init() {
display->init(115200);
display->mirror(false);

#if defined(ESP32)
if (settings.hardware.spi_bus == VSPI){
SPI.end();
SPI.begin(18, 23, 19, 5);
} else if (settings.hardware.spi_bus == HardwareSettings::WAVESHARE_SPI) {
SPI.end();
SPI.begin(13, 12, 14, 15);
}
#endif

vars.load();
}

Expand Down
54 changes: 27 additions & 27 deletions lib/Display/DisplayTypeHelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
#include <utility>

template <class Display>
inline static GxEPD2_GFX* __gxepd2_build_bw_driver(const uint8_t dc, const uint8_t rst, const uint8_t busy) {
inline static GxEPD2_GFX* __gxepd2_build_bw_driver(const uint8_t dc, const uint8_t rst, const uint8_t busy, const uint8_t ssPin) {
return new GxEPD2_BW<Display, Display::HEIGHT>(Display(SS, dc, rst, busy));
}

template <class Display>
inline static GxEPD2_GFX* __gxepd2_build_3c_driver(const uint8_t dc, const uint8_t rst, const uint8_t busy) {
inline static GxEPD2_GFX* __gxepd2_build_3c_driver(const uint8_t dc, const uint8_t rst, const uint8_t busy, const uint8_t ssPin) {
return new GxEPD2_3C<Display, Display::HEIGHT>(Display(SS, dc, rst, busy));
}

Expand Down Expand Up @@ -162,59 +162,59 @@ bool DisplayTypeHelpers::is3Color(GxEPD2::Panel type) {
}
}

GxEPD2_GFX* DisplayTypeHelpers::buildDisplay(GxEPD2::Panel type, uint8_t dc, uint8_t rst, uint8_t busy) {
GxEPD2_GFX* DisplayTypeHelpers::buildDisplay(GxEPD2::Panel type, uint8_t dc, uint8_t rst, uint8_t busy, uint8_t ss) {
switch (type) {
// black/white displays
case GxEPD2::Panel::GDEP015OC1:
return __gxepd2_build_bw_driver<GxEPD2_154>(dc, rst, busy);
return __gxepd2_build_bw_driver<GxEPD2_154>(dc, rst, busy, ss);
case GxEPD2::Panel::GDE0213B1:
return __gxepd2_build_bw_driver<GxEPD2_213>(dc, rst, busy);
return __gxepd2_build_bw_driver<GxEPD2_213>(dc, rst, busy, ss);
case GxEPD2::Panel::GDEH0213B72:
return __gxepd2_build_bw_driver<GxEPD2_213_B72>(dc, rst, busy);
return __gxepd2_build_bw_driver<GxEPD2_213_B72>(dc, rst, busy, ss);
case GxEPD2::Panel::GDEW0213I5F:
return __gxepd2_build_bw_driver<GxEPD2_213_flex>(dc, rst, busy);
return __gxepd2_build_bw_driver<GxEPD2_213_flex>(dc, rst, busy, ss);
case GxEPD2::Panel::GDEH029A1:
return __gxepd2_build_bw_driver<GxEPD2_290>(dc, rst, busy);
return __gxepd2_build_bw_driver<GxEPD2_290>(dc, rst, busy, ss);
case GxEPD2::Panel::GDEW029T5:
return __gxepd2_build_bw_driver<GxEPD2_290_T5>(dc, rst, busy);
return __gxepd2_build_bw_driver<GxEPD2_290_T5>(dc, rst, busy, ss);
case GxEPD2::Panel::GDEW027W3:
return __gxepd2_build_bw_driver<GxEPD2_270>(dc, rst, busy);
return __gxepd2_build_bw_driver<GxEPD2_270>(dc, rst, busy, ss);
case GxEPD2::Panel::GDEW042T2:
return __gxepd2_build_bw_driver<GxEPD2_420>(dc, rst, busy);
return __gxepd2_build_bw_driver<GxEPD2_420>(dc, rst, busy, ss);
case GxEPD2::Panel::GDEW0583T7:
return __gxepd2_build_bw_driver<GxEPD2_583>(dc, rst, busy);
return __gxepd2_build_bw_driver<GxEPD2_583>(dc, rst, busy, ss);
case GxEPD2::Panel::GDEW075T8:
return __gxepd2_build_bw_driver<GxEPD2_750>(dc, rst, busy);
return __gxepd2_build_bw_driver<GxEPD2_750>(dc, rst, busy, ss);
case GxEPD2::Panel::GDEH0213B73:
return __gxepd2_build_bw_driver<GxEPD2_213_B73>(dc, rst, busy);
return __gxepd2_build_bw_driver<GxEPD2_213_B73>(dc, rst, busy, ss);
case GxEPD2::Panel::GDEW026T0:
return __gxepd2_build_bw_driver<GxEPD2_260>(dc, rst, busy);
return __gxepd2_build_bw_driver<GxEPD2_260>(dc, rst, busy, ss);
case GxEPD2::Panel::GDEW0371W7:
return __gxepd2_build_bw_driver<GxEPD2_371>(dc, rst, busy);
return __gxepd2_build_bw_driver<GxEPD2_371>(dc, rst, busy, ss);
case GxEPD2::Panel::GDEW075T7:
return __gxepd2_build_bw_driver<GxEPD2_750_T7>(dc, rst, busy);
return __gxepd2_build_bw_driver<GxEPD2_750_T7>(dc, rst, busy, ss);

// Color displays
case GxEPD2::Panel::ED060SCT:
return __gxepd2_build_3c_driver<GxEPD2_it60>(dc, rst, busy);
return __gxepd2_build_3c_driver<GxEPD2_it60>(dc, rst, busy, ss);
case GxEPD2::Panel::GDEW0154Z04:
return __gxepd2_build_3c_driver<GxEPD2_154c>(dc, rst, busy);
return __gxepd2_build_3c_driver<GxEPD2_154c>(dc, rst, busy, ss);
case GxEPD2::Panel::GDEW0213Z16:
return __gxepd2_build_3c_driver<GxEPD2_213c>(dc, rst, busy);
return __gxepd2_build_3c_driver<GxEPD2_213c>(dc, rst, busy, ss);
case GxEPD2::Panel::GDEW029Z10:
return __gxepd2_build_3c_driver<GxEPD2_290c>(dc, rst, busy);
return __gxepd2_build_3c_driver<GxEPD2_290c>(dc, rst, busy, ss);
case GxEPD2::Panel::GDEW027C44:
return __gxepd2_build_3c_driver<GxEPD2_270c>(dc, rst, busy);
return __gxepd2_build_3c_driver<GxEPD2_270c>(dc, rst, busy, ss);
case GxEPD2::Panel::GDEW042Z15:
return __gxepd2_build_3c_driver<GxEPD2_420c>(dc, rst, busy);
return __gxepd2_build_3c_driver<GxEPD2_420c>(dc, rst, busy, ss);
case GxEPD2::Panel::GDEW0583Z21:
return __gxepd2_build_3c_driver<GxEPD2_583c>(dc, rst, busy);
return __gxepd2_build_3c_driver<GxEPD2_583c>(dc, rst, busy, ss);
case GxEPD2::Panel::GDEW075Z09:
return __gxepd2_build_3c_driver<GxEPD2_750c>(dc, rst, busy);
return __gxepd2_build_3c_driver<GxEPD2_750c>(dc, rst, busy, ss);
case GxEPD2::Panel::GDEW075Z08:
return __gxepd2_build_3c_driver<GxEPD2_750c_Z08>(dc, rst, busy);
return __gxepd2_build_3c_driver<GxEPD2_750c_Z08>(dc, rst, busy, ss);
default:
Serial.printf_P(PSTR("Unsupported display type, using default. Provided display: %d\n"), static_cast<size_t>(type));
return buildDisplay(DisplayTypeHelpers::DEFAULT_PANEL, dc, rst, busy);
return buildDisplay(DisplayTypeHelpers::DEFAULT_PANEL, dc, rst, busy, ss);
}
}
2 changes: 1 addition & 1 deletion lib/Display/DisplayTypeHelpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class DisplayTypeHelpers {
static GxEPD2::Panel stringToDisplayType(const String& displayType);
static bool is3Color(GxEPD2::Panel type);

static GxEPD2_GFX* buildDisplay(GxEPD2::Panel type, uint8_t dcPin, uint8_t rstPin, uint8_t busyPin);
static GxEPD2_GFX* buildDisplay(GxEPD2::Panel type, uint8_t dcPin, uint8_t rstPin, uint8_t busyPin, uint8_t ssPin);

static const GxEPD2::Panel DEFAULT_PANEL;
static const char* DISPLAY_NAMES[];
Expand Down
11 changes: 11 additions & 0 deletions lib/Settings/Settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,15 @@ void SettingsCallbackObserver::onConfigurationChanged(const ConfigurationPropert
if (this->callback) {
this->callback(value);
}
}

const uint8_t HardwareSettings::getSsPin() const {
switch (this->spi_bus) {
case HSPI:
case WAVESHARE_SPI:
return 15;
case VSPI:
default:
return 5;
}
}
9 changes: 9 additions & 0 deletions lib/Settings/Settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,20 +79,27 @@ class WebSettings : public Configuration {

class HardwareSettings : public Configuration {
public:
static const uint8_t WAVESHARE_SPI = VSPI + HSPI;
static const uint8_t WAVESHARE_SS_PIN = 15;

persistentVar(
uint8_t,
spi_bus,
EPD_DEFAULT_SPI_BUS,
{
if (spi_busString.equalsIgnoreCase("vspi")) {
spi_bus = VSPI;
} else if (spi_busString.equalsIgnoreCase("waveshare")) {
spi_bus = WAVESHARE_SPI;
} else {
spi_bus = HSPI;
}
},
{
if (spi_bus == VSPI) {
spi_busString = "VSPI";
} else if (spi_bus == WAVESHARE_SPI) {
spi_busString = "waveshare";
} else {
spi_busString = "HSPI";
}
Expand All @@ -101,6 +108,8 @@ class HardwareSettings : public Configuration {
persistentIntVar(dc_pin, EPD_DEFAULT_DC_PIN);
persistentIntVar(rst_pin, EPD_DEFAULT_RST_PIN);
persistentIntVar(busy_pin, EPD_DEFAULT_BUSY_PIN);

const uint8_t getSsPin() const;
};

class NetworkSettings : public Configuration {
Expand Down
10 changes: 2 additions & 8 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,6 @@ void cancelSleep() {
}

void initDisplay() {
#if defined(ESP32)
if (settings.hardware.spi_bus == VSPI){
SPI.end();
SPI.begin(18, 23, 19, 5);
}
#endif

if (display) {
delete display;
display = NULL;
Expand All @@ -88,7 +81,8 @@ void initDisplay() {
display = DisplayTypeHelpers::buildDisplay(settings.display.display_type,
settings.hardware.dc_pin,
settings.hardware.rst_pin,
settings.hardware.busy_pin);
settings.hardware.busy_pin,
settings.hardware.getSsPin());

if (driver != NULL) {
delete driver;
Expand Down
3 changes: 2 additions & 1 deletion web/src/settings/schema/hardware.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ export default {
title: "SPI Bus",
oneOf: [
{ const: "HSPI", title: "HSPI (default)" },
{ const: "VSPI", title: "VSPI" }
{ const: "VSPI", title: "VSPI" },
{ const: "waveshare", title: "Waveshare ESP32 Driver (custom)" },
],
type: "string",
default: "HSPI"
Expand Down

0 comments on commit 74ebd29

Please sign in to comment.