summaryrefslogtreecommitdiff
path: root/src/systemtask
diff options
context:
space:
mode:
Diffstat (limited to 'src/systemtask')
-rw-r--r--src/systemtask/Messages.h6
-rw-r--r--src/systemtask/SystemTask.cpp116
-rw-r--r--src/systemtask/SystemTask.h18
3 files changed, 85 insertions, 55 deletions
diff --git a/src/systemtask/Messages.h b/src/systemtask/Messages.h
index 3a195e2d..5aa218d2 100644
--- a/src/systemtask/Messages.h
+++ b/src/systemtask/Messages.h
@@ -20,7 +20,11 @@ namespace Pinetime {
EnableSleeping,
DisableSleeping,
OnNewDay,
- OnChargingEvent
+ OnChargingEvent,
+ SetOffAlarm,
+ StopRinging,
+ MeasureBatteryTimerExpired,
+ BatteryPercentageUpdated,
};
}
}
diff --git a/src/systemtask/SystemTask.cpp b/src/systemtask/SystemTask.cpp
index 03bf6706..f79fd8e5 100644
--- a/src/systemtask/SystemTask.cpp
+++ b/src/systemtask/SystemTask.cpp
@@ -21,7 +21,10 @@
#include "drivers/SpiNorFlash.h"
#include "drivers/TwiMaster.h"
#include "drivers/Hrs3300.h"
+#include "drivers/PinMap.h"
#include "main.h"
+#include "BootErrors.h"
+
#include <memory>
@@ -47,6 +50,11 @@ void IdleTimerCallback(TimerHandle_t xTimer) {
sysTask->OnIdle();
}
+void MeasureBatteryTimerCallback(TimerHandle_t xTimer) {
+ auto* sysTask = static_cast<SystemTask*>(pvTimerGetTimerID(xTimer));
+ sysTask->PushMessage(Pinetime::System::Messages::MeasureBatteryTimerExpired);
+}
+
SystemTask::SystemTask(Drivers::SpiMaster& spi,
Drivers::St7789& lcd,
Pinetime::Drivers::SpiNorFlash& spiNorFlash,
@@ -57,6 +65,7 @@ SystemTask::SystemTask(Drivers::SpiMaster& spi,
Controllers::Ble& bleController,
Controllers::DateTime& dateTimeController,
Controllers::TimerController& timerController,
+ Controllers::AlarmController& alarmController,
Drivers::Watchdog& watchdog,
Pinetime::Controllers::NotificationManager& notificationManager,
Pinetime::Controllers::MotorController& motorController,
@@ -79,6 +88,7 @@ SystemTask::SystemTask(Drivers::SpiMaster& spi,
bleController {bleController},
dateTimeController {dateTimeController},
timerController {timerController},
+ alarmController {alarmController},
watchdog {watchdog},
notificationManager {notificationManager},
motorController {motorController},
@@ -107,6 +117,8 @@ void SystemTask::Process(void* instance) {
}
void SystemTask::Work() {
+ BootErrors bootError = BootErrors::None;
+
watchdog.Setup(7);
watchdog.Start();
NRF_LOG_INFO("Last reset reason : %s", Pinetime::Drivers::Watchdog::ResetReasonToString(watchdog.ResetReason()));
@@ -121,17 +133,19 @@ void SystemTask::Work() {
fs.Init();
nimbleController.Init();
- nimbleController.StartAdvertising();
lcd.Init();
twiMaster.Init();
- touchPanel.Init();
+ if (!touchPanel.Init()) {
+ bootError = BootErrors::TouchController;
+ }
dateTimeController.Register(this);
- batteryController.Init();
+ batteryController.Register(this);
motorController.Init();
motionSensor.SoftReset();
timerController.Register(this);
timerController.Init();
+ alarmController.Init(this);
// Reset the TWI device because the motion sensor chip most probably crashed it...
twiMaster.Sleep();
@@ -142,28 +156,28 @@ void SystemTask::Work() {
settingsController.Init();
displayApp.Register(this);
- displayApp.Start();
-
- displayApp.PushMessage(Pinetime::Applications::Display::Messages::UpdateBatteryLevel);
+ displayApp.Start(bootError);
heartRateSensor.Init();
heartRateSensor.Disable();
heartRateApp.Start();
- nrf_gpio_cfg_sense_input(pinButton, (nrf_gpio_pin_pull_t) GPIO_PIN_CNF_PULL_Pulldown, (nrf_gpio_pin_sense_t) GPIO_PIN_CNF_SENSE_High);
+ // Button
nrf_gpio_cfg_output(15);
nrf_gpio_pin_set(15);
nrfx_gpiote_in_config_t pinConfig;
- pinConfig.skip_gpio_setup = true;
+ pinConfig.skip_gpio_setup = false;
pinConfig.hi_accuracy = false;
pinConfig.is_watcher = false;
- pinConfig.sense = (nrf_gpiote_polarity_t) NRF_GPIOTE_POLARITY_HITOLO;
+ pinConfig.sense = (nrf_gpiote_polarity_t) NRF_GPIOTE_POLARITY_TOGGLE;
pinConfig.pull = (nrf_gpio_pin_pull_t) GPIO_PIN_CNF_PULL_Pulldown;
- nrfx_gpiote_in_init(pinButton, &pinConfig, nrfx_gpiote_evt_handler);
+ nrfx_gpiote_in_init(PinMap::Button, &pinConfig, nrfx_gpiote_evt_handler);
+ nrfx_gpiote_in_event_enable(PinMap::Button, true);
- nrf_gpio_cfg_sense_input(pinTouchIrq, (nrf_gpio_pin_pull_t) GPIO_PIN_CNF_PULL_Pullup, (nrf_gpio_pin_sense_t) GPIO_PIN_CNF_SENSE_Low);
+ // Touchscreen
+ nrf_gpio_cfg_sense_input(PinMap::Cst816sIrq, (nrf_gpio_pin_pull_t) GPIO_PIN_CNF_PULL_Pullup, (nrf_gpio_pin_sense_t) GPIO_PIN_CNF_SENSE_Low);
pinConfig.skip_gpio_setup = true;
pinConfig.hi_accuracy = false;
@@ -171,24 +185,24 @@ void SystemTask::Work() {
pinConfig.sense = (nrf_gpiote_polarity_t) NRF_GPIOTE_POLARITY_HITOLO;
pinConfig.pull = (nrf_gpio_pin_pull_t) GPIO_PIN_CNF_PULL_Pullup;
- nrfx_gpiote_in_init(pinTouchIrq, &pinConfig, nrfx_gpiote_evt_handler);
+ nrfx_gpiote_in_init(PinMap::Cst816sIrq, &pinConfig, nrfx_gpiote_evt_handler);
+ // Power present
pinConfig.sense = NRF_GPIOTE_POLARITY_TOGGLE;
pinConfig.pull = NRF_GPIO_PIN_NOPULL;
pinConfig.is_watcher = false;
pinConfig.hi_accuracy = false;
- pinConfig.skip_gpio_setup = true;
- nrfx_gpiote_in_init(pinPowerPresentIrq, &pinConfig, nrfx_gpiote_evt_handler);
+ pinConfig.skip_gpio_setup = false;
+ nrfx_gpiote_in_init(PinMap::PowerPresent, &pinConfig, nrfx_gpiote_evt_handler);
+ nrfx_gpiote_in_event_enable(PinMap::PowerPresent, true);
- if (nrf_gpio_pin_read(pinPowerPresentIrq)) {
- nrf_gpio_cfg_sense_input(pinPowerPresentIrq, NRF_GPIO_PIN_NOPULL, NRF_GPIO_PIN_SENSE_LOW);
- } else {
- nrf_gpio_cfg_sense_input(pinPowerPresentIrq, NRF_GPIO_PIN_NOPULL, NRF_GPIO_PIN_SENSE_HIGH);
- }
+ batteryController.MeasureVoltage();
idleTimer = xTimerCreate("idleTimer", pdMS_TO_TICKS(2000), pdFALSE, this, IdleTimerCallback);
dimTimer = xTimerCreate("dimTimer", pdMS_TO_TICKS(settingsController.GetScreenTimeOut() - 2000), pdFALSE, this, DimTimerCallback);
+ measureBatteryTimer = xTimerCreate("measureBattery", batteryMeasurementPeriod, pdTRUE, this, MeasureBatteryTimerCallback);
xTimerStart(dimTimer, 0);
+ xTimerStart(measureBatteryTimer, portMAX_DELAY);
// Suppress endless loop diagnostic
#pragma clang diagnostic push
@@ -198,11 +212,6 @@ void SystemTask::Work() {
uint8_t msg;
if (xQueueReceive(systemTasksMsgQueue, &msg, 100)) {
-
- batteryController.Update();
- // the battery does not emit events when changing charge levels, so we piggyback
- // on any system event to read and update the current values
-
Messages message = static_cast<Messages>(msg);
switch (message) {
case Messages::EnableSleeping:
@@ -226,26 +235,29 @@ void SystemTask::Work() {
touchPanel.Wakeup();
}
- nimbleController.StartAdvertising();
xTimerStart(dimTimer, 0);
spiNorFlash.Wakeup();
lcd.Wakeup();
displayApp.PushMessage(Pinetime::Applications::Display::Messages::GoToRunning);
- displayApp.PushMessage(Pinetime::Applications::Display::Messages::UpdateBatteryLevel);
heartRateApp.PushMessage(Pinetime::Applications::HeartRateTask::Messages::WakeUp);
+ if (!bleController.IsConnected())
+ nimbleController.RestartFastAdv();
+
isSleeping = false;
isWakingUp = false;
isDimmed = false;
break;
case Messages::TouchWakeUp: {
- auto touchInfo = touchPanel.GetTouchInfo();
- if (touchInfo.touching and ((touchInfo.gesture == Pinetime::Drivers::Cst816S::Gestures::DoubleTap and
- settingsController.isWakeUpModeOn(Pinetime::Controllers::Settings::WakeUpMode::DoubleTap)) or
- (touchInfo.gesture == Pinetime::Drivers::Cst816S::Gestures::SingleTap and
- settingsController.isWakeUpModeOn(Pinetime::Controllers::Settings::WakeUpMode::SingleTap)))) {
- GoToRunning();
+ if(touchHandler.GetNewTouchInfo()) {
+ auto gesture = touchHandler.GestureGet();
+ if (gesture != Pinetime::Drivers::Cst816S::Gestures::None and ((gesture == Pinetime::Drivers::Cst816S::Gestures::DoubleTap and
+ settingsController.isWakeUpModeOn(Pinetime::Controllers::Settings::WakeUpMode::DoubleTap)) or
+ (gesture == Pinetime::Drivers::Cst816S::Gestures::SingleTap and
+ settingsController.isWakeUpModeOn(Pinetime::Controllers::Settings::WakeUpMode::SingleTap)))) {
+ GoToRunning();
+ }
}
} break;
case Messages::GoToSleep:
@@ -261,10 +273,12 @@ void SystemTask::Work() {
displayApp.PushMessage(Pinetime::Applications::Display::Messages::UpdateDateTime);
break;
case Messages::OnNewNotification:
- if (isSleeping && !isWakingUp) {
- GoToRunning();
+ if (settingsController.GetNotificationStatus() == Pinetime::Controllers::Settings::Notification::ON) {
+ if (isSleeping && !isWakingUp) {
+ GoToRunning();
+ }
+ displayApp.PushMessage(Pinetime::Applications::Display::Messages::NewNotification);
}
- displayApp.PushMessage(Pinetime::Applications::Display::Messages::NewNotification);
break;
case Messages::OnTimerDone:
if (isSleeping && !isWakingUp) {
@@ -273,6 +287,16 @@ void SystemTask::Work() {
motorController.RunForDuration(35);
displayApp.PushMessage(Pinetime::Applications::Display::Messages::TimerDone);
break;
+ case Messages::SetOffAlarm:
+ if (isSleeping && !isWakingUp) {
+ GoToRunning();
+ }
+ motorController.StartRinging();
+ displayApp.PushMessage(Pinetime::Applications::Display::Messages::AlarmTriggered);
+ break;
+ case Messages::StopRinging:
+ motorController.StopRinging();
+ break;
case Messages::BleConnected:
ReloadIdleTimer();
isBleDiscoveryTimerRunning = true;
@@ -325,8 +349,18 @@ void SystemTask::Work() {
stepCounterMustBeReset = true;
break;
case Messages::OnChargingEvent:
+ batteryController.ReadPowerState();
motorController.RunForDuration(15);
- // Battery level is updated on every message - there's no need to do anything
+ ReloadIdleTimer();
+ if (isSleeping && !isWakingUp) {
+ GoToRunning();
+ }
+ break;
+ case Messages::MeasureBatteryTimerExpired:
+ batteryController.MeasureVoltage();
+ break;
+ case Messages::BatteryPercentageUpdated:
+ nimbleController.NotifyBatteryLevel(batteryController.PercentRemaining());
break;
default:
@@ -338,22 +372,18 @@ void SystemTask::Work() {
if (bleDiscoveryTimer == 0) {
isBleDiscoveryTimerRunning = false;
// Services discovery is deffered from 3 seconds to avoid the conflicts between the host communicating with the
- // tharget and vice-versa. I'm not sure if this is the right way to handle this...
+ // target and vice-versa. I'm not sure if this is the right way to handle this...
nimbleController.StartDiscovery();
} else {
bleDiscoveryTimer--;
}
}
- if (xTaskGetTickCount() - batteryNotificationTick > batteryNotificationPeriod) {
- nimbleController.NotifyBatteryLevel(batteryController.PercentRemaining());
- batteryNotificationTick = xTaskGetTickCount();
- }
-
monitor.Process();
uint32_t systick_counter = nrf_rtc_counter_get(portNRF_RTC_REG);
dateTimeController.UpdateTime(systick_counter);
- if (!nrf_gpio_pin_read(pinButton))
+ NoInit_BackUpTime = dateTimeController.CurrentDateTime();
+ if (!nrf_gpio_pin_read(PinMap::Button))
watchdog.Kick();
}
// Clear diagnostic suppression
diff --git a/src/systemtask/SystemTask.h b/src/systemtask/SystemTask.h
index 0266ba8a..879c1be8 100644
--- a/src/systemtask/SystemTask.h
+++ b/src/systemtask/SystemTask.h
@@ -8,6 +8,7 @@
#include <heartratetask/HeartRateTask.h>
#include <components/settings/Settings.h>
#include <drivers/Bma421.h>
+#include <drivers/PinMap.h>
#include <components/motion/MotionController.h>
#include "SystemMonitor.h"
@@ -16,6 +17,7 @@
#include "components/ble/NotificationManager.h"
#include "components/motor/MotorController.h"
#include "components/timer/TimerController.h"
+#include "components/alarm/AlarmController.h"
#include "components/fs/FS.h"
#include "touchhandler/TouchHandler.h"
@@ -31,6 +33,7 @@
#include "drivers/Watchdog.h"
#include "Messages.h"
+extern std::chrono::time_point<std::chrono::system_clock, std::chrono::nanoseconds> NoInit_BackUpTime;
namespace Pinetime {
namespace Drivers {
class Cst816S;
@@ -56,6 +59,7 @@ namespace Pinetime {
Controllers::Ble& bleController,
Controllers::DateTime& dateTimeController,
Controllers::TimerController& timerController,
+ Controllers::AlarmController& alarmController,
Drivers::Watchdog& watchdog,
Pinetime::Controllers::NotificationManager& notificationManager,
Pinetime::Controllers::MotorController& motorController,
@@ -100,6 +104,7 @@ namespace Pinetime {
Pinetime::Controllers::Ble& bleController;
Pinetime::Controllers::DateTime& dateTimeController;
Pinetime::Controllers::TimerController& timerController;
+ Pinetime::Controllers::AlarmController& alarmController;
QueueHandle_t systemTasksMsgQueue;
std::atomic<bool> isSleeping {false};
std::atomic<bool> isGoingToSleep {false};
@@ -120,15 +125,6 @@ namespace Pinetime {
Pinetime::Controllers::TouchHandler& touchHandler;
Pinetime::Controllers::NimbleController nimbleController;
- static constexpr uint8_t pinSpiSck = 2;
- static constexpr uint8_t pinSpiMosi = 3;
- static constexpr uint8_t pinSpiMiso = 4;
- static constexpr uint8_t pinSpiCsn = 25;
- static constexpr uint8_t pinLcdDataCommand = 18;
- static constexpr uint8_t pinButton = 13;
- static constexpr uint8_t pinTouchIrq = 28;
- static constexpr uint8_t pinPowerPresentIrq = 19;
-
static void Process(void* instance);
void Work();
void ReloadIdleTimer();
@@ -136,13 +132,13 @@ namespace Pinetime {
uint8_t bleDiscoveryTimer = 0;
TimerHandle_t dimTimer;
TimerHandle_t idleTimer;
+ TimerHandle_t measureBatteryTimer;
bool doNotGoToSleep = false;
void GoToRunning();
void UpdateMotion();
bool stepCounterMustBeReset = false;
- static constexpr TickType_t batteryNotificationPeriod = 1000 * 60 * 10; // 1 tick ~= 1ms. 1ms * 60 * 10 = 10 minutes
- TickType_t batteryNotificationTick = 0;
+ static constexpr TickType_t batteryMeasurementPeriod = pdMS_TO_TICKS(10 * 60 * 1000);
#if configUSE_TRACE_FACILITY == 1
SystemMonitor<FreeRtosMonitor> monitor;