@@ -23,7 +23,7 @@ if (NOT TARGET _rp2040_family_inclusion_marker)
2323 set (PICO_TINYUSB_PATH ${TOP} )
2424 endif ()
2525
26- #------------------------------------
26+ #------------------------------------
2727 # Base config for both device and host; wrapped by SDK's tinyusb_common
2828 #------------------------------------
2929 add_library (tinyusb_common_base INTERFACE )
@@ -50,52 +50,21 @@ if (NOT TARGET _rp2040_family_inclusion_marker)
5050 if (CMAKE_BUILD_TYPE STREQUAL "Debug" )
5151 message ("Compiling TinyUSB with CFG_TUSB_DEBUG=1" )
5252 set (TINYUSB_DEBUG_LEVEL 1)
53- endif ()
53+ endif ()
5454
5555 target_compile_definitions (tinyusb_common_base INTERFACE
5656 CFG_TUSB_MCU=OPT_MCU_RP2040
5757 CFG_TUSB_OS=OPT_OS_PICO
5858 CFG_TUSB_DEBUG=${TINYUSB_DEBUG_LEVEL}
5959 )
6060
61- #------------------------------------
62- # PIO USB for both host and device
63- #------------------------------------
64- add_library (pico_pio_usb INTERFACE )
65-
66- if (NOT DEFINED PICO_PIO_USB_PATH)
67- set (PICO_PIO_USB_PATH "${TOP} /hw/mcu/raspberry_pi/Pico-PIO-USB" )
68- endif ()
69-
70- target_sources (pico_pio_usb INTERFACE
71- ${PICO_PIO_USB_PATH} /src/pio_usb.c
72- ${PICO_PIO_USB_PATH} /src/pio_usb_host.c
73- ${PICO_PIO_USB_PATH} /src/pio_usb_device.c
74- ${PICO_PIO_USB_PATH} /src/usb_crc.c
75- )
76-
77- target_include_directories (pico_pio_usb INTERFACE
78- ${PICO_PIO_USB_PATH} /src
79- )
80-
81- target_link_libraries (pico_pio_usb INTERFACE
82- hardware_dma
83- hardware_pio
84- pico_multicore
85- )
86-
87- target_compile_definitions (pico_pio_usb INTERFACE
88- PIO_USB_USE_TINYUSB
89- )
90-
91- #------------------------------------
61+ #------------------------------------
9262 # Base config for device mode; wrapped by SDK's tinyusb_device
9363 #------------------------------------
9464 add_library (tinyusb_device_base INTERFACE )
9565 target_sources (tinyusb_device_base INTERFACE
9666 ${TOP} /src/portable/raspberrypi/rp2040/dcd_rp2040.c
9767 ${TOP} /src/portable/raspberrypi/rp2040/rp2040_usb.c
98- ${TOP} /src/portable/raspberrypi/pio_usb/dcd_pio_usb.c
9968 ${TOP} /src/device/usbd.c
10069 ${TOP} /src/device/usbd_control.c
10170 ${TOP} /src/class/audio/audio_device.c
@@ -119,7 +88,6 @@ if (NOT TARGET _rp2040_family_inclusion_marker)
11988 target_sources (tinyusb_host_base INTERFACE
12089 ${TOP} /src/portable/raspberrypi/rp2040/hcd_rp2040.c
12190 ${TOP} /src/portable/raspberrypi/rp2040/rp2040_usb.c
122- ${TOP} /src/portable/raspberrypi/pio_usb/hcd_pio_usb.c
12391 ${TOP} /src/host/usbh.c
12492 ${TOP} /src/host/hub.c
12593 ${TOP} /src/class/cdc/cdc_host.c
@@ -140,8 +108,8 @@ if (NOT TARGET _rp2040_family_inclusion_marker)
140108 target_sources (tinyusb_bsp INTERFACE
141109 ${TOP} /hw/bsp/rp2040/family.c
142110 )
143- # target_include_directories(tinyusb_bsp INTERFACE
144- # ${TOP}/hw/bsp/rp2040)
111+ # target_include_directories(tinyusb_bsp INTERFACE
112+ # ${TOP}/hw/bsp/rp2040)
145113
146114 # tinyusb_additions will hold our extra settings for examples
147115 add_library (tinyusb_additions INTERFACE )
@@ -151,22 +119,22 @@ if (NOT TARGET _rp2040_family_inclusion_marker)
151119 )
152120
153121 if (DEFINED LOG )
154- target_compile_definitions (tinyusb_additions INTERFACE CFG_TUSB_DEBUG=${LOG} )
122+ target_compile_definitions (tinyusb_additions INTERFACE CFG_TUSB_DEBUG=${LOG} )
155123 endif ()
156124
157125 if (LOGGER STREQUAL "rtt" )
158- target_compile_definitions (tinyusb_additions INTERFACE
159- LOGGER_RTT
160- SEGGER_RTT_MODE_DEFAULT=SEGGER_RTT_MODE_BLOCK_IF_FIFO_FULL
161- )
162-
163- target_sources (tinyusb_additions INTERFACE
164- ${TOP} /lib/SEGGER_RTT/RTT/SEGGER_RTT.c
165- )
166-
167- target_include_directories (tinyusb_additions INTERFACE
168- ${TOP} /lib/SEGGER_RTT/RTT
169- )
126+ target_compile_definitions (tinyusb_additions INTERFACE
127+ LOGGER_RTT
128+ SEGGER_RTT_MODE_DEFAULT=SEGGER_RTT_MODE_BLOCK_IF_FIFO_FULL
129+ )
130+
131+ target_sources (tinyusb_additions INTERFACE
132+ ${TOP} /lib/SEGGER_RTT/RTT/SEGGER_RTT.c
133+ )
134+
135+ target_include_directories (tinyusb_additions INTERFACE
136+ ${TOP} /lib/SEGGER_RTT/RTT
137+ )
170138 endif ()
171139
172140 #------------------------------------
@@ -189,41 +157,81 @@ if (NOT TARGET _rp2040_family_inclusion_marker)
189157 target_link_libraries (${TARGET} PUBLIC pico_stdlib tinyusb_host)
190158 endfunction ()
191159
192- function (family_configure_pico_pio_usb_example TARGET )
160+ function (family_add_pico_pio_usb TARGET )
161+ target_link_libraries (${TARGET} PUBLIC tinyusb_pico_pio_usb)
162+ endfunction ()
163+
164+ function (family_configure_dual_usb_example TARGET )
193165 family_configure_target(${TARGET} )
194- target_link_libraries (${TARGET} PUBLIC pico_stdlib pico_pio_usb)
195- pico_generate_pio_header(tinyusb_common_base ${PICO_PIO_USB_PATH} /src/usb_tx.pio)
196- pico_generate_pio_header(tinyusb_common_base ${PICO_PIO_USB_PATH} /src/usb_rx.pio)
166+ # require tinyusb_pico_pio_usb
167+ target_link_libraries (${TARGET} PUBLIC pico_stdlib tinyusb_device tinyusb_host tinyusb_pico_pio_usb )
197168 endfunction ()
198169
170+ function (check_and_add_pico_pio_usb_support)
171+ # check for pico_generate_pio_header (as depending on environment we may be called before SDK is
172+ # initialized in which case it isn't available yet), and only do the initialization once
173+ if (COMMAND pico_generate_pio_header AND NOT TARGET tinyusb_pico_pio_usb)
174+ #------------------------------------
175+ # PIO USB for both host and device
176+ #------------------------------------
177+
178+ if (NOT DEFINED PICO_PIO_USB_PATH)
179+ set (PICO_PIO_USB_PATH "${TOP} /hw/mcu/raspberry_pi/Pico-PIO-USB" )
180+ endif ()
181+
182+ if (EXISTS ${PICO_PIO_USB_PATH} /src/pio_usb.c)
183+ add_library (tinyusb_pico_pio_usb INTERFACE )
184+ target_sources (tinyusb_device_base INTERFACE
185+ ${TOP} /src/portable/raspberrypi/pio_usb/dcd_pio_usb.c
186+ )
187+ target_sources (tinyusb_host_base INTERFACE
188+ ${TOP} /src/portable/raspberrypi/pio_usb/hcd_pio_usb.c
189+ )
190+
191+ target_sources (tinyusb_pico_pio_usb INTERFACE
192+ ${PICO_PIO_USB_PATH} /src/pio_usb.c
193+ ${PICO_PIO_USB_PATH} /src/pio_usb_host.c
194+ ${PICO_PIO_USB_PATH} /src/pio_usb_device.c
195+ ${PICO_PIO_USB_PATH} /src/usb_crc.c
196+ )
197+
198+ target_include_directories (tinyusb_pico_pio_usb INTERFACE
199+ ${PICO_PIO_USB_PATH} /src
200+ )
201+
202+ target_link_libraries (tinyusb_pico_pio_usb INTERFACE
203+ hardware_dma
204+ hardware_pio
205+ pico_multicore
206+ )
207+
208+ target_compile_definitions (tinyusb_pico_pio_usb INTERFACE
209+ PIO_USB_USE_TINYUSB
210+ )
211+
212+ pico_generate_pio_header(tinyusb_pico_pio_usb ${PICO_PIO_USB_PATH} /src/usb_tx.pio)
213+ pico_generate_pio_header(tinyusb_pico_pio_usb ${PICO_PIO_USB_PATH} /src/usb_rx.pio)
214+ endif ()
215+ endif ()
216+ endfunction ()
217+
218+ # Try to add Pico-PIO_USB support now for the case where this file is included directly
219+ # after Pico SDK initialization, but without using the family_ functions (as is the case
220+ # when included by the SDK itself)
221+ check_and_add_pico_pio_usb_support()
222+
199223 function (family_initialize_project PROJECT DIR)
200224 # call the original version of this function from family_common.cmake
201225 _family_initialize_project(${PROJECT} ${DIR} )
202226 enable_language (C CXX ASM)
203227 pico_sdk_init()
228+
229+ # now re-check for adding Pico-PIO_USB support now SDK is definitely available
230+ check_and_add_pico_pio_usb_support()
204231 endfunction ()
205232
206233 # This method must be called from the project scope to suppress known warnings in TinyUSB source files
207234 function (suppress_tinyusb_warnings)
208- set_source_files_properties (
209- ${PICO_TINYUSB_PATH} /src/tusb.c
210- PROPERTIES
211- COMPILE_FLAGS "-Wno-conversion" )
212- set_source_files_properties (
213- ${PICO_TINYUSB_PATH} /src/common/tusb_fifo.c
214- PROPERTIES
215- COMPILE_FLAGS "-Wno-conversion -Wno-cast-qual" )
216- set_source_files_properties (
217- ${PICO_TINYUSB_PATH} /src/device/usbd.c
218- PROPERTIES
219- COMPILE_FLAGS "-Wno-conversion -Wno-cast-qual -Wno-null-dereference" )
220- set_source_files_properties (
221- ${PICO_TINYUSB_PATH} /src/device/usbd_control.c
222- PROPERTIES
223- COMPILE_FLAGS "-Wno-conversion" )
224- set_source_files_properties (
225- ${PICO_TINYUSB_PATH} /src/class/cdc/cdc_device.c
226- PROPERTIES
227- COMPILE_FLAGS "-Wno-conversion" )
235+ # there are currently no warnings to suppress, however this function must still exist
228236 endfunction ()
229237endif ()
0 commit comments