11#pragma once
22
3- #include " stm32h7xx_hal.h"
4-
53#include " C++Utilities/CppUtils.hpp"
64#include " DigitalOutput2.hpp"
5+ #include " stm32h7xx_hal.h"
76
87#ifdef STLIB_ETH
8+ #include " ErrorHandler/ErrorHandler.hpp"
99#include " HALAL/Models/MAC/MAC.hpp"
1010#include " HALAL/Services/Communication/Ethernet/LWIP/Ethernet.hpp"
1111#include " HALAL/Services/Communication/Ethernet/LWIP/EthernetHelper.hpp"
1212#include " HALAL/Services/Communication/Ethernet/LWIP/EthernetNode.hpp"
1313#include " HALAL/Services/Communication/SNTP/SNTP.hpp"
14- #include " ErrorHandler/ErrorHandler.hpp"
1514#include " HALAL/Services/InfoWarning/InfoWarning.hpp"
1615extern " C" {
1716#include " ethernetif.h"
@@ -35,15 +34,16 @@ extern void compile_error(const char* msg);
3534#endif
3635
3736struct EthernetDomain {
38-
3937 struct EthernetPins {
38+ using OptionalPin = std::optional<reference_wrapper<const GPIODomain::Pin>>;
39+
4040 const GPIODomain::Pin& MDC;
4141 const GPIODomain::Pin& REF_CLK;
4242 const GPIODomain::Pin& MDIO;
4343 const GPIODomain::Pin& CRS_DV;
4444 const GPIODomain::Pin& RXD0;
4545 const GPIODomain::Pin& RXD1;
46- const GPIODomain::Pin& RXER;
46+ OptionalPin RXER;
4747 const GPIODomain::Pin& TXD1;
4848 const GPIODomain::Pin& TX_EN;
4949 const GPIODomain::Pin& TXD0;
@@ -57,7 +57,7 @@ struct EthernetDomain {
5757 .CRS_DV = PA7,
5858 .RXD0 = PC4,
5959 .RXD1 = PC5,
60- .RXER = PG2,
60+ .RXER = std::cref ( PG2) ,
6161 .TXD1 = PB13,
6262 .TX_EN = PG11,
6363 .TXD0 = PG13,
@@ -70,7 +70,7 @@ struct EthernetDomain {
7070 .CRS_DV = PA7,
7171 .RXD0 = PC4,
7272 .RXD1 = PC5,
73- .RXER = PG2 ,
73+ .RXER = std:: nullopt ,
7474 .TXD1 = PB13,
7575 .TX_EN = PB11,
7676 .TXD0 = PB12,
@@ -93,8 +93,24 @@ struct EthernetDomain {
9393 EthernetPins pins;
9494 Entry e;
9595
96- std::array<GPIODomain::GPIO, 10 > rmii_gpios;
96+ std::array<GPIODomain::GPIO, 9 > rmii_gpios;
9797 DigitalOutputDomain::DigitalOutput phy_reset;
98+ std::optional<GPIODomain::GPIO> rxer_gpio;
99+
100+ static consteval std::optional<GPIODomain::GPIO>
101+ make_rxer_gpio (EthernetPins::OptionalPin rxer_pin) {
102+ if (!rxer_pin.has_value ()) {
103+ return std::nullopt ;
104+ }
105+
106+ return GPIODomain::GPIO (
107+ rxer_pin->get (),
108+ GPIODomain::OperationMode::ALT_PP,
109+ GPIODomain::Pull::None,
110+ GPIODomain::Speed::VeryHigh,
111+ GPIODomain::AlternateFunction::AF11
112+ );
113+ }
98114
99115 consteval Ethernet (
100116 EthernetPins pins,
@@ -148,13 +164,6 @@ struct EthernetDomain {
148164 GPIODomain::Speed::VeryHigh,
149165 GPIODomain::AlternateFunction::AF11
150166 ),
151- GPIODomain::GPIO (
152- pins.RXER ,
153- GPIODomain::OperationMode::ALT_PP,
154- GPIODomain::Pull::None,
155- GPIODomain::Speed::VeryHigh,
156- GPIODomain::AlternateFunction::AF11
157- ),
158167 GPIODomain::GPIO (
159168 pins.TXD1 ,
160169 GPIODomain::OperationMode::ALT_PP,
@@ -177,12 +186,15 @@ struct EthernetDomain {
177186 GPIODomain::AlternateFunction::AF11
178187 )
179188 },
180- phy_reset{pins.PHY_RST } {}
189+ phy_reset{pins.PHY_RST }, rxer_gpio{ make_rxer_gpio (pins. RXER )} {}
181190
182191 template <class Ctx > consteval std::size_t inscribe (Ctx& ctx) const {
183192 for (const auto & gpio : rmii_gpios) {
184193 gpio.inscribe (ctx);
185194 }
195+ if (rxer_gpio.has_value ()) {
196+ rxer_gpio->inscribe (ctx);
197+ }
186198
187199 const auto phy_reset_id = phy_reset.inscribe (ctx);
188200 Entry entry{
0 commit comments