File tree 3 files changed +48
-0
lines changed
hardware/arduino/sam/cores/arduino/USB
3 files changed +48
-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
{
@@ -141,6 +143,12 @@ bool WEAK CDC_Setup(USBSetup& setup)
141
143
}
142
144
return true ;
143
145
}
146
+
147
+ if (CDC_SEND_BREAK == r)
148
+ {
149
+ breakValue = ((uint16_t )setup.wValueH << 8 ) | setup.wValueL ;
150
+ return true ;
151
+ }
144
152
}
145
153
return false ;
146
154
}
@@ -300,6 +308,28 @@ Serial_::operator bool()
300
308
return result;
301
309
}
302
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
+
303
333
unsigned long Serial_::baud () {
304
334
return _usbLineInfo.dwDTERate ;
305
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.
Original file line number Diff line number Diff line change 55
55
#define CDC_SET_LINE_CODING 0x20
56
56
#define CDC_GET_LINE_CODING 0x21
57
57
#define CDC_SET_CONTROL_LINE_STATE 0x22
58
+ #define CDC_SEND_BREAK 0x23
58
59
59
60
#define MSC_RESET 0xFF
60
61
#define MSC_GET_MAX_LUN 0xFE
You can’t perform that action at this time.
0 commit comments