aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--embassy-net-adin1110/src/lib.rs30
1 files changed, 11 insertions, 19 deletions
diff --git a/embassy-net-adin1110/src/lib.rs b/embassy-net-adin1110/src/lib.rs
index fd2bf868d..e917edcc8 100644
--- a/embassy-net-adin1110/src/lib.rs
+++ b/embassy-net-adin1110/src/lib.rs
@@ -44,7 +44,7 @@ pub enum AdinError<E> {
44 MDIO_ACC_TIMEOUT, 44 MDIO_ACC_TIMEOUT,
45} 45}
46 46
47pub type AEResult<T, SPIE> = core::result::Result<T, AdinError<SPIE>>; 47pub type AEResult<T, SPIError> = core::result::Result<T, AdinError<SPIError>>;
48pub const MDIO_PHY_ADDR: u8 = 0x01; 48pub const MDIO_PHY_ADDR: u8 = 0x01;
49 49
50/// Maximum Transmission Unit 50/// Maximum Transmission Unit
@@ -100,16 +100,12 @@ pub(crate) fn size_align_u32(size: u32) -> u32 {
100 (size + 3) & 0xFFFF_FFFC 100 (size + 3) & 0xFFFF_FFFC
101} 101}
102 102
103impl<SpiE, SPI> ADIN1110<SPI> 103impl<SPI: SpiDevice> ADIN1110<SPI> {
104where
105 SPI: SpiDevice<u8, Error = SpiE>,
106 SpiE: core::fmt::Debug,
107{
108 pub fn new(spi: SPI, crc: bool) -> Self { 104 pub fn new(spi: SPI, crc: bool) -> Self {
109 Self { spi, crc } 105 Self { spi, crc }
110 } 106 }
111 107
112 pub async fn read_reg(&mut self, reg: sr) -> AEResult<u32, SpiE> { 108 pub async fn read_reg(&mut self, reg: sr) -> AEResult<u32, SPI::Error> {
113 let mut tx_buf = Vec::<u8, 16>::new(); 109 let mut tx_buf = Vec::<u8, 16>::new();
114 110
115 let mut spi_hdr = SpiHeader(0); 111 let mut spi_hdr = SpiHeader(0);
@@ -148,7 +144,7 @@ where
148 Ok(value) 144 Ok(value)
149 } 145 }
150 146
151 pub async fn write_reg(&mut self, reg: sr, value: u32) -> AEResult<(), SpiE> { 147 pub async fn write_reg(&mut self, reg: sr, value: u32) -> AEResult<(), SPI::Error> {
152 let mut tx_buf = Vec::<u8, 16>::new(); 148 let mut tx_buf = Vec::<u8, 16>::new();
153 149
154 let mut spi_hdr = SpiHeader(0); 150 let mut spi_hdr = SpiHeader(0);
@@ -177,7 +173,7 @@ where
177 } 173 }
178 174
179 /// helper function for write to `MDIO_ACC` register and wait for ready! 175 /// helper function for write to `MDIO_ACC` register and wait for ready!
180 async fn write_mdio_acc_reg(&mut self, mdio_acc_val: u32) -> AEResult<u32, SpiE> { 176 async fn write_mdio_acc_reg(&mut self, mdio_acc_val: u32) -> AEResult<u32, SPI::Error> {
181 self.write_reg(sr::MDIO_ACC, mdio_acc_val).await?; 177 self.write_reg(sr::MDIO_ACC, mdio_acc_val).await?;
182 178
183 // TODO: Add proper timeout! 179 // TODO: Add proper timeout!
@@ -192,7 +188,7 @@ where
192 } 188 }
193 189
194 /// Read out fifo ethernet packet memory received via the wire. 190 /// Read out fifo ethernet packet memory received via the wire.
195 pub async fn read_fifo(&mut self, packet: &mut [u8]) -> AEResult<usize, SpiE> { 191 pub async fn read_fifo(&mut self, packet: &mut [u8]) -> AEResult<usize, SPI::Error> {
196 let mut tx_buf = Vec::<u8, 16>::new(); 192 let mut tx_buf = Vec::<u8, 16>::new();
197 193
198 // Size of the frame, also includes the appednded header. 194 // Size of the frame, also includes the appednded header.
@@ -238,7 +234,7 @@ where
238 } 234 }
239 235
240 /// Write to fifo ethernet packet memory send over the wire. 236 /// Write to fifo ethernet packet memory send over the wire.
241 pub async fn write_fifo(&mut self, frame: &[u8]) -> AEResult<(), SpiE> { 237 pub async fn write_fifo(&mut self, frame: &[u8]) -> AEResult<(), SPI::Error> {
242 let header_len = self.header_write_len(); 238 let header_len = self.header_write_len();
243 239
244 let mut packet = Packet::new(); 240 let mut packet = Packet::new();
@@ -318,7 +314,7 @@ where
318 /// Programs the mac address in the mac filters. 314 /// Programs the mac address in the mac filters.
319 /// Also set the boardcast address. 315 /// Also set the boardcast address.
320 /// The chip supports 2 priority queues but current code doesn't support this mode. 316 /// The chip supports 2 priority queues but current code doesn't support this mode.
321 pub async fn set_mac_addr(&mut self, mac: &[u8; 6]) -> AEResult<(), SpiE> { 317 pub async fn set_mac_addr(&mut self, mac: &[u8; 6]) -> AEResult<(), SPI::Error> {
322 let mac_high_part = u16::from_be_bytes(mac[0..2].try_into().unwrap()); 318 let mac_high_part = u16::from_be_bytes(mac[0..2].try_into().unwrap());
323 let mac_low_part = u32::from_be_bytes(mac[2..6].try_into().unwrap()); 319 let mac_low_part = u32::from_be_bytes(mac[2..6].try_into().unwrap());
324 320
@@ -341,12 +337,8 @@ where
341 } 337 }
342} 338}
343 339
344impl<SpiE, SPI> mdio::MdioBus for ADIN1110<SPI> 340impl<SPI: SpiDevice> mdio::MdioBus for ADIN1110<SPI> {
345where 341 type Error = AdinError<SPI::Error>;
346 SPI: SpiDevice<u8, Error = SpiE>,
347 SpiE: core::fmt::Debug,
348{
349 type Error = AdinError<SpiE>;
350 342
351 /// Read from the PHY Registers as Clause 22. 343 /// Read from the PHY Registers as Clause 22.
352 async fn read_cl22(&mut self, phy_id: u8, reg: u8) -> Result<u16, Self::Error> { 344 async fn read_cl22(&mut self, phy_id: u8, reg: u8) -> Result<u16, Self::Error> {
@@ -380,7 +372,7 @@ where
380 } 372 }
381 373
382 /// Write to the PHY Registers as Clause 45. 374 /// Write to the PHY Registers as Clause 45.
383 async fn write_cl45(&mut self, phy_id: u8, regc45: (u8, u16), value: u16) -> AEResult<(), SpiE> { 375 async fn write_cl45(&mut self, phy_id: u8, regc45: (u8, u16), value: u16) -> AEResult<(), SPI::Error> {
384 let phy_id = u32::from(phy_id & 0x1F) << 21; 376 let phy_id = u32::from(phy_id & 0x1F) << 21;
385 let dev_addr = u32::from(regc45.0 & 0x1F) << 16; 377 let dev_addr = u32::from(regc45.0 & 0x1F) << 16;
386 let reg = u32::from(regc45.1); 378 let reg = u32::from(regc45.1);