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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  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. *
  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 Teensy 3.5 and Teensy 3.6
  25. */
  26. #define CPU_32_BIT
  27. // --------------------------------------------------------------------------
  28. // Includes
  29. // --------------------------------------------------------------------------
  30. // _BV is re-defined in Arduino.h
  31. #undef _BV
  32. #include <Arduino.h>
  33. // Redefine sq macro defined by teensy3/wiring.h
  34. #undef sq
  35. #define sq(x) ((x)*(x))
  36. #include "../shared/math_32bit.h"
  37. #include "../shared/HAL_SPI.h"
  38. #include "fastio_Teensy.h"
  39. #include "watchdog_Teensy.h"
  40. #include "HAL_timers_Teensy.h"
  41. #include <stdint.h>
  42. #define ST7920_DELAY_1 DELAY_NS(600)
  43. #define ST7920_DELAY_2 DELAY_NS(750)
  44. #define ST7920_DELAY_3 DELAY_NS(750)
  45. // --------------------------------------------------------------------------
  46. // Defines
  47. // --------------------------------------------------------------------------
  48. #undef MOTHERBOARD
  49. #define MOTHERBOARD BOARD_TEENSY35_36
  50. #define IS_32BIT_TEENSY (defined(__MK64FX512__) || defined(__MK66FX1M0__))
  51. #define IS_TEENSY35 defined(__MK64FX512__)
  52. #define IS_TEENSY36 defined(__MK66FX1M0__)
  53. #define NUM_SERIAL 1
  54. #if SERIAL_PORT == -1
  55. #define MYSERIAL0 SerialUSB
  56. #elif SERIAL_PORT == 0
  57. #define MYSERIAL0 Serial
  58. #elif SERIAL_PORT == 1
  59. #define MYSERIAL0 Serial1
  60. #elif SERIAL_PORT == 2
  61. #define MYSERIAL0 Serial2
  62. #elif SERIAL_PORT == 3
  63. #define MYSERIAL0 Serial3
  64. #endif
  65. #define HAL_SERVO_LIB libServo
  66. typedef int8_t pin_t;
  67. #ifndef analogInputToDigitalPin
  68. #define analogInputToDigitalPin(p) ((p < 12u) ? (p) + 54u : -1)
  69. #endif
  70. #define CRITICAL_SECTION_START uint32_t primask = __get_PRIMASK(); __disable_irq()
  71. #define CRITICAL_SECTION_END if (!primask) __enable_irq()
  72. #define ISRS_ENABLED() (!__get_PRIMASK())
  73. #define ENABLE_ISRS() __enable_irq()
  74. #define DISABLE_ISRS() __disable_irq()
  75. #undef sq
  76. #define sq(x) ((x)*(x))
  77. #ifndef strncpy_P
  78. #define strncpy_P(dest, src, num) strncpy((dest), (src), (num))
  79. #endif
  80. // Fix bug in pgm_read_ptr
  81. #undef pgm_read_ptr
  82. #define pgm_read_ptr(addr) (*((void**)(addr)))
  83. // Add type-checking to pgm_read_word
  84. #undef pgm_read_word
  85. #define pgm_read_word(addr) (*((uint16_t*)(addr)))
  86. #define RST_POWER_ON 1
  87. #define RST_EXTERNAL 2
  88. #define RST_BROWN_OUT 4
  89. #define RST_WATCHDOG 8
  90. #define RST_JTAG 16
  91. #define RST_SOFTWARE 32
  92. #define RST_BACKUP 64
  93. /** clear reset reason */
  94. void HAL_clear_reset_source(void);
  95. /** reset reason */
  96. uint8_t HAL_get_reset_source(void);
  97. FORCE_INLINE void _delay_ms(const int delay_ms) { delay(delay_ms); }
  98. extern "C" {
  99. int freeMemory(void);
  100. }
  101. // SPI: Extended functions which take a channel number (hardware SPI only)
  102. /** Write single byte to specified SPI channel */
  103. void spiSend(uint32_t chan, byte b);
  104. /** Write buffer to specified SPI channel */
  105. void spiSend(uint32_t chan, const uint8_t* buf, size_t n);
  106. /** Read single byte from specified SPI channel */
  107. uint8_t spiRec(uint32_t chan);
  108. // ADC
  109. void HAL_adc_init();
  110. #define HAL_START_ADC(pin) HAL_adc_start_conversion(pin)
  111. #define HAL_READ_ADC() HAL_adc_get_result()
  112. #define HAL_ADC_READY() true
  113. #define HAL_ANALOG_SELECT(pin) NOOP;
  114. void HAL_adc_start_conversion(const uint8_t adc_pin);
  115. uint16_t HAL_adc_get_result(void);
  116. /*
  117. uint16_t HAL_getAdcReading(uint8_t chan);
  118. void HAL_startAdcConversion(uint8_t chan);
  119. uint8_t HAL_pinToAdcChannel(int pin);
  120. uint16_t HAL_getAdcFreerun(uint8_t chan, bool wait_for_conversion = false);
  121. //uint16_t HAL_getAdcSuperSample(uint8_t chan);
  122. void HAL_enable_AdcFreerun(void);
  123. //void HAL_disable_AdcFreerun(uint8_t chan);
  124. */
  125. #define GET_PIN_MAP_PIN(index) index
  126. #define GET_PIN_MAP_INDEX(pin) pin
  127. #define PARSED_PIN_INDEX(code, dval) parser.intval(code, dval)