Updating embedded-nal version

This commit is contained in:
Ryan Summers 2024-07-05 14:35:26 +02:00 committed by kellerkindt
commit 09db1687dd
4 changed files with 20 additions and 12 deletions

View file

@ -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

View file

@ -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"

View file

@ -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,
}
}
}

View file

@ -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<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)
@ -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;
@ -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.
@ -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,