rktk_drivers_nrf/vbus.rs
1/// Convenient macro to obtain proper VBUS detection implementation
2///
3/// VBUS detection is a mechanism for detecting when USB is connected.
4/// It is used to determine which side will take the master role in a split keyboard,
5/// and is also required when building USB drivers.
6///
7/// In embassy-nrf, VBUS detection can be performed using `HardwareVbusDetect`, but `HardwareVbusDetect` cannot be used when using a SoftDevice, and a different mechanism must be used.
8///
9/// This macro therefore returns an appropriate VbusDetect implementation depending on whether the `softdevice` feature is present or not.
10///
11/// For more advanced use (such as when you want to handle SoftDevice SocEvents yourself), see [`crate::softdevice::vbus`].
12///
13/// **WARN: Calling this macro more than twice may cause a panic.**
14#[cfg(feature = "softdevice")]
15#[macro_export]
16macro_rules! get_vbus {
17 ($spawner:expr, $irqs:expr) => {{
18 use $crate::softdevice::{SD_SOCEVENT_CHAN, vbus::SoftdeviceVbusDetect};
19
20 SoftdeviceVbusDetect::init($spawner, &SD_SOCEVENT_CHAN)
21 }};
22}
23
24#[cfg(not(feature = "softdevice"))]
25#[macro_export]
26macro_rules! get_vbus {
27 ($spawner:expr, $irqs:expr) => {{
28 use embassy_nrf::usb::vbus_detect::HardwareVbusDetect;
29
30 HardwareVbusDetect::new($irqs)
31 }};
32}
RKTK API Docs