Skip to content

Commit 859a487

Browse files
authored
Merge pull request #7633 from tannewt/fix_imx_pwm
Fix `pwmio` on iMX RT.
2 parents 8e4626f + 1acf65e commit 859a487

File tree

10 files changed

+242
-198
lines changed

10 files changed

+242
-198
lines changed

ports/atmel-samd/common-hal/pwmio/PWMOut.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,6 @@ void common_hal_pwmio_pwmout_never_reset(pwmio_pwmout_obj_t *self) {
6767
never_reset_pin_number(self->pin->number);
6868
}
6969

70-
void common_hal_pwmio_pwmout_reset_ok(pwmio_pwmout_obj_t *self) {
71-
timer_reset_ok(self->timer->index, self->timer->is_tc);
72-
}
73-
7470
void pwmout_reset(void) {
7571
// Reset all timers
7672
for (int i = 0; i < TCC_INST_NUM; i++) {
@@ -267,6 +263,7 @@ void common_hal_pwmio_pwmout_deinit(pwmio_pwmout_obj_t *self) {
267263
if (common_hal_pwmio_pwmout_deinited(self)) {
268264
return;
269265
}
266+
timer_reset_ok(self->timer->index, self->timer->is_tc);
270267
const pin_timer_t *t = self->timer;
271268
if (t->is_tc) {
272269
Tc *tc = tc_insts[t->index];

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ void common_hal_pwmio_pwmout_deinit(pwmio_pwmout_obj_t *self) {
9090
return;
9191
}
9292

93+
pwmout_dev[self->number].reset = true;
94+
9395
ioctl(pwmout_dev[self->number].fd, PWMIOC_STOP, 0);
9496
close(pwmout_dev[self->number].fd);
9597
pwmout_dev[self->number].fd = -1;
@@ -134,10 +136,6 @@ void common_hal_pwmio_pwmout_never_reset(pwmio_pwmout_obj_t *self) {
134136
pwmout_dev[self->number].reset = false;
135137
}
136138

137-
void common_hal_pwmio_pwmout_reset_ok(pwmio_pwmout_obj_t *self) {
138-
pwmout_dev[self->number].reset = true;
139-
}
140-
141139
void pwmout_reset(void) {
142140
for (int i = 0; i < MP_ARRAY_SIZE(pwmout_dev); i++) {
143141
if (pwmout_dev[i].fd >= 0 && pwmout_dev[i].reset) {

ports/espressif/common-hal/pwmio/PWMOut.c

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -164,24 +164,6 @@ void common_hal_pwmio_pwmout_never_reset(pwmio_pwmout_obj_t *self) {
164164
never_reset_pin_number(self->pin->number);
165165
}
166166

167-
void common_hal_pwmio_pwmout_reset_ok(pwmio_pwmout_obj_t *self) {
168-
never_reset_tim[self->tim_handle.timer_num] = false;
169-
// Search if any other channel is using the timer and is never reset.
170-
// Otherwise, we clear never_reset for the timer as well.
171-
bool other_never_reset = false;
172-
for (size_t i = 0; i < LEDC_CHANNEL_MAX; i++) {
173-
if (i != self->chan_handle.channel &&
174-
reserved_channels[i] == self->tim_handle.timer_num &&
175-
never_reset_chan[i]) {
176-
other_never_reset = true;
177-
break;
178-
}
179-
}
180-
if (!other_never_reset) {
181-
never_reset_chan[self->chan_handle.channel] = false;
182-
}
183-
}
184-
185167
bool common_hal_pwmio_pwmout_deinited(pwmio_pwmout_obj_t *self) {
186168
return self->deinited == true;
187169
}
@@ -196,14 +178,21 @@ void common_hal_pwmio_pwmout_deinit(pwmio_pwmout_obj_t *self) {
196178
}
197179
reserved_channels[self->chan_handle.channel] = INDEX_EMPTY;
198180
never_reset_chan[self->chan_handle.channel] = false;
181+
199182
// Search if any other channel is using the timer
200183
bool taken = false;
184+
bool other_never_reset = false;
201185
for (size_t i = 0; i < LEDC_CHANNEL_MAX; i++) {
202186
if (reserved_channels[i] == self->tim_handle.timer_num) {
203187
taken = true;
188+
other_never_reset = never_reset_chan[i];
204189
break;
205190
}
206191
}
192+
// Clear the timer's never reset if the other channel isn't never reset.
193+
if (!other_never_reset) {
194+
never_reset_tim[self->tim_handle.timer_num] = false;
195+
}
207196
// Variable frequency means there's only one channel on the timer
208197
if (!taken || self->variable_frequency) {
209198
ledc_timer_rst(LEDC_LOW_SPEED_MODE, self->tim_handle.timer_num);

0 commit comments

Comments
 (0)