Skip to content

Commit

Permalink
Updating embedded-nal version
Browse files Browse the repository at this point in the history
  • Loading branch information
ryan-summers authored and kellerkindt committed Jul 5, 2024
1 parent 270436a commit 09db168
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 12 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
6 changes: 3 additions & 3 deletions src/host/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}
}
Expand Down
23 changes: 15 additions & 8 deletions src/tcp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,31 @@ 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;

#[derive(Debug)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub enum TcpSocketError<E: core::fmt::Debug> {
NoMoreSockets,
NotReady,
NotConnected,
UnsupportedAddress,
Other(#[cfg_attr(feature = "defmt", defmt(Debug2Format))] E),
UnsupportedMode,
}

impl<E: core::fmt::Debug> TcpError for TcpSocketError<E> {
fn kind(&self) -> TcpErrorKind {
match self {
TcpSocketError::NotConnected => TcpErrorKind::PipeClosed,
_ => TcpErrorKind::Other,
}
}
}

impl<E: core::fmt::Debug> From<E> for TcpSocketError<E> {
fn from(e: E) -> Self {
TcpSocketError::Other(e)
Expand Down Expand Up @@ -135,7 +146,7 @@ impl TcpSocket {
data: &[u8],
) -> Result<usize, TcpSocketError<B::Error>> {
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;
Expand Down Expand Up @@ -171,7 +182,7 @@ impl TcpSocket {
data: &mut [u8],
) -> Result<usize, TcpSocketError<B::Error>> {
if !self.socket_is_connected(bus)? {
return Err(TcpSocketError::NotReady);
return Err(TcpSocketError::NotConnected);
}

// Check if we've received data.
Expand Down Expand Up @@ -231,10 +242,6 @@ impl<SpiBus: Bus, StateImpl: State> TcpClientStack for Device<SpiBus, StateImpl>
Ok(())
}

fn is_connected(&mut self, socket: &Self::TcpSocket) -> Result<bool, Self::Error> {
socket.socket_is_connected(&mut self.bus)
}

fn send(
&mut self,
socket: &mut Self::TcpSocket,
Expand Down

0 comments on commit 09db168

Please sign in to comment.