default class driver log level to CFG_TUH/TUD_LOG_LEVEL allow application to selectively disable usbd/usbh or driver log

This commit is contained in:
hathach 2023-08-02 15:34:18 +07:00
parent 2cf869c1a4
commit 979bf32266
No known key found for this signature in database
GPG Key ID: F5D50C6D51D17CBA
11 changed files with 84 additions and 41 deletions

View File

@ -33,6 +33,13 @@
#include "cdc_device.h" #include "cdc_device.h"
// Level where CFG_TUSB_DEBUG must be at least for this driver is logged
#ifndef CFG_TUD_CDC_LOG_LEVEL
#define CFG_TUD_CDC_LOG_LEVEL CFG_TUD_LOG_LEVEL
#endif
#define TU_LOG_DRV(...) TU_LOG(CFG_TUD_CDC_LOG_LEVEL, __VA_ARGS__)
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
// MACRO CONSTANT TYPEDEF // MACRO CONSTANT TYPEDEF
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
@ -353,7 +360,7 @@ bool cdcd_control_xfer_cb(uint8_t rhport, uint8_t stage, tusb_control_request_t
case CDC_REQUEST_SET_LINE_CODING: case CDC_REQUEST_SET_LINE_CODING:
if (stage == CONTROL_STAGE_SETUP) if (stage == CONTROL_STAGE_SETUP)
{ {
TU_LOG2(" Set Line Coding\r\n"); TU_LOG_DRV(" Set Line Coding\r\n");
tud_control_xfer(rhport, request, &p_cdc->line_coding, sizeof(cdc_line_coding_t)); tud_control_xfer(rhport, request, &p_cdc->line_coding, sizeof(cdc_line_coding_t));
} }
else if ( stage == CONTROL_STAGE_ACK) else if ( stage == CONTROL_STAGE_ACK)
@ -365,7 +372,7 @@ bool cdcd_control_xfer_cb(uint8_t rhport, uint8_t stage, tusb_control_request_t
case CDC_REQUEST_GET_LINE_CODING: case CDC_REQUEST_GET_LINE_CODING:
if (stage == CONTROL_STAGE_SETUP) if (stage == CONTROL_STAGE_SETUP)
{ {
TU_LOG2(" Get Line Coding\r\n"); TU_LOG_DRV(" Get Line Coding\r\n");
tud_control_xfer(rhport, request, &p_cdc->line_coding, sizeof(cdc_line_coding_t)); tud_control_xfer(rhport, request, &p_cdc->line_coding, sizeof(cdc_line_coding_t));
} }
break; break;
@ -390,7 +397,7 @@ bool cdcd_control_xfer_cb(uint8_t rhport, uint8_t stage, tusb_control_request_t
// Disable fifo overwriting if DTR bit is set // Disable fifo overwriting if DTR bit is set
tu_fifo_set_overwritable(&p_cdc->tx_ff, !dtr); tu_fifo_set_overwritable(&p_cdc->tx_ff, !dtr);
TU_LOG2(" Set Control Line State: DTR = %d, RTS = %d\r\n", dtr, rts); TU_LOG_DRV(" Set Control Line State: DTR = %d, RTS = %d\r\n", dtr, rts);
// Invoke callback // Invoke callback
if ( tud_cdc_line_state_cb ) tud_cdc_line_state_cb(itf, dtr, rts); if ( tud_cdc_line_state_cb ) tud_cdc_line_state_cb(itf, dtr, rts);
@ -403,7 +410,7 @@ bool cdcd_control_xfer_cb(uint8_t rhport, uint8_t stage, tusb_control_request_t
} }
else if (stage == CONTROL_STAGE_ACK) else if (stage == CONTROL_STAGE_ACK)
{ {
TU_LOG2(" Send Break\r\n"); TU_LOG_DRV(" Send Break\r\n");
if ( tud_cdc_send_break_cb ) tud_cdc_send_break_cb(itf, request->wValue); if ( tud_cdc_send_break_cb ) tud_cdc_send_break_cb(itf, request->wValue);
} }
break; break;

View File

@ -33,9 +33,12 @@
#include "cdc_host.h" #include "cdc_host.h"
// Debug level, TUSB_CFG_DEBUG must be at least this level for debug message // Level where CFG_TUSB_DEBUG must be at least for this driver is logged
#define CDCH_DEBUG 2 #ifndef CFG_TUH_CDC_LOG_LEVEL
#define TU_LOG_DRV(...) TU_LOG(CDCH_DEBUG, __VA_ARGS__) #define CFG_TUH_CDC_LOG_LEVEL CFG_TUH_LOG_LEVEL
#endif
#define TU_LOG_DRV(...) TU_LOG(CFG_TUH_CDC_LOG_LEVEL, __VA_ARGS__)
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
// Host CDC Interface // Host CDC Interface

View File

@ -37,6 +37,13 @@
// MACRO CONSTANT TYPEDEF // MACRO CONSTANT TYPEDEF
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
// Level where CFG_TUSB_DEBUG must be at least for this driver is logged
#ifndef CFG_TUD_DFU_LOG_LEVEL
#define CFG_TUD_DFU_LOG_LEVEL CFG_TUD_LOG_LEVEL
#endif
#define TU_LOG_DRV(...) TU_LOG(CFG_TUD_DFU_LOG_LEVEL, __VA_ARGS__)
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
// INTERNAL OBJECT & FUNCTION DECLARATION // INTERNAL OBJECT & FUNCTION DECLARATION
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
@ -205,7 +212,7 @@ bool dfu_moded_control_xfer_cb(uint8_t rhport, uint8_t stage, tusb_control_reque
{ {
TU_VERIFY(request->bmRequestType_bit.recipient == TUSB_REQ_RCPT_INTERFACE); TU_VERIFY(request->bmRequestType_bit.recipient == TUSB_REQ_RCPT_INTERFACE);
TU_LOG2(" DFU State : %s, Status: %s\r\n", tu_lookup_find(&_dfu_state_table, _dfu_ctx.state), tu_lookup_find(&_dfu_status_table, _dfu_ctx.status)); TU_LOG_DRV(" DFU State : %s, Status: %s\r\n", tu_lookup_find(&_dfu_state_table, _dfu_ctx.state), tu_lookup_find(&_dfu_status_table, _dfu_ctx.status));
if ( request->bmRequestType_bit.type == TUSB_REQ_TYPE_STANDARD ) if ( request->bmRequestType_bit.type == TUSB_REQ_TYPE_STANDARD )
{ {
@ -235,7 +242,7 @@ bool dfu_moded_control_xfer_cb(uint8_t rhport, uint8_t stage, tusb_control_reque
} }
else if ( request->bmRequestType_bit.type == TUSB_REQ_TYPE_CLASS ) else if ( request->bmRequestType_bit.type == TUSB_REQ_TYPE_CLASS )
{ {
TU_LOG2(" DFU Request: %s\r\n", tu_lookup_find(&_dfu_request_table, request->bRequest)); TU_LOG_DRV(" DFU Request: %s\r\n", tu_lookup_find(&_dfu_request_table, request->bRequest));
// Class request // Class request
switch ( request->bRequest ) switch ( request->bRequest )

View File

@ -37,6 +37,13 @@
// MACRO CONSTANT TYPEDEF // MACRO CONSTANT TYPEDEF
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
// Level where CFG_TUSB_DEBUG must be at least for this driver is logged
#ifndef CFG_TUD_DFU_RUNTIME_LOG_LEVEL
#define CFG_TUD_DFU_RUNTIME_LOG_LEVEL CFG_TUD_LOG_LEVEL
#endif
#define TU_LOG_DRV(...) TU_LOG(CFG_TUD_DFU_RUNTIME_LOG_LEVEL, __VA_ARGS__)
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
// INTERNAL OBJECT & FUNCTION DECLARATION // INTERNAL OBJECT & FUNCTION DECLARATION
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
@ -99,7 +106,7 @@ bool dfu_rtd_control_xfer_cb(uint8_t rhport, uint8_t stage, tusb_control_request
{ {
case DFU_REQUEST_DETACH: case DFU_REQUEST_DETACH:
{ {
TU_LOG2(" DFU RT Request: DETACH\r\n"); TU_LOG_DRV(" DFU RT Request: DETACH\r\n");
tud_control_status(rhport, request); tud_control_status(rhport, request);
tud_dfu_runtime_reboot_to_dfu_cb(); tud_dfu_runtime_reboot_to_dfu_cb();
} }
@ -107,7 +114,7 @@ bool dfu_rtd_control_xfer_cb(uint8_t rhport, uint8_t stage, tusb_control_request
case DFU_REQUEST_GETSTATUS: case DFU_REQUEST_GETSTATUS:
{ {
TU_LOG2(" DFU RT Request: GETSTATUS\r\n"); TU_LOG_DRV(" DFU RT Request: GETSTATUS\r\n");
dfu_status_response_t resp; dfu_status_response_t resp;
// Status = OK, Poll timeout is ignored during RT, State = APP_IDLE, IString = 0 // Status = OK, Poll timeout is ignored during RT, State = APP_IDLE, IString = 0
TU_VERIFY(tu_memset_s(&resp, sizeof(resp), 0x00, sizeof(resp))==0); TU_VERIFY(tu_memset_s(&resp, sizeof(resp), 0x00, sizeof(resp))==0);
@ -117,7 +124,7 @@ bool dfu_rtd_control_xfer_cb(uint8_t rhport, uint8_t stage, tusb_control_request
default: default:
{ {
TU_LOG2(" DFU RT Unexpected Request: %d\r\n", request->bRequest); TU_LOG_DRV(" DFU RT Unexpected Request: %d\r\n", request->bRequest);
return false; // stall unsupported request return false; // stall unsupported request
} }
} }

View File

@ -33,10 +33,12 @@
#include "hid_host.h" #include "hid_host.h"
// Debug level, TUSB_CFG_DEBUG must be at least this level for debug message // Level where CFG_TUSB_DEBUG must be at least for this driver is logged
#define HIDH_DEBUG 2 #ifndef CFG_TUH_HID_LOG_LEVEL
#define TU_LOG_DRV(...) TU_LOG(HIDH_DEBUG, __VA_ARGS__) #define CFG_TUH_HID_LOG_LEVEL CFG_TUH_LOG_LEVEL
#endif
#define TU_LOG_DRV(...) TU_LOG(CFG_TUH_HID_LOG_LEVEL, __VA_ARGS__)
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
// MACRO CONSTANT TYPEDEF // MACRO CONSTANT TYPEDEF
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+

View File

@ -36,7 +36,7 @@
// Level where CFG_TUSB_DEBUG must be at least for this driver is logged // Level where CFG_TUSB_DEBUG must be at least for this driver is logged
#ifndef CFG_TUD_MSC_LOG_LEVEL #ifndef CFG_TUD_MSC_LOG_LEVEL
#define CFG_TUD_MSC_LOG_LEVEL 2 #define CFG_TUD_MSC_LOG_LEVEL CFG_TUD_LOG_LEVEL
#endif #endif
#define TU_LOG_DRV(...) TU_LOG(CFG_TUD_MSC_LOG_LEVEL, __VA_ARGS__) #define TU_LOG_DRV(...) TU_LOG(CFG_TUD_MSC_LOG_LEVEL, __VA_ARGS__)

View File

@ -33,9 +33,12 @@
#include "msc_host.h" #include "msc_host.h"
// Debug level, TUSB_CFG_DEBUG must be at least this level for debug message // Level where CFG_TUSB_DEBUG must be at least for this driver is logged
#define MSCH_DEBUG 2 #ifndef CFG_TUH_MSC_LOG_LEVEL
#define TU_LOG_MSCH(...) TU_LOG(MSCH_DEBUG, __VA_ARGS__) #define CFG_TUH_MSC_LOG_LEVEL CFG_TUH_LOG_LEVEL
#endif
#define TU_LOG_DRV(...) TU_LOG(CFG_TUH_MSC_LOG_LEVEL, __VA_ARGS__)
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
// MACRO CONSTANT TYPEDEF // MACRO CONSTANT TYPEDEF
@ -308,7 +311,7 @@ void msch_close(uint8_t dev_addr)
msch_interface_t* p_msc = get_itf(dev_addr); msch_interface_t* p_msc = get_itf(dev_addr);
TU_VERIFY(p_msc->configured, ); TU_VERIFY(p_msc->configured, );
TU_LOG_MSCH(" MSCh close addr = %d\r\n", dev_addr); TU_LOG_DRV(" MSCh close addr = %d\r\n", dev_addr);
// invoke Application Callback // invoke Application Callback
if (p_msc->mounted) { if (p_msc->mounted) {
@ -426,7 +429,7 @@ bool msch_set_config(uint8_t dev_addr, uint8_t itf_num)
p_msc->configured = true; p_msc->configured = true;
//------------- Get Max Lun -------------// //------------- Get Max Lun -------------//
TU_LOG_MSCH("MSC Get Max Lun\r\n"); TU_LOG_DRV("MSC Get Max Lun\r\n");
tusb_control_request_t const request = tusb_control_request_t const request =
{ {
.bmRequestType_bit = .bmRequestType_bit =
@ -465,7 +468,7 @@ static void config_get_maxlun_complete (tuh_xfer_t* xfer)
p_msc->max_lun++; // MAX LUN is minus 1 by specs p_msc->max_lun++; // MAX LUN is minus 1 by specs
// TODO multiple LUN support // TODO multiple LUN support
TU_LOG_MSCH("SCSI Test Unit Ready\r\n"); TU_LOG_DRV("SCSI Test Unit Ready\r\n");
uint8_t const lun = 0; uint8_t const lun = 0;
tuh_msc_test_unit_ready(daddr, lun, config_test_unit_ready_complete, 0); tuh_msc_test_unit_ready(daddr, lun, config_test_unit_ready_complete, 0);
} }
@ -478,14 +481,14 @@ static bool config_test_unit_ready_complete(uint8_t dev_addr, tuh_msc_complete_d
if (csw->status == 0) if (csw->status == 0)
{ {
// Unit is ready, read its capacity // Unit is ready, read its capacity
TU_LOG_MSCH("SCSI Read Capacity\r\n"); TU_LOG_DRV("SCSI Read Capacity\r\n");
tuh_msc_read_capacity(dev_addr, cbw->lun, (scsi_read_capacity10_resp_t*) ((void*) _msch_buffer), config_read_capacity_complete, 0); tuh_msc_read_capacity(dev_addr, cbw->lun, (scsi_read_capacity10_resp_t*) ((void*) _msch_buffer), config_read_capacity_complete, 0);
}else }else
{ {
// Note: During enumeration, some device fails Test Unit Ready and require a few retries // Note: During enumeration, some device fails Test Unit Ready and require a few retries
// with Request Sense to start working !! // with Request Sense to start working !!
// TODO limit number of retries // TODO limit number of retries
TU_LOG_MSCH("SCSI Request Sense\r\n"); TU_LOG_DRV("SCSI Request Sense\r\n");
TU_ASSERT(tuh_msc_request_sense(dev_addr, cbw->lun, _msch_buffer, config_request_sense_complete, 0)); TU_ASSERT(tuh_msc_request_sense(dev_addr, cbw->lun, _msch_buffer, config_request_sense_complete, 0));
} }

View File

@ -34,6 +34,13 @@
#include "device/usbd_pvt.h" #include "device/usbd_pvt.h"
#include "net_device.h" #include "net_device.h"
// Level where CFG_TUSB_DEBUG must be at least for this driver is logged
#ifndef CFG_TUD_NCM_LOG_LEVEL
#define CFG_TUD_NCM_LOG_LEVEL CFG_TUD_LOG_LEVEL
#endif
#define TU_LOG_DRV(...) TU_LOG(CFG_TUD_NCM_LOG_LEVEL, __VA_ARGS__)
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
// MACRO CONSTANT TYPEDEF // MACRO CONSTANT TYPEDEF
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
@ -473,13 +480,13 @@ bool tud_network_can_xmit(uint16_t size)
TU_VERIFY(ncm_interface.itf_data_alt == 1); TU_VERIFY(ncm_interface.itf_data_alt == 1);
if (ncm_interface.datagram_count >= ncm_interface.max_datagrams_per_ntb) { if (ncm_interface.datagram_count >= ncm_interface.max_datagrams_per_ntb) {
TU_LOG2("NTB full [by count]\r\n"); TU_LOG_DRV("NTB full [by count]\r\n");
return false; return false;
} }
size_t next_datagram_offset = ncm_interface.next_datagram_offset; size_t next_datagram_offset = ncm_interface.next_datagram_offset;
if (next_datagram_offset + size > ncm_interface.ntb_in_size) { if (next_datagram_offset + size > ncm_interface.ntb_in_size) {
TU_LOG2("ntb full [by size]\r\n"); TU_LOG_DRV("ntb full [by size]\r\n");
return false; return false;
} }

View File

@ -34,6 +34,13 @@
#include "video_device.h" #include "video_device.h"
// Level where CFG_TUSB_DEBUG must be at least for this driver is logged
#ifndef CFG_TUD_VIDEO_LOG_LEVEL
#define CFG_TUD_VIDEO_LOG_LEVEL CFG_TUD_LOG_LEVEL
#endif
#define TU_LOG_DRV(...) TU_LOG(CFG_TUD_VIDEO_LOG_LEVEL, __VA_ARGS__)
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
// MACRO CONSTANT TYPEDEF // MACRO CONSTANT TYPEDEF
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
@ -609,17 +616,17 @@ static bool _close_vc_itf(uint8_t rhport, videod_interface_t *self)
* @param[in] altnum The target alternate setting number. */ * @param[in] altnum The target alternate setting number. */
static bool _open_vc_itf(uint8_t rhport, videod_interface_t *self, uint_fast8_t altnum) static bool _open_vc_itf(uint8_t rhport, videod_interface_t *self, uint_fast8_t altnum)
{ {
TU_LOG2(" open VC %d\n", altnum); TU_LOG_DRV(" open VC %d\n", altnum);
uint8_t const *beg = self->beg; uint8_t const *beg = self->beg;
uint8_t const *end = beg + self->len; uint8_t const *end = beg + self->len;
/* The first descriptor is a video control interface descriptor. */ /* The first descriptor is a video control interface descriptor. */
uint8_t const *cur = _find_desc_itf(beg, end, _desc_itfnum(beg), altnum); uint8_t const *cur = _find_desc_itf(beg, end, _desc_itfnum(beg), altnum);
TU_LOG2(" cur %d\n", cur - beg); TU_LOG_DRV(" cur %d\n", cur - beg);
TU_VERIFY(cur < end); TU_VERIFY(cur < end);
tusb_desc_vc_itf_t const *vc = (tusb_desc_vc_itf_t const *)cur; tusb_desc_vc_itf_t const *vc = (tusb_desc_vc_itf_t const *)cur;
TU_LOG2(" bInCollection %d\n", vc->ctl.bInCollection); TU_LOG_DRV(" bInCollection %d\n", vc->ctl.bInCollection);
/* Support for up to 2 streaming interfaces only. */ /* Support for up to 2 streaming interfaces only. */
TU_ASSERT(vc->ctl.bInCollection <= CFG_TUD_VIDEO_STREAMING); TU_ASSERT(vc->ctl.bInCollection <= CFG_TUD_VIDEO_STREAMING);
@ -628,7 +635,7 @@ static bool _open_vc_itf(uint8_t rhport, videod_interface_t *self, uint_fast8_t
/* Advance to the next descriptor after the class-specific VC interface header descriptor. */ /* Advance to the next descriptor after the class-specific VC interface header descriptor. */
cur += vc->std.bLength + vc->ctl.bLength; cur += vc->std.bLength + vc->ctl.bLength;
TU_LOG2(" bNumEndpoints %d\n", vc->std.bNumEndpoints); TU_LOG_DRV(" bNumEndpoints %d\n", vc->std.bNumEndpoints);
/* Open the notification endpoint if it exist. */ /* Open the notification endpoint if it exist. */
if (vc->std.bNumEndpoints) { if (vc->std.bNumEndpoints) {
/* Support for 1 endpoint only. */ /* Support for 1 endpoint only. */
@ -662,7 +669,7 @@ static bool _init_vs_configuration(videod_streaming_interface_t *stm)
static bool _open_vs_itf(uint8_t rhport, videod_streaming_interface_t *stm, uint_fast8_t altnum) static bool _open_vs_itf(uint8_t rhport, videod_streaming_interface_t *stm, uint_fast8_t altnum)
{ {
uint_fast8_t i; uint_fast8_t i;
TU_LOG2(" reopen VS %d\n", altnum); TU_LOG_DRV(" reopen VS %d\n", altnum);
uint8_t const *desc = _videod_itf[stm->index_vc].beg; uint8_t const *desc = _videod_itf[stm->index_vc].beg;
/* Close endpoints of previous settings. */ /* Close endpoints of previous settings. */
@ -672,7 +679,7 @@ static bool _open_vs_itf(uint8_t rhport, videod_streaming_interface_t *stm, uint
uint8_t ep_adr = _desc_ep_addr(desc + ofs_ep); uint8_t ep_adr = _desc_ep_addr(desc + ofs_ep);
usbd_edpt_close(rhport, ep_adr); usbd_edpt_close(rhport, ep_adr);
stm->desc.ep[i] = 0; stm->desc.ep[i] = 0;
TU_LOG2(" close EP%02x\n", ep_adr); TU_LOG_DRV(" close EP%02x\n", ep_adr);
} }
/* clear transfer management information */ /* clear transfer management information */
@ -709,12 +716,12 @@ static bool _open_vs_itf(uint8_t rhport, videod_streaming_interface_t *stm, uint
} }
TU_ASSERT(usbd_edpt_open(rhport, ep)); TU_ASSERT(usbd_edpt_open(rhport, ep));
stm->desc.ep[i] = (uint16_t) (cur - desc); stm->desc.ep[i] = (uint16_t) (cur - desc);
TU_LOG2(" open EP%02x\n", _desc_ep_addr(cur)); TU_LOG_DRV(" open EP%02x\n", _desc_ep_addr(cur));
} }
if (altnum) { if (altnum) {
stm->state = VS_STATE_STREAMING; stm->state = VS_STATE_STREAMING;
} }
TU_LOG2(" done\n"); TU_LOG_DRV(" done\n");
return true; return true;
} }

View File

@ -45,13 +45,6 @@
#define CFG_TUH_INTERFACE_MAX 8 #define CFG_TUH_INTERFACE_MAX 8
#endif #endif
// Level where CFG_TUSB_DEBUG must be at least for USBH is logged
#ifndef CFG_TUH_LOG_LEVEL
#define CFG_TUH_LOG_LEVEL 2
#endif
#define TU_LOG_USBH(...) TU_LOG(CFG_TUH_LOG_LEVEL, __VA_ARGS__)
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
// USBH-HCD common data structure // USBH-HCD common data structure
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+

View File

@ -35,6 +35,13 @@
extern "C" { extern "C" {
#endif #endif
// Level where CFG_TUSB_DEBUG must be at least for USBH is logged
#ifndef CFG_TUH_LOG_LEVEL
#define CFG_TUH_LOG_LEVEL 2
#endif
#define TU_LOG_USBH(...) TU_LOG(CFG_TUH_LOG_LEVEL, __VA_ARGS__)
enum { enum {
USBH_EPSIZE_BULK_MAX = (TUH_OPT_HIGH_SPEED ? TUSB_EPSIZE_BULK_HS : TUSB_EPSIZE_BULK_FS) USBH_EPSIZE_BULK_MAX = (TUH_OPT_HIGH_SPEED ? TUSB_EPSIZE_BULK_HS : TUSB_EPSIZE_BULK_FS)
}; };