@@ -85,18 +85,25 @@ static int servo_timer_config(uint32_t period_us)
85
85
// Configure and enable the servo timer, for full 20ms
86
86
uint8_t type = 0 ;
87
87
int8_t channel = FspTimer::get_available_timer (type);
88
+ #ifdef SERVO_PRINT_DEBUG_INFO
89
+ Serial.print (" \n servo_timer_config: type:" );
90
+ Serial.print (type, DEC);
91
+ Serial.print (" Channel: " );
92
+ Serial.println (channel, DEC);
93
+ #endif
88
94
if (channel != -1 ) {
89
95
// lets initially configure the servo to 50ms
90
96
servo_timer.begin (TIMER_MODE_PERIODIC, type, channel,
91
97
1000000 .0f /period_us, 50 .0f , servo_timer_callback, nullptr );
92
98
93
99
// 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 );
100
107
servo_timer.open ();
101
108
servo_timer.stop ();
102
109
@@ -146,7 +153,12 @@ static int servo_timer_stop()
146
153
}
147
154
148
155
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
+ }
150
162
}
151
163
152
164
@@ -165,14 +177,15 @@ void servo_timer_callback(timer_callback_args_t *args)
165
177
// Find the next servo to set high
166
178
while (active_servos_mask_refresh) {
167
179
channel = __builtin_ctz (active_servos_mask_refresh);
168
- active_servos_mask_refresh &= ~(1 << channel);
169
180
if (ra_servos[channel].period_us ) {
170
181
*ra_servos[channel].io_port = (uint32_t )ra_servos[channel].io_mask ;
171
182
updateClockPeriod (ra_servos[channel].period_ticks );
172
183
channel_pin_set_high = channel;
173
184
ticks_accum += ra_servos[channel_pin_set_high].period_ticks ;
185
+ active_servos_mask_refresh &= ~(1 << channel);
174
186
return ;
175
187
}
188
+ active_servos_mask_refresh &= ~(1 << channel);
176
189
}
177
190
178
191
// Got to hear we finished processing all servos, now delay to start of next pass.
0 commit comments