My Marlin configs for Fabrikator Mini and CTC i3 Pro B
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

HAL.h 4.8KB

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