Skip to content

Commit b39ca3f

Browse files
committed
Do not open the same PWM device again
1 parent 1decd11 commit b39ca3f

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,11 @@ pwmout_result_t common_hal_pulseio_pwmout_construct(pulseio_pwmout_obj_t *self,
6262
return PWMOUT_INVALID_PIN;
6363
}
6464

65-
pwmout_dev[self->number].fd = open(pwmout_dev[self->number].devpath, O_RDONLY);
6665
if (pwmout_dev[self->number].fd < 0) {
67-
return PWMOUT_INVALID_PIN;
66+
pwmout_dev[self->number].fd = open(pwmout_dev[self->number].devpath, O_RDONLY);
67+
if (pwmout_dev[self->number].fd < 0) {
68+
return PWMOUT_INVALID_PIN;
69+
}
6870
}
6971

7072
self->info.frequency = frequency;
@@ -97,7 +99,7 @@ void common_hal_pulseio_pwmout_deinit(pulseio_pwmout_obj_t *self) {
9799
}
98100

99101
bool common_hal_pulseio_pwmout_deinited(pulseio_pwmout_obj_t *self) {
100-
return self->pin == mp_const_none;
102+
return pwmout_dev[self->number].fd < 0;
101103
}
102104

103105
void common_hal_pulseio_pwmout_set_duty_cycle(pulseio_pwmout_obj_t *self, uint16_t duty) {

ports/cxd56/common-hal/pulseio/PWMOut.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ typedef struct {
3838
const mcu_pin_obj_t *pin;
3939
struct pwm_info_s info;
4040
bool variable_frequency;
41-
uint8_t number;
41+
int8_t number;
4242
} pulseio_pwmout_obj_t;
4343

4444
void pwmout_reset(void);

0 commit comments

Comments
 (0)