Skip to main content

ch32_hal/eth/v1/
pins.rs

1use super::Instance;
2use crate::gpio::{AFType, AnyPin, Pin, Pull, Speed};
3use crate::Peri;
4
5pin_trait!(RefClkPin, Instance);
6pin_trait!(MdioPin, Instance);
7pin_trait!(MdcPin, Instance);
8pin_trait!(CrsDvPin, Instance);
9pin_trait!(Rxd0Pin, Instance);
10pin_trait!(Rxd1Pin, Instance);
11pin_trait!(TxEnPin, Instance);
12pin_trait!(Txd0Pin, Instance);
13pin_trait!(Txd1Pin, Instance);
14
15// Default RMII mapping only; remapped pin combinations are not supported.
16pin_trait_impl!(crate::eth::RefClkPin, ETH, PA1, 0);
17pin_trait_impl!(crate::eth::MdioPin, ETH, PA2, 0);
18pin_trait_impl!(crate::eth::MdcPin, ETH, PC1, 0);
19pin_trait_impl!(crate::eth::CrsDvPin, ETH, PA7, 0);
20pin_trait_impl!(crate::eth::Rxd0Pin, ETH, PC4, 0);
21pin_trait_impl!(crate::eth::Rxd1Pin, ETH, PC5, 0);
22pin_trait_impl!(crate::eth::TxEnPin, ETH, PB11, 0);
23pin_trait_impl!(crate::eth::Txd0Pin, ETH, PB12, 0);
24pin_trait_impl!(crate::eth::Txd1Pin, ETH, PB13, 0);
25
26/// Pins for the default RMII mapping, consumed and configured by
27/// [`Ethernet::new_rmii`](super::Ethernet::new_rmii).
28///
29/// Signal traits are checked against the Ethernet instance by the constructor.
30pub struct RmiiPins<
31    'd,
32    REFCLK: Pin,
33    MDIO: Pin,
34    MDC: Pin,
35    CRSDV: Pin,
36    RXD0: Pin,
37    RXD1: Pin,
38    TXEN: Pin,
39    TXD0: Pin,
40    TXD1: Pin,
41> {
42    /// REF_CLK (PA1).
43    pub ref_clk: Peri<'d, REFCLK>,
44    /// MDIO (PA2).
45    pub mdio: Peri<'d, MDIO>,
46    /// MDC (PC1).
47    pub mdc: Peri<'d, MDC>,
48    /// CRS_DV (PA7).
49    pub crs_dv: Peri<'d, CRSDV>,
50    /// RXD0 (PC4).
51    pub rxd0: Peri<'d, RXD0>,
52    /// RXD1 (PC5).
53    pub rxd1: Peri<'d, RXD1>,
54    /// TX_EN (PB11).
55    pub tx_en: Peri<'d, TXEN>,
56    /// TXD0 (PB12).
57    pub txd0: Peri<'d, TXD0>,
58    /// TXD1 (PB13).
59    pub txd1: Peri<'d, TXD1>,
60}
61
62impl<'d, REFCLK: Pin, MDIO: Pin, MDC: Pin, CRSDV: Pin, RXD0: Pin, RXD1: Pin, TXEN: Pin, TXD0: Pin, TXD1: Pin>
63    RmiiPins<'d, REFCLK, MDIO, MDC, CRSDV, RXD0, RXD1, TXEN, TXD0, TXD1>
64{
65    pub(super) fn configure(self) -> [Peri<'d, AnyPin>; 9] {
66        self.ref_clk.set_as_input(Pull::None);
67        self.mdio.set_as_af_output(AFType::OutputPushPull, Speed::High);
68        self.mdc.set_as_af_output(AFType::OutputPushPull, Speed::High);
69        self.crs_dv.set_as_input(Pull::None);
70        self.rxd0.set_as_input(Pull::None);
71        self.rxd1.set_as_input(Pull::None);
72        self.tx_en.set_as_af_output(AFType::OutputPushPull, Speed::High);
73        self.txd0.set_as_af_output(AFType::OutputPushPull, Speed::High);
74        self.txd1.set_as_af_output(AFType::OutputPushPull, Speed::High);
75
76        [
77            self.ref_clk.into(),
78            self.mdio.into(),
79            self.mdc.into(),
80            self.crs_dv.into(),
81            self.rxd0.into(),
82            self.rxd1.into(),
83            self.tx_en.into(),
84            self.txd0.into(),
85            self.txd1.into(),
86        ]
87    }
88}
89
90/// Pins for the default RMII mapping without MDIO and MDC, consumed and configured by
91/// [`Ethernet::new_rmii_without_smi`](super::Ethernet::new_rmii_without_smi).
92///
93/// For a PHY the application manages on a bus of its own, so that a MAC reset never cuts
94/// a management transfer short.
95pub struct RmiiDataPins<'d, REFCLK: Pin, CRSDV: Pin, RXD0: Pin, RXD1: Pin, TXEN: Pin, TXD0: Pin, TXD1: Pin> {
96    /// REF_CLK (PA1).
97    pub ref_clk: Peri<'d, REFCLK>,
98    /// CRS_DV (PA7).
99    pub crs_dv: Peri<'d, CRSDV>,
100    /// RXD0 (PC4).
101    pub rxd0: Peri<'d, RXD0>,
102    /// RXD1 (PC5).
103    pub rxd1: Peri<'d, RXD1>,
104    /// TX_EN (PB11).
105    pub tx_en: Peri<'d, TXEN>,
106    /// TXD0 (PB12).
107    pub txd0: Peri<'d, TXD0>,
108    /// TXD1 (PB13).
109    pub txd1: Peri<'d, TXD1>,
110}
111
112impl<'d, REFCLK: Pin, CRSDV: Pin, RXD0: Pin, RXD1: Pin, TXEN: Pin, TXD0: Pin, TXD1: Pin>
113    RmiiDataPins<'d, REFCLK, CRSDV, RXD0, RXD1, TXEN, TXD0, TXD1>
114{
115    pub(super) fn configure(self) -> [Peri<'d, AnyPin>; 7] {
116        self.ref_clk.set_as_input(Pull::None);
117        self.crs_dv.set_as_input(Pull::None);
118        self.rxd0.set_as_input(Pull::None);
119        self.rxd1.set_as_input(Pull::None);
120        self.tx_en.set_as_af_output(AFType::OutputPushPull, Speed::High);
121        self.txd0.set_as_af_output(AFType::OutputPushPull, Speed::High);
122        self.txd1.set_as_af_output(AFType::OutputPushPull, Speed::High);
123
124        [
125            self.ref_clk.into(),
126            self.crs_dv.into(),
127            self.rxd0.into(),
128            self.rxd1.into(),
129            self.tx_en.into(),
130            self.txd0.into(),
131            self.txd1.into(),
132        ]
133    }
134}
135
136/// The RMII pins the driver keeps, with or without the management pins.
137// Never read: holding them is what keeps them from other drivers.
138#[allow(dead_code)]
139pub(super) enum HeldPins<'d> {
140    Rmii([Peri<'d, AnyPin>; 9]),
141    RmiiData([Peri<'d, AnyPin>; 7]),
142}