diff --git a/Grbl_Esp32/Grbl_Esp32.ino b/Grbl_Esp32/Grbl_Esp32.ino index b3133b51..120be530 100644 --- a/Grbl_Esp32/Grbl_Esp32.ino +++ b/Grbl_Esp32/Grbl_Esp32.ino @@ -22,6 +22,10 @@ # include "src/Grbl.h" void setup() { +# ifdef PIN_DEBUG + sleep(1000); +# endif + Serial.begin(115200); grbl_init(); } diff --git a/Grbl_Esp32/src/Machines/test_drive.h b/Grbl_Esp32/src/Machines/test_drive.h index 6618a992..ec81c4f4 100644 --- a/Grbl_Esp32/src/Machines/test_drive.h +++ b/Grbl_Esp32/src/Machines/test_drive.h @@ -55,10 +55,18 @@ // Output devices: // - I2S +// #define USE_I2S_OUT +// #define USE_I2S_STEPS +// #define I2S_OUT_BCK GPIO_NUM_22 +// #define I2S_OUT_WS GPIO_NUM_17 +// #define I2S_OUT_DATA GPIO_NUM_21 +// +// #define COOLANT_MIST_PIN "i2s.24" + // x CoolantControl -// #define COOLANT_MIST_PIN "gpio.2" // labeled Mist -// #define COOLANT_FLOOD_PIN "gpio.4" // labeled Flood +// #define COOLANT_MIST_PIN "gpio.2" +// #define COOLANT_FLOOD_PIN "gpio.4" // x StandardStepper diff --git a/Grbl_Esp32/src/Pin.cpp b/Grbl_Esp32/src/Pin.cpp index d94a2417..1d64677d 100644 --- a/Grbl_Esp32/src/Pin.cpp +++ b/Grbl_Esp32/src/Pin.cpp @@ -76,6 +76,10 @@ bool Pin::parse(String str, Pins::PinDetail*& pinImplementation) { // Build an options parser: Pins::PinOptionsParser parser(options.begin(), options.end()); +#if defined PIN_DEBUG && defined ESP32 + grbl_sendf(CLIENT_ALL, "Attempting to set up pin: %s, index %d\r\n", prefix.c_str(), int(pinNumber)); +#endif + // Build this pin: if (prefix == "gpio") { pinImplementation = new Pins::GPIOPinDetail(uint8_t(pinNumber), parser); diff --git a/Grbl_Esp32/src/Pins/GPIOPinDetail.cpp b/Grbl_Esp32/src/Pins/GPIOPinDetail.cpp index bac52684..c9e6b752 100644 --- a/Grbl_Esp32/src/Pins/GPIOPinDetail.cpp +++ b/Grbl_Esp32/src/Pins/GPIOPinDetail.cpp @@ -97,7 +97,7 @@ namespace Pins { } else if (opt.is("high")) { // Default: Active HIGH. } else { - Assert(false, "Bad GPIO option passed to pin: %s", opt()); + Assert(false, "Bad GPIO option passed to pin %d: %s", int(index), opt()); } } diff --git a/Grbl_Esp32/src/Pins/I2SPinDetail.cpp b/Grbl_Esp32/src/Pins/I2SPinDetail.cpp index 367e2207..d49be91e 100644 --- a/Grbl_Esp32/src/Pins/I2SPinDetail.cpp +++ b/Grbl_Esp32/src/Pins/I2SPinDetail.cpp @@ -12,28 +12,27 @@ namespace Pins { _readWriteMask(0) { // User defined pin capabilities for (auto opt : options) { - if (opt.is("pu")) { - _attributes = _attributes | PinAttributes::PullUp; - } else if (opt.is("pd")) { - _attributes = _attributes | PinAttributes::PullDown; - } else if (opt.is("low")) { + if (opt.is("low")) { _attributes = _attributes | PinAttributes::ActiveLow; } else if (opt.is("high")) { // Default: Active HIGH. + } else { + Assert(false, "Bad I2S option passed to pin %d: %s", int(index), opt()); } } // Update the R/W mask for ActiveLow setting if (_attributes.has(PinAttributes::ActiveLow)) { - _readWriteMask = 1; + _readWriteMask = HIGH; } else { - _readWriteMask = 0; + _readWriteMask = LOW; } } - PinCapabilities I2SPinDetail::capabilities() const { return PinCapabilities::Input | PinCapabilities::Output | PinCapabilities::I2S; } + PinCapabilities I2SPinDetail::capabilities() const { return PinCapabilities::Output | PinCapabilities::I2S; } void I2SPinDetail::write(int high) { + Assert(_attributes.has(PinAttributes::Output), "Pin has no output attribute defined. Cannot write to it."); int value = _readWriteMask ^ high; i2s_out_write(_index, value); } @@ -45,7 +44,7 @@ namespace Pins { void I2SPinDetail::setAttr(PinAttributes value) { // Check the attributes first: - Assert(!value.validateWith(this->_capabilities), "The requested attributes don't match the pin capabilities"); + Assert(value.validateWith(this->_capabilities), "The requested attributes don't match the pin capabilities"); Assert(!_attributes.conflictsWith(value), "Attributes on this pin have been set before, and there's a conflict."); _attributes = value; @@ -55,10 +54,14 @@ namespace Pins { // just check for conflicts above... // If the pin is ActiveLow, we should take that into account here: - write(value.has(PinAttributes::InitialOn) ? HIGH : LOW); + if (value.has(PinAttributes::InitialOn)) { + i2s_out_write(_index, HIGH ^ _readWriteMask); + } else { + i2s_out_write(_index, LOW ^ _readWriteMask); + } } - String I2SPinDetail::toString() const { return String("I2S_") + int(_index); } + String I2SPinDetail::toString() const { return String("I2S.") + int(_index); } } #endif diff --git a/Grbl_Esp32/src/Pins/I2SPinDetail.h b/Grbl_Esp32/src/Pins/I2SPinDetail.h index 82d96992..a84cd0c4 100644 --- a/Grbl_Esp32/src/Pins/I2SPinDetail.h +++ b/Grbl_Esp32/src/Pins/I2SPinDetail.h @@ -5,7 +5,6 @@ namespace Pins { class I2SPinDetail : public PinDetail { - uint8_t _index; PinCapabilities _capabilities; PinAttributes _attributes; int _readWriteMask; diff --git a/Grbl_Esp32/src/ProcessSettings.cpp b/Grbl_Esp32/src/ProcessSettings.cpp index 098abbea..82943204 100644 --- a/Grbl_Esp32/src/ProcessSettings.cpp +++ b/Grbl_Esp32/src/ProcessSettings.cpp @@ -150,9 +150,9 @@ Error list_grbl_names(const char* value, WebUI::AuthenticationLevel auth_level, Error list_settings(const char* value, WebUI::AuthenticationLevel auth_level, WebUI::ESPResponseStream* out) { for (Setting* s = Setting::List; s; s = s->next()) { const char* displayValue = auth_failed(s, value, auth_level) ? "" : s->getStringValue(); - if (s->getType() != PIN) { - show_setting(s->getName(), displayValue, NULL, out); - } + if (s->getType() != PIN) { + show_setting(s->getName(), displayValue, NULL, out); + } } return Error::Ok; }