Skip to content

Commit 7a57d86

Browse files
committed
2 parents 2fec828 + d20948d commit 7a57d86

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

Diff for: cores/arduino/USB/CDC.cpp

+24
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,30 @@ Serial_::operator bool()
299299
return result;
300300
}
301301

302+
unsigned long Serial_::baud() {
303+
return _usbLineInfo.dwDTERate;
304+
}
305+
306+
uint8_t Serial_::stopbits() {
307+
return _usbLineInfo.bCharFormat;
308+
}
309+
310+
uint8_t Serial_::paritytype() {
311+
return _usbLineInfo.bParityType;
312+
}
313+
314+
uint8_t Serial_::numbits() {
315+
return _usbLineInfo.bDataBits;
316+
}
317+
318+
bool Serial_::dtr() {
319+
return _usbLineInfo.lineState & 0x1;
320+
}
321+
322+
bool Serial_::rts() {
323+
return _usbLineInfo.lineState & 0x2;
324+
}
325+
302326
Serial_ SerialUSB;
303327

304328
#endif

Diff for: cores/arduino/USB/USBAPI.h

+22
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,28 @@ class Serial_ : public Stream
6161
virtual size_t write(const uint8_t *buffer, size_t size);
6262
using Print::write; // pull in write(str) from Print
6363
operator bool();
64+
65+
// These return the settings specified by the USB host for the
66+
// serial port. These aren't really used, but are offered here
67+
// in case a sketch wants to act on these settings.
68+
uint32_t baud();
69+
uint8_t stopbits();
70+
uint8_t paritytype();
71+
uint8_t numbits();
72+
bool dtr();
73+
bool rts();
74+
enum {
75+
ONE_STOP_BIT = 0,
76+
ONE_AND_HALF_STOP_BIT = 1,
77+
TWO_STOP_BITS = 2,
78+
};
79+
enum {
80+
NO_PARITY = 0,
81+
ODD_PARITY = 1,
82+
EVEN_PARITY = 2,
83+
MARK_PARITY = 3,
84+
SPACE_PARITY = 4,
85+
};
6486
};
6587
extern Serial_ SerialUSB;
6688

0 commit comments

Comments
 (0)