My Marlin configs for Fabrikator Mini and CTC i3 Pro B
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

HAL.h 5.4KB

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