summaryrefslogtreecommitdiff
path: root/src/components/battery
diff options
context:
space:
mode:
Diffstat (limited to 'src/components/battery')
-rw-r--r--src/components/battery/BatteryController.cpp16
-rw-r--r--src/components/battery/BatteryController.h9
2 files changed, 11 insertions, 14 deletions
diff --git a/src/components/battery/BatteryController.cpp b/src/components/battery/BatteryController.cpp
index 4ef20a2..f8a64ec 100644
--- a/src/components/battery/BatteryController.cpp
+++ b/src/components/battery/BatteryController.cpp
@@ -1,5 +1,4 @@
#include "BatteryController.h"
-#include "drivers/PinMap.h"
#include <hal/nrf_gpio.h>
#include <nrfx_saadc.h>
#include <algorithm>
@@ -10,12 +9,15 @@ Battery* Battery::instance = nullptr;
Battery::Battery() {
instance = this;
- nrf_gpio_cfg_input(PinMap::Charging, static_cast<nrf_gpio_pin_pull_t> GPIO_PIN_CNF_PULL_Disabled);
+}
+
+void Battery::Init() {
+ nrf_gpio_cfg_input(chargingPin, static_cast<nrf_gpio_pin_pull_t> GPIO_PIN_CNF_PULL_Pullup);
}
void Battery::Update() {
- isCharging = !nrf_gpio_pin_read(PinMap::Charging);
- isPowerPresent = !nrf_gpio_pin_read(PinMap::PowerPresent);
+ isCharging = !nrf_gpio_pin_read(chargingPin);
+ isPowerPresent = !nrf_gpio_pin_read(powerPresentPin);
if (isReading) {
return;
@@ -73,11 +75,5 @@ void Battery::SaadcEventHandler(nrfx_saadc_evt_t const* p_event) {
nrfx_saadc_uninit();
isReading = false;
-
- systemTask->PushMessage(System::Messages::BatteryMeasurementDone);
}
}
-
-void Battery::Register(Pinetime::System::SystemTask* systemTask) {
- this->systemTask = systemTask;
-}
diff --git a/src/components/battery/BatteryController.h b/src/components/battery/BatteryController.h
index 8af27ea..6f09b73 100644
--- a/src/components/battery/BatteryController.h
+++ b/src/components/battery/BatteryController.h
@@ -1,7 +1,8 @@
#pragma once
#include <cstdint>
#include <drivers/include/nrfx_saadc.h>
-#include <systemtask/SystemTask.h>
+#include <array>
+#include <numeric>
namespace Pinetime {
namespace Controllers {
@@ -10,8 +11,8 @@ namespace Pinetime {
public:
Battery();
+ void Init();
void Update();
- void Register(System::SystemTask* systemTask);
uint8_t PercentRemaining() const {
return percentRemaining;
@@ -33,6 +34,8 @@ namespace Pinetime {
static Battery* instance;
nrf_saadc_value_t saadc_value;
+ static constexpr uint32_t chargingPin = 12;
+ static constexpr uint32_t powerPresentPin = 19;
static constexpr nrf_saadc_input_t batteryVoltageAdcInput = NRF_SAADC_INPUT_AIN7;
uint16_t voltage = 0;
uint8_t percentRemaining = 0;
@@ -46,8 +49,6 @@ namespace Pinetime {
static void AdcCallbackStatic(nrfx_saadc_evt_t const* event);
bool isReading = false;
-
- Pinetime::System::SystemTask* systemTask = nullptr;
};
}
}