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 6.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. /**
  2. * Marlin 3D Printer Firmware
  3. * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
  4. *
  5. * Based on Sprinter and grbl.
  6. * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
  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. * SAMD51 HAL developed by Giuliano Zaro (AKA GMagician)
  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. #ifdef ADAFRUIT_GRAND_CENTRAL_M4
  32. #include "MarlinSerial_AGCM4.h"
  33. // Serial ports
  34. typedef ForwardSerial1Class< decltype(Serial) > DefaultSerial1;
  35. typedef ForwardSerial1Class< decltype(Serial1) > DefaultSerial2;
  36. typedef ForwardSerial1Class< decltype(Serial2) > DefaultSerial3;
  37. typedef ForwardSerial1Class< decltype(Serial3) > DefaultSerial4;
  38. typedef ForwardSerial1Class< decltype(Serial4) > DefaultSerial5;
  39. extern DefaultSerial1 MSerial0;
  40. extern DefaultSerial2 MSerial1;
  41. extern DefaultSerial3 MSerial2;
  42. extern DefaultSerial4 MSerial3;
  43. extern DefaultSerial5 MSerial4;
  44. #define __MSERIAL(X) MSerial##X
  45. #define _MSERIAL(X) __MSERIAL(X)
  46. #define MSERIAL(X) _MSERIAL(INCREMENT(X))
  47. #if SERIAL_PORT == -1
  48. #define MYSERIAL1 MSerial0
  49. #elif WITHIN(SERIAL_PORT, 0, 3)
  50. #define MYSERIAL1 MSERIAL(SERIAL_PORT)
  51. #else
  52. #error "SERIAL_PORT must be from 0 to 3. You can also use -1 if the board supports Native USB."
  53. #endif
  54. #ifdef SERIAL_PORT_2
  55. #if SERIAL_PORT_2 == -1
  56. #define MYSERIAL2 MSerial0
  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. You can also use -1 if the board supports Native USB."
  61. #endif
  62. #endif
  63. #ifdef MMU2_SERIAL_PORT
  64. #if MMU2_SERIAL_PORT == -1
  65. #define MMU2_SERIAL MSerial0
  66. #elif WITHIN(MMU2_SERIAL_PORT, 0, 3)
  67. #define MMU2_SERIAL MSERIAL(MMU2_SERIAL_PORT)
  68. #else
  69. #error "MMU2_SERIAL_PORT must be from 0 to 3. You can also use -1 if the board supports Native USB."
  70. #endif
  71. #endif
  72. #ifdef LCD_SERIAL_PORT
  73. #if LCD_SERIAL_PORT == -1
  74. #define LCD_SERIAL MSerial0
  75. #elif WITHIN(LCD_SERIAL_PORT, 0, 3)
  76. #define LCD_SERIAL MSERIAL(LCD_SERIAL_PORT)
  77. #else
  78. #error "LCD_SERIAL_PORT must be from 0 to 3. You can also use -1 if the board supports Native USB."
  79. #endif
  80. #endif
  81. #endif // ADAFRUIT_GRAND_CENTRAL_M4
  82. typedef int8_t pin_t;
  83. #define SHARED_SERVOS HAS_SERVOS // Use shared/servos.cpp
  84. class Servo;
  85. typedef Servo hal_servo_t;
  86. //
  87. // Interrupts
  88. //
  89. #define CRITICAL_SECTION_START() const bool irqon = !__get_PRIMASK(); __disable_irq()
  90. #define CRITICAL_SECTION_END() if (irqon) __enable_irq()
  91. #define cli() __disable_irq() // Disable interrupts
  92. #define sei() __enable_irq() // Enable interrupts
  93. //
  94. // ADC
  95. //
  96. //#define HAL_ADC_FILTERED // Disable Marlin's oversampling. The HAL filters ADC values.
  97. #define HAL_ADC_VREF 3.3
  98. #define HAL_ADC_RESOLUTION 10 // ... 12
  99. //
  100. // Pin Mapping for M42, M43, M226
  101. //
  102. #define GET_PIN_MAP_PIN(index) index
  103. #define GET_PIN_MAP_INDEX(pin) pin
  104. #define PARSED_PIN_INDEX(code, dval) parser.intval(code, dval)
  105. //
  106. // Tone
  107. //
  108. void tone(const pin_t _pin, const unsigned int frequency, const unsigned long duration=0);
  109. void noTone(const pin_t _pin);
  110. // ------------------------
  111. // Class Utilities
  112. // ------------------------
  113. #pragma GCC diagnostic push
  114. #if GCC_VERSION <= 50000
  115. #pragma GCC diagnostic ignored "-Wunused-function"
  116. #endif
  117. #ifdef __cplusplus
  118. extern "C" {
  119. #endif
  120. char *dtostrf(double __val, signed char __width, unsigned char __prec, char *__s);
  121. extern "C" int freeMemory();
  122. #ifdef __cplusplus
  123. }
  124. #endif
  125. #pragma GCC diagnostic pop
  126. // ------------------------
  127. // MarlinHAL Class
  128. // ------------------------
  129. class MarlinHAL {
  130. public:
  131. // Earliest possible init, before setup()
  132. MarlinHAL() {}
  133. // Watchdog
  134. static void watchdog_init() IF_DISABLED(USE_WATCHDOG, {});
  135. static void watchdog_refresh() IF_DISABLED(USE_WATCHDOG, {});
  136. static void init(); // Called early in setup()
  137. static void init_board() {} // Called less early in setup()
  138. static void reboot(); // Restart the firmware from 0x0
  139. // Interrupts
  140. static bool isr_state() { return !__get_PRIMASK(); }
  141. static void isr_on() { sei(); }
  142. static void isr_off() { cli(); }
  143. static void delay_ms(const int ms) { delay(ms); }
  144. // Tasks, called from idle()
  145. static void idletask() {}
  146. // Reset
  147. static uint8_t get_reset_source();
  148. static void clear_reset_source() {}
  149. // Free SRAM
  150. static int freeMemory() { return ::freeMemory(); }
  151. //
  152. // ADC Methods
  153. //
  154. static uint16_t adc_result;
  155. // Called by Temperature::init once at startup
  156. static void adc_init();
  157. // Called by Temperature::init for each sensor at startup
  158. static void adc_enable(const uint8_t ch) {}
  159. // Begin ADC sampling on the given pin. Called from Temperature::isr!
  160. static void adc_start(const pin_t pin);
  161. // Is the ADC ready for reading?
  162. static bool adc_ready() { return true; }
  163. // The current value of the ADC register
  164. static uint16_t adc_value() { return adc_result; }
  165. /**
  166. * Set the PWM duty cycle for the pin to the given value.
  167. * No option to invert the duty cycle [default = false]
  168. * No option to change the scale of the provided value to enable finer PWM duty control [default = 255]
  169. */
  170. static void set_pwm_duty(const pin_t pin, const uint16_t v, const uint16_t=255, const bool=false) {
  171. analogWrite(pin, v);
  172. }
  173. private:
  174. static void dma_init();
  175. };