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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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 Teensy 4.0 (IMXRT1062DVL6A) / 4.1 (IMXRT1062DVJ6A)
  25. */
  26. #define CPU_32_BIT
  27. #include "../shared/Marduino.h"
  28. #include "../shared/math_32bit.h"
  29. #include "../shared/HAL_SPI.h"
  30. #include "fastio.h"
  31. #include "watchdog.h"
  32. #include <stdint.h>
  33. #include <util/atomic.h>
  34. #if HAS_ETHERNET
  35. #include "../../feature/ethernet.h"
  36. #endif
  37. //#define ST7920_DELAY_1 DELAY_NS(600)
  38. //#define ST7920_DELAY_2 DELAY_NS(750)
  39. //#define ST7920_DELAY_3 DELAY_NS(750)
  40. // ------------------------
  41. // Defines
  42. // ------------------------
  43. #define IS_32BIT_TEENSY 1
  44. #define IS_TEENSY_40_41 1
  45. #ifndef IS_TEENSY40
  46. #define IS_TEENSY41 1
  47. #endif
  48. #include "../../core/serial_hook.h"
  49. typedef Serial0Type<decltype(Serial)> DefaultSerial;
  50. extern DefaultSerial MSerial;
  51. typedef ForwardSerial0Type<decltype(SerialUSB)> USBSerialType;
  52. extern USBSerialType USBSerial;
  53. #define _MSERIAL(X) MSerial##X
  54. #define MSERIAL(X) _MSERIAL(X)
  55. #define MSerial0 MSerial
  56. #if SERIAL_PORT == -1
  57. #define MYSERIAL0 SerialUSB
  58. #elif WITHIN(SERIAL_PORT, 0, 8)
  59. #define MYSERIAL0 MSERIAL(SERIAL_PORT)
  60. #else
  61. #error "The required SERIAL_PORT must be from -1 to 8. Please update your configuration."
  62. #endif
  63. #ifdef SERIAL_PORT_2
  64. #if SERIAL_PORT_2 == -1
  65. #define MYSERIAL1 usbSerial
  66. #elif SERIAL_PORT_2 == -2
  67. #define MYSERIAL1 ethernet.telnetClient
  68. #elif WITHIN(SERIAL_PORT_2, 0, 8)
  69. #define MYSERIAL1 MSERIAL(SERIAL_PORT_2)
  70. #else
  71. #error "SERIAL_PORT_2 must be from -2 to 8. Please update your configuration."
  72. #endif
  73. #endif
  74. #define HAL_SERVO_LIB libServo
  75. typedef int8_t pin_t;
  76. #ifndef analogInputToDigitalPin
  77. #define analogInputToDigitalPin(p) ((p < 12U) ? (p) + 54U : -1)
  78. #endif
  79. #define CRITICAL_SECTION_START() uint32_t primask = __get_primask(); __disable_irq()
  80. #define CRITICAL_SECTION_END() if (!primask) __enable_irq()
  81. #define ISRS_ENABLED() (!__get_primask())
  82. #define ENABLE_ISRS() __enable_irq()
  83. #define DISABLE_ISRS() __disable_irq()
  84. #undef sq
  85. #define sq(x) ((x)*(x))
  86. // Don't place string constants in PROGMEM
  87. #undef PSTR
  88. #define PSTR(str) ({static const char *data = (str); &data[0];})
  89. // Enable hooks into idle and setup for HAL
  90. #define HAL_IDLETASK 1
  91. FORCE_INLINE void HAL_idletask() {}
  92. FORCE_INLINE void HAL_init() {}
  93. // Clear reset reason
  94. void HAL_clear_reset_source();
  95. // Reset reason
  96. uint8_t HAL_get_reset_source();
  97. FORCE_INLINE void _delay_ms(const int delay_ms) { delay(delay_ms); }
  98. #if GCC_VERSION <= 50000
  99. #pragma GCC diagnostic push
  100. #pragma GCC diagnostic ignored "-Wunused-function"
  101. #endif
  102. extern "C" uint32_t freeMemory();
  103. #if GCC_VERSION <= 50000
  104. #pragma GCC diagnostic pop
  105. #endif
  106. // ADC
  107. void HAL_adc_init();
  108. #define HAL_ADC_VREF 3.3
  109. #define HAL_ADC_RESOLUTION 10
  110. #define HAL_ADC_FILTERED // turn off ADC oversampling
  111. #define HAL_START_ADC(pin) HAL_adc_start_conversion(pin)
  112. #define HAL_READ_ADC() HAL_adc_get_result()
  113. #define HAL_ADC_READY() true
  114. #define HAL_ANALOG_SELECT(pin)
  115. void HAL_adc_start_conversion(const uint8_t adc_pin);
  116. uint16_t HAL_adc_get_result();
  117. #define GET_PIN_MAP_PIN(index) index
  118. #define GET_PIN_MAP_INDEX(pin) pin
  119. #define PARSED_PIN_INDEX(code, dval) parser.intval(code, dval)
  120. bool is_output(uint8_t pin);