[ion/f730/battery] Redefine each pin as a GPIOPin

instead of a GPIO and a uint8_t
This commit is contained in:
Ruben Dashyan
2019-01-18 11:51:27 +01:00
parent 37e70113d6
commit df09059cc5
4 changed files with 16 additions and 17 deletions

View File

@@ -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);

View File

@@ -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;

View File

@@ -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() {

View File

@@ -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 {