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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. /**
  2. * Marlin 3D Printer Firmware
  3. *
  4. * Copyright (c) 2019 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 <http://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. #include "timers.h"
  29. #ifdef ADAFRUIT_GRAND_CENTRAL_M4
  30. #include "MarlinSerial_AGCM4.h"
  31. // Serial ports
  32. // MYSERIAL0 required before MarlinSerial includes!
  33. #if SERIAL_PORT == -1
  34. #define MYSERIAL0 Serial
  35. #elif SERIAL_PORT == 0
  36. #define MYSERIAL0 Serial1
  37. #elif SERIAL_PORT == 1
  38. #define MYSERIAL0 Serial2
  39. #elif SERIAL_PORT == 2
  40. #define MYSERIAL0 Serial3
  41. #elif SERIAL_PORT == 3
  42. #define MYSERIAL0 Serial4
  43. #else
  44. #error "SERIAL_PORT must be from -1 to 3. Please update your configuration."
  45. #endif
  46. #ifdef SERIAL_PORT_2
  47. #if SERIAL_PORT_2 == SERIAL_PORT
  48. #error "SERIAL_PORT_2 must be different than SERIAL_PORT. Please update your configuration."
  49. #elif SERIAL_PORT_2 == -1
  50. #define MYSERIAL1 Serial
  51. #elif SERIAL_PORT_2 == 0
  52. #define MYSERIAL1 Serial1
  53. #elif SERIAL_PORT_2 == 1
  54. #define MYSERIAL1 Serial2
  55. #elif SERIAL_PORT_2 == 2
  56. #define MYSERIAL1 Serial3
  57. #elif SERIAL_PORT_2 == 3
  58. #define MYSERIAL1 Serial4
  59. #else
  60. #error "SERIAL_PORT_2 must be from -1 to 3. Please update your configuration."
  61. #endif
  62. #define NUM_SERIAL 2
  63. #else
  64. #define NUM_SERIAL 1
  65. #endif
  66. #endif // ADAFRUIT_GRAND_CENTRAL_M4
  67. typedef int8_t pin_t;
  68. #define SHARED_SERVOS HAS_SERVOS
  69. #define HAL_SERVO_LIB Servo
  70. //
  71. // Interrupts
  72. //
  73. #define CRITICAL_SECTION_START uint32_t primask = __get_PRIMASK(); __disable_irq()
  74. #define CRITICAL_SECTION_END if (!primask) __enable_irq()
  75. #define ISRS_ENABLED() (!__get_PRIMASK())
  76. #define ENABLE_ISRS() __enable_irq()
  77. #define DISABLE_ISRS() __disable_irq()
  78. #define cli() __disable_irq() // Disable interrupts
  79. #define sei() __enable_irq() // Enable interrupts
  80. void HAL_clear_reset_source(); // clear reset reason
  81. uint8_t HAL_get_reset_source(); // get reset reason
  82. //
  83. // EEPROM
  84. //
  85. void eeprom_write_byte(uint8_t *pos, unsigned char value);
  86. uint8_t eeprom_read_byte(uint8_t *pos);
  87. //
  88. // ADC
  89. //
  90. extern uint16_t HAL_adc_result; // result of last ADC conversion
  91. #define HAL_ANALOG_SELECT(pin)
  92. void HAL_adc_init();
  93. #define HAL_ADC_FILTERED // Disable oversampling done in Marlin as ADC values already filtered in HAL
  94. #define HAL_ADC_RESOLUTION 12
  95. #define HAL_START_ADC(pin) HAL_adc_start_conversion(pin)
  96. #define HAL_READ_ADC() HAL_adc_result
  97. #define HAL_ADC_READY() true
  98. void HAL_adc_start_conversion(const uint8_t adc_pin);
  99. uint16_t HAL_adc_get_result();
  100. //
  101. // Pin Map
  102. //
  103. #define GET_PIN_MAP_PIN(index) index
  104. #define GET_PIN_MAP_INDEX(pin) pin
  105. #define PARSED_PIN_INDEX(code, dval) parser.intval(code, dval)
  106. //
  107. // Tone
  108. //
  109. void toneInit();
  110. void tone(const pin_t _pin, const unsigned int frequency, const unsigned long duration=0);
  111. void noTone(const pin_t _pin);
  112. // Enable hooks into idle and setup for HAL
  113. void HAL_init();
  114. /*
  115. #define HAL_IDLETASK 1
  116. void HAL_idletask();
  117. */
  118. //
  119. // Utility functions
  120. //
  121. FORCE_INLINE void _delay_ms(const int delay_ms) { delay(delay_ms); }
  122. #pragma GCC diagnostic push
  123. #pragma GCC diagnostic ignored "-Wunused-function"
  124. int freeMemory();
  125. #pragma GCC diagnostic pop
  126. #ifdef __cplusplus
  127. extern "C" {
  128. #endif
  129. char *dtostrf(double __val, signed char __width, unsigned char __prec, char *__s);
  130. #ifdef __cplusplus
  131. }
  132. #endif