@@ -48,7 +48,7 @@ enum capture_state {
48
48
/** Return the complementary channel number
49
49
* that is used to capture the end of the pulse.
50
50
*/
51
- static const uint32_t complementary_channel [] = {0 , 2 , 1 , 4 , 3 };
51
+ static const uint32_t complementary_channel [] = {2 , 1 , 4 , 3 };
52
52
53
53
struct pwm_stm32_capture_data {
54
54
pwm_capture_callback_handler_t callback ;
@@ -325,7 +325,7 @@ static void init_capture_channels(const struct device *dev, uint32_t channel,
325
325
TIM_TypeDef * timer = cfg -> timer ;
326
326
bool is_inverted = (flags & PWM_POLARITY_MASK ) == PWM_POLARITY_INVERTED ;
327
327
uint32_t ll_channel = ch2ll [channel - 1 ];
328
- uint32_t ll_complementary_channel = ch2ll [complementary_channel [channel ] - 1 ];
328
+ uint32_t ll_complementary_channel = ch2ll [complementary_channel [channel - 1 ] - 1 ];
329
329
330
330
331
331
/* Setup main channel */
@@ -469,7 +469,7 @@ static int pwm_stm32_enable_capture(const struct device *dev, uint32_t channel)
469
469
enable_capture_interrupt [channel - 1 ](timer );
470
470
471
471
LL_TIM_CC_EnableChannel (timer , ch2ll [channel - 1 ]);
472
- LL_TIM_CC_EnableChannel (timer , ch2ll [complementary_channel [channel ] - 1 ]);
472
+ LL_TIM_CC_EnableChannel (timer , ch2ll [complementary_channel [channel - 1 ] - 1 ]);
473
473
LL_TIM_GenerateEvent_UPDATE (timer );
474
474
475
475
return 0 ;
@@ -498,7 +498,7 @@ static int pwm_stm32_disable_capture(const struct device *dev, uint32_t channel)
498
498
499
499
LL_TIM_DisableIT_UPDATE (timer );
500
500
LL_TIM_CC_DisableChannel (timer , ch2ll [channel - 1 ]);
501
- LL_TIM_CC_DisableChannel (timer , ch2ll [complementary_channel [channel ] - 1 ]);
501
+ LL_TIM_CC_DisableChannel (timer , ch2ll [complementary_channel [channel - 1 ] - 1 ]);
502
502
503
503
return 0 ;
504
504
}
@@ -509,6 +509,7 @@ static void pwm_stm32_isr(const struct device *dev)
509
509
TIM_TypeDef * timer = cfg -> timer ;
510
510
struct pwm_stm32_data * data = dev -> data ;
511
511
struct pwm_stm32_capture_data * cpt = & data -> capture ;
512
+ uint8_t channel = cpt -> channel ;
512
513
int status = 0 ;
513
514
514
515
if (cpt -> skip_irq != 0u ) {
@@ -542,19 +543,19 @@ static void pwm_stm32_isr(const struct device *dev)
542
543
}
543
544
544
545
if (!cfg -> four_channel_capture_support ) {
545
- if (is_capture_active [cpt -> channel - 1 ](timer ) ||
546
- is_capture_active [complementary_channel [cpt -> channel ] - 1 ](timer )) {
547
- clear_capture_interrupt [cpt -> channel - 1 ](timer );
546
+ if (is_capture_active [channel - 1 ](timer ) ||
547
+ is_capture_active [complementary_channel [channel - 1 ] - 1 ](timer )) {
548
+ clear_capture_interrupt [channel - 1 ](timer );
548
549
clear_capture_interrupt
549
- [complementary_channel [cpt -> channel ] - 1 ](timer );
550
+ [complementary_channel [channel - 1 ] - 1 ](timer );
550
551
551
- cpt -> period = get_channel_capture [cpt -> channel - 1 ](timer );
552
+ cpt -> period = get_channel_capture [channel - 1 ](timer );
552
553
cpt -> pulse = get_channel_capture
553
- [complementary_channel [cpt -> channel ] - 1 ](timer );
554
+ [complementary_channel [channel - 1 ] - 1 ](timer );
554
555
}
555
556
} else {
556
557
if (cpt -> state == CAPTURE_STATE_WAIT_FOR_PULSE_START &&
557
- is_capture_active [cpt -> channel - 1 ](timer )) {
558
+ is_capture_active [channel - 1 ](timer )) {
558
559
/* Reset the counter manually instead of automatically by HW
559
560
* This sets the pulse-start at 0 and makes the pulse-end
560
561
* and period related to that number. Sure we loose some
@@ -569,19 +570,19 @@ static void pwm_stm32_isr(const struct device *dev)
569
570
570
571
} else if ((cpt -> state == CAPTURE_STATE_WAIT_FOR_UPDATE_EVENT ||
571
572
cpt -> state == CAPTURE_STATE_WAIT_FOR_PERIOD_END ) &&
572
- is_capture_active [cpt -> channel - 1 ](timer )) {
573
+ is_capture_active [channel - 1 ](timer )) {
573
574
cpt -> state = CAPTURE_STATE_IDLE ;
574
575
/* The end of the period. Both capture channels should now contain
575
576
* the timer value when the pulse and period ended respectively.
576
577
*/
577
- cpt -> pulse = get_channel_capture [complementary_channel [cpt -> channel ] - 1 ]
578
+ cpt -> pulse = get_channel_capture [complementary_channel [channel - 1 ] - 1 ]
578
579
(timer );
579
- cpt -> period = get_channel_capture [cpt -> channel - 1 ](timer );
580
+ cpt -> period = get_channel_capture [channel - 1 ](timer );
580
581
/* Reset the counter manually for next cycle */
581
582
LL_TIM_GenerateEvent_UPDATE (timer );
582
583
}
583
584
584
- clear_capture_interrupt [cpt -> channel - 1 ](timer );
585
+ clear_capture_interrupt [channel - 1 ](timer );
585
586
586
587
if (cpt -> state != CAPTURE_STATE_IDLE ) {
587
588
/* Still waiting for a complete capture */
@@ -594,14 +595,14 @@ static void pwm_stm32_isr(const struct device *dev)
594
595
}
595
596
596
597
if (!cpt -> continuous ) {
597
- pwm_stm32_disable_capture (dev , cpt -> channel );
598
+ pwm_stm32_disable_capture (dev , channel );
598
599
} else {
599
600
cpt -> overflows = 0u ;
600
601
cpt -> state = CAPTURE_STATE_WAIT_FOR_PERIOD_END ;
601
602
}
602
603
603
604
if (cpt -> callback != NULL ) {
604
- cpt -> callback (dev , cpt -> channel , cpt -> capture_period ? cpt -> period : 0u ,
605
+ cpt -> callback (dev , channel , cpt -> capture_period ? cpt -> period : 0u ,
605
606
cpt -> capture_pulse ? cpt -> pulse : 0u , status , cpt -> user_data );
606
607
}
607
608
}
0 commit comments