1
0
mirror of https://github.com/bdring/Grbl_Esp32.git synced 2025-09-02 19:02:35 +02:00

Changed ISR registration in ControlPin to class member registration.

This commit is contained in:
Stefan de Bruijn
2021-05-25 11:07:31 +02:00
parent 0de9f12c3a
commit 6eac36c66f
2 changed files with 11 additions and 13 deletions

View File

@@ -8,15 +8,12 @@
void IRAM_ATTR ControlPin::handleISR() { void IRAM_ATTR ControlPin::handleISR() {
bool pinState = _pin.read(); bool pinState = _pin.read();
_value = pinState; _value = pinState;
if (_rtVariable) { if (_rtVariable) {
*_rtVariable = pinState; *_rtVariable = pinState;
} }
} }
void /* IRAM_ATTR */ ControlPin::handle_control_pin(void* arg) {
((ControlPin*)arg)->handleISR();
}
void ControlPin::init() { void ControlPin::init() {
if (_pin.defined()) { if (_pin.defined()) {
grbl_msg_sendf(CLIENT_SERIAL, MsgLevel::Info, "%s switch on pin %s", _legend, _pin.name()); grbl_msg_sendf(CLIENT_SERIAL, MsgLevel::Info, "%s switch on pin %s", _legend, _pin.name());
@@ -25,6 +22,6 @@ void ControlPin::init() {
attr = attr | Pin::Attr::PullUp; attr = attr | Pin::Attr::PullUp;
} }
_pin.setAttr(attr); _pin.setAttr(attr);
_pin.attachInterrupt(ControlPin::handle_control_pin, CHANGE, (void*)this); _pin.attachInterrupt<ControlPin, &ControlPin::handleISR>(this, CHANGE);
} }
} }

View File

@@ -6,19 +6,20 @@ class ControlPin {
private: private:
// invertBitNum refers to a bit in INVERT_CONTROL_PIN_MASK. It is a // invertBitNum refers to a bit in INVERT_CONTROL_PIN_MASK. It is a
// short-term hack to reduce the extent of the patch. // short-term hack to reduce the extent of the patch.
bool _invertBitNum; bool _invertBitNum;
bool _value; bool _value;
const char _letter; const char _letter;
volatile bool* _rtVariable; volatile bool* _rtVariable;
const char* _legend; const char* _legend;
void IRAM_ATTR handleISR();
static void /* IRAM_ATTR */ handle_control_pin(void* arg); void IRAM_ATTR handleISR();
public: public:
ControlPin(uint8_t bitNum, volatile bool* rtVariable, const char* legend, char letter) : ControlPin(uint8_t bitNum, volatile bool* rtVariable, const char* legend, char letter) :
_invertBitNum(bitNum), _value(false), _letter(letter), _rtVariable(rtVariable), _legend(legend) {} _invertBitNum(bitNum), _value(false), _letter(letter), _rtVariable(rtVariable), _legend(legend) {}
Pin _pin; Pin _pin;
bool get() { return _value; } bool get() { return _value; }
const char* legend() { return _legend; } const char* legend() { return _legend; }
// char invertBitNum() { return _invertBitNum; } // char invertBitNum() { return _invertBitNum; }