mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-03-27 09:40:07 +01:00
[ion/f730/battery] Redefine each pin as a GPIOPin
instead of a GPIO and a uint8_t
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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() {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user