@@ -69,7 +69,6 @@ STATIC uint32_t timer_get_source_freq(uint32_t tim_id) {
69
69
70
70
STATIC uint32_t timer_get_internal_duty (uint16_t duty , uint32_t period ) {
71
71
//duty cycle is duty/0xFFFF fraction x (number of pulses per period)
72
- //Note that pulses are inverted, so duty cycle is inverted
73
72
return (duty * period ) / ((1 << 16 ) - 1 );
74
73
}
75
74
@@ -114,11 +113,12 @@ pwmout_result_t common_hal_pulseio_pwmout_construct(pulseio_pwmout_obj_t* self,
114
113
bool first_time_setup = true;
115
114
116
115
for (uint i = 0 ; i < tim_num ; i ++ ) {
117
- uint8_t l_tim_index = mcu_tim_pin_list [i ].tim_index - 1 ;
118
- uint8_t l_tim_channel = mcu_tim_pin_list [i ].channel_index - 1 ;
116
+ const mcu_tim_pin_obj_t * l_tim = & mcu_tim_pin_list [i ];
117
+ uint8_t l_tim_index = l_tim -> tim_index - 1 ;
118
+ uint8_t l_tim_channel = l_tim -> channel_index - 1 ;
119
119
120
120
//if pin is same
121
- if (mcu_tim_pin_list [ i ]. pin == pin ) {
121
+ if (l_tim -> pin == pin ) {
122
122
//check if the timer has a channel active
123
123
if (reserved_tim [l_tim_index ] != 0 ) {
124
124
//is it the same channel? (or all channels reserved by a var-freq)
@@ -139,7 +139,7 @@ pwmout_result_t common_hal_pulseio_pwmout_construct(pulseio_pwmout_obj_t* self,
139
139
first_time_setup = false; //skip setting up the timer
140
140
}
141
141
//No problems taken, so set it up
142
- self -> tim = & mcu_tim_pin_list [ i ] ;
142
+ self -> tim = l_tim ;
143
143
break ;
144
144
}
145
145
}
@@ -205,9 +205,6 @@ pwmout_result_t common_hal_pulseio_pwmout_construct(pulseio_pwmout_obj_t* self,
205
205
self -> chan_handle .Pulse = timer_get_internal_duty (duty , period );
206
206
self -> chan_handle .OCPolarity = TIM_OCPOLARITY_HIGH ;
207
207
self -> chan_handle .OCFastMode = TIM_OCFAST_DISABLE ;
208
- self -> chan_handle .OCNPolarity = TIM_OCNPOLARITY_LOW ; // needed for TIM1 and TIM8
209
- self -> chan_handle .OCIdleState = TIM_OCIDLESTATE_SET ; // needed for TIM1 and TIM8
210
- self -> chan_handle .OCNIdleState = TIM_OCNIDLESTATE_SET ; // needed for TIM1 and TIM8
211
208
if (HAL_TIM_PWM_ConfigChannel (& self -> handle , & self -> chan_handle , self -> channel ) != HAL_OK ) {
212
209
mp_raise_ValueError (translate ("Could not initialize channel" ));
213
210
}
0 commit comments