@@ -69,7 +69,6 @@ STATIC uint32_t timer_get_source_freq(uint32_t tim_id) {
6969
7070STATIC uint32_t timer_get_internal_duty (uint16_t duty , uint32_t period ) {
7171 //duty cycle is duty/0xFFFF fraction x (number of pulses per period)
72- //Note that pulses are inverted, so duty cycle is inverted
7372 return (duty * period ) / ((1 << 16 ) - 1 );
7473}
7574
@@ -114,11 +113,12 @@ pwmout_result_t common_hal_pulseio_pwmout_construct(pulseio_pwmout_obj_t* self,
114113 bool first_time_setup = true;
115114
116115 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 ;
119119
120120 //if pin is same
121- if (mcu_tim_pin_list [ i ]. pin == pin ) {
121+ if (l_tim -> pin == pin ) {
122122 //check if the timer has a channel active
123123 if (reserved_tim [l_tim_index ] != 0 ) {
124124 //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,
139139 first_time_setup = false; //skip setting up the timer
140140 }
141141 //No problems taken, so set it up
142- self -> tim = & mcu_tim_pin_list [ i ] ;
142+ self -> tim = l_tim ;
143143 break ;
144144 }
145145 }
@@ -205,9 +205,6 @@ pwmout_result_t common_hal_pulseio_pwmout_construct(pulseio_pwmout_obj_t* self,
205205 self -> chan_handle .Pulse = timer_get_internal_duty (duty , period );
206206 self -> chan_handle .OCPolarity = TIM_OCPOLARITY_HIGH ;
207207 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
211208 if (HAL_TIM_PWM_ConfigChannel (& self -> handle , & self -> chan_handle , self -> channel ) != HAL_OK ) {
212209 mp_raise_ValueError (translate ("Could not initialize channel" ));
213210 }
0 commit comments