/*This file is prepared for Doxygen automatic documentation generation.*/
/*! \file *********************************************************************
 *
 * \brief UC3-A3-Xplained board header file.
 *
 * This file contains definitions and services related to the features of the
 * UC3-A3-Xplained board.
 *
 * To use this board, define BOARD=UC3_A3_XPLAINED.
  *
 * - Compiler:           IAR EWAVR32 and GNU GCC for AVR32
 * - Supported devices:  AVR32 UC3-A3 Xplained development board.
 * - AppNote:
 *
 * \author               Atmel Corporation: http://www.atmel.com \n
 *                       Support and FAQ: http://support.atmel.no/
 *
 ******************************************************************************/

/* Copyright (c) 2010 Atmel Corporation. All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * 1. Redistributions of source code must retain the above copyright notice,
 * this list of conditions and the following disclaimer.
 *
 * 2. Redistributions in binary form must reproduce the above copyright notice,
 * this list of conditions and the following disclaimer in the documentation
 * and/or other materials provided with the distribution.
 *
 * 3. The name of Atmel may not be used to endorse or promote products derived
 * from this software without specific prior written permission.
 *
 * 4. This software may only be redistributed and used in connection with an
 * Atmel AVR product.
 *
 * THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED
 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
 * EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR
 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
 * DAMAGE.
 */

#ifndef UC3_A3_XPLAINED_H_
#define UC3_A3_XPLAINED_H_

#include "compiler.h"

//! \name Atmel Xplained Development Board Configuration

#ifdef __AVR32_ABI_COMPILER__ // Automatically defined when compiling for AVR32, not when assembling.
#  include "led.h"
#endif  // __AVR32_ABI_COMPILER__


#ifdef __cplusplus
extern "C" {
#endif



//! \name Oscillator Definitions
//! @{

/*! \brief System oscillator frequencies (Hz.) and startup times (periods).
 *
 * RCOsc has no custom calibration by default. Set the following definition
 * to the appropriate value if a custom RCOsc calibration has been applied
 * to your part.
 */

//!< RCOsc frequency: Hz.

#define FRCOSC                      (AVR32_PM_RCOSC_FREQUENCY)

//!< Osc32 frequency (Hz.) and startup time (RCOsc periods).

#define FOSC32                      (32768)
#define OSC32_STARTUP               (AVR32_PM_OSCCTRL32_STARTUP_8192_RCOSC)

#define BOARD_OSC32_IS_XTAL         true
#define BOARD_OSC32_HZ              FOSC32
#define BOARD_OSC32_STARTUP_US      (570000)


//!< Osc frequency (Hz.) and startup time (RCOsc periods).

#define FOSC0                       (12000000)
#define OSC0_STARTUP                (AVR32_PM_OSCCTRL0_STARTUP_2048_RCOSC)

#define BOARD_OSC0_IS_XTAL          true
#define BOARD_OSC0_HZ               FOSC0
#define BOARD_OSC0_STARTUP_US       (18000)

//! @}


//! Number of LEDs.

#define LED_COUNT                   4


/*! \name UC3-A3-Xplained LED to GPIO pin mappings.
 */
//! @{

#define LED0_GPIO                   (AVR32_PIN_PB03)
#define LED1_GPIO                   (AVR32_PIN_PX22)
#define LED2_GPIO                   (AVR32_PIN_PB02)
#define LED3_GPIO                   (AVR32_PIN_PB06)

//! @}


/*! \name GPIO Connections of Push Buttons
 */
//! @{

#define GPIO_PUSH_BUTTON_0          (AVR32_PIN_PB01)
#define GPIO_PUSH_BUTTON_0_PRESSED  (0)
#define GPIO_PUSH_BUTTON_1          (AVR32_PIN_PA31)
#define GPIO_PUSH_BUTTON_1_PRESSED  (0)
#define GPIO_PUSH_BUTTON_2          (AVR32_PIN_PA30)
#define GPIO_PUSH_BUTTON_2_PRESSED  (0)
#define GPIO_PUSH_BUTTON_3          (AVR32_PIN_PA29)
#define GPIO_PUSH_BUTTON_3_PRESSED  (0)
#define GPIO_PUSH_BUTTON_4          (AVR32_PIN_PA28)
#define GPIO_PUSH_BUTTON_4_PRESSED  (0)
//! @}

/*! \name GPIO Connections of Inertial 2/3 board Interrupts
 */
//! @{

#define GPIO_INERTIAL2_INT_MPU           (AVR32_PIN_PB09)
#define GPIO_INERTIAL2_INT_MPU_ACTIVE    (1)
#define GPIO_INERTIAL2_INT_ACCEL         (AVR32_PIN_PX58)
#define GPIO_INERTIAL2_INT_ACCEL_ACTIVE  (1)
#define GPIO_INERTIAL3_INT_MPU           (AVR32_PIN_PX58)
#define GPIO_INERTIAL3_INT_MPU_ACTIVE    (1)

//! @}
    

/*! \name SDRAM Definitions
 */
//! @{

//! Part header file of used SDRAM(s).
#define SDRAM_PART_HDR              "mt48lc16m16a2tg7e/mt48lc16m16a2tg7e.h"

//! Data bus width to use the SDRAM(s) with (16 or 32 bits; always 16 bits on
//! UC3).
#define SDRAM_DBW                    16

//! @}


/*! \name USART connections to GPIO
 */
//! @{

#define USART_J4                    (&AVR32_USART1)

#define USART_RXD_PIN               AVR32_USART1_RXD_0_0_PIN
#define USART_RXD_FUNCTION          AVR32_USART1_RXD_0_0_FUNCTION
#define USART_TXD_PIN               AVR32_USART1_TXD_0_0_PIN
#define USART_TXD_FUNCTION          AVR32_USART1_TXD_0_0_FUNCTION
//! @}

/*! \name TWI Master connections to GPIO
 */
//! @{


/* XXX TODO XXX
 *
 * The TWIM pins that are mapped here should correspond with the TWIM
 * interfaces selected in the conf_board.h file.  In addition, the
 * default values below map TWIM the pins on the Xplaned J1 block.
 * Modify the mappings or add appropriate conditional compilation as
 * needed.
 */

#define TWIMS0_TWD_PIN              AVR32_TWIMS0_TWD_0_0_PIN
#define TWIMS0_TWD_FUNCTION         AVR32_TWIMS0_TWD_0_0_FUNCTION
#define TWIMS0_TWCK_PIN             AVR32_TWIMS0_TWCK_0_0_PIN
#define TWIMS0_TWCK_FUNCTION        AVR32_TWIMS0_TWCK_0_0_FUNCTION
//! @}



#ifdef __cplusplus
}
#endif

#endif /* UC3_A3_XPLAINED_H_ */
