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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  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 <http://www.gnu.org/licenses/>.
  20. *
  21. */
  22. #pragma once
  23. /**
  24. * Description: HAL for Arduino Due and compatible (SAM3X8E)
  25. *
  26. * For ARDUINO_ARCH_SAM
  27. */
  28. #define CPU_32_BIT
  29. #include "../shared/Marduino.h"
  30. #include "../shared/eeprom_if.h"
  31. #include "../shared/math_32bit.h"
  32. #include "../shared/HAL_SPI.h"
  33. #include "fastio.h"
  34. #include "watchdog.h"
  35. #include "timers.h"
  36. #include <stdint.h>
  37. // Define MYSERIAL0/1 before MarlinSerial includes!
  38. #if SERIAL_PORT == -1 || ENABLED(EMERGENCY_PARSER)
  39. #define MYSERIAL0 customizedSerial1
  40. #elif SERIAL_PORT == 0
  41. #define MYSERIAL0 Serial
  42. #elif SERIAL_PORT == 1
  43. #define MYSERIAL0 Serial1
  44. #elif SERIAL_PORT == 2
  45. #define MYSERIAL0 Serial2
  46. #elif SERIAL_PORT == 3
  47. #define MYSERIAL0 Serial3
  48. #else
  49. #error "The required SERIAL_PORT must be from -1 to 3. Please update your configuration."
  50. #endif
  51. #ifdef SERIAL_PORT_2
  52. #if SERIAL_PORT_2 == SERIAL_PORT
  53. #error "SERIAL_PORT_2 must be different from SERIAL_PORT. Please update your configuration."
  54. #elif SERIAL_PORT_2 == -1 || ENABLED(EMERGENCY_PARSER)
  55. #define MYSERIAL1 customizedSerial2
  56. #elif SERIAL_PORT_2 == 0
  57. #define MYSERIAL1 Serial
  58. #elif SERIAL_PORT_2 == 1
  59. #define MYSERIAL1 Serial1
  60. #elif SERIAL_PORT_2 == 2
  61. #define MYSERIAL1 Serial2
  62. #elif SERIAL_PORT_2 == 3
  63. #define MYSERIAL1 Serial3
  64. #else
  65. #error "SERIAL_PORT_2 must be from -1 to 3. Please update your configuration."
  66. #endif
  67. #define NUM_SERIAL 2
  68. #else
  69. #define NUM_SERIAL 1
  70. #endif
  71. #ifdef DGUS_SERIAL_PORT
  72. #if DGUS_SERIAL_PORT == SERIAL_PORT
  73. #error "DGUS_SERIAL_PORT must be different from SERIAL_PORT. Please update your configuration."
  74. #elif defined(SERIAL_PORT_2) && DGUS_SERIAL_PORT == SERIAL_PORT_2
  75. #error "DGUS_SERIAL_PORT must be different than SERIAL_PORT_2. Please update your configuration."
  76. #elif DGUS_SERIAL_PORT == -1
  77. #define DGUS_SERIAL internalDgusSerial
  78. #elif DGUS_SERIAL_PORT == 0
  79. #define DGUS_SERIAL Serial
  80. #elif DGUS_SERIAL_PORT == 1
  81. #define DGUS_SERIAL Serial1
  82. #elif DGUS_SERIAL_PORT == 2
  83. #define DGUS_SERIAL Serial2
  84. #elif DGUS_SERIAL_PORT == 3
  85. #define DGUS_SERIAL Serial3
  86. #else
  87. #error "DGUS_SERIAL_PORT must be from -1 to 3. Please update your configuration."
  88. #endif
  89. #endif
  90. #include "MarlinSerial.h"
  91. #include "MarlinSerialUSB.h"
  92. // On AVR this is in math.h?
  93. #define square(x) ((x)*(x))
  94. #ifndef strncpy_P
  95. #define strncpy_P(dest, src, num) strncpy((dest), (src), (num))
  96. #endif
  97. // Fix bug in pgm_read_ptr
  98. #undef pgm_read_ptr
  99. #define pgm_read_ptr(addr) (*((void**)(addr)))
  100. #undef pgm_read_word
  101. #define pgm_read_word(addr) (*((uint16_t*)(addr)))
  102. typedef int8_t pin_t;
  103. #define SHARED_SERVOS HAS_SERVOS
  104. #define HAL_SERVO_LIB Servo
  105. //
  106. // Interrupts
  107. //
  108. #define CRITICAL_SECTION_START() uint32_t primask = __get_PRIMASK(); __disable_irq()
  109. #define CRITICAL_SECTION_END() if (!primask) __enable_irq()
  110. #define ISRS_ENABLED() (!__get_PRIMASK())
  111. #define ENABLE_ISRS() __enable_irq()
  112. #define DISABLE_ISRS() __disable_irq()
  113. void cli(); // Disable interrupts
  114. void sei(); // Enable interrupts
  115. void HAL_clear_reset_source(); // clear reset reason
  116. uint8_t HAL_get_reset_source(); // get reset reason
  117. //
  118. // ADC
  119. //
  120. extern uint16_t HAL_adc_result; // result of last ADC conversion
  121. #ifndef analogInputToDigitalPin
  122. #define analogInputToDigitalPin(p) ((p < 12u) ? (p) + 54u : -1)
  123. #endif
  124. #define HAL_ANALOG_SELECT(ch)
  125. inline void HAL_adc_init() {}//todo
  126. #define HAL_START_ADC(ch) HAL_adc_start_conversion(ch)
  127. #define HAL_ADC_RESOLUTION 10
  128. #define HAL_READ_ADC() HAL_adc_result
  129. #define HAL_ADC_READY() true
  130. void HAL_adc_start_conversion(const uint8_t ch);
  131. uint16_t HAL_adc_get_result();
  132. //
  133. // Pin Map
  134. //
  135. #define GET_PIN_MAP_PIN(index) index
  136. #define GET_PIN_MAP_INDEX(pin) pin
  137. #define PARSED_PIN_INDEX(code, dval) parser.intval(code, dval)
  138. //
  139. // Tone
  140. //
  141. void toneInit();
  142. void tone(const pin_t _pin, const unsigned int frequency, const unsigned long duration=0);
  143. void noTone(const pin_t _pin);
  144. // Enable hooks into idle and setup for HAL
  145. #define HAL_IDLETASK 1
  146. void HAL_idletask();
  147. void HAL_init();
  148. //
  149. // Utility functions
  150. //
  151. void _delay_ms(const int delay);
  152. #pragma GCC diagnostic push
  153. #pragma GCC diagnostic ignored "-Wunused-function"
  154. int freeMemory();
  155. #pragma GCC diagnostic pop
  156. #ifdef __cplusplus
  157. extern "C" {
  158. #endif
  159. char *dtostrf(double __val, signed char __width, unsigned char __prec, char *__s);
  160. #ifdef __cplusplus
  161. }
  162. #endif