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.h 3.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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 <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. #ifndef MASK
  29. #define MASK(PIN) (1 << PIN)
  30. #endif
  31. #define GPIO_BITBAND_ADDR(reg, bit) (((uint32_t)&(reg) - 0x40000000) * 32 + (bit) * 4 + 0x42000000)
  32. #define GPIO_BITBAND(reg, bit) (*(uint32_t *)GPIO_BITBAND_ADDR((reg), (bit)))
  33. /**
  34. * Magic I/O routines
  35. *
  36. * Now you can simply SET_OUTPUT(PIN); WRITE(PIN, HIGH); WRITE(PIN, LOW);
  37. *
  38. * Why double up on these macros? see https://gcc.gnu.org/onlinedocs/gcc-4.8.5/cpp/Stringification.html
  39. */
  40. #define _READ(P) bool(CORE_PIN ## P ## _PINREG & CORE_PIN ## P ## _BITMASK)
  41. #define _WRITE(P,V) do{ \
  42. if (V) CORE_PIN ## P ## _PORTSET = CORE_PIN ## P ## _BITMASK; \
  43. else CORE_PIN ## P ## _PORTCLEAR = CORE_PIN ## P ## _BITMASK; \
  44. }while(0)
  45. #define _TOGGLE(P) (*(&(CORE_PIN ## P ## _PORTCLEAR)+1) = CORE_PIN ## P ## _BITMASK)
  46. #define _SET_INPUT(P) do{ \
  47. CORE_PIN ## P ## _CONFIG = PORT_PCR_MUX(1); \
  48. GPIO_BITBAND(CORE_PIN ## P ## _DDRREG , CORE_PIN ## P ## _BIT) = 0; \
  49. }while(0)
  50. #define _SET_OUTPUT(P) do{ \
  51. CORE_PIN ## P ## _CONFIG = PORT_PCR_MUX(1)|PORT_PCR_SRE|PORT_PCR_DSE; \
  52. GPIO_BITBAND(CORE_PIN ## P ## _DDRREG , CORE_PIN ## P ## _BIT) = 1; \
  53. }while(0)
  54. #define _SET_INPUT_PULLUP(P) do{ \
  55. CORE_PIN ## P ## _CONFIG = PORT_PCR_MUX(1) | PORT_PCR_PE | PORT_PCR_PS; \
  56. GPIO_BITBAND(CORE_PIN ## P ## _DDRREG , CORE_PIN ## P ## _BIT) = 0; \
  57. }while(0)
  58. #define _IS_INPUT(P) ((CORE_PIN ## P ## _DDRREG & CORE_PIN ## P ## _BITMASK) == 0)
  59. #define _IS_OUTPUT(P) ((CORE_PIN ## P ## _DDRREG & CORE_PIN ## P ## _BITMASK) == 0)
  60. #define READ(IO) _READ(IO)
  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) _SET_INPUT_PULLUP(IO)
  65. #define SET_INPUT_PULLDOWN SET_INPUT
  66. #define SET_OUTPUT(IO) _SET_OUTPUT(IO)
  67. #define SET_PWM SET_OUTPUT
  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