Skip to content

Commit b2269b6

Browse files
committed
Detect VCP line state.
* Detect VCP line state, based on SET_CONTROL_LINE_STATE request
1 parent 532f2c3 commit b2269b6

3 files changed

Lines changed: 9 additions & 2 deletions

File tree

stm/stmusbd/usbd_cdc_vcp.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ static uint16_t VCP_Ctrl (uint32_t Cmd, uint8_t* Buf, uint32_t Len);
6262
static uint16_t VCP_DataTx (const uint8_t* Buf, uint32_t Len);
6363
static uint16_t VCP_DataRx (uint8_t* Buf, uint32_t Len);
6464

65+
extern int dev_is_connected;
66+
6567
CDC_IF_Prop_TypeDef VCP_fops =
6668
{
6769
VCP_Init,
@@ -158,7 +160,7 @@ static uint16_t VCP_Ctrl (uint32_t Cmd, uint8_t* Buf, uint32_t Len)
158160
break;
159161

160162
case SET_CONTROL_LINE_STATE:
161-
/* Not needed for this driver */
163+
dev_is_connected = Len & 0x1; //wValue passed in Len
162164
break;
163165

164166
case SEND_BREAK:

stm/stmusbd/usbd_pyb_core.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -648,7 +648,7 @@ static uint8_t usbd_pyb_Setup(void *pdev, USB_SETUP_REQ *req) {
648648
// Not a Data request
649649

650650
// Transfer the command to the interface layer */
651-
return VCP_fops.pIf_Ctrl(req->bRequest, NULL, 0);
651+
return VCP_fops.pIf_Ctrl(req->bRequest, NULL, req->wValue);
652652
}
653653

654654
} else if (req->wIndex == 2) {

stm/usb.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ extern CDC_IF_Prop_TypeDef VCP_fops;
2020
USB_OTG_CORE_HANDLE USB_OTG_Core;
2121

2222
static int dev_is_enabled = 0;
23+
int dev_is_connected=0; /* used by usbd_cdc_vcp */
2324
static char rx_buf[64];
2425
static int rx_buf_in;
2526
static int rx_buf_out;
@@ -41,6 +42,10 @@ bool usb_vcp_is_enabled(void) {
4142
return dev_is_enabled;
4243
}
4344

45+
bool usb_vcp_is_connected(void) {
46+
return dev_is_connected;
47+
}
48+
4449
void usb_vcp_receive(const char *buf, uint32_t len) {
4550
if (dev_is_enabled) {
4651
for (int i = 0; i < len; i++) {

0 commit comments

Comments
 (0)