diff --git a/src/riot-rs-embassy/src/lib.rs b/src/riot-rs-embassy/src/lib.rs index 63c54eefe..86be99f8a 100644 --- a/src/riot-rs-embassy/src/lib.rs +++ b/src/riot-rs-embassy/src/lib.rs @@ -77,7 +77,7 @@ cfg_if::cfg_if! { } else if #[cfg(context = "riot-rs")] { compile_error!("no backend for net is active"); } else { - type NetworkDevice = network::DummyDriver; + use network::DummyDriver as NetworkDevice; } } @@ -271,9 +271,6 @@ async fn init_task(mut peripherals: arch::OptionalPeripherals) { #[cfg(feature = "wifi-esp")] let device = arch::wifi::esp_wifi::init(&mut peripherals, spawner); - #[cfg(not(any(feature = "wifi-esp", feature = "wifi-cyw43", feature = "usb-ethernet")))] - let device = panic!(); - #[cfg(feature = "net")] { use embassy_net::StackResources; @@ -286,6 +283,12 @@ async fn init_task(mut peripherals: arch::OptionalPeripherals) { "maximum number of concurrent sockets allowed by the network stack" ); + #[cfg(not(any(feature = "wifi-esp", feature = "wifi-cyw43", feature = "usb-ethernet")))] + // The creation of `device` is not organized in such a way that they could be put in a + // cfg-if without larger refactoring; relying on unused variable lints to keep the + // condition list up to date. + let device: NetworkDevice = network::new_dummy(); + let config = network::config(); // Generate random seed diff --git a/src/riot-rs-embassy/src/network.rs b/src/riot-rs-embassy/src/network.rs index 932a6e125..d053de5f9 100644 --- a/src/riot-rs-embassy/src/network.rs +++ b/src/riot-rs-embassy/src/network.rs @@ -21,6 +21,7 @@ pub(crate) async fn net_task(mut runner: Runner<'static, NetworkDevice>) -> ! { runner.run().await } +#[allow(dead_code, reason = "false positive during builds outside of laze")] pub(crate) fn config() -> embassy_net::Config { #[cfg(not(feature = "override-network-config"))] { @@ -35,12 +36,26 @@ pub(crate) fn config() -> embassy_net::Config { } } -/// An uninhabited type that stands in for a network driver in documentation and linting. +/// Constructor for [`DummyDriver`'] +/// +/// This is a standalone function instead of an associated method to ease moving [`DummyDriver`] +/// into [`embassy_net`]. +#[allow( + dead_code, + reason = "constructor is only used in linter / documentation situations" +)] +pub(crate) fn new_dummy() -> DummyDriver { + panic!( + "DummyDriver must only ever be constructed for documentation and linting, not for running" + ) +} + +/// Stand-in for a network driver in documentation and linting. /// /// It also doubles as the infallible type for its own associated types. // FIXME: This should be core::convert::Infallible as soon as embassy-net implements the traits on // that. -pub(crate) enum DummyDriver {} +pub(crate) struct DummyDriver(core::convert::Infallible); impl embassy_net::driver::Driver for DummyDriver { type RxToken<'a> = Self @@ -55,23 +70,23 @@ impl embassy_net::driver::Driver for DummyDriver { &mut self, _cx: &mut core::task::Context, ) -> Option<(Self::RxToken<'_>, Self::TxToken<'_>)> { - match *self {} + match self.0 {} } fn transmit(&mut self, _cx: &mut core::task::Context) -> Option> { - match *self {} + match self.0 {} } fn link_state(&mut self, _cx: &mut core::task::Context) -> embassy_net::driver::LinkState { - match *self {} + match self.0 {} } fn capabilities(&self) -> embassy_net::driver::Capabilities { - match *self {} + match self.0 {} } fn hardware_address(&self) -> embassy_net::driver::HardwareAddress { - match *self {} + match self.0 {} } } @@ -80,7 +95,7 @@ impl embassy_net::driver::TxToken for DummyDriver { where F: FnOnce(&mut [u8]) -> R, { - match self {} + match self.0 {} } } @@ -89,6 +104,6 @@ impl embassy_net::driver::RxToken for DummyDriver { where F: FnOnce(&mut [u8]) -> R, { - match self {} + match self.0 {} } }