My Marlin configs for Fabrikator Mini and CTC i3 Pro B
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

fastio.h 4.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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 LPC1768/9
  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. /**
  28. * Description: Fast IO functions LPC1768
  29. *
  30. * For TARGET LPC1768
  31. */
  32. #ifndef _FASTIO_LPC1768_H
  33. #define _FASTIO_LPC1768_H
  34. #include <LPC17xx.h>
  35. #include <Arduino.h>
  36. #include <pinmapping.h>
  37. bool useable_hardware_PWM(pin_t pin);
  38. #define USEABLE_HARDWARE_PWM(pin) useable_hardware_PWM(pin)
  39. #define LPC_PORT_OFFSET (0x0020)
  40. #define LPC_PIN(pin) (1UL << pin)
  41. #define LPC_GPIO(port) ((volatile LPC_GPIO_TypeDef *)(LPC_GPIO0_BASE + LPC_PORT_OFFSET * port))
  42. #define SET_DIR_INPUT(IO) (LPC_GPIO(LPC1768_PIN_PORT(IO))->FIODIR &= ~LPC_PIN(LPC1768_PIN_PIN(IO)))
  43. #define SET_DIR_OUTPUT(IO) (LPC_GPIO(LPC1768_PIN_PORT(IO))->FIODIR |= LPC_PIN(LPC1768_PIN_PIN(IO)))
  44. #define SET_MODE(IO, mode) (pin_mode((LPC1768_PIN_PORT(IO), LPC1768_PIN_PIN(IO)), mode))
  45. #define WRITE_PIN_SET(IO) (LPC_GPIO(LPC1768_PIN_PORT(IO))->FIOSET = LPC_PIN(LPC1768_PIN_PIN(IO)))
  46. #define WRITE_PIN_CLR(IO) (LPC_GPIO(LPC1768_PIN_PORT(IO))->FIOCLR = LPC_PIN(LPC1768_PIN_PIN(IO)))
  47. #define READ_PIN(IO) ((LPC_GPIO(LPC1768_PIN_PORT(IO))->FIOPIN & LPC_PIN(LPC1768_PIN_PIN(IO))) ? 1 : 0)
  48. #define WRITE_PIN(IO, v) ((v) ? WRITE_PIN_SET(IO) : WRITE_PIN_CLR(IO))
  49. /**
  50. * Magic I/O routines
  51. *
  52. * Now you can simply SET_OUTPUT(STEP); WRITE(STEP, HIGH); WRITE(STEP, LOW);
  53. *
  54. * Why double up on these macros? see http://gcc.gnu.org/onlinedocs/cpp/Stringification.html
  55. */
  56. /// Read a pin
  57. #define _READ(IO) READ_PIN(IO)
  58. /// Write to a pin
  59. #define _WRITE_VAR(IO, v) digitalWrite(IO, v)
  60. #define _WRITE(IO, v) WRITE_PIN(IO, v)
  61. /// toggle a pin
  62. #define _TOGGLE(IO) _WRITE(IO, !READ(IO))
  63. /// set pin as input
  64. #define _SET_INPUT(IO) SET_DIR_INPUT(IO)
  65. /// set pin as output
  66. #define _SET_OUTPUT(IO) SET_DIR_OUTPUT(IO)
  67. /// set pin as input with pullup mode
  68. #define _PULLUP(IO, v) (pinMode(IO, (v!=LOW ? INPUT_PULLUP : INPUT)))
  69. /// set pin as input with pulldown mode
  70. #define _PULLDOWN(IO, v) (pinMode(IO, (v!=LOW ? INPUT_PULLDOWN : INPUT)))
  71. // hg42: all pins can be input or output (I hope)
  72. // hg42: undefined pins create compile error (IO, is no pin)
  73. // hg42: currently not used, but was used by pinsDebug
  74. /// check if pin is an input
  75. #define _GET_INPUT(IO) (LPC1768_PIN_PIN(IO)>=0)
  76. /// check if pin is an output
  77. #define _GET_OUTPUT(IO) (LPC1768_PIN_PIN(IO)>=0)
  78. // hg42: GET_TIMER is used only to check if it's a PWM pin
  79. // hg42: we cannot use USEABLE_HARDWARE_PWM because it uses a function that cannot be used statically
  80. // hg42: instead use PWM bit from the #define
  81. /// check if pin is an timer
  82. #define _GET_TIMER(IO) TRUE // could be LPC1768_PIN_PWM(IO), but there
  83. // hg42: could be this:
  84. // #define _GET_TIMER(IO) LPC1768_PIN_PWM(IO)
  85. // but this is an incomplete check (12 pins are PWMable, but only 6 can be used at the same time)
  86. /// Read a pin wrapper
  87. #define READ(IO) _READ(IO)
  88. /// Write to a pin wrapper
  89. #define WRITE_VAR(IO, v) _WRITE_VAR(IO, v)
  90. #define WRITE(IO, v) _WRITE(IO, v)
  91. /// toggle a pin wrapper
  92. #define TOGGLE(IO) _TOGGLE(IO)
  93. /// set pin as input wrapper
  94. #define SET_INPUT(IO) _SET_INPUT(IO)
  95. /// set pin as input with pullup wrapper
  96. #define SET_INPUT_PULLUP(IO) do{ _SET_INPUT(IO); _PULLUP(IO, HIGH); }while(0)
  97. /// set pin as input with pulldown wrapper
  98. #define SET_INPUT_PULLDOWN(IO) do{ _SET_INPUT(IO); _PULLDOWN(IO, HIGH); }while(0)
  99. /// set pin as output wrapper - reads the pin and sets the output to that value
  100. #define SET_OUTPUT(IO) do{ _WRITE(IO, _READ(IO)); _SET_OUTPUT(IO); }while(0)
  101. /// check if pin is an input wrapper
  102. #define GET_INPUT(IO) _GET_INPUT(IO)
  103. /// check if pin is an output wrapper
  104. #define GET_OUTPUT(IO) _GET_OUTPUT(IO)
  105. /// check if pin is an timer wrapper
  106. #define GET_TIMER(IO) _GET_TIMER(IO)
  107. // Shorthand
  108. #define OUT_WRITE(IO, v) { SET_OUTPUT(IO); WRITE(IO, v); }
  109. #endif // _FASTIO_LPC1768_H