My Marlin configs for Fabrikator Mini and CTC i3 Pro B
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

SAMD51.h 4.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /**
  2. * Marlin 3D Printer Firmware
  3. * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
  4. *
  5. * Based on Sprinter and grbl.
  6. * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
  7. *
  8. * This program is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation, either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  20. *
  21. */
  22. #pragma once
  23. /**
  24. * SAMD51 HAL developed by Giuliano Zaro (AKA GMagician)
  25. */
  26. #define SYNC(sc) while (sc) { \
  27. asm(""); \
  28. }
  29. // Get SAMD port/pin from specified arduino pin
  30. #define GET_SAMD_PORT(P) _GET_SAMD_PORT(PIN_TO_SAMD_PIN(P))
  31. #define GET_SAMD_PIN(P) _GET_SAMD_PIN(PIN_TO_SAMD_PIN(P))
  32. // Get external interrupt line associated to specified arduino pin
  33. #define PIN_TO_EILINE(P) _SAMDPORTPIN_TO_EILINE(GET_SAMD_PORT(P), GET_SAMD_PIN(P))
  34. // Get adc/ain associated to specified arduino pin
  35. #define PIN_TO_ADC(P) (ANAPIN_TO_ADCAIN(P) >> 8)
  36. #define PIN_TO_AIN(P) (ANAPIN_TO_ADCAIN(P) & 0xFF)
  37. // Private defines
  38. #define PIN_TO_SAMD_PIN(P) DIO##P##_PIN
  39. #define _GET_SAMD_PORT(P) ((P) >> 5)
  40. #define _GET_SAMD_PIN(P) ((P) & 0x1F)
  41. // Get external interrupt line
  42. #define _SAMDPORTPIN_TO_EILINE(P,B) ((P == 0 && WITHIN(B, 0, 31) && B != 8 && B != 26 && B != 28 && B != 29) ? (B) & 0xF \
  43. : (P == 1 && (WITHIN(B, 0, 25) || WITHIN(B, 30, 31))) ? (B) & 0xF \
  44. : (P == 1 && WITHIN(B, 26, 29)) ? 12 + (B) - 26 \
  45. : (P == 2 && (WITHIN(B, 0, 6) || WITHIN(B, 10, 31)) && B != 29) ? (B) & 0xF \
  46. : (P == 2 && B == 7) ? 9 \
  47. : (P == 3 && WITHIN(B, 0, 1)) ? (B) \
  48. : (P == 3 && WITHIN(B, 8, 12)) ? 3 + (B) - 8 \
  49. : (P == 3 && WITHIN(B, 20, 21)) ? 10 + (B) - 20 \
  50. : -1)
  51. // Get adc/ain
  52. #define ANAPIN_TO_ADCAIN(P) _PIN_TO_ADCAIN(ANAPIN_TO_SAMDPIN(P))
  53. #define _PIN_TO_ADCAIN(P) _SAMDPORTPIN_TO_ADCAIN(_GET_SAMD_PORT(P), _GET_SAMD_PIN(P))
  54. #define _SAMDPORTPIN_TO_ADCAIN(P,B) ((P == 0 && WITHIN(B, 2, 3)) ? 0x000 + (B) - 2 \
  55. : (P == 0 && WITHIN(B, 4, 7)) ? 0x000 + (B) \
  56. : (P == 0 && WITHIN(B, 8, 9)) ? 0x100 + 2 + (B) - 8 \
  57. : (P == 0 && WITHIN(B, 10, 11)) ? 0x000 + (B) \
  58. : (P == 1 && WITHIN(B, 0, 3)) ? 0x000 + 12 + (B) \
  59. : (P == 1 && WITHIN(B, 4, 7)) ? 0x100 + 6 + (B) - 4 \
  60. : (P == 1 && WITHIN(B, 8, 9)) ? 0x100 + (B) - 8 \
  61. : (P == 2 && WITHIN(B, 0, 1)) ? 0x100 + 10 + (B) \
  62. : (P == 2 && WITHIN(B, 2, 3)) ? 0x100 + 4 + (B) - 2 \
  63. : (P == 2 && WITHIN(B, 30, 31)) ? 0x100 + 12 + (B) - 30 \
  64. : (P == 3 && WITHIN(B, 0, 1)) ? 0x100 + 14 + (B) \
  65. : -1)