Hi @chunjye0808
Glad to hear that it does what require it to do.
My apologies, but to answer your questions requires a bit of explanation about the port pin registers, which isn't that straightforward, so please bear with me:
Regarding the port pin multiplexer, each pin has it's own PINCFG register to enable the peripheral multiplexer, so PINCFG[0] references PA00, PINCFG[1] => PA01, PINCFG[2] => PA02, and so on.
The PMUX register however deals with port pin even and odd pairs, so PMUX[0] references PA00 and PA01, PMUX[1] => PA02 and PA03, PMUX[2] => PA04 and PA05 and so on.
This means that there are only half the number of PMUX registers compared with PINCFG, hence the line PMUX[9 >> 1], which shifts 9 one bit to the right. This is essentially the same as dividing 9 by 2 = PMUX[4].
The PMUX register has definitions that select both the pin multiplexer switch positions: A to H, plus whether the port pin is either odd or even. For instance, PA09 is odd, while PA08 is even.
For example to access the multiplexer switch F on odd port pin PA09, you just need to change the definition from even to odd, (note the O instead of an E) in PORT_PMUX_PMUXO_F:
PORT->Group[PORTA].PMUX[9 >> 1].reg |= PORT_PMUX_PMUXO_F; // Select multiplexer channel F for PA09
To find which timer channels are connected to what pin, it's necessary to look at the "PORT Function Multiplex" table in the SAMD21 datasheet.
Note that just to make matters more confusing, timer TCC0's channels WO[0] to WO[3] are repeated on WO[4] to WO[7].
Likewise, timer TCC1's channels WO[0] to WO[1] are repeated on WO[2] to WO[3].
TCC2 just has WO[0] and WO[1] with no repeats.
Therefore in total TCC0 has 4 channels, while TCC1 and TCC2 each have 2.
You'll find the TCC2 timer outputs on port pins: PA12 and PA13, as well as PA16 and PA17, all on multiplexer switch E. These equate to Arduino Zero pins: MISO, GPIO, D11 and D13 respectively.