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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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 X86_64
  25. */
  26. #include <Arduino.h>
  27. #include <pinmapping.h>
  28. #define USEABLE_HARDWARE_PWM(pin) false
  29. #define SET_DIR_INPUT(IO) Gpio::setDir(IO, 1)
  30. #define SET_DIR_OUTPUT(IO) Gpio::setDir(IO, 0)
  31. #define SET_MODE(IO, mode) Gpio::setMode(IO, mode)
  32. #define WRITE_PIN_SET(IO) Gpio::set(IO)
  33. #define WRITE_PIN_CLR(IO) Gpio::clear(IO)
  34. #define READ_PIN(IO) Gpio::get(IO)
  35. #define WRITE_PIN(IO,V) Gpio::set(IO, V)
  36. /**
  37. * Magic I/O routines
  38. *
  39. * Now you can simply SET_OUTPUT(STEP); WRITE(STEP, HIGH); WRITE(STEP, LOW);
  40. *
  41. * Why double up on these macros? see http://gcc.gnu.org/onlinedocs/cpp/Stringification.html
  42. */
  43. /// Read a pin
  44. #define _READ(IO) READ_PIN(IO)
  45. /// Write to a pin
  46. #define _WRITE_VAR(IO,V) digitalWrite(IO,V)
  47. #define _WRITE(IO,V) WRITE_PIN(IO,V)
  48. /// toggle a pin
  49. #define _TOGGLE(IO) _WRITE(IO, !READ(IO))
  50. /// set pin as input
  51. #define _SET_INPUT(IO) SET_DIR_INPUT(IO)
  52. /// set pin as output
  53. #define _SET_OUTPUT(IO) SET_DIR_OUTPUT(IO)
  54. /// set pin as input with pullup mode
  55. #define _PULLUP(IO,V) pinMode(IO, (V) ? INPUT_PULLUP : INPUT)
  56. /// set pin as input with pulldown mode
  57. #define _PULLDOWN(IO,V) pinMode(IO, (V) ? INPUT_PULLDOWN : INPUT)
  58. // hg42: all pins can be input or output (I hope)
  59. // hg42: undefined pins create compile error (IO, is no pin)
  60. // hg42: currently not used, but was used by pinsDebug
  61. /// check if pin is an input
  62. #define _GET_INPUT(IO) (LPC1768_PIN_PIN(IO) >= 0)
  63. /// check if pin is an output
  64. #define _GET_OUTPUT(IO) (LPC1768_PIN_PIN(IO) >= 0)
  65. // hg42: GET_TIMER is used only to check if it's a PWM pin
  66. // hg42: we cannot use USEABLE_HARDWARE_PWM because it uses a function that cannot be used statically
  67. // hg42: instead use PWM bit from the #define
  68. /// check if pin is a timer
  69. #define _GET_TIMER(IO) true // could be LPC1768_PIN_PWM(IO), but there
  70. // hg42: could be this:
  71. // #define _GET_TIMER(IO) LPC1768_PIN_PWM(IO)
  72. // but this is an incomplete check (12 pins are PWMable, but only 6 can be used at the same time)
  73. /// Read a pin wrapper
  74. #define READ(IO) _READ(IO)
  75. /// Write to a pin wrapper
  76. #define WRITE_VAR(IO,V) _WRITE_VAR(IO,V)
  77. #define WRITE(IO,V) _WRITE(IO,V)
  78. /// toggle a pin wrapper
  79. #define TOGGLE(IO) _TOGGLE(IO)
  80. /// set pin as input wrapper
  81. #define SET_INPUT(IO) _SET_INPUT(IO)
  82. /// set pin as input with pullup wrapper
  83. #define SET_INPUT_PULLUP(IO) do{ _SET_INPUT(IO); _PULLUP(IO, HIGH); }while(0)
  84. /// set pin as input with pulldown wrapper
  85. #define SET_INPUT_PULLDOWN(IO) do{ _SET_INPUT(IO); _PULLDOWN(IO, HIGH); }while(0)
  86. /// set pin as output wrapper - reads the pin and sets the output to that value
  87. #define SET_OUTPUT(IO) do{ _WRITE(IO, _READ(IO)); _SET_OUTPUT(IO); }while(0)
  88. /// check if pin is an input wrapper
  89. #define GET_INPUT(IO) _GET_INPUT(IO)
  90. /// check if pin is an output wrapper
  91. #define GET_OUTPUT(IO) _GET_OUTPUT(IO)
  92. /// check if pin is a timer (wrapper)
  93. #define GET_TIMER(IO) _GET_TIMER(IO)
  94. // Shorthand
  95. #define OUT_WRITE(IO,V) do{ SET_OUTPUT(IO); WRITE(IO,V); }while(0)
  96. // digitalRead/Write wrappers
  97. #define extDigitalRead(IO) digitalRead(IO)
  98. #define extDigitalWrite(IO,V) digitalWrite(IO,V)