From 2071c00ba0fea2c27c128db01086834144fc4e27 Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Fri, 28 Sep 2012 16:18:22 +0200 Subject: [PATCH] Assigned Serial to UART and SerialUSB to USB-CDC-ACM --- build/shared/lib/keywords.txt | 2 +- hardware/arduino/sam/cores/arduino/HardwareSerial.h | 2 +- hardware/arduino/sam/cores/arduino/UARTClass.h | 2 ++ hardware/arduino/sam/cores/arduino/USARTClass.h | 2 ++ hardware/arduino/sam/cores/arduino/USB/CDC.cpp | 2 +- hardware/arduino/sam/cores/arduino/USB/USBAPI.h | 2 +- hardware/arduino/sam/cores/arduino/USB/USBCore.cpp | 2 +- hardware/arduino/sam/variants/arduino_due_x/variant.cpp | 6 +++--- hardware/arduino/sam/variants/arduino_due_x/variant.h | 2 +- 9 files changed, 13 insertions(+), 9 deletions(-) diff --git a/build/shared/lib/keywords.txt b/build/shared/lib/keywords.txt index 396a1f51d..6b4480634 100644 --- a/build/shared/lib/keywords.txt +++ b/build/shared/lib/keywords.txt @@ -163,10 +163,10 @@ shiftOut KEYWORD2 ShiftOut tone KEYWORD2 Tone Serial KEYWORD3 Serial -Serial1 KEYWORD3 Serial Serial2 KEYWORD3 Serial Serial3 KEYWORD3 Serial Serial4 KEYWORD3 Serial +SerialUSB KEYWORD3 Serial begin KEYWORD2 Serial_Begin end KEYWORD2 Serial_End peek KEYWORD2 Serial_Peek diff --git a/hardware/arduino/sam/cores/arduino/HardwareSerial.h b/hardware/arduino/sam/cores/arduino/HardwareSerial.h index af0e52707..17cc3cfac 100644 --- a/hardware/arduino/sam/cores/arduino/HardwareSerial.h +++ b/hardware/arduino/sam/cores/arduino/HardwareSerial.h @@ -34,7 +34,7 @@ class HardwareSerial : public Stream virtual void flush(void) = 0; virtual size_t write(uint8_t) = 0; using Print::write; // pull in write(str) and write(buf, size) from Print - operator bool(); + virtual operator bool() = 0; }; extern void serialEventRun(void) __attribute__((weak)); diff --git a/hardware/arduino/sam/cores/arduino/UARTClass.h b/hardware/arduino/sam/cores/arduino/UARTClass.h index 5665429c9..5836f2e62 100644 --- a/hardware/arduino/sam/cores/arduino/UARTClass.h +++ b/hardware/arduino/sam/cores/arduino/UARTClass.h @@ -54,6 +54,8 @@ class UARTClass : public HardwareSerial // virtual void write( const char *str ) ; // virtual void write( const uint8_t *buffer, size_t size ) ; #endif + + operator bool() { return true; }; // UART always active }; #endif // _UART_CLASS_ diff --git a/hardware/arduino/sam/cores/arduino/USARTClass.h b/hardware/arduino/sam/cores/arduino/USARTClass.h index 85356f2fa..deb74a71d 100644 --- a/hardware/arduino/sam/cores/arduino/USARTClass.h +++ b/hardware/arduino/sam/cores/arduino/USARTClass.h @@ -54,6 +54,8 @@ class USARTClass : public HardwareSerial // virtual void write( const char *str ) ; // virtual void write( const uint8_t *buffer, size_t size ) ; #endif + + operator bool() { return true; }; // USART always active }; #endif // _USART_CLASS_ diff --git a/hardware/arduino/sam/cores/arduino/USB/CDC.cpp b/hardware/arduino/sam/cores/arduino/USB/CDC.cpp index 615d2a2c3..1f2ee0bff 100644 --- a/hardware/arduino/sam/cores/arduino/USB/CDC.cpp +++ b/hardware/arduino/sam/cores/arduino/USB/CDC.cpp @@ -267,6 +267,6 @@ Serial_::operator bool() return result; } -Serial_ Serial; +Serial_ SerialUSB; #endif diff --git a/hardware/arduino/sam/cores/arduino/USB/USBAPI.h b/hardware/arduino/sam/cores/arduino/USB/USBAPI.h index 8f10cff99..0493c7b66 100644 --- a/hardware/arduino/sam/cores/arduino/USB/USBAPI.h +++ b/hardware/arduino/sam/cores/arduino/USB/USBAPI.h @@ -61,7 +61,7 @@ public: using Print::write; // pull in write(str) from Print operator bool(); }; -extern Serial_ Serial; +extern Serial_ SerialUSB; //================================================================================ //================================================================================ diff --git a/hardware/arduino/sam/cores/arduino/USB/USBCore.cpp b/hardware/arduino/sam/cores/arduino/USB/USBCore.cpp index 3d1ebccfd..5b816f8d4 100644 --- a/hardware/arduino/sam/cores/arduino/USB/USBCore.cpp +++ b/hardware/arduino/sam/cores/arduino/USB/USBCore.cpp @@ -598,7 +598,7 @@ static void USB_ISR(void) // Handle received bytes while (USBD_Available(CDC_RX)) - Serial.accept(); + SerialUSB.accept(); udd_ack_fifocon(CDC_RX); } diff --git a/hardware/arduino/sam/variants/arduino_due_x/variant.cpp b/hardware/arduino/sam/variants/arduino_due_x/variant.cpp index 1719aca3e..f8a182ff6 100644 --- a/hardware/arduino/sam/variants/arduino_due_x/variant.cpp +++ b/hardware/arduino/sam/variants/arduino_due_x/variant.cpp @@ -296,12 +296,12 @@ extern const PinDescription g_APinDescription[]= */ RingBuffer rx_buffer1 ; -UARTClass Serial1( UART, UART_IRQn, ID_UART, &rx_buffer1 ) ; +UARTClass Serial( UART, UART_IRQn, ID_UART, &rx_buffer1 ) ; // IT handlers void UART_Handler(void) { - Serial1.IrqHandler() ; + Serial.IrqHandler() ; } // ---------------------------------------------------------------------------- @@ -364,7 +364,7 @@ void init( void ) g_APinDescription[PINS_UART].ulPin, g_APinDescription[PINS_UART].ulPinConfiguration); - Serial1.begin(115200); + Serial.begin(115200); // Initialize Serial ports USART PIO_Configure( diff --git a/hardware/arduino/sam/variants/arduino_due_x/variant.h b/hardware/arduino/sam/variants/arduino_due_x/variant.h index f95270461..56cd60db2 100644 --- a/hardware/arduino/sam/variants/arduino_due_x/variant.h +++ b/hardware/arduino/sam/variants/arduino_due_x/variant.h @@ -201,7 +201,7 @@ static const uint8_t CANTX0 = 69; #ifdef __cplusplus -extern UARTClass Serial1 ; +extern UARTClass Serial ; extern USARTClass Serial2 ; extern USARTClass Serial3 ;