aboutsummaryrefslogtreecommitdiff
path: root/cores/arduino/CDC.cpp
diff options
context:
space:
mode:
authorMatthijs Kooijman <matthijs@stdin.nl>2015-07-30 15:33:37 +0200
committerMatthijs Kooijman <matthijs@stdin.nl>2015-07-31 14:06:19 +0200
commit31e0c941240f2b1d0e4f97d6e65d3a1ad66fbae5 (patch)
tree0d080cc0e9601e1dc453f4452d29a5fddf4b2232 /cores/arduino/CDC.cpp
parentacb1a47a78ef96a5fcfbae9013dcc7d39e30292e (diff)
Add Serial_::readBreak() to process SEND_BREAK requests
This allows detecting when the USB host sends a break request and what the value of the request was. See the comments in USBAPI.h for details. This just modifies the avr core, not the sam core.
Diffstat (limited to 'cores/arduino/CDC.cpp')
-rw-r--r--cores/arduino/CDC.cpp18
1 files changed, 18 insertions, 0 deletions
diff --git a/cores/arduino/CDC.cpp b/cores/arduino/CDC.cpp
index 90a1698..5e872c5 100644
--- a/cores/arduino/CDC.cpp
+++ b/cores/arduino/CDC.cpp
@@ -32,6 +32,7 @@ typedef struct
} LineInfo;
static volatile LineInfo _usbLineInfo = { 57600, 0x00, 0x00, 0x00, 0x00 };
+static volatile int32_t breakValue = -1;
#define WEAK __attribute__ ((weak))
@@ -76,6 +77,11 @@ bool CDC_Setup(USBSetup& setup)
if (REQUEST_HOSTTODEVICE_CLASS_INTERFACE == requestType)
{
+ if (CDC_SEND_BREAK == r)
+ {
+ breakValue = ((uint16_t)setup.wValueH << 8) | setup.wValueL;
+ }
+
if (CDC_SET_LINE_CODING == r)
{
USB_RecvControl((void*)&_usbLineInfo,7);
@@ -207,6 +213,7 @@ Serial_::operator bool() {
}
unsigned long Serial_::baud() {
+ // Disable interrupts while reading a multi-byte value
ATOMIC_BLOCK(ATOMIC_RESTORESTATE) {
return _usbLineInfo.dwDTERate;
}
@@ -232,6 +239,17 @@ bool Serial_::rts() {
return _usbLineInfo.lineState & 0x2;
}
+int32_t Serial_::readBreak() {
+ int32_t ret;
+ // Disable IRQs while reading and clearing breakValue to make
+ // sure we don't overwrite a value just set by the ISR.
+ ATOMIC_BLOCK(ATOMIC_RESTORESTATE) {
+ ret = breakValue;
+ breakValue = -1;
+ }
+ return ret;
+}
+
Serial_ Serial;
#endif /* if defined(USBCON) */