Added Network trait that keeps track of network settings and has DHCP/Manual options for setting up options
This commit is contained in:
parent
7dd4c04fe4
commit
fd9e861dde
7 changed files with 145 additions and 21 deletions
22
src/w5500.rs
22
src/w5500.rs
|
|
@ -1,17 +1,19 @@
|
|||
use crate::inactive_w5500::InactiveW5500;
|
||||
use crate::uninitialized_w5500::UninitializedW5500;
|
||||
use bus::{ActiveBus, ActiveFourWire, ActiveThreeWire, FourWire, ThreeWire};
|
||||
use network::Network;
|
||||
use embedded_hal::digital::v2::OutputPin;
|
||||
use embedded_hal::spi::FullDuplex;
|
||||
use register;
|
||||
|
||||
pub struct W5500<SpiBus: ActiveBus> {
|
||||
pub struct W5500<SpiBus: ActiveBus, NetworkImpl: Network> {
|
||||
bus: SpiBus,
|
||||
network: NetworkImpl,
|
||||
}
|
||||
|
||||
impl<SpiBus: ActiveBus> W5500<SpiBus> {
|
||||
pub fn new(bus: SpiBus) -> Self {
|
||||
W5500 { bus }
|
||||
impl<SpiBus: ActiveBus, NetworkImpl: Network> W5500<SpiBus, NetworkImpl> {
|
||||
pub fn new(bus: SpiBus, network: NetworkImpl) -> Self {
|
||||
W5500 { bus, network }
|
||||
}
|
||||
pub fn reset(mut self) -> Result<UninitializedW5500<SpiBus>, SpiBus::Error> {
|
||||
// TODO accept all sockets back
|
||||
|
|
@ -29,16 +31,16 @@ impl<SpiBus: ActiveBus> W5500<SpiBus> {
|
|||
//TODO open_udp_socket
|
||||
}
|
||||
|
||||
impl<Spi: FullDuplex<u8>, ChipSelect: OutputPin> W5500<ActiveFourWire<Spi, ChipSelect>> {
|
||||
pub fn deactivate(self) -> (InactiveW5500<FourWire<ChipSelect>>, Spi) {
|
||||
impl<Spi: FullDuplex<u8>, ChipSelect: OutputPin, NetworkImpl: Network> W5500<ActiveFourWire<Spi, ChipSelect>, NetworkImpl> {
|
||||
pub fn deactivate(self) -> (InactiveW5500<FourWire<ChipSelect>, NetworkImpl>, Spi) {
|
||||
let (bus, spi) = self.bus.deactivate();
|
||||
(InactiveW5500::new(bus), spi)
|
||||
(InactiveW5500::new(bus, self.network), spi)
|
||||
}
|
||||
}
|
||||
|
||||
impl<Spi: FullDuplex<u8>> W5500<ActiveThreeWire<Spi>> {
|
||||
pub fn deactivate(self) -> (InactiveW5500<ThreeWire>, 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), spi)
|
||||
(InactiveW5500::new(bus, self.network), spi)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue