Stubbed UdpSocket struct, added Socket structs

This commit is contained in:
Jonah Dahlquist 2019-08-13 20:03:02 -05:00 committed by Jonah Dahlquist
commit b30e4d0d34
7 changed files with 100 additions and 15 deletions

View file

@ -5,18 +5,38 @@ use embedded_hal::digital::v2::OutputPin;
use embedded_hal::spi::FullDuplex;
use network::Network;
use register;
use socket::{OwnedSockets, Socket, Sockets};
use udp::UdpSocket;
pub struct W5500<SpiBus: ActiveBus, NetworkImpl: Network> {
bus: SpiBus,
network: NetworkImpl,
sockets: OwnedSockets,
}
impl<SpiBus: ActiveBus, NetworkImpl: Network> W5500<SpiBus, NetworkImpl> {
pub fn new(bus: SpiBus, network: NetworkImpl) -> Self {
W5500 { bus, network }
pub fn new(bus: SpiBus, network: NetworkImpl, sockets: OwnedSockets) -> Self {
W5500 {
bus,
network,
sockets,
}
}
pub fn sockets(&mut self) -> Sockets {
(
&mut self.sockets.0,
&mut self.sockets.1,
&mut self.sockets.2,
&mut self.sockets.3,
&mut self.sockets.4,
&mut self.sockets.5,
&mut self.sockets.6,
&mut self.sockets.7,
)
}
pub fn reset(mut self) -> Result<UninitializedW5500<SpiBus>, SpiBus::Error> {
// TODO accept all sockets back
self.clear_mode()?;
Ok(UninitializedW5500::new(self.bus))
}
@ -30,7 +50,9 @@ impl<SpiBus: ActiveBus, NetworkImpl: Network> W5500<SpiBus, NetworkImpl> {
Ok(())
}
//TODO open_udp_socket
pub fn open_udp_socket<SocketImpl: Socket>(&self, socket: SocketImpl) -> UdpSocket<SocketImpl> {
UdpSocket { socket }
}
}
impl<Spi: FullDuplex<u8>, ChipSelect: OutputPin, NetworkImpl: Network>
@ -38,13 +60,13 @@ impl<Spi: FullDuplex<u8>, ChipSelect: OutputPin, NetworkImpl: Network>
{
pub fn deactivate(self) -> (InactiveW5500<FourWire<ChipSelect>, NetworkImpl>, Spi) {
let (bus, spi) = self.bus.deactivate();
(InactiveW5500::new(bus, self.network), spi)
(InactiveW5500::new(bus, self.network, self.sockets), spi)
}
}
impl<Spi: FullDuplex<u8>, NetworkImpl: Network> W5500<ActiveThreeWire<Spi>, NetworkImpl> {
pub fn deactivate(self) -> (InactiveW5500<ThreeWire, NetworkImpl>, Spi) {
let (bus, spi) = self.bus.deactivate();
(InactiveW5500::new(bus, self.network), spi)
(InactiveW5500::new(bus, self.network, self.sockets), spi)
}
}