File tree 2 files changed +42
-0
lines changed
hardware/arduino/sam/cores/arduino/USB
2 files changed +42
-0
lines changed Original file line number Diff line number Diff line change @@ -55,6 +55,8 @@ static volatile LineInfo _usbLineInfo = {
55
55
0x00 // lineState
56
56
};
57
57
58
+ static volatile int32_t breakValue = -1 ;
59
+
58
60
_Pragma (" pack(1)" )
59
61
static const CDCDescriptor _cdcInterface =
60
62
{
@@ -144,6 +146,7 @@ bool WEAK CDC_Setup(USBSetup& setup)
144
146
145
147
if (CDC_SEND_BREAK == r)
146
148
{
149
+ breakValue = ((uint16_t )setup.wValueH << 8 ) | setup.wValueL ;
147
150
return true ;
148
151
}
149
152
}
@@ -305,6 +308,28 @@ Serial_::operator bool()
305
308
return result;
306
309
}
307
310
311
+ int32_t Serial_::readBreak () {
312
+ uint8_t enableInterrupts = ((__get_PRIMASK () & 0x1 ) == 0 &&
313
+ (__get_FAULTMASK () & 0x1 ) == 0 );
314
+
315
+ // disable interrupts,
316
+ // to avoid clearing a breakValue that might occur
317
+ // while processing the current break value
318
+ __disable_irq ();
319
+
320
+ int ret = breakValue;
321
+
322
+ breakValue = -1 ;
323
+
324
+ if (enableInterrupts)
325
+ {
326
+ // re-enable the interrupts
327
+ __enable_irq ();
328
+ }
329
+
330
+ return ret;
331
+ }
332
+
308
333
unsigned long Serial_::baud () {
309
334
return _usbLineInfo.dwDTERate ;
310
335
}
Original file line number Diff line number Diff line change @@ -63,6 +63,23 @@ class Serial_ : public Stream
63
63
using Print::write; // pull in write(str) from Print
64
64
operator bool ();
65
65
66
+ // This method allows processing "SEND_BREAK" requests sent by
67
+ // the USB host. Those requests indicate that the host wants to
68
+ // send a BREAK signal and are accompanied by a single uint16_t
69
+ // value, specifying the duration of the break. The value 0
70
+ // means to end any current break, while the value 0xffff means
71
+ // to start an indefinite break.
72
+ // readBreak() will return the value of the most recent break
73
+ // request, but will return it at most once, returning -1 when
74
+ // readBreak() is called again (until another break request is
75
+ // received, which is again returned once).
76
+ // This also mean that if two break requests are received
77
+ // without readBreak() being called in between, the value of the
78
+ // first request is lost.
79
+ // Note that the value returned is a long, so it can return
80
+ // 0-0xffff as well as -1.
81
+ int32_t readBreak ();
82
+
66
83
// These return the settings specified by the USB host for the
67
84
// serial port. These aren't really used, but are offered here
68
85
// in case a sketch wants to act on these settings.
You can’t perform that action at this time.
0 commit comments