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.

fastio_Teensy.h 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /**
  2. * Marlin 3D Printer Firmware
  3. * Copyright (c) 2019 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 <http://www.gnu.org/licenses/>.
  20. *
  21. */
  22. #pragma once
  23. /**
  24. * Fast I/O Routines for Teensy 3.5 and Teensy 3.6
  25. * Use direct port manipulation to save scads of processor time.
  26. * Contributed by Triffid_Hunter and modified by Kliment, thinkyhead, Bob-the-Kuhn, et.al.
  27. */
  28. #pragma once
  29. #ifndef MASK
  30. #define MASK(PIN) (1 << PIN)
  31. #endif
  32. #define GPIO_BITBAND_ADDR(reg, bit) (((uint32_t)&(reg) - 0x40000000) * 32 + (bit) * 4 + 0x42000000)
  33. #define GPIO_BITBAND(reg, bit) (*(uint32_t *)GPIO_BITBAND_ADDR((reg), (bit)))
  34. /**
  35. * Magic I/O routines
  36. *
  37. * Now you can simply SET_OUTPUT(PIN); WRITE(PIN, HIGH); WRITE(PIN, LOW);
  38. *
  39. * Why double up on these macros? see http://gcc.gnu.org/onlinedocs/cpp/Stringification.html
  40. */
  41. #define _READ(P) bool(CORE_PIN ## P ## _PINREG & CORE_PIN ## P ## _BITMASK)
  42. #define _WRITE(P,V) do{ \
  43. if (V) CORE_PIN ## P ## _PORTSET = CORE_PIN ## P ## _BITMASK; \
  44. else CORE_PIN ## P ## _PORTCLEAR = CORE_PIN ## P ## _BITMASK; \
  45. }while(0)
  46. #define _TOGGLE(P) (*(&(CORE_PIN ## P ## _PORTCLEAR)+1) = CORE_PIN ## P ## _BITMASK)
  47. #define _SET_INPUT(P) do{ \
  48. CORE_PIN ## P ## _CONFIG = PORT_PCR_MUX(1); \
  49. GPIO_BITBAND(CORE_PIN ## P ## _DDRREG , CORE_PIN ## P ## _BIT) = 0; \
  50. }while(0)
  51. #define _SET_OUTPUT(P) do{ \
  52. CORE_PIN ## P ## _CONFIG = PORT_PCR_MUX(1)|PORT_PCR_SRE|PORT_PCR_DSE; \
  53. GPIO_BITBAND(CORE_PIN ## P ## _DDRREG , CORE_PIN ## P ## _BIT) = 1; \
  54. }while(0)
  55. #define _SET_INPUT_PULLUP(P) do{ \
  56. CORE_PIN ## P ## _CONFIG = PORT_PCR_MUX(1) | PORT_PCR_PE | PORT_PCR_PS; \
  57. GPIO_BITBAND(CORE_PIN ## P ## _DDRREG , CORE_PIN ## P ## _BIT) = 0; \
  58. }while(0)
  59. #define _IS_INPUT(P) ((CORE_PIN ## P ## _DDRREG & CORE_PIN ## P ## _BITMASK) == 0)
  60. #define _IS_OUTPUT(P) ((CORE_PIN ## P ## _DDRREG & CORE_PIN ## P ## _BITMASK) == 0)
  61. #define READ(IO) _READ(IO)
  62. #define WRITE(IO,V) _WRITE(IO,V)
  63. #define TOGGLE(IO) _TOGGLE(IO)
  64. #define SET_INPUT(IO) _SET_INPUT(IO)
  65. #define SET_INPUT_PULLUP(IO) _SET_INPUT_PULLUP(IO)
  66. #define SET_OUTPUT(IO) _SET_OUTPUT(IO)
  67. #define SET_PWM(IO) SET_OUTPUT(IO)
  68. #define IS_INPUT(IO) _IS_INPUT(IO)
  69. #define IS_OUTPUT(IO) _IS_OUTPUT(IO)
  70. #define OUT_WRITE(IO,V) do{ SET_OUTPUT(IO); WRITE(IO,V); }while(0)
  71. // digitalRead/Write wrappers
  72. #define extDigitalRead(IO) digitalRead(IO)
  73. #define extDigitalWrite(IO,V) digitalWrite(IO,V)
  74. #define PWM_PIN(P) digitalPinHasPWM(P)
  75. /**
  76. * Ports, functions, and pins
  77. */
  78. #define DIO0_PIN 8