diff --git a/src/lib.rs b/src/lib.rs index 2e47c49..1f6fbab 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -943,7 +943,7 @@ impl Default for Mode { pub mod bus; mod inactive_w5500; mod network; -mod register; +pub mod register; mod socket; mod udp; pub mod uninitialized_w5500; diff --git a/src/register.rs b/src/register.rs index 23b2be6..84131ed 100644 --- a/src/register.rs +++ b/src/register.rs @@ -52,11 +52,13 @@ pub mod socketn { Open = 0x01, Send = 0x20, Receive = 0x40, + Close = 0x10, } pub const INTERRUPT: u16 = 0x02; #[repr(u8)] pub enum Interrupt { + All = 0b11111111u8, SendOk = 0b010000u8, Receive = 0b00100u8, } diff --git a/src/udp/mod.rs b/src/udp/mod.rs index ec627a1..098e5bf 100644 --- a/src/udp/mod.rs +++ b/src/udp/mod.rs @@ -26,7 +26,8 @@ impl mut w5500: W5500, socket: SocketImpl, ) -> Result { - socket.reset_interrupt(&mut w5500.bus, socketn::Interrupt::SendOk)?; + socket.command(&mut w5500.bus, socketn::Command::Close)?; + socket.reset_interrupt(&mut w5500.bus, socketn::Interrupt::All)?; socket.set_source_port(&mut w5500.bus, port)?; socket.set_mode(&mut w5500.bus, socketn::Protocol::Udp)?; socket.command(&mut w5500.bus, socketn::Command::Open)?; diff --git a/src/udp/outgoing_packet.rs b/src/udp/outgoing_packet.rs index 8ebd612..f2596fd 100644 --- a/src/udp/outgoing_packet.rs +++ b/src/udp/outgoing_packet.rs @@ -6,7 +6,7 @@ use crate::udp::UdpSocket; use crate::IpAddress; pub struct OutgoingPacket { - udp_socket: UdpSocket, + pub udp_socket: UdpSocket, data_length: u16, } diff --git a/src/uninitialized_w5500.rs b/src/uninitialized_w5500.rs index cd5159f..5374251 100644 --- a/src/uninitialized_w5500.rs +++ b/src/uninitialized_w5500.rs @@ -62,6 +62,17 @@ impl UninitializedW5500 { mode_options: Mode, ) -> Result<(W5500, OwnedSockets), InitializeError> { self.assert_chip_version(0x4)?; + + // RESET + /* + let mut mode = [0b10000000]; + self + .bus + .transfer_frame(register::COMMON, register::common::MODE, true, &mut mode) + .map_err(|e| InitializeError::SpiError(e))?; + */ + + self.set_mode(mode_options) .map_err(|e| InitializeError::SpiError(e))?; network