From 0eca3bd649e0bd1b280545b824142e0651a0c9bf Mon Sep 17 00:00:00 2001
From: Jonathan BAUDIN <jonathan.baudin@atmel.com>
Date: Fri, 9 May 2014 14:09:41 +0200
Subject: [PATCH]  Use new IRQ functions

---
 cores/arduino/Uart.cpp  | 27 +++++++++++++++++++++------
 cores/arduino/Uart.h    |  3 ++-
 libraries/Wire/Wire.cpp |  4 ++--
 libraries/Wire/Wire.h   |  2 --
 4 files changed, 25 insertions(+), 11 deletions(-)

diff --git a/cores/arduino/Uart.cpp b/cores/arduino/Uart.cpp
index 19c17563..954a126a 100644
--- a/cores/arduino/Uart.cpp
+++ b/cores/arduino/Uart.cpp
@@ -66,15 +66,25 @@ int Uart::read()
 	return rxBuffer.read_char();
 }
 
-size_t Uart::write(uint8_t data)
+size_t Uart::write(const uint8_t data)
 {
-	if(txBuffer.isFull())
-		return 0;
-		
-	txBuffer.store_char(data);
+	sercom->writeDataUART(data);
 	return 1;
 }
 
+size_t Uart::write(const char * data)
+{
+	size_t writed = 0;
+	
+	while(*data != '\0')
+	{
+		writed += write(*data);
+		++data;
+	}
+	
+	return writed;
+}
+
 SercomNumberStopBit Uart::extractNbStopBit(uint8_t config)
 {
 	switch(config & HARDSER_STOP_BIT_MASK)
@@ -124,4 +134,9 @@ SercomParityMode Uart::extractParity(uint8_t config)
 	}
 }
 
-Uart Serial = Uart(SERCOM::sercom0);
\ No newline at end of file
+Uart Serial = Uart(SERCOM::sercom0);
+
+void SERCOM0_Handler()
+{
+	Serial.IrqHandler();
+}
\ No newline at end of file
diff --git a/cores/arduino/Uart.h b/cores/arduino/Uart.h
index fb3a776f..84ea558d 100644
--- a/cores/arduino/Uart.h
+++ b/cores/arduino/Uart.h
@@ -19,7 +19,8 @@ class Uart : public HardwareSerial
 		int peek();
 		int read();
 		void flush();
-		size_t write(const uint8_t c);
+		size_t write(const uint8_t data);
+		size_t write(const char * data);
 
 		void IrqHandler();
 
diff --git a/libraries/Wire/Wire.cpp b/libraries/Wire/Wire.cpp
index d99dca55..b8fad9cb 100644
--- a/libraries/Wire/Wire.cpp
+++ b/libraries/Wire/Wire.cpp
@@ -347,9 +347,9 @@ void TwoWire::onService(void)
 }*/
 
 
-TwoWire Wire = TwoWire(SERCOM::sercom3);
+TwoWire Wire(SERCOM::sercom3);
 
-void WIRE_ISR_HANDLER(void) {
+void SERCOM3_Handler(void) {
 	Wire.onService();
 }
 
diff --git a/libraries/Wire/Wire.h b/libraries/Wire/Wire.h
index b3d2ab4c..7ae75e39 100644
--- a/libraries/Wire/Wire.h
+++ b/libraries/Wire/Wire.h
@@ -99,8 +99,6 @@ class TwoWire : public Stream {
 		//static const uint32_t XMIT_TIMEOUT = 100000;
 };
 
-#if WIRE_INTERFACES_COUNT > 0
 extern TwoWire Wire;
-#endif
 
 #endif
-- 
GitLab