aboutsummaryrefslogtreecommitdiff
path: root/embassy-net-adin1110/src
diff options
context:
space:
mode:
authorRenĂ© van Dorst <[email protected]>2023-08-20 16:28:57 +0200
committerRenĂ© van Dorst <[email protected]>2023-08-24 00:52:21 +0200
commit10bf33dcacd162f0ab92a37bdc439cbac9fa437c (patch)
tree17053a38748a7d4e6ece2fb0436034f579eb8a0a /embassy-net-adin1110/src
parent46ddf7013a426f67eb737ae8436d1032a3ec9d77 (diff)
Fix linting.
I like program with deny(clippy::pedantic) but it was set as allowed, so I did get less linting errors/hints. Now it is corrected and also fix the lint errors and hints. Also fixes some comment and demagic some values. Rename `FEC` to more appropriate name `FSC`.
Diffstat (limited to 'embassy-net-adin1110/src')
-rw-r--r--embassy-net-adin1110/src/crc32.rs68
-rw-r--r--embassy-net-adin1110/src/lib.rs138
-rw-r--r--embassy-net-adin1110/src/mdio.rs13
-rw-r--r--embassy-net-adin1110/src/phy.rs14
-rw-r--r--embassy-net-adin1110/src/regs.rs15
5 files changed, 128 insertions, 120 deletions
diff --git a/embassy-net-adin1110/src/crc32.rs b/embassy-net-adin1110/src/crc32.rs
index 75a7d65b7..906c9aad7 100644
--- a/embassy-net-adin1110/src/crc32.rs
+++ b/embassy-net-adin1110/src/crc32.rs
@@ -1,33 +1,33 @@
1pub const CRC32R_LOOKUP_TABLE: [u32; 256] = [ 1pub const CRC32R_LOOKUP_TABLE: [u32; 256] = [
2 0x00000000, 0x77073096, 0xEE0E612C, 0x990951BA, 0x076DC419, 0x706AF48F, 0xE963A535, 0x9E6495A3, 0x0EDB8832, 2 0x0000_0000, 0x7707_3096, 0xEE0E_612C, 0x9909_51BA, 0x076D_C419, 0x706A_F48F, 0xE963_A535, 0x9E64_95A3, 0x0EDB_8832,
3 0x79DCB8A4, 0xE0D5E91E, 0x97D2D988, 0x09B64C2B, 0x7EB17CBD, 0xE7B82D07, 0x90BF1D91, 0x1DB71064, 0x6AB020F2, 3 0x79DC_B8A4, 0xE0D5_E91E, 0x97D2_D988, 0x09B6_4C2B, 0x7EB1_7CBD, 0xE7B8_2D07, 0x90BF_1D91, 0x1DB7_1064, 0x6AB0_20F2,
4 0xF3B97148, 0x84BE41DE, 0x1ADAD47D, 0x6DDDE4EB, 0xF4D4B551, 0x83D385C7, 0x136C9856, 0x646BA8C0, 0xFD62F97A, 4 0xF3B9_7148, 0x84BE_41DE, 0x1ADA_D47D, 0x6DDD_E4EB, 0xF4D4_B551, 0x83D3_85C7, 0x136C_9856, 0x646B_A8C0, 0xFD62_F97A,
5 0x8A65C9EC, 0x14015C4F, 0x63066CD9, 0xFA0F3D63, 0x8D080DF5, 0x3B6E20C8, 0x4C69105E, 0xD56041E4, 0xA2677172, 5 0x8A65_C9EC, 0x1401_5C4F, 0x6306_6CD9, 0xFA0F_3D63, 0x8D08_0DF5, 0x3B6E_20C8, 0x4C69_105E, 0xD560_41E4, 0xA267_7172,
6 0x3C03E4D1, 0x4B04D447, 0xD20D85FD, 0xA50AB56B, 0x35B5A8FA, 0x42B2986C, 0xDBBBC9D6, 0xACBCF940, 0x32D86CE3, 6 0x3C03_E4D1, 0x4B04_D447, 0xD20D_85FD, 0xA50A_B56B, 0x35B5_A8FA, 0x42B2_986C, 0xDBBB_C9D6, 0xACBC_F940, 0x32D8_6CE3,
7 0x45DF5C75, 0xDCD60DCF, 0xABD13D59, 0x26D930AC, 0x51DE003A, 0xC8D75180, 0xBFD06116, 0x21B4F4B5, 0x56B3C423, 7 0x45DF_5C75, 0xDCD6_0DCF, 0xABD1_3D59, 0x26D9_30AC, 0x51DE_003A, 0xC8D7_5180, 0xBFD0_6116, 0x21B4_F4B5, 0x56B3_C423,
8 0xCFBA9599, 0xB8BDA50F, 0x2802B89E, 0x5F058808, 0xC60CD9B2, 0xB10BE924, 0x2F6F7C87, 0x58684C11, 0xC1611DAB, 8 0xCFBA_9599, 0xB8BD_A50F, 0x2802_B89E, 0x5F05_8808, 0xC60C_D9B2, 0xB10B_E924, 0x2F6F_7C87, 0x5868_4C11, 0xC161_1DAB,
9 0xB6662D3D, 0x76DC4190, 0x01DB7106, 0x98D220BC, 0xEFD5102A, 0x71B18589, 0x06B6B51F, 0x9FBFE4A5, 0xE8B8D433, 9 0xB666_2D3D, 0x76DC_4190, 0x01DB_7106, 0x98D2_20BC, 0xEFD5_102A, 0x71B1_8589, 0x06B6_B51F, 0x9FBF_E4A5, 0xE8B8_D433,
10 0x7807C9A2, 0x0F00F934, 0x9609A88E, 0xE10E9818, 0x7F6A0DBB, 0x086D3D2D, 0x91646C97, 0xE6635C01, 0x6B6B51F4, 10 0x7807_C9A2, 0x0F00_F934, 0x9609_A88E, 0xE10E_9818, 0x7F6A_0DBB, 0x086D_3D2D, 0x9164_6C97, 0xE663_5C01, 0x6B6B_51F4,
11 0x1C6C6162, 0x856530D8, 0xF262004E, 0x6C0695ED, 0x1B01A57B, 0x8208F4C1, 0xF50FC457, 0x65B0D9C6, 0x12B7E950, 11 0x1C6C_6162, 0x8565_30D8, 0xF262_004E, 0x6C06_95ED, 0x1B01_A57B, 0x8208_F4C1, 0xF50F_C457, 0x65B0_D9C6, 0x12B7_E950,
12 0x8BBEB8EA, 0xFCB9887C, 0x62DD1DDF, 0x15DA2D49, 0x8CD37CF3, 0xFBD44C65, 0x4DB26158, 0x3AB551CE, 0xA3BC0074, 12 0x8BBE_B8EA, 0xFCB9_887C, 0x62DD_1DDF, 0x15DA_2D49, 0x8CD3_7CF3, 0xFBD4_4C65, 0x4DB2_6158, 0x3AB5_51CE, 0xA3BC_0074,
13 0xD4BB30E2, 0x4ADFA541, 0x3DD895D7, 0xA4D1C46D, 0xD3D6F4FB, 0x4369E96A, 0x346ED9FC, 0xAD678846, 0xDA60B8D0, 13 0xD4BB_30E2, 0x4ADF_A541, 0x3DD8_95D7, 0xA4D1_C46D, 0xD3D6_F4FB, 0x4369_E96A, 0x346E_D9FC, 0xAD67_8846, 0xDA60_B8D0,
14 0x44042D73, 0x33031DE5, 0xAA0A4C5F, 0xDD0D7CC9, 0x5005713C, 0x270241AA, 0xBE0B1010, 0xC90C2086, 0x5768B525, 14 0x4404_2D73, 0x3303_1DE5, 0xAA0A_4C5F, 0xDD0D_7CC9, 0x5005_713C, 0x2702_41AA, 0xBE0B_1010, 0xC90C_2086, 0x5768_B525,
15 0x206F85B3, 0xB966D409, 0xCE61E49F, 0x5EDEF90E, 0x29D9C998, 0xB0D09822, 0xC7D7A8B4, 0x59B33D17, 0x2EB40D81, 15 0x206F_85B3, 0xB966_D409, 0xCE61_E49F, 0x5EDE_F90E, 0x29D9_C998, 0xB0D0_9822, 0xC7D7_A8B4, 0x59B3_3D17, 0x2EB4_0D81,
16 0xB7BD5C3B, 0xC0BA6CAD, 0xEDB88320, 0x9ABFB3B6, 0x03B6E20C, 0x74B1D29A, 0xEAD54739, 0x9DD277AF, 0x04DB2615, 16 0xB7BD_5C3B, 0xC0BA_6CAD, 0xEDB8_8320, 0x9ABF_B3B6, 0x03B6_E20C, 0x74B1_D29A, 0xEAD5_4739, 0x9DD2_77AF, 0x04DB_2615,
17 0x73DC1683, 0xE3630B12, 0x94643B84, 0x0D6D6A3E, 0x7A6A5AA8, 0xE40ECF0B, 0x9309FF9D, 0x0A00AE27, 0x7D079EB1, 17 0x73DC_1683, 0xE363_0B12, 0x9464_3B84, 0x0D6D_6A3E, 0x7A6A_5AA8, 0xE40E_CF0B, 0x9309_FF9D, 0x0A00_AE27, 0x7D07_9EB1,
18 0xF00F9344, 0x8708A3D2, 0x1E01F268, 0x6906C2FE, 0xF762575D, 0x806567CB, 0x196C3671, 0x6E6B06E7, 0xFED41B76, 18 0xF00F_9344, 0x8708_A3D2, 0x1E01_F268, 0x6906_C2FE, 0xF762_575D, 0x8065_67CB, 0x196C_3671, 0x6E6B_06E7, 0xFED4_1B76,
19 0x89D32BE0, 0x10DA7A5A, 0x67DD4ACC, 0xF9B9DF6F, 0x8EBEEFF9, 0x17B7BE43, 0x60B08ED5, 0xD6D6A3E8, 0xA1D1937E, 19 0x89D3_2BE0, 0x10DA_7A5A, 0x67DD_4ACC, 0xF9B9_DF6F, 0x8EBE_EFF9, 0x17B7_BE43, 0x60B0_8ED5, 0xD6D6_A3E8, 0xA1D1_937E,
20 0x38D8C2C4, 0x4FDFF252, 0xD1BB67F1, 0xA6BC5767, 0x3FB506DD, 0x48B2364B, 0xD80D2BDA, 0xAF0A1B4C, 0x36034AF6, 20 0x38D8_C2C4, 0x4FDF_F252, 0xD1BB_67F1, 0xA6BC_5767, 0x3FB5_06DD, 0x48B2_364B, 0xD80D_2BDA, 0xAF0A_1B4C, 0x3603_4AF6,
21 0x41047A60, 0xDF60EFC3, 0xA867DF55, 0x316E8EEF, 0x4669BE79, 0xCB61B38C, 0xBC66831A, 0x256FD2A0, 0x5268E236, 21 0x4104_7A60, 0xDF60_EFC3, 0xA867_DF55, 0x316E_8EEF, 0x4669_BE79, 0xCB61_B38C, 0xBC66_831A, 0x256F_D2A0, 0x5268_E236,
22 0xCC0C7795, 0xBB0B4703, 0x220216B9, 0x5505262F, 0xC5BA3BBE, 0xB2BD0B28, 0x2BB45A92, 0x5CB36A04, 0xC2D7FFA7, 22 0xCC0C_7795, 0xBB0B_4703, 0x2202_16B9, 0x5505_262F, 0xC5BA_3BBE, 0xB2BD_0B28, 0x2BB4_5A92, 0x5CB3_6A04, 0xC2D7_FFA7,
23 0xB5D0CF31, 0x2CD99E8B, 0x5BDEAE1D, 0x9B64C2B0, 0xEC63F226, 0x756AA39C, 0x026D930A, 0x9C0906A9, 0xEB0E363F, 23 0xB5D0_CF31, 0x2CD9_9E8B, 0x5BDE_AE1D, 0x9B64_C2B0, 0xEC63_F226, 0x756A_A39C, 0x026D_930A, 0x9C09_06A9, 0xEB0E_363F,
24 0x72076785, 0x05005713, 0x95BF4A82, 0xE2B87A14, 0x7BB12BAE, 0x0CB61B38, 0x92D28E9B, 0xE5D5BE0D, 0x7CDCEFB7, 24 0x7207_6785, 0x0500_5713, 0x95BF_4A82, 0xE2B8_7A14, 0x7BB1_2BAE, 0x0CB6_1B38, 0x92D2_8E9B, 0xE5D5_BE0D, 0x7CDC_EFB7,
25 0x0BDBDF21, 0x86D3D2D4, 0xF1D4E242, 0x68DDB3F8, 0x1FDA836E, 0x81BE16CD, 0xF6B9265B, 0x6FB077E1, 0x18B74777, 25 0x0BDB_DF21, 0x86D3_D2D4, 0xF1D4_E242, 0x68DD_B3F8, 0x1FDA_836E, 0x81BE_16CD, 0xF6B9_265B, 0x6FB0_77E1, 0x18B7_4777,
26 0x88085AE6, 0xFF0F6A70, 0x66063BCA, 0x11010B5C, 0x8F659EFF, 0xF862AE69, 0x616BFFD3, 0x166CCF45, 0xA00AE278, 26 0x8808_5AE6, 0xFF0F_6A70, 0x6606_3BCA, 0x1101_0B5C, 0x8F65_9EFF, 0xF862_AE69, 0x616B_FFD3, 0x166C_CF45, 0xA00A_E278,
27 0xD70DD2EE, 0x4E048354, 0x3903B3C2, 0xA7672661, 0xD06016F7, 0x4969474D, 0x3E6E77DB, 0xAED16A4A, 0xD9D65ADC, 27 0xD70D_D2EE, 0x4E04_8354, 0x3903_B3C2, 0xA767_2661, 0xD060_16F7, 0x4969_474D, 0x3E6E_77DB, 0xAED1_6A4A, 0xD9D6_5ADC,
28 0x40DF0B66, 0x37D83BF0, 0xA9BCAE53, 0xDEBB9EC5, 0x47B2CF7F, 0x30B5FFE9, 0xBDBDF21C, 0xCABAC28A, 0x53B39330, 28 0x40DF_0B66, 0x37D8_3BF0, 0xA9BC_AE53, 0xDEBB_9EC5, 0x47B2_CF7F, 0x30B5_FFE9, 0xBDBD_F21C, 0xCABA_C28A, 0x53B3_9330,
29 0x24B4A3A6, 0xBAD03605, 0xCDD70693, 0x54DE5729, 0x23D967BF, 0xB3667A2E, 0xC4614AB8, 0x5D681B02, 0x2A6F2B94, 29 0x24B4_A3A6, 0xBAD0_3605, 0xCDD7_0693, 0x54DE_5729, 0x23D9_67BF, 0xB366_7A2E, 0xC461_4AB8, 0x5D68_1B02, 0x2A6F_2B94,
30 0xB40BBE37, 0xC30C8EA1, 0x5A05DF1B, 0x2D02EF8D, 30 0xB40B_BE37, 0xC30C_8EA1, 0x5A05_DF1B, 0x2D02_EF8D,
31]; 31];
32 32
33#[allow(non_camel_case_types)] 33#[allow(non_camel_case_types)]
@@ -35,9 +35,9 @@ pub const CRC32R_LOOKUP_TABLE: [u32; 256] = [
35pub struct ETH_FSC(pub u32); 35pub struct ETH_FSC(pub u32);
36 36
37impl ETH_FSC { 37impl ETH_FSC {
38 pub const CRC32_OK: u32 = 0x2144df1c; 38 pub const CRC32_OK: u32 = 0x2144_df1c;
39 39
40 pub fn new(data: &[u8]) -> Self { 40 #[must_use] pub fn new(data: &[u8]) -> Self {
41 let fsc = data.iter().fold(u32::MAX, |crc, byte| { 41 let fsc = data.iter().fold(u32::MAX, |crc, byte| {
42 let idx = u8::try_from(crc & 0xFF).unwrap() ^ byte; 42 let idx = u8::try_from(crc & 0xFF).unwrap() ^ byte;
43 CRC32R_LOOKUP_TABLE[usize::from(idx)] ^ (crc >> 8) 43 CRC32R_LOOKUP_TABLE[usize::from(idx)] ^ (crc >> 8)
@@ -45,15 +45,15 @@ impl ETH_FSC {
45 Self(fsc) 45 Self(fsc)
46 } 46 }
47 47
48 pub fn crc_ok(&self) -> bool { 48 #[must_use] pub fn crc_ok(&self) -> bool {
49 self.0 == Self::CRC32_OK 49 self.0 == Self::CRC32_OK
50 } 50 }
51 51
52 pub fn hton_bytes(&self) -> [u8; 4] { 52 #[must_use] pub fn hton_bytes(&self) -> [u8; 4] {
53 self.0.to_le_bytes() 53 self.0.to_le_bytes()
54 } 54 }
55 55
56 pub fn hton(&self) -> u32 { 56 #[must_use] pub fn hton(&self) -> u32 {
57 self.0.to_le() 57 self.0.to_le()
58 } 58 }
59} 59}
diff --git a/embassy-net-adin1110/src/lib.rs b/embassy-net-adin1110/src/lib.rs
index 4ce8a1895..c74648936 100644
--- a/embassy-net-adin1110/src/lib.rs
+++ b/embassy-net-adin1110/src/lib.rs
@@ -1,16 +1,10 @@
1#![allow(clippy::pedantic)] 1#![deny(clippy::pedantic)]
2#![feature(type_alias_impl_trait)] 2#![feature(type_alias_impl_trait)]
3#![feature(async_fn_in_trait)] 3#![feature(async_fn_in_trait)]
4#![cfg_attr(not(any(test, feature = "std")), no_std)] 4#![cfg_attr(not(any(test, feature = "std")), no_std)]
5 5#![allow(clippy::module_name_repetitions)]
6use ch::driver::LinkState; 6#![allow(clippy::missing_errors_doc)]
7use embassy_futures::select::{select, Either}; 7#![allow(clippy::missing_panics_doc)]
8use embassy_net_driver_channel as ch;
9use embassy_time::{Duration, Timer};
10use embedded_hal_1::digital::OutputPin;
11use embedded_hal_async::digital::Wait;
12use embedded_hal_async::spi::{Operation, SpiDevice};
13use heapless::Vec;
14 8
15mod crc32; 9mod crc32;
16mod crc8; 10mod crc8;
@@ -18,15 +12,23 @@ mod mdio;
18mod phy; 12mod phy;
19mod regs; 13mod regs;
20 14
15use ch::driver::LinkState;
21pub use crc32::ETH_FSC; 16pub use crc32::ETH_FSC;
22use crc8::crc8; 17use crc8::crc8;
18use embassy_futures::select::{select, Either};
19use embassy_net_driver_channel as ch;
20use embassy_time::{Duration, Timer};
21use embedded_hal_1::digital::OutputPin;
22use embedded_hal_async::digital::Wait;
23use embedded_hal_async::spi::{Operation, SpiDevice};
24use heapless::Vec;
23pub use mdio::MdioBus; 25pub use mdio::MdioBus;
24pub use phy::{Phy10BaseT1x, RegsC22, RegsC45}; 26pub use phy::{Phy10BaseT1x, RegsC22, RegsC45};
25pub use regs::{Config0, Config2, SpiRegisters as sr, Status0, Status1}; 27pub use regs::{Config0, Config2, SpiRegisters as sr, Status0, Status1};
26 28
27use crate::regs::{LedCntrl, LedFunc, LedPol, LedPolarity, SpiHeader}; 29use crate::regs::{LedCntrl, LedFunc, LedPol, LedPolarity, SpiHeader};
28 30
29pub const PHYID: u32 = 0x0283BC91; 31pub const PHYID: u32 = 0x0283_BC91;
30 32
31/// Error values ADIN1110 33/// Error values ADIN1110
32#[derive(Debug)] 34#[derive(Debug)]
@@ -44,21 +46,28 @@ pub enum AdinError<E> {
44 46
45pub type AEResult<T, SPIE> = core::result::Result<T, AdinError<SPIE>>; 47pub type AEResult<T, SPIE> = core::result::Result<T, AdinError<SPIE>>;
46pub const MDIO_PHY_ADDR: u8 = 0x01; 48pub const MDIO_PHY_ADDR: u8 = 0x01;
47pub const MTU: usize = 1500; 49
50/// Maximum Transmission Unit
51pub const MTU: usize = 1514;
52
48/// Max SPI/Frame buffer size 53/// Max SPI/Frame buffer size
49pub const MAX_BUFF: usize = 2048; 54pub const MAX_BUFF: usize = 2048;
50 55
51const DONT_CARE_BYTE: u8 = 0x00; 56const DONT_CARE_BYTE: u8 = 0x00;
52const TURN_AROUND_BYTE: u8 = 0x00; 57const TURN_AROUND_BYTE: u8 = 0x00;
53 58
54const FEC_LEN: usize = 4; 59/// Packet minimal frame/packet length
60const ETH_MIN_LEN: usize = 64;
61
62/// Ethernet `Frame Check Sequence` length
63const FSC_LEN: usize = 4;
55const FRAME_HEADER_LEN: usize = 2; 64const FRAME_HEADER_LEN: usize = 2;
56const WR_HEADER_LEN: usize = 2; 65const WR_HEADER_LEN: usize = 2;
57 66
58// P1 = 0x00, P2 = 0x01 67// P1 = 0x00, P2 = 0x01
59const PORT_ID_BYTE: u8 = 0x00; 68const PORT_ID_BYTE: u8 = 0x00;
60 69
61pub type Packet = Vec<u8, { MTU + FEC_LEN + WR_HEADER_LEN }>; 70pub type Packet = Vec<u8, { MTU + FSC_LEN + WR_HEADER_LEN }>;
62 71
63/// Type alias for the embassy-net driver for ADIN1110 72/// Type alias for the embassy-net driver for ADIN1110
64pub type Device<'d> = embassy_net_driver_channel::Device<'d, MTU>; 73pub type Device<'d> = embassy_net_driver_channel::Device<'d, MTU>;
@@ -69,6 +78,7 @@ pub struct State<const N_RX: usize, const N_TX: usize> {
69} 78}
70impl<const N_RX: usize, const N_TX: usize> State<N_RX, N_TX> { 79impl<const N_RX: usize, const N_TX: usize> State<N_RX, N_TX> {
71 /// Create a new `State`. 80 /// Create a new `State`.
81 #[must_use]
72 pub const fn new() -> Self { 82 pub const fn new() -> Self {
73 Self { 83 Self {
74 ch_state: ch::State::new(), 84 ch_state: ch::State::new(),
@@ -81,11 +91,11 @@ pub struct ADIN1110<SPI> {
81 /// SPI bus 91 /// SPI bus
82 spi: SPI, 92 spi: SPI,
83 /// Enable CRC on SPI transfer. 93 /// Enable CRC on SPI transfer.
84 /// This must match with the hardware pin SPI_CFG0 were 0 = CRC enable, 1 CRC disabled. 94 /// This must match with the hardware pin `SPI_CFG0` were low = CRC enable, high = CRC disabled.
85 crc: bool, 95 crc: bool,
86} 96}
87 97
88// Round size up the N u32; 98/// Round size up the N u32;
89pub(crate) fn size_align_u32(size: u32) -> u32 { 99pub(crate) fn size_align_u32(size: u32) -> u32 {
90 (size + 3) & 0xFFFF_FFFC 100 (size + 3) & 0xFFFF_FFFC
91} 101}
@@ -166,7 +176,7 @@ where
166 self.spi.write(&tx_buf).await.map_err(AdinError::Spi) 176 self.spi.write(&tx_buf).await.map_err(AdinError::Spi)
167 } 177 }
168 178
169 // helper function for write to MDIO_ACC register and wait for ready! 179 /// helper function for write to `MDIO_ACC` register and wait for ready!
170 async fn write_mdio_acc_reg(&mut self, mdio_acc_val: u32) -> AEResult<u32, SpiE> { 180 async fn write_mdio_acc_reg(&mut self, mdio_acc_val: u32) -> AEResult<u32, SpiE> {
171 self.write_reg(sr::MDIO_ACC, mdio_acc_val).await?; 181 self.write_reg(sr::MDIO_ACC, mdio_acc_val).await?;
172 182
@@ -181,6 +191,7 @@ where
181 Err(AdinError::MDIO_ACC_TIMEOUT) 191 Err(AdinError::MDIO_ACC_TIMEOUT)
182 } 192 }
183 193
194 /// Read out fifo ethernet packet memory received via the wire.
184 pub async fn read_fifo(&mut self, packet: &mut [u8]) -> AEResult<usize, SpiE> { 195 pub async fn read_fifo(&mut self, packet: &mut [u8]) -> AEResult<usize, SpiE> {
185 let mut tx_buf = Vec::<u8, 16>::new(); 196 let mut tx_buf = Vec::<u8, 16>::new();
186 197
@@ -190,7 +201,7 @@ where
190 // Packet read of write to the MAC packet buffer must be a multipul of 4! 201 // Packet read of write to the MAC packet buffer must be a multipul of 4!
191 let read_size = size_align_u32(packet_size); 202 let read_size = size_align_u32(packet_size);
192 203
193 if packet_size < u32::try_from(FRAME_HEADER_LEN + FEC_LEN).unwrap() 204 if packet_size < u32::try_from(FRAME_HEADER_LEN + FSC_LEN).unwrap()
194 || read_size > u32::try_from(packet.len()).unwrap() 205 || read_size > u32::try_from(packet.len()).unwrap()
195 { 206 {
196 return Err(AdinError::PACKET_TOO_BIG); 207 return Err(AdinError::PACKET_TOO_BIG);
@@ -226,11 +237,9 @@ where
226 Ok(packet_size as usize) 237 Ok(packet_size as usize)
227 } 238 }
228 239
240 /// Write to fifo ethernet packet memory send over the wire.
229 pub async fn write_fifo(&mut self, frame: &[u8]) -> AEResult<(), SpiE> { 241 pub async fn write_fifo(&mut self, frame: &[u8]) -> AEResult<(), SpiE> {
230 let header_len = self.header_write_len(); 242 let header_len = self.header_write_len();
231 // if packet.len() < header_len {
232 // return Err(AdinError::PACKET_TOO_SMALL);
233 // }
234 243
235 let mut packet = Packet::new(); 244 let mut packet = Packet::new();
236 245
@@ -244,37 +253,33 @@ where
244 .map_err(|_| AdinError::PACKET_TOO_BIG)?; 253 .map_err(|_| AdinError::PACKET_TOO_BIG)?;
245 254
246 if self.crc { 255 if self.crc {
247 assert_eq!(header_len, 5);
248 // Add CRC for header data 256 // Add CRC for header data
249 packet 257 packet
250 .push(crc8(&packet[0..2])) 258 .push(crc8(&packet[0..2]))
251 .map_err(|_| AdinError::PACKET_TOO_BIG)?; 259 .map_err(|_| AdinError::PACKET_TOO_BIG)?;
252 } 260 }
253 261
254 // Add port number 262 // Add port number, ADIN1110 its fixed to zero/P1, but for ADIN2111 has two ports.
255 // packet[header_len - FRAME_HEADER_LEN..header_len]
256 // .copy_from_slice(u16::from(PORT_ID_BYTE).to_be_bytes().as_slice());
257 packet 263 packet
258 .extend_from_slice(u16::from(PORT_ID_BYTE).to_be_bytes().as_slice()) 264 .extend_from_slice(u16::from(PORT_ID_BYTE).to_be_bytes().as_slice())
259 .map_err(|_| AdinError::PACKET_TOO_BIG)?; 265 .map_err(|_| AdinError::PACKET_TOO_BIG)?;
260 266
267 // Copy packet data to spi buffer.
261 packet.extend_from_slice(frame).map_err(|_| AdinError::PACKET_TOO_BIG)?; 268 packet.extend_from_slice(frame).map_err(|_| AdinError::PACKET_TOO_BIG)?;
262 269
263 // Pad data up to 64 270 // Pad data up to ETH_MIN_LEN - FCS_LEN
264 for _ in packet.len()..(64 - FEC_LEN + header_len) { 271 for _ in packet.len()..(ETH_MIN_LEN - FSC_LEN + header_len) {
265 let _ = packet.push(0x00); 272 let _ = packet.push(0x00);
266 } 273 }
267 274
268 // // add ethernet crc32 275 // add ethernet FCS only over the ethernet packet.
269 let crc = ETH_FSC::new(&packet[header_len..]); 276 let crc = ETH_FSC::new(&packet[header_len..]);
270 let _ = packet.extend_from_slice(crc.hton_bytes().as_slice()); 277 let _ = packet.extend_from_slice(crc.hton_bytes().as_slice());
271 278
272 let crc = ETH_FSC::new(&packet[header_len..]); 279 let send_len =
273 assert!(crc.crc_ok()); 280 u32::try_from(packet.len() - header_len + FRAME_HEADER_LEN).map_err(|_| AdinError::PACKET_TOO_BIG)?;
274
275 let send_len = packet.len() - header_len + FRAME_HEADER_LEN;
276 281
277 // Packet read of write to the MAC packet buffer must be a multipul of 4! 282 // Packet read of write to the MAC packet buffer must be a multipul of 4 bytes!
278 while packet.len() & 0x3 != 0 { 283 while packet.len() & 0x3 != 0 {
279 let _ = packet.push(DONT_CARE_BYTE); 284 let _ = packet.push(DONT_CARE_BYTE);
280 } 285 }
@@ -288,7 +293,7 @@ where
288 send_len, 293 send_len,
289 ); 294 );
290 295
291 self.write_reg(sr::TX_FSIZE, send_len as u32).await?; 296 self.write_reg(sr::TX_FSIZE, send_len).await?;
292 297
293 // Spi packet must be half word / even length 298 // Spi packet must be half word / even length
294 if send_len & 1 != 0 { 299 if send_len & 1 != 0 {
@@ -346,17 +351,21 @@ where
346 let mdio_acc_val: u32 = 351 let mdio_acc_val: u32 =
347 (0x1 << 28) | u32::from(phy_id & 0x1F) << 21 | u32::from(reg & 0x1F) << 16 | (0x3 << 26); 352 (0x1 << 28) | u32::from(phy_id & 0x1F) << 21 | u32::from(reg & 0x1F) << 16 | (0x3 << 26);
348 353
354 // Result is in the lower half of the answer.
355 #[allow(clippy::cast_possible_truncation)]
349 self.write_mdio_acc_reg(mdio_acc_val).await.map(|val| val as u16) 356 self.write_mdio_acc_reg(mdio_acc_val).await.map(|val| val as u16)
350 } 357 }
351 358
352 /// Read from the PHY Registers as Clause 45. 359 /// Read from the PHY Registers as Clause 45.
353 async fn read_cl45(&mut self, phy_id: u8, regc45: (u8, u16)) -> Result<u16, Self::Error> { 360 async fn read_cl45(&mut self, phy_id: u8, regc45: (u8, u16)) -> Result<u16, Self::Error> {
354 let mdio_acc_val: u32 = u32::from(phy_id & 0x1F) << 21 | u32::from(regc45.0 & 0x1F) << 16 | u32::from(regc45.1); 361 let mdio_acc_val = u32::from(phy_id & 0x1F) << 21 | u32::from(regc45.0 & 0x1F) << 16 | u32::from(regc45.1);
355 362
356 self.write_mdio_acc_reg(mdio_acc_val).await?; 363 self.write_mdio_acc_reg(mdio_acc_val).await?;
357 364
358 let mdio_acc_val: u32 = u32::from(phy_id & 0x1F) << 21 | u32::from(regc45.0 & 0x1F) << 16 | (0x03 << 26); 365 let mdio_acc_val = u32::from(phy_id & 0x1F) << 21 | u32::from(regc45.0 & 0x1F) << 16 | (0x03 << 26);
359 366
367 // Result is in the lower half of the answer.
368 #[allow(clippy::cast_possible_truncation)]
360 self.write_mdio_acc_reg(mdio_acc_val).await.map(|val| val as u16) 369 self.write_mdio_acc_reg(mdio_acc_val).await.map(|val| val as u16)
361 } 370 }
362 371
@@ -394,6 +403,7 @@ pub struct Runner<'d, SPI, INT, RST> {
394} 403}
395 404
396impl<'d, SPI: SpiDevice, INT: Wait, RST: OutputPin> Runner<'d, SPI, INT, RST> { 405impl<'d, SPI: SpiDevice, INT: Wait, RST: OutputPin> Runner<'d, SPI, INT, RST> {
406 #[allow(clippy::too_many_lines)]
397 pub async fn run(mut self) -> ! { 407 pub async fn run(mut self) -> ! {
398 loop { 408 loop {
399 let (state_chan, mut rx_chan, mut tx_chan) = self.ch.split(); 409 let (state_chan, mut rx_chan, mut tx_chan) = self.ch.split();
@@ -566,6 +576,7 @@ pub async fn new<const N_RX: usize, const N_TX: usize, SPI: SpiDevice, INT: Wait
566 576
567 // Reset sequence 577 // Reset sequence
568 reset.set_low().unwrap(); 578 reset.set_low().unwrap();
579
569 // Wait t1: 20-43mS 580 // Wait t1: 20-43mS
570 Timer::after(Duration::from_millis(30)).await; 581 Timer::after(Duration::from_millis(30)).await;
571 582
@@ -604,7 +615,7 @@ pub async fn new<const N_RX: usize, const N_TX: usize, SPI: SpiDevice, INT: Wait
604 } 615 }
605 616
606 // Config2: CRC_APPEND 617 // Config2: CRC_APPEND
607 let mut config2 = Config2(0x00000800); 618 let mut config2 = Config2(0x0000_0800);
608 config2.set_crc_append(true); 619 config2.set_crc_append(true);
609 mac.write_reg(sr::CONFIG2, config2.0).await.unwrap(); 620 mac.write_reg(sr::CONFIG2, config2.0).await.unwrap();
610 621
@@ -677,6 +688,7 @@ pub async fn new<const N_RX: usize, const N_TX: usize, SPI: SpiDevice, INT: Wait
677 ) 688 )
678} 689}
679 690
691#[allow(clippy::similar_names)]
680#[cfg(test)] 692#[cfg(test)]
681mod tests { 693mod tests {
682 use core::convert::Infallible; 694 use core::convert::Infallible;
@@ -743,16 +755,12 @@ mod tests {
743 let mut spe = ADIN1110::new(spi_dev, false); 755 let mut spe = ADIN1110::new(spi_dev, false);
744 756
745 // Read PHIID 757 // Read PHIID
746 match spe.read_reg(sr::PHYID).await { 758 let val = spe.read_reg(sr::PHYID).await.expect("Error");
747 Ok(val) => assert_eq!(val, 0x0283BC91), 759 assert_eq!(val, 0x0283_BC91);
748 Err(_e) => panic!("Error:"),
749 };
750 760
751 // Read CAPAVILITY 761 // Read CAPAVILITY
752 match spe.read_reg(sr::CAPABILITY).await { 762 let val = spe.read_reg(sr::CAPABILITY).await.expect("Error");
753 Ok(val) => assert_eq!(val, 0x000006C3), 763 assert_eq!(val, 0x0000_06C3);
754 Err(_e) => panic!("Error:"),
755 };
756 764
757 spi.done(); 765 spi.done();
758 } 766 }
@@ -778,20 +786,16 @@ mod tests {
778 786
779 let mut spe = ADIN1110::new(spi_dev, true); 787 let mut spe = ADIN1110::new(spi_dev, true);
780 788
781 assert_eq!(crc8(0x0283BC91_u32.to_be_bytes().as_slice()), 215); 789 assert_eq!(crc8(0x0283_BC91_u32.to_be_bytes().as_slice()), 215);
782 assert_eq!(crc8(0x000006C3_u32.to_be_bytes().as_slice()), 57); 790 assert_eq!(crc8(0x0000_06C3_u32.to_be_bytes().as_slice()), 57);
783 791
784 // Read PHIID 792 // Read PHIID
785 match spe.read_reg(sr::PHYID).await { 793 let val = spe.read_reg(sr::PHYID).await.expect("Error");
786 Ok(val) => assert_eq!(val, 0x0283BC91), 794 assert_eq!(val, 0x0283_BC91);
787 Err(e) => panic!("Error: {e:?}"),
788 };
789 795
790 // Read CAPAVILITY 796 // Read CAPAVILITY
791 match spe.read_reg(sr::CAPABILITY).await { 797 let val = spe.read_reg(sr::CAPABILITY).await.expect("Error");
792 Ok(val) => assert_eq!(val, 0x000006C3), 798 assert_eq!(val, 0x0000_06C3);
793 Err(_e) => panic!("Error:"),
794 };
795 799
796 spi.done(); 800 spi.done();
797 } 801 }
@@ -885,7 +889,7 @@ mod tests {
885 // ]; 889 // ];
886 890
887 // let mut packet = Packet::new(); 891 // let mut packet = Packet::new();
888 // packet.resize(64, 0).unwrap(); 892 // packet.resize(ETH_MIN_LEN, 0).unwrap();
889 893
890 // for &byte in &packet[4..] { 894 // for &byte in &packet[4..] {
891 // expectations.push(SpiTransaction::send(byte)); 895 // expectations.push(SpiTransaction::send(byte));
@@ -893,7 +897,7 @@ mod tests {
893 // } 897 // }
894 898
895 // // padding 899 // // padding
896 // for _ in packet.len() as u32..65 { 900 // for _ in packet.len()..65 {
897 // expectations.push(SpiTransaction::send(0x00)); 901 // expectations.push(SpiTransaction::send(0x00));
898 // expectations.push(SpiTransaction::read(DONT_CARE_BYTE)); 902 // expectations.push(SpiTransaction::read(DONT_CARE_BYTE));
899 // } 903 // }
@@ -943,7 +947,7 @@ mod tests {
943 // ]; 947 // ];
944 948
945 // let mut packet = Packet::new(); 949 // let mut packet = Packet::new();
946 // packet.resize(64, 0).unwrap(); 950 // packet.resize(ETH_MIN_LEN, 0).unwrap();
947 951
948 // for &byte in &packet[4..] { 952 // for &byte in &packet[4..] {
949 // expectations.push(SpiTransaction::send(byte)); 953 // expectations.push(SpiTransaction::send(byte));
@@ -951,7 +955,7 @@ mod tests {
951 // } 955 // }
952 956
953 // // padding 957 // // padding
954 // for _ in packet.len() as u32..64 { 958 // for _ in packet.len() as u32..ETH_MIN_LEN {
955 // expectations.push(SpiTransaction::send(0x00)); 959 // expectations.push(SpiTransaction::send(0x00));
956 // expectations.push(SpiTransaction::read(DONT_CARE_BYTE)); 960 // expectations.push(SpiTransaction::read(DONT_CARE_BYTE));
957 // } 961 // }
@@ -1061,7 +1065,7 @@ mod tests {
1061 // } 1065 // }
1062 1066
1063 // // padding 1067 // // padding
1064 // for _ in packet.len() as u32..64 { 1068 // for _ in packet.len()..ETH_MIN_LEN {
1065 // expectations.push(SpiTransaction::send(0x00)); 1069 // expectations.push(SpiTransaction::send(0x00));
1066 // expectations.push(SpiTransaction::read(DONT_CARE_BYTE)); 1070 // expectations.push(SpiTransaction::read(DONT_CARE_BYTE));
1067 // } 1071 // }
@@ -1119,7 +1123,7 @@ mod tests {
1119 // } 1123 // }
1120 1124
1121 // // padding 1125 // // padding
1122 // for _ in packet.len() as u32..64 { 1126 // for _ in packet.len()..ETH_MIN_LEN {
1123 // expectations.push(SpiTransaction::send(0x00)); 1127 // expectations.push(SpiTransaction::send(0x00));
1124 // expectations.push(SpiTransaction::read(DONT_CARE_BYTE)); 1128 // expectations.push(SpiTransaction::read(DONT_CARE_BYTE));
1125 // } 1129 // }
@@ -1176,7 +1180,7 @@ mod tests {
1176 // } 1180 // }
1177 1181
1178 // // padding 1182 // // padding
1179 // for _ in packet.len() as u32..64 { 1183 // for _ in packet.len()..ETH_MIN_LEN {
1180 // expectations.push(SpiTransaction::send(0x00)); 1184 // expectations.push(SpiTransaction::send(0x00));
1181 // expectations.push(SpiTransaction::read(DONT_CARE_BYTE)); 1185 // expectations.push(SpiTransaction::read(DONT_CARE_BYTE));
1182 // } 1186 // }
@@ -1219,15 +1223,17 @@ mod tests {
1219 spi_packet.extend_from_slice(&[160, 49, 143, 0, 0]).unwrap(); 1223 spi_packet.extend_from_slice(&[160, 49, 143, 0, 0]).unwrap();
1220 // Packet data 1224 // Packet data
1221 spi_packet.extend_from_slice(&packet).unwrap(); 1225 spi_packet.extend_from_slice(&packet).unwrap();
1222 // Packet padding up to 60 (64 - FCS) 1226 // Packet padding up to 60 (ETH_MIN_LEN - FCS)
1223 for _ in packet.len() as u32..60 { 1227 for _ in packet.len()..(ETH_MIN_LEN - FSC_LEN) {
1224 spi_packet.push(0x00).unwrap(); 1228 spi_packet.push(0x00).unwrap();
1225 } 1229 }
1226 // Packet FCS 1230 // Packet FCS
1227 spi_packet.extend_from_slice(&[147, 149, 213, 68]).unwrap(); 1231 spi_packet.extend_from_slice(&[147, 149, 213, 68]).unwrap();
1228 1232
1233 let spi_packet_len = u32::try_from(spi_packet.len()).unwrap();
1234
1229 // SPI HEADER Padding of u32 1235 // SPI HEADER Padding of u32
1230 for _ in spi_packet.len() as u32..size_align_u32(spi_packet.len() as u32) { 1236 for _ in spi_packet_len..size_align_u32(spi_packet_len) {
1231 spi_packet.push(0x00).unwrap(); 1237 spi_packet.push(0x00).unwrap();
1232 } 1238 }
1233 1239
@@ -1242,7 +1248,7 @@ mod tests {
1242 1248
1243 let mut spe = ADIN1110::new(spi_dev, true); 1249 let mut spe = ADIN1110::new(spi_dev, true);
1244 1250
1245 assert!(spe.write_fifo(&mut packet).await.is_ok()); 1251 assert!(spe.write_fifo(&packet).await.is_ok());
1246 1252
1247 spi.done(); 1253 spi.done();
1248 } 1254 }
diff --git a/embassy-net-adin1110/src/mdio.rs b/embassy-net-adin1110/src/mdio.rs
index ab7629d3d..68477006a 100644
--- a/embassy-net-adin1110/src/mdio.rs
+++ b/embassy-net-adin1110/src/mdio.rs
@@ -32,11 +32,11 @@ enum Reg13Op {
32 PostReadIncAddr = 0b10 << 14, 32 PostReadIncAddr = 0b10 << 14,
33 Read = 0b11 << 14, 33 Read = 0b11 << 14,
34} 34}
35/// MdioBus trait 35/// `MdioBus` trait
36/// Driver needs to implemnt the Claus 22 36/// Driver needs to implement the Clause 22
37/// Optional Clause 45 is the device supports this. 37/// Optional Clause 45 is the device supports this.
38/// 38///
39/// Claus 45 methodes are bases on https://www.ieee802.org/3/efm/public/nov02/oam/pannell_oam_1_1102.pdf 39/// Claus 45 methodes are bases on <https://www.ieee802.org/3/efm/public/nov02/oam/pannell_oam_1_1102.pdf>
40pub trait MdioBus { 40pub trait MdioBus {
41 type Error; 41 type Error;
42 42
@@ -52,13 +52,14 @@ pub trait MdioBus {
52 /// Implement this function when your hardware supports it. 52 /// Implement this function when your hardware supports it.
53 async fn read_cl45(&mut self, phy_id: PhyAddr, regc45: (u8, RegC45)) -> Result<RegVal, Self::Error> { 53 async fn read_cl45(&mut self, phy_id: PhyAddr, regc45: (u8, RegC45)) -> Result<RegVal, Self::Error> {
54 // Write FN 54 // Write FN
55 let val = (Reg13Op::Addr as RegVal) | (regc45.0 & DEV_MASK) as RegVal; 55 let val = (Reg13Op::Addr as RegVal) | RegVal::from(regc45.0 & DEV_MASK);
56
56 self.write_cl22(phy_id, REG13, val).await?; 57 self.write_cl22(phy_id, REG13, val).await?;
57 // Write Addr 58 // Write Addr
58 self.write_cl22(phy_id, REG14, regc45.1).await?; 59 self.write_cl22(phy_id, REG14, regc45.1).await?;
59 60
60 // Write FN 61 // Write FN
61 let val = (Reg13Op::Read as RegVal) | (regc45.0 & DEV_MASK) as RegVal; 62 let val = (Reg13Op::Read as RegVal) | RegVal::from(regc45.0 & DEV_MASK);
62 self.write_cl22(phy_id, REG13, val).await?; 63 self.write_cl22(phy_id, REG13, val).await?;
63 // Write Addr 64 // Write Addr
64 self.read_cl22(phy_id, REG14).await 65 self.read_cl22(phy_id, REG14).await
@@ -69,7 +70,7 @@ pub trait MdioBus {
69 /// Many hardware these days support direct Clause 45 operations. 70 /// Many hardware these days support direct Clause 45 operations.
70 /// Implement this function when your hardware supports it. 71 /// Implement this function when your hardware supports it.
71 async fn write_cl45(&mut self, phy_id: PhyAddr, regc45: (u8, RegC45), reg_val: RegVal) -> Result<(), Self::Error> { 72 async fn write_cl45(&mut self, phy_id: PhyAddr, regc45: (u8, RegC45), reg_val: RegVal) -> Result<(), Self::Error> {
72 let dev_addr = (regc45.0 & DEV_MASK) as RegVal; 73 let dev_addr = RegVal::from(regc45.0 & DEV_MASK);
73 let reg = regc45.1; 74 let reg = regc45.1;
74 75
75 // Write FN 76 // Write FN
diff --git a/embassy-net-adin1110/src/phy.rs b/embassy-net-adin1110/src/phy.rs
index 78d3fdf77..70060a0c3 100644
--- a/embassy-net-adin1110/src/phy.rs
+++ b/embassy-net-adin1110/src/phy.rs
@@ -30,7 +30,7 @@ pub mod RegsC45 {
30 } 30 }
31 31
32 impl DA1 { 32 impl DA1 {
33 pub fn into(self) -> (u8, u16) { 33 #[must_use] pub fn into(self) -> (u8, u16) {
34 (0x01, self as u16) 34 (0x01, self as u16)
35 } 35 }
36 } 36 }
@@ -48,7 +48,7 @@ pub mod RegsC45 {
48 } 48 }
49 49
50 impl DA3 { 50 impl DA3 {
51 pub fn into(self) -> (u8, u16) { 51 #[must_use] pub fn into(self) -> (u8, u16) {
52 (0x03, self as u16) 52 (0x03, self as u16)
53 } 53 }
54 } 54 }
@@ -62,7 +62,7 @@ pub mod RegsC45 {
62 } 62 }
63 63
64 impl DA7 { 64 impl DA7 {
65 pub fn into(self) -> (u8, u16) { 65 #[must_use] pub fn into(self) -> (u8, u16) {
66 (0x07, self as u16) 66 (0x07, self as u16)
67 } 67 }
68 } 68 }
@@ -84,7 +84,7 @@ pub mod RegsC45 {
84 } 84 }
85 85
86 impl DA1E { 86 impl DA1E {
87 pub fn into(self) -> (u8, u16) { 87 #[must_use] pub fn into(self) -> (u8, u16) {
88 (0x1e, self as u16) 88 (0x1e, self as u16)
89 } 89 }
90 } 90 }
@@ -100,7 +100,7 @@ pub mod RegsC45 {
100 } 100 }
101 101
102 impl DA1F { 102 impl DA1F {
103 pub fn into(self) -> (u8, u16) { 103 #[must_use] pub fn into(self) -> (u8, u16) {
104 (0x1f, self as u16) 104 (0x1f, self as u16)
105 } 105 }
106 } 106 }
@@ -121,8 +121,8 @@ impl Phy10BaseT1x {
121 MDIOBUS: MdioBus<Error = MDE>, 121 MDIOBUS: MdioBus<Error = MDE>,
122 MDE: core::fmt::Debug, 122 MDE: core::fmt::Debug,
123 { 123 {
124 let mut phyid = (mdiobus.read_cl22(self.0, RegsC22::PHY_ID1 as u8).await? as u32) << 16; 124 let mut phyid = u32::from(mdiobus.read_cl22(self.0, RegsC22::PHY_ID1 as u8).await?) << 16;
125 phyid |= mdiobus.read_cl22(self.0, RegsC22::PHY_ID2 as u8).await? as u32; 125 phyid |= u32::from(mdiobus.read_cl22(self.0, RegsC22::PHY_ID2 as u8).await?);
126 Ok(phyid) 126 Ok(phyid)
127 } 127 }
128 128
diff --git a/embassy-net-adin1110/src/regs.rs b/embassy-net-adin1110/src/regs.rs
index 93ce812db..4557929f0 100644
--- a/embassy-net-adin1110/src/regs.rs
+++ b/embassy-net-adin1110/src/regs.rs
@@ -74,7 +74,6 @@ impl From<u16> for SpiRegisters {
74} 74}
75 75
76// Register definitions 76// Register definitions
77
78bitfield! { 77bitfield! {
79 /// Status0 Register bits 78 /// Status0 Register bits
80 pub struct Status0(u32); 79 pub struct Status0(u32);
@@ -242,6 +241,7 @@ bitfield! {
242 pub link_change_mask, set_link_change_mask : 1; 241 pub link_change_mask, set_link_change_mask : 1;
243} 242}
244 243
244/// LED Functions
245#[repr(u8)] 245#[repr(u8)]
246pub enum LedFunc { 246pub enum LedFunc {
247 LinkupTxRxActicity = 0, 247 LinkupTxRxActicity = 0,
@@ -326,7 +326,7 @@ bitfield_bitrange! {struct LedCntrl(u16)}
326impl LedCntrl { 326impl LedCntrl {
327 bitfield_fields! { 327 bitfield_fields! {
328 u8; 328 u8;
329 /// LED_0 Pin Function 329 /// LED 0 Pin Function
330 pub from into LedFunc, led0_function, set_led0_function: 4, 0; 330 pub from into LedFunc, led0_function, set_led0_function: 4, 0;
331 /// LED 0 Mode Selection 331 /// LED 0 Mode Selection
332 pub led0_mode, set_led0_mode: 5; 332 pub led0_mode, set_led0_mode: 5;
@@ -334,7 +334,7 @@ impl LedCntrl {
334 pub led0_link_st_qualify, set_led0_link_st_qualify: 6; 334 pub led0_link_st_qualify, set_led0_link_st_qualify: 6;
335 /// LED 0 Enable 335 /// LED 0 Enable
336 pub led0_en, set_led0_en: 7; 336 pub led0_en, set_led0_en: 7;
337 /// LED_1 Pin Function 337 /// LED 1 Pin Function
338 pub from into LedFunc, led1_function, set_led1_function: 12, 8; 338 pub from into LedFunc, led1_function, set_led1_function: 12, 8;
339 /// /// LED 1 Mode Selection 339 /// /// LED 1 Mode Selection
340 pub led1_mode, set_led1_mode: 13; 340 pub led1_mode, set_led1_mode: 13;
@@ -349,7 +349,7 @@ impl LedCntrl {
349 } 349 }
350} 350}
351 351
352// #[allow(dead_code)] 352// LED Polarity
353#[repr(u8)] 353#[repr(u8)]
354pub enum LedPol { 354pub enum LedPol {
355 AutoSense = 0, 355 AutoSense = 0,
@@ -384,12 +384,12 @@ impl LedPolarity {
384 u8; 384 u8;
385 /// LED 1 Polarity 385 /// LED 1 Polarity
386 pub from into LedPol, led1_polarity, set_led1_polarity: 3, 2; 386 pub from into LedPol, led1_polarity, set_led1_polarity: 3, 2;
387 /// LED_0 Polarity 387 /// LED 0 Polarity
388 pub from into LedPol, led0_polarity, set_led0_polarity: 1, 0; 388 pub from into LedPol, led0_polarity, set_led0_polarity: 1, 0;
389 } 389 }
390} 390}
391 391
392/// LED Control Register 392/// SPI Header
393#[derive(Copy, Clone, PartialEq, Eq, Hash)] 393#[derive(Copy, Clone, PartialEq, Eq, Hash)]
394pub struct SpiHeader(pub u16); 394pub struct SpiHeader(pub u16);
395bitfield_bitrange! {struct SpiHeader(u16)} 395bitfield_bitrange! {struct SpiHeader(u16)}
@@ -400,8 +400,9 @@ impl SpiHeader {
400 /// Mask Bit for TXF_ECC_ERR 400 /// Mask Bit for TXF_ECC_ERR
401 pub control, set_control : 15; 401 pub control, set_control : 15;
402 pub full_duplex, set_full_duplex : 14; 402 pub full_duplex, set_full_duplex : 14;
403 /// Read or Write to register
403 pub write, set_write : 13; 404 pub write, set_write : 13;
404 /// LED_0 Polarity 405 /// Registers ID/addr
405 pub from into SpiRegisters, addr, set_addr: 11, 0; 406 pub from into SpiRegisters, addr, set_addr: 11, 0;
406 } 407 }
407} 408}