My Marlin configs for Fabrikator Mini and CTC i3 Pro B
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. /**
  2. * Marlin 3D Printer Firmware
  3. *
  4. * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
  5. * Copyright (c) 2016 Bob Cousins bobcousins42@googlemail.com
  6. * Copyright (c) 2015-2016 Nico Tonnhofer wurstnase.reprap@gmail.com
  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 <https://www.gnu.org/licenses/>.
  20. *
  21. */
  22. #pragma once
  23. /**
  24. * HAL for Arduino Due and compatible (SAM3X8E)
  25. */
  26. #define CPU_32_BIT
  27. #include "../shared/Marduino.h"
  28. #include "../shared/eeprom_if.h"
  29. #include "../shared/math_32bit.h"
  30. #include "../shared/HAL_SPI.h"
  31. #include "fastio.h"
  32. #include <stdint.h>
  33. #include "../../core/serial_hook.h"
  34. // ------------------------
  35. // Serial ports
  36. // ------------------------
  37. typedef ForwardSerial1Class< decltype(Serial) > DefaultSerial1;
  38. typedef ForwardSerial1Class< decltype(Serial1) > DefaultSerial2;
  39. typedef ForwardSerial1Class< decltype(Serial2) > DefaultSerial3;
  40. typedef ForwardSerial1Class< decltype(Serial3) > DefaultSerial4;
  41. extern DefaultSerial1 MSerial0;
  42. extern DefaultSerial2 MSerial1;
  43. extern DefaultSerial3 MSerial2;
  44. extern DefaultSerial4 MSerial3;
  45. #define _MSERIAL(X) MSerial##X
  46. #define MSERIAL(X) _MSERIAL(X)
  47. #if SERIAL_PORT == -1 || ENABLED(EMERGENCY_PARSER)
  48. #define MYSERIAL1 customizedSerial1
  49. #elif WITHIN(SERIAL_PORT, 0, 3)
  50. #define MYSERIAL1 MSERIAL(SERIAL_PORT)
  51. #else
  52. #error "The required SERIAL_PORT must be from 0 to 3, or -1 for USB Serial."
  53. #endif
  54. #ifdef SERIAL_PORT_2
  55. #if SERIAL_PORT_2 == -1 || ENABLED(EMERGENCY_PARSER)
  56. #define MYSERIAL2 customizedSerial2
  57. #elif WITHIN(SERIAL_PORT_2, 0, 3)
  58. #define MYSERIAL2 MSERIAL(SERIAL_PORT_2)
  59. #else
  60. #error "SERIAL_PORT_2 must be from 0 to 3, or -1 for USB Serial."
  61. #endif
  62. #endif
  63. #ifdef SERIAL_PORT_3
  64. #if SERIAL_PORT_3 == -1 || ENABLED(EMERGENCY_PARSER)
  65. #define MYSERIAL3 customizedSerial3
  66. #elif WITHIN(SERIAL_PORT_3, 0, 3)
  67. #define MYSERIAL3 MSERIAL(SERIAL_PORT_3)
  68. #else
  69. #error "SERIAL_PORT_3 must be from 0 to 3, or -1 for USB Serial."
  70. #endif
  71. #endif
  72. #ifdef MMU2_SERIAL_PORT
  73. #if WITHIN(MMU2_SERIAL_PORT, 0, 3)
  74. #define MMU2_SERIAL MSERIAL(MMU2_SERIAL_PORT)
  75. #else
  76. #error "MMU2_SERIAL_PORT must be from 0 to 3."
  77. #endif
  78. #endif
  79. #ifdef LCD_SERIAL_PORT
  80. #if WITHIN(LCD_SERIAL_PORT, 0, 3)
  81. #define LCD_SERIAL MSERIAL(LCD_SERIAL_PORT)
  82. #else
  83. #error "LCD_SERIAL_PORT must be from 0 to 3."
  84. #endif
  85. #endif
  86. #include "MarlinSerial.h"
  87. #include "MarlinSerialUSB.h"
  88. // ------------------------
  89. // Types
  90. // ------------------------
  91. typedef int8_t pin_t;
  92. #define SHARED_SERVOS HAS_SERVOS // Use shared/servos.cpp
  93. class Servo;
  94. typedef Servo hal_servo_t;
  95. //
  96. // Interrupts
  97. //
  98. #define sei() interrupts()
  99. #define cli() noInterrupts()
  100. #define CRITICAL_SECTION_START() const bool _irqon = hal.isr_state(); hal.isr_off()
  101. #define CRITICAL_SECTION_END() if (_irqon) hal.isr_on()
  102. //
  103. // ADC
  104. //
  105. #define HAL_ADC_VREF 3.3
  106. #define HAL_ADC_RESOLUTION 10
  107. #ifndef analogInputToDigitalPin
  108. #define analogInputToDigitalPin(p) ((p < 12U) ? (p) + 54U : -1)
  109. #endif
  110. //
  111. // Pin Mapping for M42, M43, M226
  112. //
  113. #define GET_PIN_MAP_PIN(index) index
  114. #define GET_PIN_MAP_INDEX(pin) pin
  115. #define PARSED_PIN_INDEX(code, dval) parser.intval(code, dval)
  116. //
  117. // Tone
  118. //
  119. void tone(const pin_t _pin, const unsigned int frequency, const unsigned long duration=0);
  120. void noTone(const pin_t _pin);
  121. // ------------------------
  122. // Class Utilities
  123. // ------------------------
  124. #pragma GCC diagnostic push
  125. #if GCC_VERSION <= 50000
  126. #pragma GCC diagnostic ignored "-Wunused-function"
  127. #endif
  128. #pragma GCC diagnostic pop
  129. #ifdef __cplusplus
  130. extern "C" {
  131. #endif
  132. char *dtostrf(double __val, signed char __width, unsigned char __prec, char *__s);
  133. #ifdef __cplusplus
  134. }
  135. #endif
  136. // Return free RAM between end of heap (or end bss) and whatever is current
  137. int freeMemory();
  138. // ------------------------
  139. // MarlinHAL Class
  140. // ------------------------
  141. class MarlinHAL {
  142. public:
  143. // Earliest possible init, before setup()
  144. MarlinHAL() {}
  145. // Watchdog
  146. static void watchdog_init() IF_DISABLED(USE_WATCHDOG, {});
  147. static void watchdog_refresh() IF_DISABLED(USE_WATCHDOG, {});
  148. static void init(); // Called early in setup()
  149. static void init_board(); // Called less early in setup()
  150. static void reboot(); // Restart the firmware
  151. // Interrupts
  152. static bool isr_state() { return !__get_PRIMASK(); }
  153. static void isr_on() { __enable_irq(); }
  154. static void isr_off() { __disable_irq(); }
  155. static void delay_ms(const int ms) { delay(ms); }
  156. // Tasks, called from idle()
  157. static void idletask();
  158. // Reset
  159. static uint8_t get_reset_source();
  160. static void clear_reset_source() {}
  161. // Free SRAM
  162. static int freeMemory() { return ::freeMemory(); }
  163. //
  164. // ADC Methods
  165. //
  166. static uint16_t adc_result;
  167. // Called by Temperature::init once at startup
  168. static void adc_init() {}
  169. // Called by Temperature::init for each sensor at startup
  170. static void adc_enable(const uint8_t /*ch*/) {}
  171. // Begin ADC sampling on the given channel. Called from Temperature::isr!
  172. static void adc_start(const uint8_t ch) { adc_result = analogRead(ch); }
  173. // Is the ADC ready for reading?
  174. static bool adc_ready() { return true; }
  175. // The current value of the ADC register
  176. static uint16_t adc_value() { return adc_result; }
  177. /**
  178. * Set the PWM duty cycle for the pin to the given value.
  179. * No inverting the duty cycle in this HAL.
  180. * No changing the maximum size of the provided value to enable finer PWM duty control in this HAL.
  181. */
  182. static void set_pwm_duty(const pin_t pin, const uint16_t v, const uint16_t=255, const bool=false) {
  183. analogWrite(pin, v);
  184. }
  185. };