1、新增Dengle定时参数下发功能,支持最多10条配置,断电保存到Flash,COM打开时暂停发送、关闭后恢复

2、新增USB查询产品码(0x66)和查询Dengle配置(0x74)命令
3、修复bleproto组包栈溢出导致设置Dengle后复位的问题,并完善CDC的DTR状态判断
This commit is contained in:
2026-07-31 14:54:26 +08:00
parent 79e15a9ccc
commit 2260768167
38 changed files with 1742 additions and 717 deletions
+33 -13
View File
@@ -171,22 +171,25 @@ static u32 cdc_setup(struct usb_device_t *usb_device, struct usb_ctrlrequest *ct
dump_line_coding((struct usb_cdc_line_coding *)cdc_hdl->subtype_data);
break;
case USB_CDC_REQ_SET_CONTROL_LINE_STATE:
log_debug("set control line state - %d", ctrl_req->wValue);
/* wValue.bit0=DTR(打开COM通常置1), bit1=RTS */
log_info("set control line state wValue=0x%04x DTR=%d RTS=%d",
ctrl_req->wValue,
!!(ctrl_req->wValue & BIT(0)),
!!(ctrl_req->wValue & BIT(1)));
if (cdc_hdl) {
/* if (ctrl_req->wValue & BIT(0)) { //DTR */
cdc_hdl->bmTransceiver |= BIT(0);
/* } else { */
/* usb_slave->cdc->bmTransceiver &= ~BIT(0); */
/* } */
/* if (ctrl_req->wValue & BIT(1)) { //RTS */
cdc_hdl->bmTransceiver |= BIT(1);
/* } else { */
/* usb_slave->cdc->bmTransceiver &= ~BIT(1); */
/* } */
cdc_hdl->bmTransceiver |= BIT(4); //cfg done
if (ctrl_req->wValue & BIT(0)) { /* DTR */
cdc_hdl->bmTransceiver |= BIT(0);
} else {
cdc_hdl->bmTransceiver &= ~BIT(0);
}
if (ctrl_req->wValue & BIT(1)) { /* RTS */
cdc_hdl->bmTransceiver |= BIT(1);
} else {
cdc_hdl->bmTransceiver &= ~BIT(1);
}
cdc_hdl->bmTransceiver |= BIT(4); /* cfg done */
}
usb_set_setup_phase(usb_device, USB_EP0_STAGE_SETUP);
//cdc_endpoint_init(usb_device, (ctrl_req->wIndex & USB_RECIP_MASK));
break;
default:
log_error("unsupported class req");
@@ -238,6 +241,10 @@ static void cdc_reset(struct usb_device_t *usb_device, u32 itf)
{
log_error("%s()", __func__);
const usb_dev usb_id = usb_device2id(usb_device);
/* USB 复位/重枚举时清掉 COM 开闭状态 */
if (cdc_hdl) {
cdc_hdl->bmTransceiver &= ~(BIT(0) | BIT(1));
}
#if USB_ROOT2
usb_disable_ep(usb_id, CDC_DATA_EP_IN);
#if CDC_INTR_EP_ENABLE
@@ -487,4 +494,17 @@ void cdc_release(const usb_dev usb_id)
}
}
/**
* @brief 上位机是否已打开 COMCDC DTR 有效)
* @return 1=COM 已打开 0=未打开/已关闭
*/
u8 cdc_is_com_open(void)
{
if (cdc_hdl == NULL) {
return 0;
}
/* DTR=1 表示主机打开了虚拟串口 */
return (cdc_hdl->bmTransceiver & BIT(0)) ? 1 : 0;
}
#endif
+5
View File
@@ -15,6 +15,11 @@ u32 cdc_write_data(const usb_dev usb_id, u8 *buf, u32 len);
u32 cdc_write_inir(const usb_dev usb_id, u8 *buf, u32 len);
void cdc_register(const usb_dev usb_id);
void cdc_release(const usb_dev usb_id);
/**
* @brief 上位机是否已打开 COM(依据 CDC DTR
* @return 1=已打开 0=未打开
*/
u8 cdc_is_com_open(void);
#ifdef __cplusplus
}