Skip to content

Commit d878d50

Browse files
committed
Add additional Bazel defines for tinyUSB and pico_stdio_usb
This change the makes the following defines setable in Bazel: - `LIB_TINYUSB_HOST` - `LIB_TINYUSB_DEVICE` - `PICO_STDIO_USB_ENABLE_RESET_VIA_BAUD_RATE` - `PICO_STDIO_USB_ENABLE_RESET_VIA_VENDOR_INTERFACE` This also adds `//bazel/config:PICO_TINYUSB_CONFIG`, which allows overriding the "tusb_config.h" header used to build tinyUSB. This might be used to add additional USB interfaces while preserving the functionality from pico_stdio_usb.
1 parent e7f8e48 commit d878d50

File tree

5 files changed

+78
-6
lines changed

5 files changed

+78
-6
lines changed

bazel/config/BUILD.bazel

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,36 @@ int_flag(
186186
build_setting_default = 0,
187187
)
188188

189+
# PICO_BAZEL_CONFIG: PICO_STDIO_USB_ENABLE_RESET_VIA_BAUD_RATE, Enable/disable resetting into BOOTSEL mode if the host sets the baud rate to a magic value (PICO_STDIO_USB_RESET_MAGIC_BAUD_RATE), type=bool, default=1, group=pico_stdio_usb
190+
bool_flag(
191+
name = "PICO_STDIO_USB_ENABLE_RESET_VIA_BAUD_RATE",
192+
build_setting_default = True,
193+
)
194+
195+
# PICO_BAZEL_CONFIG: PICO_STDIO_USB_ENABLE_RESET_VIA_VENDOR_INTERFACE, Enable/disable resetting into BOOTSEL mode via an additional VENDOR USB interface - enables picotool based reset, type=bool, default=1, group=pico_stdio_usb
196+
bool_flag(
197+
name = "PICO_STDIO_USB_ENABLE_RESET_VIA_VENDOR_INTERFACE",
198+
build_setting_default = True,
199+
)
200+
201+
# PICO_BAZEL_CONFIG: PICO_TINYUSB_CONFIG, [Bazel only] The library that provides TinyUSB config header (e.g. tusb_config.h), default=//src/rp2_common/pico_stdio_usb:tusb_config, group=build
202+
label_flag(
203+
name = "PICO_TINYUSB_CONFIG",
204+
build_setting_default = "//src/rp2_common/pico_stdio_usb:tusb_config",
205+
)
206+
207+
# PICO_BAZEL_CONFIG: PICO_TINYUSB_DEVICE, Indicates user code is using tinyusb in device mode, type=bool, default=0, group=pico_stdio_usb
208+
bool_flag(
209+
name = "PICO_TINYUSB_DEVICE",
210+
build_setting_default = False,
211+
)
212+
213+
# PICO_BAZEL_CONFIG: PICO_TINYUSB_HOST, Indicates user code is using tinyusb in host mode, type=bool, default=0, group=pico_stdio_usb
214+
bool_flag(
215+
name = "PICO_TINYUSB_HOST",
216+
build_setting_default = False,
217+
)
218+
189219
# PICO_BAZEL_CONFIG: PICO_TINYUSB_LIB, [Bazel only] The library that provides TinyUSB, default=@tinyusb//:tinyusb, group=build
190220
label_flag(
191221
name = "PICO_TINYUSB_LIB",

bazel/util/sdk_define.bzl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ def _pico_sdk_define_impl(ctx):
1111
val = 1 if val else 0
1212
cc_ctx = cc_common.create_compilation_context(
1313
defines = depset(
14-
direct = ["{}={}".format(ctx.attr.define_name, val)],
14+
direct = [
15+
"{}={}".format(ctx.attr.define_name, val)
16+
] if val or not ctx.attr.undef_if_falsy else [],
1517
),
1618
)
1719
return [CcInfo(compilation_context = cc_ctx)]
@@ -39,5 +41,6 @@ Example:
3941
attrs = {
4042
"define_name": attr.string(mandatory = True),
4143
"from_flag": attr.label(mandatory = True),
44+
"undef_if_falsy": attr.bool(default = False),
4245
},
4346
)

src/rp2_common/pico_stdio_usb/BUILD.bazel

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ cc_library(
2424
hdrs = ["include/tusb_config.h"],
2525
includes = ["include"],
2626
target_compatible_with = compatible_with_rp2(),
27+
deps = [
28+
":LIB_TINYUSB_DEVICE",
29+
":LIB_TINYUSB_HOST",
30+
":pico_stdio_usb_headers",
31+
],
2732
)
2833

2934
pico_sdk_define(
@@ -38,18 +43,44 @@ pico_sdk_define(
3843
from_flag = "//bazel/config:PICO_STDIO_USB_CONNECT_WAIT_TIMEOUT_MS",
3944
)
4045

46+
pico_sdk_define(
47+
name = "PICO_STDIO_USB_ENABLE_RESET_VIA_BAUD_RATE",
48+
define_name = "PICO_STDIO_USB_ENABLE_RESET_VIA_BAUD_RATE",
49+
from_flag = "//bazel/config:PICO_STDIO_USB_ENABLE_RESET_VIA_BAUD_RATE",
50+
)
51+
52+
pico_sdk_define(
53+
name = "PICO_STDIO_USB_ENABLE_RESET_VIA_VENDOR_INTERFACE",
54+
define_name = "PICO_STDIO_USB_ENABLE_RESET_VIA_VENDOR_INTERFACE",
55+
from_flag = "//bazel/config:PICO_STDIO_USB_ENABLE_RESET_VIA_VENDOR_INTERFACE",
56+
)
57+
58+
pico_sdk_define(
59+
name = "LIB_TINYUSB_HOST",
60+
define_name = "LIB_TINYUSB_HOST",
61+
from_flag = "//bazel/config:PICO_TINYUSB_HOST",
62+
undef_if_falsy = True,
63+
)
64+
65+
pico_sdk_define(
66+
name = "LIB_TINYUSB_DEVICE",
67+
define_name = "LIB_TINYUSB_DEVICE",
68+
from_flag = "//bazel/config:PICO_TINYUSB_DEVICE",
69+
undef_if_falsy = True,
70+
)
71+
4172
cc_library(
4273
name = "pico_stdio_usb_headers",
4374
hdrs = ["include/pico/stdio_usb.h"],
4475
includes = ["include"],
4576
target_compatible_with = compatible_with_rp2(),
46-
visibility = [
47-
":__pkg__",
48-
"//src/rp2_common/tinyusb:__pkg__",
49-
],
5077
deps = [
5178
":LIB_PICO_STDIO_USB",
79+
":LIB_TINYUSB_DEVICE",
80+
":LIB_TINYUSB_HOST",
5281
":PICO_STDIO_USB_CONNECT_WAIT_TIMEOUT_MS",
82+
":PICO_STDIO_USB_ENABLE_RESET_VIA_BAUD_RATE",
83+
":PICO_STDIO_USB_ENABLE_RESET_VIA_VENDOR_INTERFACE",
5384
],
5485
)
5586

@@ -65,7 +96,11 @@ cc_library(
6596
) + compatible_with_rp2(),
6697
deps = [
6798
":LIB_PICO_STDIO_USB",
99+
":LIB_TINYUSB_DEVICE",
100+
":LIB_TINYUSB_HOST",
68101
":PICO_STDIO_USB_CONNECT_WAIT_TIMEOUT_MS",
102+
":PICO_STDIO_USB_ENABLE_RESET_VIA_BAUD_RATE",
103+
":PICO_STDIO_USB_ENABLE_RESET_VIA_VENDOR_INTERFACE",
69104
":pico_stdio_usb_headers",
70105
":reset_interface_headers",
71106
"//bazel/config:PICO_TINYUSB_LIB",

src/rp2_common/pico_stdio_usb/include/pico/stdio_usb.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@
4848
#ifndef PICO_STDIO_USB_ENABLE_RESET_VIA_BAUD_RATE
4949
#if !defined(LIB_TINYUSB_HOST) && !defined(LIB_TINYUSB_DEVICE)
5050
#define PICO_STDIO_USB_ENABLE_RESET_VIA_BAUD_RATE 1
51+
#else
52+
#define PICO_STDIO_USB_ENABLE_RESET_VIA_BAUD_RATE 0
5153
#endif
5254
#endif
5355

@@ -93,6 +95,8 @@
9395
#ifndef PICO_STDIO_USB_ENABLE_RESET_VIA_VENDOR_INTERFACE
9496
#if !defined(LIB_TINYUSB_HOST) && !defined(LIB_TINYUSB_DEVICE)
9597
#define PICO_STDIO_USB_ENABLE_RESET_VIA_VENDOR_INTERFACE 1
98+
#else
99+
#define PICO_STDIO_USB_ENABLE_RESET_VIA_VENDOR_INTERFACE 0
96100
#endif
97101
#endif
98102

src/rp2_common/tinyusb/BUILD.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ cc_library(
1515
includes = ["include"],
1616
target_compatible_with = compatible_with_rp2(),
1717
deps = [
18+
"//bazel/config:PICO_TINYUSB_CONFIG",
1819
"//src/common/pico_binary_info",
1920
"//src/common/pico_stdlib_headers",
2021
"//src/common/pico_sync",
@@ -30,7 +31,6 @@ cc_library(
3031
"//src/rp2_common/pico_stdio_semihosting",
3132
"//src/rp2_common/pico_stdio_uart",
3233
"//src/rp2_common/pico_stdio_usb:pico_stdio_usb_headers",
33-
"//src/rp2_common/pico_stdio_usb:tusb_config",
3434
"//src/rp2_common/pico_unique_id",
3535
],
3636
)

0 commit comments

Comments
 (0)