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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  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. * Copyright (c) 2017 Victor Perez
  8. *
  9. * This program is free software: you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation, either version 3 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  21. *
  22. */
  23. #pragma once
  24. #define CPU_32_BIT
  25. #include "../../core/macros.h"
  26. #include "../shared/Marduino.h"
  27. #include "../shared/math_32bit.h"
  28. #include "../shared/HAL_SPI.h"
  29. #include "fastio.h"
  30. #include "watchdog.h"
  31. #include "MarlinSerial.h"
  32. #include "../../inc/MarlinConfigPre.h"
  33. #include <stdint.h>
  34. #ifdef USBCON
  35. #include <USBSerial.h>
  36. #endif
  37. // ------------------------
  38. // Defines
  39. // ------------------------
  40. #define _MSERIAL(X) MSerial##X
  41. #define MSERIAL(X) _MSERIAL(X)
  42. #if SERIAL_PORT == -1
  43. #define MYSERIAL0 SerialUSB
  44. #elif WITHIN(SERIAL_PORT, 1, 6)
  45. #define MYSERIAL0 MSERIAL(SERIAL_PORT)
  46. #else
  47. #error "SERIAL_PORT must be -1 or from 1 to 6. Please update your configuration."
  48. #endif
  49. #ifdef SERIAL_PORT_2
  50. #if SERIAL_PORT_2 == -1
  51. #define MYSERIAL1 SerialUSB
  52. #elif WITHIN(SERIAL_PORT_2, 1, 6)
  53. #define MYSERIAL1 MSERIAL(SERIAL_PORT_2)
  54. #else
  55. #error "SERIAL_PORT_2 must be -1 or from 1 to 6. Please update your configuration."
  56. #endif
  57. #endif
  58. #if HAS_DGUS_LCD
  59. #if DGUS_SERIAL_PORT == -1
  60. #define DGUS_SERIAL SerialUSB
  61. #elif WITHIN(DGUS_SERIAL_PORT, 1, 6)
  62. #define DGUS_SERIAL MSERIAL(DGUS_SERIAL_PORT)
  63. #else
  64. #error "DGUS_SERIAL_PORT must be -1 or from 1 to 6. Please update your configuration."
  65. #endif
  66. #define DGUS_SERIAL_GET_TX_BUFFER_FREE DGUS_SERIAL.availableForWrite
  67. #endif
  68. #if ENABLED(MALYAN_LCD)
  69. #if LCD_SERIAL_PORT == -1
  70. #define LCD_SERIAL SerialUSB
  71. #elif WITHIN(LCD_SERIAL_PORT, 1, 6)
  72. #define LCD_SERIAL MSERIAL(LCD_SERIAL_PORT)
  73. #else
  74. #error "LCD_SERIAL_PORT must be -1 or from 1 to 6. Please update your configuration."
  75. #endif
  76. #endif
  77. /**
  78. * TODO: review this to return 1 for pins that are not analog input
  79. */
  80. #ifndef analogInputToDigitalPin
  81. #define analogInputToDigitalPin(p) (p)
  82. #endif
  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. #define cli() __disable_irq()
  89. #define sei() __enable_irq()
  90. // On AVR this is in math.h?
  91. #define square(x) ((x)*(x))
  92. #ifndef strncpy_P
  93. #define strncpy_P(dest, src, num) strncpy((dest), (src), (num))
  94. #endif
  95. // Fix bug in pgm_read_ptr
  96. #undef pgm_read_ptr
  97. #define pgm_read_ptr(addr) (*(addr))
  98. // ------------------------
  99. // Types
  100. // ------------------------
  101. typedef int16_t pin_t;
  102. #define HAL_SERVO_LIB libServo
  103. // ------------------------
  104. // Public Variables
  105. // ------------------------
  106. // result of last ADC conversion
  107. extern uint16_t HAL_adc_result;
  108. // ------------------------
  109. // Public functions
  110. // ------------------------
  111. // Memory related
  112. #define __bss_end __bss_end__
  113. // Enable hooks into setup for HAL
  114. void HAL_init();
  115. // Clear reset reason
  116. void HAL_clear_reset_source();
  117. // Reset reason
  118. uint8_t HAL_get_reset_source();
  119. void _delay_ms(const int delay);
  120. extern "C" char* _sbrk(int incr);
  121. #pragma GCC diagnostic push
  122. #pragma GCC diagnostic ignored "-Wunused-function"
  123. static inline int freeMemory() {
  124. volatile char top;
  125. return &top - reinterpret_cast<char*>(_sbrk(0));
  126. }
  127. #pragma GCC diagnostic pop
  128. //
  129. // ADC
  130. //
  131. #define HAL_ANALOG_SELECT(pin) pinMode(pin, INPUT)
  132. inline void HAL_adc_init() {}
  133. #define HAL_ADC_VREF 3.3
  134. #define HAL_ADC_RESOLUTION 10
  135. #define HAL_START_ADC(pin) HAL_adc_start_conversion(pin)
  136. #define HAL_READ_ADC() HAL_adc_result
  137. #define HAL_ADC_READY() true
  138. void HAL_adc_start_conversion(const uint8_t adc_pin);
  139. uint16_t HAL_adc_get_result();
  140. #define GET_PIN_MAP_PIN(index) index
  141. #define GET_PIN_MAP_INDEX(pin) pin
  142. #define PARSED_PIN_INDEX(code, dval) parser.intval(code, dval)
  143. #ifdef STM32F1xx
  144. #define JTAG_DISABLE() AFIO_DBGAFR_CONFIG(AFIO_MAPR_SWJ_CFG_JTAGDISABLE)
  145. #define JTAGSWD_DISABLE() AFIO_DBGAFR_CONFIG(AFIO_MAPR_SWJ_CFG_DISABLE)
  146. #endif
  147. #define PLATFORM_M997_SUPPORT
  148. void flashFirmware(const int16_t);