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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. /**
  2. * Marlin 3D Printer Firmware
  3. *
  4. * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
  5. * SAMD51 HAL developed by Giuliano Zaro (AKA GMagician)
  6. *
  7. * This program is free software: you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation, either version 3 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  19. *
  20. */
  21. #pragma once
  22. #define CPU_32_BIT
  23. #include "../shared/Marduino.h"
  24. #include "../shared/math_32bit.h"
  25. #include "../shared/HAL_SPI.h"
  26. #include "fastio.h"
  27. #ifdef ADAFRUIT_GRAND_CENTRAL_M4
  28. #include "MarlinSerial_AGCM4.h"
  29. // Serial ports
  30. typedef ForwardSerial1Class< decltype(Serial) > DefaultSerial1;
  31. typedef ForwardSerial1Class< decltype(Serial1) > DefaultSerial2;
  32. typedef ForwardSerial1Class< decltype(Serial2) > DefaultSerial3;
  33. typedef ForwardSerial1Class< decltype(Serial3) > DefaultSerial4;
  34. typedef ForwardSerial1Class< decltype(Serial4) > DefaultSerial5;
  35. extern DefaultSerial1 MSerial0;
  36. extern DefaultSerial2 MSerial1;
  37. extern DefaultSerial3 MSerial2;
  38. extern DefaultSerial4 MSerial3;
  39. extern DefaultSerial5 MSerial4;
  40. #define __MSERIAL(X) MSerial##X
  41. #define _MSERIAL(X) __MSERIAL(X)
  42. #define MSERIAL(X) _MSERIAL(INCREMENT(X))
  43. #if SERIAL_PORT == -1
  44. #define MYSERIAL1 MSerial0
  45. #elif WITHIN(SERIAL_PORT, 0, 3)
  46. #define MYSERIAL1 MSERIAL(SERIAL_PORT)
  47. #else
  48. #error "SERIAL_PORT must be from 0 to 3. You can also use -1 if the board supports Native USB."
  49. #endif
  50. #ifdef SERIAL_PORT_2
  51. #if SERIAL_PORT_2 == -1
  52. #define MYSERIAL2 MSerial0
  53. #elif WITHIN(SERIAL_PORT_2, 0, 3)
  54. #define MYSERIAL2 MSERIAL(SERIAL_PORT_2)
  55. #else
  56. #error "SERIAL_PORT_2 must be from 0 to 3. You can also use -1 if the board supports Native USB."
  57. #endif
  58. #endif
  59. #ifdef MMU2_SERIAL_PORT
  60. #if MMU2_SERIAL_PORT == -1
  61. #define MMU2_SERIAL MSerial0
  62. #elif WITHIN(MMU2_SERIAL_PORT, 0, 3)
  63. #define MMU2_SERIAL MSERIAL(MMU2_SERIAL_PORT)
  64. #else
  65. #error "MMU2_SERIAL_PORT must be from 0 to 3. You can also use -1 if the board supports Native USB."
  66. #endif
  67. #endif
  68. #ifdef LCD_SERIAL_PORT
  69. #if LCD_SERIAL_PORT == -1
  70. #define LCD_SERIAL MSerial0
  71. #elif WITHIN(LCD_SERIAL_PORT, 0, 3)
  72. #define LCD_SERIAL MSERIAL(LCD_SERIAL_PORT)
  73. #else
  74. #error "LCD_SERIAL_PORT must be from 0 to 3. You can also use -1 if the board supports Native USB."
  75. #endif
  76. #endif
  77. #endif // ADAFRUIT_GRAND_CENTRAL_M4
  78. typedef int8_t pin_t;
  79. #define SHARED_SERVOS HAS_SERVOS // Use shared/servos.cpp
  80. class Servo;
  81. typedef Servo hal_servo_t;
  82. //
  83. // Interrupts
  84. //
  85. #define CRITICAL_SECTION_START() const bool irqon = !__get_PRIMASK(); __disable_irq()
  86. #define CRITICAL_SECTION_END() if (irqon) __enable_irq()
  87. #define cli() __disable_irq() // Disable interrupts
  88. #define sei() __enable_irq() // Enable interrupts
  89. //
  90. // ADC
  91. //
  92. //#define HAL_ADC_FILTERED // Disable Marlin's oversampling. The HAL filters ADC values.
  93. #define HAL_ADC_VREF 3.3
  94. #define HAL_ADC_RESOLUTION 10 // ... 12
  95. //
  96. // Pin Mapping for M42, M43, M226
  97. //
  98. #define GET_PIN_MAP_PIN(index) index
  99. #define GET_PIN_MAP_INDEX(pin) pin
  100. #define PARSED_PIN_INDEX(code, dval) parser.intval(code, dval)
  101. //
  102. // Tone
  103. //
  104. void tone(const pin_t _pin, const unsigned int frequency, const unsigned long duration=0);
  105. void noTone(const pin_t _pin);
  106. // ------------------------
  107. // Class Utilities
  108. // ------------------------
  109. #pragma GCC diagnostic push
  110. #if GCC_VERSION <= 50000
  111. #pragma GCC diagnostic ignored "-Wunused-function"
  112. #endif
  113. #ifdef __cplusplus
  114. extern "C" {
  115. #endif
  116. char *dtostrf(double __val, signed char __width, unsigned char __prec, char *__s);
  117. extern "C" int freeMemory();
  118. #ifdef __cplusplus
  119. }
  120. #endif
  121. #pragma GCC diagnostic pop
  122. // ------------------------
  123. // MarlinHAL Class
  124. // ------------------------
  125. class MarlinHAL {
  126. public:
  127. // Earliest possible init, before setup()
  128. MarlinHAL() {}
  129. // Watchdog
  130. static void watchdog_init() IF_DISABLED(USE_WATCHDOG, {});
  131. static void watchdog_refresh() IF_DISABLED(USE_WATCHDOG, {});
  132. static void init(); // Called early in setup()
  133. static void init_board() {} // Called less early in setup()
  134. static void reboot(); // Restart the firmware from 0x0
  135. // Interrupts
  136. static bool isr_state() { return !__get_PRIMASK(); }
  137. static void isr_on() { sei(); }
  138. static void isr_off() { cli(); }
  139. static void delay_ms(const int ms) { delay(ms); }
  140. // Tasks, called from idle()
  141. static void idletask() {}
  142. // Reset
  143. static uint8_t get_reset_source();
  144. static void clear_reset_source() {}
  145. // Free SRAM
  146. static int freeMemory() { return ::freeMemory(); }
  147. //
  148. // ADC Methods
  149. //
  150. static uint16_t adc_result;
  151. // Called by Temperature::init once at startup
  152. static void adc_init();
  153. // Called by Temperature::init for each sensor at startup
  154. static void adc_enable(const uint8_t ch) {}
  155. // Begin ADC sampling on the given pin. Called from Temperature::isr!
  156. static void adc_start(const pin_t pin);
  157. // Is the ADC ready for reading?
  158. static bool adc_ready() { return true; }
  159. // The current value of the ADC register
  160. static uint16_t adc_value() { return adc_result; }
  161. /**
  162. * Set the PWM duty cycle for the pin to the given value.
  163. * No option to invert the duty cycle [default = false]
  164. * No option to change the scale of the provided value to enable finer PWM duty control [default = 255]
  165. */
  166. static void set_pwm_duty(const pin_t pin, const uint16_t v, const uint16_t=255, const bool=false) {
  167. analogWrite(pin, v);
  168. }
  169. private:
  170. static void dma_init();
  171. };