@@ -23,7 +23,7 @@ if (NOT TARGET _rp2040_family_inclusion_marker)
23
23
set (PICO_TINYUSB_PATH ${TOP} )
24
24
endif ()
25
25
26
- #------------------------------------
26
+ #------------------------------------
27
27
# Base config for both device and host; wrapped by SDK's tinyusb_common
28
28
#------------------------------------
29
29
add_library (tinyusb_common_base INTERFACE )
@@ -50,52 +50,21 @@ if (NOT TARGET _rp2040_family_inclusion_marker)
50
50
if (CMAKE_BUILD_TYPE STREQUAL "Debug" )
51
51
message ("Compiling TinyUSB with CFG_TUSB_DEBUG=1" )
52
52
set (TINYUSB_DEBUG_LEVEL 1)
53
- endif ()
53
+ endif ()
54
54
55
55
target_compile_definitions (tinyusb_common_base INTERFACE
56
56
CFG_TUSB_MCU=OPT_MCU_RP2040
57
57
CFG_TUSB_OS=OPT_OS_PICO
58
58
CFG_TUSB_DEBUG=${TINYUSB_DEBUG_LEVEL}
59
59
)
60
60
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
+ #------------------------------------
92
62
# Base config for device mode; wrapped by SDK's tinyusb_device
93
63
#------------------------------------
94
64
add_library (tinyusb_device_base INTERFACE )
95
65
target_sources (tinyusb_device_base INTERFACE
96
66
${TOP} /src/portable/raspberrypi/rp2040/dcd_rp2040.c
97
67
${TOP} /src/portable/raspberrypi/rp2040/rp2040_usb.c
98
- ${TOP} /src/portable/raspberrypi/pio_usb/dcd_pio_usb.c
99
68
${TOP} /src/device/usbd.c
100
69
${TOP} /src/device/usbd_control.c
101
70
${TOP} /src/class/audio/audio_device.c
@@ -119,7 +88,6 @@ if (NOT TARGET _rp2040_family_inclusion_marker)
119
88
target_sources (tinyusb_host_base INTERFACE
120
89
${TOP} /src/portable/raspberrypi/rp2040/hcd_rp2040.c
121
90
${TOP} /src/portable/raspberrypi/rp2040/rp2040_usb.c
122
- ${TOP} /src/portable/raspberrypi/pio_usb/hcd_pio_usb.c
123
91
${TOP} /src/host/usbh.c
124
92
${TOP} /src/host/hub.c
125
93
${TOP} /src/class/cdc/cdc_host.c
@@ -140,8 +108,8 @@ if (NOT TARGET _rp2040_family_inclusion_marker)
140
108
target_sources (tinyusb_bsp INTERFACE
141
109
${TOP} /hw/bsp/rp2040/family.c
142
110
)
143
- # target_include_directories(tinyusb_bsp INTERFACE
144
- # ${TOP}/hw/bsp/rp2040)
111
+ # target_include_directories(tinyusb_bsp INTERFACE
112
+ # ${TOP}/hw/bsp/rp2040)
145
113
146
114
# tinyusb_additions will hold our extra settings for examples
147
115
add_library (tinyusb_additions INTERFACE )
@@ -151,22 +119,22 @@ if (NOT TARGET _rp2040_family_inclusion_marker)
151
119
)
152
120
153
121
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} )
155
123
endif ()
156
124
157
125
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
+ )
170
138
endif ()
171
139
172
140
#------------------------------------
@@ -189,41 +157,81 @@ if (NOT TARGET _rp2040_family_inclusion_marker)
189
157
target_link_libraries (${TARGET} PUBLIC pico_stdlib tinyusb_host)
190
158
endfunction ()
191
159
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 )
193
165
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 )
197
168
endfunction ()
198
169
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
+
199
223
function (family_initialize_project PROJECT DIR)
200
224
# call the original version of this function from family_common.cmake
201
225
_family_initialize_project(${PROJECT} ${DIR} )
202
226
enable_language (C CXX ASM)
203
227
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()
204
231
endfunction ()
205
232
206
233
# This method must be called from the project scope to suppress known warnings in TinyUSB source files
207
234
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
228
236
endfunction ()
229
237
endif ()
0 commit comments