Skip to content

Commit

Permalink
[ion/device/n0110/usb] Consolidate configs of Vbus pin
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
GabrielNumworks committed Apr 16, 2021
1 parent 36655f1 commit b80daf7
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 19 deletions.
4 changes: 0 additions & 4 deletions ion/src/device/n0100/drivers/usb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@ void initVbus() {
Config::VbusPin.init();
}

void shutdownVbus() {
Config::VbusPin.shutdown();
}

}
}
}
9 changes: 7 additions & 2 deletions ion/src/device/n0110/drivers/config/usb.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
10 changes: 1 addition & 9 deletions ion/src/device/n0110/drivers/usb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

}
}
}
7 changes: 4 additions & 3 deletions ion/src/device/shared/drivers/usb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
1 change: 0 additions & 1 deletion ion/src/device/shared/drivers/usb.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ namespace USB {
void init();
void shutdown();
void initVbus();
void shutdownVbus();
void initGPIO();
void shutdownGPIO();
void initOTG();
Expand Down

0 comments on commit b80daf7

Please sign in to comment.