Skip to content

Commit 9a505d2

Browse files
committed
Added optimized write(buffer,size) method in CDC class
1 parent 9b02722 commit 9a505d2

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

Diff for: hardware/arduino/sam/cores/arduino/USB/CDC.cpp

+6-2
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ void Serial_::flush(void)
211211
USBD_Flush(CDC_TX);
212212
}
213213

214-
size_t Serial_::write(uint8_t c)
214+
size_t Serial_::write(const uint8_t *buffer, size_t size)
215215
{
216216
/* only try to send bytes if the high-level CDC connection itself
217217
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)
224224
// or locks up, or host virtual serial port hangs)
225225
if (_usbLineInfo.lineState > 0)
226226
{
227-
int r = USBD_Send(CDC_TX,&c,1);
227+
int r = USBD_Send(CDC_TX, buffer, size);
228228

229229
if (r > 0)
230230
{
@@ -239,6 +239,10 @@ size_t Serial_::write(uint8_t c)
239239
return 0;
240240
}
241241

242+
size_t Serial_::write(uint8_t c) {
243+
return write(&c, 1);
244+
}
245+
242246
// This operator is a convenient way for a sketch to check whether the
243247
// port has actually been configured and opened by the host (as opposed
244248
// to just being connected to the host). It can be used, for example, in

Diff for: hardware/arduino/sam/cores/arduino/USB/USBAPI.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ class Serial_ : public Stream
5757
virtual int read(void);
5858
virtual void flush(void);
5959
virtual size_t write(uint8_t);
60-
using Print::write; // pull in write(str) and write(buf, size) from Print
60+
virtual size_t write(const uint8_t *buffer, size_t size);
61+
using Print::write; // pull in write(str) from Print
6162
operator bool();
6263
};
6364
extern Serial_ Serial;

0 commit comments

Comments
 (0)