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_timers_ESP32.h 4.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /**
  2. * Marlin 3D Printer Firmware
  3. * Copyright (c) 2019 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 <http://www.gnu.org/licenses/>.
  20. *
  21. */
  22. #pragma once
  23. // --------------------------------------------------------------------------
  24. // Includes
  25. // --------------------------------------------------------------------------
  26. #include <stdint.h>
  27. #include "driver/timer.h"
  28. // Includes needed to get I2S_STEPPER_STREAM. Note that pins.h
  29. // is included in case this header is being included early.
  30. #include "../../inc/MarlinConfig.h"
  31. #include "../../pins/pins.h"
  32. // --------------------------------------------------------------------------
  33. // Defines
  34. // --------------------------------------------------------------------------
  35. //
  36. #define FORCE_INLINE __attribute__((always_inline)) inline
  37. typedef uint64_t hal_timer_t;
  38. #define HAL_TIMER_TYPE_MAX 0xFFFFFFFFFFFFFFFFULL
  39. #define STEP_TIMER_NUM 0 // index of timer to use for stepper
  40. #define TEMP_TIMER_NUM 1 // index of timer to use for temperature
  41. #define PULSE_TIMER_NUM STEP_TIMER_NUM
  42. #define HAL_TIMER_RATE APB_CLK_FREQ // frequency of timer peripherals
  43. #if ENABLED(I2S_STEPPER_STREAM)
  44. #define STEPPER_TIMER_PRESCALE 1
  45. #define STEPPER_TIMER_RATE 250000 // 250khz, 4us pulses of i2s word clock
  46. #define STEPPER_TIMER_TICKS_PER_US ((STEPPER_TIMER_RATE) / 1000000) // stepper timer ticks per µs // wrong would be 0.25
  47. #else
  48. #define STEPPER_TIMER_PRESCALE 40
  49. #define STEPPER_TIMER_RATE (HAL_TIMER_RATE / STEPPER_TIMER_PRESCALE) // frequency of stepper timer, 2MHz
  50. #define STEPPER_TIMER_TICKS_PER_US ((STEPPER_TIMER_RATE) / 1000000) // stepper timer ticks per µs
  51. #endif
  52. #define STEP_TIMER_MIN_INTERVAL 8 // minimum time in µs between stepper interrupts
  53. #define TEMP_TIMER_PRESCALE 1000 // prescaler for setting Temp timer, 72Khz
  54. #define TEMP_TIMER_FREQUENCY 1000 // temperature interrupt frequency
  55. #define PULSE_TIMER_RATE STEPPER_TIMER_RATE // frequency of pulse timer
  56. #define PULSE_TIMER_PRESCALE STEPPER_TIMER_PRESCALE
  57. #define PULSE_TIMER_TICKS_PER_US STEPPER_TIMER_TICKS_PER_US
  58. #define ENABLE_STEPPER_DRIVER_INTERRUPT() HAL_timer_enable_interrupt(STEP_TIMER_NUM)
  59. #define DISABLE_STEPPER_DRIVER_INTERRUPT() HAL_timer_disable_interrupt(STEP_TIMER_NUM)
  60. #define STEPPER_ISR_ENABLED() HAL_timer_interrupt_enabled(STEP_TIMER_NUM)
  61. #define ENABLE_TEMPERATURE_INTERRUPT() HAL_timer_enable_interrupt(TEMP_TIMER_NUM)
  62. #define DISABLE_TEMPERATURE_INTERRUPT() HAL_timer_disable_interrupt(TEMP_TIMER_NUM)
  63. #define HAL_TEMP_TIMER_ISR() extern "C" void tempTC_Handler(void)
  64. #define HAL_STEP_TIMER_ISR() extern "C" void stepTC_Handler(void)
  65. extern "C" void tempTC_Handler(void);
  66. extern "C" void stepTC_Handler(void);
  67. // --------------------------------------------------------------------------
  68. // Types
  69. // --------------------------------------------------------------------------
  70. typedef struct {
  71. timer_group_t group;
  72. timer_idx_t idx;
  73. uint32_t divider;
  74. void (*fn)(void);
  75. } tTimerConfig;
  76. // --------------------------------------------------------------------------
  77. // Public Variables
  78. // --------------------------------------------------------------------------
  79. extern const tTimerConfig TimerConfig[];
  80. // --------------------------------------------------------------------------
  81. // Public functions
  82. // --------------------------------------------------------------------------
  83. void HAL_timer_start (const uint8_t timer_num, uint32_t frequency);
  84. void HAL_timer_set_compare(const uint8_t timer_num, const hal_timer_t count);
  85. hal_timer_t HAL_timer_get_compare(const uint8_t timer_num);
  86. hal_timer_t HAL_timer_get_count(const uint8_t timer_num);
  87. void HAL_timer_enable_interrupt(const uint8_t timer_num);
  88. void HAL_timer_disable_interrupt(const uint8_t timer_num);
  89. bool HAL_timer_interrupt_enabled(const uint8_t timer_num);
  90. #define HAL_timer_isr_prologue(TIMER_NUM)
  91. #define HAL_timer_isr_epilogue(TIMER_NUM)