From d8d0f4b76050617707b04cf2062cc69a0a1bde0b Mon Sep 17 00:00:00 2001 From: Justin Rajewski Date: Tue, 18 Mar 2014 14:15:41 -0700 Subject: [PATCH 1/2] improved USB write speeds --- hardware/arduino/cores/arduino/CDC.cpp | 7 ++++++- hardware/arduino/cores/arduino/USBAPI.h | 1 + 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/hardware/arduino/cores/arduino/CDC.cpp b/hardware/arduino/cores/arduino/CDC.cpp index e1e859d18c4..fb0c0e09c75 100644 --- a/hardware/arduino/cores/arduino/CDC.cpp +++ b/hardware/arduino/cores/arduino/CDC.cpp @@ -199,6 +199,11 @@ void Serial_::flush(void) } size_t Serial_::write(uint8_t c) +{ + return write(&c, 1); +} + +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 @@ -210,7 +215,7 @@ size_t Serial_::write(uint8_t c) // open connection isn't broken cleanly (cable is yanked out, host dies // or locks up, or host virtual serial port hangs) if (_usbLineInfo.lineState > 0) { - int r = USB_Send(CDC_TX,&c,1); + int r = USB_Send(CDC_TX,buffer,size); if (r > 0) { return r; } else { diff --git a/hardware/arduino/cores/arduino/USBAPI.h b/hardware/arduino/cores/arduino/USBAPI.h index 7a14285db05..1c5ecf0fc90 100644 --- a/hardware/arduino/cores/arduino/USBAPI.h +++ b/hardware/arduino/cores/arduino/USBAPI.h @@ -40,6 +40,7 @@ class Serial_ : public Stream virtual int read(void); virtual void flush(void); virtual size_t write(uint8_t); + virtual size_t write(const uint8_t*, size_t); using Print::write; // pull in write(str) and write(buf, size) from Print operator bool(); }; From 93434ab8e9871b0739184ef4b60bc6e0124d802c Mon Sep 17 00:00:00 2001 From: Justin Rajewski Date: Mon, 24 Nov 2014 12:08:50 -0800 Subject: [PATCH 2/2] Added USB Serial Port Callbacks --- hardware/arduino/cores/arduino/CDC.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/hardware/arduino/cores/arduino/CDC.cpp b/hardware/arduino/cores/arduino/CDC.cpp index aae91c22137..91947bd15d3 100644 --- a/hardware/arduino/cores/arduino/CDC.cpp +++ b/hardware/arduino/cores/arduino/CDC.cpp @@ -61,6 +61,14 @@ int WEAK CDC_GetInterface(u8* interfaceNum) return USB_SendControl(TRANSFER_PGM,&_cdcInterface,sizeof(_cdcInterface)); } +void WEAK lineCodingEvent(long baud, byte databits, byte parity, byte charFormat) +{ +} + +void WEAK lineStateEvent(byte linestate) +{ +} + bool WEAK CDC_Setup(Setup& setup) { u8 r = setup.bRequest; @@ -80,6 +88,10 @@ bool WEAK CDC_Setup(Setup& setup) if (CDC_SET_LINE_CODING == r) { USB_RecvControl((void*)&_usbLineInfo,7); + lineCodingEvent(_usbLineInfo.dwDTERate, + _usbLineInfo.bDataBits, + _usbLineInfo.bParityType, + _usbLineInfo.bCharFormat); return true; } @@ -87,6 +99,8 @@ bool WEAK CDC_Setup(Setup& setup) { _usbLineInfo.lineState = setup.wValueL; + lineStateEvent(_usbLineInfo.lineState); + // auto-reset into the bootloader is triggered when the port, already // open at 1200 bps, is closed. this is the signal to start the watchdog // with a relatively long period so it can finish housekeeping tasks