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.

compat.h 7.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. /****************************************************************************
  2. * Written By Marcio Teixeira 2018 - Aleph Objects, Inc. *
  3. * *
  4. * This program is free software: you can redistribute it and/or modify *
  5. * it under the terms of the GNU General Public License as published by *
  6. * the Free Software Foundation, either version 3 of the License, or *
  7. * (at your option) any later version. *
  8. * *
  9. * This program is distributed in the hope that it will be useful, *
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of *
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
  12. * GNU General Public License for more details. *
  13. * *
  14. * To view a copy of the GNU General Public License, go to the following *
  15. * location: <http://www.gnu.org/licenses/>. *
  16. ****************************************************************************/
  17. #pragma once
  18. #include "../config.h"
  19. #ifdef __MARLIN_FIRMWARE__
  20. // Marlin will define the I/O functions for us
  21. #if ENABLED(TOUCH_UI_FTDI_EVE)
  22. #define FTDI_BASIC
  23. #define FTDI_EXTENDED
  24. #endif
  25. #else // !__MARLIN_FIRMWARE__
  26. #include <Arduino.h>
  27. #ifndef CLCD_USE_SOFT_SPI
  28. #include <SPI.h>
  29. #endif
  30. namespace fast_io {
  31. template<typename port_t,uint8_t bits>
  32. struct port_pin {
  33. typedef port_t port;
  34. static inline void set_high() {port::port() = (port::port() | bits);}
  35. static inline void set_low() {port::port() = (port::port() & (~bits));}
  36. static inline void set_input() {port::ddr() = (port::ddr() & (~bits));}
  37. static inline void set_input_pullup() {set_input(); set_high();}
  38. static inline void set_output() {port::ddr() = (port::ddr() | bits);}
  39. static inline uint8_t read() {return port::pin() & bits;}
  40. static inline void write(bool v) {if (v) set_high(); else set_low();}
  41. };
  42. #define MAKE_AVR_PORT_PINS(ID) \
  43. struct port_##ID { \
  44. static volatile uint8_t &pin() {return PIN##ID;}; \
  45. static volatile uint8_t &port() {return PORT##ID;}; \
  46. static volatile uint8_t &ddr() {return DDR##ID;}; \
  47. }; \
  48. typedef port_pin<port_##ID, 0b00000001> AVR_##ID##0; \
  49. typedef port_pin<port_##ID, 0b00000010> AVR_##ID##1; \
  50. typedef port_pin<port_##ID, 0b00000100> AVR_##ID##2; \
  51. typedef port_pin<port_##ID, 0b00001000> AVR_##ID##3; \
  52. typedef port_pin<port_##ID, 0b00010000> AVR_##ID##4; \
  53. typedef port_pin<port_##ID, 0b00100000> AVR_##ID##5; \
  54. typedef port_pin<port_##ID, 0b01000000> AVR_##ID##6; \
  55. typedef port_pin<port_##ID, 0b10000000> AVR_##ID##7;
  56. #ifdef PORTA
  57. MAKE_AVR_PORT_PINS(A);
  58. #endif
  59. #ifdef PORTB
  60. MAKE_AVR_PORT_PINS(B);
  61. #endif
  62. #ifdef PORTC
  63. MAKE_AVR_PORT_PINS(C);
  64. #endif
  65. #ifdef PORTD
  66. MAKE_AVR_PORT_PINS(D);
  67. #endif
  68. #ifdef PORTE
  69. MAKE_AVR_PORT_PINS(E);
  70. #endif
  71. #ifdef PORTF
  72. MAKE_AVR_PORT_PINS(F);
  73. #endif
  74. #ifdef PORTG
  75. MAKE_AVR_PORT_PINS(G);
  76. #endif
  77. #ifdef PORTH
  78. MAKE_AVR_PORT_PINS(H);
  79. #endif
  80. #ifdef PORTJ
  81. MAKE_AVR_PORT_PINS(J);
  82. #endif
  83. #ifdef PORTK
  84. MAKE_AVR_PORT_PINS(K);
  85. #endif
  86. #ifdef PORTL
  87. MAKE_AVR_PORT_PINS(L);
  88. #endif
  89. #ifdef PORTQ
  90. MAKE_AVR_PORT_PINS(Q);
  91. #endif
  92. #ifdef PORTR
  93. MAKE_AVR_PORT_PINS(R);
  94. #endif
  95. #undef MAKE_AVR_PORT_PINS
  96. template<uint8_t p>
  97. struct arduino_digital_pin {
  98. static constexpr uint8_t pin = p;
  99. static inline void set_high() {digitalWrite(p, HIGH);}
  100. static inline void set_low() {digitalWrite(p, LOW);}
  101. static inline void set_input() {pinMode(p, INPUT);}
  102. static inline void set_input_pullup() {pinMode(p, INPUT_PULLUP);}
  103. static inline void set_output() {pinMode(p, OUTPUT);}
  104. static inline uint8_t read() {return digitalRead(p);}
  105. static inline void write(bool v) {digitalWrite(p, v ? HIGH : LOW);}
  106. };
  107. #define MAKE_ARDUINO_PINS(ID) typedef arduino_digital_pin<ID> ARDUINO_DIGITAL_##ID;
  108. MAKE_ARDUINO_PINS( 0);
  109. MAKE_ARDUINO_PINS( 1);
  110. MAKE_ARDUINO_PINS( 2);
  111. MAKE_ARDUINO_PINS( 3);
  112. MAKE_ARDUINO_PINS( 4);
  113. MAKE_ARDUINO_PINS( 5);
  114. MAKE_ARDUINO_PINS( 6);
  115. MAKE_ARDUINO_PINS( 7);
  116. MAKE_ARDUINO_PINS( 8);
  117. MAKE_ARDUINO_PINS( 9);
  118. MAKE_ARDUINO_PINS(10);
  119. MAKE_ARDUINO_PINS(11);
  120. MAKE_ARDUINO_PINS(12);
  121. MAKE_ARDUINO_PINS(13);
  122. MAKE_ARDUINO_PINS(14);
  123. MAKE_ARDUINO_PINS(15);
  124. MAKE_ARDUINO_PINS(16);
  125. MAKE_ARDUINO_PINS(17);
  126. MAKE_ARDUINO_PINS(18);
  127. MAKE_ARDUINO_PINS(19);
  128. MAKE_ARDUINO_PINS(10);
  129. MAKE_ARDUINO_PINS(21);
  130. MAKE_ARDUINO_PINS(22);
  131. MAKE_ARDUINO_PINS(23);
  132. MAKE_ARDUINO_PINS(24);
  133. MAKE_ARDUINO_PINS(25);
  134. MAKE_ARDUINO_PINS(26);
  135. MAKE_ARDUINO_PINS(27);
  136. MAKE_ARDUINO_PINS(28);
  137. MAKE_ARDUINO_PINS(29);
  138. MAKE_ARDUINO_PINS(30);
  139. MAKE_ARDUINO_PINS(31);
  140. MAKE_ARDUINO_PINS(32);
  141. MAKE_ARDUINO_PINS(33);
  142. MAKE_ARDUINO_PINS(34);
  143. MAKE_ARDUINO_PINS(35);
  144. MAKE_ARDUINO_PINS(36);
  145. MAKE_ARDUINO_PINS(37);
  146. MAKE_ARDUINO_PINS(38);
  147. MAKE_ARDUINO_PINS(39);
  148. MAKE_ARDUINO_PINS(40);
  149. MAKE_ARDUINO_PINS(41);
  150. MAKE_ARDUINO_PINS(42);
  151. MAKE_ARDUINO_PINS(43);
  152. MAKE_ARDUINO_PINS(44);
  153. MAKE_ARDUINO_PINS(45);
  154. MAKE_ARDUINO_PINS(46);
  155. MAKE_ARDUINO_PINS(47);
  156. MAKE_ARDUINO_PINS(48);
  157. MAKE_ARDUINO_PINS(49);
  158. MAKE_ARDUINO_PINS(50);
  159. MAKE_ARDUINO_PINS(51);
  160. MAKE_ARDUINO_PINS(52);
  161. MAKE_ARDUINO_PINS(53);
  162. #undef MAKE_ARDUINO_PINS
  163. } // namespace fast_io
  164. #define SET_INPUT(pin) fast_io::pin::set_input()
  165. #define SET_INPUT_PULLUP(pin) fast_io::pin::set_input(); fast_io::pin::set_high()
  166. #define SET_OUTPUT(pin) fast_io::pin::set_output()
  167. #define READ(pin) fast_io::pin::read()
  168. #define WRITE(pin, value) fast_io::pin::write(value)
  169. #ifndef pgm_read_word_far
  170. #define pgm_read_word_far pgm_read_word
  171. #endif
  172. #ifndef pgm_read_dword_far
  173. #define pgm_read_dword_far pgm_read_dword
  174. #endif
  175. #ifndef pgm_read_ptr_far
  176. #define pgm_read_ptr_far pgm_read_ptr
  177. #endif
  178. #define SERIAL_ECHO_START()
  179. #define SERIAL_ECHOLNPGM(str) Serial.println(F(str))
  180. #define SERIAL_ECHOPGM(str) Serial.print(F(str))
  181. #define SERIAL_ECHO_MSG(str) Serial.println(str)
  182. #define SERIAL_ECHOLNPAIR(str, val) {Serial.print(F(str)); Serial.println(val);}
  183. #define SERIAL_ECHOPAIR(str, val) {Serial.print(F(str)); Serial.print(val);}
  184. #define safe_delay delay
  185. // Define macros for compatibility
  186. #define _CAT(a, ...) a ## __VA_ARGS__
  187. #define SWITCH_ENABLED_ 1
  188. #define ENABLED(b) _CAT(SWITCH_ENABLED_, b)
  189. #define DISABLED(b) !ENABLED(b)
  190. #define ANY(A,B) (ENABLED(A) || ENABLED(B))
  191. #define EITHER(A,B) (ENABLED(A) || ENABLED(B))
  192. #define BOTH(A,B) (ENABLED(A) && ENABLED(B))
  193. #define NONE(A,B) (DISABLED(A) && DISABLED(B))
  194. // Remove compiler warning on an unused variable
  195. #ifndef UNUSED
  196. #if defined(ARDUINO_ARCH_STM32) && !defined(STM32GENERIC)
  197. #define UNUSED(X) (void)X
  198. #else
  199. #define UNUSED(x) ((void)(x))
  200. #endif
  201. #endif
  202. #endif // !__MARLIN_FIRMWARE__