Skip to content

Commit

Permalink
Move to Tinyusb 0.10.0 (still with RP patches) (#462)
Browse files Browse the repository at this point in the history
Most build related items have moved into <tinyusb>/hw/bsp/rp2040/family.cmake which is now the source of truth

force merging as same code save submodule was already reviewed
  • Loading branch information
kilograham authored Jun 2, 2021
1 parent 496ff66 commit 561502c
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 84 deletions.
4 changes: 4 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,9 @@ if (NOT TARGET _pico_sdk_inclusion_marker)

# add docs at the end, as we gather documentation dirs as we go
add_subdirectory(docs)

if (NOT PICO_SDK_TOP_LEVEL_PROJECT)
pico_promote_common_scope_vars()
endif()
endif()

2 changes: 1 addition & 1 deletion lib/tinyusb
Submodule tinyusb updated 818 files
24 changes: 19 additions & 5 deletions pico_sdk_init.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ if (NOT TARGET _pico_sdk_pre_init_marker)
message(WARNING "pico_sdk_init() should be called after the project is created (and languages added)")
endif()
add_subdirectory(${PICO_SDK_PATH} pico-sdk)
pico_is_top_level_project(ISTOP)
endmacro()

macro(add_sub_list_dirs var)
Expand All @@ -70,11 +71,24 @@ if (NOT TARGET _pico_sdk_pre_init_marker)
endforeach()
endmacro()

macro(pico_register_common_scope_var NAME)
if (NOT ${NAME} IN_LIST PICO_PROMOTE_COMMON_SCOPE_VARS)
list(APPEND PICO_PROMOTE_COMMON_SCOPE_VARS ${NAME})
endif()
endmacro()

set(PICO_PROMOTE_COMMON_SCOPE_VARS
PICO_INCLUDE_DIRS
PICO_SDK_POST_LIST_DIRS
PICO_SDK_POST_LIST_FILES
PICO_CONFIG_HEADER_FILES
PICO_RP2040_CONFIG_HEADER_FILES
)

macro(pico_promote_common_scope_vars)
set(PICO_INCLUDE_DIRS ${PICO_INCLUDE_DIRS} PARENT_SCOPE)
set(PICO_SDK_POST_LIST_DIRS ${PICO_SDK_POST_LIST_DIRS} PARENT_SCOPE)
set(PICO_SDK_POST_LIST_FILES ${PICO_SDK_POST_LIST_FILES} PARENT_SCOPE)
set(PICO_CONFIG_HEADER_FILES ${PICO_CONFIG_HEADER_FILES} PARENT_SCOPE)
set(PICO_RP2040_CONFIG_HEADER_FILES ${PICO_RP2040_CONFIG_HEADER_FILES} PARENT_SCOPE)
set(PICO_PROMOTE_COMMON_SCOPE_VARS ${PICO_PROMOTE_COMMON_SCOPE_VARS} PARENT_SCOPE)
foreach(VAR IN LISTS PICO_PROMOTE_COMMON_SCOPE_VARS)
SET(${VAR} ${${VAR}} PARENT_SCOPE)
endforeach()
endmacro()
endif()
6 changes: 6 additions & 0 deletions src/rp2_common/hardware_uart/include/hardware/uart.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,12 @@ static inline uint uart_get_index(uart_inst_t *uart) {
return uart == uart1 ? 1 : 0;
}

static inline uart_inst_t *uart_get_instance(uint instance) {
static_assert(NUM_UARTS == 2, "");
invalid_params_if(UART, instance >= NUM_UARTS);
return instance ? uart1 : uart0;
}

static inline uart_hw_t *uart_get_hw(uart_inst_t *uart) {
uart_get_index(uart); // check it is a hw uart
return (uart_hw_t *)uart;
Expand Down
12 changes: 5 additions & 7 deletions src/rp2_common/pico_stdio_usb/reset_interface.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@ static uint16_t resetd_open(uint8_t __unused rhport, tusb_desc_interface_t const
}

// Support for parameterized reset via vendor interface control request
static bool resetd_control_request_cb(uint8_t __unused rhport, tusb_control_request_t const *request) {
static bool resetd_control_xfer_cb(uint8_t rhport, uint8_t stage, tusb_control_request_t const * request) {
// nothing to do with DATA & ACK stage
if (stage != CONTROL_STAGE_SETUP) return true;

if (request->wIndex == itf_num) {

#if PICO_STDIO_USB_RESET_INTERFACE_SUPPORT_RESET_TO_BOOTSEL
Expand Down Expand Up @@ -69,10 +72,6 @@ static bool resetd_control_request_cb(uint8_t __unused rhport, tusb_control_requ
return false;
}

static bool resetd_control_complete_cb(uint8_t __unused rhport, tusb_control_request_t __unused const *request) {
return true;
}

static bool resetd_xfer_cb(uint8_t __unused rhport, uint8_t __unused ep_addr, xfer_result_t __unused result, uint32_t __unused xferred_bytes) {
return true;
}
Expand All @@ -85,8 +84,7 @@ static usbd_class_driver_t const _resetd_driver =
.init = resetd_init,
.reset = resetd_reset,
.open = resetd_open,
.control_request = resetd_control_request_cb,
.control_complete = resetd_control_complete_cb,
.control_xfer_cb = resetd_control_xfer_cb,
.xfer_cb = resetd_xfer_cb,
.sof = NULL
};
Expand Down
81 changes: 10 additions & 71 deletions src/rp2_common/tinyusb/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,93 +17,32 @@ endif()
if (EXISTS ${PICO_TINYUSB_PATH}/${TINYUSB_TEST_PATH})
message("TinyUSB available at ${PICO_TINYUSB_PATH}/${TINYUSB_TEST_PATH}; adding USB support.")

add_library(tinyusb_common INTERFACE)
target_link_libraries(tinyusb_common INTERFACE
hardware_structs
hardware_irq
hardware_resets
pico_sync
)

target_sources(tinyusb_common INTERFACE
${PICO_TINYUSB_PATH}/src/tusb.c
${PICO_TINYUSB_PATH}/src/common/tusb_fifo.c
)
pico_register_common_scope_var(PICO_TINYUSB_PATH)

set(TINYUSB_DEBUG_LEVEL 0)
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
message("Compiling TinyUSB with CFG_TUSB_DEBUG=1")
set(TINYUSB_DEBUG_LEVEL 1)
endif ()
set(BOARD pico_sdk)
include(${PICO_TINYUSB_PATH}/hw/bsp/rp2040/family.cmake)

target_compile_definitions(tinyusb_common INTERFACE
CFG_TUSB_MCU=OPT_MCU_RP2040
CFG_TUSB_OS=OPT_OS_PICO #seems examples are hard coded to OPT_OS_NONE
CFG_TUSB_DEBUG=${TINYUSB_DEBUG_LEVEL}
)

target_include_directories(tinyusb_common INTERFACE
${PICO_TINYUSB_PATH}/src
${PICO_TINYUSB_PATH}/src/common
${PICO_TINYUSB_PATH}/hw
)
add_library(tinyusb_common INTERFACE)
target_link_libraries(tinyusb_common INTERFACE tinyusb_common_base)

add_library(tinyusb_device_unmarked INTERFACE)
target_sources(tinyusb_device_unmarked INTERFACE
${PICO_TINYUSB_PATH}/src/portable/raspberrypi/rp2040/dcd_rp2040.c
${PICO_TINYUSB_PATH}/src/portable/raspberrypi/rp2040/rp2040_usb.c
${PICO_TINYUSB_PATH}/src/device/usbd.c
${PICO_TINYUSB_PATH}/src/device/usbd_control.c
${PICO_TINYUSB_PATH}/src/class/audio/audio_device.c
${PICO_TINYUSB_PATH}/src/class/cdc/cdc_device.c
${PICO_TINYUSB_PATH}/src/class/dfu/dfu_rt_device.c
${PICO_TINYUSB_PATH}/src/class/hid/hid_device.c
${PICO_TINYUSB_PATH}/src/class/midi/midi_device.c
${PICO_TINYUSB_PATH}/src/class/msc/msc_device.c
${PICO_TINYUSB_PATH}/src/class/net/net_device.c
${PICO_TINYUSB_PATH}/src/class/usbtmc/usbtmc_device.c
${PICO_TINYUSB_PATH}/src/class/vendor/vendor_device.c
)

target_link_libraries(tinyusb_device_unmarked INTERFACE tinyusb_device_base)
target_compile_definitions(tinyusb_device_unmarked INTERFACE
# off by default note TUD_OPT_RP2040_USB_DEVICE_ENUMERATION_FIX defaults from PICO_RP2040_USB_DEVICE_ENUMERATION_FIX
# TUD_OPT_RP2040_USB_DEVICE_ENUMERATION_FIX=1
)

# unmarked version used by stdio USB
target_link_libraries(tinyusb_device_unmarked INTERFACE tinyusb_common pico_fix_rp2040_usb_device_enumeration)
target_link_libraries(tinyusb_device_unmarked INTERFACE tinyusb_common pico_fix_rp2040_usb_device_enumeration tinyusb_device_base)

pico_add_impl_library(tinyusb_device)
target_link_libraries(tinyusb_device INTERFACE tinyusb_device_unmarked)
target_compile_definitions(tinyusb_device INTERFACE
RP2040_USB_DEVICE_MODE=1 #define is used by tinyusb still
)

pico_add_impl_library(tinyusb_host)
target_sources(tinyusb_host INTERFACE
${PICO_TINYUSB_PATH}/src/portable/raspberrypi/rp2040/hcd_rp2040.c
${PICO_TINYUSB_PATH}/src/portable/raspberrypi/rp2040/rp2040_usb.c
${PICO_TINYUSB_PATH}/src/host/usbh.c
${PICO_TINYUSB_PATH}/src/host/usbh_control.c
${PICO_TINYUSB_PATH}/src/host/hub.c
${PICO_TINYUSB_PATH}/src/class/cdc/cdc_host.c
${PICO_TINYUSB_PATH}/src/class/hid/hid_host.c
${PICO_TINYUSB_PATH}/src/class/msc/msc_host.c
${PICO_TINYUSB_PATH}/src/class/vendor/vendor_host.c
)

# Sometimes have to do host specific actions in mostly
# common functions
target_compile_definitions(tinyusb_host INTERFACE
RP2040_USB_HOST_MODE=1 #define is used by tinyusb still
)

target_link_libraries(tinyusb_host INTERFACE tinyusb_common)
target_link_libraries(tinyusb_host INTERFACE tinyusb_host_base tinyusb_common)

pico_add_impl_library(tinyusb_board)
target_sources(tinyusb_board INTERFACE
${PICO_TINYUSB_PATH}/hw/bsp/raspberry_pi_pico/board_raspberry_pi_pico.c
)
target_link_libraries(tinyusb_board INTERFACE tinyusb_bsp)

pico_promote_common_scope_vars()
endif()

0 comments on commit 561502c

Please sign in to comment.