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.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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. #include "watchdog.h"
  28. #ifdef ADAFRUIT_GRAND_CENTRAL_M4
  29. #include "MarlinSerial_AGCM4.h"
  30. // Serial ports
  31. // MYSERIAL0 required before MarlinSerial includes!
  32. #define __MSERIAL(X) Serial##X
  33. #define _MSERIAL(X) __MSERIAL(X)
  34. #define MSERIAL(X) _MSERIAL(INCREMENT(X))
  35. #if SERIAL_PORT == -1
  36. #define MYSERIAL0 Serial
  37. #elif WITHIN(SERIAL_PORT, 0, 3)
  38. #define MYSERIAL0 MSERIAL(SERIAL_PORT)
  39. #else
  40. #error "SERIAL_PORT must be from -1 to 3. Please update your configuration."
  41. #endif
  42. #ifdef SERIAL_PORT_2
  43. #if SERIAL_PORT_2 == -1
  44. #define MYSERIAL1 Serial
  45. #elif WITHIN(SERIAL_PORT_2, 0, 3)
  46. #define MYSERIAL1 MSERIAL(SERIAL_PORT_2)
  47. #else
  48. #error "SERIAL_PORT_2 must be from -1 to 3. Please update your configuration."
  49. #endif
  50. #endif
  51. #ifdef LCD_SERIAL_PORT
  52. #if LCD_SERIAL_PORT == -1
  53. #define LCD_SERIAL Serial
  54. #elif WITHIN(LCD_SERIAL_PORT, 0, 3)
  55. #define LCD_SERIAL MSERIAL(LCD_SERIAL_PORT)
  56. #else
  57. #error "LCD_SERIAL_PORT must be from -1 to 3. Please update your configuration."
  58. #endif
  59. #endif
  60. #endif // ADAFRUIT_GRAND_CENTRAL_M4
  61. typedef int8_t pin_t;
  62. #define SHARED_SERVOS HAS_SERVOS
  63. #define HAL_SERVO_LIB Servo
  64. //
  65. // Interrupts
  66. //
  67. #define CRITICAL_SECTION_START() uint32_t primask = __get_PRIMASK(); __disable_irq()
  68. #define CRITICAL_SECTION_END() if (!primask) __enable_irq()
  69. #define ISRS_ENABLED() (!__get_PRIMASK())
  70. #define ENABLE_ISRS() __enable_irq()
  71. #define DISABLE_ISRS() __disable_irq()
  72. #define cli() __disable_irq() // Disable interrupts
  73. #define sei() __enable_irq() // Enable interrupts
  74. void HAL_clear_reset_source(); // clear reset reason
  75. uint8_t HAL_get_reset_source(); // get reset reason
  76. inline void HAL_reboot() {} // reboot the board or restart the bootloader
  77. //
  78. // ADC
  79. //
  80. extern uint16_t HAL_adc_result; // Most recent ADC conversion
  81. #define HAL_ANALOG_SELECT(pin)
  82. void HAL_adc_init();
  83. //#define HAL_ADC_FILTERED // Disable Marlin's oversampling. The HAL filters ADC values.
  84. #define HAL_ADC_VREF 3.3
  85. #define HAL_ADC_RESOLUTION 10 // ... 12
  86. #define HAL_START_ADC(pin) HAL_adc_start_conversion(pin)
  87. #define HAL_READ_ADC() HAL_adc_result
  88. #define HAL_ADC_READY() true
  89. void HAL_adc_start_conversion(const uint8_t adc_pin);
  90. //
  91. // Pin Map
  92. //
  93. #define GET_PIN_MAP_PIN(index) index
  94. #define GET_PIN_MAP_INDEX(pin) pin
  95. #define PARSED_PIN_INDEX(code, dval) parser.intval(code, dval)
  96. //
  97. // Tone
  98. //
  99. void toneInit();
  100. void tone(const pin_t _pin, const unsigned int frequency, const unsigned long duration=0);
  101. void noTone(const pin_t _pin);
  102. // Enable hooks into idle and setup for HAL
  103. void HAL_init();
  104. /*
  105. #define HAL_IDLETASK 1
  106. void HAL_idletask();
  107. */
  108. //
  109. // Utility functions
  110. //
  111. FORCE_INLINE void _delay_ms(const int delay_ms) { delay(delay_ms); }
  112. #pragma GCC diagnostic push
  113. #pragma GCC diagnostic ignored "-Wunused-function"
  114. int freeMemory();
  115. #pragma GCC diagnostic pop
  116. #ifdef __cplusplus
  117. extern "C" {
  118. #endif
  119. char *dtostrf(double __val, signed char __width, unsigned char __prec, char *__s);
  120. #ifdef __cplusplus
  121. }
  122. #endif