diff options
| author | Dario Nieuwenhuis <[email protected]> | 2023-05-15 00:38:58 +0200 |
|---|---|---|
| committer | Dario Nieuwenhuis <[email protected]> | 2023-05-15 00:53:30 +0200 |
| commit | 26d7610554f262c2c25f99fb441e6dbd6abec61f (patch) | |
| tree | ac3c3f548960824a5dbc603b58225132859f03ba /embassy-net/src/lib.rs | |
| parent | 6e93d193cfdd2982410e106c383ecc1f066fccfb (diff) | |
net: do not use smoltcp Instant/Duration in public API.
Diffstat (limited to 'embassy-net/src/lib.rs')
| -rw-r--r-- | embassy-net/src/lib.rs | 18 |
1 files changed, 4 insertions, 14 deletions
diff --git a/embassy-net/src/lib.rs b/embassy-net/src/lib.rs index b80784c2b..64f558756 100644 --- a/embassy-net/src/lib.rs +++ b/embassy-net/src/lib.rs | |||
| @@ -12,6 +12,7 @@ mod device; | |||
| 12 | pub mod dns; | 12 | pub mod dns; |
| 13 | #[cfg(feature = "tcp")] | 13 | #[cfg(feature = "tcp")] |
| 14 | pub mod tcp; | 14 | pub mod tcp; |
| 15 | mod time; | ||
| 15 | #[cfg(feature = "udp")] | 16 | #[cfg(feature = "udp")] |
| 16 | pub mod udp; | 17 | pub mod udp; |
| 17 | 18 | ||
| @@ -27,10 +28,6 @@ use heapless::Vec; | |||
| 27 | use smoltcp::iface::{Interface, SocketHandle, SocketSet, SocketStorage}; | 28 | use smoltcp::iface::{Interface, SocketHandle, SocketSet, SocketStorage}; |
| 28 | #[cfg(feature = "dhcpv4")] | 29 | #[cfg(feature = "dhcpv4")] |
| 29 | use smoltcp::socket::dhcpv4::{self, RetryConfig}; | 30 | use smoltcp::socket::dhcpv4::{self, RetryConfig}; |
| 30 | #[cfg(feature = "dhcpv4")] | ||
| 31 | use smoltcp::time::Duration; | ||
| 32 | // smoltcp reexports | ||
| 33 | pub use smoltcp::time::{Duration as SmolDuration, Instant as SmolInstant}; | ||
| 34 | #[cfg(feature = "medium-ethernet")] | 31 | #[cfg(feature = "medium-ethernet")] |
| 35 | pub use smoltcp::wire::{EthernetAddress, HardwareAddress}; | 32 | pub use smoltcp::wire::{EthernetAddress, HardwareAddress}; |
| 36 | pub use smoltcp::wire::{IpAddress, IpCidr, Ipv4Address, Ipv4Cidr}; | 33 | pub use smoltcp::wire::{IpAddress, IpCidr, Ipv4Address, Ipv4Cidr}; |
| @@ -40,6 +37,7 @@ pub use smoltcp::wire::{Ipv6Address, Ipv6Cidr}; | |||
| 40 | pub use smoltcp::{socket::udp::PacketMetadata, wire::IpListenEndpoint}; | 37 | pub use smoltcp::{socket::udp::PacketMetadata, wire::IpListenEndpoint}; |
| 41 | 38 | ||
| 42 | use crate::device::DriverAdapter; | 39 | use crate::device::DriverAdapter; |
| 40 | use crate::time::{instant_from_smoltcp, instant_to_smoltcp}; | ||
| 43 | 41 | ||
| 44 | const LOCAL_PORT_MIN: u16 = 1025; | 42 | const LOCAL_PORT_MIN: u16 = 1025; |
| 45 | const LOCAL_PORT_MAX: u16 = 65535; | 43 | const LOCAL_PORT_MAX: u16 = 65535; |
| @@ -74,7 +72,7 @@ pub struct StaticConfig { | |||
| 74 | #[cfg(feature = "dhcpv4")] | 72 | #[cfg(feature = "dhcpv4")] |
| 75 | #[derive(Debug, Clone, PartialEq, Eq)] | 73 | #[derive(Debug, Clone, PartialEq, Eq)] |
| 76 | pub struct DhcpConfig { | 74 | pub struct DhcpConfig { |
| 77 | pub max_lease_duration: Option<Duration>, | 75 | pub max_lease_duration: Option<embassy_time::Duration>, |
| 78 | pub retry_config: RetryConfig, | 76 | pub retry_config: RetryConfig, |
| 79 | /// Ignore NAKs. | 77 | /// Ignore NAKs. |
| 80 | pub ignore_naks: bool, | 78 | pub ignore_naks: bool, |
| @@ -384,7 +382,7 @@ impl<D: Driver + 'static> Inner<D> { | |||
| 384 | #[cfg(feature = "dhcpv4")] | 382 | #[cfg(feature = "dhcpv4")] |
| 385 | fn apply_dhcp_config(&self, socket: &mut smoltcp::socket::dhcpv4::Socket, config: DhcpConfig) { | 383 | fn apply_dhcp_config(&self, socket: &mut smoltcp::socket::dhcpv4::Socket, config: DhcpConfig) { |
| 386 | socket.set_ignore_naks(config.ignore_naks); | 384 | socket.set_ignore_naks(config.ignore_naks); |
| 387 | socket.set_max_lease_duration(config.max_lease_duration); | 385 | socket.set_max_lease_duration(config.max_lease_duration.map(crate::time::duration_to_smoltcp)); |
| 388 | socket.set_ports(config.server_port, config.client_port); | 386 | socket.set_ports(config.server_port, config.client_port); |
| 389 | socket.set_retry_config(config.retry_config); | 387 | socket.set_retry_config(config.retry_config); |
| 390 | } | 388 | } |
| @@ -465,11 +463,3 @@ impl<D: Driver + 'static> Inner<D> { | |||
| 465 | } | 463 | } |
| 466 | } | 464 | } |
| 467 | } | 465 | } |
| 468 | |||
| 469 | fn instant_to_smoltcp(instant: Instant) -> SmolInstant { | ||
| 470 | SmolInstant::from_millis(instant.as_millis() as i64) | ||
| 471 | } | ||
| 472 | |||
| 473 | fn instant_from_smoltcp(instant: SmolInstant) -> Instant { | ||
| 474 | Instant::from_millis(instant.total_millis() as u64) | ||
| 475 | } | ||
