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

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