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