From f0d2feb901ba975418380636a22b058b4b8fbf41 Mon Sep 17 00:00:00 2001 From: Mitch Bradley Date: Fri, 28 May 2021 09:20:07 -1000 Subject: [PATCH] Report attributes in pin names --- Grbl_Esp32/src/Pins/DebugPinDetail.h | 2 +- Grbl_Esp32/src/Pins/ErrorPinDetail.cpp | 2 +- Grbl_Esp32/src/Pins/ErrorPinDetail.h | 2 +- Grbl_Esp32/src/Pins/GPIOPinDetail.cpp | 29 +++++++++++++++----------- Grbl_Esp32/src/Pins/GPIOPinDetail.h | 2 +- Grbl_Esp32/src/Pins/I2SOPinDetail.cpp | 22 +++++++++---------- Grbl_Esp32/src/Pins/I2SOPinDetail.h | 2 +- Grbl_Esp32/src/Pins/PinDetail.h | 2 +- Grbl_Esp32/src/Pins/VoidPinDetail.cpp | 2 +- Grbl_Esp32/src/Pins/VoidPinDetail.h | 2 +- 10 files changed, 35 insertions(+), 32 deletions(-) diff --git a/Grbl_Esp32/src/Pins/DebugPinDetail.h b/Grbl_Esp32/src/Pins/DebugPinDetail.h index ac75ccbc..049c235e 100644 --- a/Grbl_Esp32/src/Pins/DebugPinDetail.h +++ b/Grbl_Esp32/src/Pins/DebugPinDetail.h @@ -57,7 +57,7 @@ namespace Pins { void attachInterrupt(void (*callback)(void*), void* arg, int mode) override; void detachInterrupt() override; - String toString() const override { return _implementation->toString(); } + String toString() override { return _implementation->toString(); } ~DebugPinDetail() override {} }; diff --git a/Grbl_Esp32/src/Pins/ErrorPinDetail.cpp b/Grbl_Esp32/src/Pins/ErrorPinDetail.cpp index 8952aba9..c065af56 100644 --- a/Grbl_Esp32/src/Pins/ErrorPinDetail.cpp +++ b/Grbl_Esp32/src/Pins/ErrorPinDetail.cpp @@ -30,5 +30,5 @@ namespace Pins { } PinAttributes ErrorPinDetail::getAttr() const { return PinAttributes::None; } - String ErrorPinDetail::toString() const { return "ERROR_PIN"; } + String ErrorPinDetail::toString() { return "ERROR_PIN"; } } diff --git a/Grbl_Esp32/src/Pins/ErrorPinDetail.h b/Grbl_Esp32/src/Pins/ErrorPinDetail.h index fc24808e..204fa068 100644 --- a/Grbl_Esp32/src/Pins/ErrorPinDetail.h +++ b/Grbl_Esp32/src/Pins/ErrorPinDetail.h @@ -34,7 +34,7 @@ namespace Pins { void setAttr(PinAttributes value) override; PinAttributes getAttr() const override; - String toString() const override; + String toString() override; ~ErrorPinDetail() override {} }; diff --git a/Grbl_Esp32/src/Pins/GPIOPinDetail.cpp b/Grbl_Esp32/src/Pins/GPIOPinDetail.cpp index 70df61a4..a0ef067a 100644 --- a/Grbl_Esp32/src/Pins/GPIOPinDetail.cpp +++ b/Grbl_Esp32/src/Pins/GPIOPinDetail.cpp @@ -119,12 +119,8 @@ namespace Pins { } } - // Update the R/W mask for ActiveLow setting - if (_attributes.has(PinAttributes::ActiveLow)) { - _readWriteMask = HIGH; - } else { - _readWriteMask = LOW; - } + // readWriteMask is xor'ed with the value to invert it if active low + _readWriteMask = _attributes.has(PinAttributes::ActiveLow); } PinAttributes GPIOPinDetail::getAttr() const { return _attributes; } @@ -172,11 +168,7 @@ namespace Pins { // If the pin is ActiveLow, we should take that into account here: if (value.has(PinAttributes::Output)) { - if (value.has(PinAttributes::InitialOn)) { - __digitalWrite(_index, HIGH ^ _readWriteMask); - } else { - __digitalWrite(_index, LOW ^ _readWriteMask); - } + __digitalWrite(_index, value.has(PinAttributes::InitialOn) ^ _readWriteMask); } __pinMode(_index, pinModeValue); @@ -194,5 +186,18 @@ namespace Pins { ::detachInterrupt(_index); } - String GPIOPinDetail::toString() const { return String("GPIO.") + int(_index); } + String GPIOPinDetail::toString() { + auto s = String("gpio.") + int(_index); + if (_attributes.has(PinAttributes::ActiveLow)) { + s += ":low"; + } + if (_attributes.has(PinAttributes::PullUp)) { + s += ":pu"; + } + if (_attributes.has(PinAttributes::PullDown)) { + s += ":pd"; + } + + return s; + } } diff --git a/Grbl_Esp32/src/Pins/GPIOPinDetail.h b/Grbl_Esp32/src/Pins/GPIOPinDetail.h index f8a51362..bbbd15a5 100644 --- a/Grbl_Esp32/src/Pins/GPIOPinDetail.h +++ b/Grbl_Esp32/src/Pins/GPIOPinDetail.h @@ -43,7 +43,7 @@ namespace Pins { void attachInterrupt(void (*callback)(void*), void* arg, int mode) override; void detachInterrupt() override; - String toString() const override; + String toString() override; ~GPIOPinDetail() override {} }; diff --git a/Grbl_Esp32/src/Pins/I2SOPinDetail.cpp b/Grbl_Esp32/src/Pins/I2SOPinDetail.cpp index a56bdc92..9a7cff7f 100644 --- a/Grbl_Esp32/src/Pins/I2SOPinDetail.cpp +++ b/Grbl_Esp32/src/Pins/I2SOPinDetail.cpp @@ -39,12 +39,8 @@ namespace Pins { } } - // Update the R/W mask for ActiveLow setting - if (_attributes.has(PinAttributes::ActiveLow)) { - _readWriteMask = HIGH; - } else { - _readWriteMask = LOW; - } + // readWriteMask is xor'ed with the value to invert it if active low + _readWriteMask = _attributes.has(PinAttributes::ActiveLow); } PinCapabilities I2SOPinDetail::capabilities() const { return PinCapabilities::Output | PinCapabilities::I2S; } @@ -72,16 +68,18 @@ namespace Pins { // just check for conflicts above... // If the pin is ActiveLow, we should take that into account here: - if (value.has(PinAttributes::InitialOn)) { - i2s_out_write(_index, HIGH ^ _readWriteMask); - } else { - i2s_out_write(_index, LOW ^ _readWriteMask); - } + i2s_out_write(_index, value.has(PinAttributes::InitialOn) ^ _readWriteMask); } PinAttributes I2SOPinDetail::getAttr() const { return _attributes; } - String I2SOPinDetail::toString() const { return String("I2SO.") + int(_index); } + String I2SOPinDetail::toString() { + auto s = String("I2SO.") + int(_index); + if (_attributes.has(PinAttributes::ActiveLow)) { + s += ":low"; + } + return s; + } } #endif diff --git a/Grbl_Esp32/src/Pins/I2SOPinDetail.h b/Grbl_Esp32/src/Pins/I2SOPinDetail.h index 7618e257..a48dfd70 100644 --- a/Grbl_Esp32/src/Pins/I2SOPinDetail.h +++ b/Grbl_Esp32/src/Pins/I2SOPinDetail.h @@ -38,7 +38,7 @@ namespace Pins { void setAttr(PinAttributes value) override; PinAttributes getAttr() const override; - String toString() const override; + String toString() override; ~I2SOPinDetail() override {} }; diff --git a/Grbl_Esp32/src/Pins/PinDetail.h b/Grbl_Esp32/src/Pins/PinDetail.h index dab711b8..3f09f7f2 100644 --- a/Grbl_Esp32/src/Pins/PinDetail.h +++ b/Grbl_Esp32/src/Pins/PinDetail.h @@ -52,7 +52,7 @@ namespace Pins { virtual void attachInterrupt(void (*callback)(void*), void* arg, int mode); virtual void detachInterrupt(); - virtual String toString() const = 0; + virtual String toString() = 0; inline int number() const { return _index; } diff --git a/Grbl_Esp32/src/Pins/VoidPinDetail.cpp b/Grbl_Esp32/src/Pins/VoidPinDetail.cpp index e1cb0365..35b03532 100644 --- a/Grbl_Esp32/src/Pins/VoidPinDetail.cpp +++ b/Grbl_Esp32/src/Pins/VoidPinDetail.cpp @@ -32,6 +32,6 @@ namespace Pins { void VoidPinDetail::setAttr(PinAttributes value) {} PinAttributes VoidPinDetail::getAttr() const { return PinAttributes::None; } - String VoidPinDetail::toString() const { return ""; } + String VoidPinDetail::toString() { return ""; } } diff --git a/Grbl_Esp32/src/Pins/VoidPinDetail.h b/Grbl_Esp32/src/Pins/VoidPinDetail.h index 81abf435..29004280 100644 --- a/Grbl_Esp32/src/Pins/VoidPinDetail.h +++ b/Grbl_Esp32/src/Pins/VoidPinDetail.h @@ -35,7 +35,7 @@ namespace Pins { void setAttr(PinAttributes value) override; PinAttributes getAttr() const override; - String toString() const override; + String toString() override; ~VoidPinDetail() override {} };