Skip to content

Commit 6e6c73f

Browse files
gickingfpistm
authored andcommitted
changed SerialUSB.baud() etc. to return the actual CDC line coding
1 parent 9c1dc68 commit 6e6c73f

File tree

3 files changed

+38
-4
lines changed

3 files changed

+38
-4
lines changed

libraries/USBDevice/inc/usbd_cdc_if.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,12 @@ void CDC_deInit(void);
5353
bool CDC_connected(void);
5454
void CDC_enableDTR(bool enable);
5555

56+
// getters for CDC line codings. Do not expose struct directly
57+
uint32_t CDC_getBaudrate(void);
58+
uint8_t CDC_getStopBits(void);
59+
uint8_t CDC_getParity(void);
60+
uint8_t CDC_getDataBits(void);
61+
5662
#ifdef __cplusplus
5763
}
5864
#endif

libraries/USBDevice/src/USBSerial.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -158,22 +158,26 @@ void USBSerial::flush(void)
158158

159159
uint32_t USBSerial::baud()
160160
{
161-
return 115200;
161+
// return (virtual) CDC line setting coding
162+
return CDC_getBaudrate();
162163
}
163164

164165
uint8_t USBSerial::stopbits()
165166
{
166-
return ONE_STOP_BIT;
167+
// return (virtual) CDC line setting coding
168+
return CDC_getStopBits();
167169
}
168170

169171
uint8_t USBSerial::paritytype()
170172
{
171-
return NO_PARITY;
173+
// return (virtual) CDC line setting coding
174+
return CDC_getParity();
172175
}
173176

174177
uint8_t USBSerial::numbits()
175178
{
176-
return 8;
179+
// return (virtual) CDC line setting coding
180+
return CDC_getDataBits();
177181
}
178182

179183
void USBSerial::dtr(bool enable)

libraries/USBDevice/src/cdc/usbd_cdc_if.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,30 @@ void CDC_enableDTR(bool enable)
379379
CDC_DTR_enabled = enable;
380380
}
381381

382+
// getter for CDC baudrate
383+
uint32_t CDC_getBaudrate()
384+
{
385+
return linecoding.bitrate;
386+
}
387+
388+
// getter for CDC stop bits. Note: CDC definition identical to USBSerial.h
389+
uint8_t CDC_getStopBits(void)
390+
{
391+
return linecoding.format;
392+
}
393+
394+
// getter for CDC parity. Note: CDC definition identical to USBSerial.h
395+
uint8_t CDC_getParity(void)
396+
{
397+
return linecoding.paritytype;
398+
}
399+
400+
// getter for CDC data bits. Note: CDC definition identical to USBSerial.h
401+
uint8_t CDC_getDataBits(void)
402+
{
403+
return linecoding.datatype;
404+
}
405+
382406
#endif /* USBD_USE_CDC */
383407
#endif /* USBCON */
384408
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

0 commit comments

Comments
 (0)