44#[ cfg_attr( any( eth_v1a, eth_v1b, eth_v1c) , path = "v1/mod.rs" ) ]
55#[ cfg_attr( eth_v2, path = "v2/mod.rs" ) ]
66mod _version;
7- pub mod generic_smi ;
7+ mod generic_phy ;
88
99use core:: mem:: MaybeUninit ;
1010use core:: task:: Context ;
@@ -13,6 +13,7 @@ use embassy_net_driver::{Capabilities, HardwareAddress, LinkState};
1313use embassy_sync:: waitqueue:: AtomicWaker ;
1414
1515pub use self :: _version:: { InterruptHandler , * } ;
16+ pub use self :: generic_phy:: * ;
1617use crate :: rcc:: RccPeripheral ;
1718
1819#[ allow( unused) ]
@@ -71,7 +72,7 @@ impl<const TX: usize, const RX: usize> PacketQueue<TX, RX> {
7172
7273static WAKER : AtomicWaker = AtomicWaker :: new ( ) ;
7374
74- impl < ' d , T : Instance , P : PHY > embassy_net_driver:: Driver for Ethernet < ' d , T , P > {
75+ impl < ' d , T : Instance , P : Phy > embassy_net_driver:: Driver for Ethernet < ' d , T , P > {
7576 type RxToken < ' a >
7677 = RxToken < ' a , ' d >
7778 where
@@ -156,23 +157,15 @@ impl<'a, 'd> embassy_net_driver::TxToken for TxToken<'a, 'd> {
156157}
157158
158159/// Station Management Interface (SMI) on an ethernet PHY
159- ///
160- /// # Safety
161- ///
162- /// The methods cannot move out of self
163- pub unsafe trait StationManagement {
160+ pub trait StationManagement {
164161 /// Read a register over SMI.
165162 fn smi_read ( & mut self , phy_addr : u8 , reg : u8 ) -> u16 ;
166163 /// Write a register over SMI.
167164 fn smi_write ( & mut self , phy_addr : u8 , reg : u8 , val : u16 ) ;
168165}
169166
170- /// Traits for an Ethernet PHY
171- ///
172- /// # Safety
173- ///
174- /// The methods cannot move S
175- pub unsafe trait PHY {
167+ /// Trait for an Ethernet PHY
168+ pub trait Phy {
176169 /// Reset PHY and wait for it to come out of reset.
177170 fn phy_reset < S : StationManagement > ( & mut self , sm : & mut S ) ;
178171 /// PHY initialisation.
@@ -181,18 +174,23 @@ pub unsafe trait PHY {
181174 fn poll_link < S : StationManagement > ( & mut self , sm : & mut S , cx : & mut Context ) -> bool ;
182175}
183176
184- impl < ' d , T : Instance , P : PHY > Ethernet < ' d , T , P > {
177+ impl < ' d , T : Instance , P : Phy > Ethernet < ' d , T , P > {
185178 /// Directly expose the SMI interface used by the Ethernet driver.
186179 ///
187180 /// This can be used to for example configure special PHY registers for compliance testing.
188- ///
189- /// # Safety
190- ///
191- /// Revert any temporary PHY register changes such as to enable test modes before handing
192- /// the Ethernet device over to the networking stack otherwise things likely won't work.
193- pub unsafe fn station_management ( & mut self ) -> & mut impl StationManagement {
181+ pub fn station_management ( & mut self ) -> & mut impl StationManagement {
194182 & mut self . station_management
195183 }
184+
185+ /// Access the user-supplied `Phy`.
186+ pub fn phy ( & self ) -> & P {
187+ & self . phy
188+ }
189+
190+ /// Mutably access the user-supplied `Phy`.
191+ pub fn phy_mut ( & mut self ) -> & mut P {
192+ & mut self . phy
193+ }
196194}
197195
198196trait SealedInstance {
0 commit comments