[comment][usb] modify print log

This commit is contained in:
jzlv 2021-11-16 10:41:14 +08:00
parent 5d5c6a2f32
commit 160d44443d
8 changed files with 95 additions and 71 deletions

View File

@ -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("current volume:%d\r\n", vol);
USBD_LOG_INFO("current audio volume:%d\r\n", vol);
}
}
@ -67,8 +67,8 @@ int audio_class_request_handler(struct usb_setup_packet *setup, uint8_t **data,
break;
default:
USBD_LOG_ERR("Unhandled request 0x%02x", setup->bRequest);
break;
USBD_LOG_WRN("Unhandled Audio Class bRequest 0x%02x\r\n", setup->bRequest);
return -1;
}
return 0;

View File

@ -57,19 +57,19 @@ static void usbd_cdc_acm_reset(void)
/**
* @brief Handler called for Class requests not handled by the USB stack.
*
* @param pSetup Information about the request to execute.
* @param setup Information about the request to execute.
* @param len Size of the buffer.
* @param data Buffer containing the request result.
*
* @return 0 on success, negative errno code on fail.
*/
static int cdc_acm_class_request_handler(struct usb_setup_packet *pSetup, uint8_t **data, uint32_t *len)
static int cdc_acm_class_request_handler(struct usb_setup_packet *setup, uint8_t **data, uint32_t *len)
{
USBD_LOG_DBG("CDC Class request: "
"bRequest 0x%02x\r\n",
setup->bRequest);
switch (pSetup->bRequest) {
switch (setup->bRequest) {
case CDC_REQUEST_SET_LINE_CODING:
/*******************************************************************************/
@ -105,9 +105,9 @@ static int cdc_acm_class_request_handler(struct usb_setup_packet *pSetup, uint8_
break;
case CDC_REQUEST_SET_CONTROL_LINE_STATE:
usbd_cdc_acm_cfg.line_state = (uint8_t)pSetup->wValue;
bool dtr = (pSetup->wValue & 0x01);
bool rts = (pSetup->wValue & 0x02);
usbd_cdc_acm_cfg.line_state = (uint8_t)setup->wValue;
bool dtr = (setup->wValue & 0x01);
bool rts = (setup->wValue & 0x02);
USBD_LOG_DBG("DTR 0x%x,RTS 0x%x\r\n",
dtr, rts);
usbd_cdc_acm_set_dtr(dtr);
@ -125,8 +125,7 @@ static int cdc_acm_class_request_handler(struct usb_setup_packet *pSetup, uint8_
break;
default:
USBD_LOG_DBG("CDC ACM request 0x%x, value 0x%x\r\n",
pSetup->bRequest, pSetup->wValue);
USBD_LOG_WRN("Unhandled CDC Class bRequest 0x%02x\r\n", setup->bRequest);
return -1;
}

View File

@ -90,19 +90,19 @@ int hid_custom_request_handler(struct usb_setup_packet *setup, uint8_t **data, u
switch (value) {
case HID_DESCRIPTOR_TYPE_HID:
USBD_LOG("get HID Descriptor\r\n");
USBD_LOG_INFO("get HID Descriptor\r\n");
*data = (uint8_t *)current_hid_intf->hid_descriptor;
*len = current_hid_intf->hid_descriptor[0];
break;
case HID_DESCRIPTOR_TYPE_HID_REPORT:
USBD_LOG("get Report Descriptor\r\n");
USBD_LOG_INFO("get Report Descriptor\r\n");
*data = (uint8_t *)current_hid_intf->hid_report_descriptor;
*len = current_hid_intf->hid_report_descriptor_len;
break;
case HID_DESCRIPTOR_TYPE_HID_PHYSICAL:
USBD_LOG_DBG("get PHYSICAL Descriptor\r\n");
USBD_LOG_INFO("get PHYSICAL Descriptor\r\n");
break;
@ -180,8 +180,8 @@ int hid_class_request_handler(struct usb_setup_packet *setup, uint8_t **data, ui
break;
default:
USBD_LOG_ERR("Unhandled request 0x%02x\r\n", setup->bRequest);
break;
USBD_LOG_WRN("Unhandled HID Class bRequest 0x%02x\r\n", setup->bRequest);
return -1;
}
return 0;

View File

@ -113,24 +113,24 @@ static void usbd_msc_reset(void)
/**
* @brief Handler called for Class requests not handled by the USB stack.
*
* @param pSetup Information about the request to execute.
* @param setup Information about the request to execute.
* @param len Size of the buffer.
* @param data Buffer containing the request result.
*
* @return 0 on success, negative errno code on fail.
*/
static int msc_storage_class_request_handler(struct usb_setup_packet *pSetup, uint8_t **data, uint32_t *len)
static int msc_storage_class_request_handler(struct usb_setup_packet *setup, uint8_t **data, uint32_t *len)
{
USBD_LOG_DBG("MSC Class request: "
"bRequest 0x%02x\r\n",
setup->bRequest);
switch (pSetup->bRequest) {
switch (setup->bRequest) {
case MSC_REQUEST_RESET:
USBD_LOG_DBG("MSC_REQUEST_RESET");
USBD_LOG_DBG("MSC_REQUEST_RESET\r\n");
if (pSetup->wLength) {
USBD_LOG_WRN("Invalid length");
if (setup->wLength) {
USBD_LOG_WRN("Invalid length\r\n");
return -1;
}
@ -138,10 +138,10 @@ static int msc_storage_class_request_handler(struct usb_setup_packet *pSetup, ui
break;
case MSC_REQUEST_GET_MAX_LUN:
USBD_LOG_DBG("MSC_REQUEST_GET_MAX_LUN");
USBD_LOG_DBG("MSC_REQUEST_GET_MAX_LUN\r\n");
if (pSetup->wLength != 1) {
USBD_LOG_WRN("Invalid length");
if (setup->wLength != 1) {
USBD_LOG_WRN("Invalid length\r\n");
return -1;
}
@ -150,8 +150,7 @@ static int msc_storage_class_request_handler(struct usb_setup_packet *pSetup, ui
break;
default:
USBD_LOG_WRN("Unknown request 0x%02x, value 0x%02x",
pSetup->bRequest, pSetup->wValue);
USBD_LOG_WRN("Unhandled MSC Class bRequest 0x%02x\r\n", setup->bRequest);
return -1;
}

View File

@ -27,7 +27,7 @@ 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("VIDEO Class request: "
USBD_LOG_DBG("Video Class request: "
"bRequest 0x%02x\r\n",
setup->bRequest);
@ -90,8 +90,8 @@ int video_class_request_handler(struct usb_setup_packet *setup, uint8_t **data,
break;
default:
USBD_LOG_ERR("Unhandled request 0x%02x", setup->bRequest);
break;
USBD_LOG_WRN("Unhandled Video Class bRequest 0x%02x\r\n", setup->bRequest);
return -1;
}
return 0;

View File

@ -8,12 +8,23 @@ extern "C" {
#endif
/**
* @brief USB Device Controller API
* @defgroup _usb_device_controller_api USB Device Controller API
* @{
* USB endpoint direction and number.
*/
/**< maximum packet size (MPS) for EP 0 */
#define USB_CTRL_EP_MPS 64
#define USB_EP_DIR_MASK 0x80U
#define USB_EP_DIR_IN 0x80U
#define USB_EP_DIR_OUT 0x00U
/** Get endpoint index (number) from endpoint address */
#define USB_EP_GET_IDX(ep) ((ep) & ~USB_EP_DIR_MASK)
/** Get direction from endpoint address */
#define USB_EP_GET_DIR(ep) ((ep)&USB_EP_DIR_MASK)
/** Get endpoint address from endpoint index and direction */
#define USB_EP_GET_ADDR(idx, dir) ((idx) | ((dir)&USB_EP_DIR_MASK))
/** True if the endpoint is an IN endpoint */
#define USB_EP_DIR_IS_IN(ep) (USB_EP_GET_DIR(ep) == USB_EP_DIR_IN)
/** True if the endpoint is an OUT endpoint */
#define USB_EP_DIR_IS_OUT(ep) (USB_EP_GET_DIR(ep) == USB_EP_DIR_OUT)
/**
* USB endpoint Transfer Type mask.
*/
@ -27,6 +38,14 @@ extern "C" {
#define USB_CONTROL_OUT_EP0 0
#define USB_CONTROL_IN_EP0 0x80
/**
* @brief USB Device Controller API
* @defgroup _usb_device_controller_api USB Device Controller API
* @{
*/
/**< maximum packet size (MPS) for EP 0 */
#define USB_CTRL_EP_MPS 64
/**
* @brief USB Endpoint Transfer Type
*/
@ -153,7 +172,7 @@ int usbd_ep_write(const uint8_t ep, const uint8_t *data, uint32_t data_len, uint
* This is similar to usb_dc_ep_read, the difference being that, it doesn't
* clear the endpoint NAKs so that the consumer is not bogged down by further
* upcalls till he is done with the processing of the data. The caller should
* reactivate ep by invoking usb_dc_ep_read_continue() do so.
* reactivate ep by setting max_data_len 0 do so.
*
* @param[in] ep Endpoint address corresponding to the one
* listed in the device configuration table

View File

@ -39,8 +39,12 @@
#endif
#define __unused __attribute__((__unused__))
#define __ALIGN_END __attribute__((aligned(4)))
#ifndef __ALIGN_BEGIN
#define __ALIGN_BEGIN
#endif
#ifndef __ALIGN_END
#define __ALIGN_END __attribute__((aligned(4)))
#endif
#ifndef LO_BYTE
#define LO_BYTE(x) ((uint8_t)(x & 0x00FF))
@ -86,10 +90,12 @@
((int)((sizeof(array) / sizeof((array)[0]))))
#endif
#define USB_DESC_SECTION __attribute__((section("usb_desc"))) __used __aligned(1)
#ifndef BSWAP16
#define BSWAP16(u16) (__builtin_bswap16(u16))
#endif
#ifndef BSWAP32
#define BSWAP32(u32) (__builtin_bswap32(u32))
#endif
#define GET_BE16(field) \
(((uint16_t)(field)[0] << 8) | ((uint16_t)(field)[1]))
@ -128,15 +134,17 @@
#define WBVAL(x) (x & 0xFF), ((x >> 8) & 0xFF)
#define DBVAL(x) (x & 0xFF), ((x >> 8) & 0xFF), ((x >> 16) & 0xFF), ((x >> 24) & 0xFF)
#define USB_DESC_SECTION __attribute__((section("usb_desc"))) __used __aligned(1)
#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__)
#else
#define USBD_LOG_WRN(a, ...) bflb_platform_printf(a, ##__VA_ARGS__)
#define USBD_LOG_INFO(a, ...) bflb_platform_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_WRN(a, ...) bflb_platform_printf(a, ##__VA_ARGS__)
#define USBD_LOG_ERR(a, ...) bflb_platform_printf(a, ##__VA_ARGS__)
#endif
#endif

View File

@ -88,13 +88,13 @@ static struct usb_bos_descriptor *bos_desc;
*/
static void usbd_print_setup(struct usb_setup_packet *setup)
{
USBD_LOG_ERR("Setup: "
"bmRequestType 0x%02x, bRequest 0x%02x, wValue 0x%04x, wIndex 0x%04x, wLength 0x%04x\r\n",
setup->bmRequestType,
setup->bRequest,
setup->wValue,
setup->wIndex,
setup->wLength);
USBD_LOG_INFO("Setup: "
"bmRequestType 0x%02x, bRequest 0x%02x, wValue 0x%04x, wIndex 0x%04x, wLength 0x%04x\r\n",
setup->bmRequestType,
setup->bRequest,
setup->wValue,
setup->wIndex,
setup->wLength);
}
/**
@ -202,8 +202,8 @@ static bool usbd_set_endpoint(const struct usb_endpoint_descriptor *ep_desc)
ep_cfg.ep_mps = ep_desc->wMaxPacketSize;
ep_cfg.ep_type = ep_desc->bmAttributes & USBD_EP_TYPE_MASK;
USBD_LOG("Open endpoint:0x%x type:%u mps:%u\r\n",
ep_cfg.ep_addr, ep_cfg.ep_type, ep_cfg.ep_mps);
USBD_LOG_INFO("Open endpoint:0x%x type:%u mps:%u\r\n",
ep_cfg.ep_addr, ep_cfg.ep_type, ep_cfg.ep_mps);
usbd_ep_open(&ep_cfg);
usbd_core_cfg.configured = true;
@ -228,8 +228,8 @@ static bool usbd_reset_endpoint(const struct usb_endpoint_descriptor *ep_desc)
ep_cfg.ep_mps = ep_desc->wMaxPacketSize;
ep_cfg.ep_type = ep_desc->bmAttributes & USBD_EP_TYPE_MASK;
USBD_LOG("Close endpoint:0x%x type:%u\r\n",
ep_cfg.ep_addr, ep_cfg.ep_type);
USBD_LOG_INFO("Close endpoint:0x%x type:%u\r\n",
ep_cfg.ep_addr, ep_cfg.ep_type);
usbd_ep_close(ep_cfg.ep_addr);
@ -261,7 +261,7 @@ static bool usbd_get_descriptor(uint16_t type_index, uint8_t **data, uint32_t *l
index = GET_DESC_INDEX(type_index);
if ((type == USB_DESCRIPTOR_TYPE_STRING) && (index == USB_OSDESC_STRING_DESC_INDEX)) {
USBD_LOG("read MS OS 2.0 descriptor string\r\n");
USBD_LOG_INFO("read MS OS 2.0 descriptor string\r\n");
if (!msosv1_desc) {
return false;
@ -272,7 +272,7 @@ static bool usbd_get_descriptor(uint16_t type_index, uint8_t **data, uint32_t *l
return true;
} else if (type == USB_DESCRIPTOR_TYPE_BINARY_OBJECT_STORE) {
USBD_LOG("read BOS descriptor string\r\n");
USBD_LOG_INFO("read BOS descriptor string\r\n");
if (!bos_desc) {
return false;
@ -781,7 +781,7 @@ static int usbd_standard_request_handler(struct usb_setup_packet *setup, uint8_t
*/
static int usbd_class_request_handler(struct usb_setup_packet *setup, uint8_t **data, uint32_t *len)
{
USBD_LOG_DBG("bRequest 0x%02x, wIndex 0x%04x", setup->bRequest, setup->wIndex);
USBD_LOG_DBG("bRequest 0x%02x, wIndex 0x%04x\r\n", setup->bRequest, setup->wIndex);
if (setup->bmRequestType_b.Recipient != USB_REQUEST_TO_INTERFACE) {
return -1;
@ -806,7 +806,7 @@ static int usbd_class_request_handler(struct usb_setup_packet *setup, uint8_t **
static int usbd_vendor_request_handler(struct usb_setup_packet *setup, uint8_t **data, uint32_t *len)
{
USBD_LOG_DBG("bRequest 0x%02x, wValue0x%04x, wIndex 0x%04x", setup->bRequest, setup->wValue, setup->wIndex);
USBD_LOG_DBG("bRequest 0x%02x, wValue0x%04x, wIndex 0x%04x\r\n", setup->bRequest, setup->wValue, setup->wIndex);
// if(setup->bmRequestType_b.Recipient != USB_REQUEST_TO_DEVICE)
// {
@ -817,19 +817,19 @@ static int usbd_vendor_request_handler(struct usb_setup_packet *setup, uint8_t *
if (setup->bRequest == msosv1_desc->vendor_code) {
switch (setup->wIndex) {
case 0x04:
USBD_LOG("get Compat ID\r\n");
USBD_LOG_INFO("get Compat ID\r\n");
*data = (uint8_t *)msosv1_desc->compat_id;
*len = msosv1_desc->compat_id_len;
return 0;
case 0x05:
USBD_LOG("get Compat id properties\r\n");
USBD_LOG_INFO("get Compat id properties\r\n");
*data = (uint8_t *)msosv1_desc->comp_id_property;
*len = msosv1_desc->comp_id_property_len;
return 0;
default:
USBD_LOG("unknown vendor code\r\n");
USBD_LOG_ERR("unknown vendor code\r\n");
return -1;
}
}
@ -837,12 +837,12 @@ static int usbd_vendor_request_handler(struct usb_setup_packet *setup, uint8_t *
if (setup->bRequest == msosv2_desc->vendor_code) {
switch (setup->wIndex) {
case WINUSB_REQUEST_GET_DESCRIPTOR_SET:
USBD_LOG("GET MS OS 2.0 Descriptor\r\n");
USBD_LOG_INFO("GET MS OS 2.0 Descriptor\r\n");
*data = (uint8_t *)msosv2_desc->compat_id;
*len = msosv2_desc->compat_id_len;
return 0;
default:
USBD_LOG("unknown vendor code\r\n");
USBD_LOG_ERR("unknown vendor code\r\n");
return -1;
}
}
@ -869,7 +869,7 @@ static int usbd_vendor_request_handler(struct usb_setup_packet *setup, uint8_t *
static int usbd_custom_request_handler(struct usb_setup_packet *setup, uint8_t **data, uint32_t *len)
{
USBD_LOG_DBG("bRequest 0x%02x, wIndex 0x%04x", setup->bRequest, setup->wIndex);
USBD_LOG_DBG("bRequest 0x%02x, wIndex 0x%04x\r\n", setup->bRequest, setup->wIndex);
if (setup->bmRequestType_b.Recipient != USB_REQUEST_TO_INTERFACE) {
return -1;
@ -964,15 +964,13 @@ static void usbd_send_to_host(uint16_t len)
* last chunk is wMaxPacketSize long, to indicate the last
* packet.
*/
/* Send less data as requested during the Setup stage */
if ((!usbd_core_cfg.ep0_data_buf_residue) && !(usbd_core_cfg.ep0_data_buf_len % USB_CTRL_EP_MPS)) {
/* Transfers a zero-length packet */
// USBD_LOG("ZLP, requested %u , length %u ",
// len, usb_dev.ep0_data_buf_len);
if ((!usbd_core_cfg.ep0_data_buf_residue) && (usbd_core_cfg.ep0_data_buf_len >= USB_CTRL_EP_MPS) && !(usbd_core_cfg.ep0_data_buf_len % USB_CTRL_EP_MPS)) {
/* Transfers a zero-length packet next*/
usbd_core_cfg.zlp_flag = true;
}
} else {
usbd_core_cfg.zlp_flag = false;
USBD_LOG_DBG("send zlp\r\n");
if (usbd_ep_write(USB_CONTROL_IN_EP0, NULL, 0, NULL) < 0) {
USBD_LOG_ERR("USB write zlp failed\r\n");
return;
@ -1014,8 +1012,6 @@ static void usbd_ep0_setup_handler(void)
if (setup->wLength &&
setup->bmRequestType_b.Dir == USB_REQUEST_HOST_TO_DEVICE) {
USBD_LOG_DBG("prepare to out data\r\n");
/*set ep ack to recv next data*/
usbd_ep_read(USB_CONTROL_OUT_EP0, NULL, 0, NULL);
return;
}
@ -1083,6 +1079,7 @@ static void usbd_ep0_out_handler(void)
USBD_LOG_ERR("ep0_data_buf_residue is not zero\r\n");
}
}
static void usbd_ep0_in_handler(void)
{
struct usb_setup_packet *setup = &usbd_core_cfg.setup;
@ -1090,6 +1087,8 @@ static void usbd_ep0_in_handler(void)
/* Send more data if available */
if (usbd_core_cfg.ep0_data_buf_residue != 0 || usbd_core_cfg.zlp_flag == true) {
usbd_send_to_host(setup->wLength);
} else {
/*ep0 tx has completed,and no data to send,so do nothing*/
}
}
@ -1218,7 +1217,7 @@ void usbd_event_notify_handler(uint8_t event, void *arg)
break;
default:
USBD_LOG_ERR("USB unknown event: %d", event);
USBD_LOG_ERR("USB unknown event: %d\r\n", event);
break;
}
}