Skip to content

Commit 5cf9423

Browse files
authored
Merge pull request hathach#2200 from hathach/selective-log
default class driver log level to CFG_TUH/TUD_LOG_LEVEL
2 parents 2cf869c + 868d52f commit 5cf9423

File tree

14 files changed

+86
-43
lines changed

14 files changed

+86
-43
lines changed

.codespellrc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
[codespell]
33
# In the event of a false positive, add the problematic word, in all lowercase, to 'ignore-words.txt' (one word per line).
44
# Or copy & paste the whole problematic line to 'exclude-file.txt'
5-
ignore-words = .codespell/ignore-words.txt
6-
exclude-file = .codespell/exclude-file.txt
5+
ignore-words = tools/codespell/ignore-words.txt
6+
exclude-file = tools/codespell/exclude-file.txt
77
check-filenames =
88
check-hidden =
99
count =

src/class/cdc/cdc_device.c

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,13 @@
3333

3434
#include "cdc_device.h"
3535

36+
// Level where CFG_TUSB_DEBUG must be at least for this driver is logged
37+
#ifndef CFG_TUD_CDC_LOG_LEVEL
38+
#define CFG_TUD_CDC_LOG_LEVEL CFG_TUD_LOG_LEVEL
39+
#endif
40+
41+
#define TU_LOG_DRV(...) TU_LOG(CFG_TUD_CDC_LOG_LEVEL, __VA_ARGS__)
42+
3643
//--------------------------------------------------------------------+
3744
// MACRO CONSTANT TYPEDEF
3845
//--------------------------------------------------------------------+
@@ -353,7 +360,7 @@ bool cdcd_control_xfer_cb(uint8_t rhport, uint8_t stage, tusb_control_request_t
353360
case CDC_REQUEST_SET_LINE_CODING:
354361
if (stage == CONTROL_STAGE_SETUP)
355362
{
356-
TU_LOG2(" Set Line Coding\r\n");
363+
TU_LOG_DRV(" Set Line Coding\r\n");
357364
tud_control_xfer(rhport, request, &p_cdc->line_coding, sizeof(cdc_line_coding_t));
358365
}
359366
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
365372
case CDC_REQUEST_GET_LINE_CODING:
366373
if (stage == CONTROL_STAGE_SETUP)
367374
{
368-
TU_LOG2(" Get Line Coding\r\n");
375+
TU_LOG_DRV(" Get Line Coding\r\n");
369376
tud_control_xfer(rhport, request, &p_cdc->line_coding, sizeof(cdc_line_coding_t));
370377
}
371378
break;
@@ -390,7 +397,7 @@ bool cdcd_control_xfer_cb(uint8_t rhport, uint8_t stage, tusb_control_request_t
390397
// Disable fifo overwriting if DTR bit is set
391398
tu_fifo_set_overwritable(&p_cdc->tx_ff, !dtr);
392399

393-
TU_LOG2(" Set Control Line State: DTR = %d, RTS = %d\r\n", dtr, rts);
400+
TU_LOG_DRV(" Set Control Line State: DTR = %d, RTS = %d\r\n", dtr, rts);
394401

395402
// Invoke callback
396403
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
403410
}
404411
else if (stage == CONTROL_STAGE_ACK)
405412
{
406-
TU_LOG2(" Send Break\r\n");
413+
TU_LOG_DRV(" Send Break\r\n");
407414
if ( tud_cdc_send_break_cb ) tud_cdc_send_break_cb(itf, request->wValue);
408415
}
409416
break;

src/class/cdc/cdc_host.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,12 @@
3333

3434
#include "cdc_host.h"
3535

36-
// Debug level, TUSB_CFG_DEBUG must be at least this level for debug message
37-
#define CDCH_DEBUG 2
38-
#define TU_LOG_DRV(...) TU_LOG(CDCH_DEBUG, __VA_ARGS__)
36+
// Level where CFG_TUSB_DEBUG must be at least for this driver is logged
37+
#ifndef CFG_TUH_CDC_LOG_LEVEL
38+
#define CFG_TUH_CDC_LOG_LEVEL CFG_TUH_LOG_LEVEL
39+
#endif
40+
41+
#define TU_LOG_DRV(...) TU_LOG(CFG_TUH_CDC_LOG_LEVEL, __VA_ARGS__)
3942

4043
//--------------------------------------------------------------------+
4144
// Host CDC Interface

src/class/dfu/dfu_device.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,13 @@
3737
// MACRO CONSTANT TYPEDEF
3838
//--------------------------------------------------------------------+
3939

40+
// Level where CFG_TUSB_DEBUG must be at least for this driver is logged
41+
#ifndef CFG_TUD_DFU_LOG_LEVEL
42+
#define CFG_TUD_DFU_LOG_LEVEL CFG_TUD_LOG_LEVEL
43+
#endif
44+
45+
#define TU_LOG_DRV(...) TU_LOG(CFG_TUD_DFU_LOG_LEVEL, __VA_ARGS__)
46+
4047
//--------------------------------------------------------------------+
4148
// INTERNAL OBJECT & FUNCTION DECLARATION
4249
//--------------------------------------------------------------------+
@@ -205,7 +212,7 @@ bool dfu_moded_control_xfer_cb(uint8_t rhport, uint8_t stage, tusb_control_reque
205212
{
206213
TU_VERIFY(request->bmRequestType_bit.recipient == TUSB_REQ_RCPT_INTERFACE);
207214

208-
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));
215+
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));
209216

210217
if ( request->bmRequestType_bit.type == TUSB_REQ_TYPE_STANDARD )
211218
{
@@ -235,7 +242,7 @@ bool dfu_moded_control_xfer_cb(uint8_t rhport, uint8_t stage, tusb_control_reque
235242
}
236243
else if ( request->bmRequestType_bit.type == TUSB_REQ_TYPE_CLASS )
237244
{
238-
TU_LOG2(" DFU Request: %s\r\n", tu_lookup_find(&_dfu_request_table, request->bRequest));
245+
TU_LOG_DRV(" DFU Request: %s\r\n", tu_lookup_find(&_dfu_request_table, request->bRequest));
239246

240247
// Class request
241248
switch ( request->bRequest )

src/class/dfu/dfu_rt_device.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,13 @@
3737
// MACRO CONSTANT TYPEDEF
3838
//--------------------------------------------------------------------+
3939

40+
// Level where CFG_TUSB_DEBUG must be at least for this driver is logged
41+
#ifndef CFG_TUD_DFU_RUNTIME_LOG_LEVEL
42+
#define CFG_TUD_DFU_RUNTIME_LOG_LEVEL CFG_TUD_LOG_LEVEL
43+
#endif
44+
45+
#define TU_LOG_DRV(...) TU_LOG(CFG_TUD_DFU_RUNTIME_LOG_LEVEL, __VA_ARGS__)
46+
4047
//--------------------------------------------------------------------+
4148
// INTERNAL OBJECT & FUNCTION DECLARATION
4249
//--------------------------------------------------------------------+
@@ -99,15 +106,15 @@ bool dfu_rtd_control_xfer_cb(uint8_t rhport, uint8_t stage, tusb_control_request
99106
{
100107
case DFU_REQUEST_DETACH:
101108
{
102-
TU_LOG2(" DFU RT Request: DETACH\r\n");
109+
TU_LOG_DRV(" DFU RT Request: DETACH\r\n");
103110
tud_control_status(rhport, request);
104111
tud_dfu_runtime_reboot_to_dfu_cb();
105112
}
106113
break;
107114

108115
case DFU_REQUEST_GETSTATUS:
109116
{
110-
TU_LOG2(" DFU RT Request: GETSTATUS\r\n");
117+
TU_LOG_DRV(" DFU RT Request: GETSTATUS\r\n");
111118
dfu_status_response_t resp;
112119
// Status = OK, Poll timeout is ignored during RT, State = APP_IDLE, IString = 0
113120
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
117124

118125
default:
119126
{
120-
TU_LOG2(" DFU RT Unexpected Request: %d\r\n", request->bRequest);
127+
TU_LOG_DRV(" DFU RT Unexpected Request: %d\r\n", request->bRequest);
121128
return false; // stall unsupported request
122129
}
123130
}

src/class/hid/hid_host.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,12 @@
3333

3434
#include "hid_host.h"
3535

36-
// Debug level, TUSB_CFG_DEBUG must be at least this level for debug message
37-
#define HIDH_DEBUG 2
38-
#define TU_LOG_DRV(...) TU_LOG(HIDH_DEBUG, __VA_ARGS__)
36+
// Level where CFG_TUSB_DEBUG must be at least for this driver is logged
37+
#ifndef CFG_TUH_HID_LOG_LEVEL
38+
#define CFG_TUH_HID_LOG_LEVEL CFG_TUH_LOG_LEVEL
39+
#endif
3940

41+
#define TU_LOG_DRV(...) TU_LOG(CFG_TUH_HID_LOG_LEVEL, __VA_ARGS__)
4042
//--------------------------------------------------------------------+
4143
// MACRO CONSTANT TYPEDEF
4244
//--------------------------------------------------------------------+

src/class/msc/msc_device.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636

3737
// Level where CFG_TUSB_DEBUG must be at least for this driver is logged
3838
#ifndef CFG_TUD_MSC_LOG_LEVEL
39-
#define CFG_TUD_MSC_LOG_LEVEL 2
39+
#define CFG_TUD_MSC_LOG_LEVEL CFG_TUD_LOG_LEVEL
4040
#endif
4141

4242
#define TU_LOG_DRV(...) TU_LOG(CFG_TUD_MSC_LOG_LEVEL, __VA_ARGS__)

src/class/msc/msc_host.c

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,12 @@
3333

3434
#include "msc_host.h"
3535

36-
// Debug level, TUSB_CFG_DEBUG must be at least this level for debug message
37-
#define MSCH_DEBUG 2
38-
#define TU_LOG_MSCH(...) TU_LOG(MSCH_DEBUG, __VA_ARGS__)
36+
// Level where CFG_TUSB_DEBUG must be at least for this driver is logged
37+
#ifndef CFG_TUH_MSC_LOG_LEVEL
38+
#define CFG_TUH_MSC_LOG_LEVEL CFG_TUH_LOG_LEVEL
39+
#endif
40+
41+
#define TU_LOG_DRV(...) TU_LOG(CFG_TUH_MSC_LOG_LEVEL, __VA_ARGS__)
3942

4043
//--------------------------------------------------------------------+
4144
// MACRO CONSTANT TYPEDEF
@@ -308,7 +311,7 @@ void msch_close(uint8_t dev_addr)
308311
msch_interface_t* p_msc = get_itf(dev_addr);
309312
TU_VERIFY(p_msc->configured, );
310313

311-
TU_LOG_MSCH(" MSCh close addr = %d\r\n", dev_addr);
314+
TU_LOG_DRV(" MSCh close addr = %d\r\n", dev_addr);
312315

313316
// invoke Application Callback
314317
if (p_msc->mounted) {
@@ -426,7 +429,7 @@ bool msch_set_config(uint8_t dev_addr, uint8_t itf_num)
426429
p_msc->configured = true;
427430

428431
//------------- Get Max Lun -------------//
429-
TU_LOG_MSCH("MSC Get Max Lun\r\n");
432+
TU_LOG_DRV("MSC Get Max Lun\r\n");
430433
tusb_control_request_t const request =
431434
{
432435
.bmRequestType_bit =
@@ -465,7 +468,7 @@ static void config_get_maxlun_complete (tuh_xfer_t* xfer)
465468
p_msc->max_lun++; // MAX LUN is minus 1 by specs
466469

467470
// TODO multiple LUN support
468-
TU_LOG_MSCH("SCSI Test Unit Ready\r\n");
471+
TU_LOG_DRV("SCSI Test Unit Ready\r\n");
469472
uint8_t const lun = 0;
470473
tuh_msc_test_unit_ready(daddr, lun, config_test_unit_ready_complete, 0);
471474
}
@@ -478,14 +481,14 @@ static bool config_test_unit_ready_complete(uint8_t dev_addr, tuh_msc_complete_d
478481
if (csw->status == 0)
479482
{
480483
// Unit is ready, read its capacity
481-
TU_LOG_MSCH("SCSI Read Capacity\r\n");
484+
TU_LOG_DRV("SCSI Read Capacity\r\n");
482485
tuh_msc_read_capacity(dev_addr, cbw->lun, (scsi_read_capacity10_resp_t*) ((void*) _msch_buffer), config_read_capacity_complete, 0);
483486
}else
484487
{
485488
// Note: During enumeration, some device fails Test Unit Ready and require a few retries
486489
// with Request Sense to start working !!
487490
// TODO limit number of retries
488-
TU_LOG_MSCH("SCSI Request Sense\r\n");
491+
TU_LOG_DRV("SCSI Request Sense\r\n");
489492
TU_ASSERT(tuh_msc_request_sense(dev_addr, cbw->lun, _msch_buffer, config_request_sense_complete, 0));
490493
}
491494

src/class/net/ncm_device.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,13 @@
3434
#include "device/usbd_pvt.h"
3535
#include "net_device.h"
3636

37+
// Level where CFG_TUSB_DEBUG must be at least for this driver is logged
38+
#ifndef CFG_TUD_NCM_LOG_LEVEL
39+
#define CFG_TUD_NCM_LOG_LEVEL CFG_TUD_LOG_LEVEL
40+
#endif
41+
42+
#define TU_LOG_DRV(...) TU_LOG(CFG_TUD_NCM_LOG_LEVEL, __VA_ARGS__)
43+
3744
//--------------------------------------------------------------------+
3845
// MACRO CONSTANT TYPEDEF
3946
//--------------------------------------------------------------------+
@@ -473,13 +480,13 @@ bool tud_network_can_xmit(uint16_t size)
473480
TU_VERIFY(ncm_interface.itf_data_alt == 1);
474481

475482
if (ncm_interface.datagram_count >= ncm_interface.max_datagrams_per_ntb) {
476-
TU_LOG2("NTB full [by count]\r\n");
483+
TU_LOG_DRV("NTB full [by count]\r\n");
477484
return false;
478485
}
479486

480487
size_t next_datagram_offset = ncm_interface.next_datagram_offset;
481488
if (next_datagram_offset + size > ncm_interface.ntb_in_size) {
482-
TU_LOG2("ntb full [by size]\r\n");
489+
TU_LOG_DRV("ntb full [by size]\r\n");
483490
return false;
484491
}
485492

src/class/video/video_device.c

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,13 @@
3434

3535
#include "video_device.h"
3636

37+
// Level where CFG_TUSB_DEBUG must be at least for this driver is logged
38+
#ifndef CFG_TUD_VIDEO_LOG_LEVEL
39+
#define CFG_TUD_VIDEO_LOG_LEVEL CFG_TUD_LOG_LEVEL
40+
#endif
41+
42+
#define TU_LOG_DRV(...) TU_LOG(CFG_TUD_VIDEO_LOG_LEVEL, __VA_ARGS__)
43+
3744
//--------------------------------------------------------------------+
3845
// MACRO CONSTANT TYPEDEF
3946
//--------------------------------------------------------------------+
@@ -609,17 +616,17 @@ static bool _close_vc_itf(uint8_t rhport, videod_interface_t *self)
609616
* @param[in] altnum The target alternate setting number. */
610617
static bool _open_vc_itf(uint8_t rhport, videod_interface_t *self, uint_fast8_t altnum)
611618
{
612-
TU_LOG2(" open VC %d\n", altnum);
619+
TU_LOG_DRV(" open VC %d\n", altnum);
613620
uint8_t const *beg = self->beg;
614621
uint8_t const *end = beg + self->len;
615622

616623
/* The first descriptor is a video control interface descriptor. */
617624
uint8_t const *cur = _find_desc_itf(beg, end, _desc_itfnum(beg), altnum);
618-
TU_LOG2(" cur %d\n", cur - beg);
625+
TU_LOG_DRV(" cur %d\n", cur - beg);
619626
TU_VERIFY(cur < end);
620627

621628
tusb_desc_vc_itf_t const *vc = (tusb_desc_vc_itf_t const *)cur;
622-
TU_LOG2(" bInCollection %d\n", vc->ctl.bInCollection);
629+
TU_LOG_DRV(" bInCollection %d\n", vc->ctl.bInCollection);
623630
/* Support for up to 2 streaming interfaces only. */
624631
TU_ASSERT(vc->ctl.bInCollection <= CFG_TUD_VIDEO_STREAMING);
625632

@@ -628,7 +635,7 @@ static bool _open_vc_itf(uint8_t rhport, videod_interface_t *self, uint_fast8_t
628635

629636
/* Advance to the next descriptor after the class-specific VC interface header descriptor. */
630637
cur += vc->std.bLength + vc->ctl.bLength;
631-
TU_LOG2(" bNumEndpoints %d\n", vc->std.bNumEndpoints);
638+
TU_LOG_DRV(" bNumEndpoints %d\n", vc->std.bNumEndpoints);
632639
/* Open the notification endpoint if it exist. */
633640
if (vc->std.bNumEndpoints) {
634641
/* Support for 1 endpoint only. */
@@ -662,7 +669,7 @@ static bool _init_vs_configuration(videod_streaming_interface_t *stm)
662669
static bool _open_vs_itf(uint8_t rhport, videod_streaming_interface_t *stm, uint_fast8_t altnum)
663670
{
664671
uint_fast8_t i;
665-
TU_LOG2(" reopen VS %d\n", altnum);
672+
TU_LOG_DRV(" reopen VS %d\n", altnum);
666673
uint8_t const *desc = _videod_itf[stm->index_vc].beg;
667674

668675
/* Close endpoints of previous settings. */
@@ -672,7 +679,7 @@ static bool _open_vs_itf(uint8_t rhport, videod_streaming_interface_t *stm, uint
672679
uint8_t ep_adr = _desc_ep_addr(desc + ofs_ep);
673680
usbd_edpt_close(rhport, ep_adr);
674681
stm->desc.ep[i] = 0;
675-
TU_LOG2(" close EP%02x\n", ep_adr);
682+
TU_LOG_DRV(" close EP%02x\n", ep_adr);
676683
}
677684

678685
/* clear transfer management information */
@@ -709,12 +716,12 @@ static bool _open_vs_itf(uint8_t rhport, videod_streaming_interface_t *stm, uint
709716
}
710717
TU_ASSERT(usbd_edpt_open(rhport, ep));
711718
stm->desc.ep[i] = (uint16_t) (cur - desc);
712-
TU_LOG2(" open EP%02x\n", _desc_ep_addr(cur));
719+
TU_LOG_DRV(" open EP%02x\n", _desc_ep_addr(cur));
713720
}
714721
if (altnum) {
715722
stm->state = VS_STATE_STREAMING;
716723
}
717-
TU_LOG2(" done\n");
724+
TU_LOG_DRV(" done\n");
718725
return true;
719726
}
720727

0 commit comments

Comments
 (0)