Skip to content

Commit ca737e6

Browse files
committed
Don't disable tempoarily in deinit().
1 parent 91a88cf commit ca737e6

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

ports/nrf/common-hal/pulseio/PWMOut.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -196,19 +196,20 @@ void common_hal_pulseio_pwmout_deinit(pulseio_pwmout_obj_t* self) {
196196

197197
nrf_gpio_cfg_default(self->pin_number);
198198

199-
nrf_pwm_disable(self->pwm);
199+
NRF_PWM_Type* pwm = self->pwm;
200+
self->pwm = NULL;
200201

201-
self->pwm->PSEL.OUT[self->channel] = 0xFFFFFFFF;
202+
// Disconnect pin from channel.
203+
pwm->PSEL.OUT[self->channel] = 0xFFFFFFFF;
202204

203-
// Re-enable PWM module if there is another active channel.
204205
for(int i=0; i < CHANNELS_PER_PWM; i++) {
205206
if (self->pwm->PSEL.OUT[i] != 0xFFFFFFFF) {
206-
nrf_pwm_enable(self->pwm);
207-
break;
207+
// Some channel is still being used, so don't disable.
208+
return;
208209
}
209210
}
210211

211-
self->pwm = NULL;
212+
nrf_pwm_disable(pwm);
212213
}
213214

214215
void common_hal_pulseio_pwmout_set_duty_cycle(pulseio_pwmout_obj_t* self, uint16_t duty_cycle) {

0 commit comments

Comments
 (0)