Skip to content

Commit 604d84f

Browse files
committed
Initial support if FspTimer is AGT timer
Note FSP->AGT timer code is completely busted Will produce PR to hopefully fix it.
1 parent 4969711 commit 604d84f

File tree

1 file changed

+21
-8
lines changed

1 file changed

+21
-8
lines changed

src/renesas/Servo.cpp

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -85,18 +85,25 @@ static int servo_timer_config(uint32_t period_us)
8585
// Configure and enable the servo timer, for full 20ms
8686
uint8_t type = 0;
8787
int8_t channel = FspTimer::get_available_timer(type);
88+
#ifdef SERVO_PRINT_DEBUG_INFO
89+
Serial.print("\nservo_timer_config: type:");
90+
Serial.print(type, DEC);
91+
Serial.print(" Channel: ");
92+
Serial.println(channel, DEC);
93+
#endif
8894
if (channel != -1) {
8995
// lets initially configure the servo to 50ms
9096
servo_timer.begin(TIMER_MODE_PERIODIC, type, channel,
9197
1000000.0f/period_us, 50.0f, servo_timer_callback, nullptr);
9298

9399
// First pass assume GPT timer
94-
s_pgpt0 = (R_GPT0_Type *)((uint32_t)R_GPT0 + ((uint32_t)R_GPT1 - (uint32_t)R_GPT0) * channel);
95-
// turn off GTPR Buffer
96-
s_pgpt0->GTBER_b.PR = 0;
97-
s_pgpt0->GTBER_b.BD1 = 1;
98-
99-
servo_timer.setup_overflow_irq();
100+
if (type == GPT_TIMER) {
101+
s_pgpt0 = (R_GPT0_Type *)((uint32_t)R_GPT0 + ((uint32_t)R_GPT1 - (uint32_t)R_GPT0) * channel);
102+
// turn off GTPR Buffer
103+
s_pgpt0->GTBER_b.PR = 0;
104+
s_pgpt0->GTBER_b.BD1 = 1;
105+
}
106+
servo_timer.setup_overflow_irq(10);
100107
servo_timer.open();
101108
servo_timer.stop();
102109

@@ -146,7 +153,12 @@ static int servo_timer_stop()
146153
}
147154

148155
inline static void updateClockPeriod(uint32_t period) {
149-
if (s_pgpt0) s_pgpt0->GTPR = period;
156+
if (s_pgpt0) {
157+
s_pgpt0->GTPR = period;
158+
} else {
159+
// AGT...
160+
servo_timer.set_period(period);
161+
}
150162
}
151163

152164

@@ -165,14 +177,15 @@ void servo_timer_callback(timer_callback_args_t *args)
165177
// Find the next servo to set high
166178
while (active_servos_mask_refresh) {
167179
channel = __builtin_ctz(active_servos_mask_refresh);
168-
active_servos_mask_refresh &= ~(1 << channel);
169180
if (ra_servos[channel].period_us) {
170181
*ra_servos[channel].io_port = (uint32_t)ra_servos[channel].io_mask;
171182
updateClockPeriod(ra_servos[channel].period_ticks);
172183
channel_pin_set_high = channel;
173184
ticks_accum += ra_servos[channel_pin_set_high].period_ticks;
185+
active_servos_mask_refresh &= ~(1 << channel);
174186
return;
175187
}
188+
active_servos_mask_refresh &= ~(1 << channel);
176189
}
177190

178191
// Got to hear we finished processing all servos, now delay to start of next pass.

0 commit comments

Comments
 (0)