Restored chip mode settings/common type structs

This commit is contained in:
Jonah Dahlquist 2019-08-08 12:10:25 -05:00 committed by Jonah Dahlquist
commit 3177bad09f

View file

@ -1,4 +1,4 @@
// #![no_std] #![no_std]
// #![allow(unused)] // #![allow(unused)]
#![deny(broken_intra_doc_links)] #![deny(broken_intra_doc_links)]
@ -22,62 +22,62 @@ extern crate nb;
// const FIXED_DATA_LENGTH_2_BYTES: u8 = 0b_10; // const FIXED_DATA_LENGTH_2_BYTES: u8 = 0b_10;
// const FIXED_DATA_LENGTH_4_BYTES: u8 = 0b_11; // const FIXED_DATA_LENGTH_4_BYTES: u8 = 0b_11;
// /// IP Address struct. Represents an IP address as a u8 array of length 4. Can be instantiated with `IpAddress::new` /// IP Address struct. Represents an IP address as a u8 array of length 4. Can be instantiated with `IpAddress::new`
// #[derive(Copy, Clone, PartialOrd, PartialEq, Default, Debug)] #[derive(Copy, Clone, PartialOrd, PartialEq, Default, Debug)]
// pub struct IpAddress { pub struct IpAddress {
// pub address: [u8; 4], pub address: [u8; 4],
// } }
// impl IpAddress { impl IpAddress {
// /// Instantiate a new IP address with u8s for each address fragment /// Instantiate a new IP address with u8s for each address fragment
// pub fn new(a0: u8, a1: u8, a2: u8, a3: u8) -> IpAddress { pub fn new(a0: u8, a1: u8, a2: u8, a3: u8) -> IpAddress {
// IpAddress { IpAddress {
// address: [a0, a1, a2, a3], address: [a0, a1, a2, a3],
// } }
// } }
// } }
// impl ::core::fmt::Display for IpAddress { impl ::core::fmt::Display for IpAddress {
// /// String formatter for IP addresses, useful for debugging output /// String formatter for IP addresses, useful for debugging output
// fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
// write!( write!(
// f, f,
// "{}.{}.{}.{}", "{}.{}.{}.{}",
// self.address[0], self.address[1], self.address[2], self.address[3], self.address[0], self.address[1], self.address[2], self.address[3],
// ) )
// } }
// } }
// /// MAC address struct. Represents a MAC address as a u8 array of length 6. Can be instantiated with `MacAddress::new` /// MAC address struct. Represents a MAC address as a u8 array of length 6. Can be instantiated with `MacAddress::new`
// #[derive(Copy, Clone, PartialOrd, PartialEq, Default, Debug)] #[derive(Copy, Clone, PartialOrd, PartialEq, Default, Debug)]
// pub struct MacAddress { pub struct MacAddress {
// pub address: [u8; 6], pub address: [u8; 6],
// } }
// impl MacAddress { impl MacAddress {
// /// Instantiate a new MAC address with u8s for each address fragment /// Instantiate a new MAC address with u8s for each address fragment
// pub fn new(a0: u8, a1: u8, a2: u8, a3: u8, a4: u8, a5: u8) -> MacAddress { pub fn new(a0: u8, a1: u8, a2: u8, a3: u8, a4: u8, a5: u8) -> MacAddress {
// MacAddress { MacAddress {
// address: [a0, a1, a2, a3, a4, a5], address: [a0, a1, a2, a3, a4, a5],
// } }
// } }
// } }
// impl ::core::fmt::Display for MacAddress { impl ::core::fmt::Display for MacAddress {
// /// String formatter for MAC addresses, useful for debugging output /// String formatter for MAC addresses, useful for debugging output
// fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
// write!( write!(
// f, f,
// "{:02x}:{:02x}:{:02x}:{:02x}:{:02x}:{:02x}", "{:02x}:{:02x}:{:02x}:{:02x}:{:02x}:{:02x}",
// self.address[0], self.address[0],
// self.address[1], self.address[1],
// self.address[2], self.address[2],
// self.address[3], self.address[3],
// self.address[4], self.address[4],
// self.address[5], self.address[5],
// ) )
// } }
// } }
// /// Error enum that represents the union between SPI hardware errors and digital IO pin errors. Returned as an Error // /// Error enum that represents the union between SPI hardware errors and digital IO pin errors. Returned as an Error
// /// type by many W5500 that talk to the chip // /// type by many W5500 that talk to the chip
@ -87,34 +87,73 @@ extern crate nb;
// ChipSelectError(ChipSelectError), // ChipSelectError(ChipSelectError),
// } // }
// /// Settings for wake on LAN. Allows the W5500 to optionally emit an interrupt upon receiving a packet // if let OnWakeOnLan::InvokeInterrupt = settings.on_wake_on_lan {
// #[derive(Copy, Clone, PartialOrd, PartialEq)] // value |= 1 << 5;
// pub enum OnWakeOnLan {
// InvokeInterrupt,
// Ignore,
// } // }
// /// Settings for ping. Allows the W5500 to respond to or ignore network ping requests // if let OnPingRequest::Ignore = settings.on_ping_request {
// #[derive(Copy, Clone, PartialOrd, PartialEq)] // value |= 1 << 4;
// pub enum OnPingRequest {
// Respond,
// Ignore,
// } // }
// /// Use [TransmissionMode::PPoE] when talking // if let ConnectionType::PPoE = settings.connection_type {
// /// to an ADSL modem. Otherwise use [TransmissionMode::Ethernet] // value |= 1 << 3;
// #[derive(Copy, Clone, PartialOrd, PartialEq)]
// pub enum ConnectionType {
// PPoE,
// Ethernet,
// } // }
// #[derive(Copy, Clone, PartialOrd, PartialEq)] // if let ArpResponses::DropAfterUse = settings.arp_responses {
// pub enum ArpResponses { // value |= 1 << 1;
// Cache,
// DropAfterUse,
// } // }
/// Settings for wake on LAN. Allows the W5500 to optionally emit an interrupt upon receiving a packet
#[repr(u8)]
#[derive(Copy, Clone, PartialOrd, PartialEq)]
pub enum OnWakeOnLan {
InvokeInterrupt = 0b00100000,
Ignore = 0b00000000,
}
/// Settings for ping. Allows the W5500 to respond to or ignore network ping requests
#[repr(u8)]
#[derive(Copy, Clone, PartialOrd, PartialEq)]
pub enum OnPingRequest {
Respond = 0b00000000,
Ignore = 0b00010000,
}
/// Use [TransmissionMode::PPoE] when talking
/// to an ADSL modem. Otherwise use [TransmissionMode::Ethernet]
#[repr(u8)]
#[derive(Copy, Clone, PartialOrd, PartialEq)]
pub enum ConnectionType {
PPoE = 0b00001000,
Ethernet = 0b00000000,
}
#[derive(Copy, Clone, PartialOrd, PartialEq)]
#[repr(u8)]
pub enum ArpResponses {
Cache = 0b00000000,
DropAfterUse = 0b00000010,
}
#[derive(Copy, Clone, PartialEq)]
pub struct Settings {
on_wake_on_lan: OnWakeOnLan,
on_ping_request: OnPingRequest,
connection_type: ConnectionType,
arp_responses: ArpResponses
}
impl Default for Settings {
fn default() -> Self {
Self {
on_wake_on_lan: OnWakeOnLan::Ignore,
on_ping_request: OnPingRequest::Respond,
connection_type: ConnectionType::Ethernet,
arp_responses: ArpResponses::DropAfterUse,
}
}
}
// /// Represents a socket that has not yet been initialized for a particular protocol // /// Represents a socket that has not yet been initialized for a particular protocol
// pub struct UninitializedSocket { // pub struct UninitializedSocket {
// socket: Socket // socket: Socket