diff options
| author | Ulf Lilleengen <[email protected]> | 2023-12-20 12:44:19 +0000 |
|---|---|---|
| committer | GitHub <[email protected]> | 2023-12-20 12:44:19 +0000 |
| commit | 76c600365d8685d58c95d898f5469b0cb5bb0864 (patch) | |
| tree | 6fa081156be2f156c7ab26ff5e2fac5d3fa81b7a | |
| parent | 18dac099cb136ee9186ca2d4a97ea86dff60c5ac (diff) | |
| parent | 51a67cb69ab72e44c6cbeea677c4c6bd1e5c2550 (diff) | |
Merge pull request #2334 from embassy-rs/embassy-net-adin1110-docs
docs: embassy-net-adin1110
| -rw-r--r-- | embassy-net-adin1110/Cargo.toml | 3 | ||||
| -rw-r--r-- | embassy-net-adin1110/src/crc32.rs | 8 | ||||
| -rw-r--r-- | embassy-net-adin1110/src/lib.rs | 7 | ||||
| -rw-r--r-- | embassy-net-adin1110/src/mdio.rs | 1 | ||||
| -rw-r--r-- | embassy-net-adin1110/src/regs.rs | 1 |
5 files changed, 15 insertions, 5 deletions
diff --git a/embassy-net-adin1110/Cargo.toml b/embassy-net-adin1110/Cargo.toml index b1582ac9b..f1be52da5 100644 --- a/embassy-net-adin1110/Cargo.toml +++ b/embassy-net-adin1110/Cargo.toml | |||
| @@ -6,8 +6,7 @@ keywords = ["embedded", "ADIN1110", "embassy-net", "embedded-hal-async", "ethern | |||
| 6 | categories = ["embedded", "hardware-support", "no-std", "network-programming", "async"] | 6 | categories = ["embedded", "hardware-support", "no-std", "network-programming", "async"] |
| 7 | license = "MIT OR Apache-2.0" | 7 | license = "MIT OR Apache-2.0" |
| 8 | edition = "2021" | 8 | edition = "2021" |
| 9 | 9 | repository = "https://github.com/embassy-rs/embassy" | |
| 10 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
| 11 | 10 | ||
| 12 | [dependencies] | 11 | [dependencies] |
| 13 | heapless = "0.8" | 12 | heapless = "0.8" |
diff --git a/embassy-net-adin1110/src/crc32.rs b/embassy-net-adin1110/src/crc32.rs index ec020b70c..4b3c69f23 100644 --- a/embassy-net-adin1110/src/crc32.rs +++ b/embassy-net-adin1110/src/crc32.rs | |||
| @@ -1,3 +1,4 @@ | |||
| 1 | /// CRC32 lookup table. | ||
| 1 | pub const CRC32R_LOOKUP_TABLE: [u32; 256] = [ | 2 | pub const CRC32R_LOOKUP_TABLE: [u32; 256] = [ |
| 2 | 0x0000_0000, | 3 | 0x0000_0000, |
| 3 | 0x7707_3096, | 4 | 0x7707_3096, |
| @@ -263,8 +264,9 @@ pub const CRC32R_LOOKUP_TABLE: [u32; 256] = [ | |||
| 263 | pub struct ETH_FCS(pub u32); | 264 | pub struct ETH_FCS(pub u32); |
| 264 | 265 | ||
| 265 | impl ETH_FCS { | 266 | impl ETH_FCS { |
| 266 | pub const CRC32_OK: u32 = 0x2144_df1c; | 267 | const CRC32_OK: u32 = 0x2144_df1c; |
| 267 | 268 | ||
| 269 | /// Create a new frame check sequence from `data`. | ||
| 268 | #[must_use] | 270 | #[must_use] |
| 269 | pub fn new(data: &[u8]) -> Self { | 271 | pub fn new(data: &[u8]) -> Self { |
| 270 | let fcs = data.iter().fold(u32::MAX, |crc, byte| { | 272 | let fcs = data.iter().fold(u32::MAX, |crc, byte| { |
| @@ -274,6 +276,7 @@ impl ETH_FCS { | |||
| 274 | Self(fcs) | 276 | Self(fcs) |
| 275 | } | 277 | } |
| 276 | 278 | ||
| 279 | /// Update the frame check sequence with `data`. | ||
| 277 | #[must_use] | 280 | #[must_use] |
| 278 | pub fn update(self, data: &[u8]) -> Self { | 281 | pub fn update(self, data: &[u8]) -> Self { |
| 279 | let fcs = data.iter().fold(self.0 ^ u32::MAX, |crc, byte| { | 282 | let fcs = data.iter().fold(self.0 ^ u32::MAX, |crc, byte| { |
| @@ -283,16 +286,19 @@ impl ETH_FCS { | |||
| 283 | Self(fcs) | 286 | Self(fcs) |
| 284 | } | 287 | } |
| 285 | 288 | ||
| 289 | /// Check if the frame check sequence is correct. | ||
| 286 | #[must_use] | 290 | #[must_use] |
| 287 | pub fn crc_ok(&self) -> bool { | 291 | pub fn crc_ok(&self) -> bool { |
| 288 | self.0 == Self::CRC32_OK | 292 | self.0 == Self::CRC32_OK |
| 289 | } | 293 | } |
| 290 | 294 | ||
| 295 | /// Switch byte order. | ||
| 291 | #[must_use] | 296 | #[must_use] |
| 292 | pub fn hton_bytes(&self) -> [u8; 4] { | 297 | pub fn hton_bytes(&self) -> [u8; 4] { |
| 293 | self.0.to_le_bytes() | 298 | self.0.to_le_bytes() |
| 294 | } | 299 | } |
| 295 | 300 | ||
| 301 | /// Switch byte order as a u32. | ||
| 296 | #[must_use] | 302 | #[must_use] |
| 297 | pub fn hton(&self) -> u32 { | 303 | pub fn hton(&self) -> u32 { |
| 298 | self.0.to_le() | 304 | self.0.to_le() |
diff --git a/embassy-net-adin1110/src/lib.rs b/embassy-net-adin1110/src/lib.rs index 080b3f94d..6ecfa587d 100644 --- a/embassy-net-adin1110/src/lib.rs +++ b/embassy-net-adin1110/src/lib.rs | |||
| @@ -5,6 +5,7 @@ | |||
| 5 | #![allow(clippy::missing_errors_doc)] | 5 | #![allow(clippy::missing_errors_doc)] |
| 6 | #![allow(clippy::missing_panics_doc)] | 6 | #![allow(clippy::missing_panics_doc)] |
| 7 | #![doc = include_str!("../README.md")] | 7 | #![doc = include_str!("../README.md")] |
| 8 | #![warn(missing_docs)] | ||
| 8 | 9 | ||
| 9 | // must go first! | 10 | // must go first! |
| 10 | mod fmt; | 11 | mod fmt; |
| @@ -26,8 +27,9 @@ use embedded_hal_async::digital::Wait; | |||
| 26 | use embedded_hal_async::spi::{Error, Operation, SpiDevice}; | 27 | use embedded_hal_async::spi::{Error, Operation, SpiDevice}; |
| 27 | use heapless::Vec; | 28 | use heapless::Vec; |
| 28 | pub use mdio::MdioBus; | 29 | pub use mdio::MdioBus; |
| 29 | pub use phy::{Phy10BaseT1x, RegsC22, RegsC45}; | 30 | pub use phy::Phy10BaseT1x; |
| 30 | pub use regs::{Config0, Config2, SpiRegisters as sr, Status0, Status1}; | 31 | use phy::{RegsC22, RegsC45}; |
| 32 | use regs::{Config0, Config2, SpiRegisters as sr, Status0, Status1}; | ||
| 31 | 33 | ||
| 32 | use crate::fmt::Bytes; | 34 | use crate::fmt::Bytes; |
| 33 | use crate::regs::{LedCntrl, LedFunc, LedPol, LedPolarity, SpiHeader}; | 35 | use crate::regs::{LedCntrl, LedFunc, LedPol, LedPolarity, SpiHeader}; |
| @@ -446,6 +448,7 @@ pub struct Runner<'d, SPI, INT, RST> { | |||
| 446 | } | 448 | } |
| 447 | 449 | ||
| 448 | impl<'d, SPI: SpiDevice, INT: Wait, RST: OutputPin> Runner<'d, SPI, INT, RST> { | 450 | impl<'d, SPI: SpiDevice, INT: Wait, RST: OutputPin> Runner<'d, SPI, INT, RST> { |
| 451 | /// Run the driver. | ||
| 449 | #[allow(clippy::too_many_lines)] | 452 | #[allow(clippy::too_many_lines)] |
| 450 | pub async fn run(mut self) -> ! { | 453 | pub async fn run(mut self) -> ! { |
| 451 | loop { | 454 | loop { |
diff --git a/embassy-net-adin1110/src/mdio.rs b/embassy-net-adin1110/src/mdio.rs index 1ae5f0043..6fea9370e 100644 --- a/embassy-net-adin1110/src/mdio.rs +++ b/embassy-net-adin1110/src/mdio.rs | |||
| @@ -39,6 +39,7 @@ enum Reg13Op { | |||
| 39 | /// | 39 | /// |
| 40 | /// Clause 45 methodes are bases on <https://www.ieee802.org/3/efm/public/nov02/oam/pannell_oam_1_1102.pdf> | 40 | /// Clause 45 methodes are bases on <https://www.ieee802.org/3/efm/public/nov02/oam/pannell_oam_1_1102.pdf> |
| 41 | pub trait MdioBus { | 41 | pub trait MdioBus { |
| 42 | /// Error type. | ||
| 42 | type Error; | 43 | type Error; |
| 43 | 44 | ||
| 44 | /// Read, Clause 22 | 45 | /// Read, Clause 22 |
diff --git a/embassy-net-adin1110/src/regs.rs b/embassy-net-adin1110/src/regs.rs index beaf9466e..8780c2b9d 100644 --- a/embassy-net-adin1110/src/regs.rs +++ b/embassy-net-adin1110/src/regs.rs | |||
| @@ -2,6 +2,7 @@ use core::fmt::{Debug, Display}; | |||
| 2 | 2 | ||
| 3 | use bitfield::{bitfield, bitfield_bitrange, bitfield_fields}; | 3 | use bitfield::{bitfield, bitfield_bitrange, bitfield_fields}; |
| 4 | 4 | ||
| 5 | #[allow(missing_docs)] | ||
| 5 | #[allow(non_camel_case_types)] | 6 | #[allow(non_camel_case_types)] |
| 6 | #[derive(Debug, Copy, Clone)] | 7 | #[derive(Debug, Copy, Clone)] |
| 7 | #[cfg_attr(feature = "defmt", derive(defmt::Format))] | 8 | #[cfg_attr(feature = "defmt", derive(defmt::Format))] |
