From 1786aea78e0f7b6949a5a73e5a82623dde76579f Mon Sep 17 00:00:00 2001 From: Martin Brodbeck Date: Mon, 19 Feb 2024 13:34:38 +0100 Subject: [PATCH] first steps with tinyusb --- CMakeLists.txt | 8 ++++- src/tusb_config.h | 86 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 93 insertions(+), 1 deletion(-) create mode 100644 src/tusb_config.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 430e256..4d6c72d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -32,7 +32,7 @@ pico_set_program_name(raspi_keyer "raspi_keyer") pico_set_program_version(raspi_keyer "0.0.1") pico_enable_stdio_uart(raspi_keyer 1) -pico_enable_stdio_usb(raspi_keyer 1) +pico_enable_stdio_usb(raspi_keyer 0) target_compile_options(raspi_keyer PRIVATE -Wall -Wextra -Werror) @@ -46,6 +46,11 @@ target_include_directories(raspi_keyer PRIVATE ${CMAKE_CURRENT_LIST_DIR}/.. # for our common lwipopts or any other standard includes, if required ) +# Make sure TinyUSB can find tusb_config.h +target_include_directories(raspi_keyer PUBLIC + ${CMAKE_CURRENT_LIST_DIR}/src +) + # Add any user requested libraries target_link_libraries(raspi_keyer hardware_flash @@ -53,6 +58,7 @@ target_link_libraries(raspi_keyer hardware_pwm pico_flash pico_multicore + tinyusb_device ) pico_add_extra_outputs(raspi_keyer) diff --git a/src/tusb_config.h b/src/tusb_config.h new file mode 100644 index 0000000..f5986a9 --- /dev/null +++ b/src/tusb_config.h @@ -0,0 +1,86 @@ +#ifndef TUSB_CONFIG +#define TUSB_CONFIG + +#ifdef __cplusplus +extern "C" { +#endif + +//--------------------------------------------------------------------+ +// Board Specific Configuration +//--------------------------------------------------------------------+ + +// RHPort number used for device can be defined by board.mk, default to port 0 +#ifndef BOARD_TUD_RHPORT +#define BOARD_TUD_RHPORT 0 +#endif + +// RHPort max operational speed can defined by board.mk +#ifndef BOARD_TUD_MAX_SPEED +#define BOARD_TUD_MAX_SPEED OPT_MODE_DEFAULT_SPEED +#endif + +//-------------------------------------------------------------------- +// COMMON CONFIGURATION +//-------------------------------------------------------------------- + +// defined by board.mk +#ifndef CFG_TUSB_MCU +#error CFG_TUSB_MCU must be defined +#endif + +#ifndef CFG_TUSB_OS +#define CFG_TUSB_OS OPT_OS_NONE +#endif + +#ifndef CFG_TUSB_DEBUG +#define CFG_TUSB_DEBUG 0 +#endif + +// Enable Device stack +#define CFG_TUD_ENABLED 1 + +// Default is max speed that hardware controller could support with on-chip PHY +#define CFG_TUD_MAX_SPEED BOARD_TUD_MAX_SPEED + +/* USB DMA on some MCUs can only access a specific SRAM region with restriction on alignment. + * 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))) + */ +#ifndef CFG_TUSB_MEM_SECTION +#define CFG_TUSB_MEM_SECTION +#endif + +#ifndef CFG_TUSB_MEM_ALIGN +#define CFG_TUSB_MEM_ALIGN __attribute__((aligned(4))) +#endif + +//-------------------------------------------------------------------- +// DEVICE CONFIGURATION +//-------------------------------------------------------------------- + +#ifndef CFG_TUD_ENDPOINT0_SIZE +#define CFG_TUD_ENDPOINT0_SIZE 64 +#endif + +//------------- CLASS -------------// +#define CFG_TUD_CDC 2 +#define CFG_TUD_MSC 0 +#define CFG_TUD_HID 0 +#define CFG_TUD_MIDI 0 +#define CFG_TUD_VENDOR 0 + +// CDC FIFO size of TX and RX +#define CFG_TUD_CDC_RX_BUFSIZE (TUD_OPT_HIGH_SPEED ? 512 : 64) +#define CFG_TUD_CDC_TX_BUFSIZE (TUD_OPT_HIGH_SPEED ? 512 : 64) + +// CDC Endpoint transfer buffer size, more is faster +#define CFG_TUD_CDC_EP_BUFSIZE (TUD_OPT_HIGH_SPEED ? 512 : 64) + +#ifdef __cplusplus +} +#endif + +#endif \ No newline at end of file