File tree Expand file tree Collapse file tree 3 files changed +48
-0
lines changed
hardware/arduino/sam/cores/arduino/USB Expand file tree Collapse file tree 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 = {
5555 0x00 // lineState
5656};
5757
58+ static volatile int32_t breakValue = -1 ;
59+
5860_Pragma (" pack(1)" )
5961static const CDCDescriptor _cdcInterface =
6062{
@@ -141,6 +143,12 @@ bool WEAK CDC_Setup(USBSetup& setup)
141143 }
142144 return true ;
143145 }
146+
147+ if (CDC_SEND_BREAK == r)
148+ {
149+ breakValue = ((uint16_t )setup.wValueH << 8 ) | setup.wValueL ;
150+ return true ;
151+ }
144152 }
145153 return false ;
146154}
@@ -300,6 +308,28 @@ Serial_::operator bool()
300308 return result;
301309}
302310
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+
303333unsigned long Serial_::baud () {
304334 return _usbLineInfo.dwDTERate ;
305335}
Original file line number Diff line number Diff line change @@ -63,6 +63,23 @@ class Serial_ : public Stream
6363 using Print::write; // pull in write(str) from Print
6464 operator bool ();
6565
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+
6683 // These return the settings specified by the USB host for the
6784 // serial port. These aren't really used, but are offered here
6885 // in case a sketch wants to act on these settings.
Original file line number Diff line number Diff line change 5555#define CDC_SET_LINE_CODING 0x20
5656#define CDC_GET_LINE_CODING 0x21
5757#define CDC_SET_CONTROL_LINE_STATE 0x22
58+ #define CDC_SEND_BREAK 0x23
5859
5960#define MSC_RESET 0xFF
6061#define MSC_GET_MAX_LUN 0xFE
You can’t perform that action at this time.
0 commit comments