mirror of
https://github.com/arduino/Arduino.git
synced 2024-12-03 14:24:15 +01:00
183 lines
6.2 KiB
C++
183 lines
6.2 KiB
C++
/* ----------------------------------------------------------------------------
|
|
* SAM Software Package License
|
|
* ----------------------------------------------------------------------------
|
|
* Copyright (c) 2011, 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:
|
|
*
|
|
* - Redistributions of source code must retain the above copyright notice,
|
|
* this list of conditions and the disclaimer below.
|
|
*
|
|
* Atmel's name may not be used to endorse or promote products derived from
|
|
* this software without specific prior written permission.
|
|
*
|
|
* DISCLAIMER: 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
|
|
* 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.
|
|
* ----------------------------------------------------------------------------
|
|
*/
|
|
|
|
#include "variant.h"
|
|
|
|
/*
|
|
* Pins descriptions
|
|
*/
|
|
extern const PinDescription g_APinDescription[]=
|
|
{
|
|
// LEDS, 0..2
|
|
{ PIOB, PIO_PB0, ID_PIOB, PIO_OUTPUT_0, PIO_DEFAULT }, // LED BLUE
|
|
{ PIOB, PIO_PB1, ID_PIOB, PIO_OUTPUT_1, PIO_DEFAULT }, // LED GREEN
|
|
{ PIOB, PIO_PB2, ID_PIOB, PIO_OUTPUT_1, PIO_DEFAULT }, // LED RED
|
|
|
|
// USB, 3..3
|
|
{ PIOA, PIO_PA0, ID_PIOA, PIO_INPUT, PIO_PULLUP }, // USB_VBUS
|
|
|
|
// UART (Serial), 4..6
|
|
{ PIOA, PIO_PA11A_URXD, ID_PIOA, PIO_PERIPH_A, PIO_DEFAULT }, // URXD
|
|
{ PIOA, PIO_PA12A_UTXD, ID_PIOA, PIO_PERIPH_A, PIO_DEFAULT }, // UTXD
|
|
{ PIOA, PIO_PA11A_URXD|PIO_PA12A_UTXD, ID_PIOA, PIO_PERIPH_A, PIO_DEFAULT }, // All UART pins
|
|
|
|
// Push buttons, 7..8
|
|
{ PIOA, PIO_PA18, ID_PIOA, PIO_INPUT, PIO_PULLUP | PIO_DEGLITCH }, // PB_LEFT
|
|
{ PIOA, PIO_PA19, ID_PIOA, PIO_INPUT, PIO_PULLUP | PIO_DEGLITCH }, // PB_RIGHT
|
|
|
|
// MCI (SDCARD), 9..19
|
|
{ PIOA, PIO_PA25, ID_PIOA, PIO_INPUT, PIO_PULLUP }, // MCI Card Detect
|
|
{ PIOA, PIO_PA5A_MCDA0, ID_PIOA, PIO_PERIPH_A, PIO_PULLUP }, // MCDA0
|
|
{ PIOA, PIO_PA6A_MCDA1, ID_PIOA, PIO_PERIPH_A, PIO_PULLUP }, // MCDA1
|
|
{ PIOA, PIO_PA7A_MCDA2, ID_PIOA, PIO_PERIPH_A, PIO_PULLUP }, // MCDA2
|
|
{ PIOA, PIO_PA8A_MCDA3, ID_PIOA, PIO_PERIPH_A, PIO_PULLUP }, // MCDA3
|
|
{ PIOC, PIO_PC28B_MCDA4, ID_PIOC, PIO_PERIPH_B, PIO_PULLUP }, // MCDA4
|
|
{ PIOC, PIO_PC29B_MCDA5, ID_PIOC, PIO_PERIPH_B, PIO_PULLUP }, // MCDA5
|
|
{ PIOC, PIO_PC30B_MCDA6, ID_PIOC, PIO_PERIPH_B, PIO_PULLUP }, // MCDA6
|
|
{ PIOC, PIO_PC31B_MCDA7, ID_PIOC, PIO_PERIPH_B, PIO_PULLUP }, // MCDA7
|
|
{ PIOA, PIO_PA4A_MCCDA, ID_PIOA, PIO_PERIPH_A, PIO_PULLUP }, // MCCDA
|
|
{ PIOA, PIO_PA3A_MCCK, ID_PIOA, PIO_PERIPH_A, PIO_PULLUP }, // MCCK
|
|
|
|
// SPI, 20..23
|
|
{ PIOA, PIO_PA13A_MISO, ID_PIOA, PIO_PERIPH_A, PIO_DEFAULT }, // MISO
|
|
{ PIOA, PIO_PA14A_MOSI, ID_PIOA, PIO_PERIPH_A, PIO_DEFAULT }, // MOSI
|
|
{ PIOA, PIO_PA15A_SPCK, ID_PIOA, PIO_PERIPH_A, PIO_DEFAULT }, // SPCK
|
|
{ PIOC, PIO_PC14B_NPCS2, ID_PIOC, PIO_PERIPH_B, PIO_DEFAULT }, // NPCS2
|
|
|
|
// TouchScreen, 24..25
|
|
{ PIOA, PIO_PA24, ID_PIOA, PIO_INPUT, PIO_PULLUP }, // IRQ_TSC
|
|
{ PIOA, PIO_PA2, ID_PIOA, PIO_INPUT, PIO_PULLUP }, // BUSY_TSC
|
|
|
|
// USART1, 26..29
|
|
{ PIOA, PIO_PA21A_RXD1, ID_PIOA, PIO_PERIPH_A, PIO_DEFAULT }, // RXD1
|
|
{ PIOA, PIO_PA20A_TXD1, ID_PIOA, PIO_PERIPH_A, PIO_DEFAULT }, // TXD1
|
|
{ PIOA, PIO_PA22B_RTS1, ID_PIOA, PIO_PERIPH_A, PIO_DEFAULT }, // RTS1
|
|
{ PIOA, PIO_PA23B_CTS1, ID_PIOA, PIO_PERIPH_A, PIO_DEFAULT }, // CTS1
|
|
|
|
// LCD, 30..47
|
|
{ PIOB, 0xFE01FE00, ID_PIOB, PIO_PERIPH_A, PIO_PULLUP }, // EBI Data bus PB9-16 PB25-31
|
|
{ PIOB, PIO_PB23A_NWE, ID_PIOB, PIO_PERIPH_A, PIO_PULLUP }, // EBI_NWE
|
|
{ PIOB, PIO_PB19A_NRD, ID_PIOB, PIO_PERIPH_A, PIO_PULLUP }, // EBI_NRD
|
|
{ PIOC, PIO_PC16A_NCS2, ID_PIOC, PIO_PERIPH_A, PIO_PULLUP }, // LCD CS
|
|
{ PIOB, PIO_PB8, ID_PIOB, PIO_OUTPUT_0, PIO_DEFAULT }, // LCD RS
|
|
{ PIOC, PIO_PC19, ID_PIOC, PIO_OUTPUT_0, PIO_DEFAULT }, // LCD BackLight
|
|
|
|
{ NULL, 0, 0, PIO_NOT_A_PIN, PIO_DEFAULT } // END
|
|
} ;
|
|
|
|
/*
|
|
* UART objects
|
|
*/
|
|
RingBuffer rx_buffer1 ;
|
|
RingBuffer tx_buffer1 ;
|
|
|
|
UARTClass Serial( UART, UART_IRQn, ID_UART, &rx_buffer1, &tx_buffer1 ) ;
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
// IT handlers
|
|
extern void UART_IrqHandler( void )
|
|
{
|
|
Serial.IrqHandler() ;
|
|
}
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|
|
|
|
// ----------------------------------------------------------------------------
|
|
/*
|
|
* USART objects
|
|
*/
|
|
RingBuffer rx_buffer2 ;
|
|
RingBuffer tx_buffer2 ;
|
|
RingBuffer rx_buffer3 ;
|
|
RingBuffer tx_buffer3 ;
|
|
|
|
USARTClass Serial2( USART0, USART0_IRQn, ID_USART0, &rx_buffer2, &tx_buffer2 ) ;
|
|
USARTClass Serial3( USART1, USART1_IRQn, ID_USART1, &rx_buffer3, &tx_buffer3 ) ;
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
// IT handlers
|
|
extern void USART0_IrqHandler( void )
|
|
{
|
|
Serial2.IrqHandler() ;
|
|
}
|
|
|
|
extern void USART1_IrqHandler( void )
|
|
{
|
|
Serial3.IrqHandler() ;
|
|
}
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
/**
|
|
*
|
|
*/
|
|
extern void init( void )
|
|
{
|
|
SystemInit() ;
|
|
|
|
/* Set Systick to 1ms interval, common to all SAM3 variants */
|
|
if ( SysTick_Config( SystemCoreClock / 1000 ) )
|
|
{
|
|
/* Capture error */
|
|
while ( 1 ) ;
|
|
}
|
|
|
|
/* Disable watchdog, common to all SAM variants */
|
|
WDT_Disable( WDT ) ;
|
|
|
|
// Initialize UART Serial port
|
|
PIO_Configure( g_APinDescription[PINS_UART].pPort, g_APinDescription[PINS_UART].ulPinType,
|
|
g_APinDescription[PINS_UART].ulPin, g_APinDescription[PINS_UART].ulPinAttribute ) ;
|
|
|
|
// Switch off Power LED
|
|
PIO_Configure( g_APinDescription[PIN_LED_RED].pPort, g_APinDescription[PIN_LED_RED].ulPinType,
|
|
g_APinDescription[PIN_LED_RED].ulPin, g_APinDescription[PIN_LED_RED].ulPinAttribute ) ;
|
|
PIO_Clear( g_APinDescription[PIN_LED_RED].pPort, g_APinDescription[PIN_LED_RED].ulPin ) ;
|
|
}
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|
|
|