Skip to content

Commit da8a904

Browse files
committed
feat(usb): add optional CDC line-coding hook
1 parent dc3313b commit da8a904

2 files changed

Lines changed: 10 additions & 1 deletion

File tree

‎libraries/USBDevice/inc/usbd_cdc_if.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ uint8_t CDC_getStopBits(void);
5959
uint8_t CDC_getParity(void);
6060
uint8_t CDC_getDataBits(void);
6161

62+
/* Optional board hook invoked after the host changes the CDC line coding. */
63+
void CDC_LineCodingChanged(uint32_t bitrate);
64+
6265
#ifdef __cplusplus
6366
}
6467
#endif

‎libraries/USBDevice/src/cdc/usbd_cdc_if.c‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,12 @@ USBD_CDC_LineCodingTypeDef linecoding = {
8989
0x08 /* nb. of bits 8*/
9090
};
9191

92+
/* Boards that need a CDC line-coding side effect can override this hook. */
93+
WEAK void CDC_LineCodingChanged(uint32_t bitrate)
94+
{
95+
(void)bitrate;
96+
}
97+
9298
/* Private functions ---------------------------------------------------------*/
9399

94100
/**
@@ -175,6 +181,7 @@ static int8_t USBD_CDC_Control(uint8_t cmd, uint8_t *pbuf, uint16_t length)
175181
linecoding.format = pbuf[4];
176182
linecoding.paritytype = pbuf[5];
177183
linecoding.datatype = pbuf[6];
184+
CDC_LineCodingChanged(linecoding.bitrate);
178185
break;
179186

180187
case CDC_GET_LINE_CODING:
@@ -406,4 +413,3 @@ uint8_t CDC_getDataBits(void)
406413
#endif /* USBD_USE_CDC */
407414
#endif /* USBCON */
408415
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
409-

0 commit comments

Comments
 (0)