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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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. This code contributed by Triffid_Hunter and modified by Kliment
  24. why double up on these macros? see http://gcc.gnu.org/onlinedocs/cpp/Stringification.html
  25. */
  26. /**
  27. * Description: Fast IO functions LPC1768
  28. *
  29. * For TARGET LPC1768
  30. */
  31. #ifndef _FASTIO_LPC1768_H
  32. #define _FASTIO_LPC1768_H
  33. #include <LPC17xx.h>
  34. #include "arduino.h"
  35. #include "pinmapping.h"
  36. bool useable_hardware_PWM(uint8_t pin);
  37. #define USEABLE_HARDWARE_PWM(pin) useable_hardware_PWM(pin)
  38. #define LPC_PORT_OFFSET (0x0020)
  39. #define LPC_PIN(pin) (1UL << pin)
  40. #define LPC_GPIO(port) ((volatile LPC_GPIO_TypeDef *)(LPC_GPIO0_BASE + LPC_PORT_OFFSET * port))
  41. #define SET_DIR_INPUT(IO) (LPC_GPIO(DIO ## IO ## _PORT)->FIODIR &= ~LPC_PIN(DIO ## IO ##_PIN))
  42. #define SET_DIR_OUTPUT(IO) (LPC_GPIO(DIO ## IO ## _PORT)->FIODIR |= LPC_PIN(DIO ## IO ##_PIN))
  43. #define SET_MODE(IO, mode) (pin_mode((DIO ## IO ## _PORT, DIO ## IO ## _PIN), mode))
  44. #define WRITE_PIN_SET(IO) (LPC_GPIO(DIO ## IO ## _PORT)->FIOSET = LPC_PIN(DIO ## IO ##_PIN))
  45. #define WRITE_PIN_CLR(IO) (LPC_GPIO(DIO ## IO ## _PORT)->FIOCLR = LPC_PIN(DIO ## IO ##_PIN))
  46. #define READ_PIN(IO) ((LPC_GPIO(DIO ## IO ## _PORT)->FIOPIN & LPC_PIN(DIO ## IO ##_PIN)) ? 1 : 0)
  47. #define WRITE_PIN(IO, v) ((v) ? WRITE_PIN_SET(IO) : WRITE_PIN_CLR(IO))
  48. /**
  49. magic I/O routines
  50. now you can simply SET_OUTPUT(STEP); WRITE(STEP, 1); WRITE(STEP, 0);
  51. */
  52. /// Read a pin
  53. #define _READ(IO) READ_PIN(IO)
  54. /// Write to a pin
  55. #define _WRITE_VAR(IO, v) digitalWrite(IO, v)
  56. #define _WRITE(IO, v) WRITE_PIN(IO, v)
  57. /// toggle a pin
  58. #define _TOGGLE(IO) _WRITE(IO, !READ(IO))
  59. /// set pin as input
  60. #define _SET_INPUT(IO) SET_DIR_INPUT(IO)
  61. /// set pin as output
  62. #define _SET_OUTPUT(IO) SET_DIR_OUTPUT(IO)
  63. /// set pin as input with pullup mode
  64. #define _PULLUP(IO, v) (pinMode(IO, (v!=LOW ? INPUT_PULLUP : INPUT)))
  65. /// check if pin is an input
  66. #define _GET_INPUT(IO)
  67. /// check if pin is an output
  68. #define _GET_OUTPUT(IO)
  69. /// check if pin is an timer
  70. #define _GET_TIMER(IO)
  71. // why double up on these macros? see http://gcc.gnu.org/onlinedocs/cpp/Stringification.html
  72. /// Read a pin wrapper
  73. #define READ(IO) _READ(IO)
  74. /// Write to a pin wrapper
  75. #define WRITE_VAR(IO, v) _WRITE_VAR(IO, v)
  76. #define WRITE(IO, v) _WRITE(IO, v)
  77. /// toggle a pin wrapper
  78. #define TOGGLE(IO) _TOGGLE(IO)
  79. /// set pin as input wrapper
  80. #define SET_INPUT(IO) _SET_INPUT(IO)
  81. /// set pin as input with pullup wrapper
  82. #define SET_INPUT_PULLUP(IO) do{ _SET_INPUT(IO); _PULLUP(IO, HIGH); }while(0)
  83. /// set pin as output wrapper
  84. #define SET_OUTPUT(IO) do{ _SET_OUTPUT(IO); _WRITE(IO, LOW); }while(0)
  85. /// check if pin is an input wrapper
  86. #define GET_INPUT(IO) _GET_INPUT(IO) // todo: Never used?
  87. /// check if pin is an output wrapper
  88. #define GET_OUTPUT(IO) _GET_OUTPUT(IO) //todo: Never Used?
  89. /// check if pin is an timer wrapper
  90. #define GET_TIMER(IO) _GET_TIMER(IO)
  91. // Shorthand
  92. #define OUT_WRITE(IO, v) { SET_OUTPUT(IO); WRITE(IO, v); }
  93. #endif // _FASTIO_LPC1768_H