@@ -51,10 +51,10 @@ uint8_t tcc_refcount[TCC_INST_NUM];
5151
5252// This bitmask keeps track of which channels of a TCC are currently claimed.
5353#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.
5555#endif
5656#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.
5858#endif
5959
6060void pwmout_reset (void ) {
@@ -75,7 +75,7 @@ void pwmout_reset(void) {
7575 for (uint8_t j = 0 ; j < tcc_cc_num [i ]; j ++ ) {
7676 mask <<= 1 ;
7777 }
78- tcc_channels [i ] = 0xf0 ;
78+ tcc_channels [i ] = mask ;
7979 tccs [i ]-> CTRLA .bit .SWRST = 1 ;
8080 }
8181 Tc * tcs [TC_INST_NUM ] = TC_INSTS ;
@@ -122,7 +122,7 @@ void common_hal_pulseio_pwmout_construct(pulseio_pwmout_obj_t* self,
122122 // Figure out which timer we are using.
123123
124124 // 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.
126126 const pin_timer_t * timer = NULL ;
127127 uint8_t mux_position = 0 ;
128128 if (!variable_frequency ) {
@@ -139,6 +139,9 @@ void common_hal_pulseio_pwmout_construct(pulseio_pwmout_obj_t* self,
139139 if (tcc -> CTRLA .bit .ENABLE == 1 && channel_ok (t )) {
140140 timer = t ;
141141 mux_position = j ;
142+ // Claim channel.
143+ tcc_channels [timer -> index ] |= (1 << tcc_channel (timer ));
144+
142145 }
143146 }
144147 }
0 commit comments