My Marlin configs for Fabrikator Mini and CTC i3 Pro B
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  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 Teensy 3.2 (MK20DX256)
  25. */
  26. #define CPU_32_BIT
  27. #include "../shared/Marduino.h"
  28. #include "../shared/math_32bit.h"
  29. #include "../shared/HAL_SPI.h"
  30. #include "fastio.h"
  31. #include "watchdog.h"
  32. #include <stdint.h>
  33. // ------------------------
  34. // Defines
  35. // ------------------------
  36. #define IS_32BIT_TEENSY 1
  37. #define IS_TEENSY_31_32 1
  38. #ifndef IS_TEENSY31
  39. #define IS_TEENSY32 1
  40. #endif
  41. #define CPU_ST7920_DELAY_1 600
  42. #define CPU_ST7920_DELAY_2 750
  43. #define CPU_ST7920_DELAY_3 750
  44. // ------------------------
  45. // Serial ports
  46. // ------------------------
  47. #include "../../core/serial_hook.h"
  48. #define Serial0 Serial
  49. #define _DECLARE_SERIAL(X) \
  50. typedef ForwardSerial1Class<decltype(Serial##X)> DefaultSerial##X; \
  51. extern DefaultSerial##X MSerial##X
  52. #define DECLARE_SERIAL(X) _DECLARE_SERIAL(X)
  53. typedef ForwardSerial1Class<decltype(SerialUSB)> USBSerialType;
  54. extern USBSerialType USBSerial;
  55. #define _MSERIAL(X) MSerial##X
  56. #define MSERIAL(X) _MSERIAL(X)
  57. #if SERIAL_PORT == -1
  58. #define MYSERIAL1 USBSerial
  59. #elif WITHIN(SERIAL_PORT, 0, 3)
  60. DECLARE_SERIAL(SERIAL_PORT);
  61. #define MYSERIAL1 MSERIAL(SERIAL_PORT)
  62. #else
  63. #error "The required SERIAL_PORT must be from 0 to 3, or -1 for Native USB."
  64. #endif
  65. // ------------------------
  66. // Types
  67. // ------------------------
  68. class libServo;
  69. typedef libServo hal_servo_t;
  70. typedef int8_t pin_t;
  71. // ------------------------
  72. // Interrupts
  73. // ------------------------
  74. uint32_t __get_PRIMASK(void); // CMSIS
  75. #define CRITICAL_SECTION_START() const bool irqon = !__get_PRIMASK(); __disable_irq()
  76. #define CRITICAL_SECTION_END() if (irqon) __enable_irq()
  77. // ------------------------
  78. // ADC
  79. // ------------------------
  80. #ifndef analogInputToDigitalPin
  81. #define analogInputToDigitalPin(p) ((p < 12U) ? (p) + 54U : -1)
  82. #endif
  83. #define HAL_ADC_VREF 3.3
  84. #define HAL_ADC_RESOLUTION 10
  85. //
  86. // Pin Mapping for M42, M43, M226
  87. //
  88. #define GET_PIN_MAP_PIN(index) index
  89. #define GET_PIN_MAP_INDEX(pin) pin
  90. #define PARSED_PIN_INDEX(code, dval) parser.intval(code, dval)
  91. // ------------------------
  92. // Class Utilities
  93. // ------------------------
  94. #pragma GCC diagnostic push
  95. #if GCC_VERSION <= 50000
  96. #pragma GCC diagnostic ignored "-Wunused-function"
  97. #endif
  98. extern "C" int freeMemory();
  99. #pragma GCC diagnostic pop
  100. // ------------------------
  101. // MarlinHAL Class
  102. // ------------------------
  103. class MarlinHAL {
  104. public:
  105. // Earliest possible init, before setup()
  106. MarlinHAL() {}
  107. static void init() {} // Called early in setup()
  108. static void init_board() {} // Called less early in setup()
  109. static void reboot(); // Restart the firmware from 0x0
  110. // Interrupts
  111. static bool isr_state() { return !__get_PRIMASK(); }
  112. static void isr_on() { __enable_irq(); }
  113. static void isr_off() { __disable_irq(); }
  114. static void delay_ms(const int ms) { delay(ms); }
  115. // Tasks, called from idle()
  116. static void idletask() {}
  117. // Reset
  118. static uint8_t get_reset_source();
  119. static void clear_reset_source() {}
  120. // Free SRAM
  121. static int freeMemory() { return ::freeMemory(); }
  122. //
  123. // ADC Methods
  124. //
  125. // Called by Temperature::init once at startup
  126. static void adc_init();
  127. // Called by Temperature::init for each sensor at startup
  128. static void adc_enable(const pin_t ch) {}
  129. // Begin ADC sampling on the given channel
  130. static void adc_start(const pin_t ch);
  131. // Is the ADC ready for reading?
  132. static bool adc_ready() { return true; }
  133. // The current value of the ADC register
  134. static uint16_t adc_value();
  135. /**
  136. * Set the PWM duty cycle for the pin to the given value.
  137. * No option to invert the duty cycle [default = false]
  138. * No option to change the scale of the provided value to enable finer PWM duty control [default = 255]
  139. */
  140. static void set_pwm_duty(const pin_t pin, const uint16_t v, const uint16_t=255, const bool=false) {
  141. analogWrite(pin, v);
  142. }
  143. };