Skip to content
Snippets Groups Projects
Commit 435f4a33 authored by Thibaut VIARD's avatar Thibaut VIARD
Browse files

Merge branch 'zero' of github.com:arduino/ArduinoZero into zero_int

Conflicts:
	hardware/arduino/samd/variants/arduino_zero/variant.cpp
parents 022cfa11 12277e08
Branches
Tags
No related merge requests found
......@@ -20,8 +20,7 @@ SERCOM::SERCOM(Sercom* s)
void SERCOM::initUART(SercomUartMode mode, SercomUartSampleRate sampleRate, uint32_t baudrate)
{
resetUART();
initClock();
initNVIC();
initClockNVIC();
//Setting the CTRLA register
sercom->USART.CTRLA.reg = SERCOM_USART_CTRLA_MODE(mode) |
......@@ -154,6 +153,7 @@ int SERCOM::writeDataUART(uint8_t data)
void SERCOM::initSPI(SercomSpiTXPad mosi, SercomRXPad miso, SercomSpiCharSize charSize, SercomDataOrder dataOrder)
{
resetSPI();
initClockNVIC();
//Setting the CTRLA register
sercom->SPI.CTRLA.reg = SERCOM_SPI_CTRLA_MODE(SPI_MASTER_OPERATION) |
......@@ -191,7 +191,7 @@ void SERCOM::initSPIClock(SercomSpiClockMode clockMode, uint32_t baudrate)
void SERCOM::resetSPI()
{
//Setting the Software bit to 1
//Setting the Software Reset bit to 1
sercom->SPI.CTRLA.bit.SWRST = 0x1u;
//Wait both bits Software Reset from CTRLA and SYNCBUSY are equal to 0
......@@ -493,87 +493,54 @@ uint8_t SERCOM::readDataWIRE()
}
void SERCOM::initClock()
void SERCOM::initClockNVIC()
{
uint8_t clockId = 0;
IRQn_Type IdNvic;
if(sercom == SERCOM0)
{
clockId = GENERIC_CLOCK_SERCOM0;
IdNvic = SERCOM0_IRQn;
}
else if(sercom == SERCOM1)
{
clockId = GENERIC_CLOCK_SERCOM1;
IdNvic = SERCOM1_IRQn;
}
else if(sercom == SERCOM2)
{
clockId = GENERIC_CLOCK_SERCOM2;
IdNvic = SERCOM2_IRQn;
}
else if(sercom == SERCOM3)
{
clockId = GENERIC_CLOCK_SERCOM3;
IdNvic = SERCOM3_IRQn;
}
else if(sercom == SERCOM4)
{
clockId = GENERIC_CLOCK_SERCOM4;
IdNvic = SERCOM4_IRQn;
}
else if(sercom == SERCOM5)
{
clockId = GENERIC_CLOCK_SERCOM5;
IdNvic = SERCOM5_IRQn;
}
//Setting NVIC
NVIC_EnableIRQ(IdNvic);
NVIC_SetPriority (IdNvic, (1<<__NVIC_PRIO_BITS) - 1); /* set Priority */
//Setting clock
GCLK->CLKCTRL.reg = GCLK_CLKCTRL_ID( clockId ) | // Generic Clock 0 (SERCOMx)
GCLK_CLKCTRL_GEN_GCLK0 | // Generic Clock Generator 0 is source
GCLK_CLKCTRL_CLKEN ;
GCLK_CLKCTRL_GEN_GCLK0 | // Generic Clock Generator 0 is source
GCLK_CLKCTRL_CLKEN ;
while ( GCLK->STATUS.reg & GCLK_STATUS_SYNCBUSY )
{
/* Wait for synchronization */
}
}
void SERCOM::initNVIC()
{
IRQn_Type Id;
if(sercom == SERCOM0)
{
Id = SERCOM0_IRQn;
}
else if(sercom == SERCOM1)
{
Id = SERCOM1_IRQn;
}
else if(sercom == SERCOM2)
{
Id = SERCOM2_IRQn;
}
else if(sercom == SERCOM3)
{
Id = SERCOM3_IRQn;
}
else if(sercom == SERCOM4)
{
Id = SERCOM4_IRQn;
}
else if(sercom == SERCOM5)
{
Id = SERCOM5_IRQn;
}
NVIC_EnableIRQ(Id);
NVIC_SetPriority (Id, (1<<__NVIC_PRIO_BITS) - 1); /* set Priority */
}
/* =========================
* ===== SERCOM DEFINITION
* =========================
*/
SERCOM * SERCOM::sercom0 = new SERCOM(SERCOM0);
SERCOM * SERCOM::sercom1 = new SERCOM(SERCOM1);
SERCOM * SERCOM::sercom2 = new SERCOM(SERCOM2);
SERCOM * SERCOM::sercom3 = new SERCOM(SERCOM3);
SERCOM * SERCOM::sercom4 = new SERCOM(SERCOM4);
SERCOM * SERCOM::sercom5 = new SERCOM(SERCOM5);
......@@ -128,14 +128,6 @@ class SERCOM
{
public:
SERCOM(Sercom* s);
/* ========== SERCOM OBJECT ========== */
static SERCOM * sercom0;
static SERCOM * sercom1;
static SERCOM * sercom2;
static SERCOM * sercom3;
static SERCOM * sercom4;
static SERCOM * sercom5;
/* ========== UART ========== */
void initUART(SercomUartMode mode, SercomUartSampleRate sampleRate, uint32_t baudrate=0);
......@@ -198,8 +190,7 @@ class SERCOM
Sercom* sercom;
uint8_t calculateBaudrateSynchronous(uint32_t baudrate);
uint32_t division(uint32_t dividend, uint32_t divisor);
void initClock();
void initNVIC();
void initClockNVIC();
};
#endif
......@@ -5,16 +5,8 @@
Uart::Uart(SERCOM *s, uint8_t pinRX, uint8_t pinTX)
{
sercom = s;
if(sercom == SERCOM::sercom0)
{
pinPeripheral(pinRX, g_APinDescription[pinRX].ulPinType);
pinPeripheral(pinTX, g_APinDescription[pinTX].ulPinType);
}
else if(sercom == SERCOM::sercom5)
{
pinPeripheral(pinRX, g_APinDescription[pinRX].ulPinType);
pinPeripheral(pinTX, g_APinDescription[pinTX].ulPinType);
}
pinPeripheral(pinRX, g_APinDescription[pinRX].ulPinType);
pinPeripheral(pinTX, g_APinDescription[pinTX].ulPinType);
}
void Uart::begin(unsigned long baudrate)
......@@ -141,9 +133,6 @@ SercomParityMode Uart::extractParity(uint8_t config)
}
}
Uart Serial = Uart(SERCOM::sercom0, 0, 1);
Uart Serial5 = Uart(SERCOM::sercom5, 36, 35);
void SERCOM0_Handler()
{
Serial.IrqHandler();
......
......@@ -9,16 +9,24 @@
*/
#include "SPI.h"
#include "wiring_digital.h"
SPIClass::SPIClass(SERCOM *s)
{
sercom = s;
pinPeripheral(18, g_APinDescription[18].ulPinType);
pinPeripheral(20, g_APinDescription[20].ulPinType);
pinPeripheral(21, g_APinDescription[21].ulPinType);
}
void SPIClass::begin() {
// Default speed set to 4Mhz, SPI mode set to MODE 0 and Bit order set to MSB first.
sercom->initSPI(SPI_PAD_2_SCK_3, SERCOM_RX_PAD_0, SPI_CHAR_SIZE_8_BITS, MSB_FIRST);
sercom->initSPIClock(SERCOM_SPI_MODE_0, 4000000);
sercom->enableSPI();
}
void SPIClass::end() {
......@@ -86,4 +94,4 @@ void SPIClass::detachInterrupt() {
// Should be disableInterrupt()
}
SPIClass SPI(SERCOM::sercom4);
SPIClass SPI(&sercom4);
......@@ -15,8 +15,6 @@
#include "SERCOM.h"
#include "wiring_constants.h"
#include <stdio.h>
#define SPI_MODE0 0x02
#define SPI_MODE1 0x00
#define SPI_MODE2 0x03
......
......@@ -138,7 +138,7 @@ const PinDescription g_APinDescription[]=
{ PORTA, 23, PIO_SERCOM, PIN_ATTR_DIGITAL, No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_7 }, // SCL: SERCOM3/PAD[1]
// 18..23 SPI (ICSP:MISO,SCK,MOSI)
{ PORTA, 12, PIO_SERCOM_ALT, PIN_ATTR_DIGITAL, No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_12 }, // MISO: SERCOM4/PAD[0]
{ PORTA, 12, PIO_SERCOM, PIN_ATTR_DIGITAL, No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_12 }, // MISO: SERCOM4/PAD[0]
{ NOT_A_PORT, 0, PIO_NOT_A_PIN, PIN_ATTR_NONE, No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_NONE }, // 5V0
{ PORTB, 11, PIO_SERCOM_ALT, PIN_ATTR_DIGITAL, No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_11 }, // SCK: SERCOM4/PAD[3]
{ PORTB, 10, PIO_SERCOM_ALT, PIN_ATTR_DIGITAL, No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_10 }, // MOSI: SERCOM4/PAD[2]
......@@ -190,3 +190,14 @@ const PinDescription g_APinDescription[]=
} ;
const void* g_apTCInstances[TCC_INST_NUM+TC_INST_NUM]={ TCC0, TCC1, TCC2, TC3, TC4, TC5 } ;
// Multi-serial objects instantiation
SERCOM sercom0( SERCOM0 ) ;
SERCOM sercom1( SERCOM1 ) ;
SERCOM sercom2( SERCOM2 ) ;
SERCOM sercom3( SERCOM3 ) ;
SERCOM sercom4( SERCOM4 ) ;
SERCOM sercom5( SERCOM5 ) ;
Uart Serial( &sercom0, 0, 1 ) ;
Uart Serial5( &sercom5, 36, 35 ) ;
......@@ -36,8 +36,9 @@
#include "WVariant.h"
#ifdef __cplusplus
//#include "SERCOMUsart.h"
#endif
#include "SERCOM.h"
#include "Uart.h"
#endif // __cplusplus
#ifdef __cplusplus
extern "C"{
......@@ -97,11 +98,13 @@ extern "C"{
#define PIN_SPI_MOSI (21u)
#define PIN_SPI_MISO (18u)
#define PIN_SPI_SCK (20u)
/*
#define BOARD_SPI_SS0 (10u)
#define BOARD_SPI_SS1 (4u)
#define BOARD_SPI_SS2 (52u)
#define BOARD_SPI_SS3 PIN_SPI_SS3
#define BOARD_SPI_DEFAULT_SS BOARD_SPI_SS3
#define BOARD_PIN_TO_SPI_PIN(x) \
......@@ -113,14 +116,14 @@ extern "C"{
(x==BOARD_SPI_SS1 ? 1 : \
(x==BOARD_SPI_SS2 ? 2 : 3)))
static const uint8_t SS = BOARD_SPI_SS0;
static const uint8_t SS1 = BOARD_SPI_SS1;
static const uint8_t SS2 = BOARD_SPI_SS2;
static const uint8_t SS3 = BOARD_SPI_SS3;
static const uint8_t SS3 = BOARD_SPI_SS3;*/
static const uint8_t SS = 14; //GND
static const uint8_t MOSI = PIN_SPI_MOSI;
static const uint8_t MISO = PIN_SPI_MISO;
static const uint8_t SCK = PIN_SPI_SCK;
*/
/*
* Wire Interfaces
......@@ -203,10 +206,19 @@ static const uint8_t A5 = 25 ;
#ifdef __cplusplus
//extern UARTClass Serial;
//extern USARTClass Serial1;
//extern USARTClass Serial2;
//extern USARTClass Serial3;
/* =========================
* ===== SERCOM DEFINITION
* =========================
*/
extern SERCOM sercom0;
extern SERCOM sercom1;
extern SERCOM sercom2;
extern SERCOM sercom3;
extern SERCOM sercom4;
extern SERCOM sercom5;
extern Uart Serial;
extern Uart Serial5;
#endif
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment