diff --git a/ion/src/f730/battery.cpp b/ion/src/f730/battery.cpp index f3ed16364..5e643f6b8 100644 --- a/ion/src/f730/battery.cpp +++ b/ion/src/f730/battery.cpp @@ -14,7 +14,7 @@ namespace Ion { namespace Battery { bool isCharging() { - return !Device::ChargingGPIO.IDR()->get(Device::ChargingPin); + return !Device::ChargingPin.group().IDR()->get(Device::ChargingPin.pin()); } Charge level() { @@ -52,7 +52,7 @@ void init() { /* The BAT_SNS pin is connected to Vbat through a divider bridge. It therefore * has a voltage of Vbat/2. We'll measure this using ADC channel 0. */ - ADCGPIO.MODER()->setMode(ADCPin, GPIO::MODER::Mode::Analog); + VoltagePin.group().MODER()->setMode(VoltagePin.pin(), GPIO::MODER::Mode::Analog); // Step 2 - Enable the ADC RCC.APB2ENR()->setADC1EN(true); @@ -70,13 +70,13 @@ void initGPIO() { * open-drain output. Open-drain output are either connected to ground or left * floating. To interact with such an output, our input must therefore be * pulled up. */ - ChargingGPIO.MODER()->setMode(ChargingPin, GPIO::MODER::Mode::Input); - ChargingGPIO.PUPDR()->setPull(ChargingPin, GPIO::PUPDR::Pull::Up); + ChargingPin.group().MODER()->setMode(ChargingPin.pin(), GPIO::MODER::Mode::Input); + ChargingPin.group().PUPDR()->setPull(ChargingPin.pin(), GPIO::PUPDR::Pull::Up); } void shutdown() { - ChargingGPIO.MODER()->setMode(ChargingPin, GPIO::MODER::Mode::Analog); - ChargingGPIO.PUPDR()->setPull(ChargingPin, GPIO::PUPDR::Pull::None); + ChargingPin.group().MODER()->setMode(ChargingPin.pin(), GPIO::MODER::Mode::Analog); + ChargingPin.group().PUPDR()->setPull(ChargingPin.pin(), GPIO::PUPDR::Pull::None); // Disable the ADC ADC.CR2()->setADON(false); diff --git a/ion/src/f730/battery.h b/ion/src/f730/battery.h index 5dac49de0..e9c402d44 100644 --- a/ion/src/f730/battery.h +++ b/ion/src/f730/battery.h @@ -1,7 +1,7 @@ #ifndef ION_DEVICE_BATTERY_H #define ION_DEVICE_BATTERY_H -#include "regs/regs.h" +#include "regs/gpio.h" namespace Ion { namespace Battery { @@ -18,11 +18,9 @@ void shutdown(); void initGPIO(); void initADC(); -constexpr GPIO ChargingGPIO = GPIOE; -constexpr uint8_t ChargingPin = 3; +constexpr GPIOPin ChargingPin = GPIOPin(GPIOE, 3); -constexpr GPIO ADCGPIO = GPIOB; -constexpr uint8_t ADCPin = 1; +constexpr GPIOPin VoltagePin = GPIOPin(GPIOB, 1); constexpr uint8_t ADCChannel = 9; constexpr float ADCReferenceVoltage = 2.8f; diff --git a/ion/src/f730/wakeup.cpp b/ion/src/f730/wakeup.cpp index 3582d6ad3..9486385d7 100644 --- a/ion/src/f730/wakeup.cpp +++ b/ion/src/f730/wakeup.cpp @@ -1,9 +1,12 @@ #include "wakeup.h" -#include "regs/regs.h" + #include "battery.h" #include "usb.h" #include "keyboard.h" +#include "regs/syscfg.h" +#include "regs/exti.h" + namespace Ion { namespace WakeUp { namespace Device { @@ -15,13 +18,13 @@ void onChargingEvent() { * source input for EXTI at the same time. Here, EXTICR1 register is filled * between position 0-3 (charging pin = 0) with * 0000 (ChargingGPIO = group A). */ - SYSCFG.EXTICR1()->setEXTI(Battery::Device::ChargingPin, Battery::Device::ChargingGPIO); + SYSCFG.EXTICR1()->setEXTI(Battery::Device::ChargingPin.pin(), Battery::Device::ChargingPin.group()); - EXTI.EMR()->set(Battery::Device::ChargingPin, true); + EXTI.EMR()->set(Battery::Device::ChargingPin.pin(), true); /* We need to detect when the battery stops charging. We set the * wake up event on the rising edge. */ - EXTI.RTSR()->set(Battery::Device::ChargingPin, true); + EXTI.RTSR()->set(Battery::Device::ChargingPin.pin(), true); } void onUSBPlugging() { diff --git a/ion/src/f730/wakeup.h b/ion/src/f730/wakeup.h index 0c7d641b9..36c35af70 100644 --- a/ion/src/f730/wakeup.h +++ b/ion/src/f730/wakeup.h @@ -1,8 +1,6 @@ #ifndef ION_DEVICE_WAKE_UP_H #define ION_DEVICE_WAKE_UP_H -#include "regs/regs.h" - namespace Ion { namespace WakeUp { namespace Device {