From bb5f7e434b2bbf75f92521748efe2ece54385209 Mon Sep 17 00:00:00 2001 From: sakumisu <1203593632@qq.com> Date: Tue, 9 Nov 2021 10:28:10 +0800 Subject: [PATCH] modify class request print log --- class/audio/usbd_audio.c | 17 ++++++++++---- class/cdc/usbd_cdc.c | 4 ++++ class/cdc/usbd_cdc.h | 50 ++++++++++++++++++++-------------------- class/dfu/usbd_dfu.c | 8 ------- class/hid/usbd_hid.c | 12 +++++----- class/video/usbd_video.c | 6 ++--- common/usb_dc.h | 1 - common/usb_util.h | 13 ++++++----- 8 files changed, 58 insertions(+), 53 deletions(-) diff --git a/class/audio/usbd_audio.c b/class/audio/usbd_audio.c index b2513cf0..4ac42661 100644 --- a/class/audio/usbd_audio.c +++ b/class/audio/usbd_audio.c @@ -5,9 +5,9 @@ struct usbd_audio_control_info audio_control_info = { 0xdb00, 0x0000, 0x0100, 0x int audio_class_request_handler(struct usb_setup_packet *setup, uint8_t **data, uint32_t *len) { - USBD_LOG_DBG("Class request:" - "bRequest 0x%02x, bmRequestType 0x%02x len %d", - setup->bRequest, setup->bmRequestType, *len); + USBD_LOG_DBG("AUDIO Class request: " + "bRequest 0x%02x\r\n", + setup->bRequest); switch (setup->bRequest) { case AUDIO_REQUEST_SET_CUR: @@ -24,7 +24,7 @@ int audio_class_request_handler(struct usb_setup_packet *setup, uint8_t **data, vol = (audio_control_info.vol_current - 0xDB00 + 1) * 100 / (0xFFFF - 0xDB00); } usbd_audio_set_volume(vol); - USBD_LOG_WRN("vol:%d\r\n", vol); + USBD_LOG("current volume:%d\r\n", vol); } } @@ -44,6 +44,9 @@ int audio_class_request_handler(struct usb_setup_packet *setup, uint8_t **data, case AUDIO_REQUEST_SET_RES: break; + case AUDIO_REQUEST_SET_MEM: + break; + case AUDIO_REQUEST_GET_MIN: *data = (uint8_t *)&audio_control_info.vol_min; *len = 2; @@ -58,6 +61,10 @@ int audio_class_request_handler(struct usb_setup_packet *setup, uint8_t **data, *data = (uint8_t *)&audio_control_info.vol_res; *len = 2; break; + case AUDIO_REQUEST_GET_MEM: + *data[0] = 0; + *len = 1; + break; default: USBD_LOG_ERR("Unhandled request 0x%02x", setup->bRequest); @@ -85,9 +92,11 @@ void audio_notify_handler(uint8_t event, void *arg) break; } } + __weak void usbd_audio_set_volume(uint8_t vol) { } + void usbd_audio_add_interface(usbd_class_t *class, usbd_interface_t *intf) { static usbd_class_t *last_class = NULL; diff --git a/class/cdc/usbd_cdc.c b/class/cdc/usbd_cdc.c index 69d8d307..1e1c3fe3 100644 --- a/class/cdc/usbd_cdc.c +++ b/class/cdc/usbd_cdc.c @@ -65,6 +65,10 @@ static void usbd_cdc_acm_reset(void) */ static int cdc_acm_class_request_handler(struct usb_setup_packet *pSetup, uint8_t **data, uint32_t *len) { + USBD_LOG_DBG("CDC Class request: " + "bRequest 0x%02x\r\n", + setup->bRequest); + switch (pSetup->bRequest) { case CDC_REQUEST_SET_LINE_CODING: diff --git a/class/cdc/usbd_cdc.h b/class/cdc/usbd_cdc.h index 1441fd4c..33c2ac29 100644 --- a/class/cdc/usbd_cdc.h +++ b/class/cdc/usbd_cdc.h @@ -297,8 +297,8 @@ struct cdc_ecm_descriptor { #define CDC_ACM_DESCRIPTOR_LEN (8 + 9 + 5 + 5 + 4 + 5 + 7 + 9 + 7 + 7) // clang-format off #ifndef CONFIG_USB_HS -#define CDC_ACM_DESCRIPTOR_INIT(bFirstInterface, int_ep, out_ep, in_ep, str_idx) \ - /* Interface Associate */ \ +#define CDC_ACM_DESCRIPTOR_INIT(bFirstInterface, int_ep, out_ep, in_ep, str_idx) \ + /* Interface Associate */ \ 0x08, /* bLength */ \ USB_DESCRIPTOR_TYPE_INTERFACE_ASSOCIATION, /* bDescriptorType */ \ bFirstInterface, /* bFirstInterface */ \ @@ -306,7 +306,7 @@ struct cdc_ecm_descriptor { USB_DEVICE_CLASS_CDC, /* bFunctionClass */ \ CDC_ABSTRACT_CONTROL_MODEL, /* bFunctionSubClass */ \ CDC_COMMON_PROTOCOL_AT_COMMANDS, /* bFunctionProtocol */ \ - 0x00, /* iFunction */ /* CDC Control Interface */ \ + 0x00, /* iFunction */ \ 0x09, /* bLength */ \ USB_DESCRIPTOR_TYPE_INTERFACE, /* bDescriptorType */ \ bFirstInterface, /* bInterfaceNumber */ \ @@ -315,31 +315,31 @@ struct cdc_ecm_descriptor { USB_DEVICE_CLASS_CDC, /* bInterfaceClass */ \ CDC_ABSTRACT_CONTROL_MODEL, /* bInterfaceSubClass */ \ CDC_COMMON_PROTOCOL_AT_COMMANDS, /* bInterfaceProtocol */ \ - str_idx, /* iInterface */ /* CDC Header */ \ + str_idx, /* iInterface */ \ 0x05, /* bLength */ \ CDC_CS_INTERFACE, /* bDescriptorType */ \ CDC_FUNC_DESC_HEADER, /* bDescriptorSubtype */ \ - WBVAL(CDC_V1_10), /* bcdCDC */ /* CDC Call */ \ + WBVAL(CDC_V1_10), /* bcdCDC */ \ 0x05, /* bLength */ \ CDC_CS_INTERFACE, /* bDescriptorType */ \ CDC_FUNC_DESC_CALL_MANAGEMENT, /* bDescriptorSubtype */ \ bFirstInterface, /* bmCapabilities */ \ - (uint8_t)(bFirstInterface + 1), /* bDataInterface */ /* CDC ACM: support line request */ \ + (uint8_t)(bFirstInterface + 1), /* bDataInterface */ \ 0x04, /* bLength */ \ CDC_CS_INTERFACE, /* bDescriptorType */ \ CDC_FUNC_DESC_ABSTRACT_CONTROL_MANAGEMENT, /* bDescriptorSubtype */ \ - 0x02, /* bmCapabilities */ /* CDC Union */ \ + 0x02, /* bmCapabilities */ \ 0x05, /* bLength */ \ CDC_CS_INTERFACE, /* bDescriptorType */ \ CDC_FUNC_DESC_UNION, /* bDescriptorSubtype */ \ bFirstInterface, /* bMasterInterface */ \ - (uint8_t)(bFirstInterface + 1), /* bSlaveInterface0 */ /* Endpoint Notification */ \ + (uint8_t)(bFirstInterface + 1), /* bSlaveInterface0 */ \ 0x07, /* bLength */ \ USB_DESCRIPTOR_TYPE_ENDPOINT, /* bDescriptorType */ \ int_ep, /* bEndpointAddress */ \ 0x03, /* bmAttributes */ \ 0x40, 0x00, /* wMaxPacketSize */ \ - 0x01, /* bInterval */ /* CDC Data Interface */ \ + 0x00, /* bInterval */ \ 0x09, /* bLength */ \ USB_DESCRIPTOR_TYPE_INTERFACE, /* bDescriptorType */ \ (uint8_t)(bFirstInterface + 1), /* bInterfaceNumber */ \ @@ -348,19 +348,19 @@ struct cdc_ecm_descriptor { CDC_DATA_INTERFACE_CLASS, /* bInterfaceClass */ \ 0x00, /* bInterfaceSubClass */ \ 0x00, /* bInterfaceProtocol */ \ - 0x00, /* iInterface */ /* Endpoint Out */ \ + 0x00, /* iInterface */ \ 0x07, /* bLength */ \ USB_DESCRIPTOR_TYPE_ENDPOINT, /* bDescriptorType */ \ out_ep, /* bEndpointAddress */ \ 0x02, /* bmAttributes */ \ 0x40, 0x00, /* wMaxPacketSize */ \ - 0x01, /* bInterval */ /* Endpoint In */ \ + 0x00, /* bInterval */ \ 0x07, /* bLength */ \ USB_DESCRIPTOR_TYPE_ENDPOINT, /* bDescriptorType */ \ in_ep, /* bEndpointAddress */ \ 0x02, /* bmAttributes */ \ 0x40, 0x00, /* wMaxPacketSize */ \ - 0x01 /* bInterval */ + 0x00 /* bInterval */ #else #define CDC_ACM_DESCRIPTOR_INIT(bFirstInterface, int_ep, out_ep, in_ep, str_idx) \ /* Interface Associate */ \ @@ -371,7 +371,7 @@ struct cdc_ecm_descriptor { USB_DEVICE_CLASS_CDC, /* bFunctionClass */ \ CDC_ABSTRACT_CONTROL_MODEL, /* bFunctionSubClass */ \ CDC_COMMON_PROTOCOL_AT_COMMANDS, /* bFunctionProtocol */ \ - 0x00, /* iFunction */ /* CDC Control Interface */ \ + 0x00, /* iFunction */ \ 0x09, /* bLength */ \ USB_DESCRIPTOR_TYPE_INTERFACE, /* bDescriptorType */ \ bFirstInterface, /* bInterfaceNumber */ \ @@ -380,31 +380,31 @@ struct cdc_ecm_descriptor { USB_DEVICE_CLASS_CDC, /* bInterfaceClass */ \ CDC_ABSTRACT_CONTROL_MODEL, /* bInterfaceSubClass */ \ CDC_COMMON_PROTOCOL_AT_COMMANDS, /* bInterfaceProtocol */ \ - str_idx, /* iInterface */ /* CDC Header */ \ + str_idx, /* iInterface */ \ 0x05, /* bLength */ \ CDC_CS_INTERFACE, /* bDescriptorType */ \ CDC_FUNC_DESC_HEADER, /* bDescriptorSubtype */ \ - WBVAL(CDC_V1_10), /* bcdCDC */ /* CDC Call */ \ + WBVAL(CDC_V1_10), /* bcdCDC */ \ 0x05, /* bLength */ \ CDC_CS_INTERFACE, /* bDescriptorType */ \ CDC_FUNC_DESC_CALL_MANAGEMENT, /* bDescriptorSubtype */ \ bFirstInterface, /* bmCapabilities */ \ - (uint8_t)(bFirstInterface + 1), /* bDataInterface */ /* CDC ACM: support line request */ \ + (uint8_t)(bFirstInterface + 1), /* bDataInterface */ \ 0x04, /* bLength */ \ CDC_CS_INTERFACE, /* bDescriptorType */ \ CDC_FUNC_DESC_ABSTRACT_CONTROL_MANAGEMENT, /* bDescriptorSubtype */ \ - 0x02, /* bmCapabilities */ /* CDC Union */ \ + 0x02, /* bmCapabilities */ \ 0x05, /* bLength */ \ CDC_CS_INTERFACE, /* bDescriptorType */ \ CDC_FUNC_DESC_UNION, /* bDescriptorSubtype */ \ bFirstInterface, /* bMasterInterface */ \ - (uint8_t)(bFirstInterface + 1), /* bSlaveInterface0 */ /* Endpoint Notification */ \ + (uint8_t)(bFirstInterface + 1), /* bSlaveInterface0 */ \ 0x07, /* bLength */ \ USB_DESCRIPTOR_TYPE_ENDPOINT, /* bDescriptorType */ \ int_ep, /* bEndpointAddress */ \ 0x03, /* bmAttributes */ \ - 0x02, 0x00, /* wMaxPacketSize */ \ - 0x01, /* bInterval */ /* CDC Data Interface */ \ + 0x00, 0x02, /* wMaxPacketSize */ \ + 0x00, /* bInterval */ \ 0x09, /* bLength */ \ USB_DESCRIPTOR_TYPE_INTERFACE, /* bDescriptorType */ \ (uint8_t)(bFirstInterface + 1), /* bInterfaceNumber */ \ @@ -413,19 +413,19 @@ struct cdc_ecm_descriptor { CDC_DATA_INTERFACE_CLASS, /* bInterfaceClass */ \ 0x00, /* bInterfaceSubClass */ \ 0x00, /* bInterfaceProtocol */ \ - 0x00, /* iInterface */ /* Endpoint Out */ \ + 0x00, /* iInterface */ \ 0x07, /* bLength */ \ USB_DESCRIPTOR_TYPE_ENDPOINT, /* bDescriptorType */ \ out_ep, /* bEndpointAddress */ \ 0x02, /* bmAttributes */ \ - 0x02, 0x00, /* wMaxPacketSize */ \ - 0x01, /* bInterval */ /* Endpoint In */ \ + 0x00, 0x02, /* wMaxPacketSize */ \ + 0x00, /* bInterval */ \ 0x07, /* bLength */ \ USB_DESCRIPTOR_TYPE_ENDPOINT, /* bDescriptorType */ \ in_ep, /* bEndpointAddress */ \ 0x02, /* bmAttributes */ \ - 0x02, 0x00, /* wMaxPacketSize */ \ - 0x01 /* bInterval */ + 0x00, 0x02, /* wMaxPacketSize */ \ + 0x00 /* bInterval */ #endif // clang-format on diff --git a/class/dfu/usbd_dfu.c b/class/dfu/usbd_dfu.c index 58e94f6a..769955f8 100644 --- a/class/dfu/usbd_dfu.c +++ b/class/dfu/usbd_dfu.c @@ -14,26 +14,18 @@ int dfu_class_request_handler(struct usb_setup_packet *setup, uint8_t **data, ui switch (setup->bRequest) { case DFU_REQUEST_DETACH: - break; - case DFU_REQUEST_DNLOAD: - break; case DFU_REQUEST_UPLOAD: - break; case DFU_REQUEST_GETSTATUS: - break; case DFU_REQUEST_CLRSTATUS: - break; case DFU_REQUEST_GETSTATE: - break; case DFU_REQUEST_ABORT: - break; default: USBD_LOG_ERR("Unhandled request 0x%02x", setup->bRequest); diff --git a/class/hid/usbd_hid.c b/class/hid/usbd_hid.c index 34f2faf5..43fb5967 100644 --- a/class/hid/usbd_hid.c +++ b/class/hid/usbd_hid.c @@ -63,9 +63,9 @@ static void usbd_hid_reset(void) int hid_custom_request_handler(struct usb_setup_packet *setup, uint8_t **data, uint32_t *len) { - USBD_LOG_DBG("Standard request:" - "bmRequestType 0x%02x, bRequest 0x%02x, len %d\r\n", - setup->bmRequestType, setup->bRequest, *len); + USBD_LOG_DBG("HID Custom request: " + "bRequest 0x%02x\r\n", + setup->bRequest); if (REQTYPE_GET_DIR(setup->bmRequestType) == USB_REQUEST_DEVICE_TO_HOST && setup->bRequest == USB_REQUEST_GET_DESCRIPTOR) { @@ -118,9 +118,9 @@ int hid_custom_request_handler(struct usb_setup_packet *setup, uint8_t **data, u int hid_class_request_handler(struct usb_setup_packet *setup, uint8_t **data, uint32_t *len) { - USBD_LOG("Class request:" - "bmRequestType 0x%02x bRequest 0x%02x, len %d\r\n", - setup->bmRequestType, setup->bRequest, *len); + USBD_LOG_DBG("HID Class request: " + "bRequest 0x%02x\r\n", + setup->bRequest); struct usbd_hid_cfg_private *current_hid_intf = NULL; usb_slist_t *i; diff --git a/class/video/usbd_video.c b/class/video/usbd_video.c index 11c31649..f4570ccd 100644 --- a/class/video/usbd_video.c +++ b/class/video/usbd_video.c @@ -27,9 +27,9 @@ extern struct video_probe_and_commit_controls commit; int video_class_request_handler(struct usb_setup_packet *setup, uint8_t **data, uint32_t *len) { - USBD_LOG_DBG("Class request:" - "bRequest 0x%02x, bmRequestType 0x%02x len %d", - setup->bRequest, setup->bmRequestType, *len); + USBD_LOG_DBG("VIDEO Class request: " + "bRequest 0x%02x\r\n", + setup->bRequest); switch (setup->bRequest) { case VIDEO_REQUEST_SET_CUR: diff --git a/common/usb_dc.h b/common/usb_dc.h index ea57fcde..29997c11 100644 --- a/common/usb_dc.h +++ b/common/usb_dc.h @@ -2,7 +2,6 @@ #define _USB_DC_H #include "stdint.h" -#include "bflb_platform.h" #ifdef __cplusplus extern "C" { diff --git a/common/usb_util.h b/common/usb_util.h index eebd3401..4c18cc14 100644 --- a/common/usb_util.h +++ b/common/usb_util.h @@ -5,6 +5,7 @@ #include "string.h" #include "stdint.h" #include "stdio.h" +#include "stdlib.h" #include "usb_slist.h" #ifndef __packed @@ -127,14 +128,14 @@ #define DBVAL(x) (x & 0xFF), ((x >> 8) & 0xFF), ((x >> 16) & 0xFF), ((x >> 24) & 0xFF) #if 0 -#define USBD_LOG_WRN(a, ...) bflb_platform_printf(a, ##__VA_ARGS__) -#define USBD_LOG_DBG(a, ...) bflb_platform_printf(a, ##__VA_ARGS__) -#define USBD_LOG_ERR(a, ...) bflb_platform_printf(a, ##__VA_ARGS__) +#define USBD_LOG_WRN(a, ...) printf(a, ##__VA_ARGS__) +#define USBD_LOG_DBG(a, ...) printf(a, ##__VA_ARGS__) +#define USBD_LOG_ERR(a, ...) printf(a, ##__VA_ARGS__) #else -#define USBD_LOG_WRN(a, ...) bflb_platform_printf(a, ##__VA_ARGS__) +#define USBD_LOG_WRN(a, ...) printf(a, ##__VA_ARGS__) #define USBD_LOG_DBG(a, ...) -#define USBD_LOG_ERR(a, ...) bflb_platform_printf(a, ##__VA_ARGS__) -#define USBD_LOG(a, ...) bflb_platform_printf(a, ##__VA_ARGS__) +#define USBD_LOG_ERR(a, ...) printf(a, ##__VA_ARGS__) +#define USBD_LOG(a, ...) printf(a, ##__VA_ARGS__) #endif #endif \ No newline at end of file