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.

HAL.h 4.9KB

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