Firmware2/Marlin/src/HAL/SAMD51/endstop_interrupts.h

209 lines
6.5 KiB
C
Raw Normal View History

2019-07-28 21:48:29 +02:00
/**
* Marlin 3D Printer Firmware
*
2020-02-03 15:00:57 +01:00
* Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
2019-07-28 21:48:29 +02:00
* SAMD51 HAL developed by Giuliano Zaro (AKA GMagician)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
2020-07-23 05:20:14 +02:00
* along with this program. If not, see <https://www.gnu.org/licenses/>.
2019-07-28 21:48:29 +02:00
*
*/
#pragma once
/**
* Endstop interrupts for ATMEL SAMD51 based targets.
*
* On SAMD51, all pins support external interrupt capability.
* Any pin can be used for external interrupts, but there are some restrictions.
* At most 16 different external interrupts can be used at one time.
* Further, you cant just pick any 16 pins to use. This is because every pin on the SAMD51
2019-07-30 02:46:22 +02:00
* connects to what is called an EXTINT line, and only one pin per EXTINT line can be used for external
2019-07-28 21:48:29 +02:00
* interrupts at a time
*/
/**
* Endstop Interrupts
*
* Without endstop interrupts the endstop pins must be polled continually in
* the temperature-ISR via endstops.update(), most of the time finding no change.
* With this feature endstops.update() is called only when we know that at
* least one endstop has changed state, saving valuable CPU cycles.
*
* This feature only works when all used endstop pins can generate an 'external interrupt'.
*
* Test whether pins issue interrupts on your board by flashing 'pin_interrupt_test.ino'.
* (Located in Marlin/buildroot/share/pin_interrupt_test/pin_interrupt_test.ino)
*/
#include "../../module/endstops.h"
#define MATCH_EILINE(P1,P2) (P1 != P2 && PIN_TO_EILINE(P1) == PIN_TO_EILINE(P2))
#if HAS_X_MAX
#define MATCH_X_MAX_EILINE(P) MATCH_EILINE(P, X_MAX_PIN)
#else
#define MATCH_X_MAX_EILINE(P) false
#endif
#if HAS_X_MIN
#define MATCH_X_MIN_EILINE(P) MATCH_EILINE(P, X_MIN_PIN)
#else
#define MATCH_X_MIN_EILINE(P) false
#endif
#if HAS_Y_MAX
#define MATCH_Y_MAX_EILINE(P) MATCH_EILINE(P, Y_MAX_PIN)
#else
#define MATCH_Y_MAX_EILINE(P) false
#endif
#if HAS_Y_MIN
#define MATCH_Y_MIN_EILINE(P) MATCH_EILINE(P, Y_MIN_PIN)
#else
#define MATCH_Y_MIN_EILINE(P) false
#endif
#if HAS_Z_MAX
#define MATCH_Z_MAX_EILINE(P) MATCH_EILINE(P, Z_MAX_PIN)
#else
#define MATCH_Z_MAX_EILINE(P) false
#endif
#if HAS_Z_MIN
#define MATCH_Z_MIN_EILINE(P) MATCH_EILINE(P, Z_MIN_PIN)
#else
#define MATCH_Z_MIN_EILINE(P) false
#endif
#if HAS_Z2_MAX
#define MATCH_Z2_MAX_EILINE(P) MATCH_EILINE(P, Z2_MAX_PIN)
#else
#define MATCH_Z2_MAX_EILINE(P) false
#endif
#if HAS_Z2_MIN
#define MATCH_Z2_MIN_EILINE(P) MATCH_EILINE(P, Z2_MIN_PIN)
#else
#define MATCH_Z2_MIN_EILINE(P) false
#endif
#if HAS_Z3_MAX
#define MATCH_Z3_MAX_EILINE(P) MATCH_EILINE(P, Z3_MAX_PIN)
#else
#define MATCH_Z3_MAX_EILINE(P) false
#endif
#if HAS_Z3_MIN
#define MATCH_Z3_MIN_EILINE(P) MATCH_EILINE(P, Z3_MIN_PIN)
#else
#define MATCH_Z3_MIN_EILINE(P) false
#endif
2020-01-20 06:35:07 +01:00
#if HAS_Z4_MAX
#define MATCH_Z4_MAX_EILINE(P) MATCH_EILINE(P, Z4_MAX_PIN)
#else
#define MATCH_Z4_MAX_EILINE(P) false
#endif
#if HAS_Z4_MIN
#define MATCH_Z4_MIN_EILINE(P) MATCH_EILINE(P, Z4_MIN_PIN)
#else
#define MATCH_Z4_MIN_EILINE(P) false
#endif
2019-07-28 21:48:29 +02:00
#if HAS_Z_MIN_PROBE_PIN
#define MATCH_Z_MIN_PROBE_EILINE(P) MATCH_EILINE(P, Z_MIN_PROBE_PIN)
#else
#define MATCH_Z_MIN_PROBE_EILINE(P) false
#endif
#define AVAILABLE_EILINE(P) (PIN_TO_EILINE(P) != -1 \
&& !MATCH_X_MAX_EILINE(P) && !MATCH_X_MIN_EILINE(P) \
&& !MATCH_Y_MAX_EILINE(P) && !MATCH_Y_MIN_EILINE(P) \
&& !MATCH_Z_MAX_EILINE(P) && !MATCH_Z_MIN_EILINE(P) \
&& !MATCH_Z2_MAX_EILINE(P) && !MATCH_Z2_MIN_EILINE(P) \
&& !MATCH_Z3_MAX_EILINE(P) && !MATCH_Z3_MIN_EILINE(P) \
2020-01-20 06:35:07 +01:00
&& !MATCH_Z4_MAX_EILINE(P) && !MATCH_Z4_MIN_EILINE(P) \
2019-07-28 21:48:29 +02:00
&& !MATCH_Z_MIN_PROBE_EILINE(P))
// One ISR for all EXT-Interrupts
2019-09-17 03:31:08 +02:00
void endstop_ISR() { endstops.update(); }
2019-07-28 21:48:29 +02:00
2019-09-17 03:31:08 +02:00
void setup_endstop_interrupts() {
#define _ATTACH(P) attachInterrupt(P, endstop_ISR, CHANGE)
2019-07-28 21:48:29 +02:00
#if HAS_X_MAX
#if !AVAILABLE_EILINE(X_MAX_PIN)
2020-01-20 06:35:07 +01:00
#error "X_MAX_PIN has no EXTINT line available."
2019-07-28 21:48:29 +02:00
#endif
_ATTACH(X_MAX_PIN);
2019-07-28 21:48:29 +02:00
#endif
#if HAS_X_MIN
#if !AVAILABLE_EILINE(X_MIN_PIN)
2020-01-20 06:35:07 +01:00
#error "X_MIN_PIN has no EXTINT line available."
2019-07-28 21:48:29 +02:00
#endif
_ATTACH(X_MIN_PIN);
2019-07-28 21:48:29 +02:00
#endif
#if HAS_Y_MAX
#if !AVAILABLE_EILINE(Y_MAX_PIN)
2020-01-20 06:35:07 +01:00
#error "Y_MAX_PIN has no EXTINT line available."
2019-07-28 21:48:29 +02:00
#endif
_ATTACH(Y_MAX_PIN);
2019-07-28 21:48:29 +02:00
#endif
#if HAS_Y_MIN
#if !AVAILABLE_EILINE(Y_MIN_PIN)
2020-01-20 06:35:07 +01:00
#error "Y_MIN_PIN has no EXTINT line available."
2019-07-28 21:48:29 +02:00
#endif
_ATTACH(Y_MIN_PIN);
2019-07-28 21:48:29 +02:00
#endif
#if HAS_Z_MAX
#if !AVAILABLE_EILINE(Z_MAX_PIN)
2020-01-20 06:35:07 +01:00
#error "Z_MAX_PIN has no EXTINT line available."
2019-07-28 21:48:29 +02:00
#endif
_ATTACH(Z_MAX_PIN);
2019-07-28 21:48:29 +02:00
#endif
#if HAS_Z_MIN
#if !AVAILABLE_EILINE(Z_MIN_PIN)
2020-01-20 06:35:07 +01:00
#error "Z_MIN_PIN has no EXTINT line available."
2019-07-28 21:48:29 +02:00
#endif
_ATTACH(Z_MIN_PIN);
2019-07-28 21:48:29 +02:00
#endif
#if HAS_Z2_MAX
#if !AVAILABLE_EILINE(Z2_MAX_PIN)
2020-01-20 06:35:07 +01:00
#error "Z2_MAX_PIN has no EXTINT line available."
2019-07-28 21:48:29 +02:00
#endif
_ATTACH(Z2_MAX_PIN);
2019-07-28 21:48:29 +02:00
#endif
#if HAS_Z2_MIN
#if !AVAILABLE_EILINE(Z2_MIN_PIN)
2020-01-20 06:35:07 +01:00
#error "Z2_MIN_PIN has no EXTINT line available."
2019-07-28 21:48:29 +02:00
#endif
_ATTACH(Z2_MIN_PIN);
2019-07-28 21:48:29 +02:00
#endif
#if HAS_Z3_MAX
#if !AVAILABLE_EILINE(Z3_MAX_PIN)
2020-01-20 06:35:07 +01:00
#error "Z3_MAX_PIN has no EXTINT line available."
2019-07-28 21:48:29 +02:00
#endif
_ATTACH(Z3_MAX_PIN);
2019-07-28 21:48:29 +02:00
#endif
#if HAS_Z3_MIN
#if !AVAILABLE_EILINE(Z3_MIN_PIN)
2020-01-20 06:35:07 +01:00
#error "Z3_MIN_PIN has no EXTINT line available."
2019-07-28 21:48:29 +02:00
#endif
_ATTACH(Z3_MIN_PIN);
2019-07-28 21:48:29 +02:00
#endif
2020-01-20 06:35:07 +01:00
#if HAS_Z4_MAX
#if !AVAILABLE_EILINE(Z4_MAX_PIN)
#error "Z4_MAX_PIN has no EXTINT line available."
#endif
_ATTACH(Z4_MAX_PIN);
2020-01-20 06:35:07 +01:00
#endif
#if HAS_Z4_MIN
#if !AVAILABLE_EILINE(Z4_MIN_PIN)
#error "Z4_MIN_PIN has no EXTINT line available."
#endif
_ATTACH(Z4_MIN_PIN);
2020-01-20 06:35:07 +01:00
#endif
2019-07-28 21:48:29 +02:00
#if HAS_Z_MIN_PROBE_PIN
#if !AVAILABLE_EILINE(Z_MIN_PROBE_PIN)
2020-01-20 06:35:07 +01:00
#error "Z_MIN_PROBE_PIN has no EXTINT line available."
2019-07-28 21:48:29 +02:00
#endif
_ATTACH(Z_MIN_PROBE_PIN);
2019-07-28 21:48:29 +02:00
#endif
}