diff options
Diffstat (limited to 'cmd/sbc_harness/config/tusb_config.h')
-rw-r--r-- | cmd/sbc_harness/config/tusb_config.h | 43 |
1 files changed, 31 insertions, 12 deletions
diff --git a/cmd/sbc_harness/config/tusb_config.h b/cmd/sbc_harness/config/tusb_config.h index aeff31c..0a6d3e4 100644 --- a/cmd/sbc_harness/config/tusb_config.h +++ b/cmd/sbc_harness/config/tusb_config.h @@ -36,16 +36,35 @@ extern "C" { #endif //-------------------------------------------------------------------- -// TinyUSB Device (TUD) initialization for rp2040-based boards +// Override the default definition of TU_ASSERT() to use our logging //-------------------------------------------------------------------- -// Which USB port to use for the RootHub. -// The rp2040 only has 1 port, so it's gotta be port #0. -#define BOARD_TUD_RHPORT 0 - -// RHPort max operational speed. -// Use OPT_MODE_DEFAULT_SPEED for max speed supported by MCU. -#define BOARD_TUD_MAX_SPEED OPT_MODE_DEFAULT_SPEED +// "magically" select between the 1-arg and 2-args variants, inject a +// stringified version of `_cond`. +// +// Note: Use GNU-C `, ##__VA_ARGS__`, not standard C `__VA_OPT__(,) +// __VA_ARGS__`; because __VA_OPT__ doesn't handle present-but-empty +// arguments the way that we need. +#define TU_ASSERT(_cond, ...) \ + _GET_3RD_ARG(_cond, ##__VA_ARGS__, \ + _LIBMISC_TU_ASSERT_2ARGS, _LIBMISC_TU_ASSERT_1ARGS, _dummy) \ + (_cond, #_cond, ##__VA_ARGS__) + +#define _LIBMISC_TU_ASSERT_1ARGS(_cond, _cond_str) \ + _LIBMISC_TU_ASSERT_2ARGS(_cond, _cond_str, false) + +#define _LIBMISC_TU_ASSERT_2ARGS(_cond, _cond_str, _ret) \ + do { \ + if ( !(_cond) ) { \ + _libmisc_tu_mess_failed(_cond_str, \ + __FILE__, __LINE__, __func__); \ + TU_BREAKPOINT(); \ + return _ret; \ + } \ + } while(0) + +void _libmisc_tu_mess_failed(const char *expr, + const char *file, unsigned int line, const char *func); //-------------------------------------------------------------------- // Configuration: common @@ -66,13 +85,13 @@ extern "C" { // Tinyusb use follows macros to declare transferring memory so that they can be put // into those specific section. // e.g -// - CFG_TUSB_MEM SECTION : __attribute__ (( section(".usb_ram") )) -// - CFG_TUSB_MEM_ALIGN : __attribute__ ((aligned(4))) +// - CFG_TUSB_MEM SECTION : [[gnu::section(".usb_ram")]] +// - CFG_TUSB_MEM_ALIGN : [[gnu::aligned(4)]] #define CFG_TUSB_MEM_SECTION /* blank */ -#define CFG_TUSB_MEM_ALIGN __attribute__ ((aligned(4))) +#define CFG_TUSB_MEM_ALIGN [[gnu::aligned(4)]] #define CFG_TUD_ENABLED 1 -#define CFG_TUD_MAX_SPEED BOARD_TUD_MAX_SPEED +#define CFG_TUD_MAX_SPEED OPT_MODE_DEFAULT_SPEED //-------------------------------------------------------------------- // Configuration: TinyUSB Device (TUD) |