# Pin muxing

Pin multiplexing, or pin muxing for short, refers to the mechanics that links peripheral functions to GPIOs. Each peripheral function can be mapped to one of several GPIOs, and reciprocally, each GPIO can be mapped to one of several peripheral functions. This multiplexing matrix is hard-wired and package-dependant, and is documented in §3.2 Peripheral Multiplexing on I/O lines in the datasheet.

When a pin is mapped to a particular function (for example, an ADC channel, i.e. an analog voltage input) it can't be mapped at the same time to another function (for example, an USART TX line). If you want to use this ADC channel and this USART line at the same time, you either need to find another mapping for one of the signals or use another ADC channel/another USART port instead. It is up to you to find a mapping that allows all the peripheral functions that you need.

libtungsten defines a default pin muxing configuration in the pins_sam4l_XX.cpp file (where XX is the package you are using : 48, 64 or 100), but you can easily override this configuration at runtime using the setPin() function inside each module.

When using a new module or when changing a pin configuration with setPin(), make sure that you don't map two different peripheral functions on the same pin. The GPIO module, which takes care of enabling and disabling peripheral functions, will raise an error if it detects that a pin is used twice.

For the 64-pin TQFP/QFN packages, you can find a visual representation of the mapping matrix in the Carbide page.