add tusb_debug.h remove tusb_error.h
move debug utils to new header
This commit is contained in:
@@ -100,7 +100,7 @@ bool tuh_cdc_send(uint8_t dev_addr, void const * p_data, uint32_t length, bool i
|
|||||||
{
|
{
|
||||||
(void) is_notify;
|
(void) is_notify;
|
||||||
TU_VERIFY( tuh_cdc_mounted(dev_addr) );
|
TU_VERIFY( tuh_cdc_mounted(dev_addr) );
|
||||||
TU_VERIFY( p_data != NULL && length, TUSB_ERROR_INVALID_PARA);
|
TU_VERIFY( p_data != NULL && length);
|
||||||
|
|
||||||
uint8_t const ep_out = cdch_data[dev_addr-1].ep_out;
|
uint8_t const ep_out = cdch_data[dev_addr-1].ep_out;
|
||||||
if ( usbh_edpt_busy(dev_addr, ep_out) ) return false;
|
if ( usbh_edpt_busy(dev_addr, ep_out) ) return false;
|
||||||
@@ -112,7 +112,7 @@ bool tuh_cdc_receive(uint8_t dev_addr, void * p_buffer, uint32_t length, bool is
|
|||||||
{
|
{
|
||||||
(void) is_notify;
|
(void) is_notify;
|
||||||
TU_VERIFY( tuh_cdc_mounted(dev_addr) );
|
TU_VERIFY( tuh_cdc_mounted(dev_addr) );
|
||||||
TU_VERIFY( p_buffer != NULL && length, TUSB_ERROR_INVALID_PARA);
|
TU_VERIFY( p_buffer != NULL && length );
|
||||||
|
|
||||||
uint8_t const ep_in = cdch_data[dev_addr-1].ep_in;
|
uint8_t const ep_in = cdch_data[dev_addr-1].ep_in;
|
||||||
if ( usbh_edpt_busy(dev_addr, ep_in) ) return false;
|
if ( usbh_edpt_busy(dev_addr, ep_in) ) return false;
|
||||||
|
@@ -50,7 +50,7 @@ typedef struct {
|
|||||||
}rndish_data_t;
|
}rndish_data_t;
|
||||||
|
|
||||||
void rndish_init(void);
|
void rndish_init(void);
|
||||||
tusb_error_t rndish_open_subtask(uint8_t dev_addr, cdch_data_t *p_cdc);
|
bool rndish_open_subtask(uint8_t dev_addr, cdch_data_t *p_cdc);
|
||||||
void rndish_xfer_isr(cdch_data_t *p_cdc, pipe_handle_t pipe_hdl, xfer_result_t event, uint32_t xferred_bytes);
|
void rndish_xfer_isr(cdch_data_t *p_cdc, pipe_handle_t pipe_hdl, xfer_result_t event, uint32_t xferred_bytes);
|
||||||
void rndish_close(uint8_t dev_addr);
|
void rndish_close(uint8_t dev_addr);
|
||||||
|
|
||||||
|
6
src/class/vendor/vendor_host.h
vendored
6
src/class/vendor/vendor_host.h
vendored
@@ -49,14 +49,14 @@ static inline bool tusbh_custom_is_mounted(uint8_t dev_addr, uint16_t vendor_id,
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
tusb_error_t tusbh_custom_read(uint8_t dev_addr, uint16_t vendor_id, uint16_t product_id, void * p_buffer, uint16_t length);
|
bool tusbh_custom_read(uint8_t dev_addr, uint16_t vendor_id, uint16_t product_id, void * p_buffer, uint16_t length);
|
||||||
tusb_error_t tusbh_custom_write(uint8_t dev_addr, uint16_t vendor_id, uint16_t product_id, void const * p_data, uint16_t length);
|
bool tusbh_custom_write(uint8_t dev_addr, uint16_t vendor_id, uint16_t product_id, void const * p_data, uint16_t length);
|
||||||
|
|
||||||
//--------------------------------------------------------------------+
|
//--------------------------------------------------------------------+
|
||||||
// Internal Class Driver API
|
// Internal Class Driver API
|
||||||
//--------------------------------------------------------------------+
|
//--------------------------------------------------------------------+
|
||||||
void cush_init(void);
|
void cush_init(void);
|
||||||
tusb_error_t cush_open_subtask(uint8_t dev_addr, tusb_desc_interface_t const *p_interface_desc, uint16_t *p_length);
|
bool cush_open_subtask(uint8_t dev_addr, tusb_desc_interface_t const *p_interface_desc, uint16_t *p_length);
|
||||||
void cush_isr(pipe_handle_t pipe_hdl, xfer_result_t event);
|
void cush_isr(pipe_handle_t pipe_hdl, xfer_result_t event);
|
||||||
void cush_close(uint8_t dev_addr);
|
void cush_close(uint8_t dev_addr);
|
||||||
|
|
||||||
|
@@ -71,8 +71,8 @@
|
|||||||
#include "tusb_compiler.h"
|
#include "tusb_compiler.h"
|
||||||
#include "tusb_verify.h"
|
#include "tusb_verify.h"
|
||||||
#include "tusb_types.h"
|
#include "tusb_types.h"
|
||||||
|
#include "tusb_debug.h"
|
||||||
|
|
||||||
#include "tusb_error.h" // TODO remove
|
|
||||||
#include "tusb_timeout.h" // TODO remove
|
#include "tusb_timeout.h" // TODO remove
|
||||||
|
|
||||||
//--------------------------------------------------------------------+
|
//--------------------------------------------------------------------+
|
||||||
@@ -268,138 +268,6 @@ TU_ATTR_ALWAYS_INLINE static inline void tu_unaligned_write16 (void* mem, ui
|
|||||||
+ TU_BIN8(dlsb))
|
+ TU_BIN8(dlsb))
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
//--------------------------------------------------------------------+
|
|
||||||
// Debug Function
|
|
||||||
//--------------------------------------------------------------------+
|
|
||||||
|
|
||||||
// CFG_TUSB_DEBUG for debugging
|
|
||||||
// 0 : no debug
|
|
||||||
// 1 : print error
|
|
||||||
// 2 : print warning
|
|
||||||
// 3 : print info
|
|
||||||
#if CFG_TUSB_DEBUG
|
|
||||||
|
|
||||||
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
|
|
||||||
#define tu_printf printf
|
|
||||||
#endif
|
|
||||||
|
|
||||||
static inline
|
|
||||||
void tu_print_var(uint8_t const* buf, uint32_t bufsize)
|
|
||||||
{
|
|
||||||
for(uint32_t i=0; i<bufsize; i++) tu_printf("%02X ", buf[i]);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Log with Level
|
|
||||||
#define TU_LOG(n, ...) TU_XSTRCAT(TU_LOG, n)(__VA_ARGS__)
|
|
||||||
#define TU_LOG_MEM(n, ...) TU_XSTRCAT3(TU_LOG, n, _MEM)(__VA_ARGS__)
|
|
||||||
#define TU_LOG_VAR(n, ...) TU_XSTRCAT3(TU_LOG, n, _VAR)(__VA_ARGS__)
|
|
||||||
#define TU_LOG_INT(n, ...) TU_XSTRCAT3(TU_LOG, n, _INT)(__VA_ARGS__)
|
|
||||||
#define TU_LOG_HEX(n, ...) TU_XSTRCAT3(TU_LOG, n, _HEX)(__VA_ARGS__)
|
|
||||||
#define TU_LOG_LOCATION() tu_printf("%s: %d:\r\n", __PRETTY_FUNCTION__, __LINE__)
|
|
||||||
#define TU_LOG_FAILED() tu_printf("%s: %d: Failed\r\n", __PRETTY_FUNCTION__, __LINE__)
|
|
||||||
|
|
||||||
// Log Level 1: Error
|
|
||||||
#define TU_LOG1 tu_printf
|
|
||||||
#define TU_LOG1_MEM tu_print_mem
|
|
||||||
#define TU_LOG1_VAR(_x) tu_print_var((uint8_t const*)(_x), sizeof(*(_x)))
|
|
||||||
#define TU_LOG1_INT(_x) tu_printf(#_x " = %ld\r\n", (unsigned long) (_x) )
|
|
||||||
#define TU_LOG1_HEX(_x) tu_printf(#_x " = %lX\r\n", (unsigned long) (_x) )
|
|
||||||
|
|
||||||
// Log Level 2: Warn
|
|
||||||
#if CFG_TUSB_DEBUG >= 2
|
|
||||||
#define TU_LOG2 TU_LOG1
|
|
||||||
#define TU_LOG2_MEM TU_LOG1_MEM
|
|
||||||
#define TU_LOG2_VAR TU_LOG1_VAR
|
|
||||||
#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_VAR TU_LOG1_VAR
|
|
||||||
#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)
|
|
||||||
{
|
|
||||||
static char not_found[11];
|
|
||||||
|
|
||||||
for(uint16_t i=0; i<p_table->count; i++)
|
|
||||||
{
|
|
||||||
if (p_table->items[i].key == key) return p_table->items[i].data;
|
|
||||||
}
|
|
||||||
|
|
||||||
// not found return the key value in hex
|
|
||||||
snprintf(not_found, sizeof(not_found), "0x%08lX", (unsigned long) key);
|
|
||||||
|
|
||||||
return not_found;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif // CFG_TUSB_DEBUG
|
|
||||||
|
|
||||||
#ifndef TU_LOG
|
|
||||||
#define TU_LOG(n, ...)
|
|
||||||
#define TU_LOG_MEM(n, ...)
|
|
||||||
#define TU_LOG_VAR(n, ...)
|
|
||||||
#define TU_LOG_INT(n, ...)
|
|
||||||
#define TU_LOG_HEX(n, ...)
|
|
||||||
#define TU_LOG_LOCATION()
|
|
||||||
#define TU_LOG_FAILED()
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// TODO replace all TU_LOGn with TU_LOG(n)
|
|
||||||
|
|
||||||
#define TU_LOG0(...)
|
|
||||||
#define TU_LOG0_MEM(...)
|
|
||||||
#define TU_LOG0_VAR(...)
|
|
||||||
#define TU_LOG0_INT(...)
|
|
||||||
#define TU_LOG0_HEX(...)
|
|
||||||
|
|
||||||
|
|
||||||
#ifndef TU_LOG1
|
|
||||||
#define TU_LOG1(...)
|
|
||||||
#define TU_LOG1_MEM(...)
|
|
||||||
#define TU_LOG1_VAR(...)
|
|
||||||
#define TU_LOG1_INT(...)
|
|
||||||
#define TU_LOG1_HEX(...)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef TU_LOG2
|
|
||||||
#define TU_LOG2(...)
|
|
||||||
#define TU_LOG2_MEM(...)
|
|
||||||
#define TU_LOG2_VAR(...)
|
|
||||||
#define TU_LOG2_INT(...)
|
|
||||||
#define TU_LOG2_HEX(...)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef TU_LOG3
|
|
||||||
#define TU_LOG3(...)
|
|
||||||
#define TU_LOG3_MEM(...)
|
|
||||||
#define TU_LOG3_VAR(...)
|
|
||||||
#define TU_LOG3_INT(...)
|
|
||||||
#define TU_LOG3_HEX(...)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
174
src/common/tusb_debug.h
Normal file
174
src/common/tusb_debug.h
Normal file
@@ -0,0 +1,174 @@
|
|||||||
|
/*
|
||||||
|
* The MIT License (MIT)
|
||||||
|
*
|
||||||
|
* Copyright (c) 2022, Ha Thach (tinyusb.org)
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
* THE SOFTWARE.
|
||||||
|
*
|
||||||
|
* 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 >= 2
|
||||||
|
extern char const* const tu_str_speed[];
|
||||||
|
extern char const* const tu_str_std_request[];
|
||||||
|
#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
|
||||||
|
#define tu_printf printf
|
||||||
|
#endif
|
||||||
|
|
||||||
|
static inline void tu_print_var(uint8_t const* buf, uint32_t bufsize)
|
||||||
|
{
|
||||||
|
for(uint32_t i=0; i<bufsize; i++) tu_printf("%02X ", buf[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Log with Level
|
||||||
|
#define TU_LOG(n, ...) TU_XSTRCAT(TU_LOG, n)(__VA_ARGS__)
|
||||||
|
#define TU_LOG_MEM(n, ...) TU_XSTRCAT3(TU_LOG, n, _MEM)(__VA_ARGS__)
|
||||||
|
#define TU_LOG_VAR(n, ...) TU_XSTRCAT3(TU_LOG, n, _VAR)(__VA_ARGS__)
|
||||||
|
#define TU_LOG_INT(n, ...) TU_XSTRCAT3(TU_LOG, n, _INT)(__VA_ARGS__)
|
||||||
|
#define TU_LOG_HEX(n, ...) TU_XSTRCAT3(TU_LOG, n, _HEX)(__VA_ARGS__)
|
||||||
|
#define TU_LOG_LOCATION() tu_printf("%s: %d:\r\n", __PRETTY_FUNCTION__, __LINE__)
|
||||||
|
#define TU_LOG_FAILED() tu_printf("%s: %d: Failed\r\n", __PRETTY_FUNCTION__, __LINE__)
|
||||||
|
|
||||||
|
// Log Level 1: Error
|
||||||
|
#define TU_LOG1 tu_printf
|
||||||
|
#define TU_LOG1_MEM tu_print_mem
|
||||||
|
#define TU_LOG1_VAR(_x) tu_print_var((uint8_t const*)(_x), sizeof(*(_x)))
|
||||||
|
#define TU_LOG1_INT(_x) tu_printf(#_x " = %ld\r\n", (unsigned long) (_x) )
|
||||||
|
#define TU_LOG1_HEX(_x) tu_printf(#_x " = %lX\r\n", (unsigned long) (_x) )
|
||||||
|
|
||||||
|
// Log Level 2: Warn
|
||||||
|
#if CFG_TUSB_DEBUG >= 2
|
||||||
|
#define TU_LOG2 TU_LOG1
|
||||||
|
#define TU_LOG2_MEM TU_LOG1_MEM
|
||||||
|
#define TU_LOG2_VAR TU_LOG1_VAR
|
||||||
|
#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_VAR TU_LOG1_VAR
|
||||||
|
#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)
|
||||||
|
{
|
||||||
|
static char not_found[11];
|
||||||
|
|
||||||
|
for(uint16_t i=0; i<p_table->count; i++)
|
||||||
|
{
|
||||||
|
if (p_table->items[i].key == key) return p_table->items[i].data;
|
||||||
|
}
|
||||||
|
|
||||||
|
// not found return the key value in hex
|
||||||
|
snprintf(not_found, sizeof(not_found), "0x%08lX", (unsigned long) key);
|
||||||
|
|
||||||
|
return not_found;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // CFG_TUSB_DEBUG
|
||||||
|
|
||||||
|
#ifndef TU_LOG
|
||||||
|
#define TU_LOG(n, ...)
|
||||||
|
#define TU_LOG_MEM(n, ...)
|
||||||
|
#define TU_LOG_VAR(n, ...)
|
||||||
|
#define TU_LOG_INT(n, ...)
|
||||||
|
#define TU_LOG_HEX(n, ...)
|
||||||
|
#define TU_LOG_LOCATION()
|
||||||
|
#define TU_LOG_FAILED()
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// TODO replace all TU_LOGn with TU_LOG(n)
|
||||||
|
|
||||||
|
#define TU_LOG0(...)
|
||||||
|
#define TU_LOG0_MEM(...)
|
||||||
|
#define TU_LOG0_VAR(...)
|
||||||
|
#define TU_LOG0_INT(...)
|
||||||
|
#define TU_LOG0_HEX(...)
|
||||||
|
|
||||||
|
#ifndef TU_LOG1
|
||||||
|
#define TU_LOG1(...)
|
||||||
|
#define TU_LOG1_MEM(...)
|
||||||
|
#define TU_LOG1_VAR(...)
|
||||||
|
#define TU_LOG1_INT(...)
|
||||||
|
#define TU_LOG1_HEX(...)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef TU_LOG2
|
||||||
|
#define TU_LOG2(...)
|
||||||
|
#define TU_LOG2_MEM(...)
|
||||||
|
#define TU_LOG2_VAR(...)
|
||||||
|
#define TU_LOG2_INT(...)
|
||||||
|
#define TU_LOG2_HEX(...)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef TU_LOG3
|
||||||
|
#define TU_LOG3(...)
|
||||||
|
#define TU_LOG3_MEM(...)
|
||||||
|
#define TU_LOG3_VAR(...)
|
||||||
|
#define TU_LOG3_INT(...)
|
||||||
|
#define TU_LOG3_HEX(...)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* _TUSB_DEBUG_H_ */
|
@@ -1,77 +0,0 @@
|
|||||||
/*
|
|
||||||
* The MIT License (MIT)
|
|
||||||
*
|
|
||||||
* Copyright (c) 2019 Ha Thach (tinyusb.org)
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
|
||||||
* in the Software without restriction, including without limitation the rights
|
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
|
||||||
* furnished to do so, subject to the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be included in
|
|
||||||
* all copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
||||||
* THE SOFTWARE.
|
|
||||||
*
|
|
||||||
* This file is part of the TinyUSB stack.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/** \ingroup Group_Common
|
|
||||||
* \defgroup Group_Error Error Codes
|
|
||||||
* @{ */
|
|
||||||
|
|
||||||
#ifndef _TUSB_ERRORS_H_
|
|
||||||
#define _TUSB_ERRORS_H_
|
|
||||||
|
|
||||||
#include "tusb_option.h"
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define ERROR_ENUM(x) x,
|
|
||||||
#define ERROR_STRING(x) #x,
|
|
||||||
|
|
||||||
#define ERROR_TABLE(ENTRY) \
|
|
||||||
ENTRY(TUSB_ERROR_NONE )\
|
|
||||||
ENTRY(TUSB_ERROR_INVALID_PARA )\
|
|
||||||
ENTRY(TUSB_ERROR_DEVICE_NOT_READY )\
|
|
||||||
ENTRY(TUSB_ERROR_INTERFACE_IS_BUSY )\
|
|
||||||
ENTRY(TUSB_ERROR_HCD_OPEN_PIPE_FAILED )\
|
|
||||||
ENTRY(TUSB_ERROR_OSAL_TIMEOUT )\
|
|
||||||
ENTRY(TUSB_ERROR_CDCH_DEVICE_NOT_MOUNTED )\
|
|
||||||
ENTRY(TUSB_ERROR_MSCH_DEVICE_NOT_MOUNTED )\
|
|
||||||
ENTRY(TUSB_ERROR_NOT_SUPPORTED )\
|
|
||||||
ENTRY(TUSB_ERROR_NOT_ENOUGH_MEMORY )\
|
|
||||||
ENTRY(TUSB_ERROR_FAILED )\
|
|
||||||
|
|
||||||
/// \brief Error Code returned
|
|
||||||
/// TODO obsolete and to be remove
|
|
||||||
typedef enum
|
|
||||||
{
|
|
||||||
ERROR_TABLE(ERROR_ENUM)
|
|
||||||
TUSB_ERROR_COUNT
|
|
||||||
}tusb_error_t;
|
|
||||||
|
|
||||||
#if CFG_TUSB_DEBUG
|
|
||||||
/// Enum to String for debugging purposes. Only available if \ref CFG_TUSB_DEBUG > 0
|
|
||||||
extern char const* const tusb_strerr[TUSB_ERROR_COUNT];
|
|
||||||
extern char const* const tusb_speed_str[];
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif /* _TUSB_ERRORS_H_ */
|
|
||||||
|
|
||||||
/** @} */
|
|
@@ -74,10 +74,8 @@
|
|||||||
|
|
||||||
#if CFG_TUSB_DEBUG
|
#if CFG_TUSB_DEBUG
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#define _MESS_ERR(_err) tu_printf("%s %d: failed, error = %s\r\n", __func__, __LINE__, tusb_strerr[_err])
|
|
||||||
#define _MESS_FAILED() tu_printf("%s %d: ASSERT FAILED\r\n", __func__, __LINE__)
|
#define _MESS_FAILED() tu_printf("%s %d: ASSERT FAILED\r\n", __func__, __LINE__)
|
||||||
#else
|
#else
|
||||||
#define _MESS_ERR(_err) do {} while (0)
|
|
||||||
#define _MESS_FAILED() do {} while (0)
|
#define _MESS_FAILED() do {} while (0)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -144,32 +142,6 @@
|
|||||||
#define TU_ASSERT(...) GET_3RD_ARG(__VA_ARGS__, ASSERT_2ARGS, ASSERT_1ARGS,UNUSED)(__VA_ARGS__)
|
#define TU_ASSERT(...) GET_3RD_ARG(__VA_ARGS__, ASSERT_2ARGS, ASSERT_1ARGS,UNUSED)(__VA_ARGS__)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// TODO remove TU_ASSERT_ERR() later
|
|
||||||
|
|
||||||
/*------------- Generator for TU_VERIFY_ERR and TU_VERIFY_ERR_HDLR -------------*/
|
|
||||||
#define TU_VERIFY_ERR_DEF2(_error, _handler) do \
|
|
||||||
{ \
|
|
||||||
uint32_t _err = (uint32_t)(_error); \
|
|
||||||
if ( 0 != _err ) { _MESS_ERR(_err); _handler; return _err; } \
|
|
||||||
} while(0)
|
|
||||||
|
|
||||||
#define TU_VERIFY_ERR_DEF3(_error, _handler, _ret) do \
|
|
||||||
{ \
|
|
||||||
uint32_t _err = (uint32_t)(_error); \
|
|
||||||
if ( 0 != _err ) { _MESS_ERR(_err); _handler; return _ret; } \
|
|
||||||
} while(0)
|
|
||||||
|
|
||||||
/*------------------------------------------------------------------*/
|
|
||||||
/* ASSERT Error
|
|
||||||
* basically TU_VERIFY Error with TU_BREAKPOINT() as handler
|
|
||||||
*------------------------------------------------------------------*/
|
|
||||||
#define ASSERT_ERR_1ARGS(_error) TU_VERIFY_ERR_DEF2(_error, TU_BREAKPOINT())
|
|
||||||
#define ASSERT_ERR_2ARGS(_error, _ret) TU_VERIFY_ERR_DEF3(_error, TU_BREAKPOINT(), _ret)
|
|
||||||
|
|
||||||
#ifndef TU_ASSERT_ERR
|
|
||||||
#define TU_ASSERT_ERR(...) GET_3RD_ARG(__VA_ARGS__, ASSERT_ERR_2ARGS, ASSERT_ERR_1ARGS,UNUSED)(__VA_ARGS__)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/*------------------------------------------------------------------*/
|
/*------------------------------------------------------------------*/
|
||||||
/* ASSERT HDLR
|
/* ASSERT HDLR
|
||||||
*------------------------------------------------------------------*/
|
*------------------------------------------------------------------*/
|
||||||
|
@@ -315,23 +315,6 @@ static char const* const _usbd_event_str[DCD_EVENT_COUNT] =
|
|||||||
"Func Call"
|
"Func Call"
|
||||||
};
|
};
|
||||||
|
|
||||||
static char const* const _tusb_std_request_str[] =
|
|
||||||
{
|
|
||||||
"Get Status" ,
|
|
||||||
"Clear Feature" ,
|
|
||||||
"Reserved" ,
|
|
||||||
"Set Feature" ,
|
|
||||||
"Reserved" ,
|
|
||||||
"Set Address" ,
|
|
||||||
"Get Descriptor" ,
|
|
||||||
"Set Descriptor" ,
|
|
||||||
"Get Configuration" ,
|
|
||||||
"Set Configuration" ,
|
|
||||||
"Get Interface" ,
|
|
||||||
"Set Interface" ,
|
|
||||||
"Synch Frame"
|
|
||||||
};
|
|
||||||
|
|
||||||
// for usbd_control to print the name of control complete driver
|
// for usbd_control to print the name of control complete driver
|
||||||
void usbd_driver_print_control_complete_name(usbd_control_xfer_cb_t callback)
|
void usbd_driver_print_control_complete_name(usbd_control_xfer_cb_t callback)
|
||||||
{
|
{
|
||||||
@@ -508,7 +491,7 @@ void tud_task (void)
|
|||||||
switch ( event.event_id )
|
switch ( event.event_id )
|
||||||
{
|
{
|
||||||
case DCD_EVENT_BUS_RESET:
|
case DCD_EVENT_BUS_RESET:
|
||||||
TU_LOG2(": %s Speed\r\n", tusb_speed_str[event.bus_reset.speed]);
|
TU_LOG2(": %s Speed\r\n", tu_str_speed[event.bus_reset.speed]);
|
||||||
usbd_reset(event.rhport);
|
usbd_reset(event.rhport);
|
||||||
_usbd_dev.speed = event.bus_reset.speed;
|
_usbd_dev.speed = event.bus_reset.speed;
|
||||||
break;
|
break;
|
||||||
@@ -650,7 +633,7 @@ static bool process_control_request(uint8_t rhport, tusb_control_request_t const
|
|||||||
#if CFG_TUSB_DEBUG >= 2
|
#if CFG_TUSB_DEBUG >= 2
|
||||||
if (TUSB_REQ_TYPE_STANDARD == p_request->bmRequestType_bit.type && p_request->bRequest <= TUSB_REQ_SYNCH_FRAME)
|
if (TUSB_REQ_TYPE_STANDARD == p_request->bmRequestType_bit.type && p_request->bRequest <= TUSB_REQ_SYNCH_FRAME)
|
||||||
{
|
{
|
||||||
TU_LOG2(" %s", _tusb_std_request_str[p_request->bRequest]);
|
TU_LOG2(" %s", tu_str_std_request[p_request->bRequest]);
|
||||||
if (TUSB_REQ_GET_DESCRIPTOR != p_request->bRequest) TU_LOG2("\r\n");
|
if (TUSB_REQ_GET_DESCRIPTOR != p_request->bRequest) TU_LOG2("\r\n");
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@@ -259,6 +259,7 @@ static void process_device_unplugged(uint8_t rhport, uint8_t hub_addr, uint8_t h
|
|||||||
static bool usbh_edpt_control_open(uint8_t dev_addr, uint8_t max_packet_size);
|
static bool usbh_edpt_control_open(uint8_t dev_addr, uint8_t max_packet_size);
|
||||||
|
|
||||||
// from usbh_control.c
|
// from usbh_control.c
|
||||||
|
extern bool usbh_control_xfer (uint8_t dev_addr, tusb_control_request_t const* request, void* buffer, tuh_control_complete_cb_t complete_cb);
|
||||||
extern bool usbh_control_xfer_cb (uint8_t dev_addr, uint8_t ep_addr, xfer_result_t result, uint32_t xferred_bytes);
|
extern bool usbh_control_xfer_cb (uint8_t dev_addr, uint8_t ep_addr, xfer_result_t result, uint32_t xferred_bytes);
|
||||||
|
|
||||||
//--------------------------------------------------------------------+
|
//--------------------------------------------------------------------+
|
||||||
@@ -297,6 +298,16 @@ void osal_task_delay(uint32_t msec)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
bool tuh_control_xfer (uint8_t dev_addr, tusb_control_request_t const* request, void* buffer, tuh_control_complete_cb_t complete_cb)
|
||||||
|
{
|
||||||
|
TU_LOG2("[%u:%u] %s: ", usbh_get_rhport(dev_addr), dev_addr, request->bRequest <= TUSB_REQ_SYNCH_FRAME ? tu_str_std_request[request->bRequest] : "Unknown Request");
|
||||||
|
TU_LOG2_VAR(request);
|
||||||
|
TU_LOG2("\r\n");
|
||||||
|
|
||||||
|
return usbh_control_xfer(dev_addr, request, buffer, complete_cb);
|
||||||
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------+
|
//--------------------------------------------------------------------+
|
||||||
// Descriptors
|
// Descriptors
|
||||||
//--------------------------------------------------------------------+
|
//--------------------------------------------------------------------+
|
||||||
@@ -864,7 +875,7 @@ static bool enum_new_device(hcd_event_t* event)
|
|||||||
if ( !hcd_port_connect_status(_dev0.rhport) ) return true;
|
if ( !hcd_port_connect_status(_dev0.rhport) ) return true;
|
||||||
|
|
||||||
_dev0.speed = hcd_port_speed_get(_dev0.rhport );
|
_dev0.speed = hcd_port_speed_get(_dev0.rhport );
|
||||||
TU_LOG2("%s Speed\r\n", tusb_speed_str[_dev0.speed]);
|
TU_LOG2("%s Speed\r\n", tu_str_speed[_dev0.speed]);
|
||||||
|
|
||||||
enum_request_addr0_device_desc();
|
enum_request_addr0_device_desc();
|
||||||
}
|
}
|
||||||
|
@@ -33,6 +33,7 @@
|
|||||||
|
|
||||||
enum
|
enum
|
||||||
{
|
{
|
||||||
|
STAGE_IDLE,
|
||||||
STAGE_SETUP,
|
STAGE_SETUP,
|
||||||
STAGE_DATA,
|
STAGE_DATA,
|
||||||
STAGE_ACK
|
STAGE_ACK
|
||||||
@@ -56,7 +57,7 @@ static usbh_control_xfer_t _ctrl_xfer;
|
|||||||
// MACRO TYPEDEF CONSTANT ENUM DECLARATION
|
// MACRO TYPEDEF CONSTANT ENUM DECLARATION
|
||||||
//--------------------------------------------------------------------+
|
//--------------------------------------------------------------------+
|
||||||
|
|
||||||
bool tuh_control_xfer (uint8_t dev_addr, tusb_control_request_t const* request, void* buffer, tuh_control_complete_cb_t complete_cb)
|
bool usbh_control_xfer (uint8_t dev_addr, tusb_control_request_t const* request, void* buffer, tuh_control_complete_cb_t complete_cb)
|
||||||
{
|
{
|
||||||
// TODO need to claim the endpoint first
|
// TODO need to claim the endpoint first
|
||||||
const uint8_t rhport = usbh_get_rhport(dev_addr);
|
const uint8_t rhport = usbh_get_rhport(dev_addr);
|
||||||
@@ -66,10 +67,6 @@ bool tuh_control_xfer (uint8_t dev_addr, tusb_control_request_t const* request,
|
|||||||
_ctrl_xfer.stage = STAGE_SETUP;
|
_ctrl_xfer.stage = STAGE_SETUP;
|
||||||
_ctrl_xfer.complete_cb = complete_cb;
|
_ctrl_xfer.complete_cb = complete_cb;
|
||||||
|
|
||||||
TU_LOG2("Control Setup (addr = %u): ", dev_addr);
|
|
||||||
TU_LOG2_VAR(request);
|
|
||||||
TU_LOG2("\r\n");
|
|
||||||
|
|
||||||
// Send setup packet
|
// Send setup packet
|
||||||
TU_ASSERT( hcd_setup_send(rhport, dev_addr, (uint8_t const*) &_ctrl_xfer.request) );
|
TU_ASSERT( hcd_setup_send(rhport, dev_addr, (uint8_t const*) &_ctrl_xfer.request) );
|
||||||
|
|
||||||
|
22
src/tusb.c
22
src/tusb.c
@@ -161,9 +161,27 @@ uint16_t tu_desc_get_interface_total_len(tusb_desc_interface_t const* desc_itf,
|
|||||||
#if CFG_TUSB_DEBUG
|
#if CFG_TUSB_DEBUG
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
|
|
||||||
char const* const tusb_strerr[TUSB_ERROR_COUNT] = { ERROR_TABLE(ERROR_STRING) };
|
#if CFG_TUSB_DEBUG >= 2
|
||||||
|
|
||||||
char const* const tusb_speed_str[] = { "Full", "Low", "High" };
|
char const* const tu_str_speed[] = { "Full", "Low", "High" };
|
||||||
|
char const* const tu_str_std_request[] =
|
||||||
|
{
|
||||||
|
"Get Status" ,
|
||||||
|
"Clear Feature" ,
|
||||||
|
"Reserved" ,
|
||||||
|
"Set Feature" ,
|
||||||
|
"Reserved" ,
|
||||||
|
"Set Address" ,
|
||||||
|
"Get Descriptor" ,
|
||||||
|
"Set Descriptor" ,
|
||||||
|
"Get Configuration" ,
|
||||||
|
"Set Configuration" ,
|
||||||
|
"Get Interface" ,
|
||||||
|
"Set Interface" ,
|
||||||
|
"Synch Frame"
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
static void dump_str_line(uint8_t const* buf, uint16_t count)
|
static void dump_str_line(uint8_t const* buf, uint16_t count)
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user