mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-18 16:27:34 +01:00
[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:
@@ -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
|
||||
|
||||
18
ion/src/device/n0100/drivers/usb.cpp
Normal file
18
ion/src/device/n0100/drivers/usb.cpp
Normal 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();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
35
ion/src/device/n0110/drivers/usb.cpp
Normal file
35
ion/src/device/n0110/drivers/usb.cpp
Normal 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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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() {
|
||||
|
||||
@@ -7,6 +7,8 @@ namespace USB {
|
||||
|
||||
void init();
|
||||
void shutdown();
|
||||
void initVbus();
|
||||
void shutdownVbus();
|
||||
void initGPIO();
|
||||
void shutdownGPIO();
|
||||
void initOTG();
|
||||
|
||||
@@ -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 \
|
||||
|
||||
Reference in New Issue
Block a user