w5500_ll/
eh0.rs

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