From 6021623813bcb281105bc5756a1f54f5046c09d0 Mon Sep 17 00:00:00 2001 From: occheung Date: Mon, 25 Jan 2021 11:35:00 +0800 Subject: [PATCH] lib: add write mac --- src/lib.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index 71e6e7c..858409d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -25,6 +25,7 @@ pub trait EthController { fn send_raw_packet(&mut self, packet: &tx::TxPacket) -> Result<(), EthControllerError>; fn set_promiscuous(&mut self) -> Result<(), EthControllerError>; fn read_from_mac(&mut self, mac: &mut [u8]) -> Result<(), EthControllerError>; + fn write_mac_address(&mut self, mac: &[u8]) -> Result<(), EthControllerError>; } /// TODO: Improve these error types @@ -204,4 +205,14 @@ impl , mac[5] = self.spi_port.read_reg_8b(spi::addrs::MAADR3 + 1)?; Ok(()) } + + fn write_mac_address(&mut self, mac: &[u8]) -> Result<(), EthControllerError> { + self.spi_port.write_reg_8b(spi::addrs::MAADR1, mac[0])?; + self.spi_port.write_reg_8b(spi::addrs::MAADR1 + 1, mac[1])?; + self.spi_port.write_reg_8b(spi::addrs::MAADR2, mac[2])?; + self.spi_port.write_reg_8b(spi::addrs::MAADR2 + 1, mac[3])?; + self.spi_port.write_reg_8b(spi::addrs::MAADR3, mac[4])?; + self.spi_port.write_reg_8b(spi::addrs::MAADR3 + 1, mac[5])?; + Ok(()) + } }