w5500_ll/
eh1.rs

1//! Blocking implementations of the [`Registers`] trait using the
2//! [`embedded-hal`] version 1 blocking SPI traits.
3//!
4//! [`embedded-hal`]: https://github.com/rust-embedded/embedded-hal
5//! [`Registers`]: crate::Registers
6
7pub use eh1 as embedded_hal;
8
9#[cfg(feature = "eha1")]
10pub use eha1 as embedded_hal_async;
11
12pub mod fdm;
13pub mod vdm;
14
15/// Reset the W5500 using the reset pin.
16///
17/// This function performs the following sequence:
18///
19/// 1. Set the reset pin low.
20/// 2. Wait 1 ms (2x longer than the minimum reset cycle time of 500 µs).
21/// 3. Set the reset pin high.
22/// 4. Wait 2 ms (2x longer than the maximum PLL lock time of 1 ms).
23///
24/// # Example
25///
26/// ```
27/// # use ehm::eh1 as hal;
28/// # let mut delay = hal::delay::NoopDelay::new();
29/// # let mut reset_pin = hal::pin::Mock::new(&[
30/// #    hal::pin::Transaction::set(hal::pin::State::Low),
31/// #    hal::pin::Transaction::set(hal::pin::State::High),
32/// # ]);
33/// w5500_ll::eh1::reset(&mut reset_pin, &mut delay)?;
34/// # reset_pin.done();
35/// # Ok::<(), hal::MockError>(())
36/// ```
37pub fn reset<P, D, E>(pin: &mut P, delay: &mut D) -> Result<(), E>
38where
39    P: eh1::digital::OutputPin<Error = E>,
40    D: eh1::delay::DelayNs,
41{
42    pin.set_low()?;
43    delay.delay_us(1000);
44    pin.set_high()?;
45    delay.delay_us(2000);
46    Ok(())
47}
48
49/// Recommended W5500 SPI mode.
50///
51/// The W5500 may operate in SPI mode 0 or SPI mode 3.
52pub const MODE: eh1::spi::Mode = eh1::spi::Mode {
53    polarity: eh1::spi::Polarity::IdleLow,
54    phase: eh1::spi::Phase::CaptureOnFirstTransition,
55};