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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. /**
  2. * Marlin 3D Printer Firmware
  3. * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
  4. *
  5. * Based on Sprinter and grbl.
  6. * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
  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. /**
  23. * HAL for Teensy 3.2 (MK20DX256)
  24. */
  25. #ifdef __MK20DX256__
  26. #include "HAL.h"
  27. #include "../shared/Delay.h"
  28. #include <Wire.h>
  29. // ------------------------
  30. // Serial ports
  31. // ------------------------
  32. #define _IMPLEMENT_SERIAL(X) DefaultSerial##X MSerial##X(false, Serial##X)
  33. #define IMPLEMENT_SERIAL(X) _IMPLEMENT_SERIAL(X)
  34. #if WITHIN(SERIAL_PORT, 0, 3)
  35. IMPLEMENT_SERIAL(SERIAL_PORT);
  36. #else
  37. #error "SERIAL_PORT must be from 0 to 3."
  38. #endif
  39. USBSerialType USBSerial(false, SerialUSB);
  40. // ------------------------
  41. // MarlinHAL Class
  42. // ------------------------
  43. void MarlinHAL::reboot() { _reboot_Teensyduino_(); }
  44. uint8_t MarlinHAL::get_reset_source() {
  45. switch (RCM_SRS0) {
  46. case 128: return RST_POWER_ON; break;
  47. case 64: return RST_EXTERNAL; break;
  48. case 32: return RST_WATCHDOG; break;
  49. // case 8: return RST_LOSS_OF_LOCK; break;
  50. // case 4: return RST_LOSS_OF_CLOCK; break;
  51. // case 2: return RST_LOW_VOLTAGE; break;
  52. }
  53. return 0;
  54. }
  55. // ------------------------
  56. // Watchdog Timer
  57. // ------------------------
  58. #if ENABLED(USE_WATCHDOG)
  59. #define WDT_TIMEOUT_MS TERN(WATCHDOG_DURATION_8S, 8000, 4000) // 4 or 8 second timeout
  60. void MarlinHAL::watchdog_init() {
  61. WDOG_TOVALH = 0;
  62. WDOG_TOVALL = WDT_TIMEOUT_MS;
  63. WDOG_STCTRLH = WDOG_STCTRLH_WDOGEN;
  64. }
  65. void MarlinHAL::watchdog_refresh() {
  66. // Watchdog refresh sequence
  67. WDOG_REFRESH = 0xA602;
  68. WDOG_REFRESH = 0xB480;
  69. }
  70. #endif
  71. // ------------------------
  72. // ADC
  73. // ------------------------
  74. void MarlinHAL::adc_init() {
  75. analog_init();
  76. while (ADC0_SC3 & ADC_SC3_CAL) {}; // Wait for calibration to finish
  77. NVIC_ENABLE_IRQ(IRQ_FTM1);
  78. }
  79. void MarlinHAL::adc_start(const pin_t pin) {
  80. static const uint8_t pin2sc1a[] = {
  81. 5, 14, 8, 9, 13, 12, 6, 7, 15, 4, 0, 19, 3, 31, // 0-13, we treat them as A0-A13
  82. 5, 14, 8, 9, 13, 12, 6, 7, 15, 4, // 14-23 (A0-A9)
  83. 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, // 24-33
  84. 0+64, 19+64, 3+64, 31+64, // 34-37 (A10-A13)
  85. 26, 22, 23, 27, 29, 30 // 38-43: temp. sensor, VREF_OUT, A14, bandgap, VREFH, VREFL. A14 isn't connected to anything in Teensy 3.0.
  86. };
  87. ADC0_SC1A = pin2sc1a[pin];
  88. }
  89. uint16_t MarlinHAL::adc_value() { return ADC0_RA; }
  90. // ------------------------
  91. // Free Memory Accessor
  92. // ------------------------
  93. extern "C" {
  94. extern char __bss_end;
  95. extern char __heap_start;
  96. extern void* __brkval;
  97. int freeMemory() {
  98. int free_memory;
  99. if ((int)__brkval == 0)
  100. free_memory = ((int)&free_memory) - ((int)&__bss_end);
  101. else
  102. free_memory = ((int)&free_memory) - ((int)__brkval);
  103. return free_memory;
  104. }
  105. }
  106. #endif // __MK20DX256__