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.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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. #pragma once
  23. #include <stdint.h>
  24. #include <driver/timer.h>
  25. // ------------------------
  26. // Defines
  27. // ------------------------
  28. #define FORCE_INLINE __attribute__((always_inline)) inline
  29. typedef uint64_t hal_timer_t;
  30. #define HAL_TIMER_TYPE_MAX 0xFFFFFFFFFFFFFFFFULL
  31. #ifndef MF_TIMER_STEP
  32. #define MF_TIMER_STEP 0 // Timer Index for Stepper
  33. #endif
  34. #ifndef MF_TIMER_PULSE
  35. #define MF_TIMER_PULSE MF_TIMER_STEP
  36. #endif
  37. #ifndef MF_TIMER_TEMP
  38. #define MF_TIMER_TEMP 1 // Timer Index for Temperature
  39. #endif
  40. #ifndef MF_TIMER_PWM
  41. #define MF_TIMER_PWM 2 // index of timer to use for PWM outputs
  42. #endif
  43. #ifndef MF_TIMER_TONE
  44. #define MF_TIMER_TONE 3 // index of timer for beeper tones
  45. #endif
  46. #define HAL_TIMER_RATE APB_CLK_FREQ // frequency of timer peripherals
  47. #if ENABLED(I2S_STEPPER_STREAM)
  48. #define STEPPER_TIMER_PRESCALE 1
  49. #define STEPPER_TIMER_RATE 250000 // 250khz, 4µs pulses of i2s word clock
  50. #define STEPPER_TIMER_TICKS_PER_US ((STEPPER_TIMER_RATE) / 1000000) // stepper timer ticks per µs // wrong would be 0.25
  51. #else
  52. #define STEPPER_TIMER_PRESCALE 40
  53. #define STEPPER_TIMER_RATE ((HAL_TIMER_RATE) / (STEPPER_TIMER_PRESCALE)) // frequency of stepper timer, 2MHz
  54. #define STEPPER_TIMER_TICKS_PER_US ((STEPPER_TIMER_RATE) / 1000000) // stepper timer ticks per µs
  55. #endif
  56. #define STEP_TIMER_MIN_INTERVAL 8 // minimum time in µs between stepper interrupts
  57. #define TONE_TIMER_PRESCALE 1000 // Arbitrary value, no idea what i'm doing here
  58. #define TEMP_TIMER_PRESCALE 1000 // prescaler for setting Temp timer, 72Khz
  59. #define TEMP_TIMER_FREQUENCY 1000 // temperature interrupt frequency
  60. #define PWM_TIMER_PRESCALE 10
  61. #if ENABLED(FAST_PWM_FAN)
  62. #define PWM_TIMER_FREQUENCY FAST_PWM_FAN_FREQUENCY
  63. #else
  64. #define PWM_TIMER_FREQUENCY (50*128) // 50Hz and 7bit resolution
  65. #endif
  66. #define MAX_PWM_PINS 32 // Number of PWM pin-slots
  67. #define PULSE_TIMER_RATE STEPPER_TIMER_RATE // frequency of pulse timer
  68. #define PULSE_TIMER_PRESCALE STEPPER_TIMER_PRESCALE
  69. #define PULSE_TIMER_TICKS_PER_US STEPPER_TIMER_TICKS_PER_US
  70. #define ENABLE_STEPPER_DRIVER_INTERRUPT() HAL_timer_enable_interrupt(MF_TIMER_STEP)
  71. #define DISABLE_STEPPER_DRIVER_INTERRUPT() HAL_timer_disable_interrupt(MF_TIMER_STEP)
  72. #define STEPPER_ISR_ENABLED() HAL_timer_interrupt_enabled(MF_TIMER_STEP)
  73. #define ENABLE_TEMPERATURE_INTERRUPT() HAL_timer_enable_interrupt(MF_TIMER_TEMP)
  74. #define DISABLE_TEMPERATURE_INTERRUPT() HAL_timer_disable_interrupt(MF_TIMER_TEMP)
  75. #ifndef HAL_TEMP_TIMER_ISR
  76. #define HAL_TEMP_TIMER_ISR() extern "C" void tempTC_Handler()
  77. #endif
  78. #ifndef HAL_STEP_TIMER_ISR
  79. #define HAL_STEP_TIMER_ISR() extern "C" void stepTC_Handler()
  80. #endif
  81. #ifndef HAL_PWM_TIMER_ISR
  82. #define HAL_PWM_TIMER_ISR() extern "C" void pwmTC_Handler()
  83. #endif
  84. #ifndef HAL_TONE_TIMER_ISR
  85. #define HAL_TONE_TIMER_ISR() extern "C" void toneTC_Handler()
  86. #endif
  87. extern "C" {
  88. void tempTC_Handler();
  89. void stepTC_Handler();
  90. void pwmTC_Handler();
  91. void toneTC_Handler();
  92. }
  93. // ------------------------
  94. // Types
  95. // ------------------------
  96. typedef struct {
  97. timer_group_t group;
  98. timer_idx_t idx;
  99. uint32_t divider;
  100. void (*fn)();
  101. } tTimerConfig;
  102. // ------------------------
  103. // Public Variables
  104. // ------------------------
  105. extern const tTimerConfig timer_config[];
  106. // ------------------------
  107. // Public functions
  108. // ------------------------
  109. void HAL_timer_start(const uint8_t timer_num, const uint32_t frequency);
  110. void HAL_timer_set_compare(const uint8_t timer_num, const hal_timer_t count);
  111. hal_timer_t HAL_timer_get_compare(const uint8_t timer_num);
  112. hal_timer_t HAL_timer_get_count(const uint8_t timer_num);
  113. void HAL_timer_enable_interrupt(const uint8_t timer_num);
  114. void HAL_timer_disable_interrupt(const uint8_t timer_num);
  115. bool HAL_timer_interrupt_enabled(const uint8_t timer_num);
  116. #define HAL_timer_isr_prologue(T) NOOP
  117. #define HAL_timer_isr_epilogue(T) NOOP