My Marlin configs for Fabrikator Mini and CTC i3 Pro B
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

HAL.h 6.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. /**
  2. * Marlin 3D Printer Firmware
  3. *
  4. * Copyright (c) 2019 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 <http://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 "../../inc/MarlinConfigPre.h"
  32. #include <stdint.h>
  33. #ifdef USBCON
  34. #include <USBSerial.h>
  35. #endif
  36. // ------------------------
  37. // Defines
  38. // ------------------------
  39. #if SERIAL_PORT == 0
  40. #error "SERIAL_PORT cannot be 0. (Port 0 does not exist.) Please update your configuration."
  41. #elif SERIAL_PORT == -1
  42. #define MYSERIAL0 SerialUSB
  43. #elif SERIAL_PORT == 1
  44. #define MYSERIAL0 Serial1
  45. #elif SERIAL_PORT == 2
  46. #define MYSERIAL0 Serial2
  47. #elif SERIAL_PORT == 3
  48. #define MYSERIAL0 Serial3
  49. #elif SERIAL_PORT == 4
  50. #define MYSERIAL0 Serial4
  51. #elif SERIAL_PORT == 5
  52. #define MYSERIAL0 Serial5
  53. #elif SERIAL_PORT == 6
  54. #define MYSERIAL0 Serial6
  55. #else
  56. #error "SERIAL_PORT must be from -1 to 6. Please update your configuration."
  57. #endif
  58. #ifdef SERIAL_PORT_2
  59. #define NUM_SERIAL 2
  60. #if SERIAL_PORT_2 == 0
  61. #error "SERIAL_PORT_2 cannot be 0. (Port 0 does not exist.) Please update your configuration."
  62. #elif SERIAL_PORT_2 == SERIAL_PORT
  63. #error "SERIAL_PORT_2 must be different than SERIAL_PORT. Please update your configuration."
  64. #elif SERIAL_PORT_2 == -1
  65. #define MYSERIAL1 SerialUSB
  66. #elif SERIAL_PORT_2 == 1
  67. #define MYSERIAL1 Serial1
  68. #elif SERIAL_PORT_2 == 2
  69. #define MYSERIAL1 Serial2
  70. #elif SERIAL_PORT_2 == 3
  71. #define MYSERIAL1 Serial3
  72. #elif SERIAL_PORT_2 == 4
  73. #define MYSERIAL1 Serial4
  74. #elif SERIAL_PORT_2 == 5
  75. #define MYSERIAL1 Serial5
  76. #elif SERIAL_PORT_2 == 6
  77. #define MYSERIAL1 Serial6
  78. #else
  79. #error "SERIAL_PORT_2 must be from -1 to 6. Please update your configuration."
  80. #endif
  81. #else
  82. #define NUM_SERIAL 1
  83. #endif
  84. #if HAS_DGUS_LCD
  85. #if DGUS_SERIAL_PORT == 0
  86. #error "DGUS_SERIAL_PORT cannot be 0. (Port 0 does not exist.) Please update your configuration."
  87. #elif DGUS_SERIAL_PORT == SERIAL_PORT
  88. #error "DGUS_SERIAL_PORT must be different than SERIAL_PORT. Please update your configuration."
  89. #elif defined(SERIAL_PORT_2) && DGUS_SERIAL_PORT == SERIAL_PORT_2
  90. #error "DGUS_SERIAL_PORT must be different than SERIAL_PORT_2. Please update your configuration."
  91. #elif DGUS_SERIAL_PORT == -1
  92. #define DGUS_SERIAL SerialUSB
  93. #elif DGUS_SERIAL_PORT == 1
  94. #define DGUS_SERIAL Serial1
  95. #elif DGUS_SERIAL_PORT == 2
  96. #define DGUS_SERIAL Serial2
  97. #elif DGUS_SERIAL_PORT == 3
  98. #define DGUS_SERIAL Serial3
  99. #elif DGUS_SERIAL_PORT == 4
  100. #define DGUS_SERIAL Serial4
  101. #elif DGUS_SERIAL_PORT == 5
  102. #define DGUS_SERIAL Serial5
  103. #elif DGUS_SERIAL_PORT == 6
  104. #define DGUS_SERIAL Serial6
  105. #else
  106. #error "DGUS_SERIAL_PORT must be from -1 to 6. Please update your configuration."
  107. #endif
  108. #define DGUS_SERIAL_GET_TX_BUFFER_FREE DGUS_SERIAL.availableForWrite
  109. #endif
  110. #include "timers.h"
  111. /**
  112. * TODO: review this to return 1 for pins that are not analog input
  113. */
  114. #ifndef analogInputToDigitalPin
  115. #define analogInputToDigitalPin(p) (p)
  116. #endif
  117. #define CRITICAL_SECTION_START uint32_t primask = __get_PRIMASK(); __disable_irq()
  118. #define CRITICAL_SECTION_END if (!primask) __enable_irq()
  119. #define ISRS_ENABLED() (!__get_PRIMASK())
  120. #define ENABLE_ISRS() __enable_irq()
  121. #define DISABLE_ISRS() __disable_irq()
  122. #define cli() __disable_irq()
  123. #define sei() __enable_irq()
  124. // On AVR this is in math.h?
  125. #define square(x) ((x)*(x))
  126. #ifndef strncpy_P
  127. #define strncpy_P(dest, src, num) strncpy((dest), (src), (num))
  128. #endif
  129. // Fix bug in pgm_read_ptr
  130. #undef pgm_read_ptr
  131. #define pgm_read_ptr(addr) (*(addr))
  132. // ------------------------
  133. // Types
  134. // ------------------------
  135. typedef int16_t pin_t;
  136. #define HAL_SERVO_LIB libServo
  137. // ------------------------
  138. // Public Variables
  139. // ------------------------
  140. // result of last ADC conversion
  141. extern uint16_t HAL_adc_result;
  142. // ------------------------
  143. // Public functions
  144. // ------------------------
  145. // Memory related
  146. #define __bss_end __bss_end__
  147. // Enable hooks into setup for HAL
  148. void HAL_init();
  149. // Clear reset reason
  150. void HAL_clear_reset_source();
  151. // Reset reason
  152. uint8_t HAL_get_reset_source();
  153. void _delay_ms(const int delay);
  154. extern "C" char* _sbrk(int incr);
  155. #pragma GCC diagnostic push
  156. #pragma GCC diagnostic ignored "-Wunused-function"
  157. static inline int freeMemory() {
  158. volatile char top;
  159. return &top - reinterpret_cast<char*>(_sbrk(0));
  160. }
  161. #pragma GCC diagnostic pop
  162. //
  163. // EEPROM
  164. //
  165. // Wire library should work for i2c EEPROMs
  166. void eeprom_write_byte(uint8_t *pos, unsigned char value);
  167. uint8_t eeprom_read_byte(uint8_t *pos);
  168. void eeprom_read_block(void *__dst, const void *__src, size_t __n);
  169. void eeprom_update_block(const void *__src, void *__dst, size_t __n);
  170. //
  171. // ADC
  172. //
  173. #define HAL_ANALOG_SELECT(pin) pinMode(pin, INPUT)
  174. inline void HAL_adc_init() {}
  175. #define HAL_START_ADC(pin) HAL_adc_start_conversion(pin)
  176. #define HAL_ADC_RESOLUTION 10
  177. #define HAL_READ_ADC() HAL_adc_result
  178. #define HAL_ADC_READY() true
  179. void HAL_adc_start_conversion(const uint8_t adc_pin);
  180. uint16_t HAL_adc_get_result();
  181. #define GET_PIN_MAP_PIN(index) index
  182. #define GET_PIN_MAP_INDEX(pin) pin
  183. #define PARSED_PIN_INDEX(code, dval) parser.intval(code, dval)
  184. #define PLATFORM_M997_SUPPORT
  185. void flashFirmware(int16_t value);