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 3.9KB

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