@@ -51,10 +51,10 @@ uint8_t tcc_refcount[TCC_INST_NUM];
51
51
52
52
// This bitmask keeps track of which channels of a TCC are currently claimed.
53
53
#ifdef SAMD21
54
- uint8_t tcc_channels [3 ] = {0xf0 , 0xfc , 0xfc };
54
+ uint8_t tcc_channels [3 ]; // Set by pwmout_reset() to {0xf0, 0xfc, 0xfc} initially.
55
55
#endif
56
56
#ifdef SAMD51
57
- uint8_t tcc_channels [5 ] = {0xc0 , 0xf0 , 0xf8 , 0xfc , 0xfc };
57
+ uint8_t tcc_channels [5 ]; // Set by pwmout_reset() to {0xc0, 0xf0, 0xf8, 0xfc, 0xfc} initially.
58
58
#endif
59
59
60
60
void pwmout_reset (void ) {
@@ -75,7 +75,7 @@ void pwmout_reset(void) {
75
75
for (uint8_t j = 0 ; j < tcc_cc_num [i ]; j ++ ) {
76
76
mask <<= 1 ;
77
77
}
78
- tcc_channels [i ] = 0xf0 ;
78
+ tcc_channels [i ] = mask ;
79
79
tccs [i ]-> CTRLA .bit .SWRST = 1 ;
80
80
}
81
81
Tc * tcs [TC_INST_NUM ] = TC_INSTS ;
@@ -122,7 +122,7 @@ void common_hal_pulseio_pwmout_construct(pulseio_pwmout_obj_t* self,
122
122
// Figure out which timer we are using.
123
123
124
124
// First see if a tcc is already going with the frequency we want and our
125
- // channel is unused. tc's don't have neough channels to share.
125
+ // channel is unused. tc's don't have enough channels to share.
126
126
const pin_timer_t * timer = NULL ;
127
127
uint8_t mux_position = 0 ;
128
128
if (!variable_frequency ) {
@@ -139,6 +139,9 @@ void common_hal_pulseio_pwmout_construct(pulseio_pwmout_obj_t* self,
139
139
if (tcc -> CTRLA .bit .ENABLE == 1 && channel_ok (t )) {
140
140
timer = t ;
141
141
mux_position = j ;
142
+ // Claim channel.
143
+ tcc_channels [timer -> index ] |= (1 << tcc_channel (timer ));
144
+
142
145
}
143
146
}
144
147
}
0 commit comments