# pio.c File Reference

## Detailed Description

pio driver functions

This file contains basic pio driver functions.

- Compiler: IAR EWAVR32 and GNU GCC for AVR32
- Supported devices: All AVR32 devices with a PIO module can be used. The example is written for AP7000 and STK1000.
- AppNote: AVR32111 - Using the AVR32 PIO Controller

Author:
  Atmel Corporation: http://www.atmel.com
  Support email: avr32@atmel.com

Definition in file pio.c.

`#include "pio.h"`

Go to the source code of this file.

## Functions
void | gpio_enable_module (const gpio_map_t piomap, int size)
int | gpio_enable_module_pin (int pin, int function)
void | pio_enable_module (const gpio_map_t piomap, int size)
int | pio_setup_pin (int pin, int function)
volatile avr32_pio_t * | pioGetHandle (int port)

## Function Documentation

void gpio_enable_module | ( | const gpio_map_t | piomap,
|  | int | size |
| ) |  |  |

This function will enable a module pin for a given set of pins and respective modules

Parameters:

  | *piomap | A list of pins and pio connectivity
  | size | The number of pins in *piomap

Returns:
  nothing

Definition at line 150 of file pio.c.

References pio_enable_module().

    00151 {
    00152   pio_enable_module(piomap, size);
    00153 }

int gpio_enable_module_pin | ( | int | pin,
|  | int | function |
| ) |  |  |

This function will put a single pin under a module's control. API for gpio module.

Parameters:

  | *pin | The pin number
  | *function | The PIO module which to enable

Returns:
  PIO_SUCCESS or PIO_INVALID_ARGUMENT

Definition at line 111 of file pio.c.

References pio_setup_pin().

    00112 {
    00113   return pio_setup_pin(pin, function);
    00114 }

void pio_enable_module | ( | const gpio_map_t | piomap,
|  | int | size |
| ) |  |  |

This function will enable a module pin for a given set of pins and respective modules

Parameters:

  | *piomap | A list of pins and pio connectivity
  | size | The number of pins in *piomap

Returns:
  nothing

Definition at line 140 of file pio.c.

References gpio_map_t::function, gpio_map_t::pin, and pio_setup_pin().

Referenced by gpio_enable_module().

    00141 {
    00142   int i;
    00143
    00144   for(i=0; i<size; i++){
    00145     pio_setup_pin(piomap->pin, piomap->function );
    00146     piomap++;
    00147   }
    00148 }

int pio_setup_pin | ( | int | pin,
|  | int | function |
| ) |  |  |

This function will put a single pin under a module's control

Parameters:

  | *pin | The pin number
  | *function | The PIO module which to enable

Returns:
  PIO_SUCCESS or PIO_INVALID_ARGUMENT

Definition at line 117 of file pio.c.

References PIO_INVALID_ARGUMENT, PIO_SUCCESS, and pioGetHandle().

Referenced by gpio_enable_module_pin(), and pio_enable_module().

    00118 {
    00119   volatile avr32_pio_t *pio = pioGetHandle(pin/32);
    00120
    00121
    00122   /* Disable pio control */
    00123   pio->pdr |= (1<<(pin%32));
    00124   pio->pudr |= (1<<(pin%32));
    00125
    00126   /* Enable the correct function */
    00127   switch(function){
    00128     case 0:
    00129       pio->asr |= (1<<(pin%32));
    00130       break;
    00131     case 1:
    00132       pio->bsr |= (1<<(pin%32));
    00133       break;
    00134     default:
    00135       return PIO_INVALID_ARGUMENT;
    00136   }
    00137   return PIO_SUCCESS;
    00138 }

volatile avr32_pio_t* pioGetHandle | ( | int | port | ) |

This function will return the baseaddress for a port

Parameters:

  | *port | The port number

Returns:
  The port's baseaddress

Definition at line 92 of file pio.c.

Referenced by pio_setup_pin().

    00093 {
    00094   switch (port) {
    00095     case 0:
    00096       return &AVR32_PIOA;
    00097     case 1:
    00098       return &AVR32_PIOB;
    00099     case 2:
    00100       return &AVR32_PIOC;
    00101     case 3:
    00102       return &AVR32_PIOD;
    00103     case 4:
    00104       return &AVR32_PIOE;
    00105     default :
    00106       break;
    00107   }
    00108         return (avr32_pio_t *) -1;
    00109 }