From 09db1687dd9db65aee3baac083145d3e74a28ffe Mon Sep 17 00:00:00 2001 From: Ryan Summers Date: Fri, 5 Jul 2024 14:35:26 +0200 Subject: [PATCH] Updating embedded-nal version --- CHANGELOG.md | 1 + Cargo.toml | 2 +- src/host/mod.rs | 6 +++--- src/tcp.rs | 23 +++++++++++++++-------- 4 files changed, 20 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 94fe2ef..246c799 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - [breaking] The driver now uses the v1.0 of the `embedded-hal` traits. - [breaking] The `FourWireRef` bus and `DeviceRefMut` have been removed in favor of using `embedded-hal-bus` to facilitate SPI bus sharing. +- [breaking] Updated to `embedded-nal` v0.8 ### Added diff --git a/Cargo.toml b/Cargo.toml index 987c3b5..a735ec3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,7 +16,7 @@ no-chip-version-assertion = [] [dependencies] byteorder = { version = "1.3.4", default-features = false } embedded-hal = "1" -embedded-nal = "0.6.0" +embedded-nal = "0.8.0" bit_field = "0.10" derive-try-from-primitive = "1" nb = "1.0.0" diff --git a/src/host/mod.rs b/src/host/mod.rs index 8aa1b79..f1f9271 100644 --- a/src/host/mod.rs +++ b/src/host/mod.rs @@ -24,9 +24,9 @@ impl Default for HostConfig { fn default() -> Self { Self { mac: MacAddress::default(), - ip: Ipv4Addr::unspecified(), - gateway: Ipv4Addr::unspecified(), - subnet: Ipv4Addr::unspecified(), + ip: Ipv4Addr::UNSPECIFIED, + gateway: Ipv4Addr::UNSPECIFIED, + subnet: Ipv4Addr::UNSPECIFIED, } } } diff --git a/src/tcp.rs b/src/tcp.rs index 4fb1311..4f215ed 100644 --- a/src/tcp.rs +++ b/src/tcp.rs @@ -5,7 +5,9 @@ use crate::{ socket::Socket, }; -use embedded_nal::{nb, IpAddr, Ipv4Addr, SocketAddr, SocketAddrV4, TcpClientStack}; +use embedded_nal::{ + nb, IpAddr, Ipv4Addr, SocketAddr, SocketAddrV4, TcpClientStack, TcpError, TcpErrorKind, +}; use core::convert::TryFrom; @@ -13,12 +15,21 @@ use core::convert::TryFrom; #[cfg_attr(feature = "defmt", derive(defmt::Format))] pub enum TcpSocketError { NoMoreSockets, - NotReady, + NotConnected, UnsupportedAddress, Other(#[cfg_attr(feature = "defmt", defmt(Debug2Format))] E), UnsupportedMode, } +impl TcpError for TcpSocketError { + fn kind(&self) -> TcpErrorKind { + match self { + TcpSocketError::NotConnected => TcpErrorKind::PipeClosed, + _ => TcpErrorKind::Other, + } + } +} + impl From for TcpSocketError { fn from(e: E) -> Self { TcpSocketError::Other(e) @@ -135,7 +146,7 @@ impl TcpSocket { data: &[u8], ) -> Result> { if !self.socket_is_connected(bus)? { - return Err(TcpSocketError::NotReady); + return Err(TcpSocketError::NotConnected); } let max_size = self.socket.get_tx_free_size(bus)? as usize; @@ -171,7 +182,7 @@ impl TcpSocket { data: &mut [u8], ) -> Result> { if !self.socket_is_connected(bus)? { - return Err(TcpSocketError::NotReady); + return Err(TcpSocketError::NotConnected); } // Check if we've received data. @@ -231,10 +242,6 @@ impl TcpClientStack for Device Ok(()) } - fn is_connected(&mut self, socket: &Self::TcpSocket) -> Result { - socket.socket_is_connected(&mut self.bus) - } - fn send( &mut self, socket: &mut Self::TcpSocket,