Merge pull request #39 from LechevSpace/defmt-and-debug

Defmt
This commit is contained in:
Ryan Summers 2023-03-06 13:55:54 +01:00 committed by GitHub
commit 516bdae999
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
17 changed files with 69 additions and 15 deletions

View file

@ -11,7 +11,7 @@ jobs:
name: Check name: Check
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v3
- uses: actions-rs/toolchain@v1 - uses: actions-rs/toolchain@v1
with: with:
profile: minimal profile: minimal
@ -20,12 +20,13 @@ jobs:
- uses: actions-rs/cargo@v1 - uses: actions-rs/cargo@v1
with: with:
command: check command: check
args: --all-features
test: test:
name: Test Suite name: Test Suite
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v3
- uses: actions-rs/toolchain@v1 - uses: actions-rs/toolchain@v1
with: with:
profile: minimal profile: minimal
@ -34,12 +35,13 @@ jobs:
- uses: actions-rs/cargo@v1 - uses: actions-rs/cargo@v1
with: with:
command: test command: test
args: --all-features
fmt: fmt:
name: Rustfmt name: Rustfmt
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v3
- uses: actions-rs/toolchain@v1 - uses: actions-rs/toolchain@v1
with: with:
profile: minimal profile: minimal
@ -55,7 +57,7 @@ jobs:
name: Clippy name: Clippy
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v3
- uses: actions-rs/toolchain@v1 - uses: actions-rs/toolchain@v1
with: with:
profile: minimal profile: minimal

View file

@ -6,6 +6,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased] ## [Unreleased]
### Added
- Add `defmt` features for enabling `defmt::Format` to most structs and errors by [@elpiel](https://github.com/elpiel) ([#39](https://github.com/kellerkindt/w5500/issues/39))
## [0.4.1] - January 2nd, 2023 ## [0.4.1] - January 2nd, 2023
@ -14,7 +17,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Fix indexing for phy configuration register by [@Wassasin](https://github.com/Wassasin) ([#32](https://github.com/kellerkindt/w5500/issues/32)) - Fix indexing for phy configuration register by [@Wassasin](https://github.com/Wassasin) ([#32](https://github.com/kellerkindt/w5500/issues/32))
- Add support for MACRAW operation mode by [@ryan-summers](https://github.com/ryan-summers) ([#33](https://github.com/kellerkindt/w5500/issues/33)) - Add support for MACRAW operation mode by [@ryan-summers](https://github.com/ryan-summers) ([#33](https://github.com/kellerkindt/w5500/issues/33))
## [0.4.0] - January 22nd, 2022 ## [0.4.0] - January 22nd, 2022
### Added ### Added

View file

@ -17,6 +17,7 @@ embedded-nal = "0.6.0"
bit_field = "0.10.1" bit_field = "0.10.1"
derive-try-from-primitive = "1" derive-try-from-primitive = "1"
nb = "1.0.0" nb = "1.0.0"
defmt = { version = "0.3", optional = true }
[features] [features]
no-chip-version-assertion = [] no-chip-version-assertion = []

View file

@ -9,6 +9,8 @@ use crate::bus::Bus;
const WRITE_MODE_MASK: u8 = 0b00000_1_00; const WRITE_MODE_MASK: u8 = 0b00000_1_00;
// TODO This name is not ideal, should be renamed to VDM // 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> { pub struct FourWire<Spi: Transfer<u8> + Write<u8>, ChipSelect: OutputPin> {
cs: ChipSelect, cs: ChipSelect,
spi: Spi, spi: Spi,

View file

@ -9,6 +9,8 @@ use crate::bus::{Bus, FourWire, FourWireError};
// TODO This name is not ideal, should be renamed to VDM // TODO This name is not ideal, should be renamed to VDM
/// This is just like [crate::bus::FourWire] but takes references instead of ownership /// This is just like [crate::bus::FourWire] but takes references instead of ownership
/// for the SPI bus and the ChipSelect pin /// 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>( pub struct FourWireRef<'a, Spi: Transfer<u8> + Write<u8>, ChipSelect: OutputPin>(
FourWire<SpiRef<'a, Spi>, OutputPinRef<'a, ChipSelect>>, FourWire<SpiRef<'a, Spi>, OutputPinRef<'a, ChipSelect>>,
); );
@ -43,6 +45,7 @@ impl<Spi: Transfer<u8> + Write<u8>, ChipSelect: OutputPin> Bus
} }
#[derive(Debug)] #[derive(Debug)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct SpiRef<'a, Spi: Transfer<u8> + Write<u8>>(pub &'a mut Spi); 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> { 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)] #[derive(Debug)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct OutputPinRef<'a, P: OutputPin>(pub &'a mut P); pub struct OutputPinRef<'a, P: OutputPin>(pub &'a mut P);
impl<'a, P: OutputPin> OutputPin for OutputPinRef<'a, P> { impl<'a, P: OutputPin> OutputPin for OutputPinRef<'a, P> {

View file

@ -12,6 +12,8 @@ const FIXED_DATA_LENGTH_MODE_2: u8 = 0b000000_10;
const FIXED_DATA_LENGTH_MODE_4: u8 = 0b000000_11; const FIXED_DATA_LENGTH_MODE_4: u8 = 0b000000_11;
// TODO This name is not ideal, should be renamed to FDM // 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>> { pub struct ThreeWire<Spi: Transfer<u8> + Write<u8>> {
spi: Spi, spi: Spi,
} }

View file

@ -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> { pub(crate) struct DeviceState<HostImpl: Host> {
host: HostImpl, host: HostImpl,
sockets: [u8; 1], 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>); pub struct InactiveDevice<HostImpl: Host>(DeviceState<HostImpl>);
impl<HostImpl: Host> InactiveDevice<HostImpl> { impl<HostImpl: Host> InactiveDevice<HostImpl> {

View file

@ -2,9 +2,11 @@ use crate::bus::Bus;
use crate::host::Host; use crate::host::Host;
use crate::MacAddress; use crate::MacAddress;
#[derive(Debug)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct Dhcp { pub struct Dhcp {
// settings: HostConfig, // settings: HostConfig,
// current: HostConfig, // current: HostConfig,
} }
impl Dhcp { impl Dhcp {

View file

@ -3,6 +3,8 @@ use crate::host::{Host, HostConfig};
use crate::MacAddress; use crate::MacAddress;
use embedded_nal::Ipv4Addr; use embedded_nal::Ipv4Addr;
#[derive(Debug)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct Manual { pub struct Manual {
is_setup: bool, is_setup: bool,
settings: HostConfig, settings: HostConfig,

View file

@ -8,10 +8,15 @@ use crate::register;
use crate::MacAddress; use crate::MacAddress;
use embedded_nal::Ipv4Addr; use embedded_nal::Ipv4Addr;
#[derive(Debug)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct HostConfig { pub struct HostConfig {
mac: MacAddress, mac: MacAddress,
#[cfg_attr(feature = "defmt", defmt(Display2Format))]
ip: Ipv4Addr, ip: Ipv4Addr,
#[cfg_attr(feature = "defmt", defmt(Display2Format))]
gateway: Ipv4Addr, gateway: Ipv4Addr,
#[cfg_attr(feature = "defmt", defmt(Display2Format))]
subnet: Ipv4Addr, subnet: Ipv4Addr,
} }

View file

@ -14,15 +14,16 @@ pub mod udp;
mod uninitialized_device; mod uninitialized_device;
pub use device::{Device, DeviceRefMut, InactiveDevice}; pub use device::{Device, DeviceRefMut, InactiveDevice};
pub use host::{Dhcp, HostConfig, Manual}; pub use host::{Dhcp, Host, HostConfig, Manual};
pub use net::MacAddress; pub use net::MacAddress;
pub use uninitialized_device::UninitializedDevice; pub use uninitialized_device::{InitializeError, UninitializedDevice};
// TODO add better docs to all public items, add unit tests. // TODO add better docs to all public items, add unit tests.
/// Settings for wake on LAN. Allows the W5500 to optionally emit an interrupt upon receiving a packet /// Settings for wake on LAN. Allows the W5500 to optionally emit an interrupt upon receiving a packet
#[repr(u8)] #[repr(u8)]
#[derive(Copy, Clone, PartialOrd, PartialEq)] #[derive(Copy, Clone, Debug, PartialOrd, PartialEq)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub enum OnWakeOnLan { pub enum OnWakeOnLan {
InvokeInterrupt = 0b00100000, InvokeInterrupt = 0b00100000,
Ignore = 0b00000000, Ignore = 0b00000000,
@ -30,7 +31,8 @@ pub enum OnWakeOnLan {
/// Settings for ping. Allows the W5500 to respond to or ignore network ping requests /// Settings for ping. Allows the W5500 to respond to or ignore network ping requests
#[repr(u8)] #[repr(u8)]
#[derive(Copy, Clone, PartialOrd, PartialEq)] #[derive(Copy, Clone, Debug, PartialOrd, PartialEq)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub enum OnPingRequest { pub enum OnPingRequest {
Respond = 0b00000000, Respond = 0b00000000,
Ignore = 0b00010000, Ignore = 0b00010000,
@ -39,20 +41,23 @@ pub enum OnPingRequest {
/// Use [ConnectionType::PPoE] when talking /// Use [ConnectionType::PPoE] when talking
/// to an ADSL modem. Otherwise use [ConnectionType::Ethernet] /// to an ADSL modem. Otherwise use [ConnectionType::Ethernet]
#[repr(u8)] #[repr(u8)]
#[derive(Copy, Clone, PartialOrd, PartialEq)] #[derive(Copy, Clone, Debug, PartialOrd, PartialEq)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub enum ConnectionType { pub enum ConnectionType {
PPoE = 0b00001000, PPoE = 0b00001000,
Ethernet = 0b00000000, Ethernet = 0b00000000,
} }
#[derive(Copy, Clone, PartialOrd, PartialEq)] #[derive(Copy, Clone, Debug, PartialOrd, PartialEq)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
#[repr(u8)] #[repr(u8)]
pub enum ArpResponses { pub enum ArpResponses {
Cache = 0b00000000, Cache = 0b00000000,
DropAfterUse = 0b00000010, DropAfterUse = 0b00000010,
} }
#[derive(Copy, Clone, PartialEq)] #[derive(Copy, Clone, Debug, PartialEq)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct Mode { pub struct Mode {
pub on_wake_on_lan: OnWakeOnLan, pub on_wake_on_lan: OnWakeOnLan,
pub on_ping_request: OnPingRequest, pub on_ping_request: OnPingRequest,

View file

@ -18,6 +18,7 @@ pub use embedded_nal::Ipv4Addr;
/// ///
/// This is an EUI-48 MAC address (previously called MAC-48). /// This is an EUI-48 MAC address (previously called MAC-48).
#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Debug, Hash, Default)] #[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Debug, Hash, Default)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct MacAddress { pub struct MacAddress {
/// Octets of the MAC address. /// Octets of the MAC address.
pub octets: [u8; 6], pub octets: [u8; 6],

View file

@ -1,6 +1,8 @@
use crate::{bus::Bus, register, socket::Socket, uninitialized_device::InitializeError}; use crate::{bus::Bus, register, socket::Socket, uninitialized_device::InitializeError};
/// The W5500 operating in MACRAW mode to send and receive ethernet frames. /// 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> { pub struct RawDevice<SpiBus: Bus> {
bus: SpiBus, bus: SpiBus,
raw_socket: Socket, raw_socket: Socket,

View file

@ -2,6 +2,8 @@ use crate::bus::Bus;
use crate::register::socketn; use crate::register::socketn;
use embedded_nal::Ipv4Addr; use embedded_nal::Ipv4Addr;
#[derive(Debug)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct Socket { pub struct Socket {
pub index: u8, pub index: u8,
register: u8, register: u8,

View file

@ -11,11 +11,12 @@ use embedded_nal::{nb, IpAddr, Ipv4Addr, SocketAddr, SocketAddrV4, TcpClientStac
use core::convert::TryFrom; use core::convert::TryFrom;
#[derive(Debug)] #[derive(Debug)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub enum TcpSocketError<E: core::fmt::Debug> { pub enum TcpSocketError<E: core::fmt::Debug> {
NoMoreSockets, NoMoreSockets,
NotReady, NotReady,
UnsupportedAddress, UnsupportedAddress,
Other(E), Other(#[cfg_attr(feature = "defmt", defmt(Debug2Format))] E),
UnsupportedMode, 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 { pub struct TcpSocket {
socket: Socket, socket: Socket,
} }

View file

@ -6,6 +6,8 @@ use crate::socket::Socket;
use core::fmt::Debug; use core::fmt::Debug;
use embedded_nal::{nb, IpAddr, Ipv4Addr, SocketAddr, SocketAddrV4, UdpClientStack, UdpFullStack}; use embedded_nal::{nb, IpAddr, Ipv4Addr, SocketAddr, SocketAddrV4, UdpClientStack, UdpFullStack};
#[derive(Debug)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct UdpSocket { pub struct UdpSocket {
socket: Socket, socket: Socket,
} }
@ -76,6 +78,7 @@ impl UdpSocket {
} }
} }
/// Sets a new destination before performing the send operation.
fn send_to<SpiBus: Bus>( fn send_to<SpiBus: Bus>(
&mut self, &mut self,
bus: &mut SpiBus, bus: &mut SpiBus,
@ -86,6 +89,9 @@ impl UdpSocket {
self.send(bus, send_buffer) self.send(bus, send_buffer)
} }
/// Receive data and mutate the `receive_buffer`.
///
/// If [`Interrupt::Receive`] is not set, it will always return [`NbError::WouldBlock`].
fn receive<SpiBus: Bus>( fn receive<SpiBus: Bus>(
&mut self, &mut self,
bus: &mut SpiBus, bus: &mut SpiBus,
@ -137,13 +143,20 @@ impl UdpSocket {
self.socket.command(bus, socketn::Command::Close)?; self.socket.command(bus, socketn::Command::Close)?;
Ok(()) Ok(())
} }
/// returns the index of the socket
#[inline]
pub fn index(&self) -> u8 {
self.socket.index
}
} }
#[derive(Debug)] #[derive(Debug)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub enum UdpSocketError<E: Debug> { pub enum UdpSocketError<E: Debug> {
NoMoreSockets, NoMoreSockets,
UnsupportedAddress, UnsupportedAddress,
Other(E), Other(#[cfg_attr(feature = "defmt", defmt(Debug2Format))] E),
WriteTimeout, WriteTimeout,
} }

View file

@ -9,6 +9,8 @@ use crate::raw_device::RawDevice;
use crate::register; use crate::register;
use crate::{MacAddress, Mode}; use crate::{MacAddress, Mode};
#[derive(Debug)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct UninitializedDevice<SpiBus: Bus> { pub struct UninitializedDevice<SpiBus: Bus> {
bus: SpiBus, bus: SpiBus,
} }