Skip to content

Commit f3910f3

Browse files
author
Johannes Draaijer
committed
Put SMI into it's own MAC module
Remove type state and just have another type for owned SMI
1 parent 341ce32 commit f3910f3

File tree

4 files changed

+263
-251
lines changed

4 files changed

+263
-251
lines changed

src/lib.rs

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
//! An abstraction layer for ethernet periperhals embedded in STM32 processors.
22
//!
3-
//! For initialisation, see [`new`], and [`new_owned_smi`]
3+
//! For initialisation, see [`new`], and [`new_with_smi_pins`]
44
#![no_std]
55

6+
use mac::EthernetMACWithSmi;
67
/// Re-export
78
#[cfg(feature = "stm32f7xx-hal")]
89
pub use stm32f7xx_hal as hal;
@@ -74,6 +75,8 @@ mod consts {
7475
use self::consts::*;
7576

7677
/// HCLK must be at least 25MHz to use the ethernet peripheral.
78+
/// This (empty) struct is returned to indicate that it is not set
79+
/// correctly
7780
#[derive(Debug)]
7881
pub struct WrongClock;
7982

@@ -103,7 +106,7 @@ pub fn new<'rx, 'tx, REFCLK, CRS, TXEN, TXD0, TXD1, RXD0, RXD1>(
103106
tx_buffer: &'tx mut [TxRingEntry],
104107
clocks: Clocks,
105108
pins: EthPins<REFCLK, CRS, TXEN, TXD0, TXD1, RXD0, RXD1>,
106-
) -> Result<(EthernetDMA<'rx, 'tx>, EthernetMAC<mac::BorrowedSmi>), WrongClock>
109+
) -> Result<(EthernetDMA<'rx, 'tx>, EthernetMAC), WrongClock>
107110
where
108111
REFCLK: RmiiRefClk + AlternateVeryHighSpeed,
109112
CRS: RmiiCrsDv + AlternateVeryHighSpeed,
@@ -115,7 +118,7 @@ where
115118
{
116119
pins.setup_pins();
117120

118-
let eth_mac = EthernetMAC::<mac::BorrowedSmi>::new(eth_mac);
121+
let eth_mac = EthernetMAC::new(eth_mac);
119122

120123
unsafe { new_unchecked(eth_mac, eth_mmc, eth_dma, rx_buffer, tx_buffer, clocks) }
121124
}
@@ -139,7 +142,7 @@ where
139142
/// accessible by the peripheral. Core-Coupled Memory (CCM) is
140143
/// usually not accessible.
141144
/// - HCLK must be at least 25 MHz.
142-
pub fn new_owned_smi<'rx, 'tx, REFCLK, CRS, TXEN, TXD0, TXD1, RXD0, RXD1, MDIO, MDC>(
145+
pub fn new_with_smi<'rx, 'tx, REFCLK, CRS, TXEN, TXD0, TXD1, RXD0, RXD1, MDIO, MDC>(
143146
eth_mac: ETHERNET_MAC,
144147
eth_mmc: ETHERNET_MMC,
145148
eth_dma: ETHERNET_DMA,
@@ -149,13 +152,7 @@ pub fn new_owned_smi<'rx, 'tx, REFCLK, CRS, TXEN, TXD0, TXD1, RXD0, RXD1, MDIO,
149152
pins: EthPins<REFCLK, CRS, TXEN, TXD0, TXD1, RXD0, RXD1>,
150153
mdio: MDIO,
151154
mdc: MDC,
152-
) -> Result<
153-
(
154-
EthernetDMA<'rx, 'tx>,
155-
EthernetMAC<crate::mac::OwnedSmi<MDIO, MDC>>,
156-
),
157-
WrongClock,
158-
>
155+
) -> Result<(EthernetDMA<'rx, 'tx>, EthernetMACWithSmi<MDIO, MDC>), WrongClock>
159156
where
160157
REFCLK: RmiiRefClk + AlternateVeryHighSpeed,
161158
CRS: RmiiCrsDv + AlternateVeryHighSpeed,
@@ -169,9 +166,10 @@ where
169166
{
170167
pins.setup_pins();
171168

172-
let eth_mac = EthernetMAC::<mac::OwnedSmi<MDIO, MDC>>::new(eth_mac, mdio, mdc);
169+
let eth_mac = EthernetMAC::new(eth_mac);
173170

174171
unsafe { new_unchecked(eth_mac, eth_mmc, eth_dma, rx_buffer, tx_buffer, clocks) }
172+
.map(|(dma, mac)| (dma, mac.with_smi(mdio, mdc)))
175173
}
176174

177175
/// Create and initialise the ethernet driver (without GPIO configuration and validation).
@@ -186,14 +184,14 @@ where
186184
/// accessible by the peripheral. Core-Coupled Memory (CCM) is
187185
/// usually not accessible.
188186
/// - HCLK must be at least 25MHz.
189-
pub unsafe fn new_unchecked<'rx, 'tx, Smi>(
190-
eth_mac_in: EthernetMAC<Smi>,
187+
pub unsafe fn new_unchecked<'rx, 'tx>(
188+
eth_mac_in: EthernetMAC,
191189
eth_mmc: ETHERNET_MMC,
192190
eth_dma: ETHERNET_DMA,
193191
rx_buffer: &'rx mut [RxRingEntry],
194192
tx_buffer: &'tx mut [TxRingEntry],
195193
clocks: Clocks,
196-
) -> Result<(EthernetDMA<'rx, 'tx>, EthernetMAC<Smi>), WrongClock> {
194+
) -> Result<(EthernetDMA<'rx, 'tx>, EthernetMAC), WrongClock> {
197195
setup::setup();
198196

199197
let eth_mac = &eth_mac_in.eth_mac;

src/mac.rs

Lines changed: 0 additions & 236 deletions
This file was deleted.

0 commit comments

Comments
 (0)