From e7d86986bde742da5c884cea7935c19ec83a3e10 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Geno=20=5B=E6=A0=BC=E8=AF=BA=5D?= Date: Tue, 21 Feb 2023 10:40:48 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90USB=E3=80=91=E6=94=AF=E6=8C=81?= =?UTF-8?q?=E7=94=B5=E8=84=91=E4=BC=91=E7=9C=A0=E5=94=A4=E9=86=92=E5=8A=9F?= =?UTF-8?q?=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 注意:此处修改会导致电脑休眠后,USB指示灯长亮,下一步应当通过Uart发送电脑处于休眠状态的信息,以便蓝牙主控获取信息后关闭USB指示灯。 --- usb/main.c | 40 ++++++++++++++++------------------------ usb/uart.c | 2 +- usb/usb_descriptor.h | 4 ++-- 3 files changed, 19 insertions(+), 27 deletions(-) diff --git a/usb/main.c b/usb/main.c index be433235f..1256ccfa5 100644 --- a/usb/main.c +++ b/usb/main.c @@ -59,18 +59,6 @@ static INTERRUPT_USING(DeviceInterrupt, INT_NO_USB, 1) //USB中断服务程序, UsbIsr(); } -/** - * @brief 按键发送事件 - * - */ -static void UsbOnKeySend() -{ - if (usb_state.is_sleep && usb_state.remote_wake) { - usb_state.is_sleep = false; - CH554USBDevWakeup(); - } -} - /** * @brief 上传键盘通常按键数据包 * @@ -81,12 +69,14 @@ void KeyboardGenericUpload(uint8_t* packet, uint8_t len) { if (len != 8) return; - UsbOnKeySend(); - - usb_state.is_busy = true; - memcpy(&Ep1Buffer[64], packet, len); - UEP1_T_LEN = len; - UEP1_CTRL = UEP1_CTRL & ~MASK_UEP_T_RES | UEP_T_RES_ACK; + if ((USB_MIS_ST & bUMS_SUSPEND) && usb_state.remote_wake) { + CH554USBDevWakeup(); + } else { + usb_state.is_busy = true; + memcpy(&Ep1Buffer[64], packet, len); + UEP1_T_LEN = len; + UEP1_CTRL = UEP1_CTRL & ~MASK_UEP_T_RES | UEP_T_RES_ACK; + } } /** @@ -97,12 +87,14 @@ void KeyboardGenericUpload(uint8_t* packet, uint8_t len) */ void KeyboardExtraUpload(uint8_t* packet, uint8_t len) { - UsbOnKeySend(); - - usb_state.is_busy = true; - memcpy(Ep2Buffer, packet, len); - UEP2_T_LEN = len; - UEP2_CTRL = UEP2_CTRL & ~MASK_UEP_T_RES | UEP_T_RES_ACK; + if ((USB_MIS_ST & bUMS_SUSPEND) && usb_state.remote_wake) { + CH554USBDevWakeup(); + } else { + usb_state.is_busy = true; + memcpy(Ep2Buffer, packet, len); + UEP2_T_LEN = len; + UEP2_CTRL = UEP2_CTRL & ~MASK_UEP_T_RES | UEP_T_RES_ACK; + } } /** diff --git a/usb/uart.c b/usb/uart.c index 7f9d83aa7..4699a382c 100644 --- a/usb/uart.c +++ b/usb/uart.c @@ -134,7 +134,7 @@ static void uart_send_status() if (!IS_CHARGING) // 是否充满 data |= 0x02; #endif - if (usb_state.is_ready && !usb_state.is_sleep) // 是否连接主机 + if (usb_state.is_ready || usb_state.remote_wake) // 是否连接主机 data |= 0x04; if (usb_state.protocol) data |= 0x08; diff --git a/usb/usb_descriptor.h b/usb/usb_descriptor.h index 94d85a320..65d3f34a9 100644 --- a/usb/usb_descriptor.h +++ b/usb/usb_descriptor.h @@ -45,7 +45,7 @@ enum StringDescriptor { uint8_t const DeviceDescriptor[] = { sizeof(DeviceDescriptor), // Length of this descriptor 0x01, // Type code of this descriptor - 0x10, 0x01, // Release of USB spec + 0x00, 0x02, // Release of USB spec 0x00, // Device's base class code 0x00, // Device's sub class code 0x00, // Device's protocol type code @@ -65,7 +65,7 @@ uint8_t const DeviceDescriptor[] = { #else #define USB_NUM_INTERFACES 0x03 #endif -#define USB_SUPPORT_REM_WAKE 0x00 // 0x20 support, 0x00 not support +#define USB_SUPPORT_REM_WAKE 0x20 // 0x20 support, 0x00 not support #define USB_SUPPORT_SELF_POWERED 0x80 // not self-powered #define USB_MAX_POWER 0xfa // 500 mA