mirror of
https://github.com/bdring/Grbl_Esp32.git
synced 2025-09-03 11:22:38 +02:00
Fixed a few bugs with ISR binding. Basically you should never call attachInterrupt
without an ISR setMode; the pin might not support it after all.
This commit is contained in:
@@ -77,10 +77,11 @@ void grbl_init() {
|
|||||||
WebUI::inputBuffer.begin();
|
WebUI::inputBuffer.begin();
|
||||||
} catch (const AssertionFailed& ex) {
|
} catch (const AssertionFailed& ex) {
|
||||||
// This means something is terribly broken:
|
// This means something is terribly broken:
|
||||||
grbl_sendf(CLIENT_ALL, "Critical error in run_once: %s", ex.stackTrace.c_str());
|
|
||||||
while (true) {
|
// Should grbl_sendf always work? Serial is initialized first, so after line 34 it should.
|
||||||
sleep(1000);
|
grbl_msg_sendf(CLIENT_ALL, MsgLevel::Error, "Critical error in run_once: %s", ex.stackTrace.c_str());
|
||||||
}
|
sleep(10000);
|
||||||
|
throw;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -127,10 +128,9 @@ void run_once() {
|
|||||||
protocol_main_loop();
|
protocol_main_loop();
|
||||||
} catch (const AssertionFailed& ex) {
|
} catch (const AssertionFailed& ex) {
|
||||||
// This means something is terribly broken:
|
// This means something is terribly broken:
|
||||||
grbl_sendf(CLIENT_ALL, "Critical error in run_once: %s", ex.stackTrace.c_str());
|
grbl_msg_sendf(CLIENT_ALL, MsgLevel::Error, "Critical error in run_once: %s", ex.stackTrace.c_str());
|
||||||
while (true) {
|
sleep(10000);
|
||||||
sleep(1000);
|
throw;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -309,10 +309,11 @@ uint8_t limit_mask = 0;
|
|||||||
|
|
||||||
void limits_init() {
|
void limits_init() {
|
||||||
limit_mask = 0;
|
limit_mask = 0;
|
||||||
Pin::Attr mode = Pin::Attr::Input | Pin::Attr::PullUp;
|
Pin::Attr mode = Pin::Attr::Input | Pin::Attr::PullUp | Pin::Attr::ISR;
|
||||||
#ifdef DISABLE_LIMIT_PIN_PULL_UP
|
#ifdef DISABLE_LIMIT_PIN_PULL_UP
|
||||||
mode = Pin::Attr::Input;
|
mode = Pin::Attr::Input | Pin::Attr::ISR;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
auto n_axis = number_axis->get();
|
auto n_axis = number_axis->get();
|
||||||
for (int axis = 0; axis < n_axis; axis++) {
|
for (int axis = 0; axis < n_axis; axis++) {
|
||||||
for (int gang_index = 0; gang_index < 2; gang_index++) {
|
for (int gang_index = 0; gang_index < 2; gang_index++) {
|
||||||
|
@@ -177,7 +177,6 @@ const char* USER_ANALOG_PIN_2_DEFAULT = USER_ANALOG_PIN_2;
|
|||||||
#endif
|
#endif
|
||||||
const char* USER_ANALOG_PIN_3_DEFAULT = USER_ANALOG_PIN_3;
|
const char* USER_ANALOG_PIN_3_DEFAULT = USER_ANALOG_PIN_3;
|
||||||
|
|
||||||
|
|
||||||
#ifndef SPINDLE_OUTPUT_PIN
|
#ifndef SPINDLE_OUTPUT_PIN
|
||||||
# define SPINDLE_OUTPUT_PIN UNDEFINED_PIN
|
# define SPINDLE_OUTPUT_PIN UNDEFINED_PIN
|
||||||
#endif
|
#endif
|
||||||
|
@@ -143,6 +143,12 @@ namespace Pins {
|
|||||||
pinModeValue |= OUTPUT;
|
pinModeValue |= OUTPUT;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO FIXME: For now, I added PU capabilities to 'value' as well. This *should* be removed once the
|
||||||
|
// code that uses #define's to decide this is gone.
|
||||||
|
if (value.has(PinAttributes::PullUp)) {
|
||||||
|
pinModeValue |= PULLUP;
|
||||||
|
}
|
||||||
|
|
||||||
// PU/PD should be specified by the user. Code has nothing to do with them:
|
// PU/PD should be specified by the user. Code has nothing to do with them:
|
||||||
if (_attributes.has(PinAttributes::PullUp)) {
|
if (_attributes.has(PinAttributes::PullUp)) {
|
||||||
pinModeValue |= PULLUP;
|
pinModeValue |= PULLUP;
|
||||||
@@ -161,12 +167,14 @@ namespace Pins {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void GPIOPinDetail::attachInterrupt(void (*callback)(void*), void* arg, int mode) {
|
void GPIOPinDetail::attachInterrupt(void (*callback)(void*), void* arg, int mode) {
|
||||||
Assert(_capabilities.has(PinCapabilities::ISR), "Pin has no ISR capability defined. Cannot bind ISR.");
|
Assert(_attributes.has(PinAttributes::ISR),
|
||||||
|
"Pin has no ISR attribute, which means 'setAttr' was not set, or the pin doesn't support ISR's. Cannot bind ISR.");
|
||||||
::attachInterruptArg(_index, callback, arg, mode);
|
::attachInterruptArg(_index, callback, arg, mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GPIOPinDetail::detachInterrupt() {
|
void GPIOPinDetail::detachInterrupt() {
|
||||||
Assert(_capabilities.has(PinCapabilities::ISR), "Pin has no ISR capability defined. Cannot unbind ISR.");
|
Assert(_attributes.has(PinAttributes::ISR),
|
||||||
|
"Pin has no ISR attribute, which means 'setAttr' was not set, or the pin doesn't support ISR's. Cannot unbind ISR.");
|
||||||
::detachInterrupt(_index);
|
::detachInterrupt(_index);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -48,42 +48,42 @@ void system_ini() { // Renamed from system_init() due to conflict with esp32 fi
|
|||||||
// setup control inputs
|
// setup control inputs
|
||||||
|
|
||||||
if (ControlSafetyDoorPin->get() != Pin::UNDEFINED) {
|
if (ControlSafetyDoorPin->get() != Pin::UNDEFINED) {
|
||||||
ControlSafetyDoorPin->get().setAttr(Pin::Attr::Input | Pin::Attr::PullUp);
|
ControlSafetyDoorPin->get().setAttr(Pin::Attr::Input | Pin::Attr::PullUp | Pin::Attr::ISR);
|
||||||
ControlSafetyDoorPin->get().attachInterrupt(isr_control_inputs, CHANGE);
|
ControlSafetyDoorPin->get().attachInterrupt(isr_control_inputs, CHANGE);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ControlResetPin->get() != Pin::UNDEFINED) {
|
if (ControlResetPin->get() != Pin::UNDEFINED) {
|
||||||
ControlResetPin->get().setAttr(Pin::Attr::Input | Pin::Attr::PullUp);
|
ControlResetPin->get().setAttr(Pin::Attr::Input | Pin::Attr::PullUp | Pin::Attr::ISR);
|
||||||
ControlResetPin->get().attachInterrupt(isr_control_inputs, CHANGE);
|
ControlResetPin->get().attachInterrupt(isr_control_inputs, CHANGE);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ControlFeedHoldPin->get() != Pin::UNDEFINED) {
|
if (ControlFeedHoldPin->get() != Pin::UNDEFINED) {
|
||||||
ControlFeedHoldPin->get().setAttr(Pin::Attr::Input | Pin::Attr::PullUp);
|
ControlFeedHoldPin->get().setAttr(Pin::Attr::Input | Pin::Attr::PullUp | Pin::Attr::ISR);
|
||||||
ControlFeedHoldPin->get().attachInterrupt(isr_control_inputs, CHANGE);
|
ControlFeedHoldPin->get().attachInterrupt(isr_control_inputs, CHANGE);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ControlCycleStartPin->get() != Pin::UNDEFINED) {
|
if (ControlCycleStartPin->get() != Pin::UNDEFINED) {
|
||||||
ControlCycleStartPin->get().setAttr(Pin::Attr::Input | Pin::Attr::PullUp);
|
ControlCycleStartPin->get().setAttr(Pin::Attr::Input | Pin::Attr::PullUp | Pin::Attr::ISR);
|
||||||
ControlCycleStartPin->get().attachInterrupt(isr_control_inputs, CHANGE);
|
ControlCycleStartPin->get().attachInterrupt(isr_control_inputs, CHANGE);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (MacroButton0Pin->get() != Pin::UNDEFINED) {
|
if (MacroButton0Pin->get() != Pin::UNDEFINED) {
|
||||||
MacroButton0Pin->get().setAttr(Pin::Attr::Input | Pin::Attr::PullUp);
|
MacroButton0Pin->get().setAttr(Pin::Attr::Input | Pin::Attr::PullUp | Pin::Attr::ISR);
|
||||||
MacroButton0Pin->get().attachInterrupt(isr_control_inputs, CHANGE);
|
MacroButton0Pin->get().attachInterrupt(isr_control_inputs, CHANGE);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (MacroButton1Pin->get() != Pin::UNDEFINED) {
|
if (MacroButton1Pin->get() != Pin::UNDEFINED) {
|
||||||
MacroButton1Pin->get().setAttr(Pin::Attr::Input | Pin::Attr::PullUp);
|
MacroButton1Pin->get().setAttr(Pin::Attr::Input | Pin::Attr::PullUp | Pin::Attr::ISR);
|
||||||
MacroButton1Pin->get().attachInterrupt(isr_control_inputs, CHANGE);
|
MacroButton1Pin->get().attachInterrupt(isr_control_inputs, CHANGE);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (MacroButton2Pin->get() != Pin::UNDEFINED) {
|
if (MacroButton2Pin->get() != Pin::UNDEFINED) {
|
||||||
MacroButton2Pin->get().setAttr(Pin::Attr::Input | Pin::Attr::PullUp);
|
MacroButton2Pin->get().setAttr(Pin::Attr::Input | Pin::Attr::PullUp | Pin::Attr::ISR);
|
||||||
MacroButton2Pin->get().attachInterrupt(isr_control_inputs, CHANGE);
|
MacroButton2Pin->get().attachInterrupt(isr_control_inputs, CHANGE);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (MacroButton3Pin->get() != Pin::UNDEFINED) {
|
if (MacroButton3Pin->get() != Pin::UNDEFINED) {
|
||||||
MacroButton3Pin->get().setAttr(Pin::Attr::Input | Pin::Attr::PullUp);
|
MacroButton3Pin->get().setAttr(Pin::Attr::Input | Pin::Attr::PullUp | Pin::Attr::ISR);
|
||||||
MacroButton3Pin->get().attachInterrupt(isr_control_inputs, CHANGE);
|
MacroButton3Pin->get().attachInterrupt(isr_control_inputs, CHANGE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user