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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. /**
  2. * Marlin 3D Printer Firmware
  3. *
  4. * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
  5. * Copyright (c) 2016 Bob Cousins bobcousins42@googlemail.com
  6. * Copyright (c) 2015-2016 Nico Tonnhofer wurstnase.reprap@gmail.com
  7. *
  8. * This program is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation, either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  20. *
  21. */
  22. #pragma once
  23. /**
  24. * HAL for Arduino Due and compatible (SAM3X8E)
  25. */
  26. #define CPU_32_BIT
  27. #include "../shared/Marduino.h"
  28. #include "../shared/eeprom_if.h"
  29. #include "../shared/math_32bit.h"
  30. #include "../shared/HAL_SPI.h"
  31. #include "fastio.h"
  32. #include "watchdog.h"
  33. #include <stdint.h>
  34. #include "../../core/serial_hook.h"
  35. typedef ForwardSerial0Type< decltype(Serial) > DefaultSerial;
  36. extern DefaultSerial MSerial;
  37. typedef ForwardSerial0Type< decltype(Serial1) > DefaultSerial1;
  38. typedef ForwardSerial0Type< decltype(Serial2) > DefaultSerial2;
  39. typedef ForwardSerial0Type< decltype(Serial3) > DefaultSerial3;
  40. extern DefaultSerial1 MSerial1;
  41. extern DefaultSerial2 MSerial2;
  42. extern DefaultSerial3 MSerial3;
  43. #define _MSERIAL(X) MSerial##X
  44. #define MSERIAL(X) _MSERIAL(X)
  45. #define MSerial0 MSerial
  46. // Define MYSERIAL0/1 before MarlinSerial includes!
  47. #if SERIAL_PORT == -1 || ENABLED(EMERGENCY_PARSER)
  48. #define MYSERIAL0 customizedSerial1
  49. #elif WITHIN(SERIAL_PORT, 0, 3)
  50. #define MYSERIAL0 MSERIAL(SERIAL_PORT)
  51. #else
  52. #error "The required SERIAL_PORT must be from -1 to 3. Please update your configuration."
  53. #endif
  54. #ifdef SERIAL_PORT_2
  55. #if SERIAL_PORT_2 == -1 || ENABLED(EMERGENCY_PARSER)
  56. #define MYSERIAL1 customizedSerial2
  57. #elif WITHIN(SERIAL_PORT_2, 0, 3)
  58. #define MYSERIAL1 MSERIAL(SERIAL_PORT_2)
  59. #else
  60. #error "SERIAL_PORT_2 must be from -1 to 3. Please update your configuration."
  61. #endif
  62. #endif
  63. #ifdef MMU2_SERIAL_PORT
  64. #if WITHIN(MMU2_SERIAL_PORT, 0, 3)
  65. #define MMU2_SERIAL MSERIAL(MMU2_SERIAL_PORT)
  66. #else
  67. #error "MMU2_SERIAL_PORT must be from 0 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 lcdSerial
  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. #include "MarlinSerial.h"
  80. #include "MarlinSerialUSB.h"
  81. // On AVR this is in math.h?
  82. #define square(x) ((x)*(x))
  83. typedef int8_t pin_t;
  84. #define SHARED_SERVOS HAS_SERVOS
  85. #define HAL_SERVO_LIB Servo
  86. //
  87. // Interrupts
  88. //
  89. #define CRITICAL_SECTION_START() uint32_t primask = __get_PRIMASK(); __disable_irq()
  90. #define CRITICAL_SECTION_END() if (!primask) __enable_irq()
  91. #define ISRS_ENABLED() (!__get_PRIMASK())
  92. #define ENABLE_ISRS() __enable_irq()
  93. #define DISABLE_ISRS() __disable_irq()
  94. void cli(); // Disable interrupts
  95. void sei(); // Enable interrupts
  96. void HAL_clear_reset_source(); // clear reset reason
  97. uint8_t HAL_get_reset_source(); // get reset reason
  98. inline void HAL_reboot() {} // reboot the board or restart the bootloader
  99. //
  100. // ADC
  101. //
  102. extern uint16_t HAL_adc_result; // result of last ADC conversion
  103. #ifndef analogInputToDigitalPin
  104. #define analogInputToDigitalPin(p) ((p < 12U) ? (p) + 54U : -1)
  105. #endif
  106. #define HAL_ANALOG_SELECT(ch)
  107. inline void HAL_adc_init() {}//todo
  108. #define HAL_ADC_VREF 3.3
  109. #define HAL_ADC_RESOLUTION 10
  110. #define HAL_START_ADC(ch) HAL_adc_start_conversion(ch)
  111. #define HAL_READ_ADC() HAL_adc_result
  112. #define HAL_ADC_READY() true
  113. void HAL_adc_start_conversion(const uint8_t ch);
  114. uint16_t HAL_adc_get_result();
  115. //
  116. // Pin Map
  117. //
  118. #define GET_PIN_MAP_PIN(index) index
  119. #define GET_PIN_MAP_INDEX(pin) pin
  120. #define PARSED_PIN_INDEX(code, dval) parser.intval(code, dval)
  121. //
  122. // Tone
  123. //
  124. void toneInit();
  125. void tone(const pin_t _pin, const unsigned int frequency, const unsigned long duration=0);
  126. void noTone(const pin_t _pin);
  127. // Enable hooks into idle and setup for HAL
  128. #define HAL_IDLETASK 1
  129. void HAL_idletask();
  130. void HAL_init();
  131. //
  132. // Utility functions
  133. //
  134. void _delay_ms(const int delay);
  135. #if GCC_VERSION <= 50000
  136. #pragma GCC diagnostic push
  137. #pragma GCC diagnostic ignored "-Wunused-function"
  138. #endif
  139. int freeMemory();
  140. #if GCC_VERSION <= 50000
  141. #pragma GCC diagnostic pop
  142. #endif
  143. #ifdef __cplusplus
  144. extern "C" {
  145. #endif
  146. char *dtostrf(double __val, signed char __width, unsigned char __prec, char *__s);
  147. #ifdef __cplusplus
  148. }
  149. #endif