summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Halbert <halbert@halwitz.org>2018-09-11 19:45:22 -0400
committerDan Halbert <halbert@halwitz.org>2018-09-11 19:46:47 -0400
commitc3918bae575665895da0dc86d4c430a22a25bf67 (patch)
tree0149d8fc80661571df6752f1120a9933eff7ba7e
parentcaa232823e8118469472a670e1246f7af3452a76 (diff)
PWMOut was not claming channels on shared TCCs
-rw-r--r--ports/atmel-samd/common-hal/pulseio/PWMOut.c11
1 files changed, 7 insertions, 4 deletions
diff --git a/ports/atmel-samd/common-hal/pulseio/PWMOut.c b/ports/atmel-samd/common-hal/pulseio/PWMOut.c
index 9c04f91fa..a7a0574fe 100644
--- a/ports/atmel-samd/common-hal/pulseio/PWMOut.c
+++ b/ports/atmel-samd/common-hal/pulseio/PWMOut.c
@@ -51,10 +51,10 @@ uint8_t tcc_refcount[TCC_INST_NUM];
// This bitmask keeps track of which channels of a TCC are currently claimed.
#ifdef SAMD21
-uint8_t tcc_channels[3] = {0xf0, 0xfc, 0xfc};
+uint8_t tcc_channels[3]; // Set by pwmout_reset() to {0xf0, 0xfc, 0xfc} initially.
#endif
#ifdef SAMD51
-uint8_t tcc_channels[5] = {0xc0, 0xf0, 0xf8, 0xfc, 0xfc};
+uint8_t tcc_channels[5]; // Set by pwmout_reset() to {0xc0, 0xf0, 0xf8, 0xfc, 0xfc} initially.
#endif
void pwmout_reset(void) {
@@ -75,7 +75,7 @@ void pwmout_reset(void) {
for (uint8_t j = 0; j < tcc_cc_num[i]; j++) {
mask <<= 1;
}
- tcc_channels[i] = 0xf0;
+ tcc_channels[i] = mask;
tccs[i]->CTRLA.bit.SWRST = 1;
}
Tc *tcs[TC_INST_NUM] = TC_INSTS;
@@ -122,7 +122,7 @@ void common_hal_pulseio_pwmout_construct(pulseio_pwmout_obj_t* self,
// Figure out which timer we are using.
// First see if a tcc is already going with the frequency we want and our
- // channel is unused. tc's don't have neough channels to share.
+ // channel is unused. tc's don't have enough channels to share.
const pin_timer_t* timer = NULL;
uint8_t mux_position = 0;
if (!variable_frequency) {
@@ -139,6 +139,9 @@ void common_hal_pulseio_pwmout_construct(pulseio_pwmout_obj_t* self,
if (tcc->CTRLA.bit.ENABLE == 1 && channel_ok(t)) {
timer = t;
mux_position = j;
+ // Claim channel.
+ tcc_channels[timer->index] |= (1 << tcc_channel(timer));
+
}
}
}