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.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /**
  2. * Marlin 3D Printer Firmware
  3. * Copyright (C) 2016 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. /**
  23. * Fast I/O Routines for Teensy 3.5 and Teensy 3.6
  24. * Use direct port manipulation to save scads of processor time.
  25. * Contributed by Triffid_Hunter and modified by Kliment, thinkyhead, Bob-the-Kuhn, et.al.
  26. */
  27. #ifndef _FASTIO_TEENSY_H
  28. #define _FASTIO_TEENSY_H
  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 _PULLUP(IO,V) { pinMode(IO, (v!=LOW ? INPUT_PULLUP : INPUT)); }
  56. #define _GET_INPUT(P) ((CORE_PIN ## P ## _DDRREG & CORE_PIN ## P ## _BITMASK) == 0)
  57. #define _GET_OUTPUT(P) ((CORE_PIN ## P ## _DDRREG & CORE_PIN ## P ## _BITMASK) == 0)
  58. //#define _GET_TIMER(IO)
  59. #define READ(IO) _READ(IO)
  60. #define WRITE_VAR(IO,V) _WRITE_VAR(IO,V)
  61. #define WRITE(IO,V) _WRITE(IO,V)
  62. #define TOGGLE(IO) _TOGGLE(IO)
  63. #define SET_INPUT(IO) _SET_INPUT(IO)
  64. #define SET_INPUT_PULLUP(IO) do{ _SET_INPUT(IO); _WRITE(IO,HIGH); }while(0)
  65. #define SET_OUTPUT(IO) _SET_OUTPUT(IO)
  66. #define GET_INPUT(IO) _GET_INPUT(IO)
  67. #define GET_OUTPUT(IO) _GET_OUTPUT(IO)
  68. #define OUT_WRITE(IO,V) do{ SET_OUTPUT(IO); WRITE(IO,V); }while(0)
  69. /**
  70. * Ports, functions, and pins
  71. */
  72. #define DIO0_PIN 8
  73. #endif /* _FASTIO_TEENSY_H */