@@ -58,6 +58,8 @@ static volatile LineInfo _usbLineInfo = {
5858 0x00 // lineState
5959};
6060
61+ static volatile int32_t breakValue = -1 ;
62+
6163static CDCDescriptor _cdcInterface = {
6264 D_IAD (0 , 2 , CDC_COMMUNICATION_INTERFACE_CLASS, CDC_ABSTRACT_CONTROL_MODEL, 0 ),
6365
@@ -134,6 +136,12 @@ bool CDC_Setup(USBSetup& setup)
134136 }
135137 return false ;
136138 }
139+
140+ if (CDC_SEND_BREAK == r)
141+ {
142+ breakValue = ((uint16_t )setup.wValueH << 8 ) | setup.wValueL ;
143+ return false ;
144+ }
137145 }
138146 return false ;
139147}
@@ -289,6 +297,50 @@ Serial_::operator bool()
289297 return result;
290298}
291299
300+ int32_t Serial_::readBreak () {
301+ uint8_t enableInterrupts = ((__get_PRIMASK () & 0x1 ) == 0 );
302+
303+ // disable interrupts,
304+ // to avoid clearing a breakValue that might occur
305+ // while processing the current break value
306+ __disable_irq ();
307+
308+ int32_t ret = breakValue;
309+
310+ breakValue = -1 ;
311+
312+ if (enableInterrupts) {
313+ // re-enable the interrupts
314+ __enable_irq ();
315+ }
316+
317+ return ret;
318+ }
319+
320+ unsigned long Serial_::baud () {
321+ return _usbLineInfo.dwDTERate ;
322+ }
323+
324+ uint8_t Serial_::stopbits () {
325+ return _usbLineInfo.bCharFormat ;
326+ }
327+
328+ uint8_t Serial_::paritytype () {
329+ return _usbLineInfo.bParityType ;
330+ }
331+
332+ uint8_t Serial_::numbits () {
333+ return _usbLineInfo.bDataBits ;
334+ }
335+
336+ bool Serial_::dtr () {
337+ return _usbLineInfo.lineState & 0x1 ;
338+ }
339+
340+ bool Serial_::rts () {
341+ return _usbLineInfo.lineState & 0x2 ;
342+ }
343+
292344Serial_ SerialUSB (USBDevice);
293345
294346#endif
0 commit comments