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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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. // --------------------------------------------------------------------------
  29. // Defines
  30. // --------------------------------------------------------------------------
  31. //
  32. #define FORCE_INLINE __attribute__((always_inline)) inline
  33. typedef uint64_t hal_timer_t;
  34. #define HAL_TIMER_TYPE_MAX 0xFFFFFFFFFFFFFFFFULL
  35. #define STEP_TIMER_NUM 0 // index of timer to use for stepper
  36. #define TEMP_TIMER_NUM 1 // index of timer to use for temperature
  37. #define PULSE_TIMER_NUM STEP_TIMER_NUM
  38. #define HAL_TIMER_RATE APB_CLK_FREQ // frequency of timer peripherals
  39. #if ENABLED(I2S_STEPPER_STREAM)
  40. #define STEPPER_TIMER_PRESCALE 1
  41. #define STEPPER_TIMER_RATE 250000 // 250khz, 4us pulses of i2s word clock
  42. #define STEPPER_TIMER_TICKS_PER_US ((STEPPER_TIMER_RATE) / 1000000) // stepper timer ticks per µs // wrong would be 0.25
  43. #else
  44. #define STEPPER_TIMER_PRESCALE 40
  45. #define STEPPER_TIMER_RATE (HAL_TIMER_RATE / STEPPER_TIMER_PRESCALE) // frequency of stepper timer, 2MHz
  46. #define STEPPER_TIMER_TICKS_PER_US ((STEPPER_TIMER_RATE) / 1000000) // stepper timer ticks per µs
  47. #endif
  48. #define STEP_TIMER_MIN_INTERVAL 8 // minimum time in µs between stepper interrupts
  49. #define TEMP_TIMER_PRESCALE 1000 // prescaler for setting Temp timer, 72Khz
  50. #define TEMP_TIMER_FREQUENCY 1000 // temperature interrupt frequency
  51. #define PULSE_TIMER_RATE STEPPER_TIMER_RATE // frequency of pulse timer
  52. #define PULSE_TIMER_PRESCALE STEPPER_TIMER_PRESCALE
  53. #define PULSE_TIMER_TICKS_PER_US STEPPER_TIMER_TICKS_PER_US
  54. #define ENABLE_STEPPER_DRIVER_INTERRUPT() HAL_timer_enable_interrupt(STEP_TIMER_NUM)
  55. #define DISABLE_STEPPER_DRIVER_INTERRUPT() HAL_timer_disable_interrupt(STEP_TIMER_NUM)
  56. #define STEPPER_ISR_ENABLED() HAL_timer_interrupt_enabled(STEP_TIMER_NUM)
  57. #define ENABLE_TEMPERATURE_INTERRUPT() HAL_timer_enable_interrupt(TEMP_TIMER_NUM)
  58. #define DISABLE_TEMPERATURE_INTERRUPT() HAL_timer_disable_interrupt(TEMP_TIMER_NUM)
  59. #define HAL_TEMP_TIMER_ISR extern "C" void tempTC_Handler(void)
  60. #define HAL_STEP_TIMER_ISR extern "C" void stepTC_Handler(void)
  61. extern "C" void tempTC_Handler(void);
  62. extern "C" void stepTC_Handler(void);
  63. // --------------------------------------------------------------------------
  64. // Types
  65. // --------------------------------------------------------------------------
  66. typedef struct {
  67. timer_group_t group;
  68. timer_idx_t idx;
  69. uint32_t divider;
  70. void (*fn)(void);
  71. } tTimerConfig;
  72. // --------------------------------------------------------------------------
  73. // Public Variables
  74. // --------------------------------------------------------------------------
  75. extern const tTimerConfig TimerConfig[];
  76. // --------------------------------------------------------------------------
  77. // Public functions
  78. // --------------------------------------------------------------------------
  79. void HAL_timer_start (const uint8_t timer_num, uint32_t frequency);
  80. void HAL_timer_set_compare(const uint8_t timer_num, const hal_timer_t count);
  81. hal_timer_t HAL_timer_get_compare(const uint8_t timer_num);
  82. hal_timer_t HAL_timer_get_count(const uint8_t timer_num);
  83. void HAL_timer_enable_interrupt(const uint8_t timer_num);
  84. void HAL_timer_disable_interrupt(const uint8_t timer_num);
  85. bool HAL_timer_interrupt_enabled(const uint8_t timer_num);
  86. #define HAL_timer_isr_prologue(TIMER_NUM)
  87. #define HAL_timer_isr_epilogue(TIMER_NUM)