Peripheral Pin Select

This information relates to ZPUino Alpha 3 release. Other releases might have different specs.

ZPUino includes a feature which is called Peripheral Pin Select (in short, PPS). PPS allows you to map every device input or output pin (such as SPI clock and SPI data lines) to each individual pin (GPIO), thus not requiring you to perform synthesis and P&R each time you want to use a device on a different IO pin.

To simplify things, three methods are supplied to manipulate PPS:

  • void pinModePPS(int pin, int value)
  • void outputPinForFunction(unsigned int pin,unsigned int function)
  • void inputPinForFunction(unsigned int pin,unsigned int function)

Three register blocks exist to configure how pin selection is done. These are called GPIOPPSIN, GPIOPPSOUT and GPIOPPSMAP. The above functions manipulate these registers.

Current IO pins

Here's a list of IO pins which can be mapped:

Signal name Module Direction Index Notes
IOPIN_SPI_MISO SPI Output 0 On startup, this is mapped to platform SPI flash
IOPIN_SPI_MOSI SPI Input 1 On startup, this is mapped to platform SPI flash
IOPIN_SPI_SCK SPI Output 2 On startup, this is mapped to platform SPI flash
IOPIN_SIGMADELTA0 SigmaDelta Output 3 1st Sigma-Delta channel.
IOPIN_TIMER0_OC Timers(0) Output 4 Output compare from timer 0
IOPIN_TIMER1_OC Timers(1) Output 5 Output compare from timer 1
IOPIN_USPI_MISO USPI Input 6 User SPI
IOPIN_USPI_MOSI USPI Output 7 User SPI
IOPIN_USPI_SCK USPI Output 8 User SPI
IOPIN_SIGMADELTA1 SigmaDelta Output 13 2nd Sigma-Delta channel

Redirecting output

In order to direct any peripheral output to a GPIO pin, you have to:

  • Configure the GPIO pin as output;
  • Enable PPS on selected GPIO pin;
  • Configure GPIOPPSOUT (outputPinForFunction) to the peripheral signal;

The following example maps Sigma Delta 1st channel into GPIO pin number 30:

pinMode(30,OUTPUT); // Configure pin as output pinModePPS(30,HIGH); // enable PPS on this pin outputPinForFunction(30, IOPIN_SIGMADELTA1); // Map SigmaDelta channel 1 to pin 30
Note that you can use GPIO aliases for your board instead of GPIO number. See your board specific documentation.

Redirecting input

In order to direct GPIO input into any peripheral, you have to:

  • Configure the GPIO pin as input;
  • Configure GPIOPPSIN (inputPinForFunction) to the peripheral signal;

Note that for input you don't need to enable PPS on the pin.

The following example maps USPI MISO signal (Master-In Slave-out) to GPIO pin number 10:

pinMode(10,INPUT); // Configure pin as input inputPinForFunction(10, IOPIN_USPI_MISO); // Map pin 30 to USPI MISO