From 97e9c26fd7e748c821e43601b50accfc8f15eafd Mon Sep 17 00:00:00 2001
From: Sandeep Mistry <s.mistry@arduino.cc>
Date: Mon, 6 Jun 2016 10:00:21 -0400
Subject: [PATCH] Add Serial_::availableForWrite

---
 cores/arduino/USB/CDC.cpp  | 7 +++++++
 cores/arduino/USB/USBAPI.h | 1 +
 2 files changed, 8 insertions(+)

diff --git a/cores/arduino/USB/CDC.cpp b/cores/arduino/USB/CDC.cpp
index 5a111dce..4aa8071a 100644
--- a/cores/arduino/USB/CDC.cpp
+++ b/cores/arduino/USB/CDC.cpp
@@ -202,6 +202,13 @@ int Serial_::available(void)
 	return (uint32_t)(CDC_SERIAL_BUFFER_SIZE + buffer->head - buffer->tail) % CDC_SERIAL_BUFFER_SIZE;
 }
 
+int Serial_::availableForWrite(void)
+{
+	// return the number of bytes left in the current bank,
+	// always EP size - 1, because bank is flushed on every write
+	return (EPX_SIZE - 1);
+}
+
 int Serial_::peek(void)
 {
 	ring_buffer *buffer = &cdc_rx_buffer;
diff --git a/cores/arduino/USB/USBAPI.h b/cores/arduino/USB/USBAPI.h
index 1de82660..716edbfd 100644
--- a/cores/arduino/USB/USBAPI.h
+++ b/cores/arduino/USB/USBAPI.h
@@ -118,6 +118,7 @@ public:
 	void end(void);
 
 	virtual int available(void);
+	virtual int availableForWrite(void);
 	virtual void accept(void);
 	virtual int peek(void);
 	virtual int read(void);
-- 
GitLab