Skip to content

Commit 9b1c0a7

Browse files
committed
🎨 Rename HAL timer elements
1 parent d75e778 commit 9b1c0a7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+380
-402
lines changed

Marlin/src/HAL/AVR/timers.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,14 @@ typedef uint16_t hal_timer_t;
3434

3535
#define HAL_TIMER_RATE ((F_CPU) / 8) // i.e., 2MHz or 2.5MHz
3636

37-
#ifndef STEP_TIMER_NUM
38-
#define STEP_TIMER_NUM 1
37+
#ifndef MF_TIMER_STEP
38+
#define MF_TIMER_STEP 1
3939
#endif
40-
#ifndef PULSE_TIMER_NUM
41-
#define PULSE_TIMER_NUM STEP_TIMER_NUM
40+
#ifndef MF_TIMER_PULSE
41+
#define MF_TIMER_PULSE MF_TIMER_STEP
4242
#endif
43-
#ifndef TEMP_TIMER_NUM
44-
#define TEMP_TIMER_NUM 0
43+
#ifndef MF_TIMER_TEMP
44+
#define MF_TIMER_TEMP 0
4545
#endif
4646

4747
#define TEMP_TIMER_FREQUENCY ((F_CPU) / 64.0 / 256.0)
@@ -64,7 +64,7 @@ typedef uint16_t hal_timer_t;
6464

6565
FORCE_INLINE void HAL_timer_start(const uint8_t timer_num, const uint32_t) {
6666
switch (timer_num) {
67-
case STEP_TIMER_NUM:
67+
case MF_TIMER_STEP:
6868
// waveform generation = 0100 = CTC
6969
SET_WGM(1, CTC_OCRnA);
7070

@@ -84,7 +84,7 @@ FORCE_INLINE void HAL_timer_start(const uint8_t timer_num, const uint32_t) {
8484
TCNT1 = 0;
8585
break;
8686

87-
case TEMP_TIMER_NUM:
87+
case MF_TIMER_TEMP:
8888
// Use timer0 for temperature measurement
8989
// Interleave temperature interrupt with millies interrupt
9090
OCR0B = 128;

Marlin/src/HAL/DUE/Tone.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,17 +38,17 @@ volatile static int32_t toggles;
3838
void tone(const pin_t _pin, const unsigned int frequency, const unsigned long duration) {
3939
tone_pin = _pin;
4040
toggles = 2 * frequency * duration / 1000;
41-
HAL_timer_start(TONE_TIMER_NUM, 2 * frequency);
41+
HAL_timer_start(MF_TIMER_TONE, 2 * frequency);
4242
}
4343

4444
void noTone(const pin_t _pin) {
45-
HAL_timer_disable_interrupt(TONE_TIMER_NUM);
45+
HAL_timer_disable_interrupt(MF_TIMER_TONE);
4646
extDigitalWrite(_pin, LOW);
4747
}
4848

4949
HAL_TONE_TIMER_ISR() {
5050
static uint8_t pin_state = 0;
51-
HAL_timer_isr_prologue(TONE_TIMER_NUM);
51+
HAL_timer_isr_prologue(MF_TIMER_TONE);
5252

5353
if (toggles) {
5454
toggles--;

Marlin/src/HAL/DUE/timers.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
// Private Variables
4343
// ------------------------
4444

45-
const tTimerConfig TimerConfig [NUM_HARDWARE_TIMERS] = {
45+
const tTimerConfig timer_config[NUM_HARDWARE_TIMERS] = {
4646
{ TC0, 0, TC0_IRQn, 3}, // 0 - [servo timer5]
4747
{ TC0, 1, TC1_IRQn, 0}, // 1
4848
{ TC0, 2, TC2_IRQn, 2}, // 2 - stepper
@@ -66,9 +66,9 @@ const tTimerConfig TimerConfig [NUM_HARDWARE_TIMERS] = {
6666
*/
6767

6868
void HAL_timer_start(const uint8_t timer_num, const uint32_t frequency) {
69-
Tc *tc = TimerConfig[timer_num].pTimerRegs;
70-
IRQn_Type irq = TimerConfig[timer_num].IRQ_Id;
71-
uint32_t channel = TimerConfig[timer_num].channel;
69+
Tc *tc = timer_config[timer_num].pTimerRegs;
70+
IRQn_Type irq = timer_config[timer_num].IRQ_Id;
71+
uint32_t channel = timer_config[timer_num].channel;
7272

7373
// Disable interrupt, just in case it was already enabled
7474
NVIC_DisableIRQ(irq);
@@ -86,7 +86,7 @@ void HAL_timer_start(const uint8_t timer_num, const uint32_t frequency) {
8686

8787
pmc_set_writeprotect(false);
8888
pmc_enable_periph_clk((uint32_t)irq);
89-
NVIC_SetPriority(irq, TimerConfig [timer_num].priority);
89+
NVIC_SetPriority(irq, timer_config[timer_num].priority);
9090

9191
// wave mode, reset counter on match with RC,
9292
TC_Configure(tc, channel, TC_CMR_WAVE | TC_CMR_WAVSEL_UP_RC | TC_CMR_TCCLKS_TIMER_CLOCK1);
@@ -105,12 +105,12 @@ void HAL_timer_start(const uint8_t timer_num, const uint32_t frequency) {
105105
}
106106

107107
void HAL_timer_enable_interrupt(const uint8_t timer_num) {
108-
IRQn_Type irq = TimerConfig[timer_num].IRQ_Id;
108+
IRQn_Type irq = timer_config[timer_num].IRQ_Id;
109109
NVIC_EnableIRQ(irq);
110110
}
111111

112112
void HAL_timer_disable_interrupt(const uint8_t timer_num) {
113-
IRQn_Type irq = TimerConfig[timer_num].IRQ_Id;
113+
IRQn_Type irq = timer_config[timer_num].IRQ_Id;
114114
NVIC_DisableIRQ(irq);
115115

116116
// We NEED memory barriers to ensure Interrupts are actually disabled!
@@ -125,7 +125,7 @@ static bool NVIC_GetEnabledIRQ(IRQn_Type IRQn) {
125125
}
126126

127127
bool HAL_timer_interrupt_enabled(const uint8_t timer_num) {
128-
IRQn_Type irq = TimerConfig[timer_num].IRQ_Id;
128+
IRQn_Type irq = timer_config[timer_num].IRQ_Id;
129129
return NVIC_GetEnabledIRQ(irq);
130130
}
131131

Marlin/src/HAL/DUE/timers.h

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -37,35 +37,35 @@ typedef uint32_t hal_timer_t;
3737

3838
#define HAL_TIMER_RATE ((F_CPU) / 2) // frequency of timers peripherals
3939

40-
#ifndef STEP_TIMER_NUM
41-
#define STEP_TIMER_NUM 2 // Timer Index for Stepper
40+
#ifndef MF_TIMER_STEP
41+
#define MF_TIMER_STEP 2 // Timer Index for Stepper
4242
#endif
43-
#ifndef PULSE_TIMER_NUM
44-
#define PULSE_TIMER_NUM STEP_TIMER_NUM
43+
#ifndef MF_TIMER_PULSE
44+
#define MF_TIMER_PULSE MF_TIMER_STEP
4545
#endif
46-
#ifndef TEMP_TIMER_NUM
47-
#define TEMP_TIMER_NUM 4 // Timer Index for Temperature
46+
#ifndef MF_TIMER_TEMP
47+
#define MF_TIMER_TEMP 4 // Timer Index for Temperature
4848
#endif
49-
#ifndef TONE_TIMER_NUM
50-
#define TONE_TIMER_NUM 6 // index of timer to use for beeper tones
49+
#ifndef MF_TIMER_TONE
50+
#define MF_TIMER_TONE 6 // index of timer to use for beeper tones
5151
#endif
5252

5353
#define TEMP_TIMER_FREQUENCY 1000 // temperature interrupt frequency
5454

55-
#define STEPPER_TIMER_RATE HAL_TIMER_RATE // frequency of stepper timer (HAL_TIMER_RATE / STEPPER_TIMER_PRESCALE)
56-
#define STEPPER_TIMER_TICKS_PER_US ((STEPPER_TIMER_RATE) / 1000000) // stepper timer ticks per µs
57-
#define STEPPER_TIMER_PRESCALE (CYCLES_PER_MICROSECOND / STEPPER_TIMER_TICKS_PER_US)
55+
#define STEPPER_TIMER_RATE HAL_TIMER_RATE // frequency of stepper timer (HAL_TIMER_RATE / STEPPER_TIMER_PRESCALE)
56+
#define STEPPER_TIMER_TICKS_PER_US ((STEPPER_TIMER_RATE) / 1000000) // stepper timer ticks per µs
57+
#define STEPPER_TIMER_PRESCALE (CYCLES_PER_MICROSECOND / STEPPER_TIMER_TICKS_PER_US)
5858

59-
#define PULSE_TIMER_RATE STEPPER_TIMER_RATE // frequency of pulse timer
60-
#define PULSE_TIMER_PRESCALE STEPPER_TIMER_PRESCALE
61-
#define PULSE_TIMER_TICKS_PER_US STEPPER_TIMER_TICKS_PER_US
59+
#define PULSE_TIMER_RATE STEPPER_TIMER_RATE // frequency of pulse timer
60+
#define PULSE_TIMER_PRESCALE STEPPER_TIMER_PRESCALE
61+
#define PULSE_TIMER_TICKS_PER_US STEPPER_TIMER_TICKS_PER_US
6262

63-
#define ENABLE_STEPPER_DRIVER_INTERRUPT() HAL_timer_enable_interrupt(STEP_TIMER_NUM)
64-
#define DISABLE_STEPPER_DRIVER_INTERRUPT() HAL_timer_disable_interrupt(STEP_TIMER_NUM)
65-
#define STEPPER_ISR_ENABLED() HAL_timer_interrupt_enabled(STEP_TIMER_NUM)
63+
#define ENABLE_STEPPER_DRIVER_INTERRUPT() HAL_timer_enable_interrupt(MF_TIMER_STEP)
64+
#define DISABLE_STEPPER_DRIVER_INTERRUPT() HAL_timer_disable_interrupt(MF_TIMER_STEP)
65+
#define STEPPER_ISR_ENABLED() HAL_timer_interrupt_enabled(MF_TIMER_STEP)
6666

67-
#define ENABLE_TEMPERATURE_INTERRUPT() HAL_timer_enable_interrupt(TEMP_TIMER_NUM)
68-
#define DISABLE_TEMPERATURE_INTERRUPT() HAL_timer_disable_interrupt(TEMP_TIMER_NUM)
67+
#define ENABLE_TEMPERATURE_INTERRUPT() HAL_timer_enable_interrupt(MF_TIMER_TEMP)
68+
#define DISABLE_TEMPERATURE_INTERRUPT() HAL_timer_disable_interrupt(MF_TIMER_TEMP)
6969

7070
#ifndef HAL_STEP_TIMER_ISR
7171
#define HAL_STEP_TIMER_ISR() void TC2_Handler()
@@ -92,7 +92,7 @@ typedef struct {
9292
// Public Variables
9393
// ------------------------
9494

95-
extern const tTimerConfig TimerConfig[];
95+
extern const tTimerConfig timer_config[];
9696

9797
// ------------------------
9898
// Public functions
@@ -101,17 +101,17 @@ extern const tTimerConfig TimerConfig[];
101101
void HAL_timer_start(const uint8_t timer_num, const uint32_t frequency);
102102

103103
FORCE_INLINE static void HAL_timer_set_compare(const uint8_t timer_num, const hal_timer_t compare) {
104-
const tTimerConfig * const pConfig = &TimerConfig[timer_num];
104+
const tTimerConfig * const pConfig = &timer_config[timer_num];
105105
pConfig->pTimerRegs->TC_CHANNEL[pConfig->channel].TC_RC = compare;
106106
}
107107

108108
FORCE_INLINE static hal_timer_t HAL_timer_get_compare(const uint8_t timer_num) {
109-
const tTimerConfig * const pConfig = &TimerConfig[timer_num];
109+
const tTimerConfig * const pConfig = &timer_config[timer_num];
110110
return pConfig->pTimerRegs->TC_CHANNEL[pConfig->channel].TC_RC;
111111
}
112112

113113
FORCE_INLINE static hal_timer_t HAL_timer_get_count(const uint8_t timer_num) {
114-
const tTimerConfig * const pConfig = &TimerConfig[timer_num];
114+
const tTimerConfig * const pConfig = &timer_config[timer_num];
115115
return pConfig->pTimerRegs->TC_CHANNEL[pConfig->channel].TC_CV;
116116
}
117117

@@ -120,7 +120,7 @@ void HAL_timer_disable_interrupt(const uint8_t timer_num);
120120
bool HAL_timer_interrupt_enabled(const uint8_t timer_num);
121121

122122
FORCE_INLINE static void HAL_timer_isr_prologue(const uint8_t timer_num) {
123-
const tTimerConfig * const pConfig = &TimerConfig[timer_num];
123+
const tTimerConfig * const pConfig = &timer_config[timer_num];
124124
// Reading the status register clears the interrupt flag
125125
pConfig->pTimerRegs->TC_CHANNEL[pConfig->channel].TC_SR;
126126
}

Marlin/src/HAL/ESP32/HAL.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ void analogWrite(pin_t pin, int value) {
276276
idx = numPWMUsed;
277277
pwmPins[idx] = pin;
278278
// Start timer on first use
279-
if (idx == 0) HAL_timer_start(PWM_TIMER_NUM, PWM_TIMER_FREQUENCY);
279+
if (idx == 0) HAL_timer_start(MF_TIMER_PWM, PWM_TIMER_FREQUENCY);
280280

281281
++numPWMUsed;
282282
}
@@ -287,7 +287,7 @@ void analogWrite(pin_t pin, int value) {
287287

288288
// Handle PWM timer interrupt
289289
HAL_PWM_TIMER_ISR() {
290-
HAL_timer_isr_prologue(PWM_TIMER_NUM);
290+
HAL_timer_isr_prologue(MF_TIMER_PWM);
291291

292292
static uint8_t count = 0;
293293

@@ -301,7 +301,7 @@ HAL_PWM_TIMER_ISR() {
301301
// 128 for 7 Bit resolution
302302
count = (count + 1) & 0x7F;
303303

304-
HAL_timer_isr_epilogue(PWM_TIMER_NUM);
304+
HAL_timer_isr_epilogue(MF_TIMER_PWM);
305305
}
306306

307307
#endif // ARDUINO_ARCH_ESP32

Marlin/src/HAL/ESP32/Tone.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,16 +38,16 @@ volatile static int32_t toggles;
3838
void tone(const pin_t _pin, const unsigned int frequency, const unsigned long duration) {
3939
tone_pin = _pin;
4040
toggles = 2 * frequency * duration / 1000;
41-
HAL_timer_start(TONE_TIMER_NUM, 2 * frequency);
41+
HAL_timer_start(MF_TIMER_TONE, 2 * frequency);
4242
}
4343

4444
void noTone(const pin_t _pin) {
45-
HAL_timer_disable_interrupt(TONE_TIMER_NUM);
45+
HAL_timer_disable_interrupt(MF_TIMER_TONE);
4646
WRITE(_pin, LOW);
4747
}
4848

4949
HAL_TONE_TIMER_ISR() {
50-
HAL_timer_isr_prologue(TONE_TIMER_NUM);
50+
HAL_timer_isr_prologue(MF_TIMER_TONE);
5151

5252
if (toggles) {
5353
toggles--;

Marlin/src/HAL/ESP32/timers.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141

4242
static timg_dev_t *TG[2] = {&TIMERG0, &TIMERG1};
4343

44-
const tTimerConfig TimerConfig [NUM_HARDWARE_TIMERS] = {
44+
const tTimerConfig timer_config[NUM_HARDWARE_TIMERS] = {
4545
{ TIMER_GROUP_0, TIMER_0, STEPPER_TIMER_PRESCALE, stepTC_Handler }, // 0 - Stepper
4646
{ TIMER_GROUP_0, TIMER_1, TEMP_TIMER_PRESCALE, tempTC_Handler }, // 1 - Temperature
4747
{ TIMER_GROUP_1, TIMER_0, PWM_TIMER_PRESCALE, pwmTC_Handler }, // 2 - PWM
@@ -53,7 +53,7 @@ const tTimerConfig TimerConfig [NUM_HARDWARE_TIMERS] = {
5353
// ------------------------
5454

5555
void IRAM_ATTR timer_isr(void *para) {
56-
const tTimerConfig& timer = TimerConfig[(int)para];
56+
const tTimerConfig& timer = timer_config[(int)para];
5757

5858
// Retrieve the interrupt status and the counter value
5959
// from the timer that reported the interrupt
@@ -82,7 +82,7 @@ void IRAM_ATTR timer_isr(void *para) {
8282
* @param frequency frequency of the timer
8383
*/
8484
void HAL_timer_start(const uint8_t timer_num, uint32_t frequency) {
85-
const tTimerConfig timer = TimerConfig[timer_num];
85+
const tTimerConfig timer = timer_config[timer_num];
8686

8787
timer_config_t config;
8888
config.divider = timer.divider;
@@ -115,7 +115,7 @@ void HAL_timer_start(const uint8_t timer_num, uint32_t frequency) {
115115
* @param count threshold at which the interrupt is triggered
116116
*/
117117
void HAL_timer_set_compare(const uint8_t timer_num, hal_timer_t count) {
118-
const tTimerConfig timer = TimerConfig[timer_num];
118+
const tTimerConfig timer = timer_config[timer_num];
119119
timer_set_alarm_value(timer.group, timer.idx, count);
120120
}
121121

@@ -125,7 +125,7 @@ void HAL_timer_set_compare(const uint8_t timer_num, hal_timer_t count) {
125125
* @return the timer current threshold for the alarm to be triggered
126126
*/
127127
hal_timer_t HAL_timer_get_compare(const uint8_t timer_num) {
128-
const tTimerConfig timer = TimerConfig[timer_num];
128+
const tTimerConfig timer = timer_config[timer_num];
129129

130130
uint64_t alarm_value;
131131
timer_get_alarm_value(timer.group, timer.idx, &alarm_value);
@@ -139,7 +139,7 @@ hal_timer_t HAL_timer_get_compare(const uint8_t timer_num) {
139139
* @return the current counter of the alarm
140140
*/
141141
hal_timer_t HAL_timer_get_count(const uint8_t timer_num) {
142-
const tTimerConfig timer = TimerConfig[timer_num];
142+
const tTimerConfig timer = timer_config[timer_num];
143143
uint64_t counter_value;
144144
timer_get_counter_value(timer.group, timer.idx, &counter_value);
145145
return counter_value;
@@ -150,7 +150,7 @@ hal_timer_t HAL_timer_get_count(const uint8_t timer_num) {
150150
* @param timer_num timer number to enable interrupts on
151151
*/
152152
void HAL_timer_enable_interrupt(const uint8_t timer_num) {
153-
//const tTimerConfig timer = TimerConfig[timer_num];
153+
//const tTimerConfig timer = timer_config[timer_num];
154154
//timer_enable_intr(timer.group, timer.idx);
155155
}
156156

@@ -159,12 +159,12 @@ void HAL_timer_enable_interrupt(const uint8_t timer_num) {
159159
* @param timer_num timer number to disable interrupts on
160160
*/
161161
void HAL_timer_disable_interrupt(const uint8_t timer_num) {
162-
//const tTimerConfig timer = TimerConfig[timer_num];
162+
//const tTimerConfig timer = timer_config[timer_num];
163163
//timer_disable_intr(timer.group, timer.idx);
164164
}
165165

166166
bool HAL_timer_interrupt_enabled(const uint8_t timer_num) {
167-
const tTimerConfig timer = TimerConfig[timer_num];
167+
const tTimerConfig timer = timer_config[timer_num];
168168
return TG[timer.group]->int_ena.val | BIT(timer_num);
169169
}
170170

Marlin/src/HAL/ESP32/timers.h

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -32,20 +32,20 @@
3232
typedef uint64_t hal_timer_t;
3333
#define HAL_TIMER_TYPE_MAX 0xFFFFFFFFFFFFFFFFULL
3434

35-
#ifndef STEP_TIMER_NUM
36-
#define STEP_TIMER_NUM 0 // Timer Index for Stepper
35+
#ifndef MF_TIMER_STEP
36+
#define MF_TIMER_STEP 0 // Timer Index for Stepper
3737
#endif
38-
#ifndef PULSE_TIMER_NUM
39-
#define PULSE_TIMER_NUM STEP_TIMER_NUM
38+
#ifndef MF_TIMER_PULSE
39+
#define MF_TIMER_PULSE MF_TIMER_STEP
4040
#endif
41-
#ifndef TEMP_TIMER_NUM
42-
#define TEMP_TIMER_NUM 1 // Timer Index for Temperature
41+
#ifndef MF_TIMER_TEMP
42+
#define MF_TIMER_TEMP 1 // Timer Index for Temperature
4343
#endif
44-
#ifndef PWM_TIMER_NUM
45-
#define PWM_TIMER_NUM 2 // index of timer to use for PWM outputs
44+
#ifndef MF_TIMER_PWM
45+
#define MF_TIMER_PWM 2 // index of timer to use for PWM outputs
4646
#endif
47-
#ifndef TONE_TIMER_NUM
48-
#define TONE_TIMER_NUM 3 // index of timer for beeper tones
47+
#ifndef MF_TIMER_TONE
48+
#define MF_TIMER_TONE 3 // index of timer for beeper tones
4949
#endif
5050

5151
#define HAL_TIMER_RATE APB_CLK_FREQ // frequency of timer peripherals
@@ -79,12 +79,12 @@ typedef uint64_t hal_timer_t;
7979
#define PULSE_TIMER_PRESCALE STEPPER_TIMER_PRESCALE
8080
#define PULSE_TIMER_TICKS_PER_US STEPPER_TIMER_TICKS_PER_US
8181

82-
#define ENABLE_STEPPER_DRIVER_INTERRUPT() HAL_timer_enable_interrupt(STEP_TIMER_NUM)
83-
#define DISABLE_STEPPER_DRIVER_INTERRUPT() HAL_timer_disable_interrupt(STEP_TIMER_NUM)
84-
#define STEPPER_ISR_ENABLED() HAL_timer_interrupt_enabled(STEP_TIMER_NUM)
82+
#define ENABLE_STEPPER_DRIVER_INTERRUPT() HAL_timer_enable_interrupt(MF_TIMER_STEP)
83+
#define DISABLE_STEPPER_DRIVER_INTERRUPT() HAL_timer_disable_interrupt(MF_TIMER_STEP)
84+
#define STEPPER_ISR_ENABLED() HAL_timer_interrupt_enabled(MF_TIMER_STEP)
8585

86-
#define ENABLE_TEMPERATURE_INTERRUPT() HAL_timer_enable_interrupt(TEMP_TIMER_NUM)
87-
#define DISABLE_TEMPERATURE_INTERRUPT() HAL_timer_disable_interrupt(TEMP_TIMER_NUM)
86+
#define ENABLE_TEMPERATURE_INTERRUPT() HAL_timer_enable_interrupt(MF_TIMER_TEMP)
87+
#define DISABLE_TEMPERATURE_INTERRUPT() HAL_timer_disable_interrupt(MF_TIMER_TEMP)
8888

8989
#ifndef HAL_TEMP_TIMER_ISR
9090
#define HAL_TEMP_TIMER_ISR() extern "C" void tempTC_Handler()
@@ -121,7 +121,7 @@ typedef struct {
121121
// Public Variables
122122
// ------------------------
123123

124-
extern const tTimerConfig TimerConfig[];
124+
extern const tTimerConfig timer_config[];
125125

126126
// ------------------------
127127
// Public functions

0 commit comments

Comments
 (0)