Skip to content

Commit

Permalink
Add setting to override default SS pin
Browse files Browse the repository at this point in the history
  • Loading branch information
sidoh committed Dec 24, 2020
1 parent 059daa4 commit 7b108c7
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 6 deletions.
4 changes: 2 additions & 2 deletions lib/Display/DisplayTemplateDriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ void DisplayTemplateDriver::init() {
#if defined(ESP32)
if (settings.hardware.spi_bus == VSPI){
SPI.end();
SPI.begin(18, 23, 19, 5);
SPI.begin(18, 23, 19, settings.hardware.getSsPin());
} else if (settings.hardware.spi_bus == HardwareSettings::WAVESHARE_SPI) {
SPI.end();
SPI.begin(13, 12, 14, 15);
SPI.begin(13, 12, 14, settings.hardware.getSsPin());
}
#endif

Expand Down
4 changes: 4 additions & 0 deletions lib/Settings/Settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ void SettingsCallbackObserver::onConfigurationChanged(const ConfigurationPropert
}

const uint8_t HardwareSettings::getSsPin() const {
if (this->ss_pin_override != -1) {
return static_cast<uint8_t>(this->ss_pin_override);
}

switch (this->spi_bus) {
case HSPI:
case WAVESHARE_SPI:
Expand Down
1 change: 1 addition & 0 deletions lib/Settings/Settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ 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);
persistentIntVar(ss_pin_override, -1);

const uint8_t getSsPin() const;
};
Expand Down
18 changes: 15 additions & 3 deletions web/src/settings/schema/hardware.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
const VALID_PINS = [
0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39
];

export default {
key: "hardware",
title: "Hardware",
definitions: {
pin: {
type: "integer",
enum: [
0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39
]
enum: VALID_PINS
}
},
properties: {
Expand Down Expand Up @@ -35,6 +37,16 @@ export default {
],
type: "string",
default: "HSPI"
},
"hardware.ss_pin_override": {
$id: "#/properties/hardware.ss_pin_override",
title: "SPI SS Pin Override",
oneOf: [
{ const: -1, title: "default" },
...VALID_PINS.map(x => ({const: x, title: String(x)}))
],
type: "integer",
default: -1
}
}
};
5 changes: 4 additions & 1 deletion web/src/settings/ui_schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ export default {
"hardware.rst_pin": {
transformer: parseInt
},
"hardware.spi_bus": {
"hardware.ss_pin_override": {
transformer: parseInt,
"ui:help": <>
<div>
SPI bus to use. HSPI uses GPIOs 12, 14, 15. VSPI uses 5, 18, 19. See README for more details.
Expand All @@ -63,6 +64,8 @@ export default {
</div>
</>
},
"hardware.spi_bus": {
},
"web.port": {
transformer: parseInt
},
Expand Down

0 comments on commit 7b108c7

Please sign in to comment.