Skip to content

Commit 194f587

Browse files
⚡️ Use hal_timer_t for timing vars
Co-Authored-By: tombrazier <[email protected]>
1 parent 4fdb0fb commit 194f587

File tree

2 files changed

+31
-31
lines changed

2 files changed

+31
-31
lines changed

Marlin/src/module/stepper.cpp

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -225,11 +225,11 @@ uint32_t Stepper::advance_divisor = 0,
225225
#endif
226226

227227
#if ENABLED(LIN_ADVANCE)
228-
uint32_t Stepper::nextAdvanceISR = LA_ADV_NEVER,
229-
Stepper::la_interval = LA_ADV_NEVER;
230-
int32_t Stepper::la_delta_error = 0,
231-
Stepper::la_dividend = 0,
232-
Stepper::la_advance_steps = 0;
228+
hal_timer_t Stepper::nextAdvanceISR = LA_ADV_NEVER,
229+
Stepper::la_interval = LA_ADV_NEVER;
230+
int32_t Stepper::la_delta_error = 0,
231+
Stepper::la_dividend = 0,
232+
Stepper::la_advance_steps = 0;
233233
#endif
234234

235235
#if HAS_SHAPING
@@ -255,14 +255,14 @@ uint32_t Stepper::advance_divisor = 0,
255255
#endif
256256

257257
#if ENABLED(INTEGRATED_BABYSTEPPING)
258-
uint32_t Stepper::nextBabystepISR = BABYSTEP_NEVER;
258+
hal_timer_t Stepper::nextBabystepISR = BABYSTEP_NEVER;
259259
#endif
260260

261261
#if ENABLED(DIRECT_STEPPING)
262262
page_step_state_t Stepper::page_step_state;
263263
#endif
264264

265-
int32_t Stepper::ticks_nominal = -1;
265+
hal_timer_t Stepper::ticks_nominal = 0;
266266
#if DISABLED(S_CURVE_ACCELERATION)
267267
uint32_t Stepper::acc_step_rate; // needed for deceleration start point
268268
#endif
@@ -1462,7 +1462,7 @@ HAL_STEP_TIMER_ISR() {
14621462

14631463
void Stepper::isr() {
14641464

1465-
static uint32_t nextMainISR = 0; // Interval until the next main Stepper Pulse phase (0 = Now)
1465+
static hal_timer_t nextMainISR = 0; // Interval until the next main Stepper Pulse phase (0 = Now)
14661466

14671467
#ifndef __AVR__
14681468
// Disable interrupts, to avoid ISR preemption while we reprogram the period
@@ -1518,8 +1518,8 @@ void Stepper::isr() {
15181518
#endif
15191519

15201520
// Get the interval to the next ISR call
1521-
const uint32_t interval = _MIN(
1522-
uint32_t(HAL_TIMER_TYPE_MAX), // Come back in a very long time
1521+
const hal_timer_t interval = _MIN(
1522+
hal_timer_t(HAL_TIMER_TYPE_MAX), // Come back in a very long time
15231523
nextMainISR // Time until the next Pulse / Block phase
15241524
OPTARG(INPUT_SHAPING_X, ShapingQueue::peek_x()) // Time until next input shaping echo for X
15251525
OPTARG(INPUT_SHAPING_Y, ShapingQueue::peek_y()) // Time until next input shaping echo for Y
@@ -1598,7 +1598,7 @@ void Stepper::isr() {
15981598
// sure that the time has not arrived yet - Warrantied by the scheduler
15991599

16001600
// Set the next ISR to fire at the proper time
1601-
HAL_timer_set_compare(MF_TIMER_STEP, hal_timer_t(next_isr_ticks));
1601+
HAL_timer_set_compare(MF_TIMER_STEP, next_isr_ticks);
16021602

16031603
// Don't forget to finally reenable interrupts on non-AVR.
16041604
// AVR automatically calls sei() for us on Return-from-Interrupt.
@@ -2046,7 +2046,7 @@ void Stepper::pulse_phase_isr() {
20462046
#endif // HAS_SHAPING
20472047

20482048
// Calculate timer interval, with all limits applied.
2049-
uint32_t Stepper::calc_timer_interval(uint32_t step_rate) {
2049+
hal_timer_t Stepper::calc_timer_interval(uint32_t step_rate) {
20502050

20512051
#ifdef CPU_32_BIT
20522052

@@ -2078,7 +2078,7 @@ uint32_t Stepper::calc_timer_interval(uint32_t step_rate) {
20782078
}
20792079

20802080
// Get the timer interval and the number of loops to perform per tick
2081-
uint32_t Stepper::calc_timer_interval(uint32_t step_rate, uint8_t &loops) {
2081+
hal_timer_t Stepper::calc_timer_interval(uint32_t step_rate, uint8_t &loops) {
20822082
uint8_t multistep = 1;
20832083
#if ENABLED(DISABLE_MULTI_STEPPING)
20842084

@@ -2118,10 +2118,10 @@ uint32_t Stepper::calc_timer_interval(uint32_t step_rate, uint8_t &loops) {
21182118
* schedules planner blocks. This is executed after the step pulses
21192119
* have been done, so it is less time critical.
21202120
*/
2121-
uint32_t Stepper::block_phase_isr() {
2121+
hal_timer_t Stepper::block_phase_isr() {
21222122

21232123
// If no queued movements, just wait 1ms for the next block
2124-
uint32_t interval = (STEPPER_TIMER_RATE) / 1000UL;
2124+
hal_timer_t interval = (STEPPER_TIMER_RATE) / 1000UL;
21252125

21262126
// If there is a current block
21272127
if (current_block) {
@@ -2296,7 +2296,7 @@ uint32_t Stepper::block_phase_isr() {
22962296
else { // Must be in cruise phase otherwise
22972297

22982298
// Calculate the ticks_nominal for this nominal speed, if not done yet
2299-
if (ticks_nominal < 0) {
2299+
if (ticks_nominal == 0) {
23002300
// step_rate to timer interval and loops for the nominal speed
23012301
ticks_nominal = calc_timer_interval(current_block->nominal_rate << oversampling_factor, steps_per_isr);
23022302

@@ -2604,7 +2604,7 @@ uint32_t Stepper::block_phase_isr() {
26042604
#endif
26052605

26062606
// Mark ticks_nominal as not-yet-calculated
2607-
ticks_nominal = -1;
2607+
ticks_nominal = 0;
26082608

26092609
#if ENABLED(S_CURVE_ACCELERATION)
26102610
// Initialize the Bézier speed curve
@@ -2671,7 +2671,7 @@ uint32_t Stepper::block_phase_isr() {
26712671
#if ENABLED(INTEGRATED_BABYSTEPPING)
26722672

26732673
// Timer interrupt for baby-stepping
2674-
uint32_t Stepper::babystepping_isr() {
2674+
hal_timer_t Stepper::babystepping_isr() {
26752675
babystep.task();
26762676
return babystep.has_steps() ? BABYSTEP_TICKS : BABYSTEP_NEVER;
26772677
}

Marlin/src/module/stepper.h

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -568,24 +568,24 @@ class Stepper {
568568
#endif
569569

570570
#if ENABLED(LIN_ADVANCE)
571-
static constexpr uint32_t LA_ADV_NEVER = 0xFFFFFFFF;
572-
static uint32_t nextAdvanceISR,
573-
la_interval; // Interval between ISR calls for LA
574-
static int32_t la_delta_error, // Analogue of delta_error.e for E steps in LA ISR
575-
la_dividend, // Analogue of advance_dividend.e for E steps in LA ISR
576-
la_advance_steps; // Count of steps added to increase nozzle pressure
571+
static constexpr hal_timer_t LA_ADV_NEVER = HAL_TIMER_TYPE_MAX;
572+
static hal_timer_t nextAdvanceISR,
573+
la_interval; // Interval between ISR calls for LA
574+
static int32_t la_delta_error, // Analogue of delta_error.e for E steps in LA ISR
575+
la_dividend, // Analogue of advance_dividend.e for E steps in LA ISR
576+
la_advance_steps; // Count of steps added to increase nozzle pressure
577577
#endif
578578

579579
#if ENABLED(INTEGRATED_BABYSTEPPING)
580-
static constexpr uint32_t BABYSTEP_NEVER = 0xFFFFFFFF;
581-
static uint32_t nextBabystepISR;
580+
static constexpr hal_timer_t BABYSTEP_NEVER = HAL_TIMER_TYPE_MAX;
581+
static hal_timer_t nextBabystepISR;
582582
#endif
583583

584584
#if ENABLED(DIRECT_STEPPING)
585585
static page_step_state_t page_step_state;
586586
#endif
587587

588-
static int32_t ticks_nominal;
588+
static hal_timer_t ticks_nominal;
589589
#if DISABLED(S_CURVE_ACCELERATION)
590590
static uint32_t acc_step_rate; // needed for deceleration start point
591591
#endif
@@ -624,7 +624,7 @@ class Stepper {
624624
static void pulse_phase_isr();
625625

626626
// The stepper block processing ISR phase
627-
static uint32_t block_phase_isr();
627+
static hal_timer_t block_phase_isr();
628628

629629
#if HAS_SHAPING
630630
static void shaping_isr();
@@ -637,7 +637,7 @@ class Stepper {
637637

638638
#if ENABLED(INTEGRATED_BABYSTEPPING)
639639
// The Babystepping ISR phase
640-
static uint32_t babystepping_isr();
640+
static hal_timer_t babystepping_isr();
641641
FORCE_INLINE static void initiateBabystepping() {
642642
if (nextBabystepISR == BABYSTEP_NEVER) {
643643
nextBabystepISR = 0;
@@ -810,10 +810,10 @@ class Stepper {
810810
static void _set_position(const abce_long_t &spos);
811811

812812
// Calculate the timing interval for the given step rate
813-
static uint32_t calc_timer_interval(uint32_t step_rate);
813+
static hal_timer_t calc_timer_interval(uint32_t step_rate);
814814

815815
// Calculate timing interval and steps-per-ISR for the given step rate
816-
static uint32_t calc_timer_interval(uint32_t step_rate, uint8_t &loops);
816+
static hal_timer_t calc_timer_interval(uint32_t step_rate, uint8_t &loops);
817817

818818
#if ENABLED(S_CURVE_ACCELERATION)
819819
static void _calc_bezier_curve_coeffs(const int32_t v0, const int32_t v1, const uint32_t av);

0 commit comments

Comments
 (0)