Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

revert code changes from PR#9343 #9447

Merged
merged 1 commit into from
Jul 22, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 14 additions & 7 deletions ports/atmel-samd/common-hal/pwmio/PWMOut.c
Original file line number Diff line number Diff line change
Expand Up @@ -249,34 +249,41 @@ extern void common_hal_pwmio_pwmout_set_duty_cycle(pwmio_pwmout_obj_t *self, uin
// Track it here so that if frequency is changed we can use this value to recalculate the
// proper duty cycle.
// See https://github.com/adafruit/circuitpython/issues/2086 for more details

self->duty_cycle = duty;

const pin_timer_t *t = self->timer;
if (t->is_tc) {
uint16_t adjusted_duty = tc_periods[t->index] * duty / 0xffff;
if (adjusted_duty == 0 && duty != 0) {
adjusted_duty = 1; // prevent rounding down to 0
}
#ifdef SAMD21
tc_insts[t->index]->COUNT16.CC[t->wave_output].reg = adjusted_duty;
#endif
#ifdef SAM_D5X_E5X
Tc *tc = tc_insts[t->index];
while (tc->COUNT16.SYNCBUSY.bit.CC1 != 0) {
}
tc->COUNT16.CCBUF[1].reg = adjusted_duty;
#endif
} else {
uint32_t adjusted_duty = ((uint64_t)tcc_periods[t->index]) * duty / 0xffff;
if (adjusted_duty == 0 && duty != 0) {
adjusted_duty = 1; // prevent rounding down to 0
}
uint8_t channel = tcc_channel(t);
Tcc *tcc = tcc_insts[t->index];

// Write into the CC buffer register, which will be transferred to the
// CC register on an UPDATE (when period is finished).
// Do clock domain syncing as necessary.

while (tcc->SYNCBUSY.reg != 0) {
}

// Lock out double-buffering while updating the CCB value.
tcc->CTRLBSET.bit.LUPD = 1;
#ifdef SAMD21
tcc->CCB[channel].reg = adjusted_duty;
#endif
#ifdef SAM_D5X_E5X
tcc->CCBUF[channel].reg = adjusted_duty;
#endif
tcc->CTRLBCLR.bit.LUPD = 1;
}
}

Expand Down