1
0
mirror of https://github.com/bdring/Grbl_Esp32.git synced 2025-08-31 18:11:48 +02:00

Better error checking for GPIO pins.

Also fixed some missing .c_str()s.
This commit is contained in:
Mitch Bradley
2021-07-01 23:15:25 -10:00
parent 39fda6a642
commit 06d5d7b51e

View File

@@ -112,8 +112,10 @@ namespace Pins {
// User defined pin capabilities // User defined pin capabilities
for (auto opt : options) { for (auto opt : options) {
if (opt.is("pu")) { if (opt.is("pu")) {
Assert(_capabilities.has(PinCapabilities::PullUp), "Pin %s does not support :pu", toString().c_str());
_attributes = _attributes | PinAttributes::PullUp; _attributes = _attributes | PinAttributes::PullUp;
} else if (opt.is("pd")) { } else if (opt.is("pd")) {
Assert(_capabilities.has(PinCapabilities::PullDown), "Pin %s does not support :pd", toString().c_str());
_attributes = _attributes | PinAttributes::PullDown; _attributes = _attributes | PinAttributes::PullDown;
} else if (opt.is("low")) { } else if (opt.is("low")) {
_attributes = _attributes | PinAttributes::ActiveLow; _attributes = _attributes | PinAttributes::ActiveLow;
@@ -137,7 +139,7 @@ namespace Pins {
if (!_attributes.has(PinAttributes::Output)) { if (!_attributes.has(PinAttributes::Output)) {
log_error(toString()); log_error(toString());
} }
Assert(_attributes.has(PinAttributes::Output), "Pin %s cannot be written", toString()); Assert(_attributes.has(PinAttributes::Output), "Pin %s cannot be written", toString().c_str());
int value = _readWriteMask ^ high; int value = _readWriteMask ^ high;
__digitalWrite(_index, value); __digitalWrite(_index, value);
} }
@@ -154,10 +156,10 @@ namespace Pins {
// Check the attributes first: // Check the attributes first:
Assert(value.validateWith(this->_capabilities) || _index == 1 || _index == 3, Assert(value.validateWith(this->_capabilities) || _index == 1 || _index == 3,
"The requested attributes don't match the capabilities for %s", "The requested attributes don't match the capabilities for %s",
toString()); toString().c_str());
Assert(!_attributes.conflictsWith(value) || _index == 1 || _index == 3, Assert(!_attributes.conflictsWith(value) || _index == 1 || _index == 3,
"The requested attributes on %s conflict with previous settings", "The requested attributes on %s conflict with previous settings",
toString()); toString().c_str());
_attributes = _attributes | value; _attributes = _attributes | value;
@@ -186,7 +188,7 @@ namespace Pins {
} }
void GPIOPinDetail::attachInterrupt(void (*callback)(void*), void* arg, int mode) { void GPIOPinDetail::attachInterrupt(void (*callback)(void*), void* arg, int mode) {
Assert(_attributes.has(PinAttributes::ISR), "Pin %s does not support interrupts", toString()); Assert(_attributes.has(PinAttributes::ISR), "Pin %s does not support interrupts", toString().c_str());
::attachInterruptArg(_index, callback, arg, mode); ::attachInterruptArg(_index, callback, arg, mode);
} }