Skip to content

Commit

Permalink
settings: override eeprom MAC
Browse files Browse the repository at this point in the history
  • Loading branch information
occheung committed Jan 20, 2021
1 parent befe70a commit 20efdcc
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
20 changes: 18 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,10 @@ const APP: () = {

let identifier: String<heapless::consts::U32> = String::from(settings.id());

// Store factory MAC address of enc424j600
#[cfg(feature = "phy_enc424j600")]
let mut eth_mac_addr: [u8; 6] = [0; 6];

let mqtt_client = {
let interface = {
let spi = {
Expand Down Expand Up @@ -467,7 +471,6 @@ const APP: () = {
},
}

let mut eth_mac_addr: [u8; 6] = [0; 6];
enc424j600.read_from_mac(&mut eth_mac_addr).unwrap();

// Init Rx/Tx buffers
Expand Down Expand Up @@ -574,7 +577,12 @@ const APP: () = {
// Generate a device serial number from the MAC address.
*USB_SERIAL = {
let mut serial_string: String<heapless::consts::U64> = String::new();

#[cfg(feature = "phy_w5500")]
let octets = settings.mac().octets;
#[cfg(feature = "phy_enc424j600")]
let octets = eth_mac_addr;

write!(
&mut serial_string,
"{:02x}-{:02x}-{:02x}-{:02x}-{:02x}-{:02x}",
Expand All @@ -595,7 +603,15 @@ const APP: () = {
.device_class(usbd_serial::USB_CLASS_CDC)
.build();

SerialTerminal::new(usb_device, usb_serial, settings)
#[cfg(feature = "phy_w5500")]
{
SerialTerminal::new(usb_device, usb_serial, settings)
}

#[cfg(feature = "phy_enc424j600")]
{
SerialTerminal::new(usb_device, usb_serial, settings.set_mac(eth_mac_addr))
}
};

info!("Startup complete");
Expand Down
7 changes: 7 additions & 0 deletions src/settings/global_settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,13 @@ impl BoosterSettings {
settings
}

/// Override MAC address during initialization
pub fn set_mac(mut self, mac: [u8; 6]) -> Self {
// MAC address is designed to be unchanged in EEPROM
self.eui48.copy_from_slice(&mac);
self
}

/// Save the configuration settings to EEPROM for retrieval.
pub fn save(&mut self) {
let mut config = match self.load_config() {
Expand Down

0 comments on commit 20efdcc

Please sign in to comment.