[ion/device/n0110/usb] Consolidate configs of Vbus pin

Even though the configuration of the Vbus pin depends on the hardware
running Epsilon, we do not actually need one VbusPin object for each
configuration. Indeed, an AFGPIOPin object can be used to configure the
pin as a standard GPIO, provided one does not call its init() method.
This commit is contained in:
Gabriel Ozouf
2021-03-24 11:05:57 +01:00
committed by Gabriel
parent 36655f1c19
commit b80daf70d3
5 changed files with 12 additions and 19 deletions

View File

@@ -9,10 +9,6 @@ void initVbus() {
Config::VbusPin.init();
}
void shutdownVbus() {
Config::VbusPin.shutdown();
}
}
}
}

View File

@@ -10,8 +10,13 @@ namespace Config {
using namespace Regs;
constexpr static GPIOPin VbusPin = GPIOPin(GPIOA, 9);
constexpr static AFGPIOPin VbusAFPin = AFGPIOPin(GPIOA, 9, GPIO::AFR::AlternateFunction::AF10, GPIO::PUPDR::Pull::None, GPIO::OSPEEDR::OutputSpeed::Fast);
/* On the STM32F730, PA9 does not actually support alternate function 10.
* However, because of the wiring of the USB connector on the N0110, detection
* of when the device is plugged requires the use of this undocumented setting.
* After the revision of the USB connector and ESD protection, can can now
* follow the specification and configure the Vbus pin as a floating-input GPIO.
*/
constexpr static AFGPIOPin VbusPin = AFGPIOPin(GPIOA, 9, GPIO::AFR::AlternateFunction::AF10, GPIO::PUPDR::Pull::None, GPIO::OSPEEDR::OutputSpeed::Fast);
constexpr static AFGPIOPin DmPin = AFGPIOPin(GPIOA, 11, GPIO::AFR::AlternateFunction::AF10, GPIO::PUPDR::Pull::None, GPIO::OSPEEDR::OutputSpeed::Fast);
constexpr static AFGPIOPin DpPin = AFGPIOPin(GPIOA, 12, GPIO::AFR::AlternateFunction::AF10, GPIO::PUPDR::Pull::None, GPIO::OSPEEDR::OutputSpeed::Fast);

View File

@@ -15,21 +15,13 @@ bool useAlternateFunctionVbus() {
void initVbus() {
if (useAlternateFunctionVbus()) {
Config::VbusAFPin.init();
Config::VbusPin.init();
} else {
Config::VbusPin.group().MODER()->setMode(Config::VbusPin.pin(), GPIO::MODER::Mode::Input);
Config::VbusPin.group().PUPDR()->setPull(Config::VbusPin.pin(), GPIO::PUPDR::Pull::None);
}
}
void shutdownVbus() {
if (useAlternateFunctionVbus()) {
Config::VbusAFPin.shutdown();
} else {
Config::VbusPin.group().MODER()->setMode(Config::VbusPin.pin(), GPIO::MODER::Mode::Analog);
}
}
}
}
}

View File

@@ -75,9 +75,10 @@ void initGPIO() {
}
void shutdownGPIO() {
Config::DpPin.shutdown();
Config::DmPin.shutdown();
shutdownVbus();
constexpr static AFGPIOPin Pins[] = { Config::DpPin, Config::DmPin, Config::VbusPin };
for (const AFGPIOPin & p : Pins) {
p.shutdown();
}
}
void initOTG() {

View File

@@ -8,7 +8,6 @@ namespace USB {
void init();
void shutdown();
void initVbus();
void shutdownVbus();
void initGPIO();
void shutdownGPIO();
void initOTG();