@@ -75,9 +75,6 @@ HardwareTimer::HardwareTimer(TIM_TypeDef *instance)
75
75
void HardwareTimer::setup (TIM_TypeDef *instance)
76
76
{
77
77
uint32_t index = get_timer_index (instance);
78
- if (index == UNKNOWN_TIMER) {
79
- Error_Handler ();
80
- }
81
78
82
79
// Already initialized?
83
80
if (_timerObj.handle .Instance ) {
@@ -174,14 +171,7 @@ void HardwareTimer::pauseChannel(uint32_t channel)
174
171
175
172
int timAssociatedInputChannel;
176
173
int LLChannel = getLLChannel (channel);
177
- if (LLChannel == -1 ) {
178
- Error_Handler ();
179
- }
180
-
181
174
int interrupt = getIT (channel);
182
- if (interrupt == -1 ) {
183
- Error_Handler ();
184
- }
185
175
186
176
// Disable channel and corresponding interrupt
187
177
__HAL_TIM_DISABLE_IT (&(_timerObj.handle ), interrupt);
@@ -234,11 +224,11 @@ void HardwareTimer::resume(void)
234
224
/* *
235
225
* @brief Convert arduino channel into HAL channel
236
226
* @param Arduino channel [1..4]
237
- * @retval HAL channel. return -1 if arduino channel is invalid
227
+ * @retval HAL channel. Error handler called if arduino channel is invalid
238
228
*/
239
229
int HardwareTimer::getChannel (uint32_t channel)
240
230
{
241
- uint32_t return_value;
231
+ int return_value = - 1 ;
242
232
243
233
switch (channel) {
244
234
case 1 :
@@ -254,15 +244,15 @@ int HardwareTimer::getChannel(uint32_t channel)
254
244
return_value = TIM_CHANNEL_4;
255
245
break ;
256
246
default :
257
- return_value = - 1 ;
247
+ Error_Handler () ;
258
248
}
259
249
return return_value;
260
250
}
261
251
262
252
/* *
263
253
* @brief Convert arduino channel into LL channels used (regular and/or complementary)
264
254
* @param Arduino channel [1..4]
265
- * @retval LL channel. return -1 if arduino channel is invalid
255
+ * @retval LL channel. Error handler called if arduino channel is invalid
266
256
*/
267
257
int HardwareTimer::getLLChannel (uint32_t channel)
268
258
{
@@ -310,17 +300,20 @@ int HardwareTimer::getLLChannel(uint32_t channel)
310
300
return_value = -1 ;
311
301
}
312
302
}
303
+ if (return_value == -1 ) {
304
+ Error_Handler ();
305
+ }
313
306
return return_value;
314
307
}
315
308
316
309
/* *
317
310
* @brief Convert arduino channel into HAL Interrupt ID
318
311
* @param Arduino channel [1..4]
319
- * @retval HAL channel. return -1 if arduino channel is invalid
312
+ * @retval HAL channel. Error handler called if arduino channel is invalid
320
313
*/
321
314
int HardwareTimer::getIT (uint32_t channel)
322
315
{
323
- uint32_t return_value;
316
+ int return_value = - 1 ;
324
317
325
318
switch (channel) {
326
319
case 1 :
@@ -336,7 +329,7 @@ int HardwareTimer::getIT(uint32_t channel)
336
329
return_value = TIM_IT_CC4;
337
330
break ;
338
331
default :
339
- return_value = - 1 ;
332
+ Error_Handler () ;
340
333
}
341
334
return return_value;
342
335
}
@@ -378,19 +371,7 @@ void HardwareTimer::resumeChannel(uint32_t channel)
378
371
{
379
372
int timChannel = getChannel (channel);
380
373
int timAssociatedInputChannel;
381
- if (timChannel == -1 ) {
382
- Error_Handler ();
383
- }
384
-
385
374
int interrupt = getIT (channel);
386
- if (interrupt == -1 ) {
387
- Error_Handler ();
388
- }
389
-
390
- int LLChannel = getLLChannel (channel);
391
- if (LLChannel == -1 ) {
392
- Error_Handler ();
393
- }
394
375
395
376
// Clear flag and enable IT
396
377
if (callbacks[channel]) {
@@ -643,10 +624,6 @@ void HardwareTimer::setMode(uint32_t channel, TimerModes_t mode, PinName pin, Ch
643
624
TIM_OC_InitTypeDef channelOC;
644
625
TIM_IC_InitTypeDef channelIC;
645
626
646
- if (timChannel == -1 ) {
647
- Error_Handler ();
648
- }
649
-
650
627
/* Configure some default values. Maybe overwritten later */
651
628
channelOC.OCMode = TIMER_NOT_USED;
652
629
channelOC.Pulse = __HAL_TIM_GET_COMPARE (&(_timerObj.handle ), timChannel); // keep same value already written in hardware register
@@ -822,10 +799,6 @@ void HardwareTimer::setCaptureCompare(uint32_t channel, uint32_t compare, TimerC
822
799
uint32_t Prescalerfactor = LL_TIM_GetPrescaler (_timerObj.handle .Instance ) + 1 ;
823
800
uint32_t CCR_RegisterValue;
824
801
825
- if (timChannel == -1 ) {
826
- Error_Handler ();
827
- }
828
-
829
802
switch (format) {
830
803
case MICROSEC_COMPARE_FORMAT:
831
804
CCR_RegisterValue = ((compare * (getTimerClkFreq () / 1000000 )) / Prescalerfactor);
@@ -889,10 +862,6 @@ uint32_t HardwareTimer::getCaptureCompare(uint32_t channel, TimerCompareFormat_
889
862
uint32_t Prescalerfactor = LL_TIM_GetPrescaler (_timerObj.handle .Instance ) + 1 ;
890
863
uint32_t return_value;
891
864
892
- if (timChannel == -1 ) {
893
- Error_Handler ();
894
- }
895
-
896
865
switch (format) {
897
866
case MICROSEC_COMPARE_FORMAT:
898
867
return_value = (uint32_t )((CCR_RegisterValue * Prescalerfactor * 1000000.0 ) / getTimerClkFreq ());
@@ -1030,9 +999,6 @@ void HardwareTimer::detachInterrupt()
1030
999
void HardwareTimer::attachInterrupt (uint32_t channel, callback_function_t callback)
1031
1000
{
1032
1001
int interrupt = getIT (channel);
1033
- if (interrupt == -1 ) {
1034
- Error_Handler ();
1035
- }
1036
1002
1037
1003
if ((channel == 0 ) || (channel > (TIMER_CHANNELS + 1 ))) {
1038
1004
Error_Handler (); // only channel 1..4 have an interrupt
@@ -1059,9 +1025,6 @@ void HardwareTimer::attachInterrupt(uint32_t channel, callback_function_t callba
1059
1025
void HardwareTimer::detachInterrupt (uint32_t channel)
1060
1026
{
1061
1027
int interrupt = getIT (channel);
1062
- if (interrupt == -1 ) {
1063
- Error_Handler ();
1064
- }
1065
1028
1066
1029
if ((channel == 0 ) || (channel > (TIMER_CHANNELS + 1 ))) {
1067
1030
Error_Handler (); // only channel 1..4 have an interrupt
@@ -1198,14 +1161,6 @@ bool HardwareTimer::isRunningChannel(uint32_t channel)
1198
1161
int interrupt = getIT (channel);
1199
1162
bool ret;
1200
1163
1201
- if (LLChannel == -1 ) {
1202
- Error_Handler ();
1203
- }
1204
-
1205
- if (interrupt == -1 ) {
1206
- Error_Handler ();
1207
- }
1208
-
1209
1164
// channel is running if: timer is running, and either output channel is
1210
1165
// enabled or interrupt is set
1211
1166
ret = LL_TIM_CC_IsEnabledChannel (_timerObj.handle .Instance , LLChannel)
@@ -1365,6 +1320,9 @@ timer_index_t get_timer_index(TIM_TypeDef *instance)
1365
1320
index = TIMER22_INDEX;
1366
1321
}
1367
1322
#endif
1323
+ if (index == UNKNOWN_TIMER) {
1324
+ Error_Handler ();
1325
+ }
1368
1326
return index ;
1369
1327
}
1370
1328
0 commit comments