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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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_SAMD51.h"
  27. #include "watchdog_SAMD51.h"
  28. #include "HAL_timers_SAMD51.h"
  29. #ifdef ADAFRUIT_GRAND_CENTRAL_M4
  30. #include "MarlinSerial_AGCM4.h"
  31. // Serial ports
  32. #if !WITHIN(SERIAL_PORT, -1, 3)
  33. #error "SERIAL_PORT must be from -1 to 3"
  34. #endif
  35. // MYSERIAL0 required before MarlinSerial includes!
  36. #if SERIAL_PORT == -1
  37. #define MYSERIAL0 Serial
  38. #elif SERIAL_PORT == 0
  39. #define MYSERIAL0 Serial1
  40. #elif SERIAL_PORT == 1
  41. #define MYSERIAL0 Serial2
  42. #elif SERIAL_PORT == 2
  43. #define MYSERIAL0 Serial3
  44. #else
  45. #define MYSERIAL0 Serial4
  46. #endif
  47. #ifdef SERIAL_PORT_2
  48. #if !WITHIN(SERIAL_PORT_2, -1, 3)
  49. #error "SERIAL_PORT_2 must be from -1 to 3"
  50. #elif SERIAL_PORT_2 == SERIAL_PORT
  51. #error "SERIAL_PORT_2 must be different than SERIAL_PORT"
  52. #endif
  53. #define NUM_SERIAL 2
  54. #if SERIAL_PORT_2 == -1
  55. #define MYSERIAL1 Serial
  56. #elif SERIAL_PORT_2 == 0
  57. #define MYSERIAL1 Serial1
  58. #elif SERIAL_PORT_2 == 1
  59. #define MYSERIAL1 Serial2
  60. #elif SERIAL_PORT_2 == 2
  61. #define MYSERIAL1 Serial3
  62. #else
  63. #define MYSERIAL1 Serial4
  64. #endif
  65. #else
  66. #define NUM_SERIAL 1
  67. #endif
  68. #endif // ADAFRUIT_GRAND_CENTRAL_M4
  69. typedef int8_t pin_t;
  70. //#define HAL_SERVO_LIB Servo
  71. //
  72. // Interrupts
  73. //
  74. #define CRITICAL_SECTION_START uint32_t primask = __get_PRIMASK(); __disable_irq()
  75. #define CRITICAL_SECTION_END if (!primask) __enable_irq()
  76. #define ISRS_ENABLED() (!__get_PRIMASK())
  77. #define ENABLE_ISRS() __enable_irq()
  78. #define DISABLE_ISRS() __disable_irq()
  79. #define cli() __disable_irq() // Disable interrupts
  80. #define sei() __enable_irq() // Enable interrupts
  81. void HAL_clear_reset_source(void); // clear reset reason
  82. uint8_t HAL_get_reset_source(void); // get reset reason
  83. //
  84. // EEPROM
  85. //
  86. void eeprom_write_byte(uint8_t *pos, unsigned char value);
  87. uint8_t eeprom_read_byte(uint8_t *pos);
  88. //
  89. // ADC
  90. //
  91. extern uint16_t HAL_adc_result; // result of last ADC conversion
  92. #define HAL_ANALOG_SELECT(pin)
  93. void HAL_adc_init(void);
  94. #define HAL_START_ADC(pin) HAL_adc_start_conversion(pin)
  95. #define HAL_READ_ADC() HAL_adc_result
  96. #define HAL_ADC_READY() true
  97. void HAL_adc_start_conversion(const uint8_t adc_pin);
  98. uint16_t HAL_adc_get_result(void);
  99. //
  100. // Pin Map
  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 toneInit();
  109. void tone(const pin_t _pin, const unsigned int frequency, const unsigned long duration=0);
  110. void noTone(const pin_t _pin);
  111. // Enable hooks into idle and setup for HAL
  112. void HAL_init(void);
  113. /*#define HAL_IDLETASK 1
  114. void HAL_idletask(void);*/
  115. //
  116. // Utility functions
  117. //
  118. FORCE_INLINE void _delay_ms(const int delay_ms) { delay(delay_ms); }
  119. int freeMemory(void);