Skip to content

Commit

Permalink
riot-rs-embassy: allow overriding the network configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
kaspar030 committed Dec 20, 2023
1 parent 569cc74 commit 782f75a
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
2 changes: 2 additions & 0 deletions src/riot-rs-embassy/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,5 @@ time = ["dep:embassy-time", "embassy-executor/integrated-timers"]
usb = [ "dep:embassy-usb" ]
net = [ "dep:embassy-net" ]
usb_ethernet = [ "usb", "net" ]

override_network_config = []
28 changes: 21 additions & 7 deletions src/riot-rs-embassy/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,26 @@ const fn usb_default_config() -> embassy_usb::Config<'static> {
config
}

#[cfg(feature = "net")]
fn network_config() -> embassy_net::Config {
#[cfg(not(feature = "override_network_config"))]
{
use embassy_net::{Ipv4Address, Ipv4Cidr};
embassy_net::Config::ipv4_static(embassy_net::StaticConfigV4 {
address: Ipv4Cidr::new(Ipv4Address::new(10, 42, 0, 61), 24),
dns_servers: heapless::Vec::new(),
gateway: Some(Ipv4Address::new(10, 42, 0, 1)),
})
}
#[cfg(feature = "override_network_config")]
{
extern "Rust" {
fn riot_rs_network_config() -> embassy_net::Config;
}
unsafe { riot_rs_network_config() }
}
}

#[distributed_slice(riot_rs_rt::INIT_FUNCS)]
pub(crate) fn init() {
riot_rs_rt::debug::println!("riot-rs-embassy::init()");
Expand Down Expand Up @@ -249,13 +269,7 @@ async fn init_task(peripherals: arch::Peripherals) {
#[cfg(feature = "usb_ethernet")]
let stack = {
// network stack
//let config = embassy_net::Config::dhcpv4(Default::default());
use embassy_net::{Ipv4Address, Ipv4Cidr};
let config = embassy_net::Config::ipv4_static(embassy_net::StaticConfigV4 {
address: Ipv4Cidr::new(Ipv4Address::new(10, 42, 0, 61), 24),
dns_servers: heapless::Vec::new(),
gateway: Some(Ipv4Address::new(10, 42, 0, 1)),
});
let config = network_config();

// Generate random seed
// let mut rng = Rng::new(p.RNG, Irqs);
Expand Down

0 comments on commit 782f75a

Please sign in to comment.