Skip to content

Commit

Permalink
embedded-hal: 0.2 -> 1
Browse files Browse the repository at this point in the history
  • Loading branch information
newAM committed Aug 8, 2022
1 parent 3572a71 commit 0fd05a6
Show file tree
Hide file tree
Showing 17 changed files with 928 additions and 1,403 deletions.
1 change: 1 addition & 0 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
test-all = "test --features std,log,embedded-hal,time,chrono,num-rational,w5500-tls"
test-dhcp = "test -p w5500-dhcp --features log,std"
test-ll = "test -p w5500-ll --features embedded-hal,std"
test-hl = "test -p w5500-hl --features embedded-hal,std"
test-mqtt = "test -p w5500-mqtt --features log,std,w5500-tls"
test-regsim = "test -p w5500-regsim"
test-sntp = "test -p w5500-sntp --features std,log,embedded-hal,time,chrono,num-rational"
Expand Down
3 changes: 2 additions & 1 deletion hl/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ defmt = { version = "0.3", optional = true }
w5500-ll = { path = "../ll", version = "0.10" }

[dev-dependencies]
embedded-hal-mock = "0.8"
embedded-hal-mock = { git = "https://github.com/newAM/embedded-hal-mock", branch = "1-alpha" }
embedded-hal = "1.0.0-alpha.8"
w5500-ll = { path = "../ll", version = "0.10", features = ["embedded-hal", "defmt"] }

[package.metadata.docs.rs]
Expand Down
37 changes: 16 additions & 21 deletions hl/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
//!
//! ```no_run
//! # use embedded_hal_mock as h;
//! # let mut w5500 = w5500_ll::blocking::vdm::W5500::new(h::spi::Mock::new(&[]), h::pin::Mock::new(&[]));
//! # let mut w5500 = w5500_ll::eh::vdm::W5500::new(h::spi::Mock::new(&[]));
//! use w5500_hl::ll::{
//! net::{Ipv4Addr, SocketAddrV4},
//! Registers,
Expand All @@ -46,14 +46,14 @@
//! let data: [u8; 4] = [0, 1, 2, 3];
//! let destination = SocketAddrV4::new(Ipv4Addr::new(192, 168, 2, 4), 8080);
//! let tx_bytes = w5500.udp_send_to(Sn0, &data, &destination)?;
//! # Ok::<(), w5500_hl::ll::blocking::vdm::Error<_, _>>(())
//! # Ok::<(), embedded_hal::spi::ErrorKind>(())
//! ```
//!
//! TCP streams (client)
//!
//! ```no_run
//! # use embedded_hal_mock as h;
//! # let mut w5500 = w5500_ll::blocking::vdm::W5500::new(h::spi::Mock::new(&[]), h::pin::Mock::new(&[]));
//! # let mut w5500 = w5500_ll::eh::vdm::W5500::new(h::spi::Mock::new(&[]));
//! use w5500_hl::ll::{
//! net::{Ipv4Addr, SocketAddrV4},
//! Registers, Sn,
Expand All @@ -66,14 +66,14 @@
//!
//! // initiate a TCP connection to a MQTT server
//! w5500.tcp_connect(MQTT_SOCKET, MQTT_SOURCE_PORT, &MQTT_SERVER)?;
//! # Ok::<(), w5500_hl::ll::blocking::vdm::Error<_, _>>(())
//! # Ok::<(), embedded_hal::spi::ErrorKind>(())
//! ```
//!
//! TCP listeners (server)
//!
//! ```no_run
//! # use embedded_hal_mock as h;
//! # let mut w5500 = w5500_ll::blocking::vdm::W5500::new(h::spi::Mock::new(&[]), h::pin::Mock::new(&[]));
//! # let mut w5500 = w5500_ll::eh::vdm::W5500::new(h::spi::Mock::new(&[]));
//! use w5500_hl::ll::{
//! net::{Ipv4Addr, SocketAddrV4},
//! Registers, Sn,
Expand All @@ -85,7 +85,7 @@
//!
//! // serve HTTP
//! w5500.tcp_listen(HTTP_SOCKET, HTTP_PORT)?;
//! # Ok::<(), w5500_hl::ll::blocking::vdm::Error<_, _>>(())
//! # Ok::<(), embedded_hal::spi::ErrorKind>(())
//! ```
//!
//! [`Registers`]: https://docs.rs/w5500-ll/latest/w5500_ll/trait.Registers.html
Expand Down Expand Up @@ -195,14 +195,13 @@ pub trait Common: Registers {
/// # Example
///
/// ```no_run
/// # use embedded_hal_mock as h;
/// # let mut w5500 = w5500_ll::blocking::vdm::W5500::new(h::spi::Mock::new(&[]), h::pin::Mock::new(&[]));
/// # let mut w5500 = w5500_ll::eh::vdm::W5500::new(embedded_hal_mock::spi::Mock::new(&[]));
/// use w5500_hl::ll::{Registers, Sn::Sn0};
/// use w5500_hl::{Common, Udp};
///
/// w5500.udp_bind(Sn0, 8080)?;
/// let local_addr = w5500.local_addr(Sn0)?;
/// # Ok::<(), w5500_hl::ll::blocking::vdm::Error<_, _>>(())
/// # Ok::<(), embedded_hal::spi::ErrorKind>(())
/// ```
fn local_addr(&mut self, sn: Sn) -> Result<SocketAddrV4, Self::Error> {
let ip: Ipv4Addr = self.sipr()?;
Expand All @@ -218,13 +217,12 @@ pub trait Common: Registers {
/// # Example
///
/// ```no_run
/// # use embedded_hal_mock as h;
/// # let mut w5500 = w5500_ll::blocking::vdm::W5500::new(h::spi::Mock::new(&[]), h::pin::Mock::new(&[]));
/// # let mut w5500 = w5500_ll::eh::vdm::W5500::new(embedded_hal_mock::spi::Mock::new(&[]));
/// use w5500_hl::ll::{Registers, Sn::Sn0};
/// use w5500_hl::Common;
///
/// w5500.close(Sn0)?;
/// # Ok::<(), w5500_hl::ll::blocking::vdm::Error<_, _>>(())
/// # Ok::<(), embedded_hal::spi::ErrorKind>(())
/// ```
fn close(&mut self, sn: Sn) -> Result<(), Self::Error> {
self.set_sn_cr(sn, SocketCommand::Close)
Expand All @@ -238,16 +236,15 @@ pub trait Common: Registers {
/// # Example
///
/// ```no_run
/// # use embedded_hal_mock as h;
/// # let mut w5500 = w5500_ll::blocking::vdm::W5500::new(h::spi::Mock::new(&[]), h::pin::Mock::new(&[]));
/// # let mut w5500 = w5500_ll::eh::vdm::W5500::new(embedded_hal_mock::spi::Mock::new(&[]));
/// use w5500_hl::ll::{Registers, Sn::Sn0};
/// use w5500_hl::{Common, Udp};
///
/// w5500.close(Sn0)?;
/// assert!(w5500.is_state_closed(Sn0)?);
/// w5500.udp_bind(Sn0, 8080)?;
/// assert!(!w5500.is_state_closed(Sn0)?);
/// # Ok::<(), w5500_hl::ll::blocking::vdm::Error<_, _>>(())
/// # Ok::<(), embedded_hal::spi::ErrorKind>(())
/// ```
///
/// [Closed]: w5500_ll::SocketStatus::Closed
Expand Down Expand Up @@ -278,16 +275,15 @@ pub trait Common: Registers {
/// # Example
///
/// ```no_run
/// # use embedded_hal_mock as h;
/// # let mut w5500 = w5500_ll::blocking::vdm::W5500::new(h::spi::Mock::new(&[]), h::pin::Mock::new(&[]));
/// # let mut w5500 = w5500_ll::eh::vdm::W5500::new(embedded_hal_mock::spi::Mock::new(&[]));
/// use w5500_hl::ll::{Registers, Sn::Sn0};
/// use w5500_hl::{Common, Udp};
///
/// w5500.close(Sn0)?;
/// assert!(w5500.is_state_tcp(Sn0)?);
/// w5500.udp_bind(Sn0, 8080)?;
/// assert!(!w5500.is_state_tcp(Sn0)?);
/// # Ok::<(), w5500_hl::ll::blocking::vdm::Error<_, _>>(())
/// # Ok::<(), embedded_hal::spi::ErrorKind>(())
/// ```
///
/// [RFC 793]: https://tools.ietf.org/html/rfc793
Expand Down Expand Up @@ -327,16 +323,15 @@ pub trait Common: Registers {
/// # Example
///
/// ```no_run
/// # use embedded_hal_mock as h;
/// # let mut w5500 = w5500_ll::blocking::vdm::W5500::new(h::spi::Mock::new(&[]), h::pin::Mock::new(&[]));
/// # let mut w5500 = w5500_ll::eh::vdm::W5500::new(embedded_hal_mock::spi::Mock::new(&[]));
/// use w5500_hl::ll::{Registers, Sn::Sn0};
/// use w5500_hl::{Common, Udp};
///
/// w5500.close(Sn0)?;
/// assert!(!w5500.is_state_udp(Sn0)?);
/// w5500.udp_bind(Sn0, 8080)?;
/// assert!(w5500.is_state_udp(Sn0)?);
/// # Ok::<(), w5500_hl::ll::blocking::vdm::Error<_, _>>(())
/// # Ok::<(), embedded_hal::spi::ErrorKind>(())
/// ```
///
/// [Udp]: w5500_ll::SocketStatus::Udp
Expand Down
37 changes: 16 additions & 21 deletions hl/src/tcp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,12 @@ use w5500_ll::{
///
/// ```no_run
/// # use embedded_hal_mock as h;
/// # let mut w5500 = w5500_ll::blocking::vdm::W5500::new(h::spi::Mock::new(&[]), h::pin::Mock::new(&[]));
/// # let mut w5500 = w5500_ll::eh::vdm::W5500::new(h::spi::Mock::new(&[]));
/// use w5500_hl::{
/// io::Read,
/// ll::{Registers, Sn, SocketInterrupt},
/// net::{Ipv4Addr, SocketAddrV4},
/// Tcp,
/// TcpReader,
/// io::Read,
/// Tcp, TcpReader,
/// };
///
/// const MQTT_SOCKET: Sn = Sn::Sn0;
Expand Down Expand Up @@ -133,11 +132,12 @@ impl<'a, W5500: Registers> Read<W5500::Error> for TcpReader<'a, W5500> {
///
/// ```no_run
/// # use embedded_hal_mock as h;
/// # let mut w5500 = w5500_ll::blocking::vdm::W5500::new(h::spi::Mock::new(&[]), h::pin::Mock::new(&[]));
/// # let mut w5500 = w5500_ll::eh::vdm::W5500::new(h::spi::Mock::new(&[]));
/// use w5500_hl::{
/// io::Write,
/// ll::{Registers, Sn, SocketInterrupt},
/// net::{Ipv4Addr, SocketAddrV4},
/// Tcp, TcpWriter, io::Write,
/// Tcp, TcpWriter,
/// };
///
/// const MQTT_SOCKET: Sn = Sn::Sn0;
Expand Down Expand Up @@ -256,8 +256,7 @@ pub trait Tcp: Registers {
/// # Example
///
/// ```no_run
/// # use embedded_hal_mock as h;
/// # let mut w5500 = w5500_ll::blocking::vdm::W5500::new(h::spi::Mock::new(&[]), h::pin::Mock::new(&[]));
/// # let mut w5500 = w5500_ll::eh::vdm::W5500::new(embedded_hal_mock::spi::Mock::new(&[]));
/// use w5500_hl::{
/// ll::{Registers, Sn, SocketInterrupt},
/// net::{Ipv4Addr, SocketAddrV4},
Expand All @@ -284,7 +283,7 @@ pub trait Tcp: Registers {
/// break;
/// }
/// }
/// # Ok::<(), w5500_hl::ll::blocking::vdm::Error<_, _>>(())
/// # Ok::<(), embedded_hal::spi::ErrorKind>(())
/// ```
///
/// [`tcp_write`]: Tcp::tcp_write
Expand Down Expand Up @@ -336,8 +335,7 @@ pub trait Tcp: Registers {
/// Create an HTTP server.
///
/// ```no_run
/// # use embedded_hal_mock as h;
/// # let mut w5500 = w5500_ll::blocking::vdm::W5500::new(h::spi::Mock::new(&[]), h::pin::Mock::new(&[]));
/// # let mut w5500 = w5500_ll::eh::vdm::W5500::new(embedded_hal_mock::spi::Mock::new(&[]));
/// use w5500_hl::{
/// ll::{Registers, Sn, SocketInterrupt},
/// net::{Ipv4Addr, SocketAddrV4},
Expand Down Expand Up @@ -372,7 +370,7 @@ pub trait Tcp: Registers {
/// let filled_buf: &[u8] = &buf[..rx_bytes.into()];
///
/// // parse HTTP request here using filled_buf
/// # Ok::<(), w5500_hl::ll::blocking::vdm::Error<_, _>>(())
/// # Ok::<(), embedded_hal::spi::ErrorKind>(())
/// ```
///
/// [`tcp_write`]: Tcp::tcp_write
Expand Down Expand Up @@ -414,8 +412,7 @@ pub trait Tcp: Registers {
/// Send a MQTT CONNECT packet and read a CONNACK.
///
/// ```no_run
/// # use embedded_hal_mock as h;
/// # let mut w5500 = w5500_ll::blocking::vdm::W5500::new(h::spi::Mock::new(&[]), h::pin::Mock::new(&[]));
/// # let mut w5500 = w5500_ll::eh::vdm::W5500::new(embedded_hal_mock::spi::Mock::new(&[]));
/// use w5500_hl::{
/// ll::{Registers, Sn, SocketInterrupt},
/// net::{Ipv4Addr, SocketAddrV4},
Expand All @@ -441,7 +438,7 @@ pub trait Tcp: Registers {
/// let mut buf = [0; 10];
/// let rx_bytes: u16 = w5500.tcp_read(MQTT_SOCKET, &mut buf)?;
/// let filled_buf = &buf[..rx_bytes.into()];
/// # Ok::<(), w5500_hl::ll::blocking::vdm::Error<_, _>>(())
/// # Ok::<(), embedded_hal::spi::ErrorKind>(())
/// ```
///
/// [`Established`]: w5500_ll::SocketStatus::Established
Expand Down Expand Up @@ -476,8 +473,7 @@ pub trait Tcp: Registers {
/// Send a MQTT CONNECT packet.
///
/// ```no_run
/// # use embedded_hal_mock as h;
/// # let mut w5500 = w5500_ll::blocking::vdm::W5500::new(h::spi::Mock::new(&[]), h::pin::Mock::new(&[]));
/// # let mut w5500 = w5500_ll::eh::vdm::W5500::new(embedded_hal_mock::spi::Mock::new(&[]));
/// use w5500_hl::{
/// ll::{Registers, Sn, SocketInterrupt},
/// net::{Ipv4Addr, SocketAddrV4},
Expand All @@ -497,7 +493,7 @@ pub trait Tcp: Registers {
/// ];
/// let tx_bytes: u16 = w5500.tcp_write(MQTT_SOCKET, &CONNECT)?;
/// assert_eq!(usize::from(tx_bytes), CONNECT.len());
/// # Ok::<(), w5500_hl::ll::blocking::vdm::Error<_, _>>(())
/// # Ok::<(), embedded_hal::spi::ErrorKind>(())
/// ```
///
/// [`Established`]: w5500_ll::SocketStatus::Established
Expand Down Expand Up @@ -537,8 +533,7 @@ pub trait Tcp: Registers {
/// Connect and disconnect from a MQTT server.
///
/// ```no_run
/// # use embedded_hal_mock as h;
/// # let mut w5500 = w5500_ll::blocking::vdm::W5500::new(h::spi::Mock::new(&[]), h::pin::Mock::new(&[]));
/// # let mut w5500 = w5500_ll::eh::vdm::W5500::new(embedded_hal_mock::spi::Mock::new(&[]));
/// use w5500_hl::{
/// ll::{Registers, Sn, SocketInterrupt},
/// net::{Ipv4Addr, SocketAddrV4},
Expand All @@ -554,7 +549,7 @@ pub trait Tcp: Registers {
/// // ... wait for a CON interrupt
///
/// w5500.tcp_disconnect(MQTT_SOCKET)?;
/// # Ok::<(), w5500_hl::ll::blocking::vdm::Error<_, _>>(())
/// # Ok::<(), embedded_hal::spi::ErrorKind>(())
/// ```
///
/// [`Closed`]: w5500_ll::SocketStatus::Closed
Expand Down
Loading

0 comments on commit 0fd05a6

Please sign in to comment.