Added optimized write(buffer,size) method in CDC class

This commit is contained in:
Cristian Maglie 2012-08-29 12:13:42 +02:00
parent 9b027224a0
commit 9a505d25b2
2 changed files with 8 additions and 3 deletions

View File

@ -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

View File

@ -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;