My Marlin configs for Fabrikator Mini and CTC i3 Pro B
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

HAL.h 4.8KB

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