[ion/device/n0110] Deduce Vbus config from PCB version

Revised PCB (version number > 0) should configure Vbus as a GPIO instead
of an alternate function.
This commit is contained in:
Gabriel Ozouf
2021-02-26 10:53:50 +01:00
committed by Gabriel
parent c4ef2016ba
commit ddae6607f9
8 changed files with 69 additions and 15 deletions

View File

@@ -3,6 +3,7 @@ ion_device_src += $(addprefix ion/src/device/n0100/drivers/, \
led.cpp \
power.cpp \
reset.cpp \
usb.cpp \
)
LDSCRIPT ?= ion/src/device/n0100/flash.ld

View File

@@ -0,0 +1,18 @@
#include <drivers/usb.h>
#include <drivers/config/usb.h>
namespace Ion {
namespace Device {
namespace USB {
void initVbus() {
Config::VbusPin.init();
}
void shutdownVbus() {
Config::VbusPin.shutdown();
}
}
}
}

View File

@@ -4,6 +4,7 @@ ion_device_src += $(addprefix ion/src/device/n0110/drivers/, \
led.cpp \
power.cpp \
reset.cpp \
usb.cpp \
)
LDSCRIPT ?= ion/src/device/n0110/flash.ld

View File

@@ -10,7 +10,9 @@ namespace Config {
using namespace Regs;
constexpr static AFGPIOPin VbusPin = AFGPIOPin(GPIOA, 9, GPIO::AFR::AlternateFunction::AF10, GPIO::PUPDR::Pull::None, GPIO::OSPEEDR::OutputSpeed::Fast);
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);
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

@@ -0,0 +1,35 @@
#include <drivers/usb.h>
#include <drivers/board.h>
#include <drivers/config/usb.h>
namespace Ion {
namespace Device {
using namespace Regs;
namespace USB {
bool useAlternateFunctionVbus() {
return Board::readPCBVersion() == 0;
}
void initVbus() {
if (useAlternateFunctionVbus()) {
Config::VbusAFPin.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

@@ -65,25 +65,19 @@ void initGPIO() {
GPIOC.MODER()->setMode(11, GPIO::MODER::Mode::Output);
GPIOC.ODR()->set(11, false);
/* Configure the GPIO
* The VBUS pin is connected to the USB VBUS port. To read if the USB is
* plugged, the pin must be pulled down. */
// FIXME: Understand how the Vbus pin really works!
#if 0
Config::VbusPin.group().MODER()->setMode(Config::VbusPin.pin(), GPIO::MODER::Mode::Input);
Config::VbusPin.group().PUPDR()->setPull(Config::VbusPin.pin(), GPIO::PUPDR::Pull::Down);
#else
Config::VbusPin.init();
#endif
/* Configure the GPIO */
/* The Vbus pin is connected to the USB Vbus port. Depending on the
* hardware, it should either be configured as an AlternateFunction, or as a
* floating Input. */
initVbus();
Config::DmPin.init();
Config::DpPin.init();
}
void shutdownGPIO() {
constexpr static AFGPIOPin Pins[] = {Config::DpPin, Config::DmPin, Config::VbusPin};
for (const AFGPIOPin & p : Pins) {
p.shutdown();
}
Config::DpPin.shutdown();
Config::DmPin.shutdown();
shutdownVbus();
}
void initOTG() {

View File

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

View File

@@ -44,6 +44,7 @@ ion_device_dfu_src += ion/src/device/shared/usb/boot.cpp
ion_device_dfu_src += ion/src/device/$(MODEL)/drivers/board.cpp
ion_device_dfu_src += ion/src/device/$(MODEL)/drivers/cache.cpp
ion_device_dfu_src += ion/src/device/$(MODEL)/drivers/reset.cpp
ion_device_dfu_src += ion/src/device/$(MODEL)/drivers/usb.cpp
ion_device_dfu_src += $(addprefix ion/src/device/shared/drivers/, \
backlight.cpp \
battery.cpp \