feat: derive defmt::Format for more structs and errors
Signed-off-by: Lachezar Lechev <elpiel93@gmail.com>
This commit is contained in:
parent
1b2ba0bfab
commit
c3f79c96ed
12 changed files with 40 additions and 6 deletions
|
|
@ -9,6 +9,8 @@ use crate::bus::Bus;
|
|||
const WRITE_MODE_MASK: u8 = 0b00000_1_00;
|
||||
|
||||
// TODO This name is not ideal, should be renamed to VDM
|
||||
#[derive(Debug)]
|
||||
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
|
||||
pub struct FourWire<Spi: Transfer<u8> + Write<u8>, ChipSelect: OutputPin> {
|
||||
cs: ChipSelect,
|
||||
spi: Spi,
|
||||
|
|
|
|||
|
|
@ -9,6 +9,8 @@ use crate::bus::{Bus, FourWire, FourWireError};
|
|||
// TODO This name is not ideal, should be renamed to VDM
|
||||
/// This is just like [crate::bus::FourWire] but takes references instead of ownership
|
||||
/// for the SPI bus and the ChipSelect pin
|
||||
#[derive(Debug)]
|
||||
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
|
||||
pub struct FourWireRef<'a, Spi: Transfer<u8> + Write<u8>, ChipSelect: OutputPin>(
|
||||
FourWire<SpiRef<'a, Spi>, OutputPinRef<'a, ChipSelect>>,
|
||||
);
|
||||
|
|
@ -43,6 +45,7 @@ impl<Spi: Transfer<u8> + Write<u8>, ChipSelect: OutputPin> Bus
|
|||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
|
||||
pub struct SpiRef<'a, Spi: Transfer<u8> + Write<u8>>(pub &'a mut Spi);
|
||||
|
||||
impl<'a, Spi: Transfer<u8> + Write<u8>> Transfer<u8> for SpiRef<'a, Spi> {
|
||||
|
|
@ -64,6 +67,7 @@ impl<'a, Spi: Transfer<u8> + Write<u8>> Write<u8> for SpiRef<'a, Spi> {
|
|||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
|
||||
pub struct OutputPinRef<'a, P: OutputPin>(pub &'a mut P);
|
||||
|
||||
impl<'a, P: OutputPin> OutputPin for OutputPinRef<'a, P> {
|
||||
|
|
|
|||
|
|
@ -12,6 +12,8 @@ const FIXED_DATA_LENGTH_MODE_2: u8 = 0b000000_10;
|
|||
const FIXED_DATA_LENGTH_MODE_4: u8 = 0b000000_11;
|
||||
|
||||
// TODO This name is not ideal, should be renamed to FDM
|
||||
#[derive(Debug)]
|
||||
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
|
||||
pub struct ThreeWire<Spi: Transfer<u8> + Write<u8>> {
|
||||
spi: Spi,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,6 +19,8 @@ impl<E> From<E> for ResetError<E> {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
|
||||
pub(crate) struct DeviceState<HostImpl: Host> {
|
||||
host: HostImpl,
|
||||
sockets: [u8; 1],
|
||||
|
|
@ -104,6 +106,8 @@ impl<SpiBus: Bus, HostImpl: Host> Device<SpiBus, HostImpl> {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
|
||||
pub struct InactiveDevice<HostImpl: Host>(DeviceState<HostImpl>);
|
||||
|
||||
impl<HostImpl: Host> InactiveDevice<HostImpl> {
|
||||
|
|
|
|||
|
|
@ -2,6 +2,8 @@ use crate::bus::Bus;
|
|||
use crate::host::Host;
|
||||
use crate::MacAddress;
|
||||
|
||||
#[derive(Debug)]
|
||||
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
|
||||
pub struct Dhcp {
|
||||
// settings: HostConfig,
|
||||
// current: HostConfig,
|
||||
|
|
|
|||
|
|
@ -3,6 +3,8 @@ use crate::host::{Host, HostConfig};
|
|||
use crate::MacAddress;
|
||||
use embedded_nal::Ipv4Addr;
|
||||
|
||||
#[derive(Debug)]
|
||||
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
|
||||
pub struct Manual {
|
||||
is_setup: bool,
|
||||
settings: HostConfig,
|
||||
|
|
|
|||
|
|
@ -8,10 +8,15 @@ use crate::register;
|
|||
use crate::MacAddress;
|
||||
use embedded_nal::Ipv4Addr;
|
||||
|
||||
#[derive(Debug)]
|
||||
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
|
||||
pub struct HostConfig {
|
||||
mac: MacAddress,
|
||||
#[cfg_attr(feature = "defmt", defmt(Display2Format))]
|
||||
ip: Ipv4Addr,
|
||||
#[cfg_attr(feature = "defmt", defmt(Display2Format))]
|
||||
gateway: Ipv4Addr,
|
||||
#[cfg_attr(feature = "defmt", defmt(Display2Format))]
|
||||
subnet: Ipv4Addr,
|
||||
}
|
||||
|
||||
|
|
|
|||
15
src/lib.rs
15
src/lib.rs
|
|
@ -22,7 +22,8 @@ pub use uninitialized_device::UninitializedDevice;
|
|||
|
||||
/// Settings for wake on LAN. Allows the W5500 to optionally emit an interrupt upon receiving a packet
|
||||
#[repr(u8)]
|
||||
#[derive(Copy, Clone, PartialOrd, PartialEq)]
|
||||
#[derive(Copy, Clone, Debug, PartialOrd, PartialEq)]
|
||||
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
|
||||
pub enum OnWakeOnLan {
|
||||
InvokeInterrupt = 0b00100000,
|
||||
Ignore = 0b00000000,
|
||||
|
|
@ -30,7 +31,8 @@ pub enum OnWakeOnLan {
|
|||
|
||||
/// Settings for ping. Allows the W5500 to respond to or ignore network ping requests
|
||||
#[repr(u8)]
|
||||
#[derive(Copy, Clone, PartialOrd, PartialEq)]
|
||||
#[derive(Copy, Clone, Debug, PartialOrd, PartialEq)]
|
||||
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
|
||||
pub enum OnPingRequest {
|
||||
Respond = 0b00000000,
|
||||
Ignore = 0b00010000,
|
||||
|
|
@ -39,20 +41,23 @@ pub enum OnPingRequest {
|
|||
/// Use [ConnectionType::PPoE] when talking
|
||||
/// to an ADSL modem. Otherwise use [ConnectionType::Ethernet]
|
||||
#[repr(u8)]
|
||||
#[derive(Copy, Clone, PartialOrd, PartialEq)]
|
||||
#[derive(Copy, Clone, Debug, PartialOrd, PartialEq)]
|
||||
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
|
||||
pub enum ConnectionType {
|
||||
PPoE = 0b00001000,
|
||||
Ethernet = 0b00000000,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, PartialOrd, PartialEq)]
|
||||
#[derive(Copy, Clone, Debug, PartialOrd, PartialEq)]
|
||||
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
|
||||
#[repr(u8)]
|
||||
pub enum ArpResponses {
|
||||
Cache = 0b00000000,
|
||||
DropAfterUse = 0b00000010,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, PartialEq)]
|
||||
#[derive(Copy, Clone, Debug, PartialEq)]
|
||||
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
|
||||
pub struct Mode {
|
||||
pub on_wake_on_lan: OnWakeOnLan,
|
||||
pub on_ping_request: OnPingRequest,
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ pub use embedded_nal::Ipv4Addr;
|
|||
///
|
||||
/// This is an EUI-48 MAC address (previously called MAC-48).
|
||||
#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Debug, Hash, Default)]
|
||||
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
|
||||
pub struct MacAddress {
|
||||
/// Octets of the MAC address.
|
||||
pub octets: [u8; 6],
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
use crate::{bus::Bus, register, socket::Socket, uninitialized_device::InitializeError};
|
||||
|
||||
/// The W5500 operating in MACRAW mode to send and receive ethernet frames.
|
||||
#[derive(Debug)]
|
||||
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
|
||||
pub struct RawDevice<SpiBus: Bus> {
|
||||
bus: SpiBus,
|
||||
raw_socket: Socket,
|
||||
|
|
|
|||
|
|
@ -11,11 +11,12 @@ use embedded_nal::{nb, IpAddr, Ipv4Addr, SocketAddr, SocketAddrV4, TcpClientStac
|
|||
use core::convert::TryFrom;
|
||||
|
||||
#[derive(Debug)]
|
||||
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
|
||||
pub enum TcpSocketError<E: core::fmt::Debug> {
|
||||
NoMoreSockets,
|
||||
NotReady,
|
||||
UnsupportedAddress,
|
||||
Other(E),
|
||||
Other(#[cfg_attr(feature = "defmt", defmt(Debug2Format))] E),
|
||||
UnsupportedMode,
|
||||
}
|
||||
|
||||
|
|
@ -25,6 +26,8 @@ impl<E: core::fmt::Debug> From<E> for TcpSocketError<E> {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
|
||||
pub struct TcpSocket {
|
||||
socket: Socket,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,6 +9,8 @@ use crate::raw_device::RawDevice;
|
|||
use crate::register;
|
||||
use crate::{MacAddress, Mode};
|
||||
|
||||
#[derive(Debug)]
|
||||
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
|
||||
pub struct UninitializedDevice<SpiBus: Bus> {
|
||||
bus: SpiBus,
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue