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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  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. #ifdef LCD_SERIAL_PORT
  59. #if LCD_SERIAL_PORT == -1
  60. #define LCD_SERIAL SerialUSB
  61. #elif WITHIN(LCD_SERIAL_PORT, 1, 6)
  62. #define LCD_SERIAL MSERIAL(LCD_SERIAL_PORT)
  63. #else
  64. #error "LCD_SERIAL_PORT must be -1 or from 1 to 6. Please update your configuration."
  65. #endif
  66. #if HAS_DGUS_LCD
  67. #define SERIAL_GET_TX_BUFFER_FREE() LCD_SERIAL.availableForWrite()
  68. #endif
  69. #endif
  70. /**
  71. * TODO: review this to return 1 for pins that are not analog input
  72. */
  73. #ifndef analogInputToDigitalPin
  74. #define analogInputToDigitalPin(p) (p)
  75. #endif
  76. #define CRITICAL_SECTION_START() uint32_t primask = __get_PRIMASK(); __disable_irq()
  77. #define CRITICAL_SECTION_END() if (!primask) __enable_irq()
  78. #define ISRS_ENABLED() (!__get_PRIMASK())
  79. #define ENABLE_ISRS() __enable_irq()
  80. #define DISABLE_ISRS() __disable_irq()
  81. #define cli() __disable_irq()
  82. #define sei() __enable_irq()
  83. // On AVR this is in math.h?
  84. #define square(x) ((x)*(x))
  85. #ifndef strncpy_P
  86. #define strncpy_P(dest, src, num) strncpy((dest), (src), (num))
  87. #endif
  88. // Fix bug in pgm_read_ptr
  89. #undef pgm_read_ptr
  90. #define pgm_read_ptr(addr) (*(addr))
  91. // ------------------------
  92. // Types
  93. // ------------------------
  94. typedef int16_t pin_t;
  95. #define HAL_SERVO_LIB libServo
  96. // ------------------------
  97. // Public Variables
  98. // ------------------------
  99. // result of last ADC conversion
  100. extern uint16_t HAL_adc_result;
  101. // ------------------------
  102. // Public functions
  103. // ------------------------
  104. // Memory related
  105. #define __bss_end __bss_end__
  106. // Enable hooks into setup for HAL
  107. void HAL_init();
  108. // Clear reset reason
  109. void HAL_clear_reset_source();
  110. // Reset reason
  111. uint8_t HAL_get_reset_source();
  112. void _delay_ms(const int delay);
  113. extern "C" char* _sbrk(int incr);
  114. #pragma GCC diagnostic push
  115. #pragma GCC diagnostic ignored "-Wunused-function"
  116. static inline int freeMemory() {
  117. volatile char top;
  118. return &top - reinterpret_cast<char*>(_sbrk(0));
  119. }
  120. #pragma GCC diagnostic pop
  121. //
  122. // ADC
  123. //
  124. #define HAL_ANALOG_SELECT(pin) pinMode(pin, INPUT)
  125. inline void HAL_adc_init() {}
  126. #define HAL_ADC_VREF 3.3
  127. #define HAL_ADC_RESOLUTION 10
  128. #define HAL_START_ADC(pin) HAL_adc_start_conversion(pin)
  129. #define HAL_READ_ADC() HAL_adc_result
  130. #define HAL_ADC_READY() true
  131. void HAL_adc_start_conversion(const uint8_t adc_pin);
  132. uint16_t HAL_adc_get_result();
  133. #define GET_PIN_MAP_PIN(index) index
  134. #define GET_PIN_MAP_INDEX(pin) pin
  135. #define PARSED_PIN_INDEX(code, dval) parser.intval(code, dval)
  136. #ifdef STM32F1xx
  137. #define JTAG_DISABLE() AFIO_DBGAFR_CONFIG(AFIO_MAPR_SWJ_CFG_JTAGDISABLE)
  138. #define JTAGSWD_DISABLE() AFIO_DBGAFR_CONFIG(AFIO_MAPR_SWJ_CFG_DISABLE)
  139. #endif
  140. #define PLATFORM_M997_SUPPORT
  141. void flashFirmware(const int16_t);