From 9a505d25b2f205abfd7808fef03d1f2fe9f38d0c Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Wed, 29 Aug 2012 12:13:42 +0200 Subject: [PATCH] Added optimized write(buffer,size) method in CDC class --- hardware/arduino/sam/cores/arduino/USB/CDC.cpp | 8 ++++++-- hardware/arduino/sam/cores/arduino/USB/USBAPI.h | 3 ++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/hardware/arduino/sam/cores/arduino/USB/CDC.cpp b/hardware/arduino/sam/cores/arduino/USB/CDC.cpp index 3c4f9feaf..b53bf8974 100644 --- a/hardware/arduino/sam/cores/arduino/USB/CDC.cpp +++ b/hardware/arduino/sam/cores/arduino/USB/CDC.cpp @@ -211,7 +211,7 @@ void Serial_::flush(void) USBD_Flush(CDC_TX); } -size_t Serial_::write(uint8_t c) +size_t Serial_::write(const uint8_t *buffer, size_t size) { /* only try to send bytes if the high-level CDC connection itself is open (not just the pipe) - the OS should set lineState when the port @@ -224,7 +224,7 @@ size_t Serial_::write(uint8_t c) // or locks up, or host virtual serial port hangs) if (_usbLineInfo.lineState > 0) { - int r = USBD_Send(CDC_TX,&c,1); + int r = USBD_Send(CDC_TX, buffer, size); if (r > 0) { @@ -239,6 +239,10 @@ size_t Serial_::write(uint8_t c) return 0; } +size_t Serial_::write(uint8_t c) { + return write(&c, 1); +} + // This operator is a convenient way for a sketch to check whether the // port has actually been configured and opened by the host (as opposed // to just being connected to the host). It can be used, for example, in diff --git a/hardware/arduino/sam/cores/arduino/USB/USBAPI.h b/hardware/arduino/sam/cores/arduino/USB/USBAPI.h index de9889599..7ccd1e219 100644 --- a/hardware/arduino/sam/cores/arduino/USB/USBAPI.h +++ b/hardware/arduino/sam/cores/arduino/USB/USBAPI.h @@ -57,7 +57,8 @@ public: virtual int read(void); virtual void flush(void); virtual size_t write(uint8_t); - using Print::write; // pull in write(str) and write(buf, size) from Print + virtual size_t write(const uint8_t *buffer, size_t size); + using Print::write; // pull in write(str) from Print operator bool(); }; extern Serial_ Serial;