/* * SPDX-FileCopyrightText: Copyright (c) 2022, Ha Thach (tinyusb.org) * SPDX-License-Identifier: MIT * * This file is part of the TinyUSB stack. */ #ifndef TUSB_DEBUG_H_ #define TUSB_DEBUG_H_ #ifdef __cplusplus extern "C" { #endif //--------------------------------------------------------------------+ // Debug //--------------------------------------------------------------------+ // CFG_TUSB_DEBUG for debugging // 0 : no debug // 1 : print error // 2 : print warning // 3 : print info #if CFG_TUSB_DEBUG // Enum to String for debugging purposes #if CFG_TUSB_DEBUG >= CFG_TUH_LOG_LEVEL || CFG_TUSB_DEBUG >= CFG_TUD_LOG_LEVEL extern char const* const tu_str_speed[]; extern char const* const tu_str_std_request[]; extern char const* const tu_str_xfer_result[]; #endif void tu_print_mem(void const *buf, uint32_t count, uint8_t indent); #ifdef CFG_TUSB_DEBUG_PRINTF extern int CFG_TUSB_DEBUG_PRINTF(const char *format, ...); #define tu_printf CFG_TUSB_DEBUG_PRINTF #else #include #define tu_printf(...) (void) printf(__VA_ARGS__) #endif TU_ATTR_ALWAYS_INLINE static inline void tu_print_buf(uint8_t const* buf, uint32_t bufsize) { for(uint32_t i=0; i= 2 #define TU_LOG2 TU_LOG1 #define TU_LOG2_MEM TU_LOG1_MEM #define TU_LOG2_BUF TU_LOG1_BUF #define TU_LOG2_INT TU_LOG1_INT #define TU_LOG2_HEX TU_LOG1_HEX #endif // Log Level 3: Info #if CFG_TUSB_DEBUG >= 3 #define TU_LOG3 TU_LOG1 #define TU_LOG3_MEM TU_LOG1_MEM #define TU_LOG3_BUF TU_LOG1_BUF #define TU_LOG3_INT TU_LOG1_INT #define TU_LOG3_HEX TU_LOG1_HEX #endif typedef struct { uint32_t key; const char* data; } tu_lookup_entry_t; typedef struct { uint16_t count; tu_lookup_entry_t const* items; } tu_lookup_table_t; static inline const char* tu_lookup_find(tu_lookup_table_t const* p_table, uint32_t key) { for(uint16_t i=0; icount; i++) { if (p_table->items[i].key == key) { return p_table->items[i].data; } } #ifndef CFG_TUSB_DEBUG_PRINTF // not found return the key value in hex if no custom printf is defined static char not_found[11]; if (snprintf(not_found, sizeof(not_found), "0x%08lX", (unsigned long)key) <= 0) { not_found[0] = 0; } return not_found; #else return "NotFound"; #endif } #endif // CFG_TUSB_DEBUG #ifndef TU_LOG #define TU_LOG(n, ...) #define TU_LOG_MEM(n, ...) #define TU_LOG_BUF(n, ...) #define TU_LOG_INT(n, ...) #define TU_LOG_HEX(n, ...) #define TU_LOG_LOCATION() #define TU_LOG_FAILED() #endif #define TU_LOG0(...) #define TU_LOG0_MEM(...) #define TU_LOG0_BUF(...) #define TU_LOG0_INT(...) #define TU_LOG0_HEX(...) #ifndef TU_LOG1 #define TU_LOG1(...) #define TU_LOG1_MEM(...) #define TU_LOG1_BUF(...) #define TU_LOG1_INT(...) #define TU_LOG1_HEX(...) #endif #ifndef TU_LOG2 #define TU_LOG2(...) #define TU_LOG2_MEM(...) #define TU_LOG2_BUF(...) #define TU_LOG2_INT(...) #define TU_LOG2_HEX(...) #endif #ifndef TU_LOG3 #define TU_LOG3(...) #define TU_LOG3_MEM(...) #define TU_LOG3_BUF(...) #define TU_LOG3_INT(...) #define TU_LOG3_HEX(...) #endif #ifdef __cplusplus } #endif #endif