@@ -10,15 +10,15 @@ pub use miim::*;
1010pub ( crate ) struct MacParts {
1111 pub eth_mac : ETHERNET_MAC ,
1212 #[ cfg( feature = "f-series" ) ]
13- pub eth_mmc : ETHERNET_MMC ,
13+ pub eth_mmc : crate :: stm32 :: ETHERNET_MMC ,
1414}
1515
1616impl MacParts {
1717 fn enable_promicious_mode ( & self ) {
1818 let Self { eth_mac, .. } = self ;
1919
2020 #[ cfg( feature = "f-series" ) ]
21- let ( mac_filter_reg , flow_control) = ( & eth_mac. macffr , & eth_mac. macfcr ) ;
21+ let ( mac_filter , flow_control) = ( & eth_mac. macffr , & eth_mac. macfcr ) ;
2222 #[ cfg( feature = "stm32h7xx-hal" ) ]
2323 let ( mac_filter, flow_control) = ( & eth_mac. macpfr , & eth_mac. macqtx_fcr ) ;
2424
@@ -42,14 +42,9 @@ impl MacParts {
4242 }
4343
4444 fn disable_mmc_interrupts ( & self ) {
45- let Self {
46- eth_mac,
47- #[ cfg( feature = "f-series" ) ]
48- eth_mmc,
49- } = self ;
50-
5145 #[ cfg( feature = "f-series" ) ]
5246 {
47+ let eth_mmc = & self . eth_mmc ;
5348 // Disable all MMC RX interrupts
5449 eth_mmc
5550 . mmcrimr
@@ -69,6 +64,8 @@ impl MacParts {
6964
7065 #[ cfg( feature = "stm32h7xx-hal" ) ]
7166 {
67+ let eth_mac = & self . eth_mac ;
68+
7269 // Disable all MMC RX interrupts
7370 eth_mac. mmc_rx_interrupt_mask . write ( |w| {
7471 w. rxlpitrcim ( )
@@ -163,11 +160,7 @@ impl EthernetMAC {
163160 // it doesn't work.
164161 _dma : & EthernetDMA ,
165162 ) -> Result < Self , WrongClock > {
166- let MacParts {
167- eth_mac,
168- #[ cfg( feature = "f-series" ) ]
169- eth_mmc,
170- } = & parts;
163+ let eth_mac = & parts. eth_mac ;
171164
172165 // TODO: configure MDIOS
173166 #[ cfg( feature = "f-series" ) ]
@@ -218,12 +211,7 @@ impl EthernetMAC {
218211 . dr ( )
219212 . set_bit ( ) ;
220213
221- // Fast Ethernet speed
222- w. fes ( )
223- . set_bit ( )
224- // Duplex mode
225- . dm ( )
226- . set_bit ( )
214+ w
227215 // Receiver enable
228216 . re ( )
229217 . set_bit ( )
@@ -244,6 +232,31 @@ impl EthernetMAC {
244232 Ok ( me)
245233 }
246234
235+ /// Set the Ethernet Speed at which the MAC communicates
236+ ///
237+ /// Note that this does _not_ affect the PHY in any way. To
238+ /// configure the PHY, use [`EthernetMACWithMii`] (see: [`Self::with_mii`])
239+ /// or [`Stm32Mii`] (see: [`Self::mii`])
240+ pub fn set_speed ( & mut self , speed : Speed ) {
241+ self . eth_mac . maccr . modify ( |_, w| match speed {
242+ Speed :: HalfDuplexBase10T => w. fes ( ) . clear_bit ( ) . dm ( ) . clear_bit ( ) ,
243+ Speed :: FullDuplexBase10T => w. fes ( ) . clear_bit ( ) . dm ( ) . set_bit ( ) ,
244+ Speed :: HalfDuplexBase100Tx => w. fes ( ) . set_bit ( ) . dm ( ) . clear_bit ( ) ,
245+ Speed :: FullDuplexBase100Tx => w. fes ( ) . set_bit ( ) . dm ( ) . set_bit ( ) ,
246+ } ) ;
247+ }
248+
249+ /// Get the Ethernet Speed at which the MAC communicates
250+ pub fn get_speed ( & self ) -> Speed {
251+ let cr = self . eth_mac . maccr . read ( ) ;
252+ match ( cr. fes ( ) . bit_is_set ( ) , cr. dm ( ) . bit_is_set ( ) ) {
253+ ( false , false ) => Speed :: HalfDuplexBase10T ,
254+ ( false , true ) => Speed :: FullDuplexBase10T ,
255+ ( true , false ) => Speed :: HalfDuplexBase100Tx ,
256+ ( true , true ) => Speed :: FullDuplexBase100Tx ,
257+ }
258+ }
259+
247260 /// Borrow access to the MAC's SMI.
248261 ///
249262 /// Allows for controlling and monitoring any PHYs that may be accessible via the MDIO/MDC
@@ -271,36 +284,7 @@ impl EthernetMAC {
271284 MDIO : MdioPin ,
272285 MDC : MdcPin ,
273286 {
274- EthernetMACWithMii {
275- eth_mac : self ,
276- mdio,
277- mdc,
278- }
279- }
280-
281- /// Set the Ethernet Speed at which the MAC communicates
282- ///
283- /// Note that this does _not_ affect the PHY in any way. To
284- /// configure the PHY, use [`EthernetMACWithMii`] (see: [`Self::with_mii`])
285- /// or [`Stm32Mii`] (see: [`Self::mii`])
286- pub fn set_speed ( & mut self , speed : Speed ) {
287- self . eth_mac . maccr . modify ( |_, w| match speed {
288- Speed :: HalfDuplexBase10T => w. fes ( ) . clear_bit ( ) . dm ( ) . clear_bit ( ) ,
289- Speed :: FullDuplexBase10T => w. fes ( ) . clear_bit ( ) . dm ( ) . set_bit ( ) ,
290- Speed :: HalfDuplexBase100Tx => w. fes ( ) . set_bit ( ) . dm ( ) . clear_bit ( ) ,
291- Speed :: FullDuplexBase100Tx => w. fes ( ) . set_bit ( ) . dm ( ) . set_bit ( ) ,
292- } ) ;
293- }
294-
295- /// Get the Ethernet Speed at which the MAC communicates
296- pub fn get_speed ( & self ) -> Speed {
297- let cr = self . eth_mac . maccr . read ( ) ;
298- match ( cr. fes ( ) . bit_is_set ( ) , cr. dm ( ) . bit_is_set ( ) ) {
299- ( false , false ) => Speed :: HalfDuplexBase10T ,
300- ( false , true ) => Speed :: FullDuplexBase10T ,
301- ( true , false ) => Speed :: HalfDuplexBase100Tx ,
302- ( true , true ) => Speed :: FullDuplexBase100Tx ,
303- }
287+ EthernetMACWithMii :: new ( self , mdio, mdc)
304288 }
305289
306290 #[ cfg( feature = "ptp" ) ]
0 commit comments