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

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